diff -r 2d2de8fa5d70 -r 8bec5bd2e6b2 check_zarafa.pl
--- a/check_zarafa.pl Tue Apr 17 10:14:59 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,194 +0,0 @@
-#! /usr/bin/perl
-
-# Copyright (C) 2011 Christian Arnold
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-#
-# Christian Arnold
-
-use 5.010;
-use strict;
-use warnings;
-use File::Basename qw(basename);
-use Pod::Usage;
-use Getopt::Long;
-use LWP::Simple;
-
-delete @ENV{ grep /^LC_/ => keys %ENV };
-$ENV{LANG} = "C";
-$ENV{LC_ALL} = "C";
-
-sub version($$);
-sub get_last_version($$);
-sub get_current_version($);
-sub report($$);
-
-my %ERRORS = (
- OK => 0,
- WARNING => 1,
- CRITICAL => 2,
- UNKNOWN => 3,
- DEPENDENT => 4
-);
-
-my $ME = basename $0;
-my $NAME = 'ZARAFA';
-my $VERSION = '0.3';
-
-my %opt = (
- url => 'http://www.zarafa.com/download-release',
- search => 'http://download.zarafa.com/community/final/[\d\.]+/([\d\.-]+)',
- package => 'zarafa'
-);
-
-MAIN: {
- Getopt::Long::Configure('no_ignore_case_always');
- GetOptions(
- "u|url=s" => \$opt{url},
- "s|search=s" => \$opt{search},
- "p|package=s" => \$opt{package},
- "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) },
- "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) },
- "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; }
- ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} );
-
- my $last_verbose = get_last_version( $opt{url}, $opt{search} );
- my $current_version = get_current_version( $opt{package} );
-
- report( $last_verbose, $current_version );
-}
-
-sub get_last_version($$) {
- my ( $url, $search ) = @_;
- my @webside = ();
- my $last_verbose = "";
-
- my $side = get($url);
-
- return "can't get $url" if ( !$side );
-
- push @webside, split( "\n", $side );
- foreach (@webside) {
- /$search/ or next;
- $last_verbose = $1 and last;
- }
- return $last_verbose if ($last_verbose);
- return "-";
-}
-
-sub get_current_version($) {
- my ($package) = @_;
- my $version = undef;
-
- my @current_version = grep { /^Version:/ } `dpkg -s $package 2> /dev/null`;
- if ( $current_version[0] ) {
- $current_version[0] =~ /^Version:\s+(\S+)/ and $version = $1;
- }
- return $version if ($version);
- return "-";
-}
-
-sub report($$) {
- my ( $last_verbose, $current_version ) = @_;
-
- if ( $last_verbose eq $current_version ) {
- say "$NAME OK: $opt{package} version $current_version";
- exit $ERRORS{OK};
- }
- else {
- say
-"$NAME WARNING: $opt{package} installed version $current_version available version $last_verbose";
- exit $ERRORS{WARNING};
- }
-}
-
-sub version($$) {
- my ( $progname, $version ) = @_;
- print <<_VERSION;
-$progname version $version
-Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support.
-
-$ME comes with ABSOLUTELY NO WARRANTY. This is free software,
-and you are welcome to redistribute it under certain conditions.
-See the GNU General Public Licence for details.
-_VERSION
-}
-
-__END__
-
-=head1 NAME
-
-check_zarafa - nagios plugin to check installed zarafa version
-
-=head1 SYNOPSIS
-
-check_zarafa [B<-u>|B<--url> string] [B<-s>|B<--search> string] [B<-p>|B<--package> string]
-
-check_zarafa [B<-h>|B<--help>]
-
-check_zarafa [B<-m>|B<--man>]
-
-check_zarafa [B<-V>|B<--version>]
-
-=head1 OPTIONS
-
-=over
-
-=item B<-u>|B<--url> I
-
-URL where will be look for the I string ( default: http://www.zarafa.com/download-release )
-
-=item B<-s>|B<--search> I
-
-Perl regular expression to search version string on the url. The content of the round brackets in the
-regular expression will be used to compare with the installed package version.
-( default: 'http://download.zarafa.com/community/final/[\d\.]+/([\d\.-]+)' )
-
-=item B<-p>|B<--package> I
-
-Installed package name ( default: zarafa )
-
-=item B<-h>|B<--help>
-
-Print detailed help screen.
-
-=item B<-m>|B<--man>
-
-Print manual page.
-
-=item B<-V>|B<--version>
-
-Print version information.
-
-=back
-
-=head1 DESCRIPTION
-
-This nagios plugin I on a specified I for a version string and compare the I result with an installed I version.
-
-=head1 VERSION
-
-This man page is current for version 0.3 of B.
-
-=head1 AUTHOR
-
-Written by Christian Arnold L
-
-=head1 COPYRIGHT
-
-Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support. This is free software, and you are welcome to
-redistribute it under certain conditions.
-See the GNU General Public Licence for details.
-
-=cut