Installing Nagios On Debian Lenny And Monitoring A Debian Lenny Server - Page 2
This tutorial exists for these OS versions
- Debian 12 (Bookworm)
- Debian 9 (Stretch)
- Debian 5 (Lenny)
On this page
7. Introduce Localservices From server1 To The Monitor Server
We need to change our hostconfig we created in step 5 to monitor the new services we can now discover with nrpe.
monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg
Add this to the end of the file:
define service{ use generic-service host_name server1 service_description Current Load check_command check_nrpe_1arg!check_load } define service{ use generic-service host_name server1 service_description Current Users check_command check_nrpe_1arg!check_users } define service{ use generic-service host_name server1 service_description Disk Space check_command check_nrpe_1arg!check_hda1 } define service{ use generic-service host_name server1 service_description Total Processes check_command check_nrpe_1arg!check_total_procs }
Do a restart of the nagios service:
monitor:~# /etc/init.d/nagios3 restart
In the webservice you should now be able to see the added services and slowly they should pick up, beside one of them, the Check for the Disk Space will most likely fail cause you have no /dev/hda1 partition nor device.
Change this check on the monitor1 server to reflect the actual partition that we want to check. In my case the machine sits on a virtual server host by xen, we can determine the used partition by using the following command on server1:
server1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/iscsi1-root
7.3G 714M 6.2G 11% /
tmpfs 137M 0 137M 0% /lib/init/rw
udev 10M 568K 9.5M 6% /dev
tmpfs 137M 0 137M 0% /dev/shm
/dev/xvda1 228M 9.5M 207M 5% /boot
This will show us the partitions and the mountpoints of them, in my case the actual 'root' partition is /dev/mapper/iscsi1-root and i discovered this by looking for the mountpoint '/'.
Now we can continue to change our nrpe config on the server to make this check working. For this we open the nrpe.cfg file again:
server1:~# nano /etc/nagios/nrpe.cfg
Then we go to the line which contains (line 201 by default):
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
And change it to:
command[check_iscsi1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/iscsi1-root
Change the hostconfig on the Nagios server to reflect these changes:
monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg
From:
define service{ use generic-service host_name server1 service_description Disk Space check_command check_nrpe_1arg!check_hda1 }
To:
define service{ use generic-service host_name server1 service_description Disk Space check_command check_nrpe_1arg!check_iscsi1 }
Restart both services.
server1:~# /etc/init.d/nagios-nrpe-server restart
monitor:~# /etc/init.d/nagios3 restart
8. Configure Notifications Per Mail
You want to be notified per email when a service gets into critical status. So we have to configure the email address for the user nagiosadmin.
Go into the file /etc/nagios3/conf.d/contacts_nagios2.cfg and change the email address to your own one. If you want to add more users, just copy the 'define contact' section, create a second one with it and add your user(s) to the contactgroup below.
define contact{ contact_name root alias Root service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,r service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email [email protected] } define contact{ contact_name example alias example service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,r service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email [email protected] } define contactgroup{ contactgroup_name admins alias Nagios Administrators members root,example }
To activate simple mail notification we have to enable the smtp transport of the Debian system, because all that Nagios does is to give over the message with a Linux pipe to the standard program /usr/bin/mail.
We have to install Postfix and set up a basic configuration to let the Nagios server send out emails by himself.
monitor:~# apt-get install postfix mailx
Now configure Postfix as "Internet Site" and set a domain where the Nagios mails will come from.
After this do a restart and stop the apache service on the testserver:
monitor:~# /etc/init.d/nagios3 restart
server1:~# /etc/init.d/apache2 stop
This will create a notification message which should be received if you set your email address in the file contacts_nagios2.cfg.
Misc: About Icinga
Icinga is a Nagios fork with a larger developer community and will most likely be the software in the future to use, you will find howtos about Icinga on HowtoForge and you can reuse your custom plugins with Icinga as the Nagios plugins can be used to.
I would recommend anyone to play around with Nagios and Icinga.