forked from eulenfunk/check_mk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapsrv
executable file
·125 lines (110 loc) · 4.87 KB
/
mapsrv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/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 conflines # get lines 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)"
}
## apt-check moved to delayed check (600 seconds), needs 2 steps deployment
servicesname="mapsrv-services"
interval=600
if [ ! -d "/usr/lib/check_mk_agent/local/$interval" ]; then
mkdir /usr/lib/check_mk_agent/local/$interval
fi
if [ ! -f "/usr/lib/check_mk_agent/local/$interval/$servicesname" ]; then
cat <<EOT >> /usr/lib/check_mk_agent/local/$interval/$servicesname
#!/bin/bash
#/usr/lib/check_mk_agent/local
echo DYSFUNCTIONAL delayed localcheck placeholder, please redeploy
EOT
chmod +x /usr/lib/check_mk_agent/local/$interval/$servicesname
fi
## static data
kernel=$(uname -r);
release=$(lsb_release -ds);
latestbootkernel=$(ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | sort -Vr | head -n1)
## ubuntu-Status
echo "0 Ubuntu-Release Ubuntu-Release=$release; $release - Kernel $kernel; Boot $latestbootkernel"
## logins
logincount=$(who|wc -l)
logout="0 LocalUser CurrentLogins=$logincount.0; CurrentLogins:$logincount"
i=0
TFILE="/tmp/$(basename $0).$$.tmp"
who -u>$TFILE
while read line; do
i=$(( i + 1))
line=$(echo $line|sed s/\ +//|tr -s " ")
user=$(echo $line|cut -d" " -f1)
tty=$(echo $line|cut -d" " -f2)
idle=$(echo $line|cut -d" " -f6)
ip=$(echo $line|cut -d" " -f8)
logout="$logout\n login-$i-user:$user login-$i-tty:$tty login-$i-idle:$idle login-$i-source:$ip"
done<$TFILE
rm $TFILE
echo "$logout"
## Batman-Advanced
bat_version=$(batctl -v)
bat_adv_v=$(batctl -v 2>/dev/null|cut -d" " -f4|tr -d "]")
bat_ctl_v=$(batctl -v 2>/dev/null|cut -d" " -f2)
batadvequal=2
if [ "$bat_adv_v" == "$bat_ctl_v" ] ; then
batadvequal=1
fi
echo "P Batman-Version kernelvsctl=$batadvequal;1:2;0:3 versions:$bat_version"
#list=$(ls -F /sys/kernel/debug/batman_adv|grep /)
list=$(ip link|grep ",UP,"|cut -d" " -f2|tr -d ":")
if [[ $list != *"bat0"* ]]; then
list="$list bat0"
fi
for b in $list; do
z=$( batctl -m $b o 2>/dev/null | wc -l )
if [ $z -ge 1 ]; then
# b=$(echo $i|cut -d '/' -f1)
sitename=$(echo $b|cut -b5-)
checkbat=$(conflines /opt/eulenfunk/map/sites instance|grep "\ $sitename")
checkgw=$(echo $checkbat|cut -d" " -f 8)
checkgwh=$(( $checkgw +1 ))
checkrouter=$(echo $checkbat|cut -d" " -f 9)
checkclients=$(echo $checkbat|cut -d" " -f 10)
router=$(($(batctl -m $b o 2>/dev/null|grep "^\ \*"|wc -l)-0 ))
clients=$(batctl -m $b tg 2>/dev/null| grep "^\ \*"|grep -cEo "\[.*W.*\]+")
owngw=$(batctl -m $b gw 2>/dev/null|cut -d" " -f1|sed s/server/1/|sed s/off/0/)
gateways=$(($(batctl -m $b gwl 2>/dev/null|grep -A 999 outgoingIf|grep -v outgoingIf|wc -l ) + $owngw))
clientwarnlow=$(( $checkclients * 2 / 100 ))
clientcritlow=$(( $checkclients * 1 / 100 ))
clientwarnhigh=$(( $checkclients * 80 / 100 ))
clientcrithigh=$(( $checkclients ))
routerwarnlow=$(( $checkrouter * 10 / 100 ))
routercritlow=$(( $checkrouter * 5 / 100 ))
routerwarnhigh=$(( $checkrouter * 80 / 100 ))
routercrithigh=$(( $checkrouter ))
# needs dhtest from https://github.com/saravana815/dhtest compiled
if [ -x /opt/eulenfunk/dhtest/dhtest ] ; then
pushd /tmp >/dev/null
clientmac=ca:b1:e9:fa:b1:78
dhtestack=$(/opt/eulenfunk/dhtest/dhtest -i $b -m $clientmac -h check_mk -T 6|grep "DHCP ack received")
dhtest=0
dhtestip=0
if [ -n "$dhtestack" ] ; then
dhtest=$(echo $dhtestack|wc -l)
dhtestip=$(echo $dhtestack|cut -d":" -f2|tr -d " ")
fi
rm -f "$clientmac"
popd >/dev/null
echo "P Batman-$b Router=$router.0;$routerwarnlow.0:$routerwarnhigh.0;$routercritlow.0:$routercrithigh.0|Clients=$clients.0;$clientwarnlow.0:$clientwarnhigh.0;$clientcritlow.0:$clientcrithigh.0|Gateways=$gateways.0;$checkgw.0:$checkgwh.0;$checkgw.0:$checkgwh.0;|dhtest=$dhtest.0;0:2;0:2 dhtestip=$dhtestip";
else
echo "P Batman-$b Router=$router.0;$routerwarnlow.0:$routerwarnhigh.0;$routercritlow.0:$routercrithigh.0|Clients=$clients.0;$clientwarnlow.0:$clientwarnhigh.0;$clientcritlow.0:$clientcrithigh.0|Gateways=$gateways.0;$checkgw.0:$checkgwh.0;$checkgw.0:$checkgwh.0";
fi
fi;
done
#Get data
l_tunnel=$(ip a |grep l2tp|grep tunneldigger -c);
tunneldigger=$(ifconfig|grep tunneldigger -c);
#Output
echo "P L2TP Clients=$l_tunnel.0;1:30;0:80|Tunneldiggerbridges=$tunneldigger.0;0.1:2;0.1:3; L2TP-Clients:$l_tunnel Tunneldiggerbridges:$tunneldigger"
# call the other one..
/opt/eulenfunk/map/check.sh