[AGENT++] Get request with multiple OID
Cristian Saavedra
cristianpsg at gmail.com
Thu May 1 19:02:46 CEST 2014
Hi,
I'm trying to get multiple values with one single get request, but I
noticed that if one of the variables is incorrect I'll get an error even if
the other variables are good. I was expecting to get a value for the good
ones and an error for the other.
There is any way to achieve this in a single get? or do I need to do the
get request one by one?
Below is the code I was testing, is failing when doing the snmp.get call
Thanks.
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "snmp_pp/snmp_pp.h"
#define SYSDESCR "1.3.6.1.2.1.1.1.0" // Object ID for
system descriptor
#define SYSOBJECTID "1.3.6.1.2.1.1.1.0" // Object ID for
system object ID
#define SYSUPTIME "1.3.6.1.2.1.1.1.0" // Object ID for
system up time
#define SYSCONTACT "1.3.6.1.2.1.1.1.0" // Object ID for
system contact
#define SYSNAME "1.3.6.1.2.1.1.1.0" // Object ID for
system name
#define SYSLOCATION "1.3.6.1.2.1.1.1.0" // Object ID for
system location
#define SYSSERVICES "1.3.6.1.4.1.458.113.1.2.1.1.2.1.6.0"
using namespace std;
int main()
{
int status;
// return status
CTarget ctarget( (IpAddress) "127.0.0.1"); // SNMP++ v1 target
Vb vb[7];
// a vb for each object to get
Pdu pdu; //
SNMP++ PDU
//-------[ Construct a SNMP++ SNMP Object
]---------------------------------------
Snmp snmp( status); // Create a
SNMP++ session
if ( status != SNMP_CLASS_SUCCESS) { // check creation status
cout << snmp.error_msg( status); // if fail, print
error string
return 0; }
//-------[ build up the vbs to
get]-----------------------------------------------------------------
vb[0].set_oid( SYSDESCR);
vb[1].set_oid( SYSOBJECTID);
vb[2].set_oid( SYSUPTIME);
vb[3].set_oid(SYSCONTACT);
vb[4].set_oid( SYSNAME);
vb[5].set_oid( SYSLOCATION);
vb[6].set_oid( SYSSERVICES);
//----[ append all the vbs to the pdu
]-----------------------------------------------------
for ( int z=0;z<7;z++)
pdu += vb[z];
//-------[ Invoke a SNMP++ Get
]-------------------------------------------------------
if ( (status = snmp.get( pdu, ctarget)) != SNMP_CLASS_SUCCESS)
cout << snmp.error_msg( status);
else {
pdu.get_vblist( vb,7); //
extract the variable bindings
for ( int w=0;w<7;w++)
cout << vb[w].get_printable_value() << "\n"; } // print out
the value
}
Best Regards,
Cristian Saavedra
More information about the AGENTPP
mailing list