Confused about service_template applying or not

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
proxibid
Posts: 30
Joined: Fri Aug 15, 2014 2:19 pm

Confused about service_template applying or not

Post by proxibid »

I have a service_template -

define service {
name host-prod-linux-load
hostgroup_name prod-linux-hosts
service_description Load - Linux - Production
display_name Load - Linux - Production
check_command check_nrpe!check_load!-a '-r -w 1,0.9,0.8 -c 2,1.5,1'!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
notification_options c,r,
notifications_enabled 1
contact_groups admins
register 0
}


As you can see above, the hostgroup prod-linux-hosts is tied to the service template.

However, the service is not showing up on the hosts in the hostgroup UNLESS (it appears) there is a service defined on a host in the hostgroup that simply inherits the host-prod-linux-load service template. Then the service info is available on all the hosts.

I am new to Nagios and inheriting an existing config, and I am confused at what is going on here.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Confused about service_template applying or not

Post by scottwilkerson »

When you add the following to a service (or service template)

Code: Select all

hostgroup_name prod-linux-hosts
the affect this has is assigning this service to ALL members of the hostgroup prod-linux-hosts.

If you want to assign a host to a host group, you would need to add the directive to the host object (or host template)
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
proxibid
Posts: 30
Joined: Fri Aug 15, 2014 2:19 pm

Re: Confused about service_template applying or not

Post by proxibid »

The hostgroup has 13 members.

I would expect that with the above service_template, the service would be applied to the 13 hosts.

But it doesn't appear in the UI service information UNLESS I create a service on a host that applies the template.

So, only as set in the service_template, services don't appear in website.

After adding the below to servername.cfg it appears on the UI for all hosts in the hostgroup.

define service {
service_description Load
use host-prod-linux-load
register 1
}
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Confused about service_template applying or not

Post by scottwilkerson »

proxibid wrote:But it doesn't appear in the UI service information UNLESS I create a service on a host that applies the template.
that is correct, the template must be applied to a service to take affect
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
proxibid
Posts: 30
Joined: Fri Aug 15, 2014 2:19 pm

Re: Confused about service_template applying or not

Post by proxibid »

I apologize for being thick, but I don't understand how applying it to one host results in it applying to all the others in the hostgroup.

*Should* I be creating a service on each host that points to the template?

Right now, with the service defined on 1 host, I have 12 hosts that show a service in the UI that isn't defined in their config file. I think that is because they are inheriting it from the hostgroup config.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Confused about service_template applying or not

Post by scottwilkerson »

When you create this service object

Code: Select all

define service {
service_description Load
use host-prod-linux-load
register 1
}
You aren't applying it to a host, you are saying create a service object and use the template host-prod-linux-load and override the service_description with Load

this will take the directives from the template host-prod-linux-load which has this line

Code: Select all

hostgroup_name prod-linux-hosts
Which adds the service to every host in the prod-linux-hosts hostgroup
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
proxibid
Posts: 30
Joined: Fri Aug 15, 2014 2:19 pm

Re: Confused about service_template applying or not

Post by proxibid »

I used CCM to create the service description above.

Here is the content of the config file for my server named app02.

###############################################################################
#
# Services configuration file
#
# Created by: Nagios CCM 3.0.3
# Date: 2019-07-23 12:54:41
# Version: Nagios Core 4.x
#
# --- DO NOT EDIT THIS FILE BY HAND ---
# Nagios CCM will overwrite all manual settings during the next update if you
# would like to edit files manually, place them in the 'static' directory or
# import your configs into the CCM by placing them in the 'import' directory.
#
###############################################################################

define service {
host_name app02
service_description CPU Stats
use host-prod-linux-cpu
notifications_enabled 1
register 1
}

define service {
service_description Load
use host-prod-linux-load
register 1
}

define service {
host_name app02
service_description Uptime
use host-prod-linux-uptime
display_name Uptime
register 1
}

###############################################################################
#
# Services configuration file
#
# END OF FILE
#
###############################################################################


