Page 1 of 1

Problem with host template variables used by service

Posted: Tue May 26, 2015 11:46 am
by nbdstl
I have a multi-tenant monitoring setup where I want to use variables in a host template to record customer-specific usernames/passwords for devices. There is a hostgroup for the customer that has several site-specific hostgroups (one per office). The customer-specific host template is a member of the main hostgroup for that customer. The actual host is then a member of the main hostgroup, and the service is associated with each host that uses it.

Environment is: CentOS 7.1.1503, 64-bit, manual install

My problem is that the variable substitutions don't seem to be taking place. The actual arguments being passed to the check script are:
  • ARG1 is '-H'
    ARG2 is '172.31.3.75'
    ARG3 is '-U'
    ARG4 is '$'
    ARG5 is '-P'
    ARG6 is '$'
Hostgroup looks like this:

Code: Select all

define hostgroup {
        hostgroup_name              Customer
        alias                       Customer Full Name
        hostgroup_members           Site1,Site2,Site3,Site4
        }

define hostgroup {
        hostgroup_name              Site1
        alias                       Site1
        }

[...]
Host template looks like this:

Code: Select all

define host {
       name                         Service Passwords - Customer
       alias                        Service Passwords for Customer
       hostgroups                   Customer
       _P2000_PASSWORD              password
       _P2000_USER                  username
       register                     0

}
The host looks like:

Code: Select all

define host {
        host_name          Site1 P2000 SAN Controller A
        use                Host Alive
        alias              Site1 P2000 SAN Controller A
        address            192.168.1.10
        parents            Site1 switchstack1
        hostgroups         Site1
        register           1
        }
and finally the service is:

Code: Select all

define service {
        host_name               Site1 P2000 SAN Controller A,Site2 P2000 SAN Controller A
        service_description     Customer MSA P2000 SAN Status
        use                     Active Checks-1m-24x7
        check_command           check_p2000_api!$_HOSTP2000_USER$!$_HOSTP2000_PASSWORD$!!!!!!
        register                1
        }

Re: Problem with host template variables used by service

Posted: Tue May 26, 2015 12:19 pm
by jdalrymple
Putting 1 host into a hostgroup as another host (which doesn't really exist in your case) into a similar hostgroup won't cause the custom variables to cross. You will need to use the template you created in the actual host.

Code: Select all

define host {
        host_name          Site1 P2000 SAN Controller A
        use                Host Alive,Service Passwords - Customer
        alias              Site1 P2000 SAN Controller A
        address            192.168.1.10
        parents            Site1 switchstack1
        hostgroups         Site1
        register           1
        }

Re: Problem with host template variables used by service

Posted: Tue May 26, 2015 1:12 pm
by nbdstl
It gets better, this was all done through the XI GUI.

So I have:

Hostgroups: MASTER which is a metagroup composed of hostgroups SITE 1, SITE 2, SITE 3, SITE 4.
Host template: Customer Passwords - CustomerName; this template is a member of hostgroup MASTER.
Hosts: SAN1, SAN2; these are members of hostgroups SITE 1 and SITE 2.
Service: P2000 SAN Status, which is associated with hosts SAN1, SAN2.

I would really like to have the customer password variables automatically associated with all of the hosts for the Customer. I thought that tying it to the MASTER hostgroup would do the trick through inheritance (MASTER > Site 1 > Host > Service). Apparently not.

Where do I need to have/apply a template that defines the username/password variables that are used by the service check?

Re: Problem with host template variables used by service

Posted: Tue May 26, 2015 1:25 pm
by jdalrymple
Hostgroups don't change the behavior of hosts, they just form a connection between hosts and services. You need to quit thinking about hostgroups altogether. What you need to do can be done with a template - and you've pretty much got it done. Just make the change I suggested above and your custom variables should flow into the host and service.

Re: Problem with host template variables used by service

Posted: Tue May 26, 2015 1:43 pm
by nbdstl
Is there any purpose to putting a host template into a hostgroup? It sounds like that's a does-nothing case.

Re: Problem with host template variables used by service

Posted: Tue May 26, 2015 1:45 pm
by tmcdonald
It is not possible to put a host template "into" a hostgroup. When you specify a hostgroup on a host template, you are saying "any host that uses this template should become a member of this hostgroup".

Re: Problem with host template variables used by service

Posted: Tue May 26, 2015 1:53 pm
by nbdstl
Is there any way to apply inheritable settings to multiple hosts (a group of hosts!) without applying them to those hosts individually?

I want to be able to do things like set password variables for all hosts belonging to a single tenant, or apply a template of monitoring settings (like customized monitoring times or notification/event handling) to a tenant.

Re: Problem with host template variables used by service

Posted: Tue May 26, 2015 2:00 pm
by abrist
The best way to do this, is to use a template. I suggest deploying your hostgroup setting on a template along with any other settings you wish to be set hostgroup wide.
When you assign the host the template, it will be placed in the hostgroup and inherit any other settings on the template.