原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://dgd2010.blog.51cto.com/1539422/1678879
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
|
#!/bin/bash
# Name: getdata.sh
javalogfile=
/data/tomcat/tomcat-cstest/logs/catalina
.out
pathtojavalogfile=$(
dirname
$javalogfile)
zabbixstatusfile=pathtojavalogfile/.zabbixstatus.catalina.out
errorkeyword=13003
previoustime=$(
grep
"$errorkeyword"
$javalogfile |
wc
-l)
currenttime=$(
grep
"$errorkeyword"
$javalogfile |
wc
-l)
if
[[ ! $previoustime -
eq
$currenttime ]];
then
echo
0
exit
1
fi
while
[[ $previoustime -
eq
$currenttime ]];
do
# 其实此处就像crontab,while+sleep=crontab
sleep
2
currenttime=$(
grep
"$errorkeyword"
$javalogfile |
wc
-l)
if
[[ $currenttime -gt $previoustime ]];
then
previoustime=$currenttime
echo
0 >>$zabbixstatusfile
elif
[[ $currenttime -
le
$previoustime ]];
then
echo
1 >>$zabbixstatusfile
fi
done
#!/bin/bash
# Name: checkdata.sh
javalogfile=
/data/tomcat/tomcat-cstest/logs/catalina
.out
pathtojavalogfile=$(
dirname
$javalogfile)
zabbixstatusfile=pathtojavalogfile/.zabbixstatus.catalina.out
grep
"0"
$zabbixstatusfile
if
[[ $? -
eq
0 ]];
then
echo
0
true
> $zabbixstatusfile
exit
1
else
echo
1
exit
0
fi
|
1
2
3
4
5
6
7
8
9
10
11
12
|
# single line for Zabbix
# ItemName: cs connection error
# TemplateNmae: Template App JavaLogMonitor
# ApplicationName: JavaErrorCodeTextFound
# TriggerName: cs connection error is occur
# # /etc/zabbix/zabbix_agentd.conf.d/userparameter_csconnerr.conf
# /etc/zabbix/zabbix_agentd.conf.d/userparameter_cs.conf
# {Template App JavaLogMonitor:csprocess.cs.csconnerr[*].diff(0)}>0
# For /bin/bash, such as CentOS
# UserParameter=csprocess.cs.csconnerr[*],javalogfile=/data/tomcat/tomcat-cstest/logs/catalina.out;errorkeyword=13003;if [[ -f $javalogfile ]]; then echo $(grep "$errorkeyword" $javalogfile | wc -l); exit 0; else echo 0; exit 1; fi
# For /bin/sh, such as Ubuntu
UserParameter=csprocess.cs.csconnerr[*],javalogfile=
/data/tomcat/tomcat-cstest/logs/catalina
.out;errorkeyword=13003;
if
test
-f $javalogfile ;
then
echo
$(
grep
"$errorkeyword"
$javalogfile |
wc
-l);
exit
0;
else
echo
0;
exit
1;
fi
|