Skip to content

Instantly share code, notes, and snippets.

@lazyfrosch
Created March 28, 2019 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazyfrosch/7304942ef97b65a11b951ec38e16a1ca to your computer and use it in GitHub Desktop.
Save lazyfrosch/7304942ef97b65a11b951ec38e16a1ca to your computer and use it in GitHub Desktop.
{
"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>\""
},
"order": "2"
},
"state": {
"skip_key": true,
"value": {
"type": "Function",
"body": "var count_ok = 0\r\n\r\nvar hosts = macro(\"$cluster_hosts$\")\r\nvar service = macro(\"$cluster_service$\")\r\nvar min_warn = macro(\"$cluster_min_warn$\")\r\nvar min_crit = macro(\"$cluster_min_crit$\")\r\n\r\nfor (var host in hosts) {\r\n var s = get_service(host, service)\r\n if (s) {\r\n count += 1\r\n if (s.state == 0) {\r\n count_ok += 1\r\n }\r\n }\r\n}\r\n\r\nif (count_ok < min_crit) {\r\n return 2\r\n} else if (count_ok < min_warn) {\r\n return 1\r\n} else {\r\n return 3\r\n}"
},
"order": "1"
}
},
"command": "check_dummy",
"disabled": false,
"fields": [
{
"datafield_id": 7,
"is_required": "y",
"var_filter": null
},
{
"datafield_id": 8,
"is_required": "n",
"var_filter": null
},
{
"datafield_id": 11,
"is_required": "y",
"var_filter": null
},
{
"datafield_id": 9,
"is_required": "y",
"var_filter": null
},
{
"datafield_id": 10,
"is_required": "y",
"var_filter": null
}
],
"imports": [],
"is_string": null,
"methods_execute": "PluginCheck",
"object_name": "cluster_services",
"object_type": "object",
"timeout": null,
"vars": {
"cluster_min_crit": 1,
"cluster_min_warn": 1
},
"zone": null
}
},
"Datafield": {
"7": {
"varname": "cluster_hosts",
"caption": "Cluster Hosts",
"description": "Hosts in Cluster where the same service should be monitored",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeArray",
"format": null,
"originalId": "7",
"settings": {}
},
"8": {
"varname": "cluster_label",
"caption": "Cluster Label",
"description": "Label for the Cluster",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString",
"format": null,
"originalId": "8",
"settings": {}
},
"11": {
"varname": "cluster_min_crit",
"caption": "Cluster Minimum Crit",
"description": "Minimum services that need to be OK for this check to be not warning",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeNumber",
"format": null,
"originalId": "11",
"settings": {}
},
"9": {
"varname": "cluster_min_warn",
"caption": "Cluster Minimum Warn",
"description": "Minimum services that need to be OK for this check to be not warning",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeNumber",
"format": null,
"originalId": "9",
"settings": {
"rename_vars": "y"
}
},
"10": {
"varname": "cluster_service",
"caption": "Cluster Service",
"description": "Service which should be monitored on all hosts in the cluster",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString",
"format": null,
"originalId": "10",
"settings": {}
}
}
}
@haytxy
Copy link

haytxy commented Apr 12, 2023

@lazyfrosch Hello Markus. Could you help me here ... :( This Icinga command is great but I need one more functionality here. Are you able to improve a code so there will be a possibility to set a number of services from an exact host?
Right now we are able to set a number of hosts for an exact service.
So in the end, I will be able to create a monitoring service that will be monitoring for example every service on the chosen host and provide an OK status if every service is in OK and Critical status if even one host is in Critical or Unknown.

And yes I know ... but it could be just 5min for you to change a few lines in this Icinga basket.

@lazyfrosch
Copy link
Author

I'm no longer involved in Icinga for a while now. Please consider this an archive. You can re-use and adapt however you like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment