testing - How to test logstash with PHP script -
i have installed logstash, configured config file input, filter , output , have run it. possible test if logstash pushes log data writing php script? can provide me php script can catch log data, sending logstash?
run following list of logs in elasticsearch index :
$date = date("y.m.d"); $host = "127.0.0.1"; $port = "9200"; $index = "logstash-".$date; $type = "*"; $log = array(); $query = '{"query":{"match_all":{}}}'; $curl = curl_init(); if ($curl) { curl_setopt($curl,curlopt_url, $host."/".$index."/".$type."/_search"); curl_setopt($curl, curlopt_port, $port); curl_setopt($curl, curlopt_customrequest, "post"); curl_setopt($curl, curlopt_postfields, $query); curl_setopt($curl, curlopt_returntransfer, 1); $result = curl_exec($curl); if (curl_errno($curl)) { echo curl_error($curl); //error } curl_close($curl); if (!$result) { //error } $arr=(json_decode($result, true)); $logs = $arr['hits']['hits']; // if logs found if (count($logs)>0) { foreach ($logs $q) { // load data in $data array $log[] = $q["_source"]; echo "<pre>"; print_r($log); echo "</pre>"; } } } ?>
cheers.
Comments
Post a Comment