Merge pull request #16 from Freifunk-Troisdorf/hetzner
Merged Hetzner into Master
This commit is contained in:
commit
cfc6abc2d0
43
Todo
Normal file
43
Todo
Normal file
@ -0,0 +1,43 @@
|
||||
TODO
|
||||
|
||||
1. Statisches Routing über Interconnect Router
|
||||
|
||||
==================================================================
|
||||
# SN 4
|
||||
# FFTDF Interconnect Routen
|
||||
ip route add 10.188.32.0/19 via 10.188.0.2 table 42
|
||||
ip route add 10.188.64.0/19 via 10.188.0.2 table 42
|
||||
ip route add 10.188.96.0/19 via 10.188.0.2 table 42
|
||||
ip -6 route add 2a03:2260:121:5000::/64 via 2a03:2260:121:4000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:6000::/64 via 2a03:2260:121:4000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:7000::/64 via 2a03:2260:121:4000::2 table 42
|
||||
# SN 5
|
||||
# FFTDF Interconnect Routen
|
||||
ip route add 10.188.0.0/19 via 10.188.32.2 table 42
|
||||
ip route add 10.188.64.0/19 via 10.188.32.2 table 42
|
||||
ip route add 10.188.96.0/19 via 10.188.32.2 table 42
|
||||
ip -6 route add 2a03:2260:121:4000::/64 via 2a03:2260:121:5000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:6000::/64 via 2a03:2260:121:5000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:7000::/64 via 2a03:2260:121:5000::2 table 42
|
||||
# SN 6
|
||||
# FFTDF Interconnect Routen
|
||||
ip route add 10.188.0.0/19 via 10.188.64.2 table 42
|
||||
ip route add 10.188.32.0/19 via 10.188.64.2 table 42
|
||||
ip route add 10.188.96.0/19 via 10.188.64.2 table 42
|
||||
ip -6 route add 2a03:2260:121:4000::/64 via 2a03:2260:121:6000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:5000::/64 via 2a03:2260:121:6000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:7000::/64 via 2a03:2260:121:6000::2 table 42
|
||||
# SN 7
|
||||
# FFTDF Interconnect Routen
|
||||
ip route add 10.188.0.0/19 via 10.188.96.2 table 42
|
||||
ip route add 10.188.32.0/19 via 10.188.96.2 table 42
|
||||
ip route add 10.188.64.0/19 via 10.188.96.2 table 42
|
||||
ip -6 route add 2a03:2260:121:4000::/64 via 2a03:2260:121:7000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:5000::/64 via 2a03:2260:121:7000::2 table 42
|
||||
ip -6 route add 2a03:2260:121:6000::/64 via 2a03:2260:121:7000::2 table 42
|
||||
|
||||
==================================================================
|
||||
|
||||
2. Freifunk Yanic Installieren
|
||||
|
||||
3. chmod 644 /etc/logrotate.conf
|
6
files/check_mk-dhcp.sh
Normal file
6
files/check_mk-dhcp.sh
Normal file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
datum=$(date "+%b %d")
|
||||
hostname=$(hostname)
|
||||
clients=$(cat /var/log/syslog | grep "$(date "+%b %d")" | grep DHCPACK | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | sort | uniq | wc -l)
|
||||
echo "nc.gateways."$hostname" $clients `date +%s`" | nc -n -q 5 10.188.0.10 2003
|
||||
echo "0 Uniq-Clients count=$clients - $clients Uniq Clients heute"
|
392
files/check_mk-speedtest-cli
Normal file
392
files/check_mk-speedtest-cli
Normal file
@ -0,0 +1,392 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# Script to check Internet connection speed using speedtest-cli
|
||||
#
|
||||
# Jon Witts - 20150228
|
||||
#
|
||||
#########################################################################################################################################################
|
||||
#
|
||||
# Nagios Exit Codes
|
||||
#
|
||||
# 0 = OK = The plugin was able to check the service and it appeared to be functioning properly
|
||||
# 1 = Warning = The plugin was able to check the service, but it appeared to be above some warning
|
||||
# threshold or did not appear to be working properly
|
||||
# 2 = Critical = The plugin detected that either the service was not running or it was above some critical threshold
|
||||
# 3 = Unknown = Invalid command line arguments were supplied to the plugin or low-level failures internal
|
||||
# to the plugin (such as unable to fork, or open a tcp socket) that prevent it from performing the specified operation.
|
||||
# Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins
|
||||
# and should generally NOT be reported as UNKNOWN states.
|
||||
#
|
||||
########################################################################################################################################################
|
||||
|
||||
plugin_name="Nagios speedtest-cli plugin"
|
||||
version="1.2 2015022818.19"
|
||||
|
||||
#####################################################################
|
||||
#
|
||||
# CHANGELOG
|
||||
#
|
||||
# Version 1.0 - Initial Release
|
||||
#
|
||||
# Version 1.1 - Added requirement to use server id in test and need to define
|
||||
# full path to speedtest binary - thanks to Sigurdur Bjarnason
|
||||
# for changes and improvements
|
||||
#
|
||||
# Version 1.2 - Added ability to check speed from an internal Speedtest Mini
|
||||
# server. Idea sugested by Erik Brouwer
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
#####################################################################
|
||||
# function to output script usage
|
||||
usage()
|
||||
{
|
||||
cat << EOF
|
||||
******************************************************************************************
|
||||
|
||||
$plugin_name - Version: $version
|
||||
|
||||
OPTIONS:
|
||||
-h Show this message
|
||||
-w Download Warning Level - *Required* - integer or floating point
|
||||
-c Download Critical Level - *Required* - integer or floating point
|
||||
-W Upload Warning Level - *Required* - integer or floating point
|
||||
-C Upload Critical Level - *Required* - integer or floating point
|
||||
-l Location of speedtest server - *Required * - takes either "i" or "e". If you pass "i" for
|
||||
Internal then you will need to pass the URL of the Mini Server to the "s" option. If you pass
|
||||
"e" for External then you must pass the server integer to the "s" option.
|
||||
-s Server integer or URL for the speedtest server to test against - *Required* - Run
|
||||
"speedtest --list | less" to find your nearest server and note the number of the server
|
||||
or use the URL of an internal Speedtest Mini Server
|
||||
-p Output Performance Data
|
||||
-v Output plugin version
|
||||
-V Output debug info for testing
|
||||
|
||||
This script will output the Internet Connection Speed using speedtest-cli to Nagios.
|
||||
|
||||
You need to have installed speedtest-cli on your system first and ensured that it is
|
||||
working by calling "speedtest --simple".
|
||||
|
||||
See here: https://github.com/sivel/speedtest-cli for info about speedtest-cli
|
||||
|
||||
First you MUST define the location of your speedtest install in the script or this will
|
||||
not work.
|
||||
|
||||
The speedtest-cli can take some time to return its result. I recommend that you set the
|
||||
service_check_timeout value in your main nagios.cfg to 120 to allow time for
|
||||
this script to run; but test yourself and adjust accordingly.
|
||||
|
||||
You also need to have access to bc on your system for this script to work and that it
|
||||
exists in your path.
|
||||
|
||||
Your warning levels must be higher than your critical levels for both upload and download.
|
||||
|
||||
Performance Data will output upload and download speed against matching warning and
|
||||
critical levels.
|
||||
|
||||
Jon Witts
|
||||
|
||||
******************************************************************************************
|
||||
EOF
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
# function to output error if speedtest binary location not set
|
||||
locundef()
|
||||
{
|
||||
cat << EOF
|
||||
******************************************************************************************
|
||||
|
||||
$plugin_name - Version: $version
|
||||
|
||||
You have not defined the location of the speedtest binary in the script! You MUST do
|
||||
this before running the script. See line 170 of the script!
|
||||
|
||||
******************************************************************************************
|
||||
EOF
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
# function to check if a variable is numeric
|
||||
# expects variable to check as first argument
|
||||
# and human description of variable as second
|
||||
isnumeric()
|
||||
{
|
||||
re='^[0-9]+([.][0-9]+)?$'
|
||||
if ! [[ $1 =~ $re ]]; then
|
||||
echo $2" with a value of: "$1" is not a number!"
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
# functions for floating point operations - require bc!
|
||||
|
||||
#####################################################################
|
||||
# Default scale used by float functions.
|
||||
|
||||
float_scale=3
|
||||
|
||||
#####################################################################
|
||||
# Evaluate a floating point number expression.
|
||||
|
||||
function float_eval()
|
||||
{
|
||||
local stat=0
|
||||
local result=0.0
|
||||
if [[ $# -gt 0 ]]; then
|
||||
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null)
|
||||
stat=$?
|
||||
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi
|
||||
fi
|
||||
echo $result
|
||||
return $stat
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
# Evaluate a floating point number conditional expression.
|
||||
|
||||
function float_cond()
|
||||
{
|
||||
local cond=0
|
||||
if [[ $# -gt 0 ]]; then
|
||||
cond=$(echo "$*" | bc -q 2>/dev/null)
|
||||
if [[ -z "$cond" ]]; then cond=0; fi
|
||||
if [[ "$cond" != 0 && "$cond" != 1 ]]; then cond=0; fi
|
||||
fi
|
||||
local stat=$((cond == 0))
|
||||
return $stat
|
||||
}
|
||||
|
||||
########### End of functions ########################################
|
||||
|
||||
# Set up the variable for the location of the speedtest binary.
|
||||
# Edit the line below so that the variable is defined as the location
|
||||
# to speedtest on your system. On mine it is /usr/local/bin
|
||||
# Ensure to leave the last slash off!
|
||||
# You MUST define this or the script will not run!
|
||||
STb=/usr/bin
|
||||
|
||||
# Set up the variables to take the arguments
|
||||
DLw=150.00
|
||||
DLc=100.00
|
||||
ULw=150.00
|
||||
ULc=100.00
|
||||
Loc=e
|
||||
# Server ID, if 0 using nearest server
|
||||
SEs=0
|
||||
#PerfData=TRUE
|
||||
PerfData=
|
||||
debug=
|
||||
|
||||
# Retrieve the arguments using getopts
|
||||
while getopts "hw:c:W:C:l:s:pvV" OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h)
|
||||
usage
|
||||
exit 3
|
||||
;;
|
||||
w)
|
||||
DLw=$OPTARG
|
||||
;;
|
||||
c)
|
||||
DLc=$OPTARG
|
||||
;;
|
||||
W)
|
||||
ULw=$OPTARG
|
||||
;;
|
||||
C)
|
||||
ULc=$OPTARG
|
||||
;;
|
||||
l)
|
||||
Loc=$OPTARG
|
||||
;;
|
||||
s)
|
||||
SEs=$OPTARG
|
||||
;;
|
||||
p)
|
||||
PerfData="TRUE"
|
||||
;;
|
||||
v)
|
||||
echo "$plugin_name. Version number: $version"
|
||||
exit 3
|
||||
;;
|
||||
V)
|
||||
debug="TRUE"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
# Check if the Speedtest binary variable $STb has been defined and exit with warning if not
|
||||
if [[ -z $STb ]]
|
||||
then
|
||||
locundef
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Check for empty arguments and exit to usage if found
|
||||
if [[ -z $DLw ]] || [[ -z $DLc ]] || [[ -z $ULw ]] || [[ -z $ULc ]] || [[ -z $Loc ]] || [[ -z $SEs ]]
|
||||
then
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Check for invalid argument passed to $Loc and exit to usage if found
|
||||
if [[ "$Loc" != "e" ]] && [[ "$Loc" != "i" ]]
|
||||
then
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Check for non-numeric arguments
|
||||
isnumeric $DLw "Download Warning Level"
|
||||
isnumeric $DLc "Download Critical Level"
|
||||
isnumeric $ULw "Upload Warning Level"
|
||||
isnumeric $ULc "Upload Critical Level"
|
||||
#isnumeric $Serv "Server Number ID"
|
||||
|
||||
# Check that warning levels are not less than critical levels
|
||||
if float_cond "$DLw < $DLc"; then
|
||||
echo "\$DLw is less than \$DLc!"
|
||||
usage
|
||||
exit 3
|
||||
elif float_cond "$ULw < $ULc"; then
|
||||
echo "\$ULw is less than \$ULc!"
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Output arguments for debug
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Download Warning Level = "$DLw
|
||||
echo "Download Critical Level = "$DLc
|
||||
echo "Upload Warning Level = "$ULw
|
||||
echo "Upload Critical Level = "$ULc
|
||||
echo "Server Location = "$Loc
|
||||
echo "Server URL or Integer = "$SEs
|
||||
fi
|
||||
|
||||
#Set command up depending upon internal or external
|
||||
if [ "$Loc" == "e" ]; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "External Server defined"
|
||||
fi
|
||||
if [ "$SEs" == "0" ]; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "no SEs specified"
|
||||
fi
|
||||
command=$($STb/speedtest --simple)
|
||||
else
|
||||
command=$($STb/speedtest --server=$SEs --simple)
|
||||
fi
|
||||
elif [ "$Loc" == "i" ]; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Internal Server defined"
|
||||
fi
|
||||
command=$($STb/speedtest --mini=$SEs --simple)
|
||||
else
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "We should never get here as we checked the contents of Location variable earlier!"
|
||||
fi
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Get the output of the speedtest into an array
|
||||
# so we can begin to process it
|
||||
i=1
|
||||
typeset -a array
|
||||
|
||||
array=($command)
|
||||
|
||||
# Check if array empty or not having at least 9 indicies
|
||||
element_count=${#array[@]}
|
||||
expected_count="9"
|
||||
|
||||
# Output array indicies count for debug
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "count = $element_count"
|
||||
fi
|
||||
|
||||
if [ "$element_count" -ne "$expected_count" ]; then
|
||||
echo "You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?"
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# echo contents of speedtest for debug
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "$command"
|
||||
fi
|
||||
|
||||
# split array into our variables for processing
|
||||
ping=${array[1]}
|
||||
pingUOM=${array[2]}
|
||||
download=${array[4]}
|
||||
downloadUOM=${array[5]}
|
||||
upload=${array[7]}
|
||||
uploadUOM=${array[8]}
|
||||
|
||||
# echo each array for debug
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Ping = "$ping
|
||||
echo "Download = "$download
|
||||
echo "Upload = "$upload
|
||||
fi
|
||||
|
||||
#set up our nagios status and exit code variables
|
||||
status=
|
||||
nagcode=
|
||||
|
||||
# now we check to see if returned values are within defined ranges
|
||||
# we will make use of bc for our math!
|
||||
if float_cond "$download < $DLc"; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Download less than critical limit. \$download = $download and \$DLc = $DLc "
|
||||
fi
|
||||
status="CRITICAL"
|
||||
nagcode=2
|
||||
elif float_cond "$upload < $ULc"; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Upload less than critical limit. \$upload = $upload and \$ULc = $ULc"
|
||||
fi
|
||||
status="CRITICAL"
|
||||
nagcode=2
|
||||
elif float_cond "$download < $DLw"; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Download less than warning limit. \$download = $download and \$DLw = $DLw"
|
||||
fi
|
||||
status="WARNING"
|
||||
nagcode=1
|
||||
elif float_cond "$upload < $ULw"; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Upload less than warning limit. \$upload = $upload and \$ULw = $ULw"
|
||||
fi
|
||||
status="WARNING"
|
||||
nagcode=1
|
||||
else
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "Everything within bounds!"
|
||||
fi
|
||||
status="OK"
|
||||
nagcode=0
|
||||
fi
|
||||
|
||||
#nagout="$status - Ping = $ping $pingUOM Download = $download $downloadUOM Upload = $upload $uploadUOM"
|
||||
#perfout="|'download'=$download;$DLw;$DLc 'upload'=$upload;$ULw;$ULc"
|
||||
nagout="$nagcode speedtest-cli download=$download;$DLw;$DLc|upload=$upload;$ULw;$ULc|ping=$ping;250;500 Ping = $ping $pingUOM Download = $download $downloadUOM Upload = $upload $uploadUOM"
|
||||
|
||||
# append perfout if argument was passed to script
|
||||
if [ "$PerfData" == "TRUE" ]; then
|
||||
if [ "$debug" == "TRUE" ]; then
|
||||
echo "PerfData requested!"
|
||||
fi
|
||||
nagout=$nagout$perfout
|
||||
fi
|
||||
|
||||
echo $nagout
|
||||
exit $nagcode
|
28
files/check_mk.conf
Normal file
28
files/check_mk.conf
Normal file
@ -0,0 +1,28 @@
|
||||
service check_mk
|
||||
{
|
||||
type = UNLISTED
|
||||
port = 6556
|
||||
socket_type = stream
|
||||
protocol = tcp
|
||||
wait = no
|
||||
user = root
|
||||
server = /usr/bin/check_mk_agent
|
||||
|
||||
# listen on IPv4 AND IPv6 when available on this host
|
||||
#flags = IPv6
|
||||
|
||||
# If you use fully redundant monitoring and poll the client
|
||||
# from more then one monitoring servers in parallel you might
|
||||
# want to use the agent cache wrapper:
|
||||
#server = /usr/bin/check_mk_caching_agent
|
||||
|
||||
# configure the IP address(es) of your Nagios server here:
|
||||
only_from = 78.47.37.172
|
||||
|
||||
# Don't be too verbose. Don't log every check. This might be
|
||||
# commented out for debugging. If this option is commented out
|
||||
# the default options will be used for this service.
|
||||
log_on_success =
|
||||
|
||||
disable = no
|
||||
}
|
70
files/ckeck_mk-supernode
Normal file
70
files/ckeck_mk-supernode
Normal file
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
#/usr/lib/check_mk_agent/local
|
||||
export LANG=de_DE.UTF-8
|
||||
|
||||
function confline # get first line from file $1 mathing $2, stripped of # and ; comment lines, stripped spaces and tabs down to spaces, remove trailing ;
|
||||
{
|
||||
echo $(cat $1|grep -v '^$\|^\s*\#'|sed -e "s/[[:space:]]\+/ /g"|sed s/^\ //|sed s/\;//|grep -i "$2"|head -n 1)
|
||||
}
|
||||
|
||||
function ati # ipv4 to longint
|
||||
{
|
||||
ip4=$1; ipno=0
|
||||
for (( i=0 ; i<4 ; ++i )); do
|
||||
((ipno+=${ip4%%.*}*$((254**$((3-${i})))))) # .0 .255 should not be counted
|
||||
ip4=${ip4#*.}
|
||||
done
|
||||
echo $ipno
|
||||
}
|
||||
|
||||
## static data
|
||||
bat_version=$(batctl -v);
|
||||
kernel=$(uname -r);
|
||||
release=$(lsb_release -ds);
|
||||
|
||||
## Batman
|
||||
echo "0 Batman-Version Version=$bat_version; $bat_version"
|
||||
list=$(ls -F /sys/kernel/debug/batman_adv|grep /)
|
||||
for i in $list; do
|
||||
z=$(ls /sys/kernel/debug/batman_adv/$i|wc -l)
|
||||
if [ $z -ge 9 ]; then
|
||||
b=$(echo $i|cut -d '/' -f1)
|
||||
router=$(($(batctl -m $b o|wc -l)-2 ))
|
||||
clients=$(grep -cEo "\[.*W.*\]+" /sys/kernel/debug/batman_adv/$b/transtable_global)
|
||||
gateways=$(( $(batctl -m $b gwl|wc -l) -1 ))
|
||||
ips=$(( $(batctl -m $b dc|wc -l) - 2))
|
||||
wlow=$(( $router * 20 / 100 ))
|
||||
clow=$(( $router * 5 / 100 ))
|
||||
wlimit=$(( $router * 5 ))
|
||||
climit=$(( $router * 10 ))
|
||||
echo "P Batman-$b Router=$router.0;5:250;1:500|Clients=$clients.0;$wlow.0:$wlimit.0;$clow.0:$climit.0|Gateways=$gateways.0;0:3;0:5;|IPs=$ips.0";
|
||||
fi;
|
||||
done
|
||||
|
||||
## isc-dhcpd-server leases
|
||||
# needs script https://github.com/eulenfunk/scripts/blob/master/dhcpleases
|
||||
if [ -r /opt/freifunk/dhcpleases ] ; then
|
||||
totalleases=2040
|
||||
activeleases=$(python /opt/freifunk/dhcpleases|grep "^| Total"|cut -d":" -f2|sed s/\ //)
|
||||
remainingleases=$(($totalleases - $activeleases))
|
||||
actwarn=$(($totalleases * 75 / 100))
|
||||
actcrit=$(($totalleases * 90 / 100))
|
||||
echo "P Dhcp-Leases active-leases=$activeleases.0;5:$actwarn;1:$actcrit active:$activeleases remaining:$remainingleases pool=$totalleases";
|
||||
fi
|
||||
|
||||
#L2TP
|
||||
l_tunnel=$(ip a |grep l2tp | grep br-nodes -c);
|
||||
tunneldigger=$(ifconfig|grep br-nodes -c);
|
||||
echo "P L2TP Clients=$l_tunnel.0;1:100;0:150|Tunneldiggerbridges=$tunneldigger.0;0.1:1;0.1:2; L2TP-Clients:$l_tunnel Tunneldiggerbridges:$tunneldigger"
|
||||
|
||||
## Conntrack
|
||||
conntrack=$(conntrack -C);
|
||||
conntrack_limit=$(sysctl -a 2>/dev/null |grep net.nf_conntrack_max|cut -d ' ' -f 3);
|
||||
conntrack_remain=$(echo $conntrack_limit - $conntrack|bc)
|
||||
wlow=0.1
|
||||
clow=1.1
|
||||
wlimit=$(echo $conntrack_limit *0.7|bc)
|
||||
climit=$(echo $conntrack_limit *0.9|bc)
|
||||
wrlimit=$(echo $conntrack_limit *0.3|bc)
|
||||
crlimit=$(echo $conntrack_limit *0.1|bc)
|
||||
echo "P Conntrack conntrack=$conntrack.0;$wlow:$wlimit;$clow:$climit|conntrack_remain=$conntrack_remain.0;$wrlimit:$conntrack_limit;$crlimit:$conntrack_limit; Conntrack:$conntrack Conntrack-Remain:$conntrack_remain Conntrack-Limit:$conntrack_limit"
|
260
files/dhcpleases
Normal file
260
files/dhcpleases
Normal file
@ -0,0 +1,260 @@
|
||||
#!/usr/bin/python
|
||||
# source: http://askubuntu.com/revisions/fb67e8e2-efd4-4d0e-bb2f-416855fd8369/view-source
|
||||
# by http://askubuntu.com/users/499043/dfsmith
|
||||
import datetime, bisect
|
||||
|
||||
def parse_timestamp(raw_str):
|
||||
tokens = raw_str.split()
|
||||
|
||||
if len(tokens) == 1:
|
||||
if tokens[0].lower() == 'never':
|
||||
return 'never';
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in timestamp')
|
||||
|
||||
elif len(tokens) == 3:
|
||||
return datetime.datetime.strptime(' '.join(tokens[1:]),
|
||||
'%Y/%m/%d %H:%M:%S')
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in timestamp')
|
||||
|
||||
|
||||
def timestamp_is_ge(t1, t2):
|
||||
if t1 == 'never':
|
||||
return True
|
||||
|
||||
elif t2 == 'never':
|
||||
return False
|
||||
|
||||
else:
|
||||
return t1 >= t2
|
||||
|
||||
|
||||
def timestamp_is_lt(t1, t2):
|
||||
if t1 == 'never':
|
||||
return False
|
||||
|
||||
elif t2 == 'never':
|
||||
return t1 != 'never'
|
||||
|
||||
else:
|
||||
return t1 < t2
|
||||
|
||||
|
||||
def timestamp_is_between(t, tstart, tend):
|
||||
return timestamp_is_ge(t, tstart) and timestamp_is_lt(t, tend)
|
||||
|
||||
|
||||
def parse_hardware(raw_str):
|
||||
tokens = raw_str.split()
|
||||
|
||||
if len(tokens) == 2:
|
||||
return tokens[1]
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in hardware')
|
||||
|
||||
|
||||
def strip_endquotes(raw_str):
|
||||
return raw_str.strip('"')
|
||||
|
||||
|
||||
def identity(raw_str):
|
||||
return raw_str
|
||||
|
||||
|
||||
def parse_binding_state(raw_str):
|
||||
tokens = raw_str.split()
|
||||
|
||||
if len(tokens) == 2:
|
||||
return tokens[1]
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in binding state')
|
||||
|
||||
|
||||
def parse_next_binding_state(raw_str):
|
||||
tokens = raw_str.split()
|
||||
|
||||
if len(tokens) == 3:
|
||||
return tokens[2]
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in next binding state')
|
||||
|
||||
|
||||
def parse_rewind_binding_state(raw_str):
|
||||
tokens = raw_str.split()
|
||||
|
||||
if len(tokens) == 3:
|
||||
return tokens[2]
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in next binding state')
|
||||
|
||||
|
||||
def parse_leases_file(leases_file):
|
||||
valid_keys = {
|
||||
'starts': parse_timestamp,
|
||||
'ends': parse_timestamp,
|
||||
'tstp': parse_timestamp,
|
||||
'tsfp': parse_timestamp,
|
||||
'atsfp': parse_timestamp,
|
||||
'cltt': parse_timestamp,
|
||||
'hardware': parse_hardware,
|
||||
'binding': parse_binding_state,
|
||||
'next': parse_next_binding_state,
|
||||
'rewind': parse_rewind_binding_state,
|
||||
'uid': strip_endquotes,
|
||||
'client-hostname': strip_endquotes,
|
||||
'option': identity,
|
||||
'set': identity,
|
||||
'on': identity,
|
||||
'abandoned': None,
|
||||
'bootp': None,
|
||||
'reserved': None,
|
||||
}
|
||||
|
||||
leases_db = {}
|
||||
|
||||
lease_rec = {}
|
||||
in_lease = False
|
||||
in_failover = False
|
||||
|
||||
for line in leases_file:
|
||||
if line.lstrip().startswith('#'):
|
||||
continue
|
||||
|
||||
tokens = line.split()
|
||||
|
||||
if len(tokens) == 0:
|
||||
continue
|
||||
|
||||
key = tokens[0].lower()
|
||||
|
||||
if key == 'lease':
|
||||
if not in_lease:
|
||||
ip_address = tokens[1]
|
||||
|
||||
lease_rec = {'ip_address' : ip_address}
|
||||
in_lease = True
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in leases file')
|
||||
|
||||
elif key == 'failover':
|
||||
in_failover = True
|
||||
elif key == '}':
|
||||
if in_lease:
|
||||
for k in valid_keys:
|
||||
if callable(valid_keys[k]):
|
||||
lease_rec[k] = lease_rec.get(k, '')
|
||||
else:
|
||||
lease_rec[k] = False
|
||||
|
||||
ip_address = lease_rec['ip_address']
|
||||
|
||||
if ip_address in leases_db:
|
||||
leases_db[ip_address].insert(0, lease_rec)
|
||||
|
||||
else:
|
||||
leases_db[ip_address] = [lease_rec]
|
||||
|
||||
lease_rec = {}
|
||||
in_lease = False
|
||||
|
||||
elif in_failover:
|
||||
in_failover = False
|
||||
continue
|
||||
else:
|
||||
raise Exception('Parse error in leases file')
|
||||
|
||||
elif key in valid_keys:
|
||||
if in_lease:
|
||||
value = line[(line.index(key) + len(key)):]
|
||||
value = value.strip().rstrip(';').rstrip()
|
||||
|
||||
if callable(valid_keys[key]):
|
||||
lease_rec[key] = valid_keys[key](value)
|
||||
else:
|
||||
lease_rec[key] = True
|
||||
|
||||
else:
|
||||
raise Exception('Parse error in leases file')
|
||||
|
||||
else:
|
||||
if in_lease:
|
||||
raise Exception('Parse error in leases file')
|
||||
|
||||
if in_lease:
|
||||
raise Exception('Parse error in leases file')
|
||||
|
||||
return leases_db
|
||||
|
||||
|
||||
def round_timedelta(tdelta):
|
||||
return datetime.timedelta(tdelta.days,
|
||||
tdelta.seconds + (0 if tdelta.microseconds < 500000 else 1))
|
||||
|
||||
|
||||
def timestamp_now():
|
||||
n = datetime.datetime.utcnow()
|
||||
return datetime.datetime(n.year, n.month, n.day, n.hour, n.minute,
|
||||
n.second + (0 if n.microsecond < 500000 else 1))
|
||||
|
||||
|
||||
def lease_is_active(lease_rec, as_of_ts):
|
||||
return timestamp_is_between(as_of_ts, lease_rec['starts'],
|
||||
lease_rec['ends'])
|
||||
|
||||
|
||||
def ipv4_to_int(ipv4_addr):
|
||||
parts = ipv4_addr.split('.')
|
||||
return (int(parts[0]) << 24) + (int(parts[1]) << 16) + \
|
||||
(int(parts[2]) << 8) + int(parts[3])
|
||||
|
||||
|
||||
def select_active_leases(leases_db, as_of_ts):
|
||||
retarray = []
|
||||
sortedarray = []
|
||||
|
||||
for ip_address in leases_db:
|
||||
lease_rec = leases_db[ip_address][0]
|
||||
|
||||
if lease_is_active(lease_rec, as_of_ts):
|
||||
ip_as_int = ipv4_to_int(ip_address)
|
||||
insertpos = bisect.bisect(sortedarray, ip_as_int)
|
||||
sortedarray.insert(insertpos, ip_as_int)
|
||||
retarray.insert(insertpos, lease_rec)
|
||||
|
||||
return retarray
|
||||
|
||||
|
||||
##############################################################################
|
||||
|
||||
|
||||
myfile = open('/var/lib/dhcp/dhcpd.leases', 'r')
|
||||
leases = parse_leases_file(myfile)
|
||||
myfile.close()
|
||||
|
||||
now = timestamp_now()
|
||||
report_dataset = select_active_leases(leases, now)
|
||||
|
||||
print('+------------------------------------------------------------------------------')
|
||||
print('| DHCPD ACTIVE LEASES REPORT')
|
||||
print('+-----------------+-------------------+----------------------+-----------------')
|
||||
print('| IP Address | MAC Address | Expires (days,H:M:S) | Client Hostname ')
|
||||
print('+-----------------+-------------------+----------------------+-----------------')
|
||||
|
||||
for lease in report_dataset:
|
||||
print('| ' + format(lease['ip_address'], '<15') + ' | ' + \
|
||||
format(lease['hardware'], '<17') + ' | ' + \
|
||||
format(str((lease['ends'] - now) if lease['ends'] != 'never' else 'never'), '>20') + ' | ' + \
|
||||
lease['client-hostname'])
|
||||
|
||||
print('+-----------------+-------------------+----------------------+-----------------')
|
||||
print('| Total Active Leases: ' + str(len(report_dataset)))
|
||||
print('| Report generated (UTC): ' + str(now))
|
||||
print('+------------------------------------------------------------------------------')
|
@ -10,7 +10,7 @@
|
||||
gather_facts: False
|
||||
vars:
|
||||
snversion: master_v3.0.16
|
||||
batmanversion: v2015.2
|
||||
batmanversion: v2017.4
|
||||
common_required_packages:
|
||||
- git
|
||||
- make
|
||||
@ -41,6 +41,9 @@
|
||||
- psmisc
|
||||
- dnsutils
|
||||
- ntp
|
||||
- libnl-genl-3-dev
|
||||
- virtualenv
|
||||
- linux-image-extra-4.4.0-127-generic
|
||||
modules_required:
|
||||
- batman-adv
|
||||
- nf_conntrack_netlink
|
||||
@ -118,14 +121,14 @@
|
||||
register: aptupdates
|
||||
- name: Set clock
|
||||
shell: /etc/init.d/ntp stop && /usr/sbin/ntpd -q -g && /etc/init.d/ntp start
|
||||
- name: Add modules
|
||||
lineinfile: dest=/etc/modules line={{ item }}
|
||||
with_items: modules_required
|
||||
register: modules_req
|
||||
- name: Load modules
|
||||
modprobe: name={{ item }}
|
||||
with_items: modules_required
|
||||
when: modules_req.changed
|
||||
# - name: Add modules
|
||||
# lineinfile: dest=/etc/modules line={{ item }}
|
||||
# with_items: modules_required
|
||||
# register: modules_req
|
||||
# - name: Load modules
|
||||
# modprobe: name={{ item }}
|
||||
# with_items: modules_required
|
||||
# when: modules_req.changed
|
||||
- name: Install Linux headers
|
||||
shell: >
|
||||
apt-get install linux-headers-$(uname -r) -y
|
||||
@ -179,6 +182,16 @@
|
||||
copy: src=./files/{{ item }} dest=/etc/systemd/system owner=root group=root mode=0444
|
||||
with_items: tunneldigger_service
|
||||
when: tunneldigger.changed
|
||||
##########
|
||||
- name: Add modules
|
||||
lineinfile: dest=/etc/modules line={{ item }}
|
||||
with_items: modules_required
|
||||
register: modules_req
|
||||
- name: Load modules
|
||||
modprobe: name={{ item }}
|
||||
with_items: modules_required
|
||||
when: modules_req.changed
|
||||
#########
|
||||
- name: Tunneldigger reload
|
||||
command: "{{item}}"
|
||||
with_items:
|
||||
@ -308,6 +321,8 @@
|
||||
poll: 0
|
||||
ignore_errors: true
|
||||
when: tunneldigger.changed
|
||||
- name: Logrotate rights
|
||||
file: path=/etc/logrotate.conf mode=0644 owner=root group=root
|
||||
- name: Change root password
|
||||
user: name=root password={{ sn_rootpasswd }}
|
||||
- name: Wirte version information
|
||||
|
Loading…
Reference in New Issue
Block a user