In this recipe, you'll learn how to use a background for the legacy network map and deliberate the placement of hosts in specific points on it to make a kind of network status weathermap to see host statuses at a glance in a geographical context. At the time of writing, this method only works for the legacy map, which is available by clicking on (Legacy) to the right of the Map entry in the left-hand side menu.
You will need Nagios Core 4.0 or a newer server and have shell access to change its backend configuration. You should also have at least a couple of hosts configured to place on the map and understand the basics of using the Nagios network map and icons for hosts. These are discussed in the Using the network map and Choosing icons for hosts recipes, both in this chapter.
You should also select a background image on which you can meaningfully place hosts. If you are monitoring an office network, this could be a floor plan of the building or server room. If you're monitoring a nationwide Internet service provider, you could use a map of your state or country. Some administrators even like to use pictures of physical equipment and place the Nagios Core hosts over their physical analogues. In this example, we'll use a map of Australia, 640 by 509 pixels in size, which is a public domain image retrieved from the Natural Earth website at http://www.naturalearthdata.com/.
The background image can be anything you like and several graphics formats, including PNG, can be used. However, for the sake of quick map rendering, it's recommended to use an image in the GD2 file format with the .gd2
extension. If you have your image in the PNG format, you can generate a GD2 image from it using the free tool pngtogd2
, as follows:
$ pngtogd2 australia.png australia.gd2 0 1
This tool is available on Debian-derived systems in the libgd-tools
package. Its source code is also available online at http://www.libgd.org/.
We can set up a background for our network map like so:
physical_html_path
directory. In the default installation, this is /usr/local/nagios/share/images
; if it is different, you can find the definition of physical_html_path
in /usr/local/nagios/etc/cgi.cfg
. Run the following code:# cp /home/tom/australia.gd2 /usr/local/nagios/share/images
/usr/local/nagios/etc
. Edit the cgi.cfg
file, via the following:# cd /usr/local/nagios/etc # vi cgi.cfg
statusmap_background_image
directive in this file. Uncomment it and make its value the name of your image via the following:statusmap_background_image=australia.gd2
default_statusmap_layout
directive in the same file. Change it to 0
, which corresponds to the User-defined coordinates layout, as follows:default_statusmap_layout=0
/usr/local/nagios/etc/objects
. In this example, the Australian hosts are in a file called australia.cfg
.2d_coords
directives to each of the hosts you want to display on the map. You might like to include definitions for statusmap_image
here too, as done here:# vi australia.cfg define host { use linux-server host_name adelaide.example.net address 192.0.2.140 2d_coords 390,360 statusmap_image rack-server.gd2 } define host { use linux-server host_name cairns.example.net address 192.0.2.141 2d_coords 495,100 statusmap_image rack-server.gd2 } ... etc ...
nagios.cfg
, as follows:cfg_file=/usr/local/nagios/etc/objects/australia.cfg
2d_coords
directive, supply two comma-separated values describing the coordinates for the placement of the host. For example, adelaide.example.net
is 390 pixels from the left-hand side and 360 pixels from the top. A convenient way to get the coordinates is using GIMP, the open-source imaging tool, or even a simple tool such as MS Paint; load the image and let the cursor hover over the point you wish to use to find its pixel coordinates.Validate the configuration and restart the Nagios Core server, as follows:
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg # /etc/init.d/nagios restart
With this done, upon visiting the network map in the Nagios Core web interface by clicking on Map in the left-hand side menu, your hosts will be placed in their corresponding positions on the map, including the normal lines and colors to specify child-parent relationships and reachability, as shown in the following screenshot:
The default_statusmap_layout
directive fixes the network map into the User-supplied coords mode by default. In this mode, only the hosts with values for 2d_coords
are shown, and they are displayed at fixed points on the map rather than being dynamically placed.
It's possible to use this display mode without a background if we wish, but we can give a lot of useful context to the picture of the network generated by taking the extra step of using an actual background image.
Note that if you don't have any hosts with coordinates defined, you'll receive an error that looks something similar to this:
Using the network map with an image background can be particularly helpful to see not only the statuses of individual hosts at a glance, but in the case of outages from multiple hosts, also looking for possible geographical causes. If all of the nodes in one part of the city or country went down at once, we would be able to see this at a glance. This makes the network map an excellent choice for a network monitoring display or as one of the first ports of call in diagnosing large-scale problems.
The network map is very useful in this way and, graphically, it is probably the most impressive part of the Nagios Core web interface. If you would like even more options and an impressive range of visualizations for host statuses, you may like to consider looking at the excellent NagVis extension, which could fill a whole book in itself. There is a brief introduction to its usage in the Getting extra visualizations with NagVis recipe in Chapter 11, Automating and Extending Nagios Core.
3.145.179.59