hayt
(hayt xy)
April 11, 2023, 1:58pm
1
hello Team,
Unfortunately, I am not an expert on Icinga DSL and because of this, I have a friendly request for you.
I need to create a monitoring service that will be monitoring if ALL services under an exact host will be in status OK. I don’t want to use businessprocess module for this task.
Something similar was done here >>
checking-service-clusters-in-icinga-2
With this Icinga command, you are able to check an exact service on various hosts and give the status OK if all are UP.
I need something the same but in opposite, ALL services under one exact host .
If even one service from the list is in UNKNOWN or CRITICAL then the command will have Critical in the output.
Maybe it’s an easy thing if modify the command from this example …
In the attachment Icinga DSL from the example.
argument_1.txt (457 Bytes)
argument_2.txt (1.3 KB)
old topic is here:
Author: @mfrosch
Last Edit: 2019-03-28
Today we step into the depths of the Icinga 2 DSL and try to find a nice way to combine the state of several services into one.
This approach takes a list of hosts with one service on each and check if a minimum is OK before warning or critical.
In Icinga 1.x this would be achieved by check_cluster using macros like $SERVICESTATEID:host:service$.
Features
Nice Markup with Links and HTML for Icinga 2
Check working internally in Icinga 2
Simple defini…
xy
rsx
(Roland Sommer)
April 11, 2023, 2:37pm
2
Quick and dirty coded (with ignoring soft/hard state):
apply Service "all-services" {
check_command = "dummy"
vars.dummy_state = {{
var state = 0
for (svc in get_services(host.name)) {
if (svc.name != "all-services") {
if (state < 2 && svc.state > 1) {
state = 2
}
}
}
return state
}}
vars.dummy_text = {{
var states = ["Ok", "Warning", "Critical", "Unknown"]
var output = "Check all services\n"
for (svc in get_services(host.name)) {
if (svc.name != "all-services") {
output += svc.display_name + ": " + states[svc.state] + "\n"
}
}
return output
}}
assign where true
}
1 Like
hayt
(hayt xy)
April 12, 2023, 7:20am
3
Roland thx for the response. But could you check for creating rather an Icinga “command” that could be integrated thru Icinga Director.
here is a ready-for-use Icinga command >>
director-cluster-checks.json
{
"Command": {
"cluster_services": {
"arguments": {
"output": {
"skip_key": true,
"value": {
"type": "Function",
"body": "var count_ok = 0\r\nvar count_warning = 0\r\nvar count_critical = 0\r\nvar count_unknown = 0\r\nvar outputs = []\r\n\r\nvar hosts = macro(\"$cluster_hosts$\")\r\nvar service = macro(\"$cluster_service$\")\r\nvar label = macro(\"$cluster_label$\")\r\nvar icingaweb = macro(\"$icingaweb_baseurl$\")\r\nif (!icingaweb) {\r\n icingaweb = \"\/icingaweb2\"\r\n}\r\n\r\nfor (var host in hosts) {\r\n var s = get_service(host, service)\r\n var link = \"<a class=\\\"action-link\\\" href=\\\"\" + icingaweb + \"\/monitoring\/service\/show?host=\" + host + \"&service=\" + service +\"\\\">\" + host + \"<\/a>\"\r\n var line = \"[\" + link + \"] \"\r\n if (s) {\r\n if (s.state == 0) {\r\n count_ok += 1\r\n line += \"[OK] \"\r\n } else if (s.state == 1) {\r\n count_warning += 1\r\n line += \"[WARNING] \"\r\n } else if (s.state == 2) {\r\n count_critical += 1\r\n line += \"[CRITICAL] \"\r\n } else {\r\n count_unknown += 1\r\n line += \"[UNKNOWN] \"\r\n }\r\n\r\n if (s.last_check_result) {\r\n line += s.last_check_result.output.split(\"\\n\")[0]\r\n } else {\r\n line += \"<no check result>\"\r\n }\r\n } else {\r\n line += \"<missing>\"\r\n count_unknown += 1\r\n }\r\n\r\n outputs.add(line)\r\n}\r\n\r\nreturn \"Cluster \" + label + \": \" + count_ok + \" ok, \" + count_warning + \" warning, \" + count_critical + \" critical, \" + count_unknown + \" unknown\" + \"\\n<div class=\\\"preformatted\\\">\" + outputs.join(\"\\n\") + \"<\/div>\""
},
This file has been truncated. show original
but it has a limitation. you are monitoring services from the different hosts.
I need something in opposition to this command from provided URL. I need to create a service under the exact host. This service must monitor a number of services from the host. And give OK only when every service is in status OK.
xy
Hey you can check my command below
You can modify it as you wish, it if all services are up on a single host.
Just follow the guide provided
Add dummy command to check all services on single host
Add new Command
Create a new command and fill in the fields as shown
[image]
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 (servic…