forked from sergei-mironov/awesomerc-ierton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logmonitor
executable file
·139 lines (120 loc) · 3.65 KB
/
logmonitor
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
#!/bin/sh
#
# Copyright (C) 2010 Sergey Mironov
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Name of script (for later parsing)
this=$0
# Log to watch
log="/var/log/messages"
# Popup time
infoPopupTime=5000
warningPopupTime=8000
errorPopupTime=11000
securityPopupTime=11000
# Icons
infoIcon='/usr/share/icons/gnome/16x16/status/sunny.png'
warningIcon='/usr/share/icons/gnome/16x16/status/dialog-warning.png'
errorIcon='/usr/share/icons/gnome/16x16/status/dialog-error.png'
securityIcon='/usr/share/icons/gnome/16x16/status/security-medium.png'
# source-hightlight grammar or so
outlang=$HOME/.config/awesome/themes/awesome.outlang
filter_hide_pppd() { grep -w pppd | grep -qvE 'Welcome|Exit' ; }
filter_hide_autofs() { grep -w automount ; }
filter_hide_cron() { grep -w cron ; }
filter_hide_pptp() { grep -w pptp ; }
filter_hide_sudo() { grep -w sudo ; }
filter_hide_ntp() { grep -w ntpd ; }
filter_hide_stack() { grep "used greatest stack depth" ; }
hiders=`grep -o 'filter\_hide\_[a-z0-9]*' $this`
filter() {
while read line ; do
local failed=""
for h in $hiders ; do
echo $line | $h > /dev/null && { failed=y ; break ; }
done
test -z "$failed" && echo $line
done
}
marker_normal() { grep -q "warn" && echo error ; }
marker_err() { grep -q "err" && echo error ; }
marker_sec() { grep -qE "auth|access" && echo security ; }
marker_low() { echo low ; }
markers=`grep -o 'marker\_[a-z0-9]*' $this`
marker() {
while read line ; do
for m in $markers ; do
echo $line | $m && break
done
echo $line
done
}
colorizer() {
while { read urgency && read line ; } ; do
echo $urgency
# source-highlight has ugly default colors.
#echo $line | source-highlight --failsafe --src-lang=log --style-file=default.style --outlang-def=$outlang
# This is alternative
proc=`echo $line | sed 's/.\+ .\+ [0-9:]\+ [^:]\+ \([^:[]\+\)\(\[[0-9]\+\]\)\?: .*/\1/'`
echo -n "<span color='#FF00FF'>$proc</span>"
pid=`echo $line | sed 's/.\+ .\+ [0-9:]\+ [^:]\+ \([^:[]\+\)\(\[[0-9]\+\]\)\?: .*/\2/'`
echo -n "<span color='#00FFFF'>$pid</span>: "
msg=`echo $line | sed 's/.\+ .\+ [0-9:]\+ [^:]\+ [^:]\+: //' | sed 's/</[/g' | sed 's/>/]/g'`
echo "<span color='#BBBBBB'>$msg</span>"
done
}
sender() {
# Message header
local header=$1
while { read urgency && read line ; } ; do
case $urgency in
low|security)
urgency="low"
icon=$infoIcon
tpopup=$infoPopupTime
;;
normal)
urgency="normal"
icon=$warningIcon
tpopup=$warningPopupTime
;;
*)
urgency="critical"
icon=$errorIcon
tpopup=$errorPopupTime
;;
esac
notify-send -u "$urgency" -t "$tpopup" -i "$icon" "$header" "$line"
done
}
die() {
echo $@ >&2
{ echo "critical" ; echo "$@" ; } | sender "Error"
exit
}
check_prog() {
which "$1" >/dev/null 2>&1 || die "Please install $1"
}
check_pid() {
local pidfile="$HOME/.logmonitor.pid"
test -f "$pidfile" && pkill -P `cat $pidfile`
echo $$ > "$pidfile"
}
# Dependencies checking
check_pid
check_prog notify-send
check_prog pkill
test -f $log || die "Unable to read $log"
# Main part
tail -F -n0 $log | filter | marker | colorizer | sender $log