Commit 1b8e177e authored by Haarst, Jan van's avatar Haarst, Jan van
Browse files

Added some nagios plugins

parent bcc8f1eb
#!/bin/sh
# Nagios plugin to check for regular and security updates availability
# Copyright (c) 2012-2014 Simon Deziel <simon.deziel@gmail.com>
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Explicitly set the PATH to that of ENV_SUPATH in /etc/login.defs and unset
# various other variables. For details, see:
# https://wiki.ubuntu.com/SecurityTeam/AppArmorPolicyReview#Execute_rules
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export ENV=
export CDPATH=
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
MSG_OK="APT OK"
MSG_WARNING="APT WARNING"
MSG_CRITICAL="APT CRITICAL"
MSG_UNKNOWN="APT UNKNOWN"
SCRIPT_NAME="$(basename $0)"
BIN="/usr/lib/update-notifier/apt-check"
GETOPT="/usr/bin/getopt"
perf_data="|"
check_timeout=10
verbosity="quiet"
do_hwe_check="true"
HWE_SUPPORT_STATUS_MSG=""
PATH_TO_HWE_SUPPORT_STATUS="/usr/bin/hwe-support-status"
TIMEOUT_BIN="$(/usr/bin/which timeout 2> /dev/null)"
p_ok () {
echo "$MSG_OK: $1$perf_data"
exit "$STATE_OK"
}
p_warning () {
echo "$MSG_WARNING: $1$perf_data"
exit "$STATE_WARNING"
}
p_critical () {
echo "$MSG_CRITICAL: $1$perf_data"
exit "$STATE_CRITICAL"
}
p_unknown () {
echo "$MSG_UNKNOWN: $1$perf_data"
exit "$STATE_UNKNOWN"
}
usage () {
cat << EOF
Usage:
$SCRIPT_NAME [-h] [-t timeout] [--skip-hwe-check]
Options:
-h
Print help screen
-v
Verbose execution
-t
Seconds before execution times out (default: 10)
--skip-hwe-check
Skip HWE support status check
EOF
}
long_usage () {
cat << EOF
Copyright (c) 2012-2014 Simon Deziel
This plugin checks for regular and security updates availability
EOF
usage
exit 0
}
hwe_support_status () {
[ -e "$PATH_TO_HWE_SUPPORT_STATUS" ] || return
HWE_SUPPORT_STATUS_MSG="; $($PATH_TO_HWE_SUPPORT_STATUS --$verbosity 2>&1)"
if [ "$?" != 0 ]; then
security_updates="$((security_updates + 1))"
fi
# Throw out the HWE_SUPPORT_STATUS_MSG if in quiet mode or if mostly empty
if [ "$verbosity" = "quiet" ] || [ "$HWE_SUPPORT_STATUS_MSG" = "; " ]; then
HWE_SUPPORT_STATUS_MSG=""
fi
}
# Check if getopt is available
if [ ! -x "$GETOPT" ]; then
p_unknown "$GETOPT is not available, hint install util-linux"
fi
# Note that we use `"$@"' to let each command-line parameter expand to a
# separate word. The quotes around `$@' are essential!
# We need TEMP as the `eval set --' would nuke the return value of getopt.
TEMP=`$GETOPT -q -s sh -n $SCRIPT_NAME -o +hvt: -l skip-hwe-check -- "$@"`
if [ $? != 0 ]; then
p_unknown "Unknown/invalid argument, see $SCRIPT_NAME -h for help"
fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
# Parse arguments
while test "$1" != "--"; do case "$1" in
-h) long_usage; shift;;
-v) verbosity="verbose"; shift;;
-t) echo "$2" | grep -qE '^[0-9]+(\.[0-9]+)?$' && check_timeout="$2"; shift 2;;
--skip-hwe-check) do_hwe_check="false"; shift;;
--) shift ; break;;
*) p_unknown "Internal error";;
esac
done
# Check if the required binary is present
if [ ! -x "$BIN" ]; then
p_unknown "$BIN is not available, hint install update-notifier-common"
fi
# Check if all worked
[ -n "$TIMEOUT_BIN" ] || check_timeout=""
updates="$($TIMEOUT_BIN $check_timeout $BIN 2>&1)"
RC="$?"
if [ "$RC" -eq 124 ]; then
p_critical "Plugin timed out after $check_timeout seconds"
elif [ "$RC" -ne 0 ]; then
p_unknown "$BIN returned $RC"
fi
# Check if output is well-formed
if ! echo "$updates" | grep -qE '^[0-9]+;[0-9]+$'; then
p_unknown "$BIN output not as expected: $updates"
fi
# All was fine so far so let's see how many updates are pending
regular_updates="$(echo "$updates"|cut -d ';' -f1)"
security_updates="$(echo "$updates"|cut -d ';' -f2)"
# Check for HWE support status
if [ "$do_hwe_check" = "true" ]; then
hwe_support_status
fi
# Gather the perf data
perf_data="|regular=$regular_updates;;;0 security=$security_updates;;1;0"
# Nothing pending?
if [ "$security_updates" != 0 ]; then
p_critical "$regular_updates updates available ($security_updates critical)$HWE_SUPPORT_STATUS_MSG"
elif [ "$regular_updates" != 0 ]; then
p_warning "$regular_updates updates available ($security_updates critical)$HWE_SUPPORT_STATUS_MSG"
else
p_ok "All packages are up-to-date$HWE_SUPPORT_STATUS_MSG"
fi
#!/bin/bash
#
# Created by Sebastian Grewe, Jammicron Technology
#
# https://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_md_raid/details
# Get count of raid arrays
RAID_DEVICES=`grep ^md -c /proc/mdstat`
# Get count of degraded arrays
#RAID_STATUS=`grep "\[.*_.*\]" /proc/mdstat -c`
RAID_STATUS=`egrep "\[.*(=|>|\.).*\]" /proc/mdstat -c`
# Is an array currently recovering, get percentage of recovery
RAID_RECOVER=`grep recovery /proc/mdstat | awk '{print $4}'`
RAID_RESYNC=`grep resync /proc/mdstat | awk '{print $4}'`
# Check raid status
# RAID recovers --> Warning
if [[ $RAID_RECOVER ]]; then
STATUS="WARNING - Checked $RAID_DEVICES arrays, recovering : $RAID_RECOVER"
EXIT=1
elif [[ $RAID_RESYNC ]]; then
STATUS="WARNING - Checked $RAID_DEVICES arrays, resync : $RAID_RESYNC"
EXIT=1
# RAID ok
elif [[ $RAID_STATUS == "0" ]]; then
STATUS="OK - Checked $RAID_DEVICES arrays."
EXIT=0
# All else critical, better save than sorry
else
EXTEND_RAID_STATUS=`egrep "\[.*(=|>|\.|_).*\]" /proc/mdstat | awk '{print $2}' | uniq -c | xargs echo`
STATUS="WARNING- Checked $RAID_DEVICES arrays, $RAID_STATUS have failed check: $EXTEND_RAID_STATUS "
EXIT=1
fi
# Status and quit
echo $STATUS
exit $EXIT
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment