Jump to content

Nagios 3.x Core Notes


Recommended Posts

Also known as NetSaint until they got pulled into court from Agios because apparantly they mean similar things so they changed from NetSaint to Nagios which pretty much stands for "Nagios Ain't Gonna Insist On Sainthood"

 

Installation of Nagios is pretty straight forward and can be installed on Fedora, openSUSE or Ubuntu. They have quick start guides for each.

 

You can also take advantage of a free compiled installation from iso or rpm from FAN (Fully Automated Nagios installation). The purpose of FAN is to provide a quick and easy installation which includes the most used tools in the Nagios community. The FAN CD-ROM is ISO-certified, it is thus very easy to install. A large number of tools are also being distributed, which makes the implementation of an efficient monitoring platform much easier.  It includes CentOS which is a Fedora/RedHat based Linux install.

 

Once you get Nagios installed, comes the somewhat confusing part.. at least at the beginning, the cfg files.

 

A breakdown of some important .cfg files you need to be aware of

/etc/nagios/nagios.cfg

For the most part, I just point the cfg file to monitor folders for .cfg files and load them into nagios.  Now for this to work, your .cfg files must not have any errors which I'll go over later.  So to point to a directory search for cfg_dir= and you should get down to an area of the nagios.cfg file where you can point to a directory. Since I'm primarily monitoring servers my line looks like this

cfg_dir=/etc/nagios/objects/servers

 

/etc/nagios/objects/hostgroups.cfg <-- make sure this is listed in nagios.cfg

This will group your hosts into meaningful hostgroups. Maybe it would be helpful to group all your DNS Servers together, DHCP Servers, Web Servers, etc..

 

/etc/nagios/objects/services.cfg <-- make sure this is listed in nagios.cfg

This tells nagios what services you want to monitor on your hosts and you can assign them to your hostgroups so maybe you are only monitoring web services on your Web Servers, etc..

 

Now troubleshooting why nagios won't start can be a bit of a pain if you don't know how to find out why won't nagios start.  I went through the logs and just couldn't figure out why it would fail the pre-check until I learned this.  Instead of starting nagios the typical way /etc/init.d/nagios start, start nagios this way, /usr/bin/nagios -v /etc/nagios/nagios.cfg then you will be displayed why it's not starting.

Link to post
Share on other sites
  • 1 month later...

To add a host to be monitored all it takes is



  1. Add a .cfg file to /etc/nagios/objects/servers/

  2. Add whatever you put as the hostname in that .cfg file, add that name as a member to the appropriate /etc/nagios/objects/hostgroups.cfg

  3. Restart Nagios (/etc/init.d/nagios restart)

Note: I fixed it so that it works now when you just add a .cfg file to the directory like we were trying to do before.  It is no longer required to add it to the nagios.cfg file (I removed the one test now which I renamed from qipent-a to what its real hostname is which is rns01)



 



To add additional services to be monitored



  1. Edit /etc/nagios/objects/services.cfg (define the service you want and add to the appropriate hostgroups in the services.cfg)



Link to post
Share on other sites

EMAIL ALERTING in NAGIOS



 



Example of using a relay that requires no authentication.



 



First I setup what I want in my alert by editing /etc/nagios/objects/commands.cfg (Macros you can use can be found here)





# 'notify-host-by-email' command definition

define command{

        command_name    notify-host-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nState: $HOSTSTATE$ for $HOSTDURATION$nLast Checked: $LASTHOSTCHECK$nDowntime: $HOSTDOWNTIME$nAttempt: $HOSTATTEMPT$ out of $MAXHOSTATTEMPTS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$nnLocal Contact: $CONTACTNAME$nContant Email: $CONTACTEMAIL$nContact Address: $CONTACTADDRESS1$nnNotification NotesnAuthor: $NOTIFICATIONAUTHOR$nNotification Author Name: $NOTIFICATIONAUTHORNAME$nNotification Author Alias: $NOTIFICATIONAUTHORALIAS$nNotification Comment: $NOTIFICATIONCOMMENT$nnTotal Nagio Hosts with Problems: $TOTALHOSTPROBLEMS$n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ -- -r "alert@hosangit.com"

        }





# 'notify-service-by-email' command definition

define command{

        command_name    notify-service-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$nnNotification NotesnAuthor: $NOTIFICATIONAUTHOR$nNotification Author Name: $NOTIFICATIONAUTHORNAME$nNotification Author Alias: $NOTIFICATIONAUTHORALIAS$nNotification Comment: $NOTIFICATIONCOMMENT$n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -- -r "alert@hosangit.com"

        }



Then you need to setup Postfix to be your email relay.  Minimal needs to be done to the Postfix config (/etc/postfix/main.cf) to get this to work.



 



Example using Postfix



Article 1



Article 2



Link to post
Share on other sites
  • 2 weeks later...

Postfix is great and highly recommended versus others.  It's simple to use but can be very advanced if need be. When referencing postfix and nagios then think of postfix as a relay for the client, nagios.


 


Some configuration notes... (may not be complete)


If you want to receive email notifications for Nagios alerts, you need to install the mailx (Postfix) package.





sudo apt-get install mailx

sudo apt-get install postfix


Test your mail relay (postfix) to see if it's working





