Last active
August 29, 2015 14:13
-
-
Save ktilcu/768f37931bc33742a6f8 to your computer and use it in GitHub Desktop.
Script to display how to use php to send data to sensu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| error_reporting(E_ALL); | |
| /* The port for the sensu. */ | |
| $service_port = 3030; | |
| /* Docker binds to localhost on staging */ | |
| $address = "127.0.0.1"; | |
| /* Create a TCP/IP socket. Can also use UDP if speed is a concern*/ | |
| $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
| if ($socket === false) { | |
| echo "socket_create() failed: reason: " . | |
| socket_strerror(socket_last_error()) . "\n"; | |
| } | |
| echo "Attempting to connect to '$address' on port '$service_port'..."; | |
| $result = socket_connect($socket, $address, $service_port); | |
| if ($result === false) { | |
| echo "socket_connect() failed.\nReason: ($result) " . | |
| socket_strerror(socket_last_error($socket)) . "\n"; | |
| } | |
| $in = '{"name": "_bin_false","output": "/bin/false: No such file or directory","status": 2}'; | |
| echo "Sending data..."; | |
| socket_write($socket, $in, strlen($in)); | |
| echo "OK.\n"; | |
| socket_close($socket); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment