snmpcheck gibt ausschliesslich Wert 0 aus

Begonnen von mahlzeit24/7, 28 Oktober 2013, 18:26:03

Vorheriges Thema - Nächstes Thema

mahlzeit24/7

in der console:

2013.10.29 00:14:16 5: PRESENCE_DoLocalFunctionScan: Samsung|{snmpCheck("192.168.2.1","0x0446658322ea")}|0
2013.10.29 00:14:16 5: Cmd: >{snmpCheck("192.168.2.1","0x0446658322ea")}<
2013.10.29 00:14:17 4: Connection accepted from telnet:127.0.0.1:40309
2013.10.29 00:14:17 5: Cmd: >{PRESENCE_ProcessLocalScan('Samsung|0|absent')}<
2013.10.29 00:14:17 5: PRESENCE_ProcessLocalScan: Samsung|0|absent
2013.10.29 00:14:17 5: Triggering Samsung (1 changes)
2013.10.29 00:14:17 5: Notify loop for Samsung absent
2013.10.29 00:14:17 4: eventTypes: PRESENCE Samsung absent -> absent



jetzt kam ein wenig mehr im log an:


2013.10.29 00:20:56 5: PRESENCE_DoLocalFunctionScan: Samsung|{snmpCheck("192.168.2.1","0x0446658322ea")}|0
2013.10.29 00:20:56 5: Cmd: >{snmpCheck("192.168.2.1","0x0446658322ea")}<
2013.10.29 00:20:56 3: $VAR1 = undef;

2013.10.29 00:20:56 3: $VAR1 = "Unable to resolve the UDP/IPv4 address \"\x{c0}\x{a8}\"";



2013.10.29 00:23:33 5: PRESENCE_DoLocalFunctionScan: Samsung|{snmpCheck("192.168.2.1","0x0446658322ea")}|0
2013.10.29 00:23:33 5: Cmd: >{snmpCheck("192.168.2.1","0x0446658322ea")}<
2013.10.29 00:23:34 3: $VAR1 = undef;

2013.10.29 00:23:34 3: $VAR1 = "Unable to resolve the UDP/IPv4 address \"\x{c0}\x{a8}\"";

2013.10.29 00:23:34 4: Connection accepted from telnet:127.0.0.1:40595
2013.10.29 00:23:34 5: Cmd: >{PRESENCE_ProcessLocalScan('Samsung|0|absent')}<
2013.10.29 00:23:34 5: PRESENCE_ProcessLocalScan: Samsung|0|absent
2013.10.29 00:23:34 5: Triggering Samsung (1 changes)
2013.10.29 00:23:34 5: Notify loop for Samsung absent
2013.10.29 00:23:34 4: eventTypes: PRESENCE Samsung absent -> absent



hier nochmal meine 99_myutils, evtzl hab ich da mist gepasted

package main;

use strict;
use warnings;
use POSIX;



# start with your own functions below this line
use Net::SNMP;
use Data::Dumper;

sub
snmpCheck($$)
{
  my ($airport,$client)= @_;

  my $community = "public";
  my $host = 192.168.2.1;
  my $oid = ".1.3.6.1.2.1.3.1.1.2";
  #my $oid = ".1.3.6.1.2.1.3.1.1.2.25.1.10.0.1";

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

  if( !defined($session) ) {
    return 0;
    return "Can't connect to host $host.";
  }

  my @snmpoids = ();

  my $response = $session->get_next_request($oid);
Log 3, Dumper $response;
  my @nextid = keys %$response;
  while ( $nextid[0] =~ m/^$oid/ ) {
    push( @snmpoids, $nextid[0] );

    $response = $session->get_next_request( $nextid[0] );
Log 3, Dumper $response;
    @nextid = keys %$response;
  }

  if( !defined($response = $session->get_request( @snmpoids ) ) ) {
    return 0;
  }

#Log 3, Dumper $response;


  foreach my $value (values %$response) {
    return 1 if( $value eq $client )
  }

  return 0;
}

# behind your last function, we need the following
1;

Bitte um verzeihung für evtl dummes anstellen, es sind halt die ersten versuche in fhem.....


HG
Frank

justme1968

die ip adresse bei $host muss in anführungszeichen.

gruss
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

mahlzeit24/7

Mensch Andre,    ::)

das hat den connectionknoten gelöst:

