forked from ckujau/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_socket.sh
More file actions
executable file
·33 lines (29 loc) · 874 Bytes
/
Copy pathcheck_socket.sh
File metadata and controls
executable file
·33 lines (29 loc) · 874 Bytes
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
#!/bin/sh
#
# (c)2019 Christian Kujau <lists@nerdbynature.de>
#
# Similar to check_tcp and check_udp, we want to check if a UNIX domain socket
# is listening for connections. There is check_sockets.pl, but that only
# checks on the number of open sockets, not for a particular open socket.
#
if [ -z "$2" ]; then
echo "Usage: $(basename "$0") [path] [min] [max]"
exit 1
else
P="$1" # We need the canonical path here.
MIN="$2"
MAX="$3"
fi
# Netstat (from net-tools) is obsolete, so let's use ss (from iproute2) now.
COUNT=$(ss -Hlx src "$P" | grep -c LISTEN) # EOL printing in misc/ss.c workaround
# Needs more logic :-\
if [ "$COUNT" -ge "$MAX" ]; then
echo "CRITICAL: $COUNT sockets listening in $P"
exit 2
elif [ "$COUNT" -lt "$MIN" ]; then
echo "WARNING: $COUNT sockets listening in $P"
exit 1
else
echo "OK: $COUNT sockets listening in $P"
exit 0
fi