NagVis / nagvis

Visualization addon for your open source monitoring core
http://nagvis.org/
GNU General Public License v2.0
115 stars 74 forks source link

Adding regex-based Hosts in automaps #50

Open miragu opened 8 years ago

miragu commented 8 years ago

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_nameregex, 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.

LarsMichelsen commented 8 years ago

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.