echo "Test Message" | mail -s "subject" email@address.com


Something kinda neat, if you prefer to test using a From address of nagios@hosangit.com you would enter this command instead





echo "testing" | mail -s "haha" email@address.com -- -f nagios@hosangit.com


If successful, double check the valid path for mail by running





which mail


Also you can look in the maillog file to see what was used successfully to send mail





cat /var/log/maillog


Configure Nagios to send mail using your mail relay (postfix)


edit /usr/local/nagios/etc/objects/commands.cfg


If you found that which mail command above shows your mail client is in a different location than /bin/mail you need to search the cfg for all /bin/mail statements and replace with the location of mail for your system.



Restart Nagios





sudo /etc/init.d/nagios restart


edit commands.cfg note this is assuming your mail is at /bin/mail, if its different change that





# 'notify-host-by-email' command definition

define command{

command_name notify-host-by-email

command_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

}



# 'notify-service-by-email' command definition

define command{

command_name notify-service-by-email

command_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

}

Next you need to add contact info so edit contact.cfg. Just change the admin to your email address to test things out.  The group stuff isn't as straight forward as you think and everything defaults to sending to the admin so if admin was your email address you'll get emails.



Link to post
Share on other sites
  • 1 year later...

On my Ubuntu Installation I found the installation at

ls -l /usr/local/nagios/etc/

-rw-rw-r-- 1 nagios nagios 12270 Aug  4 07:09 cgi.cfg
-rw-rw-r-- 1 nagios nagios 12270 Aug  3 15:05 cgi.cfg~
-rw-r--r-- 1 root   root      50 Aug  3 15:07 htpasswd.users
-rw-rw-r-- 1 nagios nagios 44904 Nov  2 08:22 nagios.cfg
-rw-rw-r-- 1 nagios nagios 44833 Aug  4 06:58 nagios.cfg~
drwxrwxr-x 2 nagios nagios  4096 Nov  2 08:44 objects
-rw-rw---- 1 nagios nagios  1315 Aug  4 07:09 resource.cfg
-rw-rw---- 1 nagios nagios  1315 Aug  3 15:05 resource.cfg~
drwxr-xr-x 2 root   root    4096 Nov  2 09:42 servers

ls -l /usr/local/nagios/etc/objects

-rw-r--r-- 1 root   root    7473 Sep 11 10:30 1
-rw-rw-r-- 1 nagios nagios  7890 Nov  2 08:44 commands.cfg
-rw-rw-r-- 1 nagios nagios  7707 Aug  3 15:05 commands.cfg~
-rw-rw-r-- 1 nagios nagios  2138 Aug  4 07:09 contacts.cfg
-rw-rw-r-- 1 nagios nagios  2144 Aug  4 06:59 contacts.cfg~
-rw-r--r-- 1 root   root     157 Nov  2 08:39 custom-servicegroups.cfg
-rw-rw-r-- 1 nagios nagios  5375 Aug  4 07:09 localhost.cfg
-rw-rw-r-- 1 nagios nagios  5375 Aug  3 15:05 localhost.cfg~
-rw-rw-r-- 1 nagios nagios  3096 Aug  4 07:09 printer.cfg
-rw-rw-r-- 1 nagios nagios  3096 Aug  3 15:05 printer.cfg~
-rw-rw-r-- 1 nagios nagios  3265 Aug  4 07:09 switch.cfg
-rw-rw-r-- 1 nagios nagios  3265 Aug  3 15:05 switch.cfg~
-rw-rw-r-- 1 nagios nagios 10621 Aug  4 07:09 templates.cfg
-rw-rw-r-- 1 nagios nagios 10621 Aug  3 15:05 templates.cfg~
-rw-rw-r-- 1 nagios nagios  3180 Aug  4 07:09 timeperiods.cfg
-rw-rw-r-- 1 nagios nagios  3180 Aug  3 15:05 timeperiods.cfg~
-rw-rw-r-- 1 nagios nagios  3991 Aug  4 07:09 windows.cfg
-rw-rw-r-- 1 nagios nagios  3991 Aug  3 15:05 windows.cfg~

ls -l /usr/local/nagios/etc/servers

-rw-r--r-- 1 root root 6867 Nov  2 09:30 dfw1oapdn101.cfg
-rw-r--r-- 1 root root 6867 Nov  2 09:31 dfw1oapdn102.cfg
-rw-r--r-- 1 root root 6885 Nov  2 09:29 dfw1oapdn103.cfg
-rw-r--r-- 1 root root 6432 Nov  2 09:41 gridtest.cfg
-rw-r--r-- 1 root root  642 Nov  2 07:24 hostgroup.cfg
-rw-r--r-- 1 root root 6930 Nov  2 09:37 lab1oapdn101.cfg
-rw-r--r-- 1 root root 6211 Nov  2 09:42 lab1oapdn102.cfg
-rw-r--r-- 1 root root 6856 Nov  2 09:26 sat1oapdn101.cfg
-rw-r--r-- 1 root root 7189 Nov  2 09:25 sat1oapdn102.cfg
-rw-r--r-- 1 root root 6868 Nov  2 09:27 sat1oapdn103.cfg

Link to post
Share on other sites
×
×
  • Create New...