Note: This article is about features in a version of Weathermap that is not yet released. It is aimed at those who are testing the new version, prior to it's release. Feel free to help with that testing process, but 0.96 is not a finished or fully tested release yet.
Once you start making larger maps, or maps with a lot of 'pretty' formatting in them, then you'll find that you cut & paste a lot of the same formatting commands into many nodes or links. Weathermap 0.96 adds the first version of a new template feature that aims to reduce the hassle of managing large maps.
Templates are pretty simple to use, and pretty simple to understand. There are a few gotchas, because of the way they are currently implemented, but nothing too horrible. There is one new keyword, TEMPLATE, that you use in the node or link that you'd like to have copy another objects settings.
Let's start with an example, and talk through it.
NODE server
ICON 48 48 images/server.png
LABEL {node:this:name}
LABELOFFSET S
LABELFONT 12
LABELBGCOLOR none
LABELFONTCOLOR 255 255 255
NODE my_dns_server
TEMPLATE server
POSITION 100 100
Here, we have a "template node" that has no POSITION, so it will never be drawn on the map. It's only purpose is to hold the common configuration options that all nodes will pick up by using the TEMPLATE keyword. The second node does just this - it only needs to have a POSITION (so it is drawn), and the TEMPLATE keyword, which copies all the settings from the 'server' node.
Templates can be "nested" - so a template node can have a TEMPLATE keyword itself. You might have a generic 'server' node, but also a more specialised 'dns_server' node, which is formatted like a server, but with a different icon, for example.
It's important to note that the usual DEFAULT node and link still work. In fact, internally, the default TEMPLATE is the DEFAULT node or link. All the TEMPLATE keyword does is tweak this.
Also, because this process happens at the time the config is read, there are some rules about which order things appear in the config file:
- Any item with a TEMPLATE keyword must appear after the definition of that item. The editor helps here by writing out any nodes without position, or links without nodes right after the DEFAULT items, at the top of the config file.
- The TEMPLATE keyword must be the first keyword for the node or link. This is because the 'contents' of that item are replaced with those from the template. If it wasn't the first keyword, you would loose some configuration.
Also, the item you copy from doesn't have to be a positionless node or nodeless link - you can use any other link or node, as long it is already defined by the time you use it.
Obviously, this stuff is a lot more useful when you have a large map of many similar things, or an automatically generated map, based on some external configuration. I've just written a small tool that parses Cisco switch configs, looking for a certain set of VLANs and VRFS, and uses that to generate a map with appropriate labelling and targets - using templates has allowed me to remove a few hundred lines of text from the map config file.
July 21, 2008 - 10:05am
Hello Howie,
This template would save me a lot of time and would make my config files a lot shorter. Just a short question:
Is it possible to have a node with a relative position according to a template.
I've got a lot of items looking like below.
# ********* Cisco10 *************
NODE Cisco10
TARGET cactihost:27
USESCALE none
ICON images/Cisco10_{node:this:state}.png
POSITION 700 800
NODE Cisco10-tmp
INFOURL /graph.php?rra_id=all&local_graph_id=1086
OVERLIBGRAPH /graph_image.php?local_graph_id=1086&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300
ICON images/cisco_tmp.png
POSITION Cisco10 -20 -4
NODE Cisco10-cpu
INFOURL /graph.php?rra_id=all&local_graph_id=1084
OVERLIBGRAPH /graph_image.php?local_graph_id=1084&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300
ICON images/cisco_cpu.png
POSITION Cisco10 -4 -4
NODE Cisco10-mem
INFOURL /graph.php?rra_id=all&local_graph_id=1085
OVERLIBGRAPH /graph_image.php?local_graph_id=1085&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300
ICON images/cisco_mem.png
POSITION Cisco10 12 -4
Michael
July 21, 2008 - 8:27pm
No it isn't, but I understand... I've been thinking about some kind of macro capability for groups of nodes like this.
What would the config look like for the 'subnodes'? They would have a TEMPLATE line, to pick up the formatting, but they'd still need something else to tell weathermap which node was the parent, anyway... As far as I can see you'd still need to at least define a graph_id (and a target if they were scale-coloured icons) too.
The best you would get to would be:
NODE Cisco10-mem
TEMPLATE ciscomem
SET graph_id 1085
POSITION Cisco10 12 -4
There's a special node name 'parent' which points to the node that this one is relative to, but what you'd need is something that said 'the last non-relative position node' I guess. Then you could maybe use {node:lastnonrelative} in a POSITION line. It doesn't work now, and it's pretty ugly, but it would allow what you are looking for.
July 22, 2008 - 10:05am
Thanx,
Thought it wouldn't be easy. For the moment i will stick with my current config. Have some ideas of not using different icons per node but using generic ones with added text into them.
mgb
July 28, 2008 - 1:19pm
Hello Howie,
Solved my problem with the following code:
NODE foundry-tmp
INFOURL /graph.php?rra_id=all&local_graph_id={node:this:graphid}
OVERLIBGRAPH /graph_image.php?local_graph_id={node:this:graphid}&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300
ICON images/foundry_tmp.png
# POSITION {node:this:name} -20 -4
NODE foundry-cpu
INFOURL /graph.php?rra_id=all&local_graph_id={node:this:graphid}
OVERLIBGRAPH /graph_image.php?local_graph_id={node:this:graphid}&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300
ICON images/foundry_cpu.png
# POSITION {node:this:name} -4 -4
NODE foundry-mem
INFOURL /graph.php?rra_id=all&local_graph_id={node:this:graphid}
OVERLIBGRAPH /graph_image.php?local_graph_id={node:this:graphid}&rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300
ICON images/foundry_mem.png
# POSITION {node:this:name} 12 -4
# ********* device114 *************
NODE device114
TEMPLATE foundry
SET cactiid 35
POSITION 400 700
NODE device114-cpu
TEMPLATE foundry-cpu
SET graphid 1132
POSITION device114 -4 -4
NODE device114-mem
TEMPLATE foundry-mem
SET graphid 1133
POSITION device114 12 -4
NODE device114-tmp
TEMPLATE foundry-tmp
SET graphid 1134
POSITION device114 -20 -4
This reduces my config with a lot but it would even be better if I coulde use the relative position indicated in the Template:
# POSITION {node:this:name} -20 -4
Then I wouldn't have to add the position to the subdevices.