Icinga command to check status of all services on host

Add dummy command to check all services on single host

Add new Command

Create a new command and fill in the fields as shown

Make sure to select the check_dummy command

Fill in the arguments

Navigate to the arguments tab of the new command and add two new arguments

  • Leave Argument Name empty

  • Value Type → Icinga DSL

  • Value: paste this code

var up_count  = 0
var down_count = 0
var cluster_services = macro("$cluster_services$")
var hostname = macro("$host.name$")

for (service in cluster_services){
  if (get_service(hostname, service).state > 0){
    down_count += 1
  } else {
    up_count += 1

  return 0 
} else {
  return 2
  • Condition Format → String
  • Skip Key → Yes

Repeat the same steps for the second argument only paste the following code to the Value field:

var output = "Cluster services:\n"
var cluster_services = macro("$cluster_services$")
var hostname=macro("$host.name$")
var up=0
var warning=0
var critical=0
var unknown=0
for (service in cluster_services) {
  if (get_service(hostname, service).state==0){output += service + "status is UP"+"\n" 
  if (get_service(hostname, service).state==1){output += service + "status is WARNING"+"\n" 
  if (get_service(hostname, service).state==2){output += service + "is CRITICAL"+"\n" 
  if (get_service(hostname, service).state==3){ output += service + "is UNKNOWN"+"\n" 
       unknown +=1}
output+=up+" UP"+"\n"+warning+ " WARNING"+"\n" + critical + " CRITICAL"+"\n"+unknown+" UNKNOWN"+"\n"
return output

Add new filed

Navigate to Icinga Director-> Define Data Fields
Add new field with :
Field Name → cluster_services
Data Type → Director Object
Object → Services
Target Data Type → Array

Add the filed to the command

Navigate to the Fields tab on the command you created
Add the newly created field

Then you can create a service template and apply this service to any host


Good work.

What is the motivation and possible use cases for this check?

Thanks for sharing your work. I would like to have this in “config” based configuration ( not using Director ).

A preview from the director could provide the “config” based configuration :wink:

1 Like

it was a request from a customer :slight_smile:
I think it can be pretty useful
I took the code from here and just modified it a bit [dev.icinga.com #12928] service cluster checking in director · Issue #496 · Icinga/icingaweb2-module-director · GitHub kudos to them

1 Like