2013.10.29 00:34:41 4: Connection accepted from telnet:127.0.0.1:40946
2013.10.29 00:34:41 5: Cmd: >{PRESENCE_ProcessLocalScan('Handy1|0|present')}<
2013.10.29 00:34:41 5: PRESENCE_ProcessLocalScan: Handy1|0|present
2013.10.29 00:34:41 5: Triggering Handy1 (1 changes)
2013.10.29 00:34:41 5: Notify loop for Handy1 online
2013.10.29 00:34:41 4: eventTypes: PRESENCE Handy1 online -> online
2013.10.29 00:34:46 5: PRESENCE_DoLocalFunctionScan: Samsung|{snmpCheck("192.168.2.1","0x0446658322ea")}|0
2013.10.29 00:34:46 5: Cmd: >{snmpCheck("192.168.2.1","0x0446658322ea")}<
2013.10.29 00:34:46 3: $VAR1 = bless( {
                 '_translate' => 255,
                 '_security' => bless( {
                                         '_error' => undef,
                                         '_community' => 'public',
                                         '_version' => 0
                                       }, 'Net::SNMP::Security::Community' ),
                 '_transport_argv' => [
                                        '-hostname',
                                        '192.168.2.1',
                                        '-port',
                                        161
                                      ],
                 '_pdu' => undef,
                 '_callback' => undef,
                 '_nonblocking' => 0,
                 '_version' => 0,
                 '_transport' => bless( {
                                          '_dest_name' => '¡À¨',
                                          '_max_msg_size' => 1472,
                                          '_sock_name' => '',
                                          '_timeout' => '5',
                                          '_error' => undef,
                                          '_sock_hostname' => '',
                                          '_dest_hostname' => '192.168.2.1',
                                          '_socket' => bless( \*Symbol::GEN27224, 'IO::Socket' ),
                                          '_retries' => 1
                                        }, 'Net::SNMP::Transport::IPv4::UDP' ),
                 '_error' => undef,
                 '_context_engine_id' => undef,
                 '_context_name' => undef,
                 '_delay' => 0,
                 '_discovery_queue' => [],
                 '_hostname' => '192.168.2.1'
               }, 'Net::SNMP' );

2013.10.29 00:34:46 3: $VAR1 = '';

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.2' => '0x00089bc1b6eb'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.3' => '0x001dec01b63c'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.4' => '0x001422dd9c92'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.5' => '0x00262d05221a'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.6' => '0x002719fe4706'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.16' => '0x00d0b806f70b'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.17' => '0x001601c5f276'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.100' => '0x00216aa0b04c'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.101' => '0xd0e7823fe383'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.102' => '0x0025d3874943'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.108' => '0x109add0ba823'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.111' => '0x643150a4f93f'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.116' => '0x0446658322ea'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.132' => '0x3451c986313b'
        };

2013.10.29 00:34:46 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.3.2.192.168.2.2' => '192.168.2.2'
        };

2013.10.29 00:34:46 4: Connection accepted from telnet:127.0.0.1:40947
2013.10.29 00:34:46 5: Cmd: >{PRESENCE_ProcessLocalScan('Samsung|0|absent')}<
2013.10.29 00:34:46 5: PRESENCE_ProcessLocalScan: Samsung|0|absent
2013.10.29 00:34:46 5: Triggering Samsung (1 changes)
2013.10.29 00:34:46 5: Notify loop for Samsung absent
2013.10.29 00:34:46 4: eventTypes: PRESENCE Samsung absent -> absent
^C


frag mich nur, warum das nicht umschaltet?

HG
Frank

justme1968

den rest reparieren wie später... ich muss jetzt etwas schlafen :)

gute nacht
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

mahlzeit24/7

Ganz herzlichen Dank bis hierher und bis bald.

HG
Frank

justme1968

der nächste schritt wäre vor die foreach zeile einLog 3, "foreach"; ,nach der foreach zeile ein Log 3, ">$value< >$client<";und vor das letzte 'return 0' am ende einLog 3, "nicht gefunden";einzubauen.

gruss
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

mahlzeit24/7

Hi Andre,

ich hab gestern alles rausgehauen und abgestellt, weil nebenbei auch der ping gut am akku zog.

Eben wieder alles rein mit deinen Vorschlägen, aber das log hat nur folgenden output


