2 # Copyright (C) 2008-2013 Equinox Software, Inc.
\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
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
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
18 if [[ $1 == *help* ]]; then
\r
25 if [ -n "$1" ]; then
\r
31 # database user name
\r
32 if [ -n "$2" ]; then
\r
38 # port database runs on
\r
39 if [ -n "$3" ]; then
\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
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
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
57 elif [ "$AT_ERR_COUNT" -eq 0 ]; then
\r
58 EXITSTATUS="OK: No Action Trigger Event Failures"
\r
61 EXITSTATUS="WARN: Something is wrong with the plugin."
\r