more Community Day nagios plugins
authorMichael Tate <mtate@esilibrary.com>
Thu, 14 Nov 2013 20:59:26 +0000 (15:59 -0500)
committerJason Etheridge <jason@esilibrary.com>
Thu, 14 Nov 2013 20:59:26 +0000 (15:59 -0500)
courtesy of Michael Tate

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
monitoring/nagios/check_at_failures [new file with mode: 0644]
monitoring/nagios/check_at_pending [new file with mode: 0644]

diff --git a/monitoring/nagios/check_at_failures b/monitoring/nagios/check_at_failures
new file mode 100644 (file)
index 0000000..3d9fe10
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/bash\r
+# Copyright (C) 2008-2013  Equinox Software, Inc.\r
+#\r
+# This program is free software; you can redistribute it and/or\r
+# modify it under the terms of the GNU General Public License\r
+# as published by the Free Software Foundation; either version 2\r
+# of the License, or (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+#\r
+# Author       : Michael Tate, Sys Admin, ESI\r
+# Purpose      : Check for Action Trigger Event Failures and list them.\r
+USAGE="check_at_failures  <db; default to 'evergreen' if empty> <username; default 'evergreen'> <port database runs on, default '5432'> (CRIT > 1)"\r
+\r
+if [[ $1 == *help* ]]; then\r
+   echo "$USAGE"\r
+   exit 0\r
+fi\r
+\r
+# GET/SET VARIABLES\r
+ # database name\r
+ if [ -n "$1" ]; then\r
+   DBNAME="$1"\r
+ else\r
+   DBNAME="evergreen"\r
+ fi\r
+\r
+ # database user name\r
+ if [ -n "$2" ]; then\r
+   DBUSER="$2"\r
+ else\r
+   DBUSER="evergreen"\r
+ fi\r
+\r
+ # port database runs on\r
+ if [ -n "$3" ]; then\r
+   DBPORT="$3"\r
+ else\r
+   DBPORT=5432\r
+ fi\r
+\r
+# Execute AT Error Count\r
+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]*//'`\r
+\r
+# Result Analysis\r
+ if [ "$AT_ERR_COUNT" -gt 1 ]; then\r
+   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 ""}'`\r
+   EXITSTATUS="CRIT: $AT_ERR_COUNT Action Trigger Events Have Failed: ($AT_ERR_LIST)"\r
+   EXITCODE=2\r
+ elif [ "$AT_ERR_COUNT" -gt 0 ]; then\r
+   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"`\r
+   EXITSTATUS="CRIT: Action Trigger Event Has Failed: (`echo -n $AT_ERR_NAMES`)"\r
+   EXITCODE=2\r
+ elif [ "$AT_ERR_COUNT" -eq 0 ]; then\r
+   EXITSTATUS="OK: No Action Trigger Event Failures"\r
+   EXITCODE=0\r
+ else\r
+   EXITSTATUS="WARN: Something is wrong with the plugin."\r
+   EXITCODE=1\r
+ fi\r
+\r
+# Return results\r
+echo "$EXITSTATUS"\r
+exit $EXITCODE\r
+\r
+\r
diff --git a/monitoring/nagios/check_at_pending b/monitoring/nagios/check_at_pending
new file mode 100644 (file)
index 0000000..36ebc0a
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/bash\r
+# Copyright (C) 2008-2011  Equinox Software, Inc.\r
+# Written by Michael Tate <mtate@esilibrary.com>\r
+#\r
+# This program is free software; you can redistribute it and/or\r
+# modify it under the terms of the GNU General Public License\r
+# as published by the Free Software Foundation; either version 2\r
+# of the License, or (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+#\r
+#\r
+# Author       : MTate, Sys Admin, ESI\r
+# Purpose      : Count AT pending events\r
+# Usage        : check_at_pending <db; default to "evergreen" if empty> <username; default "evergreen"> <port database runs on, default "5432">\r
+\r
+if [[ $1 == *help* ]]; then\r
+  echo "Usage: check_dbquery <db; default to 'evergreen' if empty> <username; default 'evergreen'> <port database runs on, default '5432'>"\r
+  exit 0\r
+fi\r
+\r
+# SET/GET VARIABLES\r
+ # database name\r
+ if [ -n "$1" ]; then\r
+   DBNAME="$1"\r
+ else\r
+   DBNAME="evergreen"\r
+ fi\r
+\r
+ # database user name\r
+ if [ -n "$2" ]; then\r
+   DBUSER="$1"\r
+ else\r
+   DBUSER="evergreen"\r
+ fi\r
+\r
+ # port database runs on\r
+ if [ -n "$3" ]; then\r
+   DBPORT="$3"\r
+ else\r
+   DBPORT=5432\r
+ fi\r
+\r
+# Execute AT Pending Count\r
+ATPENDING=`PGUSER=postgres psql -U $DBUSER -d $DBNAME -p $DBPORT -c "select count(*) from action_trigger.event where state ='pending';"|sed -n '3'p`\r
+\r
+CTWARN=900000  # These values will need modification\r
+CTCRIT=1000000 # to what is normal for your environment.\r
+                # Run the check manually for two weeks \r
+                # to gather the needed info\r
+\r
+# Result Analysis\r
+ if [ $ATPENDING -gt $CTCRIT ]; then\r
+   EXITSTATUS="CRITICAL: $ATPENDING AT events pending"\r
+   EXITCODE=2\r
+ elif [ $ATPENDING -gt $CTWARN ]; then\r
+   EXITSTATUS="WARNING:  $ATPENDING AT events pending"\r
+   EXITCODE=1\r
+ elif [ $ATPENDING -gt 0 ]; then\r
+   EXITSTATUS="OK:  $ATPENDING AT events pending"\r
+   EXITCODE=0\r
+ else\r
+   if [[ $ATPENDING == "-00" ]]; then\r
+     EXITSTATUS="OK: No AT events pending"\r
+     EXITCODE=0\r
+   fi\r
+ fi\r
+\r
+# Return results\r
+echo "$EXITSTATUS"\r
+exit $EXITCODE\r