Last active
August 29, 2015 14:11
-
-
Save kazu634/e44711faee1c2b55b088 to your computer and use it in GitHub Desktop.
sensu scripts
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
#!/opt/sensu/embedded/bin/ruby | |
require 'rubygems' | |
require 'json' | |
require 'growthforecast' | |
# constants | |
COLORS = { | |
"cpu" => { | |
"user" => "#FFBB7F", | |
"system" => "#FF7FDD", | |
"softirq" => "#877FFF", | |
"irq" => "#877FFF", | |
"iowait" => "#877FFF", | |
"guest" => "#7FFFEE", | |
"steal" => "#7FFFEE", | |
"nice" => "#7FFFEE", | |
"idle" => "#7FFFAA" }, | |
"memory" => { | |
"usedWOBuffersCaches" => "#E57FFF", | |
"buffers" => "#8C7FFF", | |
"cached" => "#7FFFF2", | |
"free" => "#7FFF9D"} | |
} | |
# making instances | |
gf = GrowthForecast.new('localhost', 5125) | |
# Read event data | |
event = JSON.parse(STDIN.read, :symbolize_names => true) | |
event_output = event[:check][:output] | |
event_output.split("\n").each do |line| | |
title, value, time = line.split(" ") | |
hostname, section, key = title.split("\.") | |
# puts hostname | |
# puts section | |
# puts key | |
# puts value | |
# puts time | |
if COLORS.keys.include?(section) | |
if COLORS[section].keys.include?(key) | |
color = COLORS[section][key] | |
gf.post(hostname, section, key, value, 'gauge', color) | |
else | |
gf.post(hostname, section, key, value) | |
end | |
else | |
gf.post(hostname, section, key, value) | |
end | |
end |
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
#!/opt/sensu/embedded/bin/ruby | |
require 'rubygems' | |
require 'json' | |
################### | |
# Read event data # | |
################### | |
event = JSON.parse(STDIN.read, :symbolize_names => true) | |
event_output = event[:check][:output] | |
################ | |
# Modification # | |
################ | |
# "\\n" -> "\n" | |
event_output = event_output.gsub("\\n", "\n") | |
# Rounding the value | |
tmp_output = [] | |
event_output.split("\n").each do |line| | |
title, value, time = line.split(" ") | |
if /load_avg/ =~ title | |
value = value.to_f * 100 | |
else | |
value = value.to_f | |
end | |
value = value.round | |
tmp_output << "#{title} #{value} #{time}" | |
end | |
event_output = tmp_output.join("\n") | |
# omit unnecessary double line feeds: | |
event_output = event_output.gsub(/\n\n/, "") | |
##################################### | |
# For disk_usage or interface_usage # | |
##################################### | |
# disk_usage.root.used_percentage -> disk_usage.root_used_percentage | |
if /(disk_usage|interface)/ =~ event_output | |
event_output = event_output.gsub(/(disk_usage|interface)\.([^\.]+)\./, '\1.\2_') | |
end | |
#################### | |
# Write event data # | |
##################### | |
event[:check][:output] = event_output | |
puts event.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment