X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=config%2Fbuild-nagios;h=1eb3977d4adb88dec9300b3b5073538451b699c0;hb=66345b47d03f1be6b9c1f3dec9df1f9c6c2f9748;hp=6395e803283232d86f3d031c383422f5c7392919;hpb=c52cf8d1190f744101fe52aa0e66c299b6bc0014;p=mirror%2Fdsa-nagios.git diff --git a/config/build-nagios b/config/build-nagios index 6395e80..1eb3977 100755 --- a/config/build-nagios +++ b/config/build-nagios @@ -2,7 +2,7 @@ # build nagios and nrpe config from a single master config file -# Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009 Peter Palfrader +# Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Peter Palfrader # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -127,11 +127,13 @@ $nrpe = Nrpe.new() # host/service/etc definitions # # It skips over such keys as are listed in exclude_keys -# and also skips private keys (those starting with an underscre) +# and also skips private keys (those starting with an underscore) def print_block(fd, kind, hash, exclude_keys) fd.puts "define #{kind} {" hash.each_pair{ |key, value| - next if key[0,1] == '_' + next if key == '_extinfo' + next if key == '_hostgroups' + next if key == '_memberlist' next if exclude_keys.include? key fd.puts " #{key} #{value}" } @@ -239,9 +241,9 @@ def find_hosts(service, servers, hostgroups) hosts = merge_hosts_and_hostgroups service, servers, hostgroups, '' excludehosts = merge_hosts_and_hostgroups service, servers, hostgroups, 'exclude' - excludehosts.each{ |host| + excludehosts.uniq.each{ |host| if hosts.delete(host) == nil - throw "Cannot remove host #{host} from service #{service['service_description']}: it's not included anyway or excluded twice." + puts "info: [service #{service['service_description']}] not excluding host #{host} - it's not included anyway." end } @@ -358,6 +360,7 @@ config['servers'].each_pair{ |name, server| ############## config['hostgroups'].each_pair{ |name, hg| next if hg['private'] + throw "Empty hostgroup #{name}" if hg['_memberlist'].length == 0 set_complain_if_set hg, 'hostgroup_name', name , 'Hostgroup', name set_complain_if_set hg, 'members' , hg['_memberlist'].join(","), 'Hostgroup', name @@ -413,10 +416,12 @@ config['services'].each{ |service| # how to recursively copy this thing? hostservice = YAML::load( service.to_yaml ) host_ip = config['servers'][host]['address'] - throw "For some reason I do not have an address for #{host}. This shouldn't be." unless host_ip remotecheck = hostservice['remotecheck'] - remotecheck.gsub!(/\$HOSTADDRESS\$/, host_ip) + if remotecheck.include?('$HOSTADDRESS$') and not host_ip + throw "For some reason I do not have an address for #{host} yet I need it for the remote check. This shouldn't be." + end + remotecheck.gsub!(/\$HOSTADDRESS\$/, host_ip) if host_ip remotecheck.gsub!(/\$HOSTNAME\$/, host) check = $nrpe.add("#{host}_#{hostservice['service_description']}", remotecheck) hostservice['check_command'] = "#{NRPE_CHECKNAME_HOST}!#{ config['servers'][ relay ]['address'] }!#{ check }"