--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/check_zarafa.pl Thu May 12 14:39:14 2011 +0200
@@ -0,0 +1,190 @@
+#! /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 <http://www.gnu.org/licenses/>.
+#
+# Christian Arnold <arnold@schlittermann.de>
+
+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.1';
+
+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|uerl=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 = "";
+
+ push @webside, split( "\n", get($url) );
+ 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<string>
+
+URL where will be look for the I<search> string ( default: http://www.zarafa.com/download-release )
+
+=item B<-s>|B<--search> I<string>
+
+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<string>
+
+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<search> on a specified I<url> for a version string and compare the I<search> result with an installed I<package> version.
+
+=head1 VERSION
+
+This man page is current for version 0.1 of B<check_zarafa>.
+
+=head1 AUTHOR
+
+Written by Christian Arnold L<arnold@schlittermann.de>
+
+=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