root/lib/Resmon/Config.pm

Revision 9e52c9e99877ed8e1cc3a623e68947c4de8e7fa2, 1.9 kB (checked in by Mark Harrison <mark@omniti.com>, 6 years ago)

Removing a debugging line that shouldn't be there

git-svn-id: https://labs.omniti.com/resmon/trunk@91 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100755
Line 
1 package Resmon::Config;
2
3 use strict;
4
5 sub new {
6   my $class = shift;
7   my $filename = shift;
8   my $self = bless {
9     configfile => $filename,
10   }, $class;
11   open(CONF, "<$filename") || return undef;
12
13   my $current;
14   my $line = 0;
15   while(<CONF>) {
16     $line++;
17     next if /^\s*#/;
18     next if /^\s*$/;
19     if($current) {
20       if(/^\s*(\S+)\s*:\s*(.+)\s*$/) {
21         my %kvs;
22         $kvs{'type'} = $current;
23         $kvs{'object'} = $1;
24         my @params = split(/,/, $2);
25         grep { $kvs{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S+)\s*$/ } @params;
26         my $object = bless \%kvs, "Resmon::Module::$current";
27         push(@{$self->{Module}->{$current}}, $object);
28
29         # Test to make sure the module actually works
30         my $coderef;
31         eval { $coderef = Resmon::Module::fetch_monitor($current); };
32         if (!$coderef) {
33                 # Try to execute the config_as_hash method. If it fails, then
34                 # the module didn't load properly (e.g. syntax error).
35                 eval { $object->config_as_hash; };
36                 die "Problem loading module $current" if $@;
37         }
38
39       } elsif (/^\s*\}\s*$/) {
40         $current = undef;
41       } else {
42         die "Syntax Error on line $line\n";
43       }
44     } else {
45       if(/\s*(\S+)\s*\{/) {
46         $current = $1;
47         $self->{Module}->{$current} = [];
48         next;
49       }
50       elsif(/\S*LIB\s+(\S+)\s*;\s*/) {
51         eval "use lib '$1';";
52         next;
53       }
54       elsif(/\S*PORT\s+(\d+)\s*;\s*/) {
55         $self->{port} = $1;
56         next;
57       }
58       elsif(/\S*INTERFACE\s+(\S+)\s*;\s*/) {
59         $self->{interface} = $1;
60         next;
61       }
62       elsif(/\s*INTERVAL\s+(\d+)\s*;\s*/) {
63         $self->{interval} = $1;
64         next;
65       }
66       elsif(/\s*STATUSFILE\s+(\S+)\s*;\s*/) {
67         $self->{statusfile} = $1;
68         next;
69       }
70       else {
71         die "Syntax Error on line $line\n";
72       }
73     }
74   }
75   if($current) {
76     die "unclosed stanza\n";
77   }
78   return $self;
79 }
80
81 1;
Note: See TracBrowser for help on using the browser.