From dd8b135bebd527b2a92248a3e8befba228d3dad2 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 8 Feb 2016 10:05:07 +0100 Subject: Make nagios-check-raid-3ware work with newer perls (stricter -T), and use a more modern open variant of open --- nagios-checks/nagios-check-raid-3ware | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'nagios-checks/nagios-check-raid-3ware') diff --git a/nagios-checks/nagios-check-raid-3ware b/nagios-checks/nagios-check-raid-3ware index 8d767b8..1dea2e8 100755 --- a/nagios-checks/nagios-check-raid-3ware +++ b/nagios-checks/nagios-check-raid-3ware @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw -# Copyright (C) 2006,2008,2009 Peter Palfrader +# Copyright (C) 2006,2008,2009,2016 Peter Palfrader # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -35,7 +35,7 @@ $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; my $TW_CLI = '/usr/local/bin/tw_cli'; -my $SVN_REVISION_STRING = '$Rev$'; +my $SVN_REVISION_STRING = '$Rev: 410 $'; my ($SVN_REVISION) = ($SVN_REVISION_STRING =~ /([0-9]+)/); $SVN_REVISION = 'unknown' unless defined $SVN_REVISION; my $VERSION = '0.0.0.'.$SVN_REVISION; @@ -85,10 +85,20 @@ unless (-e $TW_CLI) { exit $UNKNOWN; }; -my $sudo = $params->{'no-sudo'} ? '' : 'sudo '; -my $command = "$sudo $TW_CLI info c$params->{'controller'} u$params->{'unit'} status"; +for my $thing (qw{controller unit}) { + if ($params->{$thing} =~ m/^([0-9]+)$/) { + $params->{$thing} = $1; + } else { + die("Invalid $thing $1.\n"); + } +}; + +my @command; +push @command, "sudo" if $params->{'no-sudo'}; +push @command, ($TW_CLI, 'info', "c$params->{'controller'}", "u$params->{'unit'}", "status"); +my $command = join(' ', @command); print STDERR "Running $command\n" if $params->{'verbose'}; -open (TW, "$command|") or die ("Cannot run $command: $!\n"); +open (TW, "-|", @command) or die ("Cannot run $command: $!\n"); my @tw=; close TW; if ($CHILD_ERROR) { # program failed -- cgit v1.2.3