forked from eulenfunk/check_mk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_server
executable file
·53 lines (45 loc) · 1.78 KB
/
gen_server
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
#!/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);
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"
## apt-check moved to delayed check (600 seconds), needs 2 steps deployment
if [ ! -d "/usr/lib/check_mk_agent/local/600" ]; then
mkdir /usr/lib/check_mk_agent/local/600
fi
if [ ! -f "/usr/lib/check_mk_agent/local/600/gen_server-services" ]; then
cat <<EOT >> /usr/lib/check_mk_agent/local/600/gen_server-services
#!/bin/bash
#/usr/lib/check_mk_agent/local
EOT
chmod +x /usr/lib/check_mk_agent/local/600/gen_server-services
fi
## 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"