In this recipe, you'll learn how to select graphics for hosts to appear in various parts of the Nagios Core web interface. This is done by adding directives to a host to specify the paths to appropriate images to represent it.
Adding these definitions has no effect on Nagios Core's monitoring behavior; they are mostly cosmetic changes, although it's useful to see at a glance whether a particular node is a server or a workstation, particularly on the network map.
You will need to run Nagios Core 4.0 or a newer server and have access to its web interface. You must also be able to edit the configuration files for the server.
It's a good idea to verify that you actually have the required images installed. The default set of icons is included in /usr/local/nagios/share/images/logos
. Don't confuse this with the directory above it, images
, which contains images used as part of the Nagios Core web interface itself.
In the logos
directory, you should find a number of images in various formats under it. In this example, we're interested in the router
and rack-server
icons:
$ ls /usr/local/nagios/share/images/logos/{router,rack-server}.* /usr/local/nagios/share/images/logos/rack-server.gd2 /usr/local/nagios/share/images/logos/rack-server.gif /usr/local/nagios/share/images/logos/router.gd2 /usr/local/nagios/share/images/logos/router.gif
To get the full benefit of the icons, you'll likely want to be familiar with using the network map and have access to view it with the appropriate hosts in your own Nagios Core instance. The network map is introduced in the Using the network map recipe in this chapter.
We can define the images to be used in displaying our host like so:
/usr/local/nagios/etc/objects
. If you've put the definition for your host in a different file, move to its directory instead and run the following line:# cd /usr/local/nagios/etc/objects
corsica.example.net
and the router icon to both calpe.example.net
and janus.example.net
, as follows:define host { use linux-server host_name corsica.example.netalias corsicaaddress 192.0.2.71 icon_image rack-server.gif icon_image_alt Rack Server statusmap_image rack-server.gd2 } define host { use linux-router host_name janus.example.net alias janusaddress 192.0.2.128 icon_image router.gif icon_image_alt Router statusmap_image router.gd2 } define host { use linux-router host_name calpe.example.net alias calpeaddress 192.0.2.129 icon_image router.gif icon_image_alt Router statusmap_image router.gd2 }
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg # /etc/init.d/nagios restart
With this done, a visit to the status map should show the appropriate hosts now being displayed with icons rather than small circles.
The Hosts list should also include a scaled-down version of the image, as in the following screenshot:
When a host list, service list, or network status map is generated, it checks for the presence of icon_image
or statusmap_image
values for each host object, reads the appropriate image if defined, and includes it as part of its processing. The network status map defaults to displaying only a colored circle in the absence of a value for the statusmap_image
directive.
Note that for the statusmap_image
directive, we chose the .gd2
version of the icon rather than the .gif
version. This applies to the legacy version of the status map for performance reasons; this status map is generated with the GD2 library, which deals more efficiently with its native .gd2
format.
The icon_image_alt
directive defines the value for the alt
attribute when the image is displayed in an <img>
HTML tag. Most web browsers will show the contents of this tag after briefly hovering over the icon.
If you have a number of hosts that need to share the same image, it is good practice to inherit from a common host template with the appropriate directives set. For our example, we might define a template like so:
define host { name router-iconicon_image router.gif icon_image_alt Router statusmap_image router.gd2 register 0}
We could then apply the image settings directly to both our routers simply by inheriting from this template and by adding it to the use
directive. Take a look at the following code:
define host { use linux-router,router-icon host_name janus.example.net alias janus address 192.0.2.128 } define host { use linux-router,router-icon host_name calpe.example.net alias calpe address 192.0.2.129 }
If you don't like the included icon set, there are many icon sets available online on the Nagios Exchange site at https://exchange.nagios.org/. If you want, you could even make your own out of physical pictures of your hardware saved in standard PNG or GD2 format.
3.137.178.133