The cactihost plugin
One of the new data source plugins in Weathermap 0.9 is cactihost. This takes a cacti “device ID” and uses it to query the cacti database for the current state of the device (simple so far). Cacti devices have 4 states: up, down, recovering and disabled, which have a number too: 0=disabled, 1=down, 2=recovering and 3=up.
The plugin returns the current state for both the ‘in’ and ‘out’ bandwidth values. Obviously, these aren’t much use for links, but for nodes they are handy.
Using the results
You can use the resulting numbers to assign a colour to the label of your nodes. To do this, define a new SCALE, so that each of 0,1,2,3 falls in a different coloured band:
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
This gives grey,red,blue and green for disabled, down, recovering and up, respectively.
Now you can add a TARGET and USESCALE line to your NODE, to make it use this SCALE:
LABEL my node label
The result is a NODE where the label changes colour, depending on the status of device #33.
(If you go to the Devices list in Cacti, you can see the device IDs on the end of the URL for the host’s page…)
The same, with icons…
So far so good, but I like icons. I want the icon to change when the host goes down, like Whats Up does.
Well, as longs as you don’t mind making 4 different copies of each of your icons, this is pretty easy.
LABEL my node
So we’ve said to use a SCALE called ‘none’ – that stops the label from changing colour. We still collect the data using a TARGET line though.
The ICON line is a bit more complicated. Since version 0.9, in a lot of Weathermap config you can use these ‘special tokens’ to embed data in strings. You can add them to labels, so the label text shows a value, and also to filenames. There’s a standard set of ‘variable names’ in weathermap for these, and plugins can define new ones. The cactihost plugin defines one called ‘state’ which will have one of 4 words in it: ‘disabled’,’up’,’down’,’recovering’. so if you create icons called myniceicon_up.png, myniceicon_down.png, myniceicon_disabled.png and myniceicon_recovering.png, then weathermap will switch between them as the host state changes.
Making use of DEFAULTS
That’s quite a lot to include in each NODE definition. Most of it is the same, too. By making more use of those special tokens, you can make it a lot more concise:
SET cacti_id 33
LABEL the label
SET cacti_id 36
LABEL next label
This time, the DEFAULT node has all the real work in it, including a special TARGET string that has a special token in it. It uses a variable that we are defining ourselves, called cacti_id. This is defined in each node using the SET command. Now, if we wanted to do something different with all our cacti nodes, we only have to change it in one place. Each node only has the details that are unique to that node.
The cactihost plugin