import to mercurial
authorChristian Arnold <arnold@schlittermann.de>
Wed, 15 Jun 2011 15:28:45 +0200
changeset 0 193a7350151d
child 1 8aa45e0a1a68
import to mercurial
.hgignore
.perltitdy
Makefile
check_zpush.pl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Jun 15 15:28:45 2011 +0200
@@ -0,0 +1,9 @@
+syntax: glob
+*.swp
+debian/files
+check_zpush
+
+syntax: regexp
+(build|configure)-stamp$
+debian/nagios-plugin-zpush[./]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.perltitdy	Wed Jun 15 15:28:45 2011 +0200
@@ -0,0 +1,2 @@
+--paren-tightness=2
+--square-bracket-tightness=2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Wed Jun 15 15:28:45 2011 +0200
@@ -0,0 +1,22 @@
+SCRIPTS = check_zpush
+CLEANFILES = ${SCRIPTS}
+DESTDIR =
+prefix = /usr
+
+plugindir = ${prefix}/lib/nagios/plugins/ius
+
+.PHONY:	all clean install
+
+all:	${SCRIPTS}
+
+clean:
+	-rm -f ${CLEANFILES}
+
+install:	all
+	install -d -m 0755 ${DESTDIR}/${plugindir}
+	install -m 0755 $(SCRIPTS) ${DESTDIR}/${plugindir}/
+
+%:	%.pl
+	@perl -c $<
+	@cp -f $< $@
+	@chmod +x $@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/check_zpush.pl	Wed Jun 15 15:28:45 2011 +0200
@@ -0,0 +1,197 @@
+#! /usr/bin/perl -w
+
+#    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 File::Basename;
+use Getopt::Long;
+use Pod::Usage;
+use LWP::Simple;
+
+delete @ENV{ grep /^LC_/ => keys %ENV };
+$ENV{LANG}   = "C";
+$ENV{LC_ALL} = "C";
+
+sub version($$);
+sub get_current_version($);
+sub get_last_version($$);
+sub report($$);
+
+my %ERRORS = (
+    OK        => 0,
+    WARNING   => 1,
+    CRITICAL  => 2,
+    UNKNOWN   => 3,
+    DEPENDENT => 4
+);
+
+my $ME      = basename $0;
+my $NAME    = "Z-PUSH";
+my $VERSION = "0.1";
+
+my %opt = (
+    url  => "http://developer.berlios.de/project/showfiles.php?group_id=8963",
+    file => "/var/www/z-push/version.php"
+);
+
+MAIN: {
+    Getopt::Long::Configure('bundling');
+    GetOptions(
+        "u|url=s"  => \$opt{url},
+        "l|file=s" => \$opt{file},
+        "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 $current_version = get_current_version( $opt{file} );
+    my $last_version = get_last_version( $opt{url}, $opt{search} );
+    report( $last_version, $current_version );
+}
+
+sub report($$) {
+    my ( $last_version, $current_version ) = @_;
+
+    unless ( $last_version eq $current_version ) {
+        say
+"$NAME WARNING: installed version $current_version available version $last_version";
+        exit $ERRORS{WARNING};
+    }
+
+    say "$NAME OK: installed version $current_version";
+    exit $ERRORS{OK};
+}
+
+sub get_current_version($) {
+    my ($file) = @_;
+
+    unless ( -r $file ) {
+        say "$NAME CRITICAL: $file - $!.";
+        exit $ERRORS{CRITICAL};
+    }
+
+    open( FH, $file )
+      or say "$NAME CRITICAL: $file - $!." and exit $ERRORS{CRITICAL};
+
+    while (<FH>) {
+        /^\$zpush_version\s+=\s+"(?<version>[\d.]+)/ and return $+{version};
+    }
+
+    close(FH);
+
+    say "$NAME CRITICAL: Can't find installed version."
+      and exit $ERRORS{CRITICAL};
+}
+
+sub get_last_version($$) {
+    my ( $url, $search ) = @_;
+    my @webside = ();
+
+    my $side = get($url);
+    return "can't get $url" if ( !$side );
+
+    push @webside, split( "\n", $side );
+    my $zpb = undef;
+    foreach (@webside) {
+        if ( $zpb || m|<h3>Z-Push Backend</h3>| ) {
+            $zpb = 1;
+            m|<h3>Z-Push Backend/older releases</h3>| and last;
+            m|>Version\s+(?<version>[\d.]+)<| and return $+{version};
+        }
+    }
+
+    say "$NAME CRITICAL: Can't find last version." and exit $ERRORS{CRITICAL};
+}
+
+sub version($$) {
+    my ( $progname, $version ) = @_;
+
+    say <<_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_zpush - nagios plugin to check z-push version
+
+=head1 SYNOPSIS
+
+check_zpush [B<-u>|B<--url>]
+
+check_zpush [B<-f>|B<--file>]
+
+check_zpush [B<-h>|B<--help>]
+
+check_zpush [B<-m>|B<--man>]
+
+check_zpush [B<-v>|B<--version>]
+
+=head1 OPTIONS
+
+=over
+
+=item B<-u>|B<--url>
+
+Download I<url> with z-push release information. (default: http://developer.berlios.de/project/showfiles.php?group_id=8963)
+
+=item B<-f>|B<--file>
+
+Local z-push version file. (default: /var/www/z-push/version.php)
+
+=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 search on a specified I<url> for a new version of z-push and compare the search result with an installed version.
+
+=head1 VERSION
+
+This man page is current for version 0.1 of B<check_zpush>.
+
+=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