mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 01:46:08 +00:00
98_ping: Add attribute for minimum fails before reporting (minFailCount)
git-svn-id: https://svn.fhem.de/fhem/trunk@10692 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
de16994950
commit
c56ad3a549
@ -1,5 +1,7 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- feature: 98_ping: Add attribute for minimum fails before reporting
|
||||||
|
(minFailCount)
|
||||||
- bugfix: PRESENCE: fix log warning "use of uninitialized value ..." when
|
- bugfix: PRESENCE: fix log warning "use of uninitialized value ..." when
|
||||||
using power set command without any argument.
|
using power set command without any argument.
|
||||||
- added: 60_allergy: Allergy forecast data for Germany
|
- added: 60_allergy: Allergy forecast data for Germany
|
||||||
|
@ -41,7 +41,7 @@ sub ping_Initialize($)
|
|||||||
$hash->{DefFn} = "ping_Define";
|
$hash->{DefFn} = "ping_Define";
|
||||||
$hash->{UndefFn} = "ping_Undefine";
|
$hash->{UndefFn} = "ping_Undefine";
|
||||||
$hash->{AttrFn} = "ping_Attr";
|
$hash->{AttrFn} = "ping_Attr";
|
||||||
$hash->{AttrList} = "disable:0,1 checkInterval ".$readingFnAttributes;
|
$hash->{AttrList} = "disable:1 checkInterval minFailCount ".$readingFnAttributes;
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -61,11 +61,14 @@ sub ping_Define($$)
|
|||||||
$hash->{HOST} = $host;
|
$hash->{HOST} = $host;
|
||||||
$hash->{MODE} = lc($mode);
|
$hash->{MODE} = lc($mode);
|
||||||
$hash->{TIMEOUT} = $timeout;
|
$hash->{TIMEOUT} = $timeout;
|
||||||
|
$hash->{FAILCOUNT} = 0;
|
||||||
|
readingsSingleUpdate($hash, "state", "Initialized", 1);
|
||||||
|
|
||||||
return "ERROR: mode must be one of tcp,udp,icmp" if ($hash->{MODE} !~ "tcp|udp|icmp");
|
return "ERROR: mode must be one of tcp,udp,icmp" if ($hash->{MODE} !~ "tcp|udp|icmp");
|
||||||
return "ERROR: timeout must be 0 or higher." if (($hash->{TIMEOUT} !~ /^\d*$/) || ($hash->{TIMEOUT} < 0));
|
return "ERROR: timeout must be 0 or higher." if (($hash->{TIMEOUT} !~ /^\d*$/) || ($hash->{TIMEOUT} < 0));
|
||||||
|
|
||||||
$attr{$name}{"checkInterval"} = 10 if (!defined($attr{$name}{"checkInterval"}));
|
$attr{$name}{"checkInterval"} = 10 if (!defined($attr{$name}{"checkInterval"}));
|
||||||
|
$attr{$name}{"event-on-change-reading"} = "state" if (!defined($attr{$name}{"event-on-change-reading"}));
|
||||||
|
|
||||||
ping_State($hash);
|
ping_State($hash);
|
||||||
|
|
||||||
@ -90,6 +93,8 @@ sub ping_Attr($$$$) {
|
|||||||
|
|
||||||
Log3 ($hash, 5, "$hash->{NAME}_Attr: Attr $attribute; Value $value");
|
Log3 ($hash, 5, "$hash->{NAME}_Attr: Attr $attribute; Value $value");
|
||||||
|
|
||||||
|
if ($command eq "set") {
|
||||||
|
|
||||||
if ($attribute eq "checkInterval")
|
if ($attribute eq "checkInterval")
|
||||||
{
|
{
|
||||||
if (($value !~ /^\d*$/) || ($value < 5))
|
if (($value !~ /^\d*$/) || ($value < 5))
|
||||||
@ -111,6 +116,7 @@ sub ping_Attr($$$$) {
|
|||||||
readingsSingleUpdate($hash, "state", "Initialized", 1);
|
readingsSingleUpdate($hash, "state", "Initialized", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -127,18 +133,26 @@ sub ping_State(@)
|
|||||||
Log3 ( $hash, 5, "$hash->{NAME}_State: Executing ping");
|
Log3 ( $hash, 5, "$hash->{NAME}_State: Executing ping");
|
||||||
|
|
||||||
# check via ping
|
# check via ping
|
||||||
my $pingstatus = "unreachable";
|
|
||||||
my $p;
|
my $p;
|
||||||
$p = Net::Ping->new($hash->{MODE});
|
$p = Net::Ping->new($hash->{MODE});
|
||||||
|
|
||||||
my $alive = $p->ping($hash->{HOST}, $hash->{TIMEOUT});
|
my $alive = $p->ping($hash->{HOST}, $hash->{TIMEOUT});
|
||||||
$p->close();
|
$p->close();
|
||||||
$pingstatus = "ok" if $alive;
|
|
||||||
|
|
||||||
# And update state
|
if ($alive) {
|
||||||
readingsSingleUpdate($hash, "state", $pingstatus, 1);
|
# State is ok
|
||||||
|
$hash->{FAILCOUNT} = 0;
|
||||||
|
readingsSingleUpdate($hash, "state", "ok", 1);
|
||||||
|
} else {
|
||||||
|
# Increment failcount and report unreachable if over limit
|
||||||
|
$hash->{FAILCOUNT} += 1;
|
||||||
|
if ($hash->{FAILCOUNT} >= AttrVal($hash->{NAME}, "minFailCount", 1)) {
|
||||||
|
readingsSingleUpdate($hash, "state", "unreachable", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Check state every X seconds
|
# Check state every X seconds
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(gettimeofday() + AttrVal($hash->{NAME}, "checkInterval", "10"), "ping_State", $hash, 0);
|
InternalTimer(gettimeofday() + AttrVal($hash->{NAME}, "checkInterval", "10"), "ping_State", $hash, 0);
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -181,6 +195,10 @@ sub ping_State(@)
|
|||||||
<b>checkInterval</b><br/>
|
<b>checkInterval</b><br/>
|
||||||
Default: 10s. Time after the bridge connection is re-checked.
|
Default: 10s. Time after the bridge connection is re-checked.
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>minFailCount</b><br/>
|
||||||
|
Default: 1. Number of failures before reporting "unreachable".
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user