Problem Timeouts in PRESENCE werden durch ein anderes Modul ausgelöst [gelöst]

Begonnen von Strida, 10 Januar 2016, 00:47:41

Vorheriges Thema - Nächstes Thema

Strida

PRESENCE mit snmpCheck (siehe unten) läuft so lange einwandfrei, bis ich ein anderes Modul (WakeOnLan - siehe ebenfalls unten) anstoße:


2016.01.10 00:23:28 1: WakeOnLan(0): perl: warning: Setting locale failed.perl: warning: Please check that your locale settings: LANGUAGE = "en_US:en", LC_ALL = (unset), LC_TIME = "de_DE.UTF-8", LC_MONETARY = "de_DE.UTF-8", LC_ADDRESS = "de_DE.UTF-8", LC_TELEPHONE = "de_DE.UTF-8", LC_NAME = "de_DE.UTF-8", LC_MEASUREMENT = "de_DE.UTF-8", LC_IDENTIFICATION = "de_DE.UTF-8", LC_NUMERIC = "de_DE.UTF-8", LC_PAPER = "de_DE.UTF-8", LANG = "en_US.UTF-8"    are supported and installed on your system.perl: warning: Falling back to the standard locale ("C").Sending magic packet to 255.255.255.255:9 with xx:xx:xx:xx:xx:XX
2016.01.10 00:23:28 3: Notify.WOL.DiskStation.Up return value: WakeOnLan(0): perl: warning: Setting locale failed.perl: warning: Please check that your locale settings: LANGUAGE = "en_US:en", LC_ALL = (unset), LC_TIME = "de_DE.UTF-8", LC_MONETARY = "de_DE.UTF-8", LC_ADDRESS = "de_DE.UTF-8", LC_TELEPHONE = "de_DE.UTF-8", LC_NAME = "de_DE.UTF-8", LC_MEASUREMENT = "de_DE.UTF-8", LC_IDENTIFICATION = "de_DE.UTF-8", LC_NUMERIC = "de_DE.UTF-8", LC_PAPER = "de_DE.UTF-8", LANG = "en_US.UTF-8"    are supported and installed on your system.perl: warning: Falling back to the standard locale ("C").Sending magic packet to 255.255.255.255:9 with xx:xx:xx:xx:xx:xx
2016.01.10 00:27:08 1: Timeout for PRESENCE_DoLocalFunctionScan reached, terminated process 28363
2016.01.10 00:27:08 2: PRESENCE (Pres.GNote4) - device could not be checked (retrying in 10 seconds)
2016.01.10 00:27:08 1: Timeout for PRESENCE_DoLocalFunctionScan reached, terminated process 28364
2016.01.10 00:27:08 2: PRESENCE (Pres.iPhone) - device could not be checked (retrying in 10 seconds)
2016.01.10 00:27:18 2: PRESENCE (Pres.GNote4) - check returned a valid result after 1 unsuccesful retry
2016.01.10 00:27:18 2: PRESENCE (Pres.iPhone) - check returned a valid result after 1 unsuccesful retry

... die Timeouts kommen im Abstand von ca. 10 Sekunden und füllen das Logfile ordentlich an.

Diese Timeouts kommen immer - nachvollziehbar - nach dem Aufruf von WakeOnLan und verschwinden bei einem Neustart.

Warum im WakeOnLan-Modul die Warnung zur locale kommt, kann ich leider nicht nachvollziehen und noch viel weniger, dass das völlig unabhängige Modul snmpCheck davon betroffen wird. Selbiges läuft bis zum ersten Ausführen von WOL auch einwandfrei.

So sieht das WOL-Modul aus:
##############################################
# $Id: myUtilsTemplate.pm 7570 2015-01-14 18:31:44Z  $
#
# Save this file as 99_myUtils.pm, and create your own functions in the new
# file. They are then available in every Perl expression.

package main;

use strict;
use warnings;
use POSIX;

sub
WakeOnLan_Initialize($$)
{
  my ($hash) = @_;
}

# Enter you functions below _this_ line.

