Access Service State from another Command

Hello all,

is it possible to access service states from a command, to pass it as an argument?
I want to use the state from two different services and pass it to a self-written script.

This script is defined as a command in the director.

The script should then define if a host is okay/critical/warning, dependend on the results from the two checks (both okay → okay, one is critical → warning, both critical → ciritical).

The script is working fine so far, only the service states are missing.

Many thanks in advance.

  • Director version (System - About): 1.8.1
  • Icinga Web 2 version and modules (System - About): 2.9.5
  • Icinga 2 version (icinga2 --version): r2.13.2-1
  • Operating System and version: Debian GNU/Linux 11
  • Webserver, PHP versions: PHP 7.4.25

Yes, you can use get_service(<host>,<service>).state with a service definition to handover the result to your command and plugin.


Thank you for your answer.
But how do i use it?
I´ve tried it here: Director → Commands → “My Command” → Arguments and then in the “Value” Field.
But this doesn´t work. I get the Error Message “Non-optional Macro […] used in argument ‘-a’ is missing.”

Found my Mistake, had to Change the Value to Icinga DSL and to do the Api Setup.
The Value is now:
return get_service(,“service_name”).state

Thank you.