Before adding the service description through CCM to app02, the Load service didn't show up for any of the hosts in the hostgroup prod-linux-hosts, of which app02 is a member.

Here is the config file for app01, another member of the prod-linux-hosts hostgroup.

###############################################################################
#
# Services configuration file
#
# Created by: Nagios CCM 3.0.3
# Date: 2019-07-23 10:43:43
# Version: Nagios Core 4.x
#
# --- DO NOT EDIT THIS FILE BY HAND ---
# Nagios CCM will overwrite all manual settings during the next update if you
# would like to edit files manually, place them in the 'static' directory or
# import your configs into the CCM by placing them in the 'import' directory.
#
###############################################################################

define service {
host_name app01
service_description /boot Disk Usage
check_command check_nrpe!check_disk!-a '-w 20% -c 10% -p /boot'
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
register 1
}

define service {
host_name app01
service_description CPU Stats
use host-prod-linux-cpu
notifications_enabled 1
register 1
}

define service {
host_name app01
service_description Cron Scheduling Daemon
check_command check_nrpe!check_init_service!-a 'crond'
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
register 1
}

define service {
host_name app01
service_description Ping
use xiwizard_linuxserver_ping_service
check_command check-host-alive!!!!!!!!
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
contact_groups admins
_xiwizard linux-server

define service {
host_name app01
service_description SSH Server
check_command check_nrpe!check_init_service!-a 'sshd'
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
register 1
}

define service {
host_name app01
service_description Swap Usage
check_command check_nrpe!check_swap!-a '-w 35 -c 20'
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
register 1
}

define service {
host_name app01
service_description Test NRPE command passthrough
check_command check_nrpe!check_all_procs!!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
retain_nonstatus_information 1
notification_interval 60
notification_period xi_timeperiod_24x7
register 1
}

define service {
host_name app01
service_description Uptime
use host-prod-linux-uptime
display_name Uptime
register 1
}

###############################################################################
#
# Services configuration file
#
# END OF FILE
#
###############################################################################


Since it is in prod-linux-hosts, it is getting the Load service check applied to it, though it is not in the config file. App02, and the other hosts in prod-linux-hosts ARE receiving 2 other service checks that are applied at the hostgroup level, but I am not sure if the checks they are getting are explicitly defined on some of the hosts or not.

If I remove the service description for Load from the app02 config file, it disappears from all of the hosts in the prod-linux-hosts hostgroup. If I add it back, it reappears for all the members of the hostgroup.

The thing that is confusing me is why adding that little stub of a service definition to one host in the hostgroup applies it to all the rest. I thought it would apply to all of them since it is applied to the hostgroup?

I feel like I am not explaining my question very well because it doesn't seem like we are looking at the same things.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Confused about service_template applying or not

Post by scottwilkerson »

proxibid wrote:If I remove the service description for Load from the app02 config file, it disappears from all of the hosts in the prod-linux-hosts hostgroup. If I add it back, it reappears for all the members of the hostgroup.
If you did this they should revert to use the service_description from the template Load - Linux - Production however I don't think the CCM will allow you to remove the service description
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
proxibid
Posts: 30
Joined: Fri Aug 15, 2014 2:19 pm

Re: Confused about service_template applying or not

Post by proxibid »

I removed app02 from the prod-linux-hosts hostgroup yesterday, and the remaining members of the hostgroup still had the Load service check applied.

I just now deleted the Load service check from app02 via CCM, and the remaining members of the prod-linux-hosts hostgroup no longer have the Load service check applied.

This does not seem like intended behavior.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Confused about service_template applying or not

Post by scottwilkerson »

proxibid wrote:This does not seem like intended behavior.
This does seem like intended behavior to me. You we assigning the service to a hostgroup, as I mentioned earlier
scottwilkerson wrote:When you add the following to a service (or service template)

Code: Select all

hostgroup_name prod-linux-hosts
the affect this has is assigning this service to ALL members of the hostgroup prod-linux-hosts.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked