Code: Select all
/usr/local/nagiosxi/scripts/reconfigure_nagios.shCode: Select all
/usr/local/nagiosxi/scripts/reconfigure_nagios.shCode: Select all
HOST=xxxxxxxx #This is the FTP servers host or IP address.
USER=xxxxxx #This is the FTP user that has access to the server.
PASS=xxxxxx #This is the password for the FTP user.
ftp -inv $HOST << EOF
user $USER $PASS
cd /nagiosftp
get primaryOnCall.txt
get secondaryOnCall.txt
delete primaryOnCall.txt
delete secondaryOnCall.txt
bye
EOF
Code: Select all
#!/usr/bin/perl
#Process primary on-call file
open (INFILE, 'primaryOnCall.txt') or die $1;
while (<INFILE>) {
chomp;
($group, $alias, $id) = split(",");
if ($alias ne '') {
open (OUTFILE, '>/usr/local/nagios/etc/static/' . $alias . '_oncall_pri.cfg');
print OUTFILE "define contactgroup{\n";
print OUTFILE "contactgroup_name $alias" . "_oncall_pri\n";
print OUTFILE "alias $group\n";
print OUTFILE "members $id\n";
print OUTFILE "}";
close (OUTFILE);
}
}
close (INFILE);
#Process secondary on-call file
open (INFILE, 'secondaryOnCall.txt') or die $1;
while (<INFILE>) {
chomp;
($group, $alias, $id) = split(",");
if ($alias ne '') {
open (OUTFILE, '>/usr/local/nagios/etc/static/' . $alias . '_oncall_sec.cfg');
print OUTFILE "define contactgroup{\n";
print OUTFILE "contactgroup_name $alias" . "_oncall_sec\n";
print OUTFILE "alias $group\n";
print OUTFILE "members $id\n";
print OUTFILE "}";
close (OUTFILE);
}
}
close (INFILE);
#Chane ownership and permissions of config files
system ("sudo /bin/chown apache:nagios /usr/local/nagios/etc/static/*.cfg");
system ("sudo /bin/chmod 775 /usr/local/nagios/etc/static/*.cfg");
#Delete data files
system ("rm primaryOnCall.txt");
system ("rm secondaryOnCall.txt");
#Restart Nagios
sudo su -l nagios -c 'cd /usr/local/nagiosxi/scripts/ && ./reconfigure_nagios.sh'
#Exit clean
exit 0;