Skip to content

Instantly share code, notes, and snippets.

@faja
Last active December 14, 2015 21:48
Show Gist options
  • Save faja/5153308 to your computer and use it in GitHub Desktop.
Save faja/5153308 to your computer and use it in GitHub Desktop.

##SENSU ###How to use one script for 'metric' and 'standard' check.

I want to use one script for metric and standard 'OK/CRITICAL' check. check.rb prints metric and additional 'OK/CRITICAL' info. Metric handler before sending data to graphite remove all "o:.*" lines, and notification handler remove all 'metric' lines from check output.

Check of course have to be 'type':'metric'.

And for escalation notification i'm using:https://github.com/faja/sensu-community-plugins/tree/master/handlers/escalation

#...
# puts some metric
puts "some.metric.line1 42 #{Time.now.to_i}"
puts "some.metric.line2 42 #{Time.now.to_i}"
#...
#then puts output info with o: prefix
puts "o:Additional info line1"
puts "o:something is CRITICAL"
#...
#then exit
exit 2
#...
metrics = @event['check']['output'].split("\n").delete_if{|item| item =~ /^o:/}.join("\n")
#...
#...
additional_info = @event['check']['output'].split("\n").keep_if{|item| item =~ /^o:/}.join("\n").gsub(/^o:/,'')
#...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment