diff options
Diffstat (limited to 'web/attachments/154472-nagios_plugins-check_test.patch')
-rw-r--r-- | web/attachments/154472-nagios_plugins-check_test.patch | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/web/attachments/154472-nagios_plugins-check_test.patch b/web/attachments/154472-nagios_plugins-check_test.patch new file mode 100644 index 0000000..832c6a0 --- /dev/null +++ b/web/attachments/154472-nagios_plugins-check_test.patch | |||
@@ -0,0 +1,172 @@ | |||
1 | --- ../../original_sources/nagios-plugins-1.4.2/contrib/check_test 2005-10-11 20:24:13.349222200 -0400 | ||
2 | +++ nagios-plugins-1.4.2/contrib/check_test 2005-10-11 20:22:49.205014064 -0400 | ||
3 | @@ -0,0 +1,169 @@ | ||
4 | +#! /bin/bash | ||
5 | + | ||
6 | +# Author: John P. Rouillard - rouilj@cs.umb.edu, | ||
7 | +# rouilj-check_test@renesys.com | ||
8 | +# A quick and dirty test program similar to check_dummy, but exit | ||
9 | +# status is contollable from an external file. It can be used for | ||
10 | +# testing nagios service dependency and host dependency notification | ||
11 | +# suppression. | ||
12 | +# | ||
13 | +# Entries in the external file are composed of a label and an exit | ||
14 | +# code, or code list seperated by an = sign. | ||
15 | +# | ||
16 | +# The exit code list is any 1, 2 or 3 digit number which will exit | ||
17 | +# with that status (0, 1, 2 and 3 are valid for nagios). The code 'S' | ||
18 | +# or 's' will cause the process to sleep for 1 hour in the expectation | ||
19 | +# that it will recieve a kill signal from nagios. | ||
20 | +# | ||
21 | +# The label has one of the following forms: | ||
22 | +# | ||
23 | +# hostname-service_name (if -H specified) | ||
24 | +# service_name (if -E is not specified) | ||
25 | +# hostname (if -H specified) | ||
26 | +# default | ||
27 | +# | ||
28 | +# The labels are searched for in order. If no matching label is found, | ||
29 | +# one is appended to the command file, with exit status 0. If duplicate | ||
30 | +# labels are in the file, the last label takes precidence. So you can | ||
31 | +# append a label/exit code line to the file and get a change in the | ||
32 | +# exit code. | ||
33 | + | ||
34 | +# Exit code lists look like: | ||
35 | +# | ||
36 | +# label=value1,value2,value3,value4,...,valueN | ||
37 | +# | ||
38 | +# where value1 is used for this invocation, and a new label entry is | ||
39 | +# added with value1 put after valueN so that value2 wil be used as | ||
40 | +# exit code on the next run. This allows deterministic runs of the | ||
41 | +# program for testing availability metrics and various senarios for | ||
42 | +# reporting and other related activities. | ||
43 | +# | ||
44 | +# Note that regular poll and error poll times along with the number of | ||
45 | +# retries to go from soft to hard have to be considered when designing | ||
46 | +# a test. | ||
47 | +# | ||
48 | +# Options: | ||
49 | +help="Usage: $0 -E -s <svc> -H <host> -e <exitcode> -f <file> -ht -m <msg> | ||
50 | + -E - exact entry including hostname is needed. Prevents matching | ||
51 | + only on service_ name. | ||
52 | + -H <hostname> - the hostname this test is running on. No default. | ||
53 | + -e <exit code> - used like check dummy, always exits with this | ||
54 | + status code. Ignores the external file. | ||
55 | + -f <filename> - the external file name used for determining exit | ||
56 | + code. Default: /tmp/check_test. | ||
57 | + -h - This help text. | ||
58 | + -s <service_name> - the service description for this test. Default | ||
59 | + the basename of the progam name. | ||
60 | + -t - enable tracing info for debugging. Note this will cause | ||
61 | + problems is run from nagios. | ||
62 | + -m - message to be put out when running. | ||
63 | +" | ||
64 | + | ||
65 | +## standard debugging preamble | ||
66 | +trace=true | ||
67 | +if ! [ -z "$SHELL_DEBUG" ]; then | ||
68 | + if echo "$SHELL_DEBUG" | grep -i xv > /dev/null 2>&1; then | ||
69 | + set -xv | ||
70 | + fi | ||
71 | + if echo "$SHELL_DEBUG" | grep -i trace > /dev/null 2>&1; then | ||
72 | + trace=echo | ||
73 | + fi | ||
74 | +fi | ||
75 | + | ||
76 | +## set variables | ||
77 | +exact="" | ||
78 | +exitcode=-1 | ||
79 | +filename=/tmp/check_test | ||
80 | +hostname="" | ||
81 | +message="" | ||
82 | +service_name=`basename $0` | ||
83 | + | ||
84 | + | ||
85 | +## parse arguments | ||
86 | +while getopts -- EH:e:f:hs:t arg | ||
87 | +do | ||
88 | + case "$arg" in | ||
89 | + E) exact="yes";; | ||
90 | + H) hostname="$OPTARG";; | ||
91 | + e) exitcode="$OPTARG";; | ||
92 | + f) filename="$OPTARG";; | ||
93 | + h) echo "$help"; exit;; | ||
94 | + m) message="$OPTARG";; | ||
95 | + s) service_name="$OPTARG";; | ||
96 | + t) trace=echo;; | ||
97 | + *) echo "Usage: $0 -E -s <svc> -H <host> -e <exitcode> -f <file>" | ||
98 | + exit 4;; | ||
99 | + esac | ||
100 | +done | ||
101 | + | ||
102 | +$trace "parsed arguments: $hostname, $service_name, $exitcode, $filename" | ||
103 | + | ||
104 | +## create command file if needed | ||
105 | +if ! [ -r $filename ]; then | ||
106 | + $trace Did not find readable file. Creating config file $filename | ||
107 | + # hmm how to capture. Wrapping with `` and assigning to variable | ||
108 | + # produces syntax error missing close ` in cygwin bash, but it works | ||
109 | + # interactively. | ||
110 | + touch $filename 2>&1 || \ | ||
111 | + eval "echo \"$0: Unable to create $filename, $error\" && exit 2" | ||
112 | +fi | ||
113 | + | ||
114 | +## find the exit code entry for this invocation | ||
115 | +if [ $exitcode = "-1" ]; then | ||
116 | + rule=`grep "^$hostname-$service_name=" $filename | tail -1` | ||
117 | + if [ -z "$rule" ]; then | ||
118 | + if [ -z "$exact" ]; then | ||
119 | + rule=`grep "^$service_name=" $filename | tail -1` | ||
120 | + fi | ||
121 | + if [ -z "$rule" ]; then | ||
122 | + if [ -n "$hostname" ]; then | ||
123 | + rule=`grep "^$hostname=" $filename | tail -1` | ||
124 | + fi | ||
125 | + if [ -z "$rule" ]; then | ||
126 | + rule=`grep "^default=" $filename | tail -1` | ||
127 | + if [ -z "$rule" ]; then | ||
128 | + $trace no matching rule found, creating new rule | ||
129 | + rule="${hostname}${hostname:+-}${service_name}=0" | ||
130 | + echo $rule >> $filename | ||
131 | + fi | ||
132 | + fi | ||
133 | + fi | ||
134 | + fi | ||
135 | + $trace rule is $rule | ||
136 | + | ||
137 | + ## split the rule to isolate the exit code(s). | ||
138 | + IFS="=" | ||
139 | + set -- $rule | ||
140 | + IFS="" | ||
141 | + | ||
142 | + if [ $# -gt 2 ]; then | ||
143 | + echo "$0: Malformed rule $rule:" | ||
144 | + exit 2 | ||
145 | + fi | ||
146 | + | ||
147 | + exitcode="$2" | ||
148 | + label=$1 | ||
149 | +fi | ||
150 | + | ||
151 | +## exit with message and proper code and rotate exit code list if present | ||
152 | +while true; do | ||
153 | + case $exitcode in | ||
154 | + 0) echo $0: $message exiting 0; exit 0;; | ||
155 | + 1) echo $0: $message exiting 1; exit 1;; | ||
156 | + 2) echo $0: $message exiting 2; exit 2;; | ||
157 | + [0-9]|[0-9][0-9]|[0-9][0-9][0-9]) | ||
158 | + # exit with odd exit codes | ||
159 | + echo $0: $message exiting $exitcode; exit $exitcode;; | ||
160 | + s|S) sleep 3600 ;; # stall forcing parent nagios to kill us | ||
161 | + *,*) IFS="," | ||
162 | + set -- $exitcode | ||
163 | + exitcode=$1 | ||
164 | + shift | ||
165 | + exitcodes="$*,$exitcode" | ||
166 | + echo "$label=$exitcodes" >> $filename | ||
167 | + # not checking for bad/missing exit code here. main | ||
168 | + # loop will do that. | ||
169 | + ;; | ||
170 | + *) echo "$0: Unrecognised status code $rule"; exit 2;; | ||
171 | + esac | ||
172 | +done | ||