ping.pl ipv6 support

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
rav
Posts: 1
Joined: Sun Sep 20, 2015 6:26 pm

ping.pl ipv6 support

Post by rav »

Hello guys, I just recently installed cacti and noticed the default ping script doesn't have support for ipv6. It just calls ping and that's it.

I modified it and would like to share it. If someone could make use of it or "fix" it if the way I have it is not the best... Please do so, I would love to see the change added to the main script.

Code: Select all

#!/usr/bin/perl

# take care for tcp:hostname or TCP:ip@
$host = $ARGV[0];
$host =~ s/tcp:/$1/gis;
$cmd  = ping;

# Check if host address is enclosed in brackets.
# If it is, remove brackets and set cmd to ping6.
if ($host =~ m/^\[.*\]$/) {
	$host =~ s/^\[(.*)\]$/$1/g;
	$cmd = ping6;
}

# old linux version use "icmp_seq"
# newer use "icmp_req" instead
open(PROCESS, "$cmd -c 1 $host | grep 'icmp_[s|r]eq' | grep time |");
$ping = <PROCESS>;
close(PROCESS);
$ping =~ m/(.*time=)(.*) (ms|usec)/;

if ($2 == "") {
	print "U"; 		# avoid cacti errors, but do not fake rrdtool stats
}elsif ($3 eq "usec") {
	print $2/1000;	# re-calculate in units of "ms"
}else{
	print $2;
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest