Hi
I am using SNMP++ on Linux and with QT 5.15.1.
Snmp get works with all data types (int, oid, octetStr and timeTicks). Snmp set works with integers as well.
Setting an oid variable does not work. I get the error SNMP: Cannot create/modify variable, Wrong Type
Setting the value over a windows device with this tool works fine (SnmpWalk (Command-line Tool) | SNMPSoft Tools | EZ5 Systems)
We use the RFC 1628 MIB (rfc1628)
Here are the codes:
Init (works fine)
Oid m_id(oid_string, true);
m_ipAddress = IpAddress(ipAddress);
m_cTarget = CTarget(m_ipAddress, community, community); // SNMP++ community target
m_cTarget.set_version(snmp_version(1));
m_vb.set_oid(oid_string);
m_snmp = new Snmp(m_status); //(m_ipAddress.get_ip_version() == Address::version_ipv4), 0
if (m_status != SNMP_CLASS_SUCCESS) { // check creation status
std::cout << "snmp++ session not created" << m_snmp->error_msg(m_status); // if fail, print error string
return;
}
Set integer value (works fine)
const int val = 1;
Oid testOid(".1.3.6.1.2.1.33.1.8.1.0");
int status = 0;
Vb test(testOid);
Snmp * snmpTest = new Snmp(status);
if (status != SNMP_CLASS_SUCCESS) { // check creation status
std::cout << “snmp++ session not created” << snmpTest->error_msg(status); // if fail, print error string
return;
}
Pdu pduTest;
test.set_value(val);
pduTest += test;
if ((status = snmpTest->set(pduTest, m_cTarget)) != SNMP_CLASS_SUCCESS){
qDebug() << “snmp set error” << snmpTest->error_msg(status);
} else {
qDebug() << “SNMP Set wirte value:” << val;
}
Set oid value (error)
int status = 0;
Snmp * snmpTest = new Snmp(status);
if (status != SNMP_CLASS_SUCCESS) { // check creation status
std::cout << “snmp++ session not created” << snmpTest->error_msg(status); // if fail, print error string
return;
}
Oid oid(".1.3.6.1.2.1.33.1.7.7.1");
Vb vb(".1.3.6.1.2.1.33.1.7.1.0");
vb.set_value(oid);
Pdu setPdu;
setPdu += vb;
if ((status = snmpTest->set(setPdu, m_cTarget)) != SNMP_CLASS_SUCCESS){
qDebug() << “snmp set error (UPS test)” << snmpTest->error_msg(status);
} else {
qDebug() << “Initiate ups test with” << oid.get_printable() << vb.get_printable_value();
}
→ SNMP: Cannot create/modify variable, Wrong Type