| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Uninets::Check; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 24639 | use 5.10.1; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 40 |  | 
| 4 | 1 |  |  | 1 |  | 10 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 5 | 1 |  |  | 1 |  | 5 | use warnings FATAL => 'all'; | 
|  | 1 |  |  |  |  | 5 |  | 
|  | 1 |  |  |  |  | 51 |  | 
| 6 | 1 |  |  | 1 |  | 333 | use Module::Pluggable sub_name => '_plugins', require => 1, search_path => ['Uninets::Check::Modules']; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | use Moo; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 NAME | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | Uninets::Check - Mini data collection framework! | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =head1 VERSION | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | Version 0.04 | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =cut | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | our $VERSION = '0.04'; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | Uninets::Check is a mini framework to collect data. | 
| 24 |  |  |  |  |  |  | The main purpose was to provide a pluggable, easy to use systems data source with consistent interface that is independent from specific systems monitoring solutions but can still be used by them. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | On object construction all modules inside the Uninets::Check::Modules namespace are loaded and new() is called on them. | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | use Uninets::Check; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | # create object and load modules | 
| 31 |  |  |  |  |  |  | my $unicheck = Uninets::Check->new; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =cut | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =head2 modules | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | Hash reference containing all loaded modules with module names as keys and module instances as values. | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | # print out loaded modules | 
| 42 |  |  |  |  |  |  | say for keys $unicheck->modules; | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =cut | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | has modules => ( | 
| 47 |  |  |  |  |  |  | is => 'rw' | 
| 48 |  |  |  |  |  |  | ); | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head1 METHODS | 
| 52 |  |  |  |  |  |  | =cut | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub BUILD { | 
| 55 |  |  |  |  |  |  | my $self = shift; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | my $modules = {}; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | for my $check ($self->_plugins){ | 
| 60 |  |  |  |  |  |  | (my $name = $check) =~ s/Uninets::Check::Modules::(.*)/$1/; | 
| 61 |  |  |  |  |  |  | $modules->{$name} = $check->new; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | $self->modules($modules); | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub _loaded_modules { | 
| 68 |  |  |  |  |  |  | my $self = shift; | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | wantarray ? keys %{$self->modules} : [keys %{$self->modules}]; | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head2 run | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | Runs a check module's run() method with parameters. | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | $unicheck->run($module, @params); | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =cut | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub run { | 
| 82 |  |  |  |  |  |  | my ($self, $module, @params) = @_; | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | $self->modules->{$module}->run(@params) if defined $module && defined $self->modules->{$module}; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head2 info | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | Show information on loaded modules. Calls the help() method of the modules and formats the output. | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | # show info of all modules | 
| 92 |  |  |  |  |  |  | say $unicheck->info; | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | # show info of specific module | 
| 95 |  |  |  |  |  |  | say $unicheck->info($module); | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =cut | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | sub info { | 
| 100 |  |  |  |  |  |  | my ($self, $module) = @_; | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | # if called with out specific module get info of all modules | 
| 103 |  |  |  |  |  |  | my @modules = $self->_loaded_modules; | 
| 104 |  |  |  |  |  |  | if (defined $module && $module) { | 
| 105 |  |  |  |  |  |  | @modules = ($module); | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  | my $info = ''; | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | for my $module (@modules){ | 
| 110 |  |  |  |  |  |  | $info .= "$module (" . $self->modules->{$module}->help->{description} . "):\n"; | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | # TODO clean up ugly mess | 
| 113 |  |  |  |  |  |  | $info .= (' ' x 2) . "Available actions:\n"; | 
| 114 |  |  |  |  |  |  | my %actions = %{$self->modules->{$module}->help->{actions}}; | 
| 115 |  |  |  |  |  |  | while (my ($action, $data) = each %actions){ | 
| 116 |  |  |  |  |  |  | $info .= (' ' x 4) . "$action ($data->{description}):\n"; | 
| 117 |  |  |  |  |  |  | $info .= (' ' x 6) . "Formats:\n"; | 
| 118 |  |  |  |  |  |  | my %formats = %{$data->{formats}}; | 
| 119 |  |  |  |  |  |  | while (my ($k, $v) = each %formats){ | 
| 120 |  |  |  |  |  |  | $info .= (' ' x 8) . "$k: $v\n"; | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  | $info .= (' ' x 6) . "Parameters:\n"; | 
| 123 |  |  |  |  |  |  | my %params = %{$data->{params}}; | 
| 124 |  |  |  |  |  |  | while (my ($k, $v) = each %params){ | 
| 125 |  |  |  |  |  |  | $info .= (' ' x 8) . "$k: $v\n"; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | $info; | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head1 AUTHOR | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | Matthias Krull, C<< <> >> | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head1 BUGS | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | Please report any bugs or feature requests to C, or through | 
| 140 |  |  |  |  |  |  | the web interface at L.  I will be notified, and then you'll | 
| 141 |  |  |  |  |  |  | automatically be notified of progress on your bug as I make changes. | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | Alternatively report bugs or feature requests at L. | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =head1 SUPPORT | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | perldoc Uninets::Check | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | You can also look for information at: | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =over 4 | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =item * RT: CPAN's request tracker (report bugs here) | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | L | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | L | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | L | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =item * Search CPAN | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | L | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =item * Github | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | L | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =back | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Copyright 2013 Matthias Krull. | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 188 |  |  |  |  |  |  | under the terms of the the Artistic License (2.0). You may obtain a | 
| 189 |  |  |  |  |  |  | copy of the full license at: | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | L | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | Any use, modification, and distribution of the Standard or Modified | 
| 194 |  |  |  |  |  |  | Versions is governed by this Artistic License. By using, modifying or | 
| 195 |  |  |  |  |  |  | distributing the Package, you accept this license. Do not use, modify, | 
| 196 |  |  |  |  |  |  | or distribute the Package, if you do not accept this license. | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | If your Modified Version has been derived from a Modified Version made | 
| 199 |  |  |  |  |  |  | by someone other than you, you are nevertheless required to ensure that | 
| 200 |  |  |  |  |  |  | your Modified Version complies with the requirements of this license. | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | This license does not grant you the right to use any trademark, service | 
| 203 |  |  |  |  |  |  | mark, tradename, or logo of the Copyright Holder. | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | This license includes the non-exclusive, worldwide, free-of-charge | 
| 206 |  |  |  |  |  |  | patent license to make, have made, use, offer to sell, sell, import and | 
| 207 |  |  |  |  |  |  | otherwise transfer the Package with respect to any patent claims | 
| 208 |  |  |  |  |  |  | licensable by the Copyright Holder that are necessarily infringed by the | 
| 209 |  |  |  |  |  |  | Package. If you institute patent litigation (including a cross-claim or | 
| 210 |  |  |  |  |  |  | counterclaim) against any party alleging that the Package constitutes | 
| 211 |  |  |  |  |  |  | direct or contributory patent infringement, then this Artistic License | 
| 212 |  |  |  |  |  |  | to you shall terminate on the date that such litigation is filed. | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | 
| 215 |  |  |  |  |  |  | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | 
| 216 |  |  |  |  |  |  | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | 
| 217 |  |  |  |  |  |  | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | 
| 218 |  |  |  |  |  |  | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | 
| 219 |  |  |  |  |  |  | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | 
| 220 |  |  |  |  |  |  | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | 
| 221 |  |  |  |  |  |  | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  |  | 
| 224 |  |  |  |  |  |  | =cut | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | 1; # End of Uninets::Check |