summaryrefslogtreecommitdiff
path: root/build-nagios
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2008-07-11 16:03:38 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2008-07-11 16:03:38 +0000
commit41e0cbd2f0860f062343ae3ef941f6bc9bc558fa (patch)
tree4e23ff672498e1e6277b5652a60e6c6e0ff66d73 /build-nagios
parent048dd0f19fa9140d73da53301fe88864bc90905c (diff)
Servicegroups
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@361 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'build-nagios')
-rwxr-xr-xbuild-nagios59
1 files changed, 42 insertions, 17 deletions
diff --git a/build-nagios b/build-nagios
index a614871..08fb32b 100755
--- a/build-nagios
+++ b/build-nagios
@@ -1,16 +1,15 @@
#!/usr/bin/ruby
-# Copyright (c) 2004, 2005, 2006, 2007 Peter Palfrader <peter@palfrader.org>
+# Copyright (c) 2004, 2005, 2006, 2007, 2008 Peter Palfrader <peter@palfrader.org>
require "yaml"
ORG="relativity"
SHORTORG="rela"
-CONTACTGROUP="weaselgroup"
GENERATED_PREFIX="/etc/NOREPLY/generated/nagios/"
nagios_filename = {};
-%w(hosts hostgroups services dependencies hostextinfo serviceextinfo).each{
+%w(hosts hostgroups services dependencies hostextinfo serviceextinfo servicegroups).each{
|x| nagios_filename[x] = GENERATED_PREFIX+"auto-#{x}.cfg"
}
nagios_filename['nrpe'] = GENERATED_PREFIX+"nrpe_#{ ORG }.cfg"
@@ -121,10 +120,9 @@ end
# Add the service definition service to hosts
# f is the file for service definitions, deps the file for dependencies
-def addService(hosts, service, files)
+def addService(hosts, service, files, servers)
set_if_unset service, 'use' , SERVICE_TEMPLATE_NAME
- set_complain_if_set service, 'host_name' , hosts.join(',') , 'Service', service['service_description']
set_if_unset service, 'max_check_attempts', MAX_CHECK_ATTEMPTS_DEFAULT
service['max_check_attempts'] = MAX_CHECK_ATTEMPTS_DEFAULT + service['max_check_attempts'] if service['max_check_attempts'] < 0
@@ -140,9 +138,17 @@ def addService(hosts, service, files)
service['depends'] << NRPE_PROCESS_SERVICE unless service['service_description'] == NRPE_PROCESS_SERVICE # Depend on NRPE unless we are it
end
- print_block files['services'], 'service', service, %w(nrpe runfrom remotecheck
- depends
- hosts hostgroups excludehosts excludehostgroups)
+ hosts.each{ |host|
+ s = service.clone
+ set_complain_if_set s, 'host_name', host, 'Service', s['service_description']
+ %w{contacts contact_groups}.each{ |k|
+ set_if_unset(s, k, servers[host][k]) if servers[host].has_key? k
+ }
+
+ print_block files['services'], 'service', s, %w(nrpe runfrom remotecheck
+ depends
+ hosts hostgroups excludehosts excludehostgroups)
+ }
if service['depends']
service['depends'].each{ |prerequisite|
@@ -245,8 +251,10 @@ nagios_filename.each_pair{ |name, filename|
# create the "all" and "pingable" hostgroups
config['hostgroups']['all'] = {}
config['hostgroups']['all']['alias'] = "all servers"
+config['hostgroups']['all']['private'] = true
config['hostgroups']['pingable'] = {}
config['hostgroups']['pingable']['alias'] = "pingable servers"
+config['hostgroups']['pingable']['private'] = true
config['hostgroups'].each_pair{ |name, hg|
throw "Empty hostgroup or hostgroup #{name} not a hash" unless hg.kind_of?(Hash)
@@ -271,6 +279,8 @@ config['servers'].each_pair{ |name, server|
};
}
+config['servicegroups'] = {} unless config.has_key? 'servicegroups'
+
##############
# HOSTS
##############
@@ -293,12 +303,17 @@ config['servers'].each_pair{ |name, server|
# Handle hostextinfo
- config['hostgroups'][ server['_hostgroups'].first ]['_extinfo'].each_pair{ |k, v|
- # substitute hostname into the notes_url
- v = sprintf(v,name) if k == 'notes_url'
-
- set_if_unset server['_extinfo'], k ,v
- }
+ #config['hostgroups'][ server['_hostgroups'].first ]['_extinfo'].each_pair{ |k, v|
+ # find the first hostgroup that has extinfo
+ extinfo = server['_hostgroups'].collect{ |hgname | config['hostgroups'][hgname]['_extinfo'] }.delete_if{ |ei| ei.size == 0 }.first
+ if extinfo then
+ extinfo.each_pair do |k, v|
+ # substitute hostname into the notes_url
+ v = sprintf(v,name) if k == 'notes_url'
+
+ set_if_unset server['_extinfo'], k ,v
+ end
+ end
set_complain_if_set server['_extinfo'], 'host_name' , name, 'hostextinfo', name
set_if_unset server['_extinfo'], 'vrml_image' , server['_extinfo']['icon_image'] if server['_extinfo'].has_key?('icon_image')
@@ -317,7 +332,6 @@ config['hostgroups'].each_pair{ |name, hg|
set_complain_if_set hg, 'hostgroup_name', name , 'Hostgroup', name
set_complain_if_set hg, 'members' , hg['_memberlist'].join(","), 'Hostgroup', name
- set_if_unset hg, 'contact_groups', CONTACTGROUP
print_block files['hostgroups'], 'hostgroup', hg, %w()
}
@@ -381,17 +395,28 @@ config['services'].each{ |service|
# And append this new dependency
hostservice['depends'] << "#{ relay }:#{ NRPE_PROCESS_SERVICE }";
- addService( [ host ], hostservice, files)
+ addService( [ host ], hostservice, files, config['servers'])
}
elsif service['runfrom'] || service['remotecheck']
throw "runfrom and remotecheck must either appear both or not at all in service #{service['service_description']}"
throw "must not remotecheck without runfrom" if service['remotecheck']
else
- addService(hosts, service, files)
+ addService(hosts, service, files, config['servers'])
end
}
+
+##############
+# SERVICEGROUPS
+##############
+config['servicegroups'].each_pair{ |name, sg|
+ set_complain_if_set sg, 'servicegroup_name', name , 'Servicegroup', name
+
+ print_block files['servicegroups'], 'servicegroup', sg, %w()
+}
+
+
##############
# NRPE config file
##############