Page 2 of 3

Re: Adding a simple host to monitor Up / Down state

Posted: Wed Mar 16, 2016 1:23 pm
by VincentF
rkennedy wrote:Sounds good - let us know if you need any further assistance!
Thanks so much.

I just wish there was a clearer way to have what I had outlined that can be put into use. :cry:

Re: Adding a simple host to monitor Up / Down state

Posted: Wed Mar 16, 2016 1:28 pm
by rkennedy
From what I understand, you just want a host check using ping only - is that right?

To help you better understand, I wrote this post out on Monday. It gives a pretty good explanation on how things correlate (although not related to what you're asking, it may help understand core a bit more). https://support.nagios.com/forum/viewto ... 30#p175559

Re: Adding a simple host to monitor Up / Down state

Posted: Wed Mar 16, 2016 1:38 pm
by VincentF
rkennedy wrote:From what I understand, you just want a host check using ping only - is that right?

To help you better understand, I wrote this post out on Monday. It gives a pretty good explanation on how things correlate (although not related to what you're asking, it may help understand core a bit more). https://support.nagios.com/forum/viewto ... 30#p175559

Here is the exact scenario. I have gotten all the way up to the normal Nagios web and it's all about configuring it to do exactly what I want.

Right now, there is one workstation per site and I have about 1200 sites. As of right now, there is nothing that is monitoring the workstations as to when they go down and when they come up. In some cases its related to power and in other cases it could be that the LAN / WAN link to the location is down. Regardless of WHY it went down, I just need to know that the site is down, when was the last known uptime, and - if it came back up - when did it come back up. My thoughts is that ALL THIS can be done with a simple ping to all workstations and let Nagios do the rest.

The frequency by which it checks and all that can be sorted out later, but thats ALL that i'm looking for. The one advatage i DO have is that I have an ID and IP address for EACH location saved in a .csv file and would LOVE to have it just pull the info from there. But, of course, that is WAYYYYYYY out of my leauge... :oops:

Re: Adding a simple host to monitor Up / Down state

Posted: Wed Mar 16, 2016 2:40 pm
by eloyd
Nagios likes to be statically defined for each host so it can maintain history information, rather than dynamically choosing things from a list to check. Honestly, if you have some script-writing-fu or someone around you has some Excel variable concatination-fu, you could write something that simply exports that Excel data as a CSV file, and import it into your script and have the script create a giant hosts definition file for you.

In fact, if you PM me the CSV file with IP addresses and names of machines, I'd be happy to do it for you if you remember to vote for me for a Nagios MVP award when the time comes. :-)

Re: Adding a simple host to monitor Up / Down state

Posted: Wed Mar 16, 2016 3:04 pm
by rkennedy
@eloyd - beat you to it. Recycling an old script here :)

I had created a bash script to create 100k config files before. I've altered it slightly for your needs. Keep in mind, you may need to make more changes to this based on your environment. This should work though, to help you automate creating the 1200 host checks your looking for.

Create a folder, /usr/local/nagios/etc/genconfigs/

Then, in it, create genconfigs.sh - put the following:

Code: Select all

#!/bin/sh
COUNTER=1

while [ $COUNTER -lt 5001 ]
do

DOMAIN=$(sed "${COUNTER}q;d" domains.txt)

echo "define host {" > $DOMAIN.cfg
echo "        use                             linux-server" >> $DOMAIN.cfg
echo "        host_name                       $DOMAIN" >> $DOMAIN.cfg
echo "        alias                           $DOMAIN Alias Monitoring" >> $DOMAIN.cfg
echo "        address                         $DOMAIN" >> $DOMAIN.cfg
echo "        max_check_attempts              5" >> $DOMAIN.cfg
echo "        check_period                    24x7" >> $DOMAIN.cfg
echo "        notification_interval           30" >> $DOMAIN.cfg
echo "        notification_period             24x7" >> $DOMAIN.cfg
echo "        contact_groups                  admins" >> $DOMAIN.cfg
echo "}" >> $DOMAIN.cfg

echo $COUNTER
COUNTER=$(( $COUNTER + 1 ))
done
I changed the count to stop at 5001, if you have more lines then that in your txt file please change this accordingly.

Make genconfigs.sh executable, chmod +x genconfigs.sh

Now in that same folder, /usr/local/nagios/etc/genconfigs/ - create domains.txt from your CSV. A sample is below -

Code: Select all

google.com
yahoo.com
bing.com
Let's create the configuration files. Run ./genconfigs.sh

Now that they're created, lets tell Nagios to look in that directory for configuration files. Add this line to /usr/local/nagios/etc/nagios.cfg -

Code: Select all

cfg_dir=/usr/local/nagios/etc/genconfigs
Now, if everything worked out properly, restart the nagios service and your whole list of ips/domains from domains.txt should now be checking. service nagios restart

Re: Adding a simple host to monitor Up / Down state

Posted: Thu Mar 17, 2016 6:16 am
by VincentF
eloyd wrote:Nagios likes to be statically defined for each host so it can maintain history information, rather than dynamically choosing things from a list to check. Honestly, if you have some script-writing-fu or someone around you has some Excel variable concatination-fu, you could write something that simply exports that Excel data as a CSV file, and import it into your script and have the script create a giant hosts definition file for you.

In fact, if you PM me the CSV file with IP addresses and names of machines, I'd be happy to do it for you if you remember to vote for me for a Nagios MVP award when the time comes. :-)
eLoyd - I think you've already have earned that title :D

I'll PM you the excel sheet - but really - do NOT go crazy because - remember - i have much learning to do to get to where I need to be with Linux & Nagios. Like i've said so many times before - I must be CRAZY trying to learn BOTH at the same time all while trying to use it in a production environment. But, the way I see it - the best way to learn ANYTHING is by NOT understanding something then trying to figure it out. Any how - here goes nothing!

Re: Adding a simple host to monitor Up / Down state

Posted: Thu Mar 17, 2016 6:44 am
by nozlaf
couldn't read this without a few comments

first of all, be careful in district 9 because I hear the prawns are really quite bad and District 13 should have been eliminated already
also district 12 has the potential to cause you problems in the future may be a good idea to eliminate it before it causes you grief



on a more serious note adding the hosts as you suggested is going to obviously yield a great result but you should also consider once you have done this to add your network equipment into the mix


because Nagios supports parent / child relationships for hosts it will be smart enough realise that you cant access District 13 because the router wont respond and it wont alert you about all the hosts behind the district 13 router




for Panem

Re: Adding a simple host to monitor Up / Down state

Posted: Thu Mar 17, 2016 6:53 am
by VincentF
Totally true.

Understand though that - as i've said many many times before - I am completely new to Linux / Ubuntu & Nagios. Short of hiring someone - which we cannot do - i am trying to be as proactive and doing this on my own. Of course, me being the Cisco guru that I am, i have enough of a networking background that I can try and wing it.

Meh...i'll do my best...

Re: Adding a simple host to monitor Up / Down state

Posted: Thu Mar 17, 2016 7:45 am
by eloyd
If all you want to know is if things are up or down, then you're good. That's what your stated goal was. If you want to know that things are unreachable because something in the middle is down, then you need to get more complex as @nozlaf has said. At some point, you'll need to decide whether you want to learn how to more effectively and efficiently use Nagios, or if you just want a ping checker.

Re: Adding a simple host to monitor Up / Down state

Posted: Thu Mar 17, 2016 7:48 am
by VincentF
Very true. I guess there is no in-between.... :lol: