« Previous 1 2 3
Network monitoring with Icinga and Raspberry Pi
Close Watch
Notifications
A powerful feature of network monitoring is its ability to inform you when your infrastructure is having issues. Such notifications can be sent via email, pager, Jabber, and other methods.
To enable email notifications, edit the /etc/incinga/objects/contacts.cfg
file, find the line that begins with email
, and replace icinga@localhost
with your email address:
email <myemail>@<mydomain>.com
By default, notifications in Icinga are not enabled. To do this, you can edit /etc/icinga/objects/localhost.cfg
and comment out any notification instances as follows:
#notifications_enabled 0
Now that you understand some of the basics of Icinga, it's time to dive into monitoring servers, services, and networking devices.
Monitoring a Linux Server
Routinely, I have half a dozen running systems in my lab at once, and I often keep an eye on uptime and system availability. Monitoring a Linux server via Icinga can be done with the use of two plugins: the check_by_ssh plugin or NRPE .
The check_by_ssh plugin, as its name indicates, uses SSH to monitor nodes. The NRPE tool allows plugins to execute on a remote host, so you can monitor disk usage, CPU load, memory, and so on.
For this article, I will use NRPE. The first step is to configure the additional Linux server to be monitored (named ubuntusrv ) by installing NRPE on that server. You can do this with the following command:
sudo apt-get install nagios-nrpe-server
Next, you need to configure NRPE by editing the config file nrpe.conf
:
nano /etc/nagios/nrpe.cfg
Under allowed hosts, add the IP address or CIDR notation network that you want to access NRPE:
allowed_hosts=127.0.0.1, 192.168.7.50 dont_blame_nrpe=1
Save your changes and then restart the NRPE server:
service nagios-nrpe-server restart
Now, on the Raspberry Pi, you will need to install the nagios-nrpe-plugin package. You can do that using the following command:
apt-get --no-install-recommends install nagios-nrpe-plugin
Next, you should check whether you can connect to NRPE on the client from the Pi:
sweetpi@raspberrypi ~ $ /usr/lib/nagios/plugins/check_nrpe-H 192.168.7.51 NRPE v2.15
If you see NRPE v2.15 in the output, it's good to go.
Next, on the Raspberry Pi Icinga server, you will need to create a new configuration file for the Linux server that is to be monitored using:
sudo nano ubuntusrv_icinga.cfg
Then, add the text in Listing 1 to the newly created configuration file. Next, you can restart Icinga:
Listing 1
Linux Server Configuration File
01 define host{ 02 use generic-host 03 host_name ubuntusrv 04 alias server2 05 address 192.168.7.51 06 } 07 define service{ 08 use generic-service 09 host_name ubuntusrv 10 service_description PING 11 check_command check_ping!100.0,20%!500.0,60% 12 } 13 define service{ 14 use generic-service ; Name of service template to use 15 host_name ubuntusrv 16 service_description Disk Space 17 check_command check_nrpe!check_disks!20%!10% 18 } 19 define service{ 20 use generic-service 21 host_name ubuntusrv 22 service_description Current Users 23 check_command check_nrpe!check_users!20!50 24 } 25 26 define service{ 27 use generic-service ; Name of service template to use 28 host_name ubuntusrv 29 service_description Current Load 30 check_command check_nrpe!check_load!5.0!4.0!3.0!10.0!6.0!4.0 31 } 32 define service{ 33 use generic-service ; Name of service template to use 34 host_name ubuntusrv 35 service_description SMTP 36 check_command check_smtp 37 } 38 define service{ 39 use generic-service ; Name of service template to use 40 host_name ubuntusrv 41 service_description HTTP 42 check_command check_http 43 }
sudo service icinga restart
Now that you are monitoring your key Linux server with Icinga (Figure 4), you also should set up monitoring for another example device – a Windows server.
Monitoring Microsoft Windows 2012
Most of the world of computing is heterogeneous. Rarely does a network comprise a single OS or technology. Thankfully, open source does an outstanding job of supporting just such a reality. Icinga is no exception. Out of the box, it supports industry standards and technologies. With Icinga, you can monitor Windows servers through a client called NSClient++ [17], so the first step is to install an NSClient++ [18] on, for example, a Microsoft Windows 2012 server – with lots of pointing and clicking.
After starting the NSClient++ Setup Wizard, fill out the configuration as in Figure 5. Remember to open TCP port 12489 for NSClient on the Windows firewall. Also, its a good idea to block this port explicitly in your network firewall.
Now that you have the client (called w2k12srv ) you are going to monitor installed on the server, you need to return to your Raspberry Pi and create a new host definition and detail its related services. To do so, create another configuration file,
sudo nano w2k12srv_icinga.cfg
to which you add the configuration shown in Listing 2. Finally, you should edit resources.cfg
and add the password you specified when installing NSClient++ on your Windows server:
Listing 2
Windows Server Configuration File
01 define host{ 02 use windows-server ; Inherit default values from a template 03 host_name w2k12srv ; The name we're giving to this host 04 alias Windows Server 2012 ; A longer name associated with the host 05 address 192.168.7.52 ; IP address of the host 06 } 07 define service{ 08 use generic-service 09 host_name w2k12srv 10 service_description Uptime 11 check_command check_nt!UPTIME 12 } 13 define service{ 14 use generic-service 15 host_name w2k12srv 16 service_description CPU Load 17 check_command check_nt!CPULOAD!-l 5,80,90 18 } 19 define service{ 20 use generic-service 21 host_name w2k12srv 22 service_description Memory Usage 23 check_command check_nt!MEMUSE!-w 80 -c 90 24 } 25 define service{ 26 use generic-service 27 host_name w2k12srv 28 service_description C:\ Drive Space 29 check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90 30 } 31 define service{ 32 use generic-service ; Inherit default values from a template 33 host_name w2k12srv 34 service_description HTTP 35 check_command check_http 36 }
$USER9$=averysecretpassword
Next, you have to make a small change to your /etc/nagios-plugins/config/nt.cfg
file by changing the first three lines in the section that begins # 'check_nt' command definition
to the lines shown in Listing 3.
Listing 3
Plugins Configuration File
01 # 'check_nt' command definition 02 define command { 03 command_name check_nt 04 command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s $USER9$ -v $ARG1$ $ARG2$
Now when you return to the Icinga web interface, your three nodes are up and running, with one service giving an error (Figure 6). Icinga is doing its job swimmingly. However, something is down. No worries, because this is a virtual test machine and not a mission-critical machine or service.
I hope this short exploration of Icinga on Raspberry Pi has been elucidating and fun. You have built a simple, inexpensive, feature-rich network monitor with the power of open technology. You really have no need to pay a bundle for a SaaS monitoring solution or big bulky server; you can build it yourself. My hope is that you will do more exploring [19] and find new and exciting uses for both Raspberry Pi and Icinga. Happy monitoring!
Infos
- Icinga: https://www.icinga.org/download/
- Icinga docs: http://docs.icinga.org
- Icinga plugin and add-on repository: http://monitoringexchange.org
- Raspberry Pi Model B+ specifications: https://www.adafruit.com/datasheets/pi-specs.pdf
- Rasp Pi case template: http://ivanreyes.tv/share/RaspberryPi_BPlus.pdf
- Win32 Disk Imager: http://sourceforge.net/projects/win32diskimager/
- SD Formatter for Mac: https://www.sdcard.org/downloads/formatter_4/eula_mac/index.html
- Formatting SD card on Linux: http://elinux.org/RPi_Easy_SD_Card_Setup#Using_the_Linux_command_line
- MicroSD card with Raspbian "Wheezy" preinstalled: http://www.adafruit.com/products/1121
- Raspbian download: http://www.raspberrypi.org/downloads/
- IDO2DB: http://docs.icinga.org/latest/en/db_components.html#ido2db
- Icinga Quick Setup: http://docs.icinga.org/latest/en/quickstart-icinga.html
- Icinga configuration file options: http://docs.icinga.org/latest/en/configmain.html
- Sample config files and definitions: http://docs.icinga.org/latest/en/sample-config.html
- NConf: http://www.nconf.org/dokuwiki/doku.php
- NagiosQL: http://www.nagiosql.org/
- Icinga Windows documentation: http://docs.icinga.org/latest/en/monitoring-windows.html
- Icinga NSClient++ Windows monitoring client: http://sourceforge.net/projects/nscplus/
- Icinga community forum: http://monitoring-portal.org
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.