3e48383a666a9081578aee8277f6a8d30d36bf66
[WWW-Mechanize-Script.git] / bin / check_web2.pl
blob3e48383a666a9081578aee8277f6a8d30d36bf66
1 #! perl
3 use strict;
4 use warnings;
6 # PODNAME: check_web2
7 # ABSTRACT: allows checking of website according to configured specifications
9 use v5.10.1;
11 use Getopt::Long;
13 use Params::Util qw(_ARRAY);
15 use WWW::Mechanize::Script::Util qw(:ALL);
16 use WWW::Mechanize::Script;
18 my $VERSION = '0.001_003';
19 my %opts;
20 my @options = ( "file=s", "help|h", "usage|?" );
22 GetOptions( \%opts, @options ) or pod2usage(2);
24 defined( $opts{help} )
25 and $opts{help}
26 and pod2usage(
28 -verbose => 2,
29 -exitval => 0
32 defined( $opts{usage} ) and $opts{usage} and pod2usage(1);
33 opt_required_all( \%opts, qw(file) );
35 my %cfg = load_config( \%opts );
38 my %cfgvar = ( OPTS_FILE => $opts{file} );
39 my $cfgkeys = join( "|", keys %cfgvar );
40 $cfg{summary}->{target} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
41 $cfg{report}->{target} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
42 } while (0);
44 my $wms = WWW::Mechanize::Script->new( \%cfg );
46 _ARRAY( $cfg{wtscript_extensions} )
47 and Config::Any::WTScript->extensions( @{ $cfg{wtscript_extensions} } );
48 my @script_files = find_scripts( \%cfg, $opts{file} );
50 my ( $code, @msgs ) = (0);
51 eval {
52 my @script;
53 my $scripts = Config::Any->load_files(
55 files => [@script_files],
56 use_ext => 1,
57 flatten_to_hash => 1,
60 foreach my $filename (@script_files)
62 defined( $scripts->{$filename} )
63 or next; # file not found or not parsable ...
64 # merge into default and previous loaded config ...
65 push( @script, @{ $scripts->{$filename} } );
67 ( $code, @msgs ) = $wms->run_script(@script);
69 $@ and say("UNKNOWN - $@");
70 exit( $@ ? 255 : $code );
72 __END__
74 =head1 DESCRIPTION
76 check_web2 is intended to be used to check web-sites according a configuration.
77 The configuration covers the request configuration (including agent part) and
78 check configuration to specify check parameters.
80 See C<WWW::Mechanize::Script> for details about the configuration options.
82 =head2 HISTORY
84 This script is created as successor of an check_web script of a nagios setup
85 based on HTTP::WebCheck. This module isn't longer maintained, so decision
86 was made to create a new environment simulating the old one basing on
87 WWW::Mechanize.
89 =head1 SYNOPSIS
91 $ check_web2 --file domain1/site1.json
92 $ check_web2 --file domain2/site1.yml
93 # for compatibility
94 $ check_web2 --file domain1/site2.wts
96 =head1 AUTHOR
98 Jens Rehsack, C<< <rehsack at cpan.org> >>
100 =head1 BUGS
102 Please report any bugs or feature requests to C<bug-www-mechanize-script at rt.cpan.org>, or through
103 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Mechanize-Script>. I will be notified, and then you'll
104 automatically be notified of progress on your bug as I make changes.
106 =head1 SUPPORT
108 You can find documentation for this module with the perldoc command.
110 perldoc WWW:Mechanize::Script
112 You can also look for information at:
114 =over 4
116 =item * RT: CPAN's request tracker (report bugs here)
118 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mechanize-Script>
120 =item * AnnoCPAN: Annotated CPAN documentation
122 L<http://annocpan.org/dist/WWW-Mechanize-Script>
124 =item * CPAN Ratings
126 L<http://cpanratings.perl.org/d/WWW-Mechanize-Script>
128 =item * Search CPAN
130 L<http://search.cpan.org/dist/WWW-Mechanize-Script/>
132 =back
134 =head1 ACKNOWLEDGEMENTS
136 =head1 LICENSE AND COPYRIGHT
138 Copyright 2012 Jens Rehsack.
140 This program is free software; you can redistribute it and/or modify it
141 under the terms of either: the GNU General Public License as published
142 by the Free Software Foundation; or the Artistic License.
144 See http://dev.perl.org/licenses/ for more information.
146 =cut