-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbartlby_process.sh
executable file
·205 lines (158 loc) · 3.79 KB
/
bartlby_process.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
#########################################
# Bartlby Check Disk
# $Id: bartlby_process.sh,v 1.4 2006/09/09 20:10:09 hjanuschka Exp $ */
#
#
# $Revision: 1.4 $
# $Source: /cvsroot/bartlby/bartlby-plugins/bartlby_process.sh,v $
#
#
#
# $Log: bartlby_process.sh,v $
# Revision 1.4 2006/09/09 20:10:09 hjanuschka
# snmp
#
# Revision 1.3 2006/09/09 19:38:42 hjanuschka
# auto commit
#
# Revision 1.2 2005/11/16 23:52:43 hjanuschka
# PATH fixes
#
# Revision 1.1 2005/09/20 21:14:49 hjanuschka
# initial import
#
#
#
#########################################
VERSION="0.1";
MY_PATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
export PATH="$PATH:/usr/local/bin/";
if [ -f $MY_PATH/bartlby.funcs ]; then
. $MY_PATH/bartlby.funcs
plg_init_args $*;
else
echo "your setup doesnt look fine cant locate 'bartlby.funcs'";
exit 2;
fi;
set_my_name "bartlby_process"
has_executable "qpst" "please see http://www.januschka.com/__qpst.c/";
plg_get_arg "h" "IS_HELP";
plg_get_arg "w" "W_LEVEL";
plg_get_arg "c" "C_LEVEL";
plg_get_arg "p" "P_TO_FIND";
plg_get_arg "S" "SNMP";
plg_get_arg "C" "SNMP_COMM";
plg_get_arg "H" "SNMP_HOST";
plg_get_arg "v" "SNMP_VER";
plg_get_arg "I" "PROC_INV";
if [ "$W_LEVEL" = "false" ];
then
W_LEVEL="1";
fi;
if [ "$C_LEVEL" = "false" ];
then
C_LEVEL="1";
fi;
if [ "$P_TO_FIND" = "false" ];
then
echo "You should pass the -p option";
export IS_HELP="true";
fi;
if [ "$IS_HELP" != "false" ];
then
echo "Bartlby Check Swap $VERSION";
echo "***************************";
echo "Check Swap usage and alert if percentage of free swap is lower than X";
echo "-h Display Help";
echo "-p Process to find (looks at whole command line)";
echo "-w Warn if count of found processes is lower than -w (Default: 1)";
echo "-w Critical if count of found processes is lower than -w (Default: 1)";
echo "-I Invert result, alert if there are more than X procs found";
echo "-S use SNMP mode";
echo " -C Community (default: public)";
echo " -H Host (default: localhost)";
echo " -i interface index (default: 1)";
echo " -v version (default: 1), 1 or 2c";
end_warning "";
fi;
function snmp_get_ps_parms {
snmpwalk -Oq -v $SNMP_VER -c $SNMP_COMM $SNMP_HOST hrSWRunParameters.$1|while read oid axf a;
do
echo "$axf";
done;
}
function snmp_ps {
snmpwalk -Oq -v $SNMP_VER -c $SNMP_COMM $SNMP_HOST hrSWRunIndex|while read oid axf a;
do
IDX=$(echo $oid|awk -F. '{print $NF}');
name=$(snmpget -t 3 -Oqv -v $SNMP_VER -c $SNMP_COMM $SNMP_HOST hrSWRunPath.$IDX 2>/dev/null);
params=$(snmp_get_ps_parms $IDX);
echo "$name $params"|tr -d '"';
done;
}
function check_proc {
cnt=`qpst -r $P_TO_FIND -i -p $$ -P $$ -c`; #exit code isnt safe as of 255 limitation ;-)
echo -n " [ found $cnt processes for $P_TO_FIND $1/$2 ]\\dbr";
DR="-lt";
if [ "$3" = "true" ];
then
DR="-gt";
fi;
if [ $cnt $DR $2 ];
then
exit $STATE_CRITICAL;
fi;
if [ $cnt $DR $1 ];
then
exit $STATE_WARNING;
fi;
exit $STATE_OK;
}
#### SNMP
#hrSWRunIndex
#
if [ "$SNMP" = "false" ];
then
MY_OUT_STR=`check_proc $W_LEVEL $C_LEVEL $PROC_INV`;
ECO=$?;
else
has_executable "snmpget"
has_executable "snmpwalk"
if [ "$SNMP_HOST" = "false" ];
then
SNMP_HOST="localhost";
fi;
if [ "$SNMP_COMM" = "false" ];
then
SNMP_COMM="public";
fi;
if [ "$SNMP_VER" = "false" ];
then
SNMP_VER="1";
fi;
cnt=$(snmp_ps|grep $P_TO_FIND|wc -l);
MY_OUT_STR=" [ SNMP found $cnt processes for $P_TO_FIND $W_LEVEL/$C_LEVEL ]\\dbr";
if [ $cnt -lt $C_LEVEL ];
then
ECO=$STATE_CRITICAL;
fi;
if [ $cnt -lt $W_LEVEL ];
then
ECO=$STATE_WARNING;
fi;
ECO=$STATE_OK;
fi;
if [ $ECO = $STATE_CRITICAL ];
then
end_critical "$MY_OUT_STR";
fi;
if [ $ECO = $STATE_WARNING ];
then
end_warning "$MY_OUT_STR";
fi;
end_ok "$MY_OUT_STR";
#parse args
#get part list
#df each part
#produce warning/crit/ok