Commits

Palmer, 2E0EOL committed df9057f Draft

Start working on megaraid plugin.
This is just stripped down copy of the Zpool plugin for now.

  • Participants
  • Parent commits b2eabb4
  • Branches f/201207-lsi-megaraid

Comments (0)

Files changed (2)

File bin/check_disks_megaraid

+#!/usr/bin/perl -w
+#
+# Daybo Logic 'Nagios' plugins collection
+# Copyright (c) 2012-2013, David Duncan Ross Palmer, Daybo Logic
+# All rights reserved. No claims are made for 'Nagios' which is a project
+# we are merely contributing plugins to.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#     * Redistributions of source code must retain the above copyright notice,
+#       this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in the
+#       documentation and/or other materials provided with the distribution.
+#
+#     * Neither the name of the Daybo Logic nor the names of its contributors
+#       may be used to endorse or promote products derived from this software
+#       without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+use strict;
+use warnings;
+use diagnostics;
+
+package main;
+use Data::Dumper;
+use Getopt::Std;
+
+my %opts;
+
+sub ReadStat($)
+{
+	my @ret = ( );
+	if ( $_[0] && open(my $h, '<', $_[0]) ) {
+		while ( my $line = <$h> ) {
+			chomp($line);
+			push(@ret, $line);
+		}
+		close($h);
+		return \@ret;
+	}
+	return undef;
+}
+
+sub ExecStat()
+{
+	my $output = `/root/sbin/megarc.bin -dispCfg -a0`; #TODO: Need multiple adaptor support
+	if ( $output ) {
+		my @lines = split(m'\n', $output);
+		return \@lines;
+	}
+	return $output;
+}
+
+sub main(@)
+{
+	my $Debug = 0;
+	my $mr_status;
+	my %Opts = @_;
+	my ( $status, $statusMsg );
+
+	$Debug = 1 if ( $Opts{'d'} );
+	$mr_status = ReadStat($Opts{'f'}) || ExecStat();
+	#$zpool_info = ParseZpoolStatus($zpool_status);
+	#print Dumper $zpool_info if ( $Debug );
+	#return $zpool_info->{exit} if ( $zpool_info->{exit} ); # Early exit requested
+
+	#( $status, $statusMsg ) = ProcessZpoolStatus($zpool_info);
+	printf("%s\n", $statusMsg) unless ( $Opts{'q'} );
+	return $status;
+}
+
+exit(3) if ( !getopts('df:', \%opts) );
+exit(main(%opts)) if ( !caller() );
+1;

File t/check_disks_megaraid.t

+#!/usr/bin/perl -w
+
+package main;
+use strict;
+use warnings;
+use diagnostics;
+
+require 'bin/check_disks_megaraid';
+
+use Test::More tests => 4;
+
+sub t_main()
+{
+	my %fn_ec_map = (
+		'degraded' => 2,
+		'rebuild'  => 1,
+		'optimal'  => 0
+	);
+
+	my $testdir = 'testdata/check_disks_megaraid';
+	if ( opendir(my $d, $testdir) ) {
+		while ( my $ent = readdir($d) ) {
+			next if ( $ent =~ m/^\./ );
+			if ( $ent =~ m/^(\d)\_(\w+)\.txt$/ ) {
+				my $filename = "$testdir/$ent";
+				my $expect_exit = $fn_ec_map{$2};
+				if ( !defined($expect_exit) ) {
+					warn "Not running unit test (unknown filename): $ent";
+					next;
+				}
+				is(main(q => 1, f => $filename), $expect_exit, "$filename exits $expect_exit");
+			} else {
+				warn "Not running unit test $ent";
+			}
+		}
+		closedir($d);
+	}
+	return 0;
+}
+
+exit(t_main());