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.

Figure 4: The newly added server ubuntusrv shows up in the Service Status Details window.

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.

Figure 5: The NSClient++ wizard makes it simple to set up a Windows server for monitoring.

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.

Figure 6: Icinga monitoring three servers.

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!

The Author

Joseph Guarino is a Senior Consultant/Owner at Evolutionary IT, which provides Business and Information Technology solutions to the New England area and beyond. In his free time, you will find him writing, teaching, speaking, brewing delicious ales, and digging on FOSS projects. You can find and connect with Joseph online on all social networks from http://network.evolutionaryit.com

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Monitoring network computers with the Icinga Nagios fork
    A network monitor supports administrators by displaying a full set of critical information at a central location and alerting in case of trouble.
  • Understanding Autodiscovery

    A lack of information about your infrastructure can result in faulty system configuration and other difficulties. Automatic discovery of all hosts and services would seem to be the best solution – but can it also prove itself in practice?

  • Monitoring with collectd 4.3
    Collectd 4.3 is a comprehensive monitoring tool with a removable plugin architecture.
  • Monitoring and service discovery with Consul
    When dozens of new services and VMs emerge and disappear every day in dynamic cloud environments, conventional monitoring provides false alarms, not operational security.
  • All for Admins
    Our Admin special edition was so popular we're back, with a new quarterly magazine that is all for admins. Welcome to the first issue of Admin: Network and Security – a magazine for administrators of heterogenous networks.
comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



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.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=