I want to get the number of VPN sessions on an ASA 5515 and the usernames of the users connected.
Warning will be at if any users are connected. No critical alert needed.
I have created the script below:
Code: Select all
#!/bin/bash
VPN_USERS=$(sshpass -p 'xxx' ssh [email protected] $'sh vpn-sessiondb svc\n exit\n' | grep "Username : " | awk {'print $3'} | tr "\\\ " " ")
if [ -z "$VPN_USERS" ]
then
echo "OK- No VPN users connected."
exit 0
else
echo "WARNING - Connected VPN users: $VPN_USERS"
exit 1
fiCode: Select all
ASA# sh vpn-sessiondb svc
Session Type: AnyConnect
Username : ABCD Index : 123456789
Assigned IP : xxx.xxx.xxx.xxx Public IP : xxx.xxx.xxx.xxx
Protocol : AnyConnect-Parent SSL-Tunnel DTLS-Tunnel
License : AnyConnect Essentials, AnyConnect for Mobile
Encryption : AnyConnect-Parent: (1)none SSL-Tunnel: (1)AES256 DTLS-Tunnel: (1)AES128
Hashing : AnyConnect-Parent: (1)none SSL-Tunnel: (1)SHA256 DTLS-Tunnel: (1)SHA1
Bytes Tx : 99999999 Bytes Rx : 999999999
Group Policy : XXXXXXXXXXXX
Tunnel Group : XXXXXXXXXXXX
Login Time : 06:39:27 CEDT Fri Aug 30 2019
Duration : 4h:00m:44s
Inactivity : 0h:00m:00s
VLAN Mapping : N/A VLAN : none
Audt Sess ID : 00000000019babcdef123456
Security Grp : XXXXXXXXXXXX
Username : WXYZ Index : 123456
Assigned IP : xxx.xxx.xxx.xxx Public IP : xxx.xxx.xxx.xxx
Protocol : AnyConnect-Parent SSL-Tunnel DTLS-Tunnel
License : AnyConnect Essentials
Encryption : AnyConnect-Parent: (1)none SSL-Tunnel: (1)AES256 DTLS-Tunnel: (1)AES128
Hashing : AnyConnect-Parent: (1)none SSL-Tunnel: (1)SHA256 DTLS-Tunnel: (1)SHA1
Bytes Tx : 999999999 Bytes Rx : 999999999
Group Policy : XXXXXXXXXXXX
Tunnel Group : XXXXXXXXXXXX
Login Time : 08:11:47 CEDT Fri Aug 30 2019
Duration : 1h:42m:24s
Inactivity : 0h:00m:00s
VLAN Mapping : N/A VLAN : none
Audt Sess ID : 000000000de7abcdef123456
Security Grp : noneCode: Select all
[root@abdcfeg libexec]# ./check_asa_vpn.sh
Connection to xxx.xxx.xxx.xxx closed by remote host.
WARNING - Connected VPN users: ABCD
WXYZ
Running nagios core on centos.
Any tips?
