Skip to content

Instantly share code, notes, and snippets.

@logikal
Created July 25, 2016 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logikal/41a37c0a78b2e43cbfce0955b31782f6 to your computer and use it in GitHub Desktop.
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.
#!/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