root/lib/Resmon/Config.pm

Revision 37857c4c91096e325fa1d70b9d1ea78ab5c7f15d, 1.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

support PORT and INTERFACE in the config

git-svn-id: https://labs.omniti.com/resmon/trunk@34 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       } elsif (/^\s*\}\s*$/) {
29         $current = undef;
30       } else {
31         die "Syntax Error on line $line\n";
32       }
33     } else {
34       if(/\s*(\S+)\s*\{/) {
35         $current = $1;
36         $self->{Module}->{$current} = [];
37         next;
38       }
39       elsif(/\S*LIB\s+(\S+)\s*;\s*/) {
40         eval "use lib '$1';";
41         next;
42       }
43       elsif(/\S*PORT\s+(\d+)\s*;\s*/) {
44         $self->{port} = $1;
45         next;
46       }
47       elsif(/\S*INTERFACE\s+(\S+)\s*;\s*/) {
48         $self->{interface} = $1;
49         next;
50       }
51       elsif(/\s*INTERVAL\s+(\d+)\s*;\s*/) {
52         $self->{interval} = $1;
53         next;
54       }
55       elsif(/\s*STATUSFILE\s+(\S+)\s*;\s*/) {
56         $self->{statusfile} = $1;
57         next;
58       }
59       else {
60         die "Syntax Error on line $line\n";
61       }
62     }
63   }
64   if($current) {
65     die "unclosed stanza\n";
66   }
67   return $self;
68 }
69
70 1;
Note: See TracBrowser for help on using the browser.