#!/usr/bin/env ruby require 'json' def salt_state(output) out = JSON.parse(output) states = out["local"].values drifted_states = states.reject { |i| i["result"] } num_ok = states.count - drifted_states.count total = states.count state = num_ok == total ? "ok" : "warning" "#{state}:#{num_ok}:#{total}" end timeout = ARGV.shift || 240 begin out = `timeout -k 60s #{timeout}s salt-call state.highstate test=True --out=json --state-output=changes 2>/dev/null` if $?.exitstatus == 0 puts salt_state(out) else puts "error:unknown:unknown" end rescue puts "exception:unknown:unknown" end