Dependency for all services if one service goes down

Hello,

I’d like to set up a service/host dependency rule that should work like follows:

  1. HostA with check_power checks the current power status in the datacentre.
  2. There also exists HostB, HostC, HostD with their own sets of checks etc. these are not powered by UPS.
  3. The power goes out.
  4. An alert is raised for check_power that the power has gone out
  5. No other services or hosts send notifications when they go down

Would I be able to do this with something as simple as the following?

apply Dependency "check_power_dep" to Service {
  parent_service_name = "check_power"

  states = [ OK ] // Fail if the parent service state switches to NOT-OK
  disable_notifications = true

  assign where true
  ignore where host.name == "HostA"
  ignore where service.name == "check_power"
}

Then, if I had another check, check_network for example, could I make another dependency like the above and do ignore where service.name == “check_network” && ignore where service.name == “check_power” etc.?

Thank you,

Will.

Why this? I thought you want it on the services of HostA.

@Al2Klimov I would like HostA to still send notifications in the event of a power outage, as it also checks things like DNS, network connectivity - other core things. But I don’t want all other hosts to send notifications.

Have you tried it out?

I haven’t yet - I wanted to ask whether it would even work first :slight_smile: I can give it a go and report back…

The proof of the pudding is in the eating :slight_smile:

Unfortunately my attempt does not seem to work - I’m getting the following output from Icinga for all our services:

[2021-05-27 13:24:34 +0100] critical/config: Error: Dependency 'somehost.example.com!ha-check_test/some/path!dev_httpd_dep' references a parent host/service which doesn't exist.
Location: in /etc/icinga2/zones.d/icinga2-ha-zone/dependencies/dev_httpd-dependency.conf: 1:0-1:42
/etc/icinga2/zones.d/icinga2-ha-zone/dependencies/dev_httpd-dependency.conf(1): apply Dependency "dev_httpd_dep" to Service {
                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/icinga2-ha-zone/dependencies/dev_httpd-dependency.conf(2):   parent_service_name = "check_dev_httpd_cluster"
/etc/icinga2/zones.d/icinga2-ha-zone/dependencies/dev_httpd-dependency.conf(3):

The parent service, which I am using for testing purposes, is defined as follows:

apply Service "check_dev_httpd_cluster" {
  import "15m-service"
  check_command = "check_cluster_service"

  vars.cluster_label = "dev_httpd"
  vars.cluster_hosts = [
    "anotherhost.example.com",
  ]
  vars.cluster_services = [
    "check_systemd_service_callout httpd"
  ]
  vars.cluster_min_warn = 0
  vars.cluster_min_crit = 0

  assign where host.vars.check_dev_httpd_cluster
  vars.callout = true
}

I also tried using “check_systemd_service_callout httpd” instead to try things but also no luck,

Do you have any insight into how I might overcome this please?

Please share the dependency and host+service config of parent and child.

Here’s the dependency config:

apply Dependency "dev_httpd_dep" to Service {
  parent_service_name = "check_dev_httpd_cluster"

  states = [ OK ] // Fail if the parent service state switches to NOT-OK
  disable_notifications = true

  assign where true
  ignore where host.name == "devrunner-will"
  ignore where service.name == "check_dev_httpd_cluster"
}

The service is above, and runs on devrunner-will, which has the following config:

object Host "devrunner-will" {
  check_command = "dummy"
  address                    = "172.16.1.1"
  vars.remote_client         = "icinga-master-host.example.com"

  vars.check_dev_httpd_cluster = true

  vars.notification["mail"]  = { users = [ "admin" ] }
}

The error I posted is from one of the over 20K service + host combos we have (critical/config: 28547 errors), it fails with all of them, they have no relation to this particular host and service combo, but I’d like them to depend on it.

So you’d like almost everything to depend on devrunner-will!check_dev_httpd_cluster?

Yes that’s exactly what I would like to do! :slight_smile:

Then specify also parent_host_name.

1 Like

Thank you so much! That works perfectly for my use case :slight_smile: