JSchmitz has asked for the wisdom of the Perl Monks concerning the following question:

this is running inside NetIq and monitoring our disksuite stuff using the metastat command - any ideas on making it cleaner?
use NetIQ::Nqext; use strict; our $Sev_fail = 10; my ($results); my $resmsg = ""; our $metastat = "/usr/sbin/metastat"; if (!(-e $metastat)){ goto KS_CLEANUP; } $results = NetIQ::Nqext::ExecCmd("metastat|grep State:|grep -v Okay"); if ($results eq "") { goto KS_CLEANUP; } $results = NetIQ::Nqext::ExecCmd("metastat"); if ($do_event eq "y") { NetIQ::Nqext::CreateEvent($severity, "Disksuite Disk(s) Need Attenti +on", $Akpid, $resmsg, 0, $results , "", 0, 0); } KS_CLEANUP:

Replies are listed 'Best First'.
Re: netiq metastat
by Juerd (Abbot) on May 12, 2004 at 19:55 UTC

    The goto is ugly and very probably not at all necessary. I'll assume a sub cleanup() for the moment. For some reason, you chose to only test if $metastat exists, and then you don't use it in ExecCmd. I'll assume you have a good reason for that.

    The exercise is to spot the differences yourself.

    use strict; # first. use NetIQ::Nqext; my $sev_fail = 10; my $metastat = "/usr/sbin/metastat"; my $resmsg = ""; -e $metastat or cleanup; # Assuming 0 also indicates failure: NetIQ::Nqext::ExecCmd("metastat|grep State:|grep -v Okay") or cleanup; my $results = NetIQ::Nqext::ExecCmd("metastat"); # Where does $do_event come from and why isn't it just a simple boolea +n? if ($do_event eq "y") { NetIQ::Nqext::CreateEvent( $severity, "Disksuite Disk(s) Need Attention", $Akpid, # capital A? $resmsg, 0, # description of the parameter (one word will suff +ice) $results, "", # description 0, # description 0 # description ); }
    If you do not have a sub cleanup(), you can still avoid using the ugly goto LABEL by putting this code in a bare block (which is a loop that runs one time).
    use strict; # first. use NetIQ::Nqext; my $sev_fail = 10; my $metastat = "/usr/sbin/metastat"; my $resmsg = ""; { -e $metastat or last; # Assuming 0 also indicates failure: NetIQ::Nqext::ExecCmd("metastat|grep State:|grep -v Okay") or last +; my $results = NetIQ::Nqext::ExecCmd("metastat"); if ($do_event eq "y") { NetIQ::Nqext::CreateEvent( ... ); } }

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }