diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index e2a120f61d..fee48fe32e 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2013-10-09 Junichi Satoh + + * lib/PandoraFMS/Tools.pm: Fixed ping monitoring failure on NetBSD. + Contributed by Hiroki SHIMIZU. Thanks! + 2013-10-08 Junichi Satoh * pandora_server_installer: Added p5-JSON to description for FreeBSD. diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index b3a3fbbcec..15ca4e04d1 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -702,6 +702,9 @@ sub free_mem { $free_mem = $pages_free * $page_size / 1024; } + elsif ($OSNAME eq "netbsd"){ + $free_mem = `cat /proc/meminfo | grep MemFree | awk '{ print \$2 }'`; + } # by default LINUX calls else { $free_mem = `free | grep Mem | awk '{ print \$4 }'`; @@ -808,6 +811,24 @@ sub pandora_ping ($$$$) { } return 0; } + + elsif ($OSNAME eq "netbsd"){ + my $ping_command = "ping -w $timeout"; + + if ($host =~ /\d+:|:\d+/ ) { + $ping_command = "ping6"; + } + + # Note: timeout(-w) option is not implemented in ping6. + # 'networktimeout' is not used by ping6 on NetBSD. + + # Ping the host + `$ping_command -q -n -c $retries $host >/dev/null 2>&1`; + if ($? == 0) { + return 1; + } + return 0; + } # by default LINUX calls else { @@ -918,6 +939,30 @@ sub pandora_ping_latency ($$$$) { return undef unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); return $2; } + + elsif ($OSNAME eq "netbsd"){ + my $ping_command = "ping -w $timeout"; + + if ($host =~ /\d+:|:\d+/ ) { + $ping_command = "ping6"; + } + + # Note: timeout(-w) option is not implemented in ping6. + # timeout(-w) and waittime(-W) options in ping are not the same as + # Linux. On latency, there are no way to set timeout. + # 'networktimeout' is not used on NetBSD. + + # Ping the host + my @output = `$ping_command -q -n -c $retries $host >/dev/null 2>&1`; + + # Something went wrong + return undef in ($? != 0); + + # Parse the output + my $stats = pop (@output); + return undef unless ($stats =~ m/([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) +ms/); + return $2; + } # by default LINUX calls else { @@ -1203,3 +1248,4 @@ sub valid_regex ($) { 1; __END__ +