Feature #54
Nagios - Configure eMail & IRC Notifications, Accepting External Commands
100%
Description
Accessing the Nagios Web Interface¶
You can now access the web based administration and reporting tools by visiting http://example.com/nagios/, where example.com refers to your default virtual host. You will need to authenticate with the nagiosadmin
user you created earlier.
- Note:
The above example does not use SSL, and your password will be sent unencrypted. You will need to generate an SSL certificate and install it yourself.
Configuring Notifications¶
A great deal of the power of Nagios is its ability to send notifications and alerts regarding the status of services and devices. While most of this fine-grained configuration is beyond the scope of this document, we have outlined some basic notifications below.
Email Alerts¶
Nagios can send alerts by email, but to receive them you'll need to add your email address to the Nagios configuration file. Here's how:
- Open the Nagios configuration file for editing by entering the following command:
sudo vi /etc/nagios3/conf.d/contacts_nagios2.cfg
- Enter your username on the system and your email address by replacing
your_username
with your username, andyouremail@example.com
with your email address.
/etc/nagios3/conf.d/contacts_nagios2.cfg
define contact{ contact_name your_username service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r,f host_notification_options d,u,r,f service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email youremail@example.com }
Note:
To send email alerts to more than one user, duplicate the define contact section for as many users as you want to add. Or, to configure notifications to a group, edit the define contactgroup section.
- Save the changes to the configuration
- Restart Nagios to apply the changes:
sudo service nagios3 restart
IRC Notifications¶
You can also configure Nagios to send notifications to an IRC channel through a bot.
- Install the IRC bot:
sudo apt-get install nagircbot
- You'll need to provide a few parameters to the IRC bot - such as its nickname and server - in order to use it. To see a list of parameters, enter the following command:
nagircbot -h
- To start the Nagios IRC bot, enter the following command:
sudo nagircbot
Now set the parameters. Use the following example as a starting point. Replace
irc.example.com
with the address of your IRC network, and#bucknell
with the name of the IRC channel that the bot should send notifications to. Replacenagircbot
with the desired nickname for your bot, and ident and realname with the ident and real name strings for the IRC bot.nagircbot -f /var/cache/nagios3/status.dat -s irc.example.com:6667 -c \#bucknell -C -n nagircbot -u ident -U realname -I 900
In the above example, -f /usr/local/nagios/var/status.dat
tells the bot where to get status updates. The -C
flag allows the bot to send colored messages to the channel depending on the status of the service. When services are down, red status messages are displayed. These messages turn green when the service has recovered. Warnings are displayed in yellow, but do not typically represent a critical issue.
The -I 900
parameter tells the bot to send a status message to the channel every 900 seconds (or 15 minutes). For example, the bot may send something like Critical: 0, warning: 1, ok: 6, up: 2, down: 0, unreachable: 0, pending: 0
, which indicates that there are no critical messages and 1 warning.
Accepting External Commands
External Commands¶
Nagios can accept external commands so that you can acknowledge problems, add comments, and more. Here's how to enable external commands:
- Open the Nagios configuration file:
sudo vi /etc/nagios3/nagios.cfg
- Change the
check_external_commands
setting tocheck_external_commands=1
. - Save the changes to the configuration file.
- Restart Apache:
sudo service apache2 restart
- Open the system group file for editing by entering the following command:
sudo nano /etc/group
- Change the
nagios:x:118
setting tonagios:x:118:www-data
. - Save the changes to the configuration file.
- Change the permissions of a Nagios configuration file:
sudo chmod g+x /var/lib/nagios3/rw
- Change the permissions of the Nagios directory:
sudo chmod g+x /var/lib/nagios3
- Restart Nagios:
sudo service nagios3 restart
External commands are now enabled.
No data to display