Page 1 of 1

Host Multiple -> Hostgroup Inheritance Sources/Priority

Posted: Thu Feb 21, 2019 1:07 am
by jonatgil
Hello guy,
I'm in the following situation.
I got a bunch of windows server. And I would like to apply a default hostgroup for every host that would have service attacge to it.
->''Check_C_Drive".
I have a few servers that would require to have a different check_C_Drive, for example a check with less resource.

I would like to select witch host group have the priority over the other. In the Nagios XI UI. Even if I try to put one first and put the other after. After saving the configuration, the order is change and sort in alphabetic Order.
I though the order would go up to down or inverse similar to the list of hostgroup with comma but it's does seems to take it.

Do you have any idea?

When I check the file configuration it's always staying in this order.
Is there a way to invert those that in the UI ?

hostgroups win_check_C_Hight,win_check_Default

Thank you.

https://assets.nagios.com/downloads/nag ... tance.html


Note: At the moment I'm only testing this behavior. At the moment I cannot put the ''win_check_Default'' before the ''win_check_C_Hight'' since the letter C is before the D and it's doing some sort of aphabic sort. I know I could change the name of the hostgroup but that's is not the ideal situation.

Re: Host Multiple -> Hostgroup Inheritance Sources/Priority

Posted: Thu Feb 21, 2019 1:15 pm
by SteveBeauchemin
You could use Free Variables (FV) to solve this.

Where I work we have some systems with very small drives, and some with Huge drives. The 2 different systems need to run tests using different thresholds. The small systems can provide a warning at 4% free and critical at 2% free with no problem. On the Huge disk, 4% free could be 800GB and they do not want alerts. So on the small system we use 2% and 4% free for thresholds and on the big disk we may use 4GB and 2GB free for alert thresholds.

We use one service test for this. It works on both disk sizes. The way we do it is to have the common Host Template store a default warning and critical threshold. To the Host template we add 2 Free Variables. For example:

Code: Select all

__DRIVE_C_WARN_FREE	4%
__DRIVE_C_CRIT_FREE	2%
Since the FV are in a template they get inherited by all hosts using the template. A single Service tied to a single Host Group is all we use.
The Free Variable name __DRIVE_C_WARN_FREE will be converted to a macro named $_HOST_DRIVE_C_WARN_FREE$ by Nagios when it runs. I use extra underscores to make the variable easier to read later. Basically, we make free variables but we use Macros.

The power of this approach is that you can now make exceptions host by host as needed.

The initial setup uses the same setting for all systems. Here are some command and service definitions I use to do this. I will show a C drive example.
Check command:

Code: Select all

/usr/local/nagios/libexec/check_nrpe --unknown-timeout --timeout 120:3 --host $HOSTADDRESS$ --command $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$ $ARG8$
Service Definition:

Code: Select all

$ARG1$ = check_drivesize
$ARG2$ = -a "drive=c:"
$ARG3$ = "filter=size>1G"
$ARG4$ = "warn=free<$_HOST_DRIVE_C_WARN_FREE$"
$ARG5$ = "crit=free<$_HOST_DRIVE_C_CRIT_FREE$"
$ARG6$ = "detail-syntax=Drive %(drive) (Currently %(total_free) %(free_pct)% Available) Thresholds: Warn lt $_HOST_DRIVE_C_WARN_FREE$, Crit lt $_HOST_DRIVE_C_CRIT_FREE$"
$ARG7$ = show-all
This will use the Template definition with 2% and 4%. So that covers 'most' of the systems. The output looks like this.

Code: Select all

OK Drive c: (Currently 3.345GB 4% Available) Thresholds: Warn lt 4%, Crit lt 2%|'c: free'=3.34494GB;3.19992;1.59996;0;79.99804 'c: free %'=4%;4;2;0;100
Now lets edit one host, add the FV, and use different thresholds.
Edit a host definition for a system that needs different thresholds. Open the Misc tab and add FV.

Code: Select all

__DRIVE_C_WARN_FREE	4GB
__DRIVE_C_CRIT_FREE	2GB
So now this one host uses the same service definition as all the other hosts, but has different alerting criteria and looks like this.

Code: Select all

OK Drive c: (Currently 71.529GB 71% Available) Thresholds: Warn lt 4G, Crit lt 2G|'c: free'=71.52921GB;4;2;0;99.99804 'c: free %'=72%;4;2;0;100
Single Service, single Host Group, single Host Template, different Free Variable depending on the host.

This methodology can be applied in many places.

Hope this helps.

Steve B

Re: Host Multiple -> Hostgroup Inheritance Sources/Priority

Posted: Thu Feb 21, 2019 1:56 pm
by cdienger
Thanks for sharing the excellent post, @SteveBeuchemin!

Re: Host Multiple -> Hostgroup Inheritance Sources/Priority

Posted: Mon Feb 25, 2019 5:18 pm
by jonatgil
Thank you SteveBeauchemin for this wonderfull solution. Will try it out for sure tomorrow.

Re: Host Multiple -> Hostgroup Inheritance Sources/Priority

Posted: Tue Feb 26, 2019 1:52 pm
by cdienger
Keep us posted.

Re: Host Multiple -> Hostgroup Inheritance Sources/Priority

Posted: Sat Mar 30, 2019 8:15 am
by jonatgil
Did not try it out at the end since it would have been to advance for the team but the idea was pretty good.
Thank you for sharing the idea.
Can close the post .

Re: Host Multiple -> Hostgroup Inheritance Sources/Priority

Posted: Mon Apr 01, 2019 8:04 am
by scottwilkerson
jonatgil wrote:Did not try it out at the end since it would have been to advance for the team but the idea was pretty good.
Thank you for sharing the idea.
Can close the post .
Great!

Locking thread