Skripte für Zabbix aufgenommen
parent
e9a63db7dd
commit
efb16a066a
|
@ -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()
|
|
@ -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
|
Loading…
Reference in New Issue