]> git.evergreen-ils.org Git - contrib/equinox.git/blob - monitoring/nagios/check_at_failures
errant line sending a copy of the row
[contrib/equinox.git] / monitoring / nagios / check_at_failures
1 #!/bin/bash\r
2 # Copyright (C) 2008-2013  Equinox Software, Inc.\r
3 #\r
4 # This program is free software; you can redistribute it and/or\r
5 # modify it under the terms of the GNU General Public License\r
6 # as published by the Free Software Foundation; either version 2\r
7 # of the License, or (at your option) any later version.\r
8 #\r
9 # This program is distributed in the hope that it will be useful,\r
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12 # GNU General Public License for more details.\r
13 #\r
14 # Author       : Michael Tate, Sys Admin, ESI\r
15 # Purpose      : Check for Action Trigger Event Failures and list them.\r
16 USAGE="check_at_failures  <db; default to 'evergreen' if empty> <username; default 'evergreen'> <port database runs on, default '5432'> (CRIT > 1)"\r
17 \r
18 if [[ $1 == *help* ]]; then\r
19    echo "$USAGE"\r
20    exit 0\r
21 fi\r
22 \r
23 # GET/SET VARIABLES\r
24  # database name\r
25  if [ -n "$1" ]; then\r
26    DBNAME="$1"\r
27  else\r
28    DBNAME="evergreen"\r
29  fi\r
30 \r
31  # database user name\r
32  if [ -n "$2" ]; then\r
33    DBUSER="$2"\r
34  else\r
35    DBUSER="evergreen"\r
36  fi\r
37 \r
38  # port database runs on\r
39  if [ -n "$3" ]; then\r
40    DBPORT="$3"\r
41  else\r
42    DBPORT=5432\r
43  fi\r
44 \r
45 # Execute AT Error Count\r
46 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
47 \r
48 # Result Analysis\r
49  if [ "$AT_ERR_COUNT" -gt 1 ]; then\r
50    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
51    EXITSTATUS="CRIT: $AT_ERR_COUNT Action Trigger Events Have Failed: ($AT_ERR_LIST)"\r
52    EXITCODE=2\r
53  elif [ "$AT_ERR_COUNT" -gt 0 ]; then\r
54    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
55    EXITSTATUS="CRIT: Action Trigger Event Has Failed: (`echo -n $AT_ERR_NAMES`)"\r
56    EXITCODE=2\r
57  elif [ "$AT_ERR_COUNT" -eq 0 ]; then\r
58    EXITSTATUS="OK: No Action Trigger Event Failures"\r
59    EXITCODE=0\r
60  else\r
61    EXITSTATUS="WARN: Something is wrong with the plugin."\r
62    EXITCODE=1\r
63  fi\r
64 \r
65 # Return results\r
66 echo "$EXITSTATUS"\r
67 exit $EXITCODE\r
68 \r
69 \r