Benjamin Renard commited on 2014-12-08 12:57:03
Showing 2 changed files, with 98 additions and 0 deletions.
... | ... |
@@ -0,0 +1,96 @@ |
1 |
+#!/bin/bash |
|
2 |
+# Lock file path |
|
3 |
+LOCK_FILE="" |
|
4 |
+# Lock file valid owner |
|
5 |
+VALID_OWNER="" |
|
6 |
+# WARNING time in hours |
|
7 |
+WARN=12 |
|
8 |
+# Critical time in hours |
|
9 |
+CRIT=24 |
|
10 |
+# Debug mode |
|
11 |
+DEBUG=0 |
|
12 |
+ |
|
13 |
+function usage() { |
|
14 |
+ echo "Check lock file status" |
|
15 |
+ echo |
|
16 |
+ echo " -l /path/to/lock.file Path to lock file" |
|
17 |
+ echo " -o uid Valid lock file owner (optional)" |
|
18 |
+ echo " -w W Exit with WARNING status if lock file" |
|
19 |
+ echo " has been created for more than W hours" |
|
20 |
+ echo " -c C Exit with CRITICAL status if lock file" |
|
21 |
+ echo " has been created for more than C hours" |
|
22 |
+ echo " -d Enable debug mode" |
|
23 |
+ echo " -h Show this message" |
|
24 |
+} |
|
25 |
+ |
|
26 |
+while getopts :l:o:w:c:dh FLAG |
|
27 |
+do |
|
28 |
+ [ $DEBUG -eq 1 ] && echo "Parameter $FLAG present. Value : '$OPTARG'" |
|
29 |
+ case $FLAG in |
|
30 |
+ l) |
|
31 |
+ LOCK_FILE=$OPTARG |
|
32 |
+ ;; |
|
33 |
+ o) |
|
34 |
+ VALID_OWNER=$OPTARG |
|
35 |
+ ;; |
|
36 |
+ w) |
|
37 |
+ [ $( echo "$OPTARG"|grep -c -e "^[0-9][0-9]*$" ) -ne 1 ] && echo "Invalid WARNING parameter (-w). Must be an integer" && exit 1 |
|
38 |
+ WARN=$OPTARG |
|
39 |
+ ;; |
|
40 |
+ c) |
|
41 |
+ [ $( echo "$OPTARG"|grep -c -e "^[0-9][0-9]*$" ) -ne 1 ] && echo "Invalid CRITICAL parameter (-c). Must be an integer" && exit 1 |
|
42 |
+ CRIT=$OPTARG |
|
43 |
+ ;; |
|
44 |
+ d) |
|
45 |
+ DEBUG=1 |
|
46 |
+ ;; |
|
47 |
+ h) |
|
48 |
+ usage |
|
49 |
+ exit 0 |
|
50 |
+ ;; |
|
51 |
+ esac |
|
52 |
+done |
|
53 |
+ |
|
54 |
+[ -z "$LOCK_FILE" ] && echo "You must specify the lock file path (-l parameter)." && usage && exit 1 |
|
55 |
+ |
|
56 |
+if [ ! -d "$( dirname $LOCK_FILE )" ] |
|
57 |
+then |
|
58 |
+ echo "UNKNWON - Lock file's parent directory does not exists." |
|
59 |
+ exit 3 |
|
60 |
+fi |
|
61 |
+[ $DEBUG -eq 1 ] && ls -ld "$( dirname $LOCK_FILE )" |
|
62 |
+ |
|
63 |
+if [ -f $LOCK_FILE ] |
|
64 |
+then |
|
65 |
+ # Check owner |
|
66 |
+ if [ ! -z "$VALID_OWNER" -a $( ls -al $LOCK_FILE|awk '{print $3}' ) != "$VALID_OWNER" ] |
|
67 |
+ then |
|
68 |
+ echo "CRITICAL - Lock file present but not owned by $VALID_OWNER" |
|
69 |
+ exit 2 |
|
70 |
+ fi |
|
71 |
+ |
|
72 |
+ T=$( ls -al --time-style=+%s $LOCK_FILE|awk '{print $6}' ) |
|
73 |
+ CUR=$( date +%s ) |
|
74 |
+ let diff=CUR-T |
|
75 |
+ |
|
76 |
+ let WARN_TIME=WARN*3600 |
|
77 |
+ let CRIT_TIME=CRIT*3600 |
|
78 |
+ |
|
79 |
+ # CRITICAL if diff > $CRIT |
|
80 |
+ if [ $diff -gt $CRIT_TIME ] |
|
81 |
+ then |
|
82 |
+ echo "CRITICAL - Parser lock file present since more than ${CRIT}h" |
|
83 |
+ exit 2 |
|
84 |
+ # WARNING if diff > $WARN |
|
85 |
+ elif [ $diff -gt $WARN_TIME ] |
|
86 |
+ then |
|
87 |
+ echo "WARNING - Parser lock file present since more than ${WARN}h" |
|
88 |
+ exit 1 |
|
89 |
+ else |
|
90 |
+ echo "OK - Lock file present since less than ${WARN}h" |
|
91 |
+ exit 0 |
|
92 |
+ fi |
|
93 |
+else |
|
94 |
+ echo 'OK - Lock file not present' |
|
95 |
+ exit 0 |
|
96 |
+fi |
|
0 | 97 |