| 1 | package Uninets::Check::Modules::MongoDB; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.10.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use MongoDB; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | Uninets::Check::Modules::MongoDB - Uninets::Check module to check mongodb servers. | ||||||||||
| 15 | |||||||||||
| 16 | =head1 VERSION | ||||||||||
| 17 | |||||||||||
| 18 | Version 0.01 | ||||||||||
| 19 | |||||||||||
| 20 | =cut | ||||||||||
| 21 | |||||||||||
| 22 | 1 | our $VERSION = '0.02'; | |||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||
| 26 | |||||||||||
| 27 | Uninets::Check::Modules::MongoDB can check mongod reachability. | ||||||||||
| 28 | |||||||||||
| 29 | # to show available information on parameters run | ||||||||||
| 30 | unicheck --info MongoDB | ||||||||||
| 31 | |||||||||||
| 32 | =cut | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub run { | ||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 35 | 0 | my ($self, $action, @params) = @_; | |||||||||
| 36 | |||||||||||
| 37 | 0 | $self->$action(@params); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | =head1 ACTIONS | ||||||||||
| 41 | |||||||||||
| 42 | =head2 reachable | ||||||||||
| 43 | |||||||||||
| 44 | Check if the server is reachable. | ||||||||||
| 45 | |||||||||||
| 46 | # check default localhost:27017 | ||||||||||
| 47 | unicheck MongoDB reachable | ||||||||||
| 48 | |||||||||||
| 49 | # check specific host:port | ||||||||||
| 50 | unicheck MongoDB reachable --host example.com --port 1234 | ||||||||||
| 51 | |||||||||||
| 52 | =cut | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub reachable { | ||||||||
|
Subroutine
reachable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 55 | 0 | my ($self, @params) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 0 | my $host = 'localhost'; | |||||||||
| 58 | 0 | my $port = 27017; | |||||||||
| 59 | 0 | my $format = 'num'; | |||||||||
| 60 | |||||||||||
| 61 | 0 | GetOptionsFromArray([@params], | |||||||||
| 62 | 'port=i' => \$port, | ||||||||||
| 63 | 'host=s' => \$host, | ||||||||||
| 64 | 'format=s' => \$format, | ||||||||||
| 65 | ); | ||||||||||
| 66 | |||||||||||
| 67 | 0 | my $retval; | |||||||||
| 68 | 0 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 69 | 0 | MongoDB::MongoClient->new(host => $host, port => $port); | |||||||||
| 70 | 0 | $retval = $self->_return(1, 'Connection successful', $format); | |||||||||
| 71 | 0 | ▶ | } catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 72 | 0 | $retval = $self->_return(0, $_, $format); | |||||||||
| 73 | 0 | }; | |||||||||
| 74 | |||||||||||
| 75 | 0 | $retval; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub _return { | ||||||||
|
Subroutine
_return: not called CC=2 SCAR=17.9
| |||||||||||
| 79 | 0 | my ($self, $status, $value, $format) = @_; | |||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | return JSON->new->encode( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | { | ||||||||||
| 83 | message => $value, | ||||||||||
| 84 | status => $status, | ||||||||||
| 85 | } | ||||||||||
| 86 | ) if $format eq 'json'; | ||||||||||
| 87 | # default last in case some non supported format was given | ||||||||||
| 88 | 0 | return $status; # if $format eq 'num' | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub help { | ||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 92 | { | ||||||||||
| 93 | 0 | description => 'Check mongoDB status', | |||||||||
| 94 | actions => { | ||||||||||
| 95 | reachable => { | ||||||||||
| 96 | description => 'Check if mongodb server is reachable', | ||||||||||
| 97 | params => { | ||||||||||
| 98 | '--host' => 'Default: localhost', | ||||||||||
| 99 | '--port' => 'Default: 27017', | ||||||||||
| 100 | '--format' => 'Default: num' | ||||||||||
| 101 | }, | ||||||||||
| 102 | formats => { | ||||||||||
| 103 | 'num' => 'Returns the status code', | ||||||||||
| 104 | 'json' => 'Returns a JSON structure', | ||||||||||
| 105 | }, | ||||||||||
| 106 | }, | ||||||||||
| 107 | }, | ||||||||||
| 108 | } | ||||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | =head1 AUTHOR | ||||||||||
| 112 | |||||||||||
| 113 | Matthias Krull, C<< <<m.krull at uninets.eu>> >> | ||||||||||
| 114 | |||||||||||
| 115 | =head1 BUGS | ||||||||||
| 116 | |||||||||||
| 117 | Please report any bugs or feature requests to C<bug-uninets-check-modules-mongodb at rt.cpan.org>, or through | ||||||||||
| 118 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Uninets-Check-Modules-MongoDB>. 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 Uninets::Check::Modules::MongoDB | ||||||||||
| 129 | |||||||||||
| 130 | |||||||||||
| 131 | You can also look for information at: | ||||||||||
| 132 | |||||||||||
| 133 | =over 4 | ||||||||||
| 134 | |||||||||||
| 135 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||
| 136 | |||||||||||
| 137 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Uninets-Check-Modules-MongoDB> | ||||||||||
| 138 | |||||||||||
| 139 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 140 | |||||||||||
| 141 | L<http://annocpan.org/dist/Uninets-Check-Modules-MongoDB> | ||||||||||
| 142 | |||||||||||
| 143 | =item * CPAN Ratings | ||||||||||
| 144 | |||||||||||
| 145 | L<http://cpanratings.perl.org/d/Uninets-Check-Modules-MongoDB> | ||||||||||
| 146 | |||||||||||
| 147 | =item * Search CPAN | ||||||||||
| 148 | |||||||||||
| 149 | L<http://search.cpan.org/dist/Uninets-Check-Modules-MongoDB/> | ||||||||||
| 150 | |||||||||||
| 151 | =back | ||||||||||
| 152 | |||||||||||
| 153 | |||||||||||
| 154 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 155 | |||||||||||
| 156 | |||||||||||
| 157 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 158 | |||||||||||
| 159 | Copyright 2013 Matthias Krull. | ||||||||||
| 160 | |||||||||||
| 161 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 162 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||
| 163 | copy of the full license at: | ||||||||||
| 164 | |||||||||||
| 165 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||
| 166 | |||||||||||
| 167 | Any use, modification, and distribution of the Standard or Modified | ||||||||||
| 168 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||
| 169 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||
| 170 | or distribute the Package, if you do not accept this license. | ||||||||||
| 171 | |||||||||||
| 172 | If your Modified Version has been derived from a Modified Version made | ||||||||||
| 173 | by someone other than you, you are nevertheless required to ensure that | ||||||||||
| 174 | your Modified Version complies with the requirements of this license. | ||||||||||
| 175 | |||||||||||
| 176 | This license does not grant you the right to use any trademark, service | ||||||||||
| 177 | mark, tradename, or logo of the Copyright Holder. | ||||||||||
| 178 | |||||||||||
| 179 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||
| 180 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||
| 181 | otherwise transfer the Package with respect to any patent claims | ||||||||||
| 182 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||
| 183 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||
| 184 | counterclaim) against any party alleging that the Package constitutes | ||||||||||
| 185 | direct or contributory patent infringement, then this Artistic License | ||||||||||
| 186 | to you shall terminate on the date that such litigation is filed. | ||||||||||
| 187 | |||||||||||
| 188 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||
| 189 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||
| 190 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||
| 191 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||
| 192 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||
| 193 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||
| 194 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||
| 195 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||
| 196 | |||||||||||
| 197 | |||||||||||
| 198 | =cut | ||||||||||
| 199 | |||||||||||
| 200 | 1 | 1; # End of Uninets::Check::Modules::MongoDB | |||||||||