nagvis icon indicating copy to clipboard operation
nagvis copied to clipboard

Adding regex-based Hosts in automaps

Open miragu opened this issue 8 years ago • 1 comments

Hello,

This is a feature request with patch included. I'm using automaps with livestatus source and wanted to do some differentiation based on the host name, such as bigger icons, different label backgrounds, etc. I couldn't find any way to do this in the documentation and in testing (everything seems to be directed at regular maps, not automaps). So I hacked support for regular expressions in host definitions, using a custom attribute host_name_regex, and inherited some additional attributes I needed (label_*, z). Here's the patch: nagvis-automap-regex.txt

The idea is to define regex hosts like this:

define host { 
host_name=router-regex
host_name_regex=/^router-/
x=0
y=0
object_id=ee8693
iconset=icon_router
icon_size=100
label_show=1   
z=98
}

...which overrides the default and global attributes. Note that at first I experimented with putting the regex directly in the host_name, and matching for hosts starting with "/", but I found there's strict rules for hostnames that don't allow many useful regex characters, so I went with a specific attribute. With these "host groups", I was able to easily automap custom groups of hosts like this (shrinked for privacy):

automap-regex

A note regarding the future. For now this patch fits my purposes but could be improved. Something that bothers me is that if I want to customize a specific host, say "router-abc" which is matched by the example regex, I can define a regular host (not regex) for it at the end of the configuration, but this completely overrides the regex host. So I have to define all attributes again in that regular host (I did this to create the above image, because the labels are arbitrary, unrelated to the host name or alias). Work for a future patch, perhaps.

Is this regex-based host feature something you would consider adding to nagvis? If not as-is, I can try to improve it where needed. Thank you.

miragu avatar Apr 26 '16 17:04 miragu

Hi,

thanks for your idea and the proof of concept. I'll need to think about this. Having to define both a host_name and host_name regex is not good. This would need to be changed. And it would also be necessary to make this configurable via the GUI to make it usable for more users.

LarsMichelsen avatar May 10 '16 19:05 LarsMichelsen