Posts Tagged ‘perl’

Learning Perl with SNMP Part I

March 31st, 2009 by admin

Ok my first stab at it was great (snmp.pl)
#!/usr/bin/perl
$SNMP_GET_CMD = “snmpget -v1 -c public -Ovq”;
$SNMP_TARGET = “1.1.1.2″;
chomp($model = `${SNMP_GET_CMD} ${SNMP_TARGET} 1.3.6.1.2.1.1.3.0`);
chomp($serial = `${SNMP_GET_CMD} ${SNMP_TARGET} 1.3.6.1.2.1.1.4.0`);
$model =~ s/\”//g;      # Ditch the quotes.
$serial =~ s/\”//g;
print <<END;
APC UPS                         ${SNMP_TARGET}
Model: ${model}         Serial No: ${serial}
END
The output:
APC UPS                         1.1.1.2
Model: 33:17:35:52.07         Serial No: NOC 555-555-5555
Basically I’m using snmp-get from a command line [...]