[Resmon-devel] [resmon commit] r293 - branches/resmon2/resources

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Sun Mar 28 11:34:49 EDT 2010


Author: mark
Date: 2010-03-28 11:34:49 -0400 (Sun, 28 Mar 2010)
New Revision: 293

Added:
   branches/resmon2/resources/testmod
Log:
Testmod command for testing modules updated for resmon 2

Added: branches/resmon2/resources/testmod
===================================================================
--- branches/resmon2/resources/testmod	                        (rev 0)
+++ branches/resmon2/resources/testmod	2010-03-28 15:34:49 UTC (rev 293)
@@ -0,0 +1,85 @@
+#!/usr/bin/env perl
+# testmod - A simple script to test a resmon module
+# Usage:
+#
+# testmod Module::Name check_name key val key val
+#
+# module_name and check_name are required, the key val pairs are passed to the
+# module as its configuration.
+#
+# This script should be run from the module dir. For example, if you wanted to
+# run Core::Sample, then cd to resmon/lib (i.e. just outside the Core
+# directory), and run:
+#
+#   ../resources/testmod Core::Sample some_check_name arg1 foo arg2 bar
+
+use strict;
+use warnings;
+
+use lib '.';
+
+# Hack to mark modules we provide here as already loaded
+$INC{"Resmon/Module.pm"} = $0;
+$INC{"Resmon/ExtComm.pm"} = $0;
+
+package Resmon::Module;
+use strict;
+use warnings;
+
+sub new {
+    my ($class, $check_name, $config) = @_;
+    my $self = {};
+    $self->{config} = $config;
+    $self->{check_name} = $check_name;
+    bless ($self, $class);
+    return $self;
+}
+
+1;
+
+package Resmon::ExtComm;
+use strict;
+use warnings;
+
+use base "Exporter";
+our @EXPORT_OK = qw/cache_command run_command/;
+
+sub cache_command($$) {
+    my $command = shift;
+    return `$command`;
+}
+
+sub run_command($) {
+    my $command = shift;
+    return `$command`;
+}
+
+1;
+
+package main;
+
+my $module = shift;        # Module to test
+my $check_name = shift;
+my $kvs = {@ARGV};
+
+if (!$module || !$check_name) {
+    print "Usage: $0 module_name check_name [[key] [val]] [[key] [val]]\n";
+    exit 1;
+}
+
+eval "use $module;";
+if ($@) {
+    print "$@\n";
+    exit 1;
+}
+my $obj = $module->new($check_name, $kvs);
+my $metrics = $obj->handler();
+print "$module $check_name\n\n";
+for my $k (sort keys %$metrics) {
+    my $v = $metrics->{$k};
+    # Default type is auto
+    if (ref($v) ne "ARRAY") {
+        $v = [$v, "0"];
+    }
+    printf "%15s = %s (%s)\n", $k , $v->[0], $v->[1];
+}


Property changes on: branches/resmon2/resources/testmod
___________________________________________________________________
Added: svn:executable
   + *



More information about the Resmon-devel mailing list