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