restructered the directory layout default tip
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Thu, 03 Nov 2011 09:05:07 +0100
changeset 6 aa38ce4e9c64
parent 5 3ce1738b5b5c
restructered the directory layout
.perltidyrc
bash/submit-via-nsca
perl/.perltidyrc
perl/submit-via-nsca
submit-via-nsca.pl
submit-via-nsca.sh
--- a/.perltidyrc	Wed Nov 02 18:08:04 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
---paren-tightness=2
---square-bracket-tightness=2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bash/submit-via-nsca	Thu Nov 03 09:05:07 2011 +0100
@@ -0,0 +1,64 @@
+#! /bin/bash
+# © 2011 Heiko Schlittermann <hs@schlittermann.de>
+# source: https://ssl.schlittermann.de/hg/check-by-nsca
+
+set -e
+
+unset ${!LC_*} LANG
+export LC_ALL=C
+ME=$(basename $0)
+TAB=$'\x09'
+
+function send()       { send_nsca "$@"; }
+function debug_send() { echo "CMDLINE: $@"; sed 's/\t/<<TAB>>/g'; }
+send=send             # changed by option
+
+
+# read defaults, if exist
+test -f /etc/defaults/$ME \
+    && source /etc/defaults/$ME
+
+hostname=$(hostname -f)
+svcname=-
+nsca_host=
+nsca_port=
+
+tmp=$(getopt -n $0 -o hH:S:p:d \
+    -l help,hostname:,servicename:,nsca-host:,nsca-port:,debug \
+    -- "$@") || exit 2
+eval set -- "$tmp"
+
+while true; do
+    opt="$1"; shift
+    case "$opt" in
+        -H|--hostname)  hostname="$1"; shift;;
+        -S|--svcname)   svcname="$1"; shift;;
+           --nsca-host) nsca_host="$1"; shift;;
+        -p|--nsca-port) nsca_port="$1"; shift;;
+        -h|--help)      cat <<_USAGE
+Usage: $ME [options] -- {test} [test-options]
+       -H|--hostname    Hostname to be sent along the result ($hostname).
+       -S|--servicename Servicename to be sent along the result.
+                        Use "" to mark a host check.
+                        Use "-" (the default) to have the servicename guessed 
+                        from the test output (the first word).
+       --nsca-host      Destination host ($nsca_host)
+       --nsca-port      Destination port ($nsca_port)
+_USAGE
+                        exit 0;;
+       -d|--debug)      send="debug_$send";;
+        --)     break;;
+    esac
+
+done
+
+rc=0
+output=$("$@") || rc=$?
+
+test "$svcname" = "-" && svcname="${output%% *}"
+svcname="${svcname:+$TAB$svcname}"
+
+echo "$hostname$svcname$TAB$rc$TAB$output" \
+        | $send -H "$nsca_host" ${nsca_port:+-p $nsca_port}
+
+# vim:sts=4 sw=4 aw ai sm et:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/.perltidyrc	Thu Nov 03 09:05:07 2011 +0100
@@ -0,0 +1,2 @@
+--paren-tightness=2
+--square-bracket-tightness=2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/submit-via-nsca	Thu Nov 03 09:05:07 2011 +0100
@@ -0,0 +1,125 @@
+#! /usr/bin/perl
+# © 2011 Heiko Schlittermann <hs@schlittermann.de>
+# source: https://ssl.schlittermann.de/hg/check-by-nsca
+
+use strict;
+use warnings;
+use Sys::Hostname;
+use File::Basename;
+use Getopt::Long;
+use Pod::Usage;
+use Readonly;
+
+Readonly my $ME => basename $0;
+
+delete @ENV{ grep /^(LC_|LANG)/ => keys %ENV };
+$ENV{LC_ALL} = "C";
+
+my %o = (
+    hostname  => hostname(),
+    svcname   => "-",
+    nsca_host => undef,
+    nsca_port => undef,
+    debug     => undef,
+);
+
+MAIN: {
+    Getopt::Long::Configure("bundling");
+    GetOptions(
+        "H|hostname=s"    => \$o{hostname},
+        "S|servicename=s" => \$o{svcname},
+        "nsca-host=s"     => \$o{nsca_host},
+        "p|nsca-port=i"   => \$o{nsca_port},
+        "h|help"          => sub { pod2usage(-verbose => 1, -exit => 0) },
+        "m|man"           => sub {
+            pod2usage(
+                -verbose   => 2,
+                -exit      => 0,
+                -noperldoc => system("perldoc -V 2>/dev/null 1>/dev/null")
+            );
+        },
+        "d|debug" => \$o{debug},
+    ) or pod2usage();
+
+    my $cmdline = "send_nsca -H '$o{nsca_host}'"
+      . (defined $o{nsca_port} ? " -p $o{nsca_port}" : "");
+
+    $_ = `@ARGV`;
+    my $rc = $? >> 8;
+
+    if ($o{svcname} eq "-") {
+        /^(?<service>\S+)\s/ or die "$ME: Can't guess servicename!\n";
+        $o{svcname} = $+{service};
+    }
+    $_ =
+      join "\t" => $o{hostname},
+      length($o{svcname})
+      ? $o{svcname}
+      : (), $rc, $_;
+
+    if ($o{debug}) {
+        print $cmdline, "\n$_\n";
+        exit;
+    }
+
+    open(SEND, "|$cmdline") or die "$ME: Can't open `$cmdline': $!\n";
+    print SEND $_;
+    close(SEND)
+      or die $!
+      ? "$ME: Error closing `$cmdline': $!\n"
+      : "$ME: Error status from `$cmdline': $?\n";
+
+}
+
+__END__
+
+=head1 NAME
+
+ submit-via-nsca - submit service, or host check results via nsca
+
+=head1 SYNOPSIS
+
+ submit-via nsca --nsca-host {host} [options] -- {check} [check-options]
+
+=head1 DESCRIPTION
+
+This simple script submits the result of nagios check plugins to an NSCA
+receiver. The script does not send the result itself, it's merely a
+wrapper around C<send_nsca>.
+
+=head1 OPTIONS
+
+=over
+
+=item B<-H> | B<--hostname> I<hostname>
+
+The hostname to be sent along with the result. (defaults to the local
+host name).
+
+=item B<-S> | B<--servicename> I<servicename>
+
+The servicename to be sent along with the result. If a single "-" (dash)
+is used, the servicename is guessed from service check output, if ""
+(empty), a host check is submitted. (default: "-")
+
+=item B<--nsca-host> I<hostname>
+
+The destination host (the host, where the NSCA listener is running).
+(no default).
+
+=item B<--nsca-port> I<port>
+
+The destination port. (default depends on the C<send_nsca> utility)
+
+=item B<-h> | B<--help>
+
+=item B<-m> | B<--man>
+
+The long or short help text.
+
+=back
+
+=head1 AUTHORS
+
+Heiko Schlittermann L<mailto:hs@schlittermann.de>, the source can be
+found at L<https://ssl.schlittermann.de/hg/submit-via-nsca>.
--- a/submit-via-nsca.pl	Wed Nov 02 18:08:04 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-#! /usr/bin/perl
-# © 2011 Heiko Schlittermann <hs@schlittermann.de>
-# source: https://ssl.schlittermann.de/hg/check-by-nsca
-
-use strict;
-use warnings;
-use Sys::Hostname;
-use File::Basename;
-use Getopt::Long;
-use Pod::Usage;
-use Readonly;
-
-Readonly my $ME => basename $0;
-
-delete @ENV{ grep /^(LC_|LANG)/ => keys %ENV };
-$ENV{LC_ALL} = "C";
-
-my %o = (
-    hostname  => hostname(),
-    svcname   => "-",
-    nsca_host => undef,
-    nsca_port => undef,
-    debug     => undef,
-);
-
-MAIN: {
-    Getopt::Long::Configure("bundling");
-    GetOptions(
-        "H|hostname=s"    => \$o{hostname},
-        "S|servicename=s" => \$o{svcname},
-        "nsca-host=s"     => \$o{nsca_host},
-        "p|nsca-port=i"   => \$o{nsca_port},
-        "h|help"          => sub { pod2usage(-verbose => 1, -exit => 0) },
-        "m|man"           => sub {
-            pod2usage(
-                -verbose   => 2,
-                -exit      => 0,
-                -noperldoc => system("perldoc -V 2>/dev/null 1>/dev/null")
-            );
-        },
-        "d|debug" => \$o{debug},
-    ) or pod2usage();
-
-    my $cmdline = "send_nsca -H '$o{nsca_host}'"
-      . (defined $o{nsca_port} ? " -p $o{nsca_port}" : "");
-
-    $_ = `@ARGV`;
-    my $rc = $? >> 8;
-
-    if ($o{svcname} eq "-") {
-        /^(?<service>\S+)\s/ or die "$ME: Can't guess servicename!\n";
-        $o{svcname} = $+{service};
-    }
-    $_ =
-      join "\t" => $o{hostname},
-      length($o{svcname})
-      ? $o{svcname}
-      : (), $rc, $_;
-
-    if ($o{debug}) {
-        print $cmdline, "\n$_\n";
-        exit;
-    }
-
-    open(SEND, "|$cmdline") or die "$ME: Can't open `$cmdline': $!\n";
-    print SEND $_;
-    close(SEND)
-      or die $!
-      ? "$ME: Error closing `$cmdline': $!\n"
-      : "$ME: Error status from `$cmdline': $?\n";
-
-}
-
-__END__
-
-=head1 NAME
-
- submit-via-nsca - submit service, or host check results via nsca
-
-=head1 SYNOPSIS
-
- submit-via nsca --nsca-host {host} [options] -- {check} [check-options]
-
-=head1 DESCRIPTION
-
-This simple script submits the result of nagios check plugins to an NSCA
-receiver. The script does not send the result itself, it's merely a
-wrapper around C<send_nsca>.
-
-=head1 OPTIONS
-
-=over
-
-=item B<-H> | B<--hostname> I<hostname>
-
-The hostname to be sent along with the result. (defaults to the local
-host name).
-
-=item B<-S> | B<--servicename> I<servicename>
-
-The servicename to be sent along with the result. If a single "-" (dash)
-is used, the servicename is guessed from service check output, if ""
-(empty), a host check is submitted. (default: "-")
-
-=item B<--nsca-host> I<hostname>
-
-The destination host (the host, where the NSCA listener is running).
-(no default).
-
-=item B<--nsca-port> I<port>
-
-The destination port. (default depends on the C<send_nsca> utility)
-
-=item B<-h> | B<--help>
-
-=item B<-m> | B<--man>
-
-The long or short help text.
-
-=back
-
-=head1 AUTHORS
-
-Heiko Schlittermann L<mailto:hs@schlittermann.de>, the source can be
-found at L<https://ssl.schlittermann.de/hg/submit-via-nsca>.
--- a/submit-via-nsca.sh	Wed Nov 02 18:08:04 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-#! /bin/bash
-# © 2011 Heiko Schlittermann <hs@schlittermann.de>
-# source: https://ssl.schlittermann.de/hg/check-by-nsca
-
-set -e
-
-unset ${!LC_*} LANG
-export LC_ALL=C
-ME=$(basename $0)
-TAB=$'\x09'
-
-function send()       { send_nsca "$@"; }
-function debug_send() { echo "CMDLINE: $@"; sed 's/\t/<<TAB>>/g'; }
-send=send             # changed by option
-
-
-# read defaults, if exist
-test -f /etc/defaults/$ME \
-    && source /etc/defaults/$ME
-
-hostname=$(hostname -f)
-svcname=-
-nsca_host=
-nsca_port=
-
-tmp=$(getopt -n $0 -o hH:S:p:d \
-    -l help,hostname:,servicename:,nsca-host:,nsca-port:,debug \
-    -- "$@") || exit 2
-eval set -- "$tmp"
-
-while true; do
-    opt="$1"; shift
-    case "$opt" in
-        -H|--hostname)  hostname="$1"; shift;;
-        -S|--svcname)   svcname="$1"; shift;;
-           --nsca-host) nsca_host="$1"; shift;;
-        -p|--nsca-port) nsca_port="$1"; shift;;
-        -h|--help)      cat <<_USAGE
-Usage: $ME [options] -- {test} [test-options]
-       -H|--hostname    Hostname to be sent along the result ($hostname).
-       -S|--servicename Servicename to be sent along the result.
-                        Use "" to mark a host check.
-                        Use "-" (the default) to have the servicename guessed 
-                        from the test output (the first word).
-       --nsca-host      Destination host ($nsca_host)
-       --nsca-port      Destination port ($nsca_port)
-_USAGE
-                        exit 0;;
-       -d|--debug)      send="debug_$send";;
-        --)     break;;
-    esac
-
-done
-
-rc=0
-output=$("$@") || rc=$?
-
-test "$svcname" = "-" && svcname="${output%% *}"
-svcname="${svcname:+$TAB$svcname}"
-
-echo "$hostname$svcname$TAB$rc$TAB$output" \
-        | $send -H "$nsca_host" ${nsca_port:+-p $nsca_port}
-
-# vim:sts=4 sw=4 aw ai sm et: