From 536bd24438799a15686415b054f57676b053702d Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 30 Sep 2021 23:32:45 +0200 Subject: move --- Makefile | 2 +- check_ipmi | 75 ------------------------------ check_jenkins_job | 29 ------------ check_mem | 51 --------------------- check_pressure | 72 ----------------------------- check_sensors | 30 ------------ check_snmp_if | 114 ---------------------------------------------- check_systemd | 25 ---------- plugins/check_ipmi | 75 ++++++++++++++++++++++++++++++ plugins/check_jenkins_job | 29 ++++++++++++ plugins/check_mem | 51 +++++++++++++++++++++ plugins/check_pressure | 72 +++++++++++++++++++++++++++++ plugins/check_sensors | 30 ++++++++++++ plugins/check_snmp_if | 114 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/check_systemd | 25 ++++++++++ 15 files changed, 397 insertions(+), 397 deletions(-) delete mode 100755 check_ipmi delete mode 100755 check_jenkins_job delete mode 100755 check_mem delete mode 100755 check_pressure delete mode 100755 check_sensors delete mode 100755 check_snmp_if delete mode 100755 check_systemd create mode 100755 plugins/check_ipmi create mode 100755 plugins/check_jenkins_job create mode 100755 plugins/check_mem create mode 100755 plugins/check_pressure create mode 100755 plugins/check_sensors create mode 100755 plugins/check_snmp_if create mode 100755 plugins/check_systemd diff --git a/Makefile b/Makefile index 0474b60..e5b9f30 100644 --- a/Makefile +++ b/Makefile @@ -5,5 +5,5 @@ build: install: build @mkdir -p $(INSTDIR) - @cp check_* $(INSTDIR) + @cp plugins/* $(INSTDIR) diff --git a/check_ipmi b/check_ipmi deleted file mode 100755 index b1223ee..0000000 --- a/check_ipmi +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -#-I lanplus -U -P -L User -H - -2>&2 > /dev/null which ipmitool || exit 3 - -# also replaces na with "" -function strip_string() { - local RETURN="" - [ "$1" = "na" ] || RETURN="$@" - echo "$RETURN" -} - -function float_compare() { - [ $# -ne 2 ] && return 1 - - (( $(echo "$1 > $2" | bc -l ) )) && return 0 - return 1 -} - -WARN=() -CRIT=() - -PERFDATA=() - -DATA="$(ipmitool $@ sensor list; exit $?)" -RET=$? - -if [ $RET -ne 0 ]; then - echo UNKOWN: IPMI error - echo "$DATA" - exit 3 -fi - -# Lower Non-Recoverable : na -# Lower Critical : 5.000 -# Lower Non-Critical : 10.000 -# Upper Non-Critical : 61.000 -# Upper Critical : 66.000 -# Upper Non-Recoverable : na -while IFS='|' read sensor value unit state lnr lc lw uw uc unr ; do - val="$( strip_string $value )" - [ -z $val ] && continue - - unt="$( strip_string $unit )" - [ -z "$unt" -o "$unt" = "discrete" ] && continue - - snsr="$( strip_string $sensor )" - - low_warn="$( strip_string $lw )" - low_crit="$( strip_string $lc )" - hi_warn="$( strip_string $uw )" - hi_crit="$( strip_string $uc )" - - if float_compare $val $hi_crit || float_compare $low_crit $val; then - CRIT+=("$snsr") - elif float_compare $val $hi_warn || float_compare $low_warn $val; then - WARN+=("$snsr") - fi - - PERFDATA+=("$snsr=$val;$low_warn${hi_warn:+:$hi_warn};$low_crit${hi_crit:+:$hi_crit}") -done <<< "$DATA" - -if [ ${#WARN[@]} -gt 0 ]; then - echo -n "IPMI WARNING: ${WARN[@]}" - RET=1 -elif [ ${#CRIT[@]} -gt 0 ]; then - echo -n "IPMI CRITICAL: ${CRIT[@]}" - RET=2 -else - echo -n "IPMI OK" - RET=0 -fi - -echo "|${PERFDATA[@]}" diff --git a/check_jenkins_job b/check_jenkins_job deleted file mode 100755 index ab40f87..0000000 --- a/check_jenkins_job +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# Usage: check_jenkins_job - -if [ "$#" -lt 3 ]; then - echo "Usage: $0 " - exit 3 -fi - -JENKINS_URL=$1 -VIEW=$2 -JOB=$3 -PASS=$5 -USER=$4 - -shift 5 - -CURL_OUT=$( curl -s --basic -u "$USER:$PASS" $@ $JENKINS_URL/view/$VIEW/job/$JOB/lastBuild/api/json ) - -RESULT=$( jq -r .result <<< $CURL_OUT ) -ID=$( jq -r .displayName <<< $CURL_OUT ) - -if [ "$RESULT" = "SUCCESS" ]; then - echo JOB OK: $JOB $ID succeeded - exit 0 -fi - -echo JOB CRITICAL: $JOB $ID failed -exit 2 diff --git a/check_mem b/check_mem deleted file mode 100755 index 09b4ba8..0000000 --- a/check_mem +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -if [ $# -ne 2 ]; then - cat << EOF -Check memory usage. Values: used% -USAGE: $0 -Note: USED=TOTAL-AVAILABLE -EOF - exit 3 -fi - -WARN=$1 -CRIT=$2 - -if ! which free > /dev/null; then - echo UNKNOWN: free command not found. - exit 3 -fi - -TOTAL=0 -USED=0 -AVAIL=0 - -while read line; do - ARR=( $line ) - [ ${ARR[0]} != "Mem:" ] && continue - - TOTAL=${ARR[1]} - AVAIL=${ARR[6]} - USED=$(($TOTAL-$AVAIL)) - - break -done <<< $(free | tail -n -2) - -PERCENT_USED=$(echo "scale=4; $USED / $TOTAL * 100 " | bc -l) -PERCENT_USED=${PERCENT_USED%00} -PERCENT_USED_INT=${PERCENT_USED%.*} - -if [ $PERCENT_USED_INT -ge $CRIT ]; then - RET=2 - echo -n "Memory CRITICAL: " -elif [ $PERCENT_USED_INT -ge $WARN ]; then - RET=1 - echo -n "Memory WARNING: " -else - RET=0 - echo -n "Memory OK: " -fi - -echo "$PERCENT_USED% Used | percent_used=$PERCENT_USED% total=$TOTAL available=$AVAIL" -exit $RET diff --git a/check_pressure b/check_pressure deleted file mode 100755 index 787827c..0000000 --- a/check_pressure +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash - -#USAGE: check_pressure cpu|io|memory some|full [--10 w,c] [--60 w,c] [--300 w,c] - -RESULTS=(OK WARNING CRITICAL UNKNOWN) - -fail() { - local RET=$1 - shift - echo "$@" - exit $RET -} - -float_compare() { - [ $# -ne 2 ] && return 1 - - (( $(echo "$1 > $2" | bc -l ) )) && return 0 - return 1 -} - -# pressure is a relatively new feature. Ignore if not present. -[ ! -e "/proc/pressure" ] && fail 0 pressure API not present - -RESOURCE="$1" -[ ! -e "/proc/pressure/$RESOURCE" ] && fail 3 invalid resource \""$RESOURCE"\" -shift - -( echo "$1" | grep "^some$\|^full$" > /dev/null ) \ - || fail 3 \""$1"\" invalid. must be \"some\" or \"full\" -MODE="$1" - -while shift; do - case "$1" in - "--10") - VAL[0]="$2" - shift;; - "--60") - VAL[1]="$2" - shift;; - "--300") - VAL[2]="$2" - shift;; - "");; - *) - fail 3 "Unkown argument: \"$1\"" - ;; - esac -done - -[ "${#VAL[@]}" -eq 0 ] && fail 3 "At least one set of threshholds must be set" - -read MD avg10 avg60 avg300 catch < <(grep "$MODE" "/proc/pressure/$RESOURCE") \ - || fail 3 "Parsing of file failed. Does $RESOURCE support $MODE?" - -AVG=( "$avg10" "$avg60" "$avg300" ) -WARNING_OFFENDERS=() -CRITICAL_OFFENDERS=() - -for i in 0 1 2; do - [ -z "${VAL[$i]}" ] && continue - IFS=',' read WARN CRIT <<< "${VAL[$i]}" - IFS='=' read KEY VALUE <<< "${AVG[$i]}" - - float_compare "$VALUE" "$CRIT" && CRITICAL_OFFENDERS+=("$KEY($VALUE)=C") && continue - float_compare "$VALUE" "$WARN" && WARNING_OFFENDERS+=("$KEY($VALUE)=W") -done - -WORST=0 -[ ${#WARNING_OFFENDERS[@]} -gt 0 ] && WORST=1 -[ ${#CRITICAL_OFFENDERS[@]} -gt 0 ] && WORST=2 - -echo "PRESSURE ${RESULTS[$WORST]}: ${CRITICAL_OFFENDERS[@]} ${WARNING_OFFENDERS[@]} | ${AVG[@]}" diff --git a/check_sensors b/check_sensors deleted file mode 100755 index 8cb1e20..0000000 --- a/check_sensors +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# °C -WARN=75 -CRIT=85 - -PERFDATA="|" -IS_WARN="false" -IS_CRIT="false" - -TEXT=(OK WARNING CRITICAL UNKOWN) -LEVEL=0 - -DATA=( $(sensors | \ - grep "^Core" | \ - sed -n "s|^Core\s[0-9]\+:\s\++\([0-9]\+\.[0-9]\+\).*$|\1|p" ) ) - -for (( i=0; i<${#DATA[@]}; i++ )); do - (( $(echo "${DATA[$i]} > $WARN" | bc -l ) )) && IS_WARN="true" - (( $(echo "${DATA[$i]} > $CRIT" | bc -l ) )) && IS_CRIT="true" - PERFDATA+=" core_$i=${DATA[$i]}C" -done - -[ $IS_WARN = true ] && LEVEL=1 -[ $IS_CRIT = true ] && LEVEL=2 -[ ${#DATA[@]} -eq 0 ] && LEVEL=3 - -echo "sensors ${TEXT[$LEVEL]}$PERFDATA" - -exit $LEVEL diff --git a/check_snmp_if b/check_snmp_if deleted file mode 100755 index 5d56ae3..0000000 --- a/check_snmp_if +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash - -# https://ixnfo.com/en/snmp-oid-and-mib-for-interfaces.html -# https://oidref.com/1.3.6.1.2.1.2.2.1 -# https://bestmonitoringtools.com/mibdb/mibdb_search.php?mib=IF-MIB - -RESULTS=(OK WARNING CRITICAL UNKNOWN) - -readonly MIB_IFOPERSTATUS="1.3.6.1.2.1.2.2.1.8" -readonly MIB_ALIAS="1.3.6.1.2.1.31.1.1.1.18" -readonly MIB_NAME="1.3.6.1.2.1.31.1.1.1.1" -readonly MIB_IN="1.3.6.1.2.1.31.1.1.1.6" -readonly MIB_OUT="1.3.6.1.2.1.31.1.1.1.10" -readonly MIB_ERR_IN="1.3.6.1.2.1.2.2.1.14" -readonly MIB_ERR_OUT="1.3.6.1.2.1.2.2.1.20" - -perror() { - echo "$@" -} >&2 - -fail() { - local RET=$1 - shift - perror "$@" - exit $RET -} - -result() { - local RET=$1 - shift - echo -n "SNMP IF ${RESULTS[$RET]}: $@" - perfdata - exit $RET -} - -walk() { - snmpwalk $AUTH "$HOSTNAME" "$1" - return $? -} - -extract_val() { - sed -n 's/.*=\(.*\)/\1/p' | sed -n 's/.*:\s*\(.*\)/\1/p' | tr -d "\"'" -} - -perfdata() { - [ $GENPERFDATA -eq 0 ] && return - - echo -n "| " - echo -n "in=$INOCTETS " - echo -n "out=$OUTOCTETS " - echo -n "in_err=$INERRORS " - echo -n "out_err=$OUTERRORS " - echo -} - -GENPERFDATA=0 - -while getopts ":H:c:i:u:p:" opt; do - case $opt in - H) - HOSTNAME="$OPTARG" - ;; - c) - COMMUNITY="$OPTARG" - ;; - i) - INTERFACE="$OPTARG" - ;; - u) - SNMP_USER="$OPTARG" - ;; - p) - SNMP_PW="$OPTARG" - ;; - :) - fail 3 "$OPTARG requires Argument." - ;; - *) - fail 3 "Invalid option $OPTARG" - esac -done - -AUTH="" -if [ -n "$COMMUNITY" ]; then - AUTH="-c $COMMUNITY -v 2c" -elif [ -n "$SNMP_USER" ] && [ -n "$SNMP_PW" ]; then - AUTH="-v 3 -u $SNMP_USER -A $SNMP_PW -l authNoPriv" -else - result 3 "No or insufficient authentication info provided" -fi - -SNMPWALK_RESULT=$(walk "$MIB_IFOPERSTATUS.$INTERFACE"; exit $?) -RET=$? - -[ $RET -ne 0 ] && result 3 "snmpwalk failed with code $RET: $SNMPWALK_RESULT" -[ -z "$SNMPWALK_RESULT" ] && result 2 "No matching entry found." - -GENPERFDATA=1 - -NAME=$(walk "$MIB_NAME.$INTERFACE" | extract_val) -ALIAS=$(walk "$MIB_ALIAS.$INTERFACE" | extract_val) - -COMPLETE_NAME="$NAME" -if [ -n "$ALIAS" ]; then COMPLETE_NAME+=" ($ALIAS)"; fi - -INOCTETS=$(walk "$MIB_IN.$INTERFACE" | extract_val) -OUTOCTETS=$(walk "$MIB_OUT.$INTERFACE" | extract_val) - -INERRORS=$(walk "$MIB_ERR_IN.$INTERFACE" | extract_val) -OUTERRORS=$(walk "$MIB_ERR_OUT.$INTERFACE" | extract_val) - -extract_val <<< "$SNMPWALK_RESULT" | grep "up\|1" > /dev/null && result 0 "$COMPLETE_NAME is up." - -result 2 "$COMPLETE_NAME $INTERFACE is not up: $SNMPWALK_RESULT" diff --git a/check_systemd b/check_systemd deleted file mode 100755 index bf8d532..0000000 --- a/check_systemd +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# USAGE: -# check_systemd [UNIT ...] - -FAILED=() - -for unit in "$@"; do - if ! systemctl is-active "$unit" > /dev/null; then - FAILED+=("$unit") - fi -done - -if [ ${#FAILED[@]} -gt 0 ]; then - echo "systemd CRITICAL: failed units: ${FAILED[@]}" - exit 2 -fi - -#if ! systemctl is-system-running > /dev/null; then -# echo systemd WARNING: System state degraded. -# exit 1 -#fi - -echo "systemd OK: $# units checked" -exit 0 diff --git a/plugins/check_ipmi b/plugins/check_ipmi new file mode 100755 index 0000000..b1223ee --- /dev/null +++ b/plugins/check_ipmi @@ -0,0 +1,75 @@ +#!/bin/bash + +#-I lanplus -U -P -L User -H + +2>&2 > /dev/null which ipmitool || exit 3 + +# also replaces na with "" +function strip_string() { + local RETURN="" + [ "$1" = "na" ] || RETURN="$@" + echo "$RETURN" +} + +function float_compare() { + [ $# -ne 2 ] && return 1 + + (( $(echo "$1 > $2" | bc -l ) )) && return 0 + return 1 +} + +WARN=() +CRIT=() + +PERFDATA=() + +DATA="$(ipmitool $@ sensor list; exit $?)" +RET=$? + +if [ $RET -ne 0 ]; then + echo UNKOWN: IPMI error + echo "$DATA" + exit 3 +fi + +# Lower Non-Recoverable : na +# Lower Critical : 5.000 +# Lower Non-Critical : 10.000 +# Upper Non-Critical : 61.000 +# Upper Critical : 66.000 +# Upper Non-Recoverable : na +while IFS='|' read sensor value unit state lnr lc lw uw uc unr ; do + val="$( strip_string $value )" + [ -z $val ] && continue + + unt="$( strip_string $unit )" + [ -z "$unt" -o "$unt" = "discrete" ] && continue + + snsr="$( strip_string $sensor )" + + low_warn="$( strip_string $lw )" + low_crit="$( strip_string $lc )" + hi_warn="$( strip_string $uw )" + hi_crit="$( strip_string $uc )" + + if float_compare $val $hi_crit || float_compare $low_crit $val; then + CRIT+=("$snsr") + elif float_compare $val $hi_warn || float_compare $low_warn $val; then + WARN+=("$snsr") + fi + + PERFDATA+=("$snsr=$val;$low_warn${hi_warn:+:$hi_warn};$low_crit${hi_crit:+:$hi_crit}") +done <<< "$DATA" + +if [ ${#WARN[@]} -gt 0 ]; then + echo -n "IPMI WARNING: ${WARN[@]}" + RET=1 +elif [ ${#CRIT[@]} -gt 0 ]; then + echo -n "IPMI CRITICAL: ${CRIT[@]}" + RET=2 +else + echo -n "IPMI OK" + RET=0 +fi + +echo "|${PERFDATA[@]}" diff --git a/plugins/check_jenkins_job b/plugins/check_jenkins_job new file mode 100755 index 0000000..ab40f87 --- /dev/null +++ b/plugins/check_jenkins_job @@ -0,0 +1,29 @@ +#!/bin/bash + +# Usage: check_jenkins_job + +if [ "$#" -lt 3 ]; then + echo "Usage: $0 " + exit 3 +fi + +JENKINS_URL=$1 +VIEW=$2 +JOB=$3 +PASS=$5 +USER=$4 + +shift 5 + +CURL_OUT=$( curl -s --basic -u "$USER:$PASS" $@ $JENKINS_URL/view/$VIEW/job/$JOB/lastBuild/api/json ) + +RESULT=$( jq -r .result <<< $CURL_OUT ) +ID=$( jq -r .displayName <<< $CURL_OUT ) + +if [ "$RESULT" = "SUCCESS" ]; then + echo JOB OK: $JOB $ID succeeded + exit 0 +fi + +echo JOB CRITICAL: $JOB $ID failed +exit 2 diff --git a/plugins/check_mem b/plugins/check_mem new file mode 100755 index 0000000..09b4ba8 --- /dev/null +++ b/plugins/check_mem @@ -0,0 +1,51 @@ +#!/bin/bash + +if [ $# -ne 2 ]; then + cat << EOF +Check memory usage. Values: used% +USAGE: $0 +Note: USED=TOTAL-AVAILABLE +EOF + exit 3 +fi + +WARN=$1 +CRIT=$2 + +if ! which free > /dev/null; then + echo UNKNOWN: free command not found. + exit 3 +fi + +TOTAL=0 +USED=0 +AVAIL=0 + +while read line; do + ARR=( $line ) + [ ${ARR[0]} != "Mem:" ] && continue + + TOTAL=${ARR[1]} + AVAIL=${ARR[6]} + USED=$(($TOTAL-$AVAIL)) + + break +done <<< $(free | tail -n -2) + +PERCENT_USED=$(echo "scale=4; $USED / $TOTAL * 100 " | bc -l) +PERCENT_USED=${PERCENT_USED%00} +PERCENT_USED_INT=${PERCENT_USED%.*} + +if [ $PERCENT_USED_INT -ge $CRIT ]; then + RET=2 + echo -n "Memory CRITICAL: " +elif [ $PERCENT_USED_INT -ge $WARN ]; then + RET=1 + echo -n "Memory WARNING: " +else + RET=0 + echo -n "Memory OK: " +fi + +echo "$PERCENT_USED% Used | percent_used=$PERCENT_USED% total=$TOTAL available=$AVAIL" +exit $RET diff --git a/plugins/check_pressure b/plugins/check_pressure new file mode 100755 index 0000000..787827c --- /dev/null +++ b/plugins/check_pressure @@ -0,0 +1,72 @@ +#!/bin/bash + +#USAGE: check_pressure cpu|io|memory some|full [--10 w,c] [--60 w,c] [--300 w,c] + +RESULTS=(OK WARNING CRITICAL UNKNOWN) + +fail() { + local RET=$1 + shift + echo "$@" + exit $RET +} + +float_compare() { + [ $# -ne 2 ] && return 1 + + (( $(echo "$1 > $2" | bc -l ) )) && return 0 + return 1 +} + +# pressure is a relatively new feature. Ignore if not present. +[ ! -e "/proc/pressure" ] && fail 0 pressure API not present + +RESOURCE="$1" +[ ! -e "/proc/pressure/$RESOURCE" ] && fail 3 invalid resource \""$RESOURCE"\" +shift + +( echo "$1" | grep "^some$\|^full$" > /dev/null ) \ + || fail 3 \""$1"\" invalid. must be \"some\" or \"full\" +MODE="$1" + +while shift; do + case "$1" in + "--10") + VAL[0]="$2" + shift;; + "--60") + VAL[1]="$2" + shift;; + "--300") + VAL[2]="$2" + shift;; + "");; + *) + fail 3 "Unkown argument: \"$1\"" + ;; + esac +done + +[ "${#VAL[@]}" -eq 0 ] && fail 3 "At least one set of threshholds must be set" + +read MD avg10 avg60 avg300 catch < <(grep "$MODE" "/proc/pressure/$RESOURCE") \ + || fail 3 "Parsing of file failed. Does $RESOURCE support $MODE?" + +AVG=( "$avg10" "$avg60" "$avg300" ) +WARNING_OFFENDERS=() +CRITICAL_OFFENDERS=() + +for i in 0 1 2; do + [ -z "${VAL[$i]}" ] && continue + IFS=',' read WARN CRIT <<< "${VAL[$i]}" + IFS='=' read KEY VALUE <<< "${AVG[$i]}" + + float_compare "$VALUE" "$CRIT" && CRITICAL_OFFENDERS+=("$KEY($VALUE)=C") && continue + float_compare "$VALUE" "$WARN" && WARNING_OFFENDERS+=("$KEY($VALUE)=W") +done + +WORST=0 +[ ${#WARNING_OFFENDERS[@]} -gt 0 ] && WORST=1 +[ ${#CRITICAL_OFFENDERS[@]} -gt 0 ] && WORST=2 + +echo "PRESSURE ${RESULTS[$WORST]}: ${CRITICAL_OFFENDERS[@]} ${WARNING_OFFENDERS[@]} | ${AVG[@]}" diff --git a/plugins/check_sensors b/plugins/check_sensors new file mode 100755 index 0000000..8cb1e20 --- /dev/null +++ b/plugins/check_sensors @@ -0,0 +1,30 @@ +#!/bin/bash + +# °C +WARN=75 +CRIT=85 + +PERFDATA="|" +IS_WARN="false" +IS_CRIT="false" + +TEXT=(OK WARNING CRITICAL UNKOWN) +LEVEL=0 + +DATA=( $(sensors | \ + grep "^Core" | \ + sed -n "s|^Core\s[0-9]\+:\s\++\([0-9]\+\.[0-9]\+\).*$|\1|p" ) ) + +for (( i=0; i<${#DATA[@]}; i++ )); do + (( $(echo "${DATA[$i]} > $WARN" | bc -l ) )) && IS_WARN="true" + (( $(echo "${DATA[$i]} > $CRIT" | bc -l ) )) && IS_CRIT="true" + PERFDATA+=" core_$i=${DATA[$i]}C" +done + +[ $IS_WARN = true ] && LEVEL=1 +[ $IS_CRIT = true ] && LEVEL=2 +[ ${#DATA[@]} -eq 0 ] && LEVEL=3 + +echo "sensors ${TEXT[$LEVEL]}$PERFDATA" + +exit $LEVEL diff --git a/plugins/check_snmp_if b/plugins/check_snmp_if new file mode 100755 index 0000000..5d56ae3 --- /dev/null +++ b/plugins/check_snmp_if @@ -0,0 +1,114 @@ +#!/bin/bash + +# https://ixnfo.com/en/snmp-oid-and-mib-for-interfaces.html +# https://oidref.com/1.3.6.1.2.1.2.2.1 +# https://bestmonitoringtools.com/mibdb/mibdb_search.php?mib=IF-MIB + +RESULTS=(OK WARNING CRITICAL UNKNOWN) + +readonly MIB_IFOPERSTATUS="1.3.6.1.2.1.2.2.1.8" +readonly MIB_ALIAS="1.3.6.1.2.1.31.1.1.1.18" +readonly MIB_NAME="1.3.6.1.2.1.31.1.1.1.1" +readonly MIB_IN="1.3.6.1.2.1.31.1.1.1.6" +readonly MIB_OUT="1.3.6.1.2.1.31.1.1.1.10" +readonly MIB_ERR_IN="1.3.6.1.2.1.2.2.1.14" +readonly MIB_ERR_OUT="1.3.6.1.2.1.2.2.1.20" + +perror() { + echo "$@" +} >&2 + +fail() { + local RET=$1 + shift + perror "$@" + exit $RET +} + +result() { + local RET=$1 + shift + echo -n "SNMP IF ${RESULTS[$RET]}: $@" + perfdata + exit $RET +} + +walk() { + snmpwalk $AUTH "$HOSTNAME" "$1" + return $? +} + +extract_val() { + sed -n 's/.*=\(.*\)/\1/p' | sed -n 's/.*:\s*\(.*\)/\1/p' | tr -d "\"'" +} + +perfdata() { + [ $GENPERFDATA -eq 0 ] && return + + echo -n "| " + echo -n "in=$INOCTETS " + echo -n "out=$OUTOCTETS " + echo -n "in_err=$INERRORS " + echo -n "out_err=$OUTERRORS " + echo +} + +GENPERFDATA=0 + +while getopts ":H:c:i:u:p:" opt; do + case $opt in + H) + HOSTNAME="$OPTARG" + ;; + c) + COMMUNITY="$OPTARG" + ;; + i) + INTERFACE="$OPTARG" + ;; + u) + SNMP_USER="$OPTARG" + ;; + p) + SNMP_PW="$OPTARG" + ;; + :) + fail 3 "$OPTARG requires Argument." + ;; + *) + fail 3 "Invalid option $OPTARG" + esac +done + +AUTH="" +if [ -n "$COMMUNITY" ]; then + AUTH="-c $COMMUNITY -v 2c" +elif [ -n "$SNMP_USER" ] && [ -n "$SNMP_PW" ]; then + AUTH="-v 3 -u $SNMP_USER -A $SNMP_PW -l authNoPriv" +else + result 3 "No or insufficient authentication info provided" +fi + +SNMPWALK_RESULT=$(walk "$MIB_IFOPERSTATUS.$INTERFACE"; exit $?) +RET=$? + +[ $RET -ne 0 ] && result 3 "snmpwalk failed with code $RET: $SNMPWALK_RESULT" +[ -z "$SNMPWALK_RESULT" ] && result 2 "No matching entry found." + +GENPERFDATA=1 + +NAME=$(walk "$MIB_NAME.$INTERFACE" | extract_val) +ALIAS=$(walk "$MIB_ALIAS.$INTERFACE" | extract_val) + +COMPLETE_NAME="$NAME" +if [ -n "$ALIAS" ]; then COMPLETE_NAME+=" ($ALIAS)"; fi + +INOCTETS=$(walk "$MIB_IN.$INTERFACE" | extract_val) +OUTOCTETS=$(walk "$MIB_OUT.$INTERFACE" | extract_val) + +INERRORS=$(walk "$MIB_ERR_IN.$INTERFACE" | extract_val) +OUTERRORS=$(walk "$MIB_ERR_OUT.$INTERFACE" | extract_val) + +extract_val <<< "$SNMPWALK_RESULT" | grep "up\|1" > /dev/null && result 0 "$COMPLETE_NAME is up." + +result 2 "$COMPLETE_NAME $INTERFACE is not up: $SNMPWALK_RESULT" diff --git a/plugins/check_systemd b/plugins/check_systemd new file mode 100755 index 0000000..bf8d532 --- /dev/null +++ b/plugins/check_systemd @@ -0,0 +1,25 @@ +#!/bin/bash + +# USAGE: +# check_systemd [UNIT ...] + +FAILED=() + +for unit in "$@"; do + if ! systemctl is-active "$unit" > /dev/null; then + FAILED+=("$unit") + fi +done + +if [ ${#FAILED[@]} -gt 0 ]; then + echo "systemd CRITICAL: failed units: ${FAILED[@]}" + exit 2 +fi + +#if ! systemctl is-system-running > /dev/null; then +# echo systemd WARNING: System state degraded. +# exit 1 +#fi + +echo "systemd OK: $# units checked" +exit 0 -- cgit v1.2.3