Skip to content

Instantly share code, notes, and snippets.

@formorer
Created March 21, 2017 20:23
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 formorer/9f10e82fdc7cd219a5d23fce04d447f1 to your computer and use it in GitHub Desktop.
Save formorer/9f10e82fdc7cd219a5d23fce04d447f1 to your computer and use it in GitHub Desktop.
Clusterchecks mit Icinga2
object CheckCommand "clustercheck" {
import "plugin-check-command"
command = {{
var cmd = [ PluginDir + "/check_dummy" ]
var cluster_nodes = macro("$cluster_nodes$")
var host_failed = [ ]
for (cluster_node in cluster_nodes) {
log("Check state of " + cluster_node)
/* get host state from node */
var host = get_host(cluster_node)
/* wenn der Host kritisch ist zählen wir den Fehlerwert hoch
und speichern den kritischen Host in einer Variable */
if (host.state_raw != 0 && host.state_raw != 1) {
log(cluster_node + " failed")
host_failed += [ cluster_node ]
}
}
if (len(host_failed) >= number(macro("$cluster_critical$"))) {
cmd += [ "2", "Cluster ist in einem kritischen Zustand. Kritische Hosts: " + host_failed.join(",") ]
} else {
if (len(host_failed) >= 1) {
cmd += [ "0", "Cluster hat Probleme. Kritische Hosts: " + host_failed.join(",") ]
} else {
cmd += [0, "Cluster ist OK"]
}
}
return cmd
}}
}
object Host "node1" {
import "generic-host"
address = "127.0.0.1"
}
object Host "node2" {
import "generic-host"
address = "127.0.0.1"
}
object Host "node3" {
import "generic-host"
address = "192.100.213.2"
}
object Host "cluster" {
import "generic-host"
check_command = "clustercheck"
/* unser cluster ist kritisch wenn mehr als 2 Hosts weg sind */
vars.cluster_critical = "2"
vars.cluster_nodes = [
"node1",
"node2",
"node3"
]
check_interval = 10s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment