[Resmon-devel] [resmon commit] r339 - branches/resmon2/lib/Resmon

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Thu Apr 29 18:04:18 EDT 2010


Author: mark
Date: 2010-04-29 18:04:18 -0400 (Thu, 29 Apr 2010)
New Revision: 339

Modified:
   branches/resmon2/lib/Resmon/Config.pm
Log:
Includes support in resmon

Syntax (used outside of module configuration stanzas):

INCLUDE filename.conf

Supports the following substitutions:

%h - hostname (uses Sys::Hostname)
%o - operating system name (uses $^O)

Modified: branches/resmon2/lib/Resmon/Config.pm
===================================================================
--- branches/resmon2/lib/Resmon/Config.pm	2010-04-29 19:39:54 UTC (rev 338)
+++ branches/resmon2/lib/Resmon/Config.pm	2010-04-29 22:04:18 UTC (rev 339)
@@ -3,20 +3,25 @@
 use strict;
 use warnings;
 
+use Sys::Hostname;
+
 sub new {
     my $class = shift;
     my $filename = shift;
-    my $self = bless {
+    my $self = shift; # Allows calling this recursively - you can pass in self
+    $self ||= bless {
         configfile => $filename,
         modstatus => [],
         # Defaults
         timeout => 10
     }, $class;
-    open(CONF, "<$filename") || return undef;
+    my $conf;
+    open($conf, "<$filename") ||
+        die "Unable to open configuration file $filename";
 
     my $current;
     my $line = 0;
-    while(<CONF>) {
+    while(<$conf>) {
         $line++;
         next if /^\s*#/;
         next if /^\s*$/;
@@ -103,10 +108,15 @@
             elsif(/\S*AUTHPASS\s+(\S+)\s*;\s*/) {
                 $self->{authpass} = $1;
                 next;
+            } elsif(/\s*INCLUDE\s+(\S+)\s*;\s*/) {
+                my $incfilename = $1;
+                my $HOSTNAME = hostname; # Uses Sys::Hostname
+                $incfilename =~ s/%h/$HOSTNAME/g;
+                $incfilename =~ s/%o/$^O/g;
+                new($class, $incfilename, $self);
+            } else {
+                die "Syntax Error in config file $filename on line $line\n";
             }
-            else {
-                die "Syntax Error on line $line\n";
-            }
         }
     }
     if($current) {



More information about the Resmon-devel mailing list