Page 1 of 2
Notifications - modify %host% output
Posted: Mon Jan 16, 2017 7:13 am
by jacek
We use our Nagios from an central point and monitor many sites.
So the host names have their naming convention, and are ALWAYS looking this way:
Site-Type-Hostname
example: London-Server-SERVER01, Berlin-Switch-MAIN01, and so on.
What I'm looking for is cutting down the %host% variable to show only the "Hostname" part in the e-mail subject.
Like using some regexp to cut out everything from the left side untill (and including) the second minus "Site-Type-" and leave "Hostname".
The naming convention is very good from an administering point of view, but for the notified people don't need the whole story

I hope I made my point somehow clear

Re: Notifications - modify %host% output
Posted: Mon Jan 16, 2017 10:42 am
by bwallace
This doc should enable you to make the modifications you've mentioned:
https://assets.nagios.com/downloads/nag ... iables.pdf
Note that it applies to XI users, not contacts - which of these are "
...the notified people?"
Re: Notifications - modify %host% output
Posted: Mon Jan 16, 2017 1:03 pm
by jacek
So You mean I would need to create an additional variable?
I have an 1:1 core contact and XI user setup if thats what You are asking for?
I could also consider using the alias field with the hostname only, or? Would there be a way to automate this?
Re: Notifications - modify %host% output
Posted: Mon Jan 16, 2017 1:39 pm
by bwallace
Glad that these are XI users so yeah that doc will work. I 'd suggest using %hostalias% instead. You can use the bulk renaming tool to appoint an alias name for hosts en mass if you haven't already. Other than the doc below (I don't think it is good for this task or scenario) I'm unaware of any other alternatives for automating these changes unfortunately - I take it you have a lot of XI users ?
https://assets.nagios.com/downloads/nag ... gement.pdf
Re: Notifications - modify %host% output
Posted: Mon Jan 16, 2017 1:47 pm
by jacek
Ok, then I will consider both solutions.
But I think I would go with the first one.
I have under 20 users, so I dont think thats much, but why are You asking?
Re: Notifications - modify %host% output
Posted: Mon Jan 16, 2017 1:51 pm
by bwallace
Just asking out of an assumption is all - since you were inquiring about automation I assumed there were a ton of users involved, of course making it tedious to implement the changes one by one, but 20 is definitely manageable!
Re: Notifications - modify %host% output
Posted: Mon Jan 16, 2017 2:05 pm
by jacek
I seem I am getting confused?
How does the XI user ammount affect the ammount of work that I need to do?
Re: Notifications - modify %host% output
Posted: Mon Jan 16, 2017 2:22 pm
by dwhitfield
For an automated system, it shouldn't matter (although at some point performance would become an issue).
@bwallace was just curious about the scale.
Did you have any questions about
https://assets.nagios.com/downloads/nag ... iables.pdf ?
Re: Notifications - modify %host% output
Posted: Tue Jan 17, 2017 5:52 am
by jacek
The "Understanding (...) Variables" doesn't help me much further.
It seems that the custom variables are static and added to each host, right?
If so, then I think it would be better to use the Alias field to put there an shorter hostname.
I presume aliases can be duplicated?
Am I here on an right track? It could be also an good use for the users of Nagios - having shorter names if they want (using aliases on the lists - saw that option somewhere).
Re: Notifications - modify %host% output
Posted: Tue Jan 17, 2017 1:49 pm
by dwhitfield
slytheer wrote:
I presume aliases can be duplicated?
Yes.
If you set an alias, you'll still want to use the variable in the notification...unless you are scripting things some other way.