Skip to content

Instantly share code, notes, and snippets.

@phoolish
Created May 22, 2013 14:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoolish/5627988 to your computer and use it in GitHub Desktop.
Save phoolish/5627988 to your computer and use it in GitHub Desktop.
Very basic collectd exec plugin that checks yum for updates and security updates and returns the count
#!/bin/bash
#
# Checks yum for updates and passes the count to collectd.
#
# Requriments:
# - collectd_exec_plugin
# - yum-plugin-security package
#
# <Plugin exec>
# Exec "nobody" "/path/to/yum_update.sh"
# </Plugin>
#
# Or to define the interval.
# <Plugin exec>
# Exec "nobody" "/path/to/yum_update.sh" "-i" "60000"
# </Plugin>
#
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
# run every 12 hours
INTERVAL="43200"
while getopts "i:" c; do
case $c in
i) INTERVAL=$OPTARG;;
*) echo "Usage: $0 [-i <interval in seconds>]";;
esac
done
while [ $? -eq 0 ]; do
updates=$(yum check-update -q | sed "1 d" | wc -l)
security_updates=$(yum check-update -q --security | sed "1 d" | wc -l)
echo "PUTVAL $HOSTNAME/yum/updates interval=$INTERVAL N:$updates"
echo "PUTVAL $HOSTNAME/yum/security_updates interval=$INTERVAL N:$security_updates"
sleep "$INTERVAL"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment