Przeglądaj źródła

Salt-Check tut jetzt

Maximilian Wilhelm 4 lat temu
rodzic
commit
093fd08ac6
2 zmienionych plików z 12 dodań i 5 usunięć
  1. 2 1
      icinga2/init.sls
  2. 10 4
      icinga2/plugins/check_salt

+ 2 - 1
icinga2/init.sls

@@ -282,7 +282,8 @@ Cleanup /etc/icinga2/ffho-conf.d/net/wbbl/:
 
 salt-cron-state-apply:
   cron.present:
-    - name: /usr/bin/salt-call state.highstate --state-verbose=False test=True > /var/cache/salt/state_apply 2>/dev/null
+    - identifier: SALT_CRON_STATE_APPLY
+    - name: "/usr/bin/salt-call state.highstate --state-verbose=False test=True > /var/cache/salt/state_apply.tmp 2>/dev/null ; mv /var/cache/salt/state_apply.tmp /var/cache/salt/state_apply"
     - user: root
     - minute: random
     - hour: "*/6"

+ 10 - 4
icinga2/plugins/check_salt

@@ -6,11 +6,17 @@ if [ ! -f /var/cache/salt/state_apply ] ; then echo "Statefile does not exist" ;
 # 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
+if grep -o ' changed=\([0-9]\+\)' /var/cache/salt/state_apply > /dev/null ; then 
+
+	ANZ_CHANGED=$(grep -o ' changed=\([0-9]\+\)' /var/cache/salt/state_apply | cut -d= -f2)
 
+	if [ $ANZ_CHANGED -gt 0 ] ; then
+		echo "IDs with changes:"
+		cat /var/cache/salt/state_apply | grep "ID:"
+		exit 1 # warning
+	fi
+
+fi
 echo "Nothing to do"
 exit 0 # ok