Mass Scripting Service Dependency issue
-
JakeHatMacys
- Posts: 281
- Joined: Thu Sep 25, 2014 3:21 pm
Mass Scripting Service Dependency issue
So the goal here was to create a service dependency for 1 device and then use the same format across 2000 or so devices. The way we set up our services is by inheriting them via Host groups. So the service checks are set to a host group and any member of that group inherits them.
define servicedependency {
dependent_host_name dmj1db01
dependent_service_description check_FS_space_Solaris_by_sshpass
host_name dmj1db01
service_description ping
inherits_parent 1
execution_failure_criteria w,u,c,p,
dependency_period 24x7
}
This is an example of one, not sure why it's getting formatted odd there. but we basically just replaced the dependent host name & host name with the appropriate host... we scripted it into the attached file an imported it (I deleted the attachment since it contains server lists, I can PM it to anyone on Nagios side but it's a massive reproduction of the example with host info swapped). The result was 2000 plus duplicate services were created per dependency entry...
Thoughts?
FYI we did the same thing with host dependencies on host groups (we used our store switches to shut down checks on members of that store host group) and it worked fine. Not the same thing I know but would like to get the service stuff sorted out.
define servicedependency {
dependent_host_name dmj1db01
dependent_service_description check_FS_space_Solaris_by_sshpass
host_name dmj1db01
service_description ping
inherits_parent 1
execution_failure_criteria w,u,c,p,
dependency_period 24x7
}
This is an example of one, not sure why it's getting formatted odd there. but we basically just replaced the dependent host name & host name with the appropriate host... we scripted it into the attached file an imported it (I deleted the attachment since it contains server lists, I can PM it to anyone on Nagios side but it's a massive reproduction of the example with host info swapped). The result was 2000 plus duplicate services were created per dependency entry...
Thoughts?
FYI we did the same thing with host dependencies on host groups (we used our store switches to shut down checks on members of that store host group) and it worked fine. Not the same thing I know but would like to get the service stuff sorted out.
-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Mass Scripting Service Dependency issue
So you're trying to write a service dependency that would prevent the disk service from exploding when the host itself goes down?
2 thoughts:
1) Shouldn't the dependency be based on check_ssh instead of check_ping - I'm sure you have your reasons, I guess I just wondered what they were.
2) This should be doable in 1 servicedependency with the proper hostgroups defined... I think:
All Hosts In Multiple Hostgroups:
If you want to create service dependencies for services of the same name/description that are assigned to all hosts in in one or more hostgroups, you can do use the hostgroup_name and/or dependent_hostgroup_name directives. In the example below, service SERVICE2 on all hosts in hostgroups HOSTGROUP3 and HOSTGROUP4 would be dependent on service SERVICE1 on all hosts in hostgroups HOSTGROUP1 and HOSTGROUP2. Assuming there were five hosts in each of the hostgroups, this definition would be equivalent to creating 100 single service dependency definitions! All the instances of the service dependency would be identical except for the host names (i.e. have the same notification failure criteria, etc.).
2 thoughts:
1) Shouldn't the dependency be based on check_ssh instead of check_ping - I'm sure you have your reasons, I guess I just wondered what they were.
2) This should be doable in 1 servicedependency with the proper hostgroups defined... I think:
All Hosts In Multiple Hostgroups:
If you want to create service dependencies for services of the same name/description that are assigned to all hosts in in one or more hostgroups, you can do use the hostgroup_name and/or dependent_hostgroup_name directives. In the example below, service SERVICE2 on all hosts in hostgroups HOSTGROUP3 and HOSTGROUP4 would be dependent on service SERVICE1 on all hosts in hostgroups HOSTGROUP1 and HOSTGROUP2. Assuming there were five hosts in each of the hostgroups, this definition would be equivalent to creating 100 single service dependency definitions! All the instances of the service dependency would be identical except for the host names (i.e. have the same notification failure criteria, etc.).
Code: Select all
define servicedependency{
hostgroup_name HOSTGROUP1,HOSTGROUP2
service_description SERVICE1
dependent_hostgroup_name HOSTGROUP3,HOSTGROUP4
dependent_service_description SERVICE2
other dependency directives ...
}-
JakeHatMacys
- Posts: 281
- Joined: Thu Sep 25, 2014 3:21 pm
Re: Mass Scripting Service Dependency issue
Yes if I can do it by host group that'd be great. I thought I tried this before and it didn't go 1 to 1 with the services like that. But i'll try it again, and yes the goal is when we can't ping the server to shut off the check_disk script.
But just to verify mine would look like this:
define servicedependency{
hostgroup_name HOSTGROUP1
service_description SERVICE1
dependent_hostgroup_name HOSTGROUP1
dependent_service_description SERVICE2
other dependency directives ...
}
But just to verify mine would look like this:
define servicedependency{
hostgroup_name HOSTGROUP1
service_description SERVICE1
dependent_hostgroup_name HOSTGROUP1
dependent_service_description SERVICE2
other dependency directives ...
}
-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Mass Scripting Service Dependency issue
Just that easy.
I might be able to make it even easier for you:
Don't forget you will have to have a SEPARATE check_ping besides the default host check command defined. That's why I'd suggest doing check_ssh instead as it is less redundant and offers an additional little bit of useful data.
Also - I won't lie, I'm not a dependency wizard. There is a lot you can do though. If this doesn't work let us know and I'll fiddle.
I might be able to make it even easier for you:
Code: Select all
define servicedependency{
hostgroup_name check_by_ssh_hosts
service_description check_ping
dependent_hostgroup_name check_by_ssh_hosts
dependent_service_description check_disk,check_swap,check_mem
other dependency directives ...
}Also - I won't lie, I'm not a dependency wizard. There is a lot you can do though. If this doesn't work let us know and I'll fiddle.
-
JakeHatMacys
- Posts: 281
- Joined: Thu Sep 25, 2014 3:21 pm
Re: Mass Scripting Service Dependency issue
Sure, I think it should work out I'll get this moving here and find out. But it'll probably be Monday as I'm knee deep in a few other things.
Quick question for sorta the same topic.
In the future we're going to be scripting out moving store devices to different host groups (having roles defined by the host group and inherited) but we wanted to dump out the current devices and host groups they belong to in a spread sheet to compare to AD to stay up to date (when new devices are shipped out or some moved to different stores etc).
So the question is do you have some SQL commands handy to dump all hosts & their host groups into a spread sheet say in the /tmp directory?
And the same for Service Groups?
I grabbed this from google but wanted versions that add ALL hosts and host groups they belong to if you get me:
I'm more of an OPS minded guy so wasn't sure how to modify it O.o
Quick question for sorta the same topic.
In the future we're going to be scripting out moving store devices to different host groups (having roles defined by the host group and inherited) but we wanted to dump out the current devices and host groups they belong to in a spread sheet to compare to AD to stay up to date (when new devices are shipped out or some moved to different stores etc).
So the question is do you have some SQL commands handy to dump all hosts & their host groups into a spread sheet say in the /tmp directory?
And the same for Service Groups?
I grabbed this from google but wanted versions that add ALL hosts and host groups they belong to if you get me:
Code: Select all
echo "use nagiosql; select host_name from tbl_host into outfile '/tmp/hosts.csv' fields terminated by ',' enclosed by '\"' lines terminated by '\n'" | mysql -u root -pnagiosxiRe: Mass Scripting Service Dependency issue
Our DBs are pretty relational, and the tbl_host will actually not link directly to a hostgroup. There are two intermediary tables, tbl_lnkHostToHostgroup and tbl_lnkHostgroupToHost that relate the object IDs of the hosts and hostgroups. It's not something I would try to do in a single query, I would instead build a PHP script to do the joining and display/output. That's getting a little more developy than I usually like to stray, but if you come back Monday when we've got a bit more time I can maybe get you something to push you in the right direction.
Former Nagios employee
-
JakeHatMacys
- Posts: 281
- Joined: Thu Sep 25, 2014 3:21 pm
Re: Mass Scripting Service Dependency issue
Let me know if you can give me that pushtmcdonald wrote:Our DBs are pretty relational, and the tbl_host will actually not link directly to a hostgroup. There are two intermediary tables, tbl_lnkHostToHostgroup and tbl_lnkHostgroupToHost that relate the object IDs of the hosts and hostgroups. It's not something I would try to do in a single query, I would instead build a PHP script to do the joining and display/output. That's getting a little more developy than I usually like to stray, but if you come back Monday when we've got a bit more time I can maybe get you something to push you in the right direction.
Re: Mass Scripting Service Dependency issue
So here's the pseudo-code for how I would handle it:
Fair warning: I am not a developer and this is probably an eye-sore to anyone who is. If we were to get the devs involved this would need to be a feature request or custom development.
Code: Select all
for each host
search for id as master in tbl_lnkHostToHostgroup
enter each host id into an array as the key, add hostgroup id as CSV entry into value
for each hostgroup
search for id as master in tbl_lnkHostgroupToHost
enter each hostgroup id into the array as the value for the associated host id, removing duplicate hostgroup ids
print into CSV file
Former Nagios employee
-
JakeHatMacys
- Posts: 281
- Joined: Thu Sep 25, 2014 3:21 pm
Re: Mass Scripting Service Dependency issue
I think we'll be able to handle it in house. Thanks for the pointers you can lock this guy up.tmcdonald wrote:So here's the pseudo-code for how I would handle it:
Fair warning: I am not a developer and this is probably an eye-sore to anyone who is. If we were to get the devs involved this would need to be a feature request or custom development.Code: Select all
for each host search for id as master in tbl_lnkHostToHostgroup enter each host id into an array as the key, add hostgroup id as CSV entry into value for each hostgroup search for id as master in tbl_lnkHostgroupToHost enter each hostgroup id into the array as the value for the associated host id, removing duplicate hostgroup ids print into CSV file