packages: nagios-plugin-check_raid/check_raid - omit sudo if ran as root or...
glen
glen at pld-linux.org
Wed Sep 9 17:14:22 CEST 2009
Author: glen Date: Wed Sep 9 15:14:22 2009 GMT
Module: packages Tag: HEAD
---- Log message:
- omit sudo if ran as root or sudo is not found
---- Files affected:
packages/nagios-plugin-check_raid:
check_raid (1.6 -> 1.7)
---- Diffs:
================================================================
Index: packages/nagios-plugin-check_raid/check_raid
diff -u packages/nagios-plugin-check_raid/check_raid:1.6 packages/nagios-plugin-check_raid/check_raid:1.7
--- packages/nagios-plugin-check_raid/check_raid:1.6 Wed Sep 9 17:07:20 2009
+++ packages/nagios-plugin-check_raid/check_raid Wed Sep 9 17:14:17 2009
@@ -31,7 +31,7 @@
my $mdstat = 1 if -f "/proc/mdstat"; # Linux LVM
my $mpt_status = find_prog("mpt-status"); # LSILogic MPT ServeRAID
my $megaraid = 1 if -d "/proc/megaraid"; # MegaRAID
-my $aaccli = find_prog("aaccli") # Adaptec ServeRAID
+my $aaccli = find_prog("aaccli"); # Adaptec ServeRAID
my $lsraid = find_prog("lsraid"); # Linux, software RAID
my $metastat = find_prog("metastat"); # Solaris, software RAID
my $lsvg = find_prog('lsvg'); # AIX LVM
@@ -65,7 +65,10 @@
sub check_metastat {
my($l,$s,$d,$sd);
- open METASTAT,"$metastat |" or return;
+ my $CMD = $metastat;
+ $CMD = "$sudo $CMD" if $> and $sudo;
+
+ open METASTAT,"$CMD |" or return;
while( $l = <METASTAT> ) {
chomp $l;
if($l =~ /^(\S+):/) { $d = $1; $sd = ''; next; }
@@ -135,7 +138,10 @@
my($l);
my($s,$n,$f);
- open LSRAID,"$lsraid -A -p 2>/dev/null |" or return;
+ my $CMD = "$lsraid -A -p";
+ $CMD = "$sudo $CMD" if $> and $sudo;
+
+ open LSRAID,"$CMD 2>/dev/null |" or return;
while( $l = <LSRAID> ) {
chomp $l;
if( $l =~ /\/dev\/(\S+) \S+ (\S+)/ ) {
@@ -155,7 +161,10 @@
my($l, at f);
my($s,$n,$f);
- open LSVG,"$lsvg 2>/dev/null |" or return;
+ my $CMD = $lsvg;
+ $CMD = "$sudo $CMD" if $> and $sudo;
+
+ open LSVG,"$CMD 2>/dev/null |" or return;
while( $l = <LSVG> ) { chomp $l; push @vg, $l; }
close LSVG;
foreach $vg ( @vg ) {
@@ -178,10 +187,9 @@
sub check_ips {
my($l, at f);
my($s,$n,$c);
- my($CMD);
my $CMD = "$ipssend getconfig 1 LD";
- $CMD = "$sudo $CMD" if $>;
+ $CMD = "$sudo $CMD" if $> and $sudo;
open IPS,"$CMD |" or return;
while( $l = <IPS> ) {
@@ -203,8 +211,11 @@
sub check_aaccli {
my($dsk,$stat);
+ my $CMD = $aaccli;
+ $CMD = "$sudo $CMD" if $> and $sudo;
+
chdir "/tmp";
- open AACCLI,"|$sudo $aaccli >/dev/null 2>&1";
+ open AACCLI,"|$CMD >/dev/null 2>&1";
print AACCLI "open aac0\n";
print AACCLI "logfile start $$.log\n";
print AACCLI "container list /full\n";
@@ -245,13 +256,18 @@
close STAT;
unlink "$$.log";
}
+
sub check_afacli {
$message .= "afacli:not_supported ";
}
+
sub check_mpt {
my($dsk,$stat);
- open CMD,"$sudo $mpt_status |" or return;
+ my $CMD = $mpt_status;
+ $CMD = "$sudo $CMD" if $> and $sudo;
+
+ open CMD,"$CMD |" or return;
while ( <CMD> ) {
next if(! /vol_id\s*(\d+).*state\s+(\S+),/ );
($dsk,$stat) = ($1,$2);
@@ -267,16 +283,17 @@
}
close CMD;
}
+
sub check_megaraid {
my($f,$l);
my($s,$n);
my($CMD);
foreach $f ( glob('/proc/megaraid/*/raiddrives*') ) {
- if (-r $f) {
- $CMD = "<$f";
- } else {
+ if ($sudo && !-r $f) {
$CMD = "$sudo /bin/cat $f |";
+ } else {
+ $CMD = "<$f";
}
open MEGARAID,$CMD or next;
while( $l = <MEGARAID> ) {
@@ -326,7 +343,7 @@
open SUDOERS, ">>$f";
print SUDOERS "ALL ALL=(root) NOPASSWD: $ipssend getconfig 1 LD\n" if $ipssend;
print SUDOERS "ALL ALL=(root) NOPASSWD: $aaccli container list /full\n" if $aaccli;
- print SUDOERS "ALL ALL=(root) NOPASSWD: $mpt_status\n" if $mpt_status and -d "/proc/mpt"
+ print SUDOERS "ALL ALL=(root) NOPASSWD: $mpt_status\n" if $mpt_status and -d "/proc/mpt";
print SUDOERS "ALL ALL=(root) NOPASSWD:/bin/cat /proc/megaide/0/status\n" if -d "/proc/megaide/0";
print SUDOERS "ALL ALL=(root) NOPASSWD:/bin/cat /proc/megaide/1/status\n" if -d "/proc/megaide/1";
foreach my $mr ( glob('/proc/mega*/*/raiddrives*') ) {
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/nagios-plugin-check_raid/check_raid?r1=1.6&r2=1.7&f=u
More information about the pld-cvs-commit
mailing list