TopOne_ 发表于 2012-01-31 13:53

nagios牛人进..

我想写个脚本监控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调用……
期待解答。。

baroquesoul 发表于 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 == "-q" && $ARGV == "-H" && $ARGV == "-P" && $ARGV == "-w" && $ARGV == "-c" && $ARGV == "-C" && $ARGV !="")
{
my $check = 1;
my $recall = $ARGV;
my $HOST = $ARGV;
my $PORT = $ARGV;
my $WARN = $ARGV;
my $CRIT = $ARGV;
my $COU = $ARGV;
my $query = &CRC ($recall);
my @call = split(//,$recall);
my @dlen = (@call);
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";

baroquesoul 发表于 2012-02-07 13:41

具体的规则,可以看nagios的官方手册中的 Nagios Plugin API 一节。说得很详细。。
页: [1]
查看完整版本: nagios牛人进..