Changeset 7b227a82217114afb1353bc581d01f7af4bd1996

Show
Ignore:
Timestamp:
03/25/09 15:31:04 (5 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1237995064 +0000
git-parent:

[93f065db84146fc1f40658fbfce3abcceff75b6f]

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

Support for viewing checks by state and module

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

Files:

Legend:

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

    r93f065d r7b227a8  
    8888    while(my ($service, $info) = each %$services) { 
    8989      $rv .= $dumper->($module,$service,$info); 
     90    } 
     91  } 
     92  return $rv; 
     93} 
     94sub dump_generic_module { 
     95  # Dumps a single module rather than all checks 
     96  my $self = shift; 
     97  my $dumper = shift; 
     98  my $module = shift; 
     99  my $rv = ''; 
     100  my $services = $self->{store}->{$module}; 
     101  while(my ($service, $info) = each %$services) { 
     102    $rv .= $dumper->($module,$service,$info); 
     103  } 
     104  return $rv; 
     105} 
     106sub dump_generic_state { 
     107  # Dumps only checks with a specific state 
     108  my $self = shift; 
     109  my $dumper = shift; 
     110  my $state = shift; 
     111  my $rv = ''; 
     112  while(my ($module, $services) = each %{$self->{store}}) { 
     113    while(my ($service, $info) = each %$services) { 
     114      if ($info->{state} eq $state) { 
     115        $rv .= $dumper->($module,$service,$info); 
     116      } 
    90117    } 
    91118  } 
     
    263290    $client->print($response . "\r\n"); 
    264291    return; 
    265   } else { 
    266     if($req =~ /^\/([^\/]+)\/(.+)$/) { 
    267       if(exists($self->{store}->{$1}) && 
    268          exists($self->{store}->{$1}->{$2})) { 
    269         my $info = $self->{store}->{$1}->{$2}; 
    270         my $response = qq^<?xml version="1.0" encoding="UTF-8"?>\n^; 
    271         my $response .= qq^<?xml-stylesheet type="text/xsl" href="/resmon.xsl"?>^; 
    272         $response .= "<ResmonResults>\n". 
    273                      xml_info($1,$2,$info). 
    274                      "</ResmonResults>\n"; 
    275         $client->print(http_header(200, length($response), 'text/xml', $snip)); 
    276         $client->print( $response . "\r\n"); 
    277         return; 
    278       } 
     292  } elsif($req =~ /^\/([^\/]+)\/(.+)$/) { 
     293    if(exists($self->{store}->{$1}) && 
     294        exists($self->{store}->{$1}->{$2})) { 
     295    my $info = $self->{store}->{$1}->{$2}; 
     296    my $response = qq^<?xml version="1.0" encoding="UTF-8"?>\n^; 
     297    my $response .= qq^<?xml-stylesheet type="text/xsl" href="/resmon.xsl"?>^; 
     298    $response .= "<ResmonResults>\n". 
     299                    xml_info($1,$2,$info). 
     300                    "</ResmonResults>\n"; 
     301    $client->print(http_header(200, length($response), 'text/xml', $snip)); 
     302    $client->print( $response . "\r\n"); 
     303    return; 
     304    } 
     305  } elsif($req =~ /^\/([^\/]+)$/) { 
     306    if ($1 eq "BAD" || $1 eq "OK" || $1 eq "WARNING") { 
     307      my $response = qq^<?xml version="1.0" encoding="UTF-8"?>\n^; 
     308      my $response .= qq^<?xml-stylesheet type="text/xsl" href="/resmon.xsl"?>^; 
     309      $response .= "<ResmonResults>\n". 
     310                      $self->dump_generic_state(\&xml_info,$1) . 
     311                      "</ResmonResults>\n"; 
     312      $client->print(http_header(200, length($response), 'text/xml', $snip)); 
     313      $client->print( $response . "\r\n"); 
     314      return; 
     315    } elsif(exists($self->{store}->{$1})) { 
     316      my $response = qq^<?xml version="1.0" encoding="UTF-8"?>\n^; 
     317      my $response .= qq^<?xml-stylesheet type="text/xsl" href="/resmon.xsl"?>^; 
     318      $response .= "<ResmonResults>\n". 
     319                      $self->dump_generic_module(\&xml_info,$1) . 
     320                      "</ResmonResults>\n"; 
     321      $client->print(http_header(200, length($response), 'text/xml', $snip)); 
     322      $client->print( $response . "\r\n"); 
     323      return; 
    279324    } 
    280325  }