From 7e3875015fc15eb99f1ff03593356dbc355869de Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 15 Jan 2018 22:50:44 +0100 Subject: [PATCH] GWinfo erstellt --- GWinfo.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 GWinfo.sh diff --git a/GWinfo.sh b/GWinfo.sh new file mode 100755 index 0000000..f00384b --- /dev/null +++ b/GWinfo.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# +# Gateway data script for FFF Monitoring +# Copyright Adrian Schmutzler, 2018. +# License GPLv3 +# +# v1.2.1 - 2018-01-12 +# - Added "grep fff" to support L2TP +# +# v1.2 - 2018-01-12 +# - Added batctl command and vpnif +# +# v1.1 - 2018-01-12 +# - Initial Version +# + +# Config +api_url="http://monitoring.freifunk-franken.de/api/gwinfo" +batctlpath=/usr/local/sbin/batctl # Adjust to YOUR path! +hostname="fff-ab-01" # Namen nicht zu lang machen, kein hostname.fff.irgendwas +admin1="da-checka" +admin2= +admin3= +statslink="http://5.189.177.88" # Provide link to stats page (MRTG or similar) + +# Code +tmp=$(/bin/mktemp) +echo "{\"hostname\":\"$hostname\",\"stats_page\":\"$statslink\",\"netifs\":[" > $tmp + +comma="" +for netif in $(ls /sys/class/net); do + if [ "$netif" = "lo" ] ; then + continue + fi + mac="$(cat "/sys/class/net/$netif/address")" + batctl="$("$batctlpath" -m "$netif" if | grep "fff" | sed -n 's/:.*//p')" + echo "$comma{\"mac\":\"$mac\",\"netif\":\"$netif\",\"vpnif\":\"$batctl\"}" >> $tmp + comma="," +done + +echo "],\"admins\":[" >> $tmp + +comma="" +[ -n "$admin1" ] && echo "\"$admin1\"" >> $tmp && comma="," +[ -n "$admin2" ] && echo "$comma\"$admin2\"" >> $tmp && comma="," +[ -n "$admin3" ] && echo "$comma\"$admin3\"" >> $tmp + +echo "]}" >> $tmp + + +/usr/bin/curl -k -v -H "Content-type: application/json; charset=UTF-8" -X POST --data-binary @$tmp $api_url +/bin/rm "$tmp"