首页 > 代码库 > Nagios监控LINUX /var/log/message脚本

Nagios监控LINUX /var/log/message脚本

写的不好轻喷
#! /bin/sh
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
currdate=`date | awk ‘{print $2,"*",$3}‘`

if [ `/usr/bin/sudo tail -20 /var/log/messages | grep "$currdate" | grep -i -E ‘error|fail|offline|suspending‘ | grep -v -E ‘nfs|ftp|sshd|telnet|login|timeout|authentication|cdrom|channel_handler|segfault|rip|rsp‘ |grep -v ‘(No output on stdout) stderr:‘| wc -l` -gt 0 ];then
dmsgtmp=`/usr/bin/sudo tail -20 /var/log/messages | grep "$currdate" | grep -i -E ‘error|fail|offline|suspending‘ | grep -v -E ‘nfs|ftp|sshd|telnet|login|timeout|authentication|cdrom|channel_handler|segfault|rip|rsp‘`
echo "============`date +%Y-%m-%d-%H:%M:%S`==============" >> /home/nagios/sys_error.log
echo "Linux OS log result:" >> /home/nagios/sys_error.log
echo "CRITICAL-$dmsgtmp" >> /home/nagios/sys_error.log
exit $STATE_CRITICAL
fi
if [ `/usr/bin/sudo tail -20 /var/log/messages | grep "$currdate" | grep -i -E ‘error|fail|offline|suspending‘ | grep -v -E ‘nfs|ftp|sshd|telnet|login|timeout|authentication|cdrom|channel_handler|segfault|rip|rsp‘ |grep -v ‘(No output on stdout) stderr:‘| wc -l` -eq 0 ];then
echo "OK"
exit $STATE_OK
fi

Nagios监控LINUX /var/log/message脚本