Perl extension NetSNMP::ASN does not return values in the request, where Exportable constants- ASN_IPADDRESS

"Drovalev R.N." <[email protected]>
Newsgroups gmane.network.net-snmp.devel
Message-ID <[email protected]>
Hello!

 

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.

 

Perl extension NetSNMP::ASN does not return values in the request, where
Exportable constants - ASN_IPADDRESS, but return values other any types is
very good!

Why?

 

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

 

But

 

#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

 

 

 

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.

 

--- code ---

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-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
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.