/usr/lib/xymon/client/bin/xynagios is in hobbit-plugins 20131022.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | #!/usr/bin/perl -w
use strict;
use Getopt::Long;
use Hobbit;
use Sysadm::Install qw(tap);
sub usage ()
{
print <<EOT;
xynagios (c) Christoph Berg <myon\@debian.org>
usage:
--hostname=<host> Override hostname from environment.
--strip=<prefix> Remove this prefix from test names; "check_" is always
removed.
--trends Send performance data as a "data <host>.trends" report
--help
--version Print this text
EOT
}
my $params;
Getopt::Long::config('bundling');
if (!GetOptions (
'--hostname=s' => \$params->{'hostname'},
'--strip=s' => \$params->{'strip'},
'--trends' => \$params->{'trends'},
'--help' => \$params->{'help'},
'--version' => \$params->{'help'},))
{
usage ();
exit (1);
};
if ($params->{help}) {
usage ();
exit (0);
}
my $test = $ARGV[0];
$test =~ s!.*/!!;
$test =~ s!\..*!!;
$test =~ s/^check_//;
$test =~ s/^$params->{strip}// if ($params->{strip});
my $bb = new Hobbit ({ test => $test, hostname => $params->{hostname} });
my ($stdout, $stderr, $exit_code) = tap (@ARGV);
my ($exit, $signal) = ($exit_code >> 8, $exit_code & 0xff);
if ($signal) {
$bb->color_line ('red', "$test was killed by signal $signal, exit $exit\n");
}
if ($exit > 2) {
$bb->color_line ('red', "$test returned exit $exit\n");
}
if ($stderr) {
$bb->color_line ('red', "Stderr output:\n$stderr");
}
if ($exit == 2) {
$bb->add_color ('red');
} elsif ($exit == 1) {
$bb->add_color ('yellow');
} else {
$bb->add_color ('green');
}
if ($stdout =~ s/^(\S+) +(OK|WARNING|CRITICAL|ERROR|UNKNOWN): *//s) {
$bb->{title} = "$1 $2";
$bb->{test} = lc ($1);
}
$bb->{test} =~ s/^check_//;
$bb->{test} =~ s/^$params->{strip}// if ($params->{strip});
my $trends;
if ($params->{trends}) {
$trends = new Hobbit ({ type => 'data', test => 'trends', hostname => $params->{hostname} });
}
# | time=0.02 postgres=4583020 template0=4349956 template1=4349956
my ($performance, $time);
if ($stdout =~ s/\s+\|\s+(.*)//) {
my @values = split (/\s+/, $1);
foreach my $value (@values) {
unless ($value =~ /(.*)=(.*)/) {
#warn "Missing = in performance value $value\n";
next;
}
my ($label, @figures) = ($1, split (/;/, $2));
$label =~ s/^'|'$//g;
if ($label eq 'time') { # do not treat 'time' as performance data
$time = shift (@figures);
next;
}
my $value = shift (@figures);
$performance .= "$label : $value";
my $warn = shift @figures; $performance .= " warn $warn" if $warn;
my $crit = shift @figures; $performance .= " crit $crit" if $crit;
my $min = shift @figures; $performance .= " min $min" if $min;
my $max = shift @figures; $performance .= " max $max" if $max;
$performance .= "\n";
if ($params->{trends}) {
$trends->print ("[$bb->{test},$label.rrd]\n");
$trends->print ("DS:lambda:GAUGE:600:U:U $value\n");
}
}
}
$bb->print ($stdout);
$bb->print ("\nPerformance data:\n$performance") if $performance;
$bb->print ("\ntime $time") if $time;
$bb->send;
if ($params->{trends}) {
$trends->send;
}
=pod
=head1 NAME
B<xynagios> - adaptor for using Nagios checks with Xymon
=head1 SYNOPSIS
B<xynagios> [I<options> --] I<plugin> [I<options ...>]
=head1 DESCRIPTION
B<xynagios> runs a Nagios check, and reports its output in a way compatible
with the Xymon (Hobbit, BB) monitoring system.
The Xymon test name is taken from the plugin output if it starts with
I<test_name> I<OK|WARNING|CRITICAL|ERROR|UNKNOWN>B<:>. Otherwise, the basename
of the plugin filename is used. A B<check_> prefix is removed for brevity.
=head1 OPTIONS
=over
=item B<--hostname=>I<host>
Report tests as this host.
=item B<--strip=>I<prefix>
Remove I<prefix> (regexp) from test names. The prefix "check_" is always
removed before stripping other prefixes. Useful for trimming down overly
verbose Nagios test names, e.g. "check_postgres_database_size" to
"database_size".
=item B<--trends>
In addition to printing performance data in the status report (suitable for the
NCV/SPLITNCV xymond_rrd modules), send in a data report for
I<hostname>B<.trends>. This rrd module is more robust.
=item B<--help>
=item B<--version>
Print help text and version, and exit.
=back
=head1 SEE ALSO
xymon(7), xymon(1), xymoncmd(1), nagios3(8).
=head1 AUTHOR
Christoph Berg <myon@debian.org>
=head1 LICENSE AND COPYRIGHT
Copyright (c) Christoph Berg <myon@debian.org>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
=cut
|