At some point in the last few weeks, I repeatedly had to recreate my Nagios config for currently six filers. After doing that a few times, I ended up (like sooo often) writing a short Bash script, that’ll do this for me - without any fuss.
The only thing the script needs, is that the filers and the filers are registered in DNS … Here’s an example:
1
2
3
4
| fas3240a IN A 172.31.76.150
fas3240a-sp IN A 172.31.74.150
fas3240b IN A 172.31.76.151
fas3240b-sp IN A 172.31.74.151
|
With that done, the script will create the necessary Nagios config for those filers.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| #!/bin/bash -f
#set -x
for host in $@; do
echo "define host{" | tee /etc/nagios/objects/hosts/san/$host.cfg
echo -e "thost_namettt$host" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo -e "tusettttgeneric-host-perfdata" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo "" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo -e "taddresstttt$( dig +short $host.home.barfoo.org )" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo -e "taliastttt$host.home.barfoo.org" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo -e "tdisplay_namettt$host.home.barfoo.org" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo -e "thostgroupstttnetapp-fas-fc" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo -e "t_DOTSPtt$( dig +short $host-sp.home.barfoo.org )" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo "}" | tee -a /etc/nagios/objects/hosts/san/$host.cfg
echo | tee -a /etc/nagios/objects/hosts/san/$host.cfg
done
#set +x
|