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
}
}
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:
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
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