# Icinga command to check status of all services on host

**URL:** <https://community.icinga.com/t/icinga-command-to-check-status-of-all-services-on-host/11906>\
**Category:** Icinga 2\
**Tags:** commands, director\
**Created:** [May 2, 2023, 2:27pm UTC](https://community.icinga.com/t/icinga-command-to-check-status-of-all-services-on-host/11906 "2023-05-02T14:27:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjofalanga](https://community.icinga.com/user_avatar/community.icinga.com/benjofalanga/32/6073_2.png) [@benjofalanga](https://community.icinga.com/u/benjofalanga)\
**Post date:** [May 2, 2023, 2:27pm UTC](https://community.icinga.com/t/icinga-command-to-check-status-of-all-services-on-host/11906/1 "2023-05-02T14:27:42Z")

</div>

## Add dummy command to check all services on single host

# Add new Command

Create a new command and fill in the fields as shown  
[![](https://community.icinga.com/uploads/default/original/2X/9/9d19ca5f85a27a56e527f9545f5d331d9767e6f2.jpeg)](https://www.linkpicture.com/view.php?img=LPic645118d39990a1038447325)  
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

```auto
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
  }
}

if(down_count==0){
  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:

```auto
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" 
     up+=1}
  if (get_service(hostname, service).state==1){output += service + "status is WARNING"+"\n" 
       warning+=1}
  if (get_service(hostname, service).state==2){output += service + "is CRITICAL"+"\n" 
       critical+=1}  
  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

```

[![](https://community.icinga.com/uploads/default/original/2X/e/e9877d5edc6553ea3d49f9d555af81eef174fc8d.png)](https://www.linkpicture.com/view.php?img=LPic645118d39990a1038447325)

# 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  
[![](https://community.icinga.com/uploads/default/original/2X/3/36e5a4f2f6ca85eebd48f89fdca940b56bf47cee.png)](https://www.linkpicture.com/view.php?img=LPic645118d39990a1038447325)

# Add the filed to the command

Navigate to the Fields tab on the command you created  
Add the newly created field  
[![](https://community.icinga.com/uploads/default/original/2X/d/d9a20ea590574864b54251544eb6c6bac2047e4d.jpeg)](https://www.linkpicture.com/view.php?img=LPic645118d39990a1038447325)

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

---

<div class="post-metadata">

**Author:** ![rivad](https://community.icinga.com/user_avatar/community.icinga.com/rivad/32/5852_2.png) [@rivad](https://community.icinga.com/u/rivad)\
**Post date:** [May 3, 2023, 7:19am UTC](https://community.icinga.com/t/icinga-command-to-check-status-of-all-services-on-host/11906/2 "2023-05-03T07:19:10Z")

</div>

Good work.

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

---

<div class="post-metadata">

**Author:** ![monigacom](https://community.icinga.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@monigacom](https://community.icinga.com/u/monigacom)\
**Post date:** [May 3, 2023, 1:57pm UTC](https://community.icinga.com/t/icinga-command-to-check-status-of-all-services-on-host/11906/3 "2023-05-03T13:57:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rivad](https://community.icinga.com/user_avatar/community.icinga.com/rivad/32/5852_2.png) [@rivad](https://community.icinga.com/u/rivad)\
**Post date:** [May 3, 2023, 2:12pm UTC](https://community.icinga.com/t/icinga-command-to-check-status-of-all-services-on-host/11906/4 "2023-05-03T14:12:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![benjofalanga](https://community.icinga.com/user_avatar/community.icinga.com/benjofalanga/32/6073_2.png) [@benjofalanga](https://community.icinga.com/u/benjofalanga)\
**Post date:** [May 3, 2023, 8:31pm UTC](https://community.icinga.com/t/icinga-command-to-check-status-of-all-services-on-host/11906/5 "2023-05-03T20:31:43Z")

</div>

it was a request from a customer 🙂  
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](https://github.com/Icinga/icingaweb2-module-director/issues/496#issuecomment-273105783) kudos to them
