From 756cc750d0054006ad6acfda9a55a4e2607ac2f3 Mon Sep 17 00:00:00 2001 From: Dallas Date: Wed, 17 Jan 2018 16:41:53 -0600 Subject: [PATCH] Check via hostname not working Check whether the input is either a hostname or IP address and then run the appropriate check --- check_pf_ipsec_tunnel | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/check_pf_ipsec_tunnel b/check_pf_ipsec_tunnel index 5e5de3a..7bfc880 100644 --- a/check_pf_ipsec_tunnel +++ b/check_pf_ipsec_tunnel @@ -8,7 +8,17 @@ exitstatus=2 #default endpoint=$2 name_instead=$4 -result=$(/usr/local/sbin/ipsec statusall | grep 'ESTABLISHED' | grep $endpoint | cut -d":" -f2 | cut -d "," -f1 | sed -e 's/^[ \t]*//')||exit 3 +regex="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" + +IPTEST=$(echo $endpoint | egrep $regex) +if [ "$?" -eq 0 ] +then + result=$(/usr/local/sbin/ipsec statusall | grep 'ESTABLISHED' | grep $endpoint | cut -d":" -f2 | cut -d "," -f1 | sed -e 's/^[ \t]*//')||exit 3 +else + hostip=$(dig +short $endpoint) + result=$(/usr/local/sbin/ipsec statusall | grep 'ESTABLISHED' | grep $hostip | cut -d":" -f2 | cut -d "," -f1 | sed -e 's/^[ \t]*//')||exit 3 +fi + if [ "$name_instead" != "" ] then endpoint=$name_instead