From efb5cd4130e7fec04009905028f817ea6c02c79c Mon Sep 17 00:00:00 2001 From: Michael Tate Date: Thu, 14 Nov 2013 15:59:26 -0500 Subject: [PATCH] more Community Day nagios plugins courtesy of Michael Tate Signed-off-by: Jason Etheridge --- monitoring/nagios/check_at_failures | 69 ++++++++++++++++++++++++++++++++++ monitoring/nagios/check_at_pending | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 monitoring/nagios/check_at_failures create mode 100644 monitoring/nagios/check_at_pending diff --git a/monitoring/nagios/check_at_failures b/monitoring/nagios/check_at_failures new file mode 100644 index 0000000..3d9fe10 --- /dev/null +++ b/monitoring/nagios/check_at_failures @@ -0,0 +1,69 @@ +#!/bin/bash +# Copyright (C) 2008-2013 Equinox Software, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Author : Michael Tate, Sys Admin, ESI +# Purpose : Check for Action Trigger Event Failures and list them. +USAGE="check_at_failures (CRIT > 1)" + +if [[ $1 == *help* ]]; then + echo "$USAGE" + exit 0 +fi + +# GET/SET VARIABLES + # database name + if [ -n "$1" ]; then + DBNAME="$1" + else + DBNAME="evergreen" + fi + + # database user name + if [ -n "$2" ]; then + DBUSER="$2" + else + DBUSER="evergreen" + fi + + # port database runs on + if [ -n "$3" ]; then + DBPORT="$3" + else + DBPORT=5432 + fi + +# Execute AT Error Count +AT_ERR_COUNT=`PGUSER=postgres psql -U $DBUSER -d $DBNAME -p $DBPORT -c "select count(name) from action_trigger.event_definition where id IN (select distinct event_def from action_trigger.event where (state='error' or error_output is not null) and date(add_time)=date(now()));"|sed -n 3p|cut -d: -f1|sed 's/^[ \t]*//'` + +# Result Analysis + if [ "$AT_ERR_COUNT" -gt 1 ]; then + AT_ERR_LIST=`PGUSER=postgres psql -U $DBUSER -d $DBNAME -p $DBPORT -c "select name as ename from action_trigger.event_definition where id IN (select distinct event_def from action_trigger.event where (state='error' or error_output is not null) and date(add_time)=date(now()));"|grep -v "ename\|----\|rows"|awk '{printf "%s,",$0} END {print ""}'` + EXITSTATUS="CRIT: $AT_ERR_COUNT Action Trigger Events Have Failed: ($AT_ERR_LIST)" + EXITCODE=2 + elif [ "$AT_ERR_COUNT" -gt 0 ]; then + AT_ERR_NAMES=`PGUSER=postgres psql -U $DBUSER -d $DBNAME -p $DBPORT -c "select name as ename from action_trigger.event_definition where id IN (select distinct event_def from action_trigger.event where (state='error' or error_output is not null) and date(add_time)=date(now()));"|grep -v "ename\|----\|row"` + EXITSTATUS="CRIT: Action Trigger Event Has Failed: (`echo -n $AT_ERR_NAMES`)" + EXITCODE=2 + elif [ "$AT_ERR_COUNT" -eq 0 ]; then + EXITSTATUS="OK: No Action Trigger Event Failures" + EXITCODE=0 + else + EXITSTATUS="WARN: Something is wrong with the plugin." + EXITCODE=1 + fi + +# Return results +echo "$EXITSTATUS" +exit $EXITCODE + + diff --git a/monitoring/nagios/check_at_pending b/monitoring/nagios/check_at_pending new file mode 100644 index 0000000..36ebc0a --- /dev/null +++ b/monitoring/nagios/check_at_pending @@ -0,0 +1,74 @@ +#!/bin/bash +# Copyright (C) 2008-2011 Equinox Software, Inc. +# Written by Michael Tate +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# +# Author : MTate, Sys Admin, ESI +# Purpose : Count AT pending events +# Usage : check_at_pending + +if [[ $1 == *help* ]]; then + echo "Usage: check_dbquery " + exit 0 +fi + +# SET/GET VARIABLES + # database name + if [ -n "$1" ]; then + DBNAME="$1" + else + DBNAME="evergreen" + fi + + # database user name + if [ -n "$2" ]; then + DBUSER="$1" + else + DBUSER="evergreen" + fi + + # port database runs on + if [ -n "$3" ]; then + DBPORT="$3" + else + DBPORT=5432 + fi + +# Execute AT Pending Count +ATPENDING=`PGUSER=postgres psql -U $DBUSER -d $DBNAME -p $DBPORT -c "select count(*) from action_trigger.event where state ='pending';"|sed -n '3'p` + +CTWARN=900000 # These values will need modification +CTCRIT=1000000 # to what is normal for your environment. + # Run the check manually for two weeks + # to gather the needed info + +# Result Analysis + if [ $ATPENDING -gt $CTCRIT ]; then + EXITSTATUS="CRITICAL: $ATPENDING AT events pending" + EXITCODE=2 + elif [ $ATPENDING -gt $CTWARN ]; then + EXITSTATUS="WARNING: $ATPENDING AT events pending" + EXITCODE=1 + elif [ $ATPENDING -gt 0 ]; then + EXITSTATUS="OK: $ATPENDING AT events pending" + EXITCODE=0 + else + if [[ $ATPENDING == "-00" ]]; then + EXITSTATUS="OK: No AT events pending" + EXITCODE=0 + fi + fi + +# Return results +echo "$EXITSTATUS" +exit $EXITCODE -- 2.11.0