Support IPv6 in ping monitor and others

This commit is contained in:
Jamie Cameron
2010-10-30 21:54:54 -07:00
parent 120ffa9357
commit 5ce0b222fc
5 changed files with 27 additions and 22 deletions

View File

@@ -2,19 +2,19 @@
sub get_dns_status
{
if (&has_command("nslookup")) {
if (&has_command("dig")) {
local $out;
&execute_command("dig \@".quotemeta($_[0]->{'server'})." ".
quotemeta($_[0]->{'host'}), undef, \$out, \$out);
return $out =~ /\Q$_[0]->{'host'}.\E\s+\S+\s+IN\s+A\s+\Q$_[0]->{'address'}\E/ ? { 'up' => 1 } : { 'up' => 0 };
}
elsif (&has_command("nslookup")) {
local $out;
local $cmd = "server $_[0]->{'server'}\n$_[0]->{'host'}\n";
&execute_command("nslookup", \$cmd, \$out, \$out);
return $out =~ /\Q$_[0]->{'address'}\E/ ? { 'up' => 1 }
: { 'up' => 0 };
}
elsif (&has_command("dig")) {
local $out;
&execute_command("dig \@".quotemeta($_[0]->{'server'})." ".
quotemeta($_[0]->{'host'}), undef, \$out, \$out);
return $out =~ /\Q$_[0]->{'host'}.\E\s+\S+\s+IN\s+A\s+\Q$_[0]->{'address'}\E/ ? { 'up' => 1 } : { 'up' => 0 };
}
else {
return { 'up' => - 1 };
}
@@ -36,7 +36,8 @@ sub parse_dns_dialog
{
&has_command("nslookup") || &has_command("dig") ||
&error($text{'dns_ecmds'});
gethostbyname($in{'server'}) || &error($text{'dns_eserver'});
&to_ipaddress($in{'server'}) || &to_ip6address($in{'server'}) ||
&error($text{'dns_eserver'});
$_[0]->{'server'} = $in{'server'};
$in{'host'} =~ /^[a-z0-9\.\-\_]+$/i || &error($text{'dns_ehost'});
$_[0]->{'host'} = $in{'host'};

View File

@@ -7,22 +7,25 @@ use Socket;
sub get_ping_status
{
local $wait = defined($_[0]->{'wait'}) ? $_[0]->{'wait'} : 5;
local $ip = inet_aton($_[0]->{'host'});
local $ip = &to_ipaddress($_[0]->{'host'}) ||
&to_ip6address($_[0]->{'host'});
return { 'up' => 0 } if (!$ip);
if ($config{'pinger'}) {
# Call a ping command
local $ipv6 = &to_ip6address($_[0]->{'host'}) &&
!&to_ipaddress($_[0]->{'host'});
if ($config{'pinger'} || $ipv6) {
# Call a ping command if configured, or if using IPv6 since the built-
# in code doesn't support it yet
local $cmd;
if ($config{'pinger'} eq "linux" &&
$gconfig{'os_type'} =~ /-linux$/) {
local $auto_pinger = $config{'pinger'} eq "linux" || !$config{'pinger'};
if ($auto_pinger && $gconfig{'os_type'} =~ /-linux$/) {
# Use linux command
$cmd = "ping -c 1 -w $wait";
$cmd = ($ipv6 ? "ping6" : "ping")." -c 1 -w $wait";
}
elsif ($config{'pinger'} eq "linux" &&
$gconfig{'os_type'} eq 'freebsd') {
elsif ($auto_pinger && $gconfig{'os_type'} eq 'freebsd') {
# Use FreeBSD command
$cmd = "ping -c 1 -W ".($wait * 1000);
$cmd = ($ipv6 ? "ping6" : "ping")." -c 1 -W ".($wait * 1000);
}
elsif ($config{'pinger'} eq "linux") {
elsif ($auto_pinger) {
# Don't know command for this OS
return { 'up' => - 1 };
}
@@ -53,7 +56,7 @@ print &ui_table_row($text{'ping_wait'},
sub parse_ping_dialog
{
#$config{'ping_cmd'} || &error($text{'ping_econfig'});
&check_ipaddress($in{'host'}) || gethostbyname($in{'host'}) ||
&to_ipaddress($in{'host'}) || &to_ip6address($in{'host'}) ||
&error($text{'ping_ehost'});
$in{'wait'} =~ /^(\d*\.)?\d+$/ || &error($text{'ping_ewait'});
$_[0]->{'host'} = $in{'host'};

View File

@@ -86,7 +86,8 @@ if ($in{'host_def'}) {
delete($_[0]->{'host'});
}
else {
gethostbyname($in{'host'}) || &error($text{'query_ehost'});
&to_ipaddress($in{'host'}) || &to_ip6address($in{'host'}) ||
&error($text{'query_ehost'});
$_[0]->{'host'} = $in{'host'};
}

View File

@@ -46,7 +46,7 @@ if ($in{'smtp_def'}) {
}
else {
if (!$in{'from_def'}) {
gethostbyname($in{'smtp'}) || &check_ipaddress($in{'smtp'}) ||
&to_ipaddress($in{'smtp'}) || &to_ip6address($in{'smtp'}) ||
&error($text{'sched_esmtp'});
}
$config{'sched_smtp'} = $in{'smtp'};

View File

@@ -36,7 +36,7 @@ print &ui_table_row($text{'tcp_alarm'},
sub parse_tcp_dialog
{
&check_ipaddress($in{'host'}) || gethostbyname($in{'host'}) ||
&to_ipaddress($in{'host'}) || &to_ip6address($in{'host'}) ||
&error($text{'tcp_ehost'});
$_[0]->{'host'} = $in{'host'};