Getting Data In

How to post to Http Event Collector with PHP?

daniel333
Builder

All,

Anyone ever post to HEC using PHP? Got a working example? Or see where I am going wrong?

<?php
        $ch = curl_init("https://10.x.x.x:8088/services/collector/event");
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERPWD, "x:MYTOKEN");
        curl_setopt($ch, CURLOPT_POSTFIELDS, "number=10");
        $output = curl_exec($ch);
        curl_close($ch);
        echo $output;
?>
0 Karma
1 Solution

daniel333
Builder

Got it! Trick was the formatting of the $data variable.

// Send Data to HEC with PHP

<?php
        $data = "{\"event\":\"testing\",\"sourcetype\": \"st\"}";
        $ch = curl_init("https://10.x.x.x:8088/services/collector/event");
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERPWD, "x:cbmytoen");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $output = curl_exec($ch);
        curl_close($ch);
        echo $output;
?>

View solution in original post

daniel333
Builder

Got it! Trick was the formatting of the $data variable.

// Send Data to HEC with PHP

<?php
        $data = "{\"event\":\"testing\",\"sourcetype\": \"st\"}";
        $ch = curl_init("https://10.x.x.x:8088/services/collector/event");
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERPWD, "x:cbmytoen");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $output = curl_exec($ch);
        curl_close($ch);
        echo $output;
?>
Get Updates on the Splunk Community!

.conf24 | Day 0

Hello Splunk Community! My name is Chris, and I'm based in Canberra, Australia's capital, and I travelled for ...

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...