diff options
Diffstat (limited to 'plugins-scripts/check_log.sh')
-rwxr-xr-x | plugins-scripts/check_log.sh | 54 |
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 | ||
61 | PATH="@TRUSTED_PATH@" | 61 | PATH="@TRUSTED_PATH@" |
62 | export PATH | 62 | export PATH |
63 | PROGNAME=$(basename $0) | 63 | PROGNAME=$(basename "$0") |
64 | PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') | 64 | PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') |
65 | REVISION="@NP_VERSION@" | 65 | REVISION="@NP_VERSION@" |
66 | 66 | ||
67 | . $PROGPATH/utils.sh | 67 | . "$PROGPATH"/utils.sh |
68 | 68 | ||
69 | print_usage() { | 69 | print_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 | ||
75 | print_help() { | 75 | print_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 | ||
88 | if [ $# -lt 1 ]; then | 88 | if [ $# -lt 1 ]; then |
89 | print_usage | 89 | print_usage |
90 | exit $STATE_UNKNOWN | 90 | exit "$STATE_UNKNOWN" |
91 | fi | 91 | fi |
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 | ||
160 | if [ ! -e $logfile ]; then | 160 | if [ ! -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" |
163 | elif [ ! -r $logfile ] ; then | 163 | elif [ ! -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" |
166 | fi | 166 | fi |
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 | ||
172 | if [ ! -e $oldlog ]; then | 172 | if [ ! -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" |
176 | fi | 176 | fi |
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 | |||
184 | else | 184 | else |
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" |
189 | fi | 189 | fi |
190 | 190 | ||
191 | diff $logfile $oldlog | grep -v "^>" > $tempdiff | 191 | diff "$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 |
194 | count=$(grep -c "$query" $tempdiff) | 194 | count=$(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 |
197 | lastentry=$(grep "$query" $tempdiff | tail -1) | 197 | lastentry=$(grep "$query" "$tempdiff" | tail -1) |
198 | 198 | ||
199 | rm -f $tempdiff | 199 | rm -f "$tempdiff" |
200 | cat $logfile > $oldlog | 200 | cat "$logfile" > "$oldlog" |
201 | 201 | ||
202 | if [ "$count" = "0" ]; then # no matches, exit with no error | 202 | if [ "$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 |
208 | fi | 208 | fi |
209 | 209 | ||
210 | exit $exitstatus | 210 | exit "$exitstatus" |