Use of uninitialized value XXX in concatenation (.) or string (perl snmp)

Written by - 0 comments

Published on - Listed in Perl Linux


While I was working on a Perl script which uses Net::SNMP, I got the following error:

Need to query .1.3.6.1.4.1.7933.1.20.2.1.1.14.1.15
Odd number of elements in hash assignment at /usr/lib/perl5/vendor_perl/5.16.2/Net/SNMP.pm line 2278.
Use of uninitialized value $enclosure in concatenation (.) or string at ./myscriptpl line 288.

What I was doing in my perl script was this:

      print "Need to query $oid_base.2.1.1.14.1.$oidend\n"; # debug
      my @oidlist2 = ($oid_base.2.1.1.14.1.$oidend);
      my $response = $session->get_request(-varbindlist => \@oidlist2);
      my $enclosure = $$response{"$oid_base.2.1.1.14.1.$oidend"};

Now the issue is that I missed the fact that I can't just put multiple variables together like this. It works correctly in the "print" line, because there I have set everything as a string in double-quotes.
In the definition of oidlist2, I forgot to use the double-quotes - so the OID wasn't really a SNMP OID anymore, which caused the snmp request to fail.

Ti simply put the oidlist2 definition into double-quotes solved that issue:

      #print "Need to query $oid_base.2.1.1.14.1.$oidend\n"; # debug
      my @oidlist2 = ("$oid_base.2.1.1.14.1.$oidend");
      my $response = $session->get_request(-varbindlist => \@oidlist2);
      my $enclosure = $$response{"$oid_base.2.1.1.14.1.$oidend"};
      #print "This drive is in Enclosure: $enclosure\n"; # debug

On my research "perl snmp Use of uninitialized value in concatenation" I did not find a single website pointing me to the solution. So once I figured it out myself, I thought I'd share that.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder