[Resmon-devel] [resmon commit] r275 - branches/resmon2/lib/Resmon/Module

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Sat Mar 20 12:08:49 EDT 2010


Author: mark
Date: 2010-03-20 12:08:49 -0400 (Sat, 20 Mar 2010)
New Revision: 275

Added:
   branches/resmon2/lib/Resmon/Module/Sample.pm
Log:
A sample module to use as a guide for other modules.

Demonstrates:

 - documentation
 - module structure
 - a new method for initialization code (no actual code is there though - this
   may or may not need to be fixed)
 - fetching configuration and check name
 - running an external command (no cache_command at the moment, discussion is
   needed on whether we should use it or not given the interval mechanism)
 - returning metrics of various types

So far anything here is just an idea for how we could/should do things and is
subject to change after some discussion (read: people telling me how stupid
some of the ideas are)


Added: branches/resmon2/lib/Resmon/Module/Sample.pm
===================================================================
--- branches/resmon2/lib/Resmon/Module/Sample.pm	                        (rev 0)
+++ branches/resmon2/lib/Resmon/Module/Sample.pm	2010-03-20 16:08:49 UTC (rev 275)
@@ -0,0 +1,107 @@
+package Resmon::Module::Sample;
+
+use strict;
+use warnings;
+
+use Resmon::Module;
+use vars ('@ISA');
+ at ISA = ("Resmon::Module");
+
+=pod
+
+=head1 NAME
+
+Resmon::Module::Sample - a sample/template resmon module
+
+=head1 SYNOPSIS
+
+ Resmon::Module::Sample {
+     some_check_name: arg1 => foo, arg2 => bar
+ }
+
+=head1 DESCRIPTION
+
+This module is a sample resmon module that demonstrates how to write and use a
+resmon module, as well as exposing some features modules can use.
+Documentation for a module should be done using pod (see B<perldoc perlpod>).
+
+To read the documenation, use B<perldoc Sample.pm>.
+
+To verify the documentatioe, use B<podchecker Sample.pm>.
+
+=head1 CONFIGURATION
+
+=over
+
+=item check_name
+
+The check name is descriptive only in this check. It is not used for anything.
+Some checks use the check_name as part of the configuration, such as
+free space checks that specify the filesystem to use.
+
+=item arg1
+
+A sample argument that is printed out in a metric
+
+=item arg2
+
+A sample argument that is printed out in a metric
+
+=back
+
+=head1 METRICS
+
+=over
+
+=item check_name
+
+The name of the current check. You wouldn't normally return this, but it is
+here to show how to access the check name, and for testing purposes.
+
+=item arg1
+
+The contents of what you put in the arg1 configuration variable.
+
+=item arg2
+
+The contents of what you put in the arg2 configuration variable.
+
+=item date
+
+Todays date. It only shows the actual date of the month as an example of an
+integer (type "i") metric.
+
+=back
+
+=cut
+
+sub new {
+    # This is only needed if you have initialization code. Most of the time,
+    # you can skip the new method and just implement a handler method.
+    my ($class, $check_name, $config) = @_;
+    my $self = $class->SUPER::new($check_name, $config);
+
+    # Add initialization code here
+
+    bless($self, $class);
+    return $self;
+}
+
+sub handler {
+    my $self = shift;
+    my $config = $self->{config}; # All configuration is in here
+    my $check_name = $self->{check_name}; # The check name is in here
+
+    # This is an example of running an external command. There are much better
+    # ways to get the current date.
+    my $date = `date +%d`;
+
+    return {
+        "check_name" => [$self->{check_name}, "s"],
+        "arg1" => [$config->{arg1}, "s"],
+        "arg2" => [$config->{arg2}, "s"],
+        "date" => [$date, "i"]
+    };
+};
+
+1;



More information about the Resmon-devel mailing list