root/lib/Resmon/Module/RESMON.pm

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

Fixed a bug in the resmon module and added checking for bad config/failed
module loading.

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

  • Property mode set to 100644
Line 
1 package Resmon::Module::RESMON;
2 use Resmon::ExtComm qw/cache_command/;
3 use vars qw/@ISA/;
4 @ISA = qw/Resmon::Module/;
5
6 use Sys::Hostname;
7
8 # A resmon 'health check' module
9 # Currently just prints the hostname and svn revision in the output, always
10 # returning OK. In future it will check for a broken config and broken
11 # modules, reporting that it is running with old modules/an old config.
12
13 my $resmon_dir = $0;
14 $resmon_dir =~ s/\/?[^\/]+$//;
15
16 sub handler {
17     my $arg = shift;
18     my $os = $arg->fresh_status();
19
20     # Get the global config object
21     my $config = $main::config;
22     my $configstatus = $config->{'configstatus'} || "";
23     my $modstatus = $config->{'modstatus'} || "";
24
25     ## Current revision
26     # Find location of subversion binary
27     my $svn = 'svn';
28     for my $path (qw(/usr/local/bin /opt/omni/bin)) {
29         if (-x "$path/svn") {
30             $svn = "$path/svn";
31             last;
32         }
33     }
34     my $output = cache_command("$svn info $resmon_dir 2>&1", 600);
35     my $revision = 0;
36     for (split(/\n/, $output)) {
37         if (/^Revision:\s*(\d*)$/) { $revision = "r$1"; }
38         if (/^svn: (.*) is not a working copy$/) {
39             $revision = "not a working copy";
40         }
41     }
42
43
44     # The hostname command croaks (dies) if it fails, hence the eval
45     my $hostname = eval { hostname } || "Unknown";
46
47     my $status = "OK";
48     my $statusmsg = "running";
49     if ($configstatus) {
50         $statusmsg = "BAD config file, running on old configuration";
51         $status = "BAD";
52     }
53     if ($modstatus) {
54         $statusmsg .= " with failed modules: $modstatus";
55         $status = "BAD";
56     }
57
58     # Set 'config' variables so it shows up in the xml output
59     $arg->{'revision'} = $revision;
60     $arg->{'hostname'} = $hostname;
61     $arg->{'configstatus'} = $configstatus || "OK";
62     $arg->{'modstatus'} = $modstatus || "OK";
63
64     return $arg->set_status($status, "$hostname $statusmsg ($revision)");
65 }
66
67 1;
Note: See TracBrowser for help on using the browser.