Introduction
This is a quick write-up on how to make your nodes change depending on the state of a host in the Cacti database. You can use the same kind of ideas for things like CPU load on servers,interface status on switches, or session counts on a firewall.
Ingredients
These are the key parts to make this work:
-
Everything in Weathermap is simply translating a number from a datasource into a colour, using a scale. Scales can also have text ‘tags’ attached, which are useful for updating node labels, or selecting different icons. Weathermap does not know what “up” or “down” or “disabled” actually means. They are just text that it can use to find image files.
-
Weathermap also has a built-in datasource plugin that can look up the current status of a host in the Cacti database. It returns that as a number from 0 to 5, and also sets some Hint Variables that you can use.
-
For any node or link, you can access the Hint Variables in most places that a string is expected like this:
{node:this:variablename}
(the main exception is that you can’t use a variable that was defined by a datasource in a TARGET line, to stop bad datasource plugins from interfering with each other. You can use variables that you defined with SET though)
Recipe
First of all, you need to know the Cacti host ID for the host. This is in the URL when you look at that host’s details on the Manage…Devices section of Cacti.
For the node, you can now collect the current status.
NODE mynode
POSITION 100 100
TARGET cactihost:22
Now the ‘in’ and ‘out’ traffic values collected for this node are actually the current cacti host status, from 0 to 5. However, we’re still using the DEFAULT scale, and a MAXVALUE of 100, which are the defaults for a new node, so the node will change colour, but not in a useful way. We need a new SCALE. There’s one in the manual, for you!
SCALE cactiupdown 0 0.5 192 192 192
SCALE cactiupdown 0.5 1.5 255 0 0
SCALE cactiupdown 1.5 2.5 0 0 255
SCALE cactiupdown 2.5 3.5 0 255 0
SCALE cactiupdown 4.5 5.5 128 128 128
NODE mynode
POSITION 100 100
TARGET cactihost:22
USESCALE cactiupdown in
Now our node will change colour in a more useful way. Status 1 is down, so the scale says that from 0.5-1.5 we will show red. (it is good practice to not have gaps in your scale, so each of the value bands here ‘touches’ the ones either side of it)
Fancy Version
You can stop there if you like, but what if you wanted to change the ICON for each state as well? We can add ‘scale tags’ to the scale like this:
SCALE cactiupdown 0 0.5 192 192 192 disabled
SCALE cactiupdown 0.5 1.5 255 0 0 down
SCALE cactiupdown 1.5 2.5 0 0 255 recovering
SCALE cactiupdown 2.5 3.5 0 255 0 up
SCALE cactiupdown 4.5 5.5 128 128 128 unknown
And now, for each node there will be a new Hint Variable called {node:this:inscaletag}
that contains the text on the end of the line, for the scale line that was actually matched in that node.
That means we can use that variable to decide which icon to display:
NODE mynode
POSITION 100 100
TARGET cactihost:22
USESCALE cactiupdown in
ICON images/state_{node:this:inscaletag}.png
As long as we create the icons in the images
directory: state_disabled.png
, state_down.png
etc…
Extra Notes
Using the advanced version here will confuse the web-based editor, because it isn’t smart enough to know what the possible values of ‘inscaletag’ are - so you may get strange results when you edit a map that uses this method.
Also, it does take Cacti a few polls to decide that a node is down, so this isn’t a very good way to do your monitoring. Depending on the situation, the fping datasource plugin, or a real monitoring system like Nagios would be a better choice.