check_exec.pl
changeset 4 67e8bd9a87c5
parent 3 211e08d0d2b8
child 5 03bee3138913
--- a/check_exec.pl	Wed Dec 22 13:42:49 2010 +0100
+++ b/check_exec.pl	Wed Dec 22 15:24:30 2010 +0100
@@ -1,61 +1,71 @@
 #!/usr/bin/perl -w
 
+#    Copyright (C) 2010  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/>.
+#
+#    Chrisitan Arnold <arnold@schlittermann.de>
+
 use strict;
 use File::Basename;
+use Pod::Usage;
 use Getopt::Long;
 use LWP::Simple;
 use HTTP::Status;
 use File::Path;
 
 use lib "/usr/lib/nagios/plugins";
-use utils qw (%ERRORS &print_revision &support);
+use utils qw (%ERRORS);
 
 $ENV{LANG} = "POSIX";
 
 my $ME      = basename $0;
 my $VERSION = "0.2";
-my $USAGE   = <<EOF;
-Usage: $ME -u | --url
-       $ME [ -b | --binary ]
-       $ME [ -p | --path ]
-       $ME [ -h | --help ]
-       $ME [ -V | --version ]
-EOF
-
-sub print_help();
-sub print_usage();
 
 sub download($$);
 sub verify($);
 sub cleanup($);
 sub execute($);
+sub version($$);
 
-my $opt_url;
-my $opt_path   = "/var/tmp/nagios";
-my $opt_binary = "/usr/bin/gpg";
-
-my $home_dir = (getpwuid($>))[7];
+my $opt = {
+    url    => "",
+    path   => "/var/tmp/nagios",
+    binary => "/usr/bin/gpg"
+};
 
 MAIN: {
     Getopt::Long::Configure('bundling');
     GetOptions(
-        "u|url=s"    => \$opt_url,
-        "b|binary=s" => \$opt_binary,
-        "p|path=s"   => \$opt_path,
-        "h|help"     => sub { print_help(); exit $ERRORS{OK}; },
-        "V|version"  => sub { print_revision($ME, $VERSION); exit $ERRORS{OK}; }
+        "u|url=s"    => \$opt->{url},
+        "b|binary=s" => \$opt->{binary},
+        "p|path=s"   => \$opt->{path},
+        "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 do {
-        print $USAGE;
+        pod2usage(-verbose => 1, -exitval => $ERRORS{CRITICAL});
         exit $ERRORS{CRITICAL};
       };
 
-    unless ($opt_url) {
-        print $USAGE;
+    unless ($opt->{url}) {
+        pod2usage(-verbose => 1, -exitval => $ERRORS{CRITICAL});
         exit $ERRORS{CRITICAL};
     }
 
-    download($opt_url, $opt_path);
+    download($opt->{url}, $opt->{path});
 }
 
 sub execute($) {
@@ -121,9 +131,10 @@
     my $file     = shift;
     my $dir      = dirname($file);
     my $run_file = fileparse($file, qw/\.[^.]*/);
+    my $home_dir = (getpwuid($>))[7];
 
-    my $vc = qq{$opt_binary --homedir $home_dir/.gnupg --verify};
-    my $dc = qq{$opt_binary --homedir $home_dir/.gnupg --batch --yes};
+    my $vc = qq|$opt->{binary} --homedir $home_dir/.gnupg --verify|;
+    my $dc = qq|$opt->{binary} --homedir $home_dir/.gnupg --batch --yes|;
 
     my @r = qx/$vc $file 2>&1/;
     if ($?) {
@@ -140,28 +151,83 @@
     execute("$dir/$run_file");
 }
 
-sub print_usage() { print $USAGE }
+sub version($$) {
+    my $progname = shift;
+    my $version  = shift;
+
+    print <<_VERSION;
+$progname version $version
+Copyright (C) 2010 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
+}
+
+=head1 NAME
+
+check_exec - nagios plugin to download/verify/execute a program file
+
+=head1 SYNOPSIS
+
+check_exec -u|--url
+          [-b|--binary path]
+          [-p|--path path]
+
+check_exec [-h|--help]
+
+check_exec [-m|--man]
+
+check_exec [-v|--version]
 
-sub print_help() {
-    print_revision($ME, $VERSION);
-    print <<EOF;
-Copyright (c) 2010 Christian Arnold
+=head1 OPTIONS
+
+=over
+
+=item B<-u>|B<--url> url
+
+Download url for generic script.
+
+=item B<-b>|B<--binary> path
+
+Path to gpg binary program (default: /usr/bin/gpg)
+
+=item B<-p>|B<--path> path
+
+Location for store download script (default: /var/tmp/nagios)
+
+=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 plugin loads a program file via http or https from a
 server and verifies its validity based on a gpg key.
 
-$USAGE
-    -u, --url
-        download url for generic script
-    -b, --binary
-        path to gpg (default: /usr/bin/gpg)
-    -p, --path
-        location for store download script (default: /var/tmp/nagios)
-    -h, --help
-        print detailed help screen
-    -V, --version
-        print version information
+=head1 VERSION
+
+This man page is current for version 0.2 of check_exec.
+
+=head1 AUTHOR
+
+Written by Christian Arnold <arnold@schlittermann.de>
 
-EOF
-    support();
-}
+=head1 COPYRIGHT
+
+Copyright (C) 2010 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