Skip to content

Instantly share code, notes, and snippets.

@hughsaunders
Created November 24, 2015 16:46
Show Gist options
  • Save hughsaunders/4ea07983e9a2f1ca6271 to your computer and use it in GitHub Desktop.
Save hughsaunders/4ea07983e9a2f1ca6271 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
run_plugin(){
config_file="$1"
# skip config files that don't define plugin checks
grep agent.plugin $config_file &>/dev/null || continue
plugin_file="$(awk '/^\s*file\s*:/{print $3}' <$config_file)"
plugin_args="$(awk '/args/{gsub(/\s*args\s*:\s*/, ""); print}' <$config_file |tr -d "\",'][")"
/usr/lib/rackspace-monitoring-agent/plugins/"$plugin_file" $plugin_args
}
for path in /etc/rackspace-monitoring-agent.conf.d/*.yaml
do
file=$(basename $path)
# run each plugin, prepending the file name to each line of output, store output in temp file
run_plugin "$file" |sed "s/^/$file /" >/tmp/maastesting
#output status line if pass, otherwise log full output.
grep 'status okay' /tmp/maastesting || cat /tmp/maastesting
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment