I installed Sensu on Debian Wheezy using the omnibus package. Things are working fine except for this one issue I am facing. I cannot resolve events using sensu-api. Is anyone else using the API to post updates? Can this work?
My goal is to allow Pagerduty to resolve Sensu events using Pagerduty webhooks. I am testing to see how the sensu-api works for resolving active events.
I am monitoring a cron process on my sensu client. I stopped the process on the client cFQDN and waited for the event to show in the sensu-server log:
(Note: cFQDN is my client and hFQDN is the sensu server.)
{“timestamp”:“2014-01-30T15:59:15.206641-0800”,“level”:“info”,“message”:“handler output”,“handler”:{“type”:“pipe”,“command”:"/etc/sensu/handlers/pagerduty.rb",“name”:“pagerduty”},“output”:“pagerduty – Created incident – cFQDN/cron_check\n”}
{“timestamp”:“2014-01-30T15:59:15.868650-0800”,“level”:“info”,“message”:“handler output”,“handler”:{“type”:“pipe”,“command”:"/etc/sensu/handlers/mailer.rb",“name”:“mailer”},“output”:“mail – sent alert for cFQDN/cron_check to sensu@email.info\n”}
I get the alert email and see the incident on Pagerduty:
Description: cFQDN : cron_check : CheckProcs CRITICAL: Found 0 matching processes; cmd /cron/
Incident Key: cFQDN/cron_check
Now I want to manually resolve the event using the sensu-api.
I use this php with Interactive mode enabled:
php > $username = “user”;
php > $password = “pass”;
php > $data = array(“client” => “cFQDN”, “check” => “cron_check”);
php > $data_string = json_encode($data);
php > $ch = curl_init();
php > curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”);
php > curl_setopt($ch, CURLOPT_URL, “http://hFQDN:4567”);
php > $result = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, “http://hFQDN:4567/events”);
php > curl_setopt($ch, CURLOPT_URL, “http://hFQDN:4567/events”);
php > $result = curl_exec($ch);
[{“output”:“CheckProcs CRITICAL: Found 0 matching processes; cmd /cron/\n”,“status”:2,“issued”:1391128634,“handlers”:[“mailer”,“pagerduty”],“flapping”:false,“occurrences”:3,“client”:“cFQDN”,“check”:“cron_check”}]php > echo $result,"\n";
1
php > curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
php > curl_setopt($ch, CURLOPT_URL, “http://hFQDN:4567/event/resolve”);
php > $result = curl_exec($ch);
php > echo $result,"\n";
1
php > curl_close($ch);
So access through sensu-api is working. The login occurs and the /events get displayed. When the /event/resolve POST is attempted it does not resolve the event.
These are the results from sensu-api log:
{“timestamp”:“2014-01-30T16:03:21.118570-0800”,“level”:“info”,“message”:“GET /events”,“remote_address”:“xxx.xxx.xx.xxx”,“user_agent”:null,“request_method”:“GET”,“request_uri”:"/events",“request_body”:""}
{“timestamp”:“2014-01-30T16:03:21.124943-0800”,“level”:“info”,“message”:“POST /event/resolve”,“remote_address”:“xxx.xxx.xx.xxx”,“user_agent”:null,“request_method”:“POST”,“request_uri”:"/event/resolve",“request_body”:"{“client”:“cFQDN”,“check”:“cron_check”}"}