Skip to content

Instantly share code, notes, and snippets.

@octplane
Created August 11, 2011 12:30
Show Gist options
  • Select an option

  • Save octplane/1139530 to your computer and use it in GitHub Desktop.

Select an option

Save octplane/1139530 to your computer and use it in GitHub Desktop.
Declare default values for monitored jobs and some default usual tests.
module DefaultMonitoredValues
# Handle defaults to prevent cluttering the chef registry with these things
def DefaultMonitoredValues.value_or(hash, key, or_value)
if hash.has_key?(key)
hash[key]
else
or_value
end
end
def DefaultMonitoredValues.passive(service)
value_or(service, 'passive', false)
end
def DefaultMonitoredValues.check_command(service)
begin
(service['check_command'].
is_a?(Hash)?service['check_command']['nagios']:
service['check_command']).to_a.map{|i| i.to_s}.join("!")
rescue Exception=>e
Chef::Log.error("Unable to build command for service:#{service.inspect}")
raise e
end
end
def DefaultMonitoredValues.check_on(service)
value_or(service, 'check_on', ['infrabox', 'testing', 'staging', 'prod'])
end
def DefaultMonitoredValues.notification_period(service)
value_or(service, 'notification_period', {'prod' => "24x7", 'testing' => 'workhours', 'staging' => 'workhours', 'infrabox' => "never"})
end
def DefaultMonitoredValues.retry_interval(service)
value_or(service, 'retry_interval', 1)
end
def DefaultMonitoredValues.normal_check_interval(service)
value_or(service, 'normal_check_interval', 5)
end
def DefaultMonitoredValues.depends(service)
value_or(service, 'depends' [])
end
def DefaultMonitoredValues.infrabox_check(service)
value_or(service, 'infrabox_check', true)
end
def DefaultMonitoredValues.max_check_attempts(service)
value_or(service, 'max_check_attempts', 3)
end
def DefaultMonitoredValues.normal_check_interval(service)
value_or(service, 'normal_check_interval', 5)
end
end
# Define aliase between the command passed in monitored and:
# - the command used in nagios configuration (key nagios)
# - the command used to run the test in command line (key cli)
def ssh
{'nagios' => ['check_ssh'],
'cli' => ['check_ssh', node[:fqdn]]
}
end
def nrpe(*args)
if args.length > 1
{'nagios' => ['check_nrpe_2args', args[0], args[1]],
'cli' => ['check_nrpe', '-H' + node[:fqdn], '-c', args[0], '-a', args[1]]
}
else
{'nagios' => ['check_nrpe_1arg', args[0]],
'cli' => ['check_nrpe', '-H' + node[:fqdn], '-c', args[0]]
}
end
end
def process(name, args)
nrpe('check_process', "#{name} #{args}")
end
def check_http(*args)
{'nagios' => ['check_http_args', args.join(" ")],
'cli' => ['check_http', '-I '+node[:fqdn], args]
}
end
def check_tcp(*args)
{'nagios' => ['check_tcp_args', args.join(" ")],
'cli' => ['check_tcp','-H '+node[:fqdn],args]
}
end
def check_github()
{'nagios' => ['check_github'],
'cli' => ['/usr/local/nagios/libexec/check_github.rb']
}
end
def check_features()
{'nagios' => ['check_features'],
'cli' => ['/usr/local/nagios/libexec/check_features']
}
end
def check_mysql_slow()
{ 'nagios' => ['check_mysql_slow'],
'cli' => ['/usr/lib/nagios/plugins/check_slow.rb']
}
end
def check_cluster_state()
{ 'nagios' => ['check_cluster_state'],
'cli' => ['/ftn/apps/hamr/check_cluster_state.rb']
}
end
def check_chef_expander
{ 'nagios' => ['check_chef_expander'],
'cli' => ["/usr/local/bin/chef-ruby.sh /mnt/gems-chef-#{CHEF_PACKAGE_VERSION}/gems/chef-expander-0.10.0/scripts/check_queue_size", " -w 250 -c 500"]
}
end
def check_nagios3
{ 'nagios' => ['check_procs_args','-a "sbin/[n]agios3" -c1:1'],
'cli' => ['/usr/lib/nagios/plugins/check_procs', '-a "sbin/[n]agios3" -c1:1']
}
end
def check_nsca
{ 'nagios' => ['check_procs_args','-a "sbin/[n]sca" -c1:1'],
'cli' => ['/usr/lib/nagios/plugins/check_procs', '-a "sbin/[n]sca" -c1:1']
}
end
def check_mongo_replica_member(port)
{ 'nagios' => ['check_mongo_replica_member', port.to_s],
'cli' => [ '/usr/lib/nagios/plugins/check_mongo_replica_member', node[:ipaddress], port.to_s]
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment