-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_service
63 lines (55 loc) · 1.09 KB
/
check_service
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
#!/bin/bash
#Author: Tino
#VARIABLES NAGIOS
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
PROGNAME=`basename $0 .sh`
VERSION="Version 1.1"
print_version() {
echo "$VERSION"
}
print_help() {
print_version $PROGNAME $VERSION
echo ""
echo "$PROGNAME is a Nagios plugin to check a specific service using systemctl."
echo ""
echo "$PROGNAME -s <service_name>"
exit $UNKNOWN
}
if test -z "$1"
then
print_help
exit $CRITICAL
fi
while test -n "$1"; do
case "$1" in
--help|-h)
print_help
exit $UNKNOWN
;;
--version|-v)
print_version $PROGNAME $VERSION
exit $UNKNOWN
;;
--service|-s)
SERVICE=$2
shift
;;
*)
echo "Unknown argument: $1"
print_help
exit $UNKNOWN
;;
esac
shift
done
if systemctl is-active $SERVICE >/dev/null 2>&1
then
echo -e "OK: Service $SERVICE is running!"
exit $OK
else
echo -e "CRITICAL: Service $SERVICE is not running!"
exit $CRITICAL
fi