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