Nagios Perl Script to add Hosts and Escalations
A couple of perl scripts to help add Hosts and Host Escalations into Nagios config files.
DIRECTIONS: Edit .list file for script to read
FOR: addHost.pl edit host.list to include tab seperated parameter (5)options
use host_name alias address host_groups
FOR: addEscalation.pl edit Escalation.list to include tab seperated parameter (2)options
host_name contact_groups
Here is addHost.pl script
#!/usr/bin/perl
#
#
# Usage: Perl script to add hosts for Nagios monigoing
# Written by: brandon.w.thompson
#
#use strict;
my $ugly_file = shift;
if(!defined $ugly_file){
print "Usage: $0 >> file.cfg>\n";
exit;
}
our @ARGV = ("use", "host_name", "alias", "address", "hostgroups", "contact_groups");
open(FILE, $ugly_file);
while(){
chomp;
# if (/!! Start !!/ .. /!! End !!/) { #Uncomment this line to process certain part of file#
# if (1..10); #Uncomment this line to process certain concecutive lines#
($field1, $field2, $field3, $field4, $field5, $field6)=split("\t");
print "define host{\n\t$ARGV[0]\t\t$field1\n\t$ARGV[1]\t$field2\n\t$ARGV[2]\t\t$field3\n\t$ARGV[3]\t\t$field4\n\t$ARGV[4]\t$field5\n\t$ARGV[5]\t$field6\n}\n";
# }
}
close(FILE);
exit;
Here is addHostescalation.pl script
#!/usr/bin/perl
#
#
# Usage: Perl script to add hosts for Nagios monigoing
# Written by: brandon.w.thompson
#
my $ugly_file = shift;
if(!defined $ugly_file){
print "Usage: $0 >> \n";
exit;
}
our @ARGV = ("host_name", "first_notification", "last_notification", "notification_interval", "contact_groups");
open(FILE, $ugly_file);
while(){
chomp;
# if (/!! Start !!/ .. /!! End !!/) { #Uncomment this line to process certain part of file#
# if (1..10); #Uncomment this line to process certain concecutive lines#
($field1, $field2)=split("\t");
print "define hostescalation{\n\t$ARGV[0]\t\t$field1\n\t$ARGV[1]\t2\n\t$ARGV[2]\t0\n\t$ARGV[3]\t10\n\t$ARGV[4]\t\t$field2\n}\n\n";
# }
}
close(FILE);
exit;
September 4, 2009 at 10:29 am
This script was extremely helpful. I did find, however, that there were a few things missing. I wanted to make you aware and have listed only the updated lines below. I used the variable $line.
while($line = ){
($field1, $field2, $field3, $field4, $field5, $field6)=split(“\t” , $line);
Thanks again for making this script available.
T.
September 4, 2009 at 10:31 am
First line should have been…..
while($line = ){
my bad.