File Coverage

blib/lib/Xymon/Client.pm
Criterion Covered Total %
statement 22 45 48.8
branch 0 6 0.0
condition 1 6 16.6
subroutine 5 7 71.4
pod 1 3 33.3
total 29 67 43.2


line stmt bran cond sub pod time code
1             package Xymon::Client;
2 1     1   42804 use strict;
  1         2  
  1         40  
3              
4             BEGIN {
5 1     1   5 use Exporter ();
  1         1  
  1         19  
6 1     1   5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  1         76  
  1         122  
7 1     1   2 $VERSION = '0.08';
8 1         15 @ISA = qw(Exporter);
9 1         2 @EXPORT = qw();
10 1         1 @EXPORT_OK = qw();
11 1         604 %EXPORT_TAGS = ();
12             }
13              
14              
15              
16              
17             sub new
18             {
19 1     1 1 13 my ($class,$parm) = @_;
20              
21            
22 1   33     10 my $self = bless ({}, ref ($class) || $class);
23 1         11 $self->{home} = $parm->{home};
24 1         3 $self->{DEBUG} = $parm->{DEBUG};
25              
26 1         2 my $fh;
27 1         54 open($fh, "<",$self->{home}."/etc/hobbitclient.cfg");
28 1         6 while(<$fh>) {
29 0         0 chomp;
30 0 0 0     0 if(!m/^#/ && m/\w+/) {
31 0         0 s/\"//g;
32 0         0 s/\#.*$//g;
33 0         0 my @fields = (split(/=|\s+/));
34 0         0 my $field = shift @fields;
35            
36 0 0       0 if( @fields > 1 ) {
37 0         0 $self->{$field} = \@fields;
38             } else {
39 0         0 $self->{$field} = $fields[0];
40             }
41            
42            
43             }
44             }
45            
46 1         6 return $self;
47            
48              
49             }
50              
51             sub get_status
52             {
53 0     0 0   my $self = shift;
54 0           my $service = shift;
55 0           my $cmd;
56            
57 0           my $host = $self->{BBDISPLAYS}[0];
58            
59 0           open($cmd,"$self->{home}/bin/bb $host 'hobbitdboard host=$host fields=hostname,testname,color'");
60            
61 0           while(<$cmd>) {
62 0           print $_ . "\n";
63             }
64              
65            
66             }
67              
68              
69             sub send_status
70             {
71 0     0 0   my $self = shift;
72 0           my $args = shift;
73            
74              
75 0           foreach my $host (@{$self->{BBDISPLAYS}}) {
  0            
76 0           system("$self->{home}/bin/bb $host 'status $args->{server}.$args->{testname} $args->{color} $args->{msg}'") ;
77 0 0         if( $self->{DEBUG} == 1 ) {
78 0           print "$self->{home}/bin/bb $host 'status $args->{server}.$args->{testname} $args->{color} $args->{msg}'";
79             }
80             }
81            
82             }
83              
84             =head1 NAME
85              
86             Xymon::Client - Interface to xymon/hobbit client.
87              
88             =head1 SYNOPSIS
89              
90             use Xymon::Client;
91             my $xymon = Xymon::Client->new("/home/hobbit/client/");
92            
93             $xymon->send_status({
94             server => 'servername',
95             testname => 'test',
96             color => 'red',
97             msg => 'test failed',
98            
99             })
100              
101              
102             =head1 DESCRIPTION
103              
104             Provides an object interface to the xymon/hobbit client.
105              
106             =head1 METHODS
107              
108             =head2 Xymon::Client->new($home)
109              
110             Create a new Xymon Client object, passing it the xymon/hobbit home dir.
111             This is usually /home/hobbit/client.
112              
113              
114             =head2 send({...})
115              
116             Sends a status message to the hobbit server. The following parameters should be passed:
117              
118             server: the server name that was tested
119             testname: the name of the test (ie the column on the xymon page)
120             color: the status color
121             msg: the message to send which may be multiline and include any name-colon-value parameters.
122              
123             ie
124              
125             $xymon->send({
126             server => 'servername',
127             testname => 'test',
128             color => 'red',
129             msg => 'test failed',
130            
131             })
132              
133              
134            
135            
136             =cut
137              
138              
139              
140              
141             =head1 AUTHOR
142              
143             David Peters
144             CPAN ID: DAVIDP
145             davidp@electronf.com
146             http://www.electronf.com
147              
148             =head1 COPYRIGHT
149              
150             This program is free software; you can redistribute
151             it and/or modify it under the same terms as Perl itself.
152              
153             The full text of the license can be found in the
154             LICENSE file included with this module.
155              
156              
157             =head1 SEE ALSO
158              
159             perl(1), bb(1)
160              
161             =cut
162              
163              
164              
165              
166             1;
167              
168