Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sensu trigger event manually

Tags:

sensu

Sensu says: A Sensu Event is created when a check result indicates a change in state.

Is it possible to create a custom event which is not a result of a check ?

Sensu API has no command to create an event: https://sensuapp.org/docs/latest/api-events.

like image 430
Max Ivak Avatar asked Dec 18 '15 16:12

Max Ivak


1 Answers

Yes, but it will look a check in Uchiwa - despite not being defined in sensu.

See this page: https://sensuapp.org/docs/0.16/external_result_input

On a client (linux) I ran;

echo '{ "name": "my_check", "output": "some output", "status": 0 }' > /dev/tcp/localhost/3030

And it magically appeared in Uchiwa under that client's checks list.

Then I ran it again with the status field set to 1:

echo '{ "name": "my_check", "output": "some output", "status": 1 }' > /dev/tcp/localhost/3030

And Uchiwa displayed it as a warning.

I ran it a third time with a status of 2 and, as expected, it turned into a critical. Running it again with a status of 0 will return it to normal.

So, depending on what you want to achieve, you could execute this in PHP/Python/Whatever on the client, and then define a handler for it on your sensu server to do whatever it is you need to do. Just add the handler name to to JSON, plus any other data you want to pass along.

Eg:

echo '{ "name": "trickyCheck", "output": "cake is delicious", "status": 0, "handler": "handlerOfDoom", "link": "http://cats.com" }' > /dev/tcp/localhost/3030

Handler:

{
  "handlers": {
    "handlerOfDoom": {
      "type": "pipe",
      "command": "doSomethingCool.rb",
      "severities": ["warning","critical"]
      }
    }
  }
}

The ruby script will have access to everything in the JSON; output, link, status, etc... So do what you need to do there.

To achieve the same with Sensu on Windows might require another tool to send data to a tcp port on the localhost. https://serverfault.com/questions/629682/send-text-string-to-a-socket-in-windows

like image 132
Chris Avatar answered Oct 26 '22 06:10

Chris