#!/usr/bin/perl
###############################################################################
#
# checkWatchguardVPNTunnel.pl
#
# reads out watchguard snmp ipsec table and check if tunnel to specified subnet exists
#
# OMD[romina]:~/local/bin$ snmpwalk -v 2c -c rompub 10.163.10.1 .1.3.6.1.4.1.3097.6.5.1.2.1.20
# SNMPv2-SMI::enterprises.3097.6.5.1.2.1.20.0 = IpAddress: 192.168.104.0
# SNMPv2-SMI::enterprises.3097.6.5.1.2.1.20.1 = IpAddress: 172.22.0.0
# SNMPv2-SMI::enterprises.3097.6.5.1.2.1.20.2 = IpAddress: 172.22.0.0
# SNMPv2-SMI::enterprises.3097.6.5.1.2.1.20.3 = IpAddress: 172.16.0.0
# SNMPv2-SMI::enterprises.3097.6.5.1.2.1.20.4 = IpAddress: 172.16.0.0
# SNMPv2-SMI::enterprises.3097.6.5.1.2.1.20.5 = IpAddress: 172.16.0.0
# SNMPv2-SMI::enterprises.3097.6.5.1.2.1.20.6 = IpAddress: 172.16.0.0
#
# usage:
# ./checkWatchguardVPNTunnel.pl 10.0.0.1 public 172.99.0.0 vpnname
#
# example:
# ./checkWatchguardVPNTunnel.pl <hostname> <community> <vpn-tunnel-ip> <display-name>
#
# output:
# 0 VPNTunnel-vpnname-172.99.0.0 - Tunnels found for IP 172.99.0.0 = 2.
#
# version 2021-09-23, mw
#
###############################################################################

$watchguard=$ARGV[0];
$community=$ARGV[1];
$searchForIP=$ARGV[2];
$name=$ARGV[3];
$debug=0; #1=on

if (($watchguard eq '') || ($community eq '') || ($searchForIP eq '') || ($name eq '') ){
print "usage: checkWatchguardVPNTunnel.pl <hostname> <community> <vpn-tunnel-ip> <display-name> \n";
print "\n";
exit 1;
}


$found=0;
open(IN,"snmpwalk -v 2c -c $community $watchguard 1.3.6.1.4.1.3097.6.5.1.2.1.20 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
print "$line\n" if $debug;
if ($line =~ /$searchForIP$/){
print "found!!\n" if $debug;
$found++;
}
}
close(IN);

print "<<<check_mk>>>\n";
print "Version:v2021-03-23\n";
print "<<<local>>>\n";

if ($found == 0){
print "1 VPNTunnel-$name-$searchForIP - No tunnels found for IP $searchForIP\n";
exit(0);
#exit(1);
}

print "0 VPNTunnel-$name-$searchForIP - Tunnels found for IP $searchForIP = $found.\n";
exit(0);

computer2know :: thank you for your visit :: have a nice day :: © 2022