Created
June 16, 2014 01:24
-
-
Save alice-xu/6f5f3ff65bd09dc4c02e to your computer and use it in GitHub Desktop.
OpenVPN client config discovery for Zabbix LLD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
VPN_SERVER=$( hostname --fqdn ) | |
CLIENT_CONFIG_DIR="$1" | |
[ -z "${CLIENT_CONFIG_DIR}" ] && CLIENT_CONFIG_DIR='/etc/openvpn/ccd' | |
{ | |
echo "{" | |
echo " \"data\":[" | |
for line in $( ls -1 "${CLIENT_CONFIG_DIR}" 2> /dev/null ); do | |
CLIENT_CN=$(echo $line|sed -e 's/\\/\\\\/g' -e 's|/|\\/|g') | |
CLIENT_VPN_IP=$(cat "${CLIENT_CONFIG_DIR}"/$line|grep ifconfig-push|awk '{print $2}') | |
echo " {" | |
echo " \"{#VPN_SERVER}\":\"${VPN_SERVER}\"," | |
echo " \"{#CLIENT_CN}\":\"${CLIENT_CN}\"," | |
echo " \"{#CLIENT_VPN_IP}\":\"${CLIENT_VPN_IP}\"" | |
echo " }," | |
done | sed -e '$d' | |
echo " }" | |
echo " ]" | |
echo "}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment