Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am unfamiliar with perl, and I have a need to modify a Nagios check.

(我不熟悉perl,并且需要修改Nagios支票。)

I'd appreciate any advice on how to proceed.

(我将不胜感激任何有关如何进行的建议。)

The check I'm using is check_smart, found here:

(我正在使用的支票是check_smart,可在此处找到:)

https://www.claudiokuenzler.com/nagios-plugins/check_smart.php

(https://www.claudiokuenzler.com/nagios-plugins/check_smart.php)

This script lets you check SMART values from hard drives and present the results in a simple form for monitoring.

(该脚本使您可以检查硬盘驱动器中的SMART值,并以简单的形式显示结果以进行监视。)

As it stands, the script can take a regex in the form /dev/sd[ac] for one of the options;

(就目前而言,该脚本可以采用/ dev / sd [ac]形式的正则表达式作为其中一个选项。)

I believe that this is the section which allows this:

(我相信这是允许这样做的部分:)

        # list of devices for a loop
    my(@dev);

    if ( $opt_d ){
        # normal mode - push opt_d on the list of devices
        push(@dev,$opt_d);
    } else {
        # glob all devices - try '?' first 
        @dev =glob($opt_g);
    }

    foreach my $opt_dl (@dev){
        warn "Found $opt_dl
" if $opt_debug;
        if (-b $opt_dl || -c $opt_dl){
            $device .= $opt_dl.":";

        } else {
            warn "$opt_dl is not a valid block/character special device!

" if $opt_debug;
        }
    }

I don't quite understand why the variable is $opt_dl when earlier it seems to be $opt_d.

(我不太明白为什么变量在早期是$ opt_d时才是$ opt_dl。)

The result, however, is that the script returns something like: OK: [/dev/sda] - Device is clean --- [/dev/sdb] - Device is clean --- [/dev/sdc] - Device is clean

(但是,结果是脚本返回以下内容:确定:[/ dev / sda]-设备干净--- [/ dev / sdb]-设备干净--- [/ dev / sdc]-设备干净清洁)

EDIT: Here's the code where $opt_d is set;

(编辑:这是设置$ opt_d的代码;)

on further thought it seems like $opt_dl is just $opt_d while it's in a loop or something?

(进一步想想,好像$ opt_dl只是$ opt_d而在循环中还是什么?)

use vars qw($opt_b $opt_d $opt_g $opt_debug $opt_h $opt_i $opt_v);
Getopt::Long::Configure('bundling');
GetOptions(
                      "debug"       => $opt_debug,
    "b=i" => $opt_b, "bad=i"       => $opt_b,
    "d=s" => $opt_d, "device=s"    => $opt_d,
    "g=s" => $opt_g, "global=s"    => $opt_g,
    "h"   => $opt_h, "help"        => $opt_h,
    "i=s" => $opt_i, "interface=s" => $opt_i,
    "v"   => $opt_v, "version"     => $opt_v,
);

The part of the code I'd like to change in a similar fashion is:

(我想以类似方式更改的代码部分是:)

        # Allow all device types currently supported by smartctl
    # See http://www.smartmontools.org/wiki/Supported_RAID-Controllers
    if ($opt_i =~ m/(ata|scsi|3ware|areca|hpt|cciss|megaraid|sat)/) {
            $interface = $opt_i;
    } else {
            print "invalid interface $opt_i for $opt_d!

";
            print_help();
            exit $ERRORS{'UNKNOWN'};
    }

Specifically, I'd like to be able to pass the script something like "megaraid,[5-8]" and let it run for each.

(具体来说,我希望能够传递诸如“ megaraid [5-8]”之类的脚本并让其针对每个脚本运行。)

In this case, I would not be passing the regex for the device, it would just be /dev/sda.

(在这种情况下,我不会为设备传递正则表达式,而只是/ dev / sda。)

If anyone could give me advice on this I'd appreciate it!

(如果有人可以给我建议,我将不胜感激!)

  ask by user2792137 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
438 views
Welcome To Ask or Share your Answers For Others

1 Answer

$opt_dl is probably poorly named and has nothing to do with your $opt_d , those are two separate variables.

($opt_dl命名可能不$opt_d ,与$opt_d ,它们是两个单独的变量。)

From the if statement, if $opt_d is not set (that is the script was not given any device name to act upon), then glob is called with the value of $opt_g and it is glob in fact that finds out all filenames based on the regex given inside $opt_g .

(从if语句中,如果$opt_d没有设置(即剧本没有得到任何设备的名字时采取行动),则glob被调用的价值$opt_g ,它是glob的事实,找出所有文件名基于$opt_g内给出的正则表达式。)

After this if statement, the @dev array is filed with the names of devices to handle.

(在此if语句之后,将使用要处理的设备名称归档@dev数组。)

And then you have a foreach statement which means a loop on each item inside the @dev array.

(然后,您有一个foreach语句,这意味着在@dev数组内的每个项目上都有一个循环。)

And during the loop, each item is in the $opt_dl variable, due to its use on the foreach statement.

(并且在循环期间,由于每个项目都在foreach语句中使用,因此每个项目都在$opt_dl变量中。)

However I was not able to understand what you wanted to do in your last paragraph.

(但是,我无法理解您在上一段中想要做什么。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...