######## WakeOnLan von Ubuntu with  ############
sub
WakeOnLan
{
my $mac = shift;
my $ret = "";

$SIG{CHLD}="DEFAULT"; # Otherwise there is an error: Can't ignore signal CHLD
$ret .= qx( wakeonlan $mac 2>&1 );
my $exitcode = $?;
#my $exitcode = $? >> 8;
$ret =~ s,[\r\n]*,,g;    # remove CR from return-string

Log 1, "WakeOnLan($exitcode): $ret" ;
return "WakeOnLan($exitcode): $ret" ;
}

1;


und so mein snmpCheck:

##############################################
# $Id: myUtilsTemplate.pm 7580 2016-01-05 23:13:00Z strida $
#
# Requires libnet-snmp-perl to be installed.

package main;

use strict;
use warnings;
use POSIX;

use Net::SNMP;

sub
snmpCheckIpMac_Initialize($$)
{
  my ($hash) = @_;
}

# Enter you functions below _this_ line.

sub
snmpCheckIpMac( $$$ )
{
my ( $airport, $clientIp, $clientMac )= @_;

my $community = "public";
my $host = $airport;
# snmpwalk -Os -c public -v2c 192.168.1.1 | grep iso.3.6.1.2.1.3.1.1.2
#         iso.3.6.1.2.1.3.1.1.2.2.1.YY.YY.YY.YY = Hex-STRING: xx xx xx xx xx xx # WAN Interface
#         iso.3.6.1.2.1.3.1.1.2.7.1.192.168.1.2 = Hex-STRING: xx xx xx xx xx xx # LAN Interface
my $oid = ".1.3.6.1.2.1.3.1.1.2.7.1"; # LAN IP-Adresses
# my $oid = ".1.3.6.1.2.1.3.1.1.2"; # ALL IP-Adresses (use if the above OID is not working or you want to check if your router is present)
my $oidLen = 1 + length $oid;

my ( $session, $error ) = Net::SNMP->session(
-hostname  => $host,
-community => $community,
-port      => 161,
-version   => 1
);

if( !defined( $session ) ) {
warn "snmpCheck: Could not connect to host $host.\n";
Log 1, "snmpCheck: Could not connect to host $host." ;
return 0;
# } else {
# print "Connected to $host.\n";
}

my $response = $session->get_next_request( $oid );
my @nextid = keys %$response;
## print "          $oid \n";
while ( @nextid && $nextid[0] && $nextid[0] =~ m/^$oid/ ) {
my $currIp = substr $nextid[0], $oidLen;
if( $currIp eq $clientIp ) {
# Experimental: my @currMacAddr = values %$session->get_request( $nextid[0] );
my $currMacAddrReq = $session->get_request( $nextid[0] );
my @currMacAddr    = values %$currMacAddrReq;
## print "Checking: $currIp against $currMacAddr[0]\n";
if( lc $currMacAddr[0] eq lc "0x".$clientMac ) {
# print "snmpCheckIpMac: $clientIp online with proper MAC-address.\n";
# Log 2, "snmpCheckIpMac: $clientIp online with proper MAC-address.";
return 1;
}
# This is either a bad configuration or some sort of attack:
# warn "snmpCheckIpMac: ATTENTION $clientIp MAC missmatch: 0x$clientMac != $currMacAddr[0].\n";
Log 1, "snmpCheckIpMac: ATTENTION $clientIp MAC missmatch: 0x$clientMac != $currMacAddr[0].";
return 0;
}
## print "Ignoring: $nextid[0] => $currIp\n";
$response = $session->get_next_request( $nextid[0] );
@nextid = keys %$response;
}

# warn "snmpCheckIpMac: $clientIp NOT found.\n";
        # Log 2, "snmpCheckIpMac: $clientIp NOT found.";
        return 0;
}

1;


Strida

Die Perl-Warnung zur Locale konnte ich selbst beheben. Da mein Server in englischer Sprache installiert war, mussten noch die deutschen Definitionen erstellt werden:

sudo locale-gen de_DE.UTF-8