2013.10.29 21:16:20 5: PRESENCE_DoLocalFunctionScan: Samsung|{snmpCheck("192.168.2.1","0x0446658322ea")}|0
2013.10.29 21:16:20 5: Cmd: >{snmpCheck("192.168.2.1","0x0446658322ea")}<
2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.2' => '0x00089bc1b6eb'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.3' => '0x001dec01b63c'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.4' => '0x001422dd9c92'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.5' => '0x00262d05221a'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.6' => '0x002719fe4706'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.16' => '0x00d0b806f70b'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.17' => '0x001601c5f276'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.100' => '0x00216aa0b04c'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.101' => '0xd0e7823fe383'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.102' => '0x0025d3874943'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.103' => '0x109add1dfcd1'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.104' => '0x7cc5374738c5'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.108' => '0x109add0ba823'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.111' => '0x643150a4f93f'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.116' => '0x0446658322ea'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.130' => '0x00262d05221a'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.2.2.192.168.2.132' => '0x3451c986313b'
        };

2013.10.29 21:16:20 3: $VAR1 = {
          '.1.3.6.1.2.1.3.1.1.3.2.192.168.2.2' => '192.168.2.2'
        };

2013.10.29 21:16:20 4: Connection accepted from telnet:127.0.0.1:39388
2013.10.29 21:16:20 5: Cmd: >{PRESENCE_ProcessLocalScan('Samsung|0|absent')}<
2013.10.29 21:16:20 5: PRESENCE_ProcessLocalScan: Samsung|0|absent
2013.10.29 21:16:20 5: Triggering Samsung (1 changes)
2013.10.29 21:16:20 5: Notify loop for Samsung absent
2013.10.29 21:16:20 4: eventTypes: PRESENCE Samsung absent -> absent


Im Anhang nochmal zur sicherheit meine 99_myutils.pm

herzliche grüße

PS: ping ist nicht wirklich ne alternative

mahlzeit24/7


mahlzeit24/7

wobei ich jetzt da wohl nen fehler drin hab....

syntax error at ./FHEM/99_myUtils.pm line 11, near ") {" Can't use global @_ in "my" at ./FHEM/99_myUtils.pm line 12, near "= @_" Can't use global @_ in "my" at ./FHEM/99_myUtils.pm line 19, near "= @_" syntax error at ./FHEM/99_myUtils.pm line 64, near "}"

mahlzeit24/7


mahlzeit24/7

Andre hat das Problem fixen können, ganz herzlichen  Dank dafür.

Ich habs jetzt etwa 2 Tage am Laufen und keine Fehler drin.

Wo jetzt genau das Problem lag ist uns noch nicht ganz klar, anbei das Codeschnipsel.

Herzliche Grüße

Frank

chiefjoejj

Sorry,
passt jetzt eigentlich nicht hierher, aber bin langsam am verzweifeln...
Könnte mich bitte jemand erhellen, wie ich eine "gängige" Mac-Adresse (z.B. 28:E1:4D:92:AD:D9) in das für die Abfrage notwendige Format (beginnend mit 0x) umrechnen kann? Hab schon Unzähliges probiert, komme aber auf keinen grünen Zweig..

justme1968

einfach alles aneinander hängen und kleinbuchstaben verwenden...

28:E1:4D:92:AD:D9 -> 0x28e14d92add9

gruss
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

chiefjoejj

Danke!
Dann war meine Vermutung zwar richtig, es funktioniert aber trotzdem nicht zuverlässig. Wenn ich mir das FHEM-Logfile ansehe, finde ich jede Menge Mac-Adressen der Geräte, die sich in meinem Netzwerk befinden (kabelgebunden und per WLan angebunden) und vom Script entsprechend erkannt bzw. abgefragt werden. Die Mac-Adresse meines iPhones jedoch, welches ebenfalls verbunden ist, wird trotzdem nicht angezeigt, obwohl es definitiv per WLan verbunden ist. Könnte es sein, dass es daran liegt, dass der AirPort Extreme zwar für das WLan zuständig ist, die DHCP-Funktion aber durch meinen Router (Fritzbox) übernommen wird? Jedenfalls sagt selbst das AirPort-Dienstprogramm, dass das iPhone mit der entsprechenden Mac-Adresse über den AirPort Extreme verbunden ist.

justme1968

wenn es mit mac adresse im aurpot diensprogramm auftaut sollte es auch per snmp sichtbar sein.

gruss
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968