Page 1 of 2
Confused about service_template applying or not
Posted: Tue Jul 23, 2019 12:55 pm
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.
Re: Confused about service_template applying or not
Posted: Tue Jul 23, 2019 1:07 pm
by scottwilkerson
When you add the following to a service (or service template)
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)
Re: Confused about service_template applying or not
Posted: Tue Jul 23, 2019 1:17 pm
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
}
Re: Confused about service_template applying or not
Posted: Tue Jul 23, 2019 1:54 pm
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
Re: Confused about service_template applying or not
Posted: Tue Jul 23, 2019 2:02 pm
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.
Re: Confused about service_template applying or not
Posted: Tue Jul 23, 2019 3:53 pm
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
Which adds the service to every host in the
prod-linux-hosts hostgroup
Re: Confused about service_template applying or not
Posted: Wed Jul 24, 2019 9:03 am
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.
Re: Confused about service_template applying or not
Posted: Thu Jul 25, 2019 6:26 am
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
Re: Confused about service_template applying or not
Posted: Thu Jul 25, 2019 9:07 am
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.
Re: Confused about service_template applying or not
Posted: Thu Jul 25, 2019 9:15 am
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)
the affect this has is assigning this service to ALL members of the hostgroup prod-linux-hosts.