Two services state dependent of each other - HOW TO

Hi!

I have an issue which I have no idea how to approach. We have two services that are dependent of each other (outside of Icinga). I’ve declared two hosts in Icinga and each of them have one of those two dependent services. The issue here is that one service is in OK state and the second one is in CRITICAL state and it’s the desired situation, but I would like to see them both as OK state - to make some kind of dependency between them. I already tried working with dependency.conf, but I don’t really think it can help me with this issue.

How would you approach this scenario? If it’s not clear for you, I can explain it further.

Thanks

Hello @lukasz.skiba,
This looks like an active-passive situation there (one ok, one ko = ok)

To manage complex situations like this with sometime weird rules i usually do something close to this :

  • make a virtual host (dumb ip, whatever you like, doesn’t matter)
  • use the dummy checkcommand on this host, it will change its states based on a custom logic.

The result of this checkcommand is defined by a custom function which implements the logic you desire between your two services. From what you said for your need i’d do a XOR operation between thoses.

In your case, it’ll look like something like this :

check_command = "dummy"
vars.dummy_state = {{ 
 if ( !bool(get_service("hostA","ServiceA").state) ^ !bool(get_service("hostB","ServiceB").state) ) {
      return 0 // UP
    } else {
      return 2 // down
    }
return 3
}}

You can then make a classic dependency between this virtual host and others checkables depending of your 2 services if you wish.

You have a good example on how to implement something close to that here :
access-object-attributes-at-runtime

You’ll also need thoses :
dummy
get_service

I strongly advise you to test in console if you want to understand what’s going on step by step, that’ll help you to build your logic :
icinga console