38. begin
JSON.parse(RestClient.get(url)).each do |cache|
data["#{cache['target']}"] = 0
count = 0
cache["datapoints"].each do |point|
unless (point[0].nil?)
data["#{cache['target']}"] += point[0]
count += 1
end
end
data["#{cache['target']}"] /= count
data["total"] += data["#{cache['target']}"]
end
rescue ZeroDivisionError => e
puts "UNKNOWN metric not in graphite!"
exit EXIT_UNKNOWN
rescue => e
puts e.message
exit EXIT_CRITICAL
end
Friday, August 23, 13
39. begin
JSON.parse(RestClient.get(url)).each do |cache|
data["#{cache['target']}"] = 0
count = 0
cache["datapoints"].each do |point|
unless (point[0].nil?)
data["#{cache['target']}"] += point[0]
count += 1
end
end
data["#{cache['target']}"] /= count
data["total"] += data["#{cache['target']}"]
end
rescue ZeroDivisionError => e
puts "UNKNOWN metric not in graphite!"
exit EXIT_UNKNOWN
rescue => e
puts e.message
exit EXIT_CRITICAL
end
Friday, August 23, 13
57. # Seed the initial file with false, and enable
# on next run with gh-nagios enable_pager <hostname>
file { '/etc/facter/facts.d/enable_pager.txt':
ensure => file,
owner
=> 'root',
group
=> 'root',
mode
=> '0644',
content => 'enable_pager=false',
replace => false,
}
Friday, August 23, 13
72. # autoloader.pp
class nagios::autoload_helpers {
$helpers = get_nagios_helpers()
case $::puppetversion {
/^3/: { include $helpers }
default: {
nagios::autoload_helpers::import_shim { $helpers: }
}
}
}
Friday, August 23, 13
73. # autoloader.pp
class nagios::autoload_helpers {
$helpers = get_nagios_helpers()
case $::puppetversion {
/^3/: { include $helpers }
default: {
nagios::autoload_helpers::import_shim { $helpers: }
}
}
}
Friday, August 23, 13
74. module Puppet::Parser::Functions
newfunction(:get_nagios_helpers,
:type => :rvalue,
:doc => "Grab all modules that have nagios helpers for
import") do
module_path = File.expand_path('..',
Puppet::Module.find('nagios',compiler.environment.to_s).path)
helpers = Dir["#{module_path}/**/nagios/helpers.pp"].map do |d|
"#{d.split('/')[-4]}::nagios::helpers"
done
helpers
end
end
Friday, August 23, 13
80. # Seed the initial file with false, and enable
# on next run with gh-nagios enable_pager <hostname>
file { '/etc/facter/facts.d/enable_pager.txt':
ensure => file,
owner
=> 'root',
group
=> 'root',
mode
=> '0644',
content => 'enable_pager=false',
replace => false,
}
Friday, August 23, 13
81. if $::enable_pager {
@@file { "/etc/nagios/objects/${type}.d/${filename}.cfg":
content => template('nagios/etc/nagios/object.erb'),
mode
=> '0444',
group
=> 'nagios',
notify => Service['nagios'],
}
}
Friday, August 23, 13