Die Timeouts in PRESENCE nach dem Aufruf von dem WOL bleiben leider:

2016.01.10 20:30:45 3: CUL_HM set Schalter...... statusRequest
2016.01.10 20:32:14 1: WakeOnLan(0): Sending magic packet to 255.255.255.255:9 with xx:xx:xx:xx:xx:xx
2016.01.10 20:32:14 3: Notify.WOL.DiskStation.Up return value: WakeOnLan(0): Sending magic packet to 255.255.255.255:9 with xx:xx:xx:xx:xx:xx
2016.01.10 20:32:29 1: WakeOnLan(0): Sending magic packet to 255.255.255.255:9 with xx:xx:xx:xx:xx:xx
2016.01.10 20:32:29 3: Notify.WOL.DiskStation.Up return value: WakeOnLan(0): Sending magic packet to 255.255.255.255:9 with xx:xx:xx:xx:xx:xx
2016.01.10 20:34:31 1: Timeout for PRESENCE_DoLocalFunctionScan reached, terminated process 11704
2016.01.10 20:34:31 2: PRESENCE (Pres.GNote4) - device could not be checked (retrying in 10 seconds)
2016.01.10 20:34:31 1: Timeout for PRESENCE_DoLocalFunctionScan reached, terminated process 11705
2016.01.10 20:34:31 2: PRESENCE (Pres.iPhone) - device could not be checked (retrying in 10 seconds)
2016.01.10 20:34:41 2: PRESENCE (Pres.GNote4) - check returned a valid result after 1 unsuccesful retry
2016.01.10 20:34:41 2: PRESENCE (Pres.iPhone) - check returned a valid result after 1 unsuccesful retry
2016.01.10 20:35:00 3: CUL_HM set Dimmer.....

Strida

Lösung:

Nachdem /usr/bin/wakeonlan ein Perl-Script ist, das von meinem Modul (oben) aufgerufen wird, habe ich die wesentlichen Teile direkt in ein neues Modul übernommen:

################################################################################
# $Id: 99_WakeOnLanJpo.pm 7570 2016-01-10 21:30:00Z strida $
#

package main;

use strict;
use warnings;
use POSIX;
use Net::hostent;
use Socket;

sub
WakeOnLanJpo_Initialize($$)
{
  my ($hash) = @_;
}

my $DEFAULT_IP      = '255.255.255.255';
my $DEFAULT_PORT    = getservbyname('discard', 'udp');

######## WakeOnLanJpo based on the wakeonlan perl script #######################
######## located as /usr/bin/wakeonlan within ubuntu     #######################
sub
WakeOnLanJpo
{
my $host    = shift;
my $ipaddr  = $DEFAULT_IP;
my $port    = $DEFAULT_PORT;

my ($raddr, $them, $proto);
my ($hwaddr, $hwaddr_re, $pkt);

# get the hardware address (ethernet address)

$hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6);
if ($host =~ m/^$hwaddr_re$/) {
$hwaddr = $host;
} else {
Log 1, "WakeOnLanJpo: Bad hardwareaddress $host";
return -1;
}

# Generate magic sequence

foreach (split /:/, $hwaddr) {
$pkt .= chr(hex($_));
}
$pkt = chr(0xFF) x 6 . $pkt x 16;

# Allocate socket and send packet

$raddr = gethostbyname($ipaddr)->addr;
$them = pack_sockaddr_in($port, $raddr);
$proto = getprotobyname('udp');

socket(S, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!";
setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $!";

#print "Sending magic packet to $ipaddr:$port with $hwaddr\n";

send(S, $pkt, 0, $them) or die "send : $!";
close S;

Log 2, "WakeOnLanJpo: sent magic packet to $ipaddr:$port with $hwaddr";

return 0;
}

1;


Der positive Nebeneffekt ist, dass man das entsprechende ubuntu packet nicht mehr benötigt und das Modul wahrscheinlich auf allen Plattformen wie OpenWRT laufen müsste.

Leider bleibt die Frage, wie ein Aufruf eines externen Perl-Scripts ein anderes Modul zu einem Timeout bringt?