免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2202 | 回复: 2
打印 上一主题 下一主题

nagios牛人进.. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-31 13:53 |只看该作者 |倒序浏览
我想写个脚本监控raid卡的
脚本如下
#!/bin/bash
d=`/usr/sbin/megasasctl | grep 'RAID' | grep  'optimal'`
dd=`/usr/sbin/megasasctl | grep 'RAID' | grep -v 'optimal'`
if [ "$ddd" != "optimal" ]
then
echo "$dd"
fi
a=`/usr/sbin/megasasctl | grep  'a0e' |grep -v 'online' | egrep  -v "hotspare|hot spares"`
if [ -n "$a" ]
then
echo "$a"
fi


我想把它变成一个nagios可调用的 正常返回OK不正常返回$a,$dd  那个什么w,c,o的怎么写进去让nagios调用……
期待解答。。

论坛徽章:
0
2 [报告]
发表于 2012-02-07 10:17 |只看该作者
本帖最后由 baroquesoul 于 2012-02-07 13:38 编辑

我之前写的监控脚本,,通过exit返回值来判断告警级别,分别是
3 Unknown
2 Critical
1 Warning
0 OK
具体数值可以通过print类似函数的输出,具体格式就是:
    你期望的输出 | 监控项=当前值;Warning阀值;Critical阀值
其中 Warning阀值和Critical阀值可以通过外部输入获得。
-------------------------------------------------------------------------
#!/usr/bin/perl

use Digest::CRC;
use IO::Socket::INET;
use strict;

#===主程序================================================

if ($ARGV[0] == "-q" && $ARGV[2] == "-H" && $ARGV[4] == "-P" && $ARGV[6] == "-w" && $ARGV[8] == "-c" && $ARGV[10] == "-C" && $ARGV[11] !="")
{
my $check = 1;
my $recall = $ARGV[1];
my $HOST = $ARGV[3];
my $PORT = $ARGV[5];
my $WARN = $ARGV[7];
my $CRIT = $ARGV[9];
my $COU = $ARGV[11];
my $query = &CRC ($recall);
my @call = split(//,$recall);
my @dlen = (@call[8..11]);
my $lenth = join("",@dlen);
my $ll = hex($lenth)*2+5;
my $respon = "";
while ($check == "1")
{
sleep 1;
$respon = &TEL($HOST,$PORT,$query,$ll);
$check = &CRCCH($respon);
}
my $result = &CHAG($respon,$COU);
#=========数值判断==========================
if ($result < 1)
{
        printf("UNKNOWN! - Current is %.1f A !|current=$result;$WARN;$CRIT\n",$result);
        exit 3;
}
elsif ($result < $WARN)
{
        printf("OK - Current is %.1f A .|current=$result;$WARN;$CRIT\n",$result);
        exit 0;
}elsif ($result < $CRIT)
{
        printf("WARNING! - Current is %.1f A .|current=$result;$WARN;$CRIT\n",$result);
        exit 1;
}elsif ($result < 50)
{
        printf("CRITICAL! - Current is %.1f A .|current=$result;$WARN;$CRIT\n",$result);
        exit 2;
}else
{
        printf("UNKNOWN! - Current is %.1f A !|current=$result;$WARN;$CRIT\n",$result);
        exit 3;
}
}else{
        &HELP;
}
exit;
#==子程序=====================================================

#==Telnet=取数据===============================================
sub TEL
{
}
#=CRC16=校验=================================================
sub CRC
{
}
#==CheckSum=返回值校=========================================
sub CRCCH
{
}
#=========HexToDec=十六进制转十进制=========================================
sub CHAG
{
}
#=========HELP=========================================
sub HELP
{
print "\nUsage: check_modubs  [-h] -q query -H host -P port -w warn -c crit -C count\n";
print "-h help\n";
print "-q query Query command such as:010400010001 Don't get the CRC.\n";
print "-H host Host is such as:10.0.0.1.\n";
print "-P port The port of Host such as:1001.\n";
print "-w Warning Value.\n";
print "-c Critical Valeu.\n";
print "-C count The count for the result caclu.\n";
print "If any problem, Please connact dongyanqiong\@cnpc.com.cn\n\n";

论坛徽章:
0
3 [报告]
发表于 2012-02-07 13:41 |只看该作者
具体的规则,可以看nagios的官方手册中的 Nagios Plugin API 一节。说得很详细。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP