GNU/LinuxNovember 16, 2008 3:44 pm

On Ubuntu, you can use perl to get the value of specific SNMP object using perl module Net::SNMP. You have to install libnet-snmp-perl package.

These lines below are example how to do it on perl :

——————————————————————————————-

#!/usr/bin/perl
use Net::SNMP;

# requires a hostname and a community string as its arguments
($session,$error) = Net::SNMP->session(Hostname => $ARGV[0],
                                       Community => $ARGV[1]);

die "session error: $error" unless ($session);

#  1.3.6.1.4.1.2021.9.1.5.1  
$result = $session->get_request("1.3.6.1.4.1.2021.9.1.5.1");

die "request error: ".$session->error unless (defined $result);

$session->close;

print "Disk Percent 1: ".$result->{"1.3.6.1.4.1.2021.9.1.5.1"}."\n";
 

——————————————————————————————–

Change the permission to 755 and execute using command : <script-name> <host> <community-name>

For example : getHDUsage.pl localhost heaven

 

GNU/Linux 3:39 pm

We can query the value of total disk space usage on GNU/Linux using snmpget tools. The tools can be read SNMP v1 or v2c. On SNMP v1, disk space usage OID defined on UCD-SNMP-MIB with value : 1.3.6.1.4.1.2021.9.1.5. On SNMP v2c, it defined with OID : UCD-SNMP-MIB::dskTotal

To read the total disk space usage using SNMP v1, you can execute command below :

snmpget -v1 -Cf -c heaven localhost 1.3.6.1.4.1.2021.9.1.5.1

To read the total disk space usage using SNMP v1, you can execute command below :

snmpget -v2c -Cf -c heaven localhost UCD-SNMP-MIB::dskTotal.1

Note that : heaven is a community name you set on snmpd.conf