Created
July 25, 2016 23:02
-
-
Save logikal/41a37c0a78b2e43cbfce0955b31782f6 to your computer and use it in GitHub Desktop.
A sensu mutator to turn warnings into criticals when the TTL has expired.
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
#!/usr/bin/env ruby | |
# | |
# Mutate TTL results with warnings to critical status | |
# Because Sensu hardcodes a stale TTL check to status=1 | |
# we'll never get paged for TTL failures. | |
# Refer to https://github.com/sensu/sensu/issues/1166 | |
# | |
# Cribbed from the example at https://sensuapp.org/docs/0.25/reference/plugins.html#example-plugins | |
require 'json' | |
event = JSON.parse(STDIN.read, :symbolize_names => true) | |
# If we have a check with a ttl and a warning status | |
# check if the time since execution is more than the allowed TTL | |
# Change the status to 2 if so. | |
if (event[:check].key?(:ttl) && event[:check][:status] == 1) | |
time_since_last_execution = Time.now.to_i - event[:check][:executed] | |
if time_since_last_execution >= event[:check][:ttl] | |
event[:check][:status] = 2 | |
end | |
end | |
puts event.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment