Notification of a NEW host
Notification of a NEW host
Is it possible to have it set so that when a new host is added, that a notification gets sent to a person (or people)?
The reason for this is that I have 4 other Admins that also add systems to Nagios and some of them always mess something up.
If I can get notified when a new system is added, I can go in and make sure its done right.
The reason for this is that I have 4 other Admins that also add systems to Nagios and some of them always mess something up.
If I can get notified when a new system is added, I can go in and make sure its done right.
Everybody is somebody else’s weirdo
-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Notification of a NEW host
Use this and count the number of *cfg files in /usr/local/nagios/etc/hosts/ maybe?
Re: Notification of a NEW host
that might work, put i get an error when trying to run it
Code: Select all
]# ./check_files.pl
Can't locate Date/Parse.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./check_files.pl line 159.
BEGIN failed--compilation aborted at ./check_files.pl line 159.
Everybody is somebody else’s weirdo
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Notification of a NEW host
Code: Select all
yum -y install perl-TimeDateAs of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Notification of a NEW host
Or use this quick script I just wrote since I loved your idea and suffer same thing here!!!!
I'm not in the office to test this, but pretty darn sure it is bug free 
EDIT #1: Wait, dont use it yet, have to update it to write the new count to the file
EDIT #2: Ok, fixed. You'll have to set max checks to 1 as when it detects and exits with a warning, it'll return to OK on the very next check.
EDIT #3: Connected to work and fixed the bug I had in it, lol
EDIT #4: Added code correction in following post.
Code: Select all
#!/bin/bash
#
# Check for new hosts
# by Jim Clark / banditbbs @ gmail . com
#
# Get current count of host files
current_count=$(ls /usr/local/nagios/etc/hosts | wc -l)
# Check for this script running before and if not create dummy file
if [ ! -f /usr/local/nagios/libexec/hostcount ]; then
echo "1" > "/usr/local/nagios/libexec/hostcount"
fi
# Read old count file
old_count=$(head -n 1 /usr/local/nagios/libexec/hostcount)
# Compare counts
if [ "$old_count" -lt "$current_count" ];then
echo "Warning - New host has been added!"
echo $current_count > "/usr/local/nagios/libexec/hostcount"
exit 1
fi
echo "OK - No new hosts added"
echo $current_count > "/usr/local/nagios/libexec/hostcount"
exit 0
EDIT #1: Wait, dont use it yet, have to update it to write the new count to the file
EDIT #2: Ok, fixed. You'll have to set max checks to 1 as when it detects and exits with a warning, it'll return to OK on the very next check.
EDIT #3: Connected to work and fixed the bug I had in it, lol
EDIT #4: Added code correction in following post.
Last edited by BanditBBS on Wed Apr 22, 2015 7:58 am, edited 1 time in total.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
Re: Notification of a NEW host
Need to account for the case when hosts are deleted. I'm fairly certain XI deletes the old host files when hosts are deleted. If you were to delete 5 hosts you will not get an alert until a 6th new host is added.
if you change
it would solve this issue. My initial though was to query the database directly for a count of hosts and trigger off that but not knowing the table structure or MySQL or how to access this in a script this way was probably out of reach for me.
if you change
Code: Select all
echo "OK - No new hosts added"
exit 0Code: Select all
echo "OK - No new hosts added"
echo $current_count > "/usr/local/nagios/libexec/hostcount"
exit 0Grumpy Olde IT Guy
Re: Notification of a NEW host
Yeah good catch on that. I'll modify my original post once I get to work. The only time this won't catch one is if somebody deletes and adds all within the same apply config!
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
Re: Notification of a NEW host
Code: Select all
yum -y install perl-TimeDateBanditBBS;
Your script works great as well. Thank you.
I will try to get it to check for deleted hosts as well.
Everybody is somebody else’s weirdo
Re: Notification of a NEW host
Also, even a better idea would be to write a plugin to search the audit log for "New host inserted:" and display any outputs. it would have the new hostname after the : as well. I have no clue which DB the audit log is kept in. if someone in nagios wants to tell me the DB and table I'll attempt to write the plugin.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
Re: Notification of a NEW host
ok, i added some lines to notify when a host has been deleted
If you were able to include the name, that would be awesome.
The part I added is
Dont forget to set permissions on the hostcount file so that Nagios can write to it
If you were able to include the name, that would be awesome.
Code: Select all
#!/bin/bash
#
# Check for new hosts
# by Jim Clark / banditbbs @ gmail . com
#
# Get current count of host files
current_count=$(ls /usr/local/nagios/etc/hosts | wc -l)
# Check for this script running before and if not create dummy file
if [ ! -f /usr/local/nagios/libexec/hostcount ]; then
echo "1" > "/usr/local/nagios/libexec/hostcount"
fi
# Read old count file
old_count=$(head -n 1 /usr/local/nagios/libexec/hostcount)
# Compare counts
if [ "$old_count" -lt "$current_count" ];then
echo "Warning - New host has been added!"
echo $current_count > "/usr/local/nagios/libexec/hostcount"
exit 1
fi
if [ "$old_count" -gt "$current_count" ];then
echo "Warning - Host has been Nuked!"
echo $current_count > "/usr/local/nagios/libexec/hostcount"
exit 1
fi
echo "OK - No new hosts added"
echo $current_count > "/usr/local/nagios/libexec/hostcount"
exit 0Code: Select all
if [ "$old_count" -gt "$current_count" ];then
echo "Warning - Host has been Nuked!"
echo $current_count > "/usr/local/nagios/libexec/hostcount"
exit 1
fiDont forget to set permissions on the hostcount file so that Nagios can write to it
Everybody is somebody else’s weirdo