Skripte für Zabbix aufgenommen

master
Thomas Hooge 2016-11-28 18:16:56 +01:00
parent e9a63db7dd
commit efb16a066a
2 changed files with 58 additions and 0 deletions

23
zabbix/dhcpd.leases Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env python
import re
import datetime
def count_dhcp_leases():
regex_leaseblock = re.compile(r"lease (?P<ip>\d+\.\d+\.\d+\.\d+) {(?P<config>[\s\S]+?)\n}")
regex_properties = re.compile(r"\s+(?P<key>\S+) (?P<value>[\s\S]+?);")
leases = 0
with open("/var/lib/dhcp/dhcpd.leases") as lease_file:
macs = set()
for match in regex_leaseblock.finditer(lease_file.read()):
block = match.groupdict()
properties = {key: value for (key, value) in regex_properties.findall(block['config'])}
if properties['binding'].split(' ')[1] == 'active' and properties['ends'] != 'never':
dt_ends = datetime.datetime.strptime(properties['ends'][2:], "%Y/%m/%d %H:%M:%S")
if dt_ends > datetime.datetime.utcnow() and properties['hardware'].startswith('ethernet'):
macs.add(properties['hardware'][9:])
leases = len(macs)
return leases
if __name__ == "__main__":
print count_dhcp_leases()

35
zabbix/exitvpn.state Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
#
# Check if ExitVPN is working
# 1 - OK
# 0 - Failed
#
VPNCONF=$(grep -e "^AUTOSTART=" /etc/default/openvpn)
INTERFACE=$(sed -e 's/^"//' -e 's/"$//' <<< ${VPNCONF#*=})
NATIF=$(iptables -t nat -vnL | grep MASQUERADE | awk '{$1=$1};1' | cut -d' ' -f 7)
TESTIP=81.7.16.37 # gate01
if [ ! `pgrep openvpn` ]; then
echo 0
exit 0
fi
if [ ! -d "/sys/class/net/$INTERFACE" ]; then
echo 0
exit 0
fi
if ! test "$NATIF" == "$INTERFACE" ; then
echo 0
exit 0
fi
ping -q -I $INTERFACE $TESTIP -c 3 -i 1 -W 5 >/dev/null 2>&1
if ! test $? -eq 0; then
echo 0
exit 0
fi
echo 1
exit 0