ASN_IPADDRESS does not return values in the request.

Дровалев Р.Н. <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hello, all!

 

There is a need to return the value of the ip address when requesting a
specific OID. 

It is necessary to emulate the snmp device.

Implemented via perl, which I am new to.

 

1.       If in the file -  my $string_ASN = ASN_OCTET_STR;

# snmpget -c public -v 1 192.168.3.102 1.3.6.1.4.1.318.2.1.2.1.2.1

Iso.1.3.6.1.4.1.318.2.1.2.1.2.1 = STRING: "192.168.3.7"

 

2.  If in the file -  my $string_ASN = ASN_IPADDRESS;

#snmpget -c public -v 1 192.168.3.102 1.3.6.1.4.1.318.2.1.2.1.2.1

Reason: (noSuchName) There is no such variable name in this MIB.

Failed object: iso.1.3.6.1.4.1.318.2.1.2.1.2.1

 

 

Why isn't the ip address returned? How to correctly assign ip address in
perl for ASN_IPADDRESS?

Where is my mistake? Please tell me.

Thanks.

 

#systemctl status snmpd (p.#2)

snmpd.service - Simple Network Management Protocol (SNMP) Daemon.

     Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor
preset: enabled)

     Active: active (running) since Fri 2020-09-11 14:24:24 MSK; 5min ago

    Process: 30895 ExecStartPre=/bin/mkdir -p /var/run/agentx (code=exited,
status=0/SUCCESS)

   Main PID: 30905 (snmpd)

      Tasks: 1 (limit: 1075)

     Memory: 19.6M

     CGroup: /system.slice/snmpd.service

             L-30905 /usr/sbin/snmpd -LOw -u Debian-snmp -g Debian-snmp -I
-smux mteTrigger mteTriggerConf -f -p /run/snmpd.pid

 

Sep 11 14:24:24 snmpd systemd[1]: Starting Simple Network Management
Protocol (SNMP) Daemon....

Sep 11 14:24:24 snmpd systemd[1]: Started Simple Network Management Protocol
(SNMP) Daemon..

Sep 11 14:24:26 snmpd snmpd[30905]: IP address of 11 bytes passed to
setValue with ASN_IPADDRESS

 

Enable the file in snmpd.conf:

perl do "/usr/share/snmp/2.1.2.1.pl";

 

Example my 2.1.2.1.pl.pl file :

#!/usr/bin/perl

use NetSNMP::agent (':all');

use NetSNMP::ASN qw(ASN_IPADDRESS ASN_OCTET_STR);

 

sub hello_handler {

  my ($handler, $registration_info, $request_info, $requests) = @_;

  my $request;

  my $string_value = "192.168.3.7";

 

  my $string_ASN = ASN_OCTET_STR;

  #my $string_ASN = ASN_IPADDRESS;

 

  for($request = $requests; $request; $request = $request->next()) {

    my $oid = $request->getOID();

    if ($request_info->getMode() == MODE_GET) {

      if ($oid == new NetSNMP::OID(".1.3.6.1.4.1.318.2.1.2.1.2.1")) {

        $request->setValue($string_ASN, ($string_value));

      }

      elsif ($oid == new NetSNMP::OID(".1.3.6.1.4.1.318.2.1.2.1.2.1")) {

        $request->setValue($string_ASN, ($string_value));

      }

    } elsif ($request_info->getMode() == MODE_GETNEXT) {

      if ($oid == new NetSNMP::OID(".1.3.6.1.4.1.318.2.1.2.1.2.1")) {

        $request->setOID(".1.3.6.1.4.1.318.2.1.2.1.2.2");

        $request->setValue($string_ASN, ($string_value));

      }

      elsif ($oid < new NetSNMP::OID(".1.3.6.1.4.1.318.2.1.2.1.2.1")) {

        $request->setOID(".1.3.6.1.4.1.318.2.1.2.1.2.1");

        $request->setValue($string_ASN, ($string_value));

      }

    }

  }

}

my $agent = new NetSNMP::agent();

$agent->register(".1.3.6.1.4.1.318.2.1.2.1.2.1",
".1.3.6.1.4.1.318.2.1.2.1.2.1",

                 \&hello_handler);

 

P.S. My task is to return the address of the computer that makes the request
for this OID. But at least just returned an arbitrary address!

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.