9 use File
::Basename
qw(fileparse);
10 use File
::ConfigDir
qw(config_dirs);
17 use WWW
::Mechanize
::Script
;
21 my @options = ( "file=s", "help|h", "usage|?" );
23 GetOptions
( \
%opts, @options ) or pod2usage
(2);
25 defined( $opts{help
} )
33 defined( $opts{usage
} ) and $opts{usage
} and pod2usage
(1);
34 defined( $opts{file
} ) or isatty
(*STDOUT
) ? pod2usage
(1) : die "Missing --file argument";
41 accept_cookies
=> 'yes',
43 show_headers
=> 'yes',
45 terse
=> 'failed_only',
49 ( $opts{file
} =~ /(_w$|^wap\/)/ )
50 ?
"Nokia6210/1.0 (03.01) UP.Link/5.0.0.4 VZDE-check_wap $VERSION"
51 : "Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv: VZDE-check_web $VERSION)"
56 'Premature end of script headers',
57 'Error processing directive',
58 'XML Parsing partner document',
59 'sun.io.MalformedInputException',
60 'an error occurred while processing this directive'
66 my @cfg_dirs = config_dirs
();
67 my $progname = fileparse
( $0, qr/\.[^.]*$/ );
68 my @cfg_pattern = map { $progname . "." . $_ } Config
::Any
->extensions();
69 my @cfg_files = File
::Find
::Rule
->file()->name(@cfg_pattern)->maxdepth(1)->in(@cfg_dirs);
72 my $merger = Hash
::Merge
->new('LEFT_PRECEDENT');
74 my $all_cfg = Config
::Any
->load_files(
76 files
=> [@cfg_files],
82 foreach my $filename (@cfg_files)
84 defined( $all_cfg->{$filename} )
85 or next; # file not found or not parsable ...
86 # merge into default and previous loaded config ...
87 %cfg = %{ $merger->merge( \
%cfg, $all_cfg->{$filename} ) };
93 my %cfgvar = ( OPTS_FILE
=> $opts{file
} );
94 my $cfgkeys = join( "|", keys %cfgvar );
95 $cfg{summary
}->{target
} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
96 $cfg{report
}->{target
} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
99 my $wms = WWW
::Mechanize
::Script
->new( \
%cfg );
101 if ( -f
$opts{file
} and -r
$opts{file
} )
103 @cfg_files = ( $opts{file
} );
107 my ( $volume, $directories, $fn ) = File
::Spec
->splitpath( $opts{file
} );
108 @cfg_dirs = config_dirs
( $cfg{script_dir
} // "check_web" );
111 map { File
::Spec
->catdir( $_, $directories ) }
112 config_dirs
( $cfg{script_dir
} // "check_web" ); # XXX basename $0
113 @cfg_pattern = map { $fn . "." . $_ } Config
::Any
->extensions();
114 @cfg_files = File
::Find
::Rule
->file()->name(@cfg_pattern)->maxdepth(1)->in(@cfg_dirs);
117 my ( $code, @msgs ) = (0);
120 my $scripts = Config
::Any
->load_files(
122 files
=> [@cfg_files],
124 flatten_to_hash
=> 1,
127 foreach my $filename (@cfg_files)
129 defined( $scripts->{$filename} )
130 or next; # file not found or not parsable ...
131 # merge into default and previous loaded config ...
132 push( @script, @
{ $scripts->{$filename} } );
134 ( $code, @msgs ) = $wms->run_script(@script);
136 $@
and say("UNKNOWN - $@");
137 exit( $@ ?
255 : $code );
143 check_web2 - allows checking of website according to configured specifications
147 check_web2 is intended to be used to check web-sites accoring a configuration.
148 The configuration covers the request configuration (including agent part) and
149 check configuration to specify check parameters.
151 See C<WWW::Mechanize::Script> for details about the configuration options.
155 This script is created as successor of an check_web script of a nagios setup
156 based on HTTP::WebCheck. This module isn't longer maintained, so decision
157 was made to create a new environment simulating the old one basing on
162 $ check_web2 --file domain1/site1.json
163 $ check_web2 --file domain2/site1.yml
165 $ check_web2 --file domain1/site2.wts
169 Jens Rehsack, C<< <rehsack at cpan.org> >>
173 Please report any bugs or feature requests to C<bug-www-mechanize-script at rt.cpan.org>, or through
174 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Mechanize-Script>. I will be notified, and then you'll
175 automatically be notified of progress on your bug as I make changes.
179 You can find documentation for this module with the perldoc command.
181 perldoc WWW:Mechanize::Script
183 You can also look for information at:
187 =item * RT: CPAN's request tracker (report bugs here)
189 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mechanize-Script>
191 =item * AnnoCPAN: Annotated CPAN documentation
193 L<http://annocpan.org/dist/WWW-Mechanize-Script>
197 L<http://cpanratings.perl.org/d/WWW-Mechanize-Script>
201 L<http://search.cpan.org/dist/WWW-Mechanize-Script/>
205 =head1 ACKNOWLEDGEMENTS
207 =head1 LICENSE AND COPYRIGHT
209 Copyright 2012 Jens Rehsack.
211 This program is free software; you can redistribute it and/or modify it
212 under the terms of either: the GNU General Public License as published
213 by the Free Software Foundation; or the Artistic License.
215 See http://dev.perl.org/licenses/ for more information.