Browse Source

Icinga: Add check for salt state

Signed-off-by: Michael Schwarz <post@michael-schwarz.name>
Maximilian Wilhelm 4 years ago
parent
commit
bc96301547
4 changed files with 47 additions and 0 deletions
  1. 3 0
      icinga2/commands.d/check_salt.conf
  2. 7 0
      icinga2/init.sls
  3. 16 0
      icinga2/plugins/check_salt
  4. 21 0
      icinga2/services/salt.conf

+ 3 - 0
icinga2/commands.d/check_salt.conf

@@ -0,0 +1,3 @@
+object CheckCommand "check_salt" {
+        command = [ FFHOPluginDir + "/check_salt" ]
+}

+ 7 - 0
icinga2/init.sls

@@ -279,3 +279,10 @@ Cleanup /etc/icinga2/ffho-conf.d/net/wbbl/:
     - template: jinja
     - require:
       - file: /etc/icinga2/ffho-conf.d
+
+/etc/cron.d/icinga_check_salt:
+  file.managed:
+    - contents: "0 */4 * * * root sleep $(($RANDOM % 14400)) ; /usr/bin/salt-call state.highstate --state-verbose=False test=True > /var/cache/salt/state_apply 2>/dev/null"
+    - user: root
+    - mode: 640
+

+ 16 - 0
icinga2/plugins/check_salt

@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# Check if state-file exists, otherwise exit with unknown
+if [ ! -f /var/cache/salt/state_apply ] ; then echo "Statefile does not exist" ; exit 3 ; fi
+
+# Check age of statefile. If it's older than 2 hours, exit with unknown
+if [ $(($(date +%s) - $(date -r /var/cache/salt/state_apply +%s))) -gt 25200 ] ; then echo "Statefile too old" ; exit 3 ; fi
+
+if egrep "Succeeded:.*changed=[^0]\)|Failed:      [^0]" /var/cache/salt/state_apply > /dev/null ; then
+	cat /var/cache/salt/state_apply
+	exit 1 # warning
+fi
+
+echo "Nothing to do"
+exit 0 # ok
+

+ 21 - 0
icinga2/services/salt.conf

@@ -0,0 +1,21 @@
+#
+# Check if salt has to do anything
+#
+
+
+#
+# Salt
+apply Service "salt" {
+        import "generic-service"
+
+	check_command = "check_salt"
+
+	if (host.name != NodeName) {
+		command_endpoint = host.name
+	}
+
+	vars.ok_string = "[ OK ]"
+
+	assign where host.address && host.vars.os == "Linux"
+}
+