From 077d1360ff13f899ba4f3d2ce6a17642a3125d1a Mon Sep 17 00:00:00 2001
From: Jason Dixon <jdixon@omniti.com>
Date: Fri, 23 Apr 2010 21:05:47 +0000
Subject: [PATCH] new module to monitor faults on Solaris with fmadm

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@316 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
---
 lib/Core/Fmadm.pm | 85 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100755 lib/Core/Fmadm.pm

diff --git a/lib/Core/Fmadm.pm b/lib/Core/Fmadm.pm
new file mode 100755
index 0000000..74079b8
--- /dev/null
+++ b/lib/Core/Fmadm.pm
@@ -0,0 +1,85 @@
+package Core::Fmadm;
+
+use strict;
+use warnings;
+
+use base 'Resmon::Module';
+
+use Resmon::ExtComm qw(run_command cache_command);
+
+=pod
+
+=head1 NAME
+
+Core::Fmadm - Monitor hardware fault conditions in Solaris
+
+=head1 SYNOPSIS
+
+ Core::Fmadm {
+     failures : noop
+ }
+
+ Core::Fmadm {
+     failures : fmadm_path => /usr/sbin/fmadm
+ }
+
+=head1 DESCRIPTION
+
+This module monitors hardware fault conditions using the Solaris fmadm utility.
+
+=head1 CONFIGURATION
+
+=over
+
+=item check_name
+
+The check name is used for descriptive purposes only.  It is not used for
+anything functional.
+
+=item svcs_path
+
+Provide an alternate path to the fmadm command (optional).
+
+=back
+
+=head1 METRICS
+
+=over
+
+=item count
+
+A count of how many services are in a faulted or degraded state. This should
+normally be zero.
+
+=item resources
+
+Concatenated list of the resources (FMRI) and their respective state.  Each
+entry will be separated by commas.
+
+=back
+
+=cut
+
+sub handler {
+    my $self = shift;
+    my $config = $self->{'config'};
+    my $fmadm_path = $config->{'fmadm_path'} || 'fmadm';
+    my $osname = $^O;
+    my %results;
+
+    die "Unsupported platform: $osname\n"  unless ($osname eq 'solaris');
+
+    my $output = run_command("$fmadm_path faulty -r");
+    foreach (split(/\n/, $output)) {
+        /(\S+)\s+(\w+)/;
+        $results{$1} = $2;
+    }
+
+    return {
+        "count" => [scalar(keys %results), "i"],
+        "resources" => [join(", ", map { "$_ $results{$_}" } keys %results), "s"]
+    };
+};
+
+1;
+
-- 
GitLab