summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_log.sh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/check_log.sh')
-rwxr-xr-xplugins-scripts/check_log.sh54
1 files changed, 27 insertions, 27 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index 4599268..8f76b1b 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -60,11 +60,11 @@
60 60
61PATH="@TRUSTED_PATH@" 61PATH="@TRUSTED_PATH@"
62export PATH 62export PATH
63PROGNAME=$(basename $0) 63PROGNAME=$(basename "$0")
64PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') 64PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,')
65REVISION="@NP_VERSION@" 65REVISION="@NP_VERSION@"
66 66
67. $PROGPATH/utils.sh 67. "$PROGPATH"/utils.sh
68 68
69print_usage() { 69print_usage() {
70 echo "Usage: $PROGNAME -F logfile -O oldlog -q query" 70 echo "Usage: $PROGNAME -F logfile -O oldlog -q query"
@@ -73,7 +73,7 @@ print_usage() {
73} 73}
74 74
75print_help() { 75print_help() {
76 print_revision $PROGNAME $REVISION 76 print_revision "$PROGNAME" "$REVISION"
77 echo "" 77 echo ""
78 print_usage 78 print_usage
79 echo "" 79 echo ""
@@ -87,7 +87,7 @@ print_help() {
87 87
88if [ $# -lt 1 ]; then 88if [ $# -lt 1 ]; then
89 print_usage 89 print_usage
90 exit $STATE_UNKNOWN 90 exit "$STATE_UNKNOWN"
91fi 91fi
92 92
93# Grab the command line arguments 93# Grab the command line arguments
@@ -100,19 +100,19 @@ while test -n "$1"; do
100 case "$1" in 100 case "$1" in
101 --help) 101 --help)
102 print_help 102 print_help
103 exit $STATE_OK 103 exit "$STATE_OK"
104 ;; 104 ;;
105 -h) 105 -h)
106 print_help 106 print_help
107 exit $STATE_OK 107 exit "$STATE_OK"
108 ;; 108 ;;
109 --version) 109 --version)
110 print_revision $PROGNAME $REVISION 110 print_revision "$PROGNAME" "$REVISION"
111 exit $STATE_OK 111 exit "$STATE_OK"
112 ;; 112 ;;
113 -V) 113 -V)
114 print_revision $PROGNAME $REVISION 114 print_revision "$PROGNAME" "$REVISION"
115 exit $STATE_OK 115 exit "$STATE_OK"
116 ;; 116 ;;
117 --filename) 117 --filename)
118 logfile=$2 118 logfile=$2
@@ -149,7 +149,7 @@ while test -n "$1"; do
149 *) 149 *)
150 echo "Unknown argument: $1" 150 echo "Unknown argument: $1"
151 print_usage 151 print_usage
152 exit $STATE_UNKNOWN 152 exit "$STATE_UNKNOWN"
153 ;; 153 ;;
154 esac 154 esac
155 shift 155 shift
@@ -157,22 +157,22 @@ done
157 157
158# If the source log file doesn't exist, exit 158# If the source log file doesn't exist, exit
159 159
160if [ ! -e $logfile ]; then 160if [ ! -e "$logfile" ]; then
161 echo "Log check error: Log file $logfile does not exist!" 161 echo "Log check error: Log file $logfile does not exist!"
162 exit $STATE_UNKNOWN 162 exit "$STATE_UNKNOWN"
163elif [ ! -r $logfile ] ; then 163elif [ ! -r "$logfile" ] ; then
164 echo "Log check error: Log file $logfile is not readable!" 164 echo "Log check error: Log file $logfile is not readable!"
165 exit $STATE_UNKNOWN 165 exit "$STATE_UNKNOWN"
166fi 166fi
167 167
168# If the old log file doesn't exist, this must be the first time 168# If the old log file doesn't exist, this must be the first time
169# we're running this test, so copy the original log file over to 169# we're running this test, so copy the original log file over to
170# the old diff file and exit 170# the old diff file and exit
171 171
172if [ ! -e $oldlog ]; then 172if [ ! -e "$oldlog" ]; then
173 cat $logfile > $oldlog 173 cat "$logfile" > "$oldlog"
174 echo "Log check data initialized..." 174 echo "Log check data initialized..."
175 exit $STATE_OK 175 exit "$STATE_OK"
176fi 176fi
177 177
178# The old log file exists, so compare it to the original log now 178# The old log file exists, so compare it to the original log now
@@ -184,20 +184,20 @@ if [ -x /bin/mktemp ]; then
184else 184else
185 tempdiff=$(/bin/date '+%H%M%S') 185 tempdiff=$(/bin/date '+%H%M%S')
186 tempdiff="/tmp/check_log.${tempdiff}" 186 tempdiff="/tmp/check_log.${tempdiff}"
187 touch $tempdiff 187 touch "$tempdiff"
188 chmod 600 $tempdiff 188 chmod 600 "$tempdiff"
189fi 189fi
190 190
191diff $logfile $oldlog | grep -v "^>" > $tempdiff 191diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
192 192
193# Count the number of matching log entries we have 193# Count the number of matching log entries we have
194count=$(grep -c "$query" $tempdiff) 194count=$(grep -c "$query" "$tempdiff")
195 195
196# Get the last matching entry in the diff file 196# Get the last matching entry in the diff file
197lastentry=$(grep "$query" $tempdiff | tail -1) 197lastentry=$(grep "$query" "$tempdiff" | tail -1)
198 198
199rm -f $tempdiff 199rm -f "$tempdiff"
200cat $logfile > $oldlog 200cat "$logfile" > "$oldlog"
201 201
202if [ "$count" = "0" ]; then # no matches, exit with no error 202if [ "$count" = "0" ]; then # no matches, exit with no error
203 echo "Log check ok - 0 pattern matches found" 203 echo "Log check ok - 0 pattern matches found"
@@ -207,4 +207,4 @@ else # Print total matche count and the last entry we found
207 exitstatus=$STATE_CRITICAL 207 exitstatus=$STATE_CRITICAL
208fi 208fi
209 209
210exit $exitstatus 210exit "$exitstatus"