Changeset 4dec1cad7b7b758eb26a27a13dad73fc8609af3f for lib
- Timestamp:
- 03/18/10 22:03:35 (8 years ago)
- git-parent:
- Files:
-
- lib/Resmon/Module.pm (modified) (1 diff)
- lib/Resmon/Module/RESMON.pm (modified) (3 diffs)
- lib/Resmon/Status.pm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lib/Resmon/Module.pm
rf51cc7c r4dec1ca 61 61 return undef; 62 62 } 63 64 sub set_status { 63 sub cache_metrics { 65 64 my $arg = shift; 66 $arg->{laststatus} = shift; 67 $arg->{lastmessage} = shift; 65 $arg->{lastmetrics} = shift; 68 66 $arg->{lastupdate} = time; 69 if($arg->{laststatus} =~ /^([A-Z]+)\((.*)\)$/s) {70 # This handles old-style modules that return just set status as71 # STATE(message)72 $arg->{laststatus} = $1;73 $arg->{lastmessage} = $2;74 }75 return ($arg->{laststatus}, $arg->{lastmessage});76 67 } 77 68 sub config_as_hash { lib/Resmon/Module/RESMON.pm
r95026f2 r4dec1ca 19 19 # Get the global config object 20 20 my $config = $main::config; 21 my $configstatus = $config->{'configstatus'} || "";22 my $modstatus = $config->{'modstatus'} || "";21 my $configstatus = $config->{'configstatus'}; 22 my $modstatus = $config->{'modstatus'}; 23 23 24 24 ## Current revision 25 25 # Find location of subversion binary 26 # TODO - use svn keywords for this rather than running svn info 26 27 my $svn = 'svn'; 27 28 for my $path (qw(/usr/local/bin /opt/omni/bin /opt/csw/bin)) { … … 34 35 my $revision = "svn revision unknown"; 35 36 for (split(/\n/, $output)) { 36 if (/^Revision:\s*(\d*)$/) { $revision = " r$1"; }37 if (/^Revision:\s*(\d*)$/) { $revision = "$1"; } 37 38 if (/^svn: (.*) is not a working copy$/) { 38 39 $revision = "not a working copy"; … … 44 45 my $hostname = eval { hostname } || "Unknown"; 45 46 46 my $status = "OK"; 47 my $statusmsg = "running"; 48 if ($configstatus) { 49 $statusmsg = "BAD config file, running on old configuration"; 50 $status = "BAD"; 51 } 52 if ($modstatus) { 53 $statusmsg .= " with failed modules: $modstatus"; 54 $status = "BAD"; 55 } 56 57 # Set 'config' variables so it shows up in the xml output 58 $arg->{'revision'} = $revision; 59 $arg->{'hostname'} = $hostname; 60 $arg->{'configstatus'} = $configstatus || "OK"; 61 $arg->{'modstatus'} = $modstatus || "OK"; 62 63 return $status, { 64 "message" => ["$hostname $statusmsg ($revision)", "s"] 47 return { 48 "revision" => [$revision, "i"], 49 "hostname" => [$hostname, "s"], 50 "configstatus" => [$configstatus ? "BAD" : "OK", "s"], 51 "modstatus" => [$modstatus ? "BAD" : "OK", "s"] 65 52 }; 66 } 53 }; 67 54 68 55 1; lib/Resmon/Status.pm
rf51cc7c r4dec1ca 119 119 return $rv; 120 120 } 121 sub dump_generic_state {122 # Dumps only checks with a specific state123 my $self = shift;124 my $dumper = shift;125 my $state = shift;126 my $rv = '';127 while(my ($module, $services) = each %{$self->{store}}) {128 while(my ($service, $info) = each %$services) {129 if ($info->{state} eq $state) {130 $rv .= $dumper->($module,$service,$info);131 }132 }133 }134 return $rv;135 }136 sub dump_oldstyle {137 my $self = shift;138 my $response = $self->dump_generic(sub {139 my($module,$service,$info) = @_;140 my $message = $info->{metric}->{message};141 if (ref $message eq "ARRAY") {142 $message = $message->[0];143 }144 return "$service($module) :: $info->{state}($message)\n";145 });146 return $response;147 }148 121 sub dump_xml { 149 122 my $self = shift; … … 172 145 <ul class="navbar"> 173 146 <li><a href="/">List all checks</a></li> 174 <li><a href="/BAD">List all checks that are BAD</a></li>175 <li><a href="/WARNING">List all checks that are WARNING</a></li>176 <li><a href="/OK">List all checks that are OK</a></li>177 147 </ul> 178 148 <p> … … 184 154 <xsl:sort select="\@service" /> 185 155 <div class="item"> 186 <xsl:attribute name="class">187 item <xsl:value-of select="state" />188 </xsl:attribute>189 156 <div class="info"> 190 157 Last check: <xsl:value-of select="last_runtime_seconds" /> … … 205 172 <xsl:value-of select="\@service" /> 206 173 </a> 207 -208 <xsl:value-of select="state"/>:209 <xsl:value-of select="metric[attribute::name='message']" />210 174 </h1> 211 <xsl:if test="count(metric[attribute::name!='message']) > 0"> 212 <ul> 213 <xsl:for-each select="metric[attribute::name!='message']"> 214 <xsl:sort select="\@name" /> 215 <li><xsl:value-of select="\@name" /> = 216 <xsl:value-of select="." /></li> 217 </xsl:for-each> 218 </ul> 219 </xsl:if> 175 <ul> 176 <xsl:for-each select="metric"> 177 <xsl:sort select="\@name" /> 178 <li><xsl:value-of select="\@name" /> = 179 <xsl:value-of select="." /></li> 180 </xsl:for-each> 181 </ul> 220 182 </div> 221 183 </xsl:for-each> … … 257 219 padding: 0; 258 220 margin: 0; 259 }260 261 .OK {262 background-color: #afa;263 border-left: 10px solid #393;264 }265 266 .WARNING {267 background-color: #ffa;268 border-left: 10px solid #993;269 }270 271 .BAD {272 background-color: #faa;273 border-left: 10px solid #933;274 221 } 275 222 … … 344 291 $client->print($response . "\r\n"); 345 292 return; 346 } elsif($req eq '/' or $req eq '/status') {293 } elsif($req eq '/') { 347 294 my $response .= $self->dump_xml(); 348 295 $client->print(http_header(200, length($response), 'text/xml', $snip)); 349 $client->print($response . "\r\n");350 return;351 } elsif($req eq '/status.txt') {352 my $response = $self->dump_oldstyle();353 $client->print(http_header(200, length($response), 'text/plain', $snip));354 296 $client->print($response . "\r\n"); 355 297 return; … … 378 320 } 379 321 } elsif($req =~ /^\/([^\/]+)$/) { 380 if ($1 eq "BAD" || $1 eq "OK" || $1 eq "WARNING") { 381 my $response = qq^<?xml version="1.0" encoding="UTF-8"?>\n^; 382 my $response .= qq^<?xml-stylesheet type="text/xsl" href="/resmon.xsl"?>^; 383 $response .= "<ResmonResults>\n". 384 $self->dump_generic_state(\&xml_info,$1) . 385 "</ResmonResults>\n"; 386 $client->print(http_header(200, length($response), 'text/xml', $snip)); 387 $client->print( $response . "\r\n"); 388 return; 389 } elsif(exists($self->{store}->{$1})) { 322 if(exists($self->{store}->{$1})) { 390 323 my $response = qq^<?xml version="1.0" encoding="UTF-8"?>\n^; 391 324 my $response .= qq^<?xml-stylesheet type="text/xsl" href="/resmon.xsl"?>^; … … 563 496 $message = $message->[0]; 564 497 } 498 # TODO - print metrics here insead of message 565 499 if($self->{handle}) { 566 $self->{handle}->print("$name($type) :: $ info->{state}($message)\n");500 $self->{handle}->print("$name($type) :: $message\n"); 567 501 } else { 568 print "$name($type) :: $ info->{state}($message)\n";502 print "$name($type) :: $message\n"; 569 503 } 570 504 }