I have a question about inheritance and how to do it efficiently (meaning less typing). Here is the setup I am imaginging (simplified to make the question more clear)
[code]CFG_SERVER_DIR
|=> GLOBAL
|=> host1-global.cfg
|=> host2-global.cfg
|=> PROD
|=> host1-prod.cfg
|=> host2-prod.cfg
|=> QA
|=> host1-qa.cfg
|=> host2-qa.cfg
[/code]
My goal is to have service checks in the GLOBAL directory for each host. Then in the PROD and QA folders, the matching hosts inherit the service checks. The only difference is the contact group for PROD is different than QA. I know I can do this by redefining service checks in the host1-prod.cfg like similar:
define service{
use host1-global;
host_name host1-prod;
contact_groups +prod_contact_group;
}
but I would prefer to not have to add that to every host config file. My goal would be for a host config file to be like so:
define host{
host_name host1-prod;
hostgroups host1-global-checks,prod_contact_group;
}
Or something similar to minimize typing and therefore configs getting incorrect.
Could anyone please help me out or point me to a tutorial that would explain this for me? I tried looking at the inheritance documentation and for whatever reason, I could not determine how to do the above correctly since the inheritance is coming from two different directions.
You are on the right track. There are a couple specific things to keep in mind.
The most specific template needs to be listed first for the inheritance to work properly. This is especially true if an option (such as the contacts or command) are defined more than once. I’ve found it easier to make the configuration lines disjoint - if one parent provides a contact line all others it inherits does not. If you can manage this I’ve found it makes things much easier to administer as it is less worrisome to get the order just right.
The other thing you should look at for this configuration is host groups.
Set the host group at one of the inherited parents and this will allow a much more compact configuration.
define service{
hostgroup_name prod-servers
use check_rdp,prod-service,local-service
}
define service{
name local-service
notification_options d,r
notification_interval 180
register 0
}
define service{
name prod-service
contacts mycontacts
register 0
}
define service{
name check_rdp
register 0
<check commands and options>
define host{
name prod-template
hostgroups prod-servers
register 0
}
This won’t give you quite what you are after but it’s the closest thing I’ve found.
Great info. Based on that, I think I can get where I need with the below. This allows me to configure new hosts by only creating a host definition with hostgroups. Perfect!
CFG_SERVER_DIR
|=> GLOBAL
|=> SERVICES
|=> global_ssh_check.cfg
service {
name global_ssh_check
service_description SSH Check
check_command check_ssh
contact_groups nagios_admins
register 0
}
|=> PROD
|=> SERVICES
|=> prod_ssh_check.cfg
service {
name prod_ssh_check
use global_ssh_check
contact_groups +on_call
hostgroup_name prod_hosts
}
|=> HOSTGROUPS
|=> prod_hosts.cfg
define hostgroup{
hostgroup_name prod_hosts
alias prod_hosts
}
|=> HOSTS
|=> prod_appX_01.cfg
host {
name prod_ prod_appX_01
hostgroups prod_hosts
}
|=> prod_appX_02.cfg
host {
name prod_ prod_appX_02
hostgroups prod_hosts
}
|=> QA
|=> SERVICES
|=> qa_ssh_check.cfg
service {
name qa_ssh_check
use global_ssh_check
contact_groups +qa_team
hostgroup_name qa_hosts
}
|=> HOSTGROUPS
|=> qa_hosts.cfg
define hostgroup{
hostgroup_name qa_hosts
alias qa_hosts
}
|=> HOSTS
|=> qa_appX_01.cfg
host {
name prod_ qa_appX_01
hostgroups qa_hosts
}