-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcheck_checkrestart.sh
executable file
·189 lines (175 loc) · 6.06 KB
/
check_checkrestart.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
#!/bin/sh
#
# ============================== SUMMARY =====================================
#
# Program : check_checkrestart.sh
# Version : 0.2
# Date : January 28 2015
# Author : Dirk Doerflinger - dirk(at)doerflinger(dot)org
# Summary : This is a Nagios plugin to check if any processes are still using
# old versions of updated libraries. I needs check_restart from
# debian-goodies. Debian only!
#
# Licence : MIT
#
# =========================== PROGRAM LICENSE =================================
#
# Copyright (C) 2014 Dirk Doerflinger
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ===================== INFORMATION ABOUT THIS PLUGIN =========================
#
# This nagios plugin uses the checkrestart script from the debian-goodies to
# check if any processes are still using old version of updated libs.
#
# This program is written and maintained by:
# Dirk Doerflinger - dirk(at)doerflinger(dot)org
# Landry MINOZA - lminoza[at]mgi.fr - v0.2
#
# ============================= SETUP NOTES ====================================
#
# Copy this file to your Nagios plugin folder, e.g. /usr/lib64/nagios/plugins/
# or /usr/local/lib/nagios/plugins.
# Make sure it is executable for the nagios user
#
# You need to have debian-goodies installed, which provides
# /usr/sbin/checkrestart
#
# ./check_checkrestart.sh -w <warning> -c <critical>
#
# Where <warning> and <critical> is the number of processes found triggering
#
# ========================= SETUP EXAMPLES ==================================
#
# ===== Nagios command ======================================================
# define command{
# command_name check_checkrestart
# command_line $USER1$/check_checkrestart.sh -w $ARG1$ -c $ARG2$
# }
#
# ===== Nagios service ======================================================
# define service{
# use generic-service
# host_name debian-server
# service_description Debian obsolete libraries used
# check_command check_checkrestart!3!1
# normal_check_interval 3
# retry_check_interval 1
# }
#
# ===== NRPE check ==========================================================
# command[check_checkrestart]=/usr/local/lib/nagios/plugins/check_checkrestart.sh
#
# ===== Sudoers conf ========================================================
# User_Alias CHECK_CHECKRESTART=nagios
# Defaults:CHECK_CHECKRESTART !requiretty
# CHECK_CHECKRESTART ALL=(root) NOPASSWD: /usr/sbin/checkrestart
#
# ================================ REVISION ==================================
#
# 0.1 Initial release
# 0.2 Add -p option for debian >= 7, use sudo if needed and add nrpe example
#
# ============================================================================
package=check_checkrestart
# Path to racadm binary
checkrestart=/usr/sbin/checkrestart
# use sudo for nrpe server running under nagios user
if [ "$(id -u)" -ne 0 ] ; then
checkrestart="sudo ${checkrestart}"
fi
# use -p for newer versions
$checkrestart -h 2>&1 | grep -q vhpa
if [ $? -eq 0 ] ; then
checkrestart="${checkrestart} -p"
fi
# default values for warnings and critical
warning=1
critical=4
# initialize an exit code
exitcode=0
# parse parameters
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "$package - Check obsolete libraries still in use"
echo " "
echo "Needs debian-goodies!"
echo " "
echo "$package [options]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-w, --warning Warning number of processes using old libraries. Default: $warning"
echo "-c, --critical Crtitical number of processes using old libraries. Default: $critical"
exit 0
;;
-w|--warning)
shift
if test $# -gt 0; then
export warning=$1
else
echo "no warning level specified, defaulting to $warning"
fi
shift
;;
-c|--critical)
shift
if test $# -gt 0; then
export critical=$1
else
echo "no critical level specified, defaulting to $critical"
fi
shift
;;
esac
done
result=$($checkrestart | grep Found | awk '{print $2}')
# Make sure we have a result. If we don't that usually means that the connection failed, e.g. wrom hostname or credentials
if [ -z $result ]; then
echo "CRITICAL - No data, maybe $checkrestart missing?"
exit 2
fi
if [ $result -ge $critical ]; then
exitcode=2
elif [ $result -ge $warning ]; then
exitcode=1
else
exitcode=0
fi
case $exitcode in
0)
echo "OK: no service or process to restart | to_restart=$result"
exit 0
;;
1)
echo "WARNING: $result services or processes to restart | to_restart=$result"
exit 1
;;
2)
echo "CRTITICAL: $result services or processes to restart | to_restart=$result"
exit 2
;;
*)
echo "UNKNOWN - Weird data"
exit 3
;;
esac
#EOF