我有一个供应系统设置新的主机在域test.domain.local,即client44.test.domain.local
,我有一个Icinga服务器,我想自动监视所有这些主机使用正则expression式,如*.test.domain.local
。
所有的客户端都会得到nagios-nrpe-server
(version。2.13-3)包,它也被configuration为允许icinga服务器从它们中获取数据,并且已经被证实是可行的。
我们只是现在要监视服务/我们知道所有节点将会有的东西,例如SSH,响应ping等。
我已经看过这个链接,但我不太了解主机,主机组和服务类之间的关系?
Icinga服务器和所有客户端都运行Debian。
在这个问题上,我一直和fredmu一起工作,并提出了一个由Tim Brigham的答案启发的工作解决scheme。
使用默认的generic-host
定义,这可以使用基于模板自动生成主机configuration文件的脚本来解决。 可以select将其作为cronjob来按常规生成这些文件。
generate_host_cfg.sh
#!/usr/bin/env bash icinga_root="/etc/icinga/objects" subnet="10.0.0.*" template="template_icinga.cfg" alias_file="alias.txt" # navigate to the Icinga configuration directory cd $icinga_root # create first server alias if doesn't exist if [ ! -e $alias_file ]; then echo "1" > $alias_file fi # iterate through subnet, store "hostname:ip" in associative array declare -A address for host in $(nmap -sP $subnet | awk -F '[ ()]' '/for [az]+/ {print $5 ":" $7}'); do address[$(echo $host | cut -d: -f1)]=$(echo $host | cut -d: -f2) done # iterate through hosts, create files if not exist based off template for host in ${!address[@]}; do host_file=${host}_icinga.cfg if [ ! -e $host_file ]; then # fetch new server alias alias=$(cat $alias_file) # create the next server alias expr $alias + 1 > $alias_file # create hostname_icinga.cfg if doesn't exist, based off template cp $template $host_file # replace contents of new template; hostname, alias and ip sed -i -r \ -e "s/tmp-hostname/$host/" \ -e "s/tmp-alias/Server$alias/" \ -e "s/tmp-address/${address[$host]}/" $host_file fi done
template_icinga.cfg
define host{ use generic-host host_name tmp-hostname alias tmp-alias address tmp-address }
导致像这样的文件:
define host{ use generic-host host_name monitor.company.local alias Server1 address 10.0.0.1 }
有很多方法来解决这个问题。
我以前组装过的bash脚本将作为一个单一的icinga检查运行。 然后,脚本将检查子域中的所有主机,并根据是否发现多less故障来返回状态。
最近我已经成为傀儡自定义事实的粉丝。 结合writeb模板,您可以使用for循环轻松地将检查添加到大量节点中。