Show
Ignore:
Timestamp:
05/15/08 21:48:02 (6 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1210888082 +0000
git-parent:

[9e52c9e99877ed8e1cc3a623e68947c4de8e7fa2]

git-author:
Mark Harrison <mark@omniti.com> 1210888082 +0000
Message:

Split out the modules from Modules.pm to the Modules/ directory. Also made
sure each module returned a true value.

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/Resmon/Module.pm

    r11b1de2 r748aca8  
    7474  return $conf; 
    7575} 
    76 #### Begin actual monitor functions #### 
    77  
    78 package Resmon::Module::DATE; 
    79 use vars qw/@ISA/; 
    80 @ISA = qw/Resmon::Module/; 
    81  
    82 sub handler { 
    83   my $arg = shift; 
    84   my $os = $arg->fresh_status(); 
    85   return $arg->set_status("OK(".time().")"); 
    86 } 
    87  
    88 package Resmon::Module::DISK; 
    89 use Resmon::ExtComm qw/cache_command/; 
    90 use vars qw/@ISA/; 
    91 @ISA = qw/Resmon::Module/; 
    92  
    93 my $dfcmd = ($^O eq 'linux') ? 'df -kP' : 'df -k'; 
    94  
    95 sub handler { 
    96   my $arg = shift; 
    97   my $os = $arg->fresh_status(); 
    98   return $os if $os; 
    99   my $devorpart = $arg->{'object'}; 
    100   my $output = cache_command("$dfcmd", 120); 
    101   my ($line) = grep(/$devorpart\s*/, split(/\n/, $output)); 
    102   if($line =~ /(\d+)%/) { 
    103     if($1 > $arg->{'limit'}) { 
    104       return $arg->set_status("BAD($1% full)"); 
    105     } 
    106     if(exists $arg->{'warnat'} && $1 > $arg->{'warnat'}) { 
    107       return $arg->set_status("WARNING($1% full)"); 
    108     } 
    109     return $arg->set_status("OK($1% full)"); 
    110   } 
    111   return $arg->set_status("BAD(no data)"); 
    112 } 
    113  
    114 package Resmon::Module::LOGFILE; 
    115 use vars qw/@ISA/; 
    116 @ISA = qw/Resmon::Module/; 
    117  
    118 my %logfile_stats; 
    119 sub handler { 
    120   my $arg = shift; 
    121   my $os = $arg->fresh_status(); 
    122   return $os if $os; 
    123   my $file = $arg->{'object'}; 
    124   my $match = $arg->{'match'}; 
    125   my $max = $arg->{'max'} || 8; 
    126   my @statinfo = stat($file); 
    127   if(exists($arg->{file_dev})) {  
    128     if(($arg->{file_dev} == $statinfo[0]) && 
    129        ($arg->{file_ino} == $statinfo[1])) { 
    130       if($arg->{lastsize} == $statinfo[7]) { 
    131         if($arg->{errors}) { 
    132           return $arg->set_status("BAD($arg->{nerrs}: $arg->{errors})"); 
    133         } 
    134         return $arg->set_status("OK(0)"); 
    135       } 
    136     } else { 
    137       # File is a different file now 
    138       $arg->{lastsize} = 0; 
    139       $arg->{nerrs} = 0; 
    140       $arg->{errors} = ''; 
    141     } 
    142   } 
    143   if(!open(LOG, "<$file")) { 
    144     return $arg->set_status("BAD(ENOFILE)"); 
    145   } 
    146   seek(LOG, $arg->{lastsize}, 0); 
    147  
    148   while(<LOG>) { 
    149     chomp; 
    150     if(/$match/) { 
    151       if($arg->{nerrs} < $max) { 
    152         $arg->{errors} .= " " if(length($arg->{errors})); 
    153         $arg->{errors} .= $_; 
    154       } 
    155       $arg->{nerrs}++; 
    156     } 
    157   } 
    158  
    159   # Remember where we were 
    160   $arg->{file_dev} = $statinfo[0]; 
    161   $arg->{file_ino} = $statinfo[1]; 
    162   $arg->{lastsize} = $statinfo[7]; 
    163  
    164   if($arg->{nerrs}) { 
    165     return $arg->set_status("BAD($arg->{nerrs}: $arg->{errors})"); 
    166   } 
    167   return $arg->set_status("OK(0)"); 
    168 } 
    169  
    170 package Resmon::Module::FILESIZE; 
    171 use vars qw/@ISA/; 
    172 @ISA = qw/Resmon::Module/; 
    173  
    174 sub handler { 
    175   my $arg = shift; 
    176   my $os = $arg->fresh_status(); 
    177   return $os if $os; 
    178   my $file = $arg->{'object'}; 
    179   my @statinfo = stat($file); 
    180   my $size = $statinfo[7]; 
    181   my $minsize = $arg->{minimum}; 
    182   my $maxsize = $arg->{maximum}; 
    183   return $arg->set_status("BAD(too big, $size > $maxsize)") 
    184         if($maxsize && ($size > $maxsize)); 
    185   return $arg->set_status("BAD(too small, $size < $minsize)") 
    186         if($minsize && ($size > $minsize)); 
    187   return $arg->set_status("OK($size)"); 
    188 } 
    189  
    190 package Resmon::Module::REMOTEFILESIZE; 
    191 use vars qw/@ISA/; 
    192 use Resmon::ExtComm qw/cache_command/; 
    193 @ISA = qw/Resmon::Module/; 
    194  
    195 sub handler { 
    196   my $arg = shift; 
    197   my $os = $arg->fresh_status(); 
    198   return $os if $os; 
    199   my $host = $arg->{'host'}; 
    200   my $file = $arg->{'object'}; 
    201   my $output = cache_command("ssh -i /root/.ssh/id_dsa $host du -b $file", 600); 
    202   $output =~ /^(\d+)\s/;  
    203   my $size = $1; 
    204   my $minsize = $arg->{minimum}; 
    205   my $maxsize = $arg->{maximum}; 
    206   return $arg->set_status("BAD(too big, $size > $maxsize)") 
    207         if($maxsize && ($size > $maxsize)); 
    208   return $arg->set_status("BAD(too small, $size < $minsize)") 
    209         if($minsize && ($size > $minsize)); 
    210   return $arg->set_status("OK($size)"); 
    211 } 
    212  
    213 package Resmon::Module::FILEAGE; 
    214 use vars qw/@ISA/; 
    215 @ISA = qw/Resmon::Module/; 
    216  
    217 sub handler { 
    218   my $arg = shift; 
    219   my $os = $arg->fresh_status(); 
    220   return $os if $os; 
    221   my $file = $arg->{'object'}; 
    222   my @statinfo = stat($file); 
    223   my $age = time() - $statinfo[9]; 
    224   return $arg->set_status("BAD(too old $age seconds)") 
    225         if($arg->{maximum} && ($age > $arg->{maximum})); 
    226   return $arg->set_status("BAD(too new $age seconds)") 
    227         if($arg->{minimum} && ($age > $arg->{minimum})); 
    228   return $arg->set_status("OK($age)"); 
    229 } 
    230  
    231 package Resmon::Module::NETSTAT; 
    232 use Resmon::ExtComm qw/cache_command/; 
    233 use vars qw/@ISA/; 
    234 @ISA = qw/Resmon::Module/; 
    235  
    236 sub handler { 
    237   my $arg = shift; 
    238   my $os = $arg->fresh_status(); 
    239   return $os if $os; 
    240   my $output = cache_command("netstat -an", 30); 
    241   my @lines = split(/\n/, $output); 
    242   @lines = grep(/\s$arg->{state}\s*$/, @lines) if($arg->{state}); 
    243   @lines = grep(/^$arg->{localip}/, @lines) if($arg->{localip}); 
    244   @lines = grep(/^\s*[\w\d\*\.]+.*[\.\:]+$arg->{localport}/, @lines) if($arg->{localport}); 
    245   @lines = grep(/[\d\*\.]+\d+\s+$arg->{remoteip}/, @lines) 
    246         if($arg->{remoteip}); 
    247   @lines = grep(/[\d\*\.]+\s+[\d\*\.]+[\.\:]+$arg->{remoteport}\s+/, @lines) 
    248         if($arg->{remoteport}); 
    249   my $count = scalar(@lines); 
    250   return $arg->set_status("BAD($count)") 
    251         if($arg->{limit} && ($count > $arg->{limit})); 
    252   return $arg->set_status("BAD($count)") 
    253         if($arg->{atleast} && ($count < $arg->{atleast})); 
    254   return $arg->set_status("OK($count)"); 
    255 } 
    25676 
    25777$rmloading = "Demand loading";