Chinaunix首页 | 论坛 | 博客
  • 博客访问: 193630
  • 博文数量: 44
  • 博客积分: 2021
  • 博客等级: 大尉
  • 技术积分: 937
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-03 22:55
文章分类

全部博文(44)

文章存档

2009年(2)

2008年(42)

我的朋友

分类:

2008-07-29 01:41:35

#!/bin/sh
TMP_F='/tmp/all_hosts'
MID_FILE=/tmp/noti_tmp
STATUS_FILE=/usr/local/nagios/var/status.dat
find /usr/local/nagios/etc/ -type f -name "hosts.cfg" |xargs -i cat {} >$TMP_F
if grep $1 $TMP_F >/dev/null
        then
        host_name=`grep -B2 $1 $TMP_F | head -1 | awk '{print $2}'`
else
        echo -e "\n\033[0;31;40m$1 is not monitored in nagios,please check\033[0m"
        exit 1
fi
grep -A 50 "$host_name$" $STATUS_FILE |egrep "$host_name|notifications_enabled|service_description|plugin_output" >$MID_FILE
cat $MID_FILE | head -4 | grep -q "notifications_enabled=1"
if [ $? -eq 0 ]
        then
        echo -e "\n\033[0;32;40m$1($host_name)  enabled\033[0m\n"
else
        echo -e "\n\033[0;31;40m$1($host_name)  disabled\033[0m\n"
fi
for services in `cat $MID_FILE |grep -A1 $host_name$ |grep service_description | awk -F "service_description=" '{print $2}'`
do
output=`grep -A1 =$services$ $MID_FILE | grep "plugin_output=" |awk -F= '{print $2}'`
grep -A3 =$services$ $MID_FILE | grep -q "notifications_enabled=1"
if [ $? -eq 0 ]
        then
        echo -e "$services\t\t\tenabled\t\t\t$output"
else
        echo -e "\033[0;31;40m$services\t\t\tdisabled\t\t\t$output\033[0m"
fi
done

说明一下关于颜色的处理
在上面命令中,“\033[0;32;40m” 表示定义后面文本的颜色,“\033”表示启动一个转义序列,“[”定义开始颜色定义,“0”定义默认的字体颜色,其它部分稍后定义。“32”定义文本的 前景色,这里32表示绿色;“40”定义文本的背景色,40表示黑色。在字符串的最后定义了“ \033[0m”,它是用来恢复了默认的文本颜色设置,这样就只会得到一个彩色提示符,而不会影响命令和其输出的颜色显示(即黑底白字)。

     我们一共有8种字体颜色可供选择,它们分别是30 (黑色)、31 (红色)、32 (绿色)、33 (黄色)、34 (蓝色)、35 ( 紫红色)、36 (青色)和37 (白色)。对于底色也有8种颜色可供选择,只需要将字体颜色的3修改为4即可,例如40、41、42、43、44、45、46、47。

阅读(877) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~