-
Notifications
You must be signed in to change notification settings - Fork 6
/
konzentrator
194 lines (182 loc) · 8.01 KB
/
konzentrator
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/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)"
}
## static data
kernel=$(uname -r);
release=$(lsb_release -ds);
## ubuntu-Status
echo "0 Ubuntu-Release Ubuntu-Release=$release; $release - Kernel $kernel"
## ubuntu patch status
nupdates=0
supdates=0
nupdates=$(cat /var/lib/update-notifier/updates-available|grep -i 'packages\ can\ be\ updated\|Software-Pakete'|cut -d" " -f1)
supdates=$(cat /var/lib/update-notifier/updates-available|grep -i 'updates\ are\ security\ updates\|Sicherheitsaktualisierungen'|cut -d" " -f1)
reboot=0
if [ -x /usr/lib/update-notifier/update-motd-reboot-required ]; then
reboot=$(/usr/lib/update-notifier/update-motd-reboot-required|grep \*\*\**\*\*\*|wc -l)
fi
echo "P Ubuntu-Patchstatus SecurityUpdates-waiting=$supdates.0;0:0.9;0:2|RegularUpdates-waiting=$nupdates.0;0:10;0:15|Reboot-waiting=$reboot.0;0:0.9;0:1"
## 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"
# BGP-interfaces
interconf=/etc/network/interfaces
tunnel=$(conflines $interconf iface|grep " tunnel")
tunnelzahl=$(echo "$tunnel"|wc -l)
tunnelup=0
while read -r line; do
remote=$(echo $line|cut -d" " -f2)
state=$(ip link|grep $remote|wc -l)
if [ $state -eq 1 ]; then
tunnelup=$(( $tunnelup + 1 ))
tunnelst="UP"
else
tunnelst="DOWN"
fi
mtu=$(ip link|grep $remote|cut -d" " -f5)
echo "P tunl_$remote link-$remote=$state.0;0:2;0:2; link-$remote:$tunnelst mtu:$mtu"
done <<< "$tunnel"
wlow=$(( $tunnelzahl - 2))
clow=$(( $tunnelzahl - 1))
wlimit=$(( $tunnelzahl + 1))
climit=$(( $tunnelzahl + 1))
echo "P Tunlinks Tunnel-Up=$tunnelup.0;$wlow:$wlimit;$clow:$climit|Tunnel-Configured=$tunnelzahl.0 Tunnel-Configured:$tunnelzahl Tunnel-Up:$tunnelup"
## Bird4
bird4conf=/etc/bird/bird.conf
bird4=$(conflines $bird4conf protocol|grep -i " bgp")
bird4confzahl=$(echo "$bird4"|wc -l)
bird4loaded=0
bird4up=0
bird4imported=0
bird4exported=0
wlow=$(( $bird4confzahl - 2 ))
clow=$(( $bird4confzahl - 1 ))
wlimit=$(( $bird4confzahl + 1 ))
climit=$(( $bird4confzahl + 1 ))
TFILE="/tmp/$(basename $0).$$.tmp"
birdc s p>$TFILE
while read line; do
line=$(echo $line|sed -e "s/[[:space:]]\+/ /g"|sed s/^\ //|sed s/\;//)
if [ $(echo $line|cut -d" " -f2) = "BGP" ] ; then
bird4loaded=$(( $bird4loaded + 1))
remote=$(echo $line|cut -d" " -f1)
link=$(echo $line|cut -d" " -f4)
since=$(echo $line|cut -d" " -f5)
linkstate=$(echo $line|cut -d" " -f6)
state=2
if [ $linkstate = "Established" ] ; then
birdlink="UP"
bird4up=$(( $bird4up + 1 ))
state=0
else
birdlink="DOWN"
fi
TFILE2="/tmp/$(basename $0).$$$.tmp"
birdc s p all $remote>$TFILE2
preference=$(confline $TFILE2 Preference:|cut -d" " -f2)
routes=$(confline $TFILE2 Routes:)
imported=$(echo $routes|cut -d" " -f2-3|grep -i "imported"|cut -d" " -f1)
bird4imported=$(( $bird4imported + $imported ))
exported=$(echo $routes|cut -d" " -f4-5|grep -i "exported"|cut -d" " -f1)
bird4exported=$(( $bird4exported + $exported ))
preferred=$(echo $routes|cut -d" " -f6-7|grep -i "preferred"|cut -d" " -f1)
ImportUp=$(confline $TFILE2 "Import")
ImpUpAcp=$(echo $routes|cut -d" " -f6)
ImportUp=$(confline $TFILE2 "Import withdraws:")
ImpUpWit=$(echo $routes|cut -d" " -f6)
ExportUp=$(confline $TFILE2 "Export updates:")
ExpUpAcp=$(echo $routes|cut -d" " -f6)
ExportUp=$(confline $TFILE2 "Export withdraws:")
ExpUpWit=$(echo $routes|cut -d" " -f6)
rm $TFILE2
echo "$state bird4l-$remote Bird4-$remote=$linkok.0 linkstate:$linkstate since:$since preference:$preference preferred:$preferred imported:$imported exported:$exported ImpUpAcp:$ImpUpAcp ImpUpWit:$ImpUpWit ExpUpAcp:$ExpUpAcp ExUpWit:$ExpUpWit"
fi
done<$TFILE
rm $TFILE
echo "P Bird4links bird4-Up=$bird4up.0;$wlow:$wlimit;$clow:$climit|Bird4-Configured=$bird4confzahl.0|Bird4-Loaded=$bird4loaded.0;$(($bird4confzahl - 1)):$(($bird4confzahl + 1));$(($bird4confzahl - 1)):$(($bird4confzahl + 1))|Bird4Imported=$bird4imported.0|Bird4Exported=$bird4exported.0 Up:$bird4up Configured:$bird4confzahl Loaded:$bird4loaded Imported:$bird4imported Exported:$bird4exported"
## Bird6
bird6conf=/etc/bird/bird6.conf
bird6=$(conflines $bird6conf protocol|grep -i " bgp")
bird6confzahl=$(echo "$bird6"|wc -l)
bird6loaded=0
bird6up=0
bird6imported=0
bird6exported=0
wlow=$(( $bird6confzahl - 2))
clow=$(( $bird6confzahl - 1))
wlimit=$(( $bird6confzahl + 1))
climit=$(( $bird6confzahl + 1))
TFILE="/tmp/$(basename $0).$$.tmp"
birdc6 s p>$TFILE
while read line; do
line=$(echo $line|sed -e "s/[[:space:]]\+/ /g"|sed s/^\ //|sed s/\;//)
if [ $(echo $line|cut -d" " -f2) = "BGP" ] ; then
bird6loaded=$(( $bird6loaded + 1))
remote=$(echo $line|cut -d" " -f1)
link=$(echo $line|cut -d" " -f4)
since=$(echo $line|cut -d" " -f5)
linkstate=$(echo $line|cut -d" " -f6)
state=2
if [ $linkstate = "Established" ] ; then
birdlink="UP"
bird6up=$(( $bird6up + 1 ))
state=0
else
birdlink="DOWN"
fi
TFILE2="/tmp/$(basename $0).$$$.tmp"
birdc6 s p all $remote>$TFILE2
preference=$(confline $TFILE2 Preference:|cut -d" " -f2)
routes=$(confline $TFILE2 Routes:)
imported=$(echo $routes|cut -d" " -f2-3|grep -i "imported"|cut -d" " -f1)
bird6imported=$(( $bird6imported + $imported ))
exported=$(echo $routes|cut -d" " -f4-5|grep -i "exported"|cut -d" " -f1)
bird6exported=$(( $bird6exported + $exported ))
preferred=$(echo $routes|cut -d" " -f6-7|grep -i "preferred"|cut -d" " -f1)
ImportUp=$(confline $TFILE2 "Import")
ImpUpAcp=$(echo $routes|cut -d" " -f6)
ImportUp=$(confline $TFILE2 "Import withdraws:")
ImpUpWit=$(echo $routes|cut -d" " -f6)
ExportUp=$(confline $TFILE2 "Export updates:")
ExpUpAcp=$(echo $routes|cut -d" " -f6)
ExportUp=$(confline $TFILE2 "Export withdraws:")
ExpUpWit=$(echo $routes|cut -d" " -f6)
rm $TFILE2
echo "$state bird6l-$remote Bird6-$remote=$linkok.0 linkstate:$linkstate since:$since preference:$preference preferred:$preferred imported:$imported exported:$exported ImpUpAcp:$ImpUpAcp ImpUpWit:$ImpUpWit ExpUpAcp:$ExpUpAcp ExUpWit:$ExpUpWit"
fi
done<$TFILE
rm $TFILE
echo "P Bird6links bird6-Up=$bird6up.0;$wlow:$wlimit;$clow:$climit|Bird6-Configured=$bird6confzahl.0|Bird6-Loaded=$bird6loaded.0;$(($bird6confzahl - 1)):$(($bird6confzahl + 1));$(($bird6confzahl - 1)):$(($bird6confzahl + 1))|Bird6Imported=$bird6imported.0|Bird6Exported=$bird6exported.0 Up:$bird6up Configured:$bird6confzahl Loaded:$bird6loaded Imported:$bird6imported Exported:$bird6exported"
## 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"