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