From 13298773a3dbf0afe3cdbf337b89f103b16cf293 Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:46:22 +0200 Subject: [PATCH 01/16] Create Todo --- Todo | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Todo diff --git a/Todo b/Todo new file mode 100644 index 0000000..f377364 --- /dev/null +++ b/Todo @@ -0,0 +1,4 @@ +TODO + +1. Check_mk Agent installieren +2. Check_Mk Local checks From d156ea2d607a62cbc01bad111a2a51240ed20e5b Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:47:37 +0200 Subject: [PATCH 02/16] Create dhcpleases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DHCP-Leasees Python Script für Check_mk und DNS Auto Hostnames --- files/dhcpleases | 260 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 files/dhcpleases diff --git a/files/dhcpleases b/files/dhcpleases new file mode 100644 index 0000000..40465c2 --- /dev/null +++ b/files/dhcpleases @@ -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('+------------------------------------------------------------------------------') From df2c3c8fa3ec1ae096c0a8d4f8b8ec9a0b6d9bd7 Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:51:13 +0200 Subject: [PATCH 03/16] Update Todo --- Todo | 1 + 1 file changed, 1 insertion(+) diff --git a/Todo b/Todo index f377364..f7a1ee3 100644 --- a/Todo +++ b/Todo @@ -2,3 +2,4 @@ TODO 1. Check_mk Agent installieren 2. Check_Mk Local checks +File: dhcpleases kopieren nach /opt/freifunk/dhcpleases und ausführbar machen From 10827541b410e58491fbe92d6d2c2e8c6996c5a5 Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:52:29 +0200 Subject: [PATCH 04/16] Create check_mk_dhcp.sh --- check_mk_dhcp.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 check_mk_dhcp.sh diff --git a/check_mk_dhcp.sh b/check_mk_dhcp.sh new file mode 100644 index 0000000..90a4827 --- /dev/null +++ b/check_mk_dhcp.sh @@ -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" From 992273bd68ffc87fec80b84c86c9306ec371032b Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:52:40 +0200 Subject: [PATCH 05/16] Delete check_mk_dhcp.sh --- check_mk_dhcp.sh | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 check_mk_dhcp.sh diff --git a/check_mk_dhcp.sh b/check_mk_dhcp.sh deleted file mode 100644 index 90a4827..0000000 --- a/check_mk_dhcp.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/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" From 676b3120d5db22853e7b1203dfa3759a650d7655 Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:52:59 +0200 Subject: [PATCH 06/16] Create check_mk-dhcp.sh --- files/check_mk-dhcp.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 files/check_mk-dhcp.sh diff --git a/files/check_mk-dhcp.sh b/files/check_mk-dhcp.sh new file mode 100644 index 0000000..90a4827 --- /dev/null +++ b/files/check_mk-dhcp.sh @@ -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" From bc0dc3b5036003454e3e3dab2b5f0ae1cac0dc2c Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:54:13 +0200 Subject: [PATCH 07/16] Create check_mk-speedtest-cli --- files/check_mk-speedtest-cli | 392 +++++++++++++++++++++++++++++++++++ 1 file changed, 392 insertions(+) create mode 100644 files/check_mk-speedtest-cli diff --git a/files/check_mk-speedtest-cli b/files/check_mk-speedtest-cli new file mode 100644 index 0000000..abe634a --- /dev/null +++ b/files/check_mk-speedtest-cli @@ -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 From 1de96d7feb9c306dbf99d54929e95c63d938d448 Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:55:05 +0200 Subject: [PATCH 08/16] Create ckeck_mk-supernode --- files/ckeck_mk-supernode | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 files/ckeck_mk-supernode diff --git a/files/ckeck_mk-supernode b/files/ckeck_mk-supernode new file mode 100644 index 0000000..19a902c --- /dev/null +++ b/files/ckeck_mk-supernode @@ -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" From 42a284cdde62048bcc507e9782f9bc7cffd37ecc Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 11:59:48 +0200 Subject: [PATCH 09/16] Update Todo --- Todo | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Todo b/Todo index f7a1ee3..51ffcce 100644 --- a/Todo +++ b/Todo @@ -2,4 +2,9 @@ TODO 1. Check_mk Agent installieren 2. Check_Mk Local checks -File: dhcpleases kopieren nach /opt/freifunk/dhcpleases und ausführbar machen +3. File: dhcpleases kopieren nach /opt/freifunk/dhcpleases und ausführbar machen +4. Check_mk Local Checks: + 4.1 /usr/lib/check_mk_agent/local/supernode kopieren und ausführbar machen (file: check_mk-supernode) + 4.2 /usr/lib/check_mk_agent/local/3600/speedtest-cli kopieren und ausführbar machen (file: check_mk-speedtest-cli) + 4.3 /usr/lib/check_mk_agent/local/3600/dhcp.sh kopieren und ausführbar machen (file: check_mk-dhcp.sh) +5. Check_Mk config zugriffe nur von unserem Check_mk zulassen (file: check_mk.conf) nach /etc/xinted.d/check_mk From 07716a757d7a0bb574aeceaa1a962815d0b15d55 Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 12:00:11 +0200 Subject: [PATCH 10/16] Create check_mk.conf --- files/check_mk.conf | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 files/check_mk.conf diff --git a/files/check_mk.conf b/files/check_mk.conf new file mode 100644 index 0000000..96807a5 --- /dev/null +++ b/files/check_mk.conf @@ -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 +} From b2074306604824f722b95c5b708f890f70f87033 Mon Sep 17 00:00:00 2001 From: stebifan Date: Sun, 18 Jun 2017 12:01:17 +0200 Subject: [PATCH 11/16] Update Todo --- Todo | 1 + 1 file changed, 1 insertion(+) diff --git a/Todo b/Todo index 51ffcce..ac0c176 100644 --- a/Todo +++ b/Todo @@ -8,3 +8,4 @@ TODO 4.2 /usr/lib/check_mk_agent/local/3600/speedtest-cli kopieren und ausführbar machen (file: check_mk-speedtest-cli) 4.3 /usr/lib/check_mk_agent/local/3600/dhcp.sh kopieren und ausführbar machen (file: check_mk-dhcp.sh) 5. Check_Mk config zugriffe nur von unserem Check_mk zulassen (file: check_mk.conf) nach /etc/xinted.d/check_mk +6. xinetd installieren (apt) From f6031565ebbc8b0e62dbefa1f9318ef537714ff7 Mon Sep 17 00:00:00 2001 From: stebifan Date: Tue, 5 Sep 2017 22:02:54 +0200 Subject: [PATCH 12/16] Update Todo --- Todo | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Todo b/Todo index ac0c176..5b563e4 100644 --- a/Todo +++ b/Todo @@ -9,3 +9,40 @@ TODO 4.3 /usr/lib/check_mk_agent/local/3600/dhcp.sh kopieren und ausführbar machen (file: check_mk-dhcp.sh) 5. Check_Mk config zugriffe nur von unserem Check_mk zulassen (file: check_mk.conf) nach /etc/xinted.d/check_mk 6. xinetd installieren (apt) +7. 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 + +================================================================== From 0bf611b7ad2f52da424a994ed3b82175352a08bf Mon Sep 17 00:00:00 2001 From: stebifan Date: Thu, 19 Apr 2018 17:37:24 +0200 Subject: [PATCH 13/16] Update Todo --- Todo | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Todo b/Todo index 5b563e4..a93bc1c 100644 --- a/Todo +++ b/Todo @@ -1,15 +1,6 @@ TODO -1. Check_mk Agent installieren -2. Check_Mk Local checks -3. File: dhcpleases kopieren nach /opt/freifunk/dhcpleases und ausführbar machen -4. Check_mk Local Checks: - 4.1 /usr/lib/check_mk_agent/local/supernode kopieren und ausführbar machen (file: check_mk-supernode) - 4.2 /usr/lib/check_mk_agent/local/3600/speedtest-cli kopieren und ausführbar machen (file: check_mk-speedtest-cli) - 4.3 /usr/lib/check_mk_agent/local/3600/dhcp.sh kopieren und ausführbar machen (file: check_mk-dhcp.sh) -5. Check_Mk config zugriffe nur von unserem Check_mk zulassen (file: check_mk.conf) nach /etc/xinted.d/check_mk -6. xinetd installieren (apt) -7. Statisches Routing über Interconnect Router +1. Statisches Routing über Interconnect Router ================================================================== # SN 4 @@ -46,3 +37,5 @@ 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 From f687accec3949a836ab823d06193c6d2398fae3b Mon Sep 17 00:00:00 2001 From: rojoka Date: Mon, 21 May 2018 18:57:05 +0200 Subject: [PATCH 14/16] logrotate corrected --- Todo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Todo b/Todo index a93bc1c..e72c9c0 100644 --- a/Todo +++ b/Todo @@ -39,3 +39,5 @@ 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 From f953a01b84f33a5049ca56d929b782b51e62d568 Mon Sep 17 00:00:00 2001 From: Ansible Admin Date: Tue, 3 Jul 2018 21:20:16 +0200 Subject: [PATCH 15/16] Access rights logrotate.conf set to 644 --- install.sn.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/install.sn.yml b/install.sn.yml index b7fd977..63fafcc 100644 --- a/install.sn.yml +++ b/install.sn.yml @@ -308,6 +308,11 @@ poll: 0 ignore_errors: true when: tunneldigger.changed + - file: + path: /etc/logrotate.conf + owner: root + group: root + mode: 0644 - name: Change root password user: name=root password={{ sn_rootpasswd }} - name: Wirte version information From 301dc1ecb5acd5fdf16d373cd6dd0bf94dc119a2 Mon Sep 17 00:00:00 2001 From: Ansible Admin Date: Tue, 3 Jul 2018 23:10:50 +0200 Subject: [PATCH 16/16] Batman-adv fixes for Ubuntu 16.04 --- install.sn.yml | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/install.sn.yml b/install.sn.yml index 63fafcc..931c20e 100644 --- a/install.sn.yml +++ b/install.sn.yml @@ -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,11 +321,8 @@ poll: 0 ignore_errors: true when: tunneldigger.changed - - file: - path: /etc/logrotate.conf - owner: root - group: root - mode: 0644 + - 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