modify default extensions for web-test scripts, allow override and take from config
[WWW-Mechanize-Script.git] / bin / check_web2.pl
blob15f1cc05565792994471c5fdf05fcaaf975ecbd4
1 #! perl
3 use strict;
4 use warnings;
6 use v5.10.1;
8 use Getopt::Long;
10 use Params::Util qw(_ARRAY);
12 use WWW::Mechanize::Script::Util qw(:ALL);
13 use WWW::Mechanize::Script;
15 my $VERSION = 0.001;
16 my %opts;
17 my @options = ( "file=s", "help|h", "usage|?" );
19 GetOptions( \%opts, @options ) or pod2usage(2);
21 defined( $opts{help} )
22 and $opts{help}
23 and pod2usage(
25 -verbose => 2,
26 -exitval => 0
29 defined( $opts{usage} ) and $opts{usage} and pod2usage(1);
30 opt_required_all( \%opts, qw(file) );
32 my %cfg = load_config( \%opts );
35 my %cfgvar = ( OPTS_FILE => $opts{file} );
36 my $cfgkeys = join( "|", keys %cfgvar );
37 $cfg{summary}->{target} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
38 $cfg{report}->{target} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
39 } while (0);
41 my $wms = WWW::Mechanize::Script->new( \%cfg );
43 my @script_files = find_scripts( \%cfg, $opts{file} );
45 _ARRAY( $cfg{wtscript_extensions} )
46 and Config::Any::WTScript->extensions( @{ $cfg{wtscript_extensions} } );
47 my ( $code, @msgs ) = (0);
48 eval {
49 my @script;
50 my $scripts = Config::Any->load_files(
52 files => [@script_files],
53 use_ext => 1,
54 flatten_to_hash => 1,
57 foreach my $filename (@script_files)
59 defined( $scripts->{$filename} )
60 or next; # file not found or not parsable ...
61 # merge into default and previous loaded config ...
62 push( @script, @{ $scripts->{$filename} } );
64 ( $code, @msgs ) = $wms->run_script(@script);
66 $@ and say("UNKNOWN - $@");
67 exit( $@ ? 255 : $code );
69 __END__
71 =head1 NAME
73 check_web2 - allows checking of website according to configured specifications
75 =head1 DESCRIPTION
77 check_web2 is intended to be used to check web-sites according a configuration.
78 The configuration covers the request configuration (including agent part) and
79 check configuration to specify check parameters.
81 See C<WWW::Mechanize::Script> for details about the configuration options.
83 =head2 HISTORY
85 This script is created as successor of an check_web script of a nagios setup
86 based on HTTP::WebCheck. This module isn't longer maintained, so decision
87 was made to create a new environment simulating the old one basing on
88 WWW::Mechanize.
90 =head1 SYNOPSIS
92 $ check_web2 --file domain1/site1.json
93 $ check_web2 --file domain2/site1.yml
94 # for compatibility
95 $ check_web2 --file domain1/site2.wts
97 =head1 AUTHOR
99 Jens Rehsack, C<< <rehsack at cpan.org> >>
101 =head1 BUGS
103 Please report any bugs or feature requests to C<bug-www-mechanize-script at rt.cpan.org>, or through
104 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Mechanize-Script>. I will be notified, and then you'll
105 automatically be notified of progress on your bug as I make changes.
107 =head1 SUPPORT
109 You can find documentation for this module with the perldoc command.
111 perldoc WWW:Mechanize::Script
113 You can also look for information at:
115 =over 4
117 =item * RT: CPAN's request tracker (report bugs here)
119 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mechanize-Script>
121 =item * AnnoCPAN: Annotated CPAN documentation
123 L<http://annocpan.org/dist/WWW-Mechanize-Script>
125 =item * CPAN Ratings
127 L<http://cpanratings.perl.org/d/WWW-Mechanize-Script>
129 =item * Search CPAN
131 L<http://search.cpan.org/dist/WWW-Mechanize-Script/>
133 =back
135 =head1 ACKNOWLEDGEMENTS
137 =head1 LICENSE AND COPYRIGHT
139 Copyright 2012 Jens Rehsack.
141 This program is free software; you can redistribute it and/or modify it
142 under the terms of either: the GNU General Public License as published
143 by the Free Software Foundation; or the Artistic License.
145 See http://dev.perl.org/licenses/ for more information.
147 =cut