File Coverage

blib/lib/Xymon/Plugin/Server.pm
Criterion Covered Total %
statement 16 25 64.0
branch 6 16 37.5
condition 1 2 50.0
subroutine 6 6 100.0
pod 3 3 100.0
total 32 52 61.5


line stmt bran cond sub pod time code
1             package Xymon::Plugin::Server;
2              
3 6     6   77470 use strict;
  6         13  
  6         295  
4 6     6   34 use warnings FATAL => 'all';
  6         50  
  6         314  
5              
6 6     6   60 use Carp;
  6         14  
  6         3715  
7              
8             =head1 NAME
9              
10             Xymon::Plugin::Server - Xymon Server side plugin helper
11              
12             =head1 VERSION
13              
14             Version 0.02
15              
16             =cut
17              
18             our $VERSION = '0.02';
19              
20              
21             =head1 DESCRIPTION
22              
23             Xymon::Plugin::Server package contains some useful modules to write
24             Xymon plugin executed in server side.
25              
26             =over
27              
28             =item Xymon::Plugin::Server::Status
29              
30             Status reporter
31              
32             =item Xymon::Plugin::Server::Devmon
33              
34             Data generator in devmon style
35              
36             =item Xymon::Plugin::Server::Dispatch
37              
38             Dispatcher
39              
40             =back
41              
42             Check example directory to see how to each modules.
43              
44              
45             =head1 SUBROUTINES/METHODS
46              
47             =head2 home
48              
49             Get Xymon/Hobbit home directory.
50             This is a class method. call like this:
51              
52             my $home = Xymon::Plugin::Server->home;
53              
54             =cut
55              
56             sub home {
57 36 100   36 1 212 return $ENV{XYMONHOME} if (defined($ENV{XYMONHOME})); # xymn 4.3
58 18 50       125 return $ENV{BBHOME} if (defined($ENV{BBHOME})); # xymn 4.2
59              
60 0 0       0 if (defined($ENV{HOME})) {
61 0         0 my $xyhome = "$ENV{HOME}/server";
62              
63 0 0       0 return $xyhome if (-f "$xyhome/etc/hosts.cfg"); # xymon 4.3
64 0 0       0 return $xyhome if (-f "$xyhome/etc/bb-hosts"); # xymon 4.2
65             }
66              
67 0         0 croak "environment variable BBHOME/XYMONHOME is not set.";
68             }
69              
70             =head2 version
71              
72             Guess Xymon version and returns resulst as ARRAYREF like [major, minor].
73              
74             This is a class method. call like this:
75              
76             my $ver = Xymon::Plugin::Server->version;
77              
78             =cut
79              
80             sub version {
81 16     16 1 1095 my $xyhome = __PACKAGE__->home;
82              
83 16 100       6772 return [4, 3] if (-f "$xyhome/etc/hosts.cfg"); # xymon 4.3
84              
85 8         43 return [4, 2];
86             }
87              
88             =head2 display_hosts
89              
90             Guess display hosts and returns ARRAY.
91              
92             This is a class method. call like this:
93              
94             my @hosts = Xymon::Plugin::Server->display_hosts;
95              
96             =cut
97              
98             sub display_hosts {
99 20   50 20 1 1421 my $display = $ENV{'BBDISP'} || '127.0.0.1';
100              
101 20 50       271 return $display if ($display ne '0.0.0.0');
102              
103 0           my $multi_display = $ENV{'BBDISPLAYS'};
104 0 0         if (defined($multi_display)) {
105 0           return split(/\s+/, $multi_display);
106             }
107              
108 0           return $display;
109             }
110              
111             =head1 AUTHOR
112              
113             Toshimitsu FUJIWARA, C<< >>
114              
115             =head1 BUGS
116              
117             Please report any bugs or feature requests to C, or through
118             the web interface at L. I will be notified, and then you'll
119             automatically be notified of progress on your bug as I make changes.
120              
121              
122              
123              
124             =head1 SUPPORT
125              
126             You can find documentation for this module with the perldoc command.
127              
128             perldoc Xymon::Plugin::Server
129              
130              
131             You can also look for information at:
132              
133             =over 4
134              
135             =item * About Xymon
136              
137             L
138              
139             =item * About RRDTool
140              
141             L
142              
143             =item * RT: CPAN's request tracker (report bugs here)
144              
145             L
146              
147             =item * AnnoCPAN: Annotated CPAN documentation
148              
149             L
150              
151             =item * CPAN Ratings
152              
153             L
154              
155             =item * Search CPAN
156              
157             L
158              
159             =back
160              
161              
162             =head1 ACKNOWLEDGEMENTS
163              
164              
165             =head1 LICENSE AND COPYRIGHT
166              
167             Copyright 2013 Toshimitsu FUJIWARA.
168              
169             This program is free software; you can redistribute it and/or modify it
170             under the terms of the the Artistic License (2.0). You may obtain a
171             copy of the full license at:
172              
173             L
174              
175             Any use, modification, and distribution of the Standard or Modified
176             Versions is governed by this Artistic License. By using, modifying or
177             distributing the Package, you accept this license. Do not use, modify,
178             or distribute the Package, if you do not accept this license.
179              
180             If your Modified Version has been derived from a Modified Version made
181             by someone other than you, you are nevertheless required to ensure that
182             your Modified Version complies with the requirements of this license.
183              
184             This license does not grant you the right to use any trademark, service
185             mark, tradename, or logo of the Copyright Holder.
186              
187             This license includes the non-exclusive, worldwide, free-of-charge
188             patent license to make, have made, use, offer to sell, sell, import and
189             otherwise transfer the Package with respect to any patent claims
190             licensable by the Copyright Holder that are necessarily infringed by the
191             Package. If you institute patent litigation (including a cross-claim or
192             counterclaim) against any party alleging that the Package constitutes
193             direct or contributory patent infringement, then this Artistic License
194             to you shall terminate on the date that such litigation is filed.
195              
196             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
197             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
198             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
199             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
200             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
201             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
202             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
203             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
204              
205              
206             =cut
207              
208             1; # End of Xymon::Plugin::Server