Add scripts to ping other hosts

tags/zabbix-agent-addons-0.2.62-1
Daniel Berteaud 5 years ago
parent 499a46a8ba
commit 3bec374bb2
  1. 1
      zabbix-agent-addons.spec
  2. 6
      zabbix_conf/icmp.conf
  3. 45
      zabbix_scripts/check_icmp_sudo

@ -22,6 +22,7 @@ Requires: perl(POSIX)
Requires: perl(MIME::Base64)
Requires: perl(File::Which)
Requires: perl(Config::Simple)
Requires: fping
%if ! 0%{?_without_selinux}
Requires: policycoreutils
BuildRequires: selinux-policy-devel

@ -0,0 +1,6 @@
# net.icmp takes two args. The host to ping (either an IP or a host name), and one of
# * all: returns info in JSON format
# * latency: returns latency in seconds. Floating number
# * respond: returns 0 if no response where received, 1 otherwise
# * loss: returns % of packet loss. Floating number
UserParameter=net.icmp[*],/usr/bin/sudo /var/lib/zabbix/bin/check_icmp_sudo $1 --info=$2

@ -0,0 +1,45 @@
#!/usr/bin/perl -w
use warnings;
use strict;
use File::Which;
use Getopt::Long;
use JSON;
my $fping = which('fping');
unless ($fping){
die "ZBX_NOTSUPPOTED\n";
}
my $info = 'all';
my $pretty = 0;
my @valid_info = qw(all respond latency loss);
my $host = $ARGV[0];
GetOptions(
'info=s' => \$info,
'pretty' => \$pretty
);
unless (grep { $info eq $_ } @valid_info){
die "Usage: $0 [--info=<respond|latency|loss>] host\n";
}
my $ping = qx($fping -c 5 -p 10 -q $host 2>&1);
# Output looks like 10.29.254.2 : xmt/rcv/%loss = 5/5/0%, min/avg/max = 1.42/1.65/1.90
if ($ping =~ m|^$host : xmt/rcv/%loss = 5/(\d)/(\d+(?:\.\d+)?)%(?:, min/avg/max = (?:\d+(?:\.\d+)?)/(\d+(\.\d+))/(?:\d+(?:\.\d+)?))?$|){
my $stat = {
respond => ($1 > 0) ? 1 : 0,
loss => $2 + 0,
latency => (defined $3) ? $3 / 1000 : 0
};
if ($info ne 'all'){
print $stat->{$info} . "\n";
} else {
print to_json($stat, { pretty => $pretty }) . "\n";
}
} else {
die "ZBX_NOTSUPPOTED\n";
}
exit 0;
Loading…
Cancel
Save