Unsolved
This post is more than 5 years old
7 Posts
0
7081
July 13th, 2009 07:00
SNMP Get in ASL
Hi,
Does anyone have any examples of how to use ASL to get the value of an SNMP OID? It looks like the class ACT_SNMP would be the way to go, but I'm not sure what the arguments would look like.
Thanks,
Alicia
No Events found!
FredericMeunier_0588be
143 Posts
0
July 13th, 2009 07:00
Hi Alicia,
you should have seen that the method signature is :
get target oid timeout retries policy format
only the first 2 parameters are mandatory. The second one is obvious (ex : ".1.3.6.1.2.1.1.5.0"), the first one is a struct :
struct target {
/// The target's IP address or hostname
string address;
/// The target's UDP port number
unsigned short port;
/// The target's SNMP version
version_t version;
/// The target's community string (for SNMPv1 / SNMPv2c)
string community;
/// The target's username (for SNMPv3)
string username;
/// The user's Authentication Protocol (for SNMPv3)
string authProtocol;
/// The user's Privacy Protocol (for SNMPv3)
string privProtocol;
/// The user's Authentication Password (for SNMPv3)
string authPassword;
/// The user's Privacy Password (for SNMPv3)
string privPassword;
/// The target's VACM Context Name (for SNMPv3)
string contextName;
};
the return value is an array with:
0 : OID
1 : type
2 : value
if I remember well.
HTH,
--Fred
ArunDeva
37 Posts
0
July 14th, 2009 01:00
Is it possible to run this ACT_SNMP on a Smarts OI server. Because I am getting the following error while trying to get snmpActGet from an OI sever.
ASL-W-ERROR_RULE_SOURCE-While executing rule set
'/opt/InCharge7/SAM/smarts/local/rules/icoi-trapd/xenpak.asl'
ASL-ERROR_ACTION-While executing action at:
ASL-CALL_STACK_RULE- RuleName: START, Line: 134
ASL-ERROR_INVOKE-While attempting to invoke operation 'snmpActGet' of object
'MR_Object::ICF-TopologyManager'
SVIF-EREMOTE-CI-E-EGENERIC-At
.
/work/bluecurrent/FOUNDATION-7.2.0.X/28/smarts/repos/mr/classdef.c:6825
. snmpActGet: Specified operation not found in class
. MR-OPERATION_NOT_FOUND-Specified operation not found in class
I am using the following command to get the objects.
topoObj = object("ICF-TopologyManager");
varbind = topoObj->snmpActGet(snmpAct, agentObj,oids[oid]);
Is this error occurring because of the difference in the instances in ICF_TopologyManager in AM domain and in OI domain?
regards
Arun
FredericMeunier_0588be
143 Posts
0
July 14th, 2009 06:00
Hi ArunDeva,
my example is based on :
ACT_SNMP
object, as requested by Alicia, not :
ICF_TopologyManager
And yes, the ICF_TopologyManager class in OI is different than the one in AM. Do a :
dmctl -s getop
and you will see the class' methods.
So in your case, you should be able to use the ACT_SNMP object in order to do SNMP requests from OI.
--Fred
== Monitor your Smarts environment using APG ReportPack for Smarts health ==
Frederic Meunier
Solutions Watch4Net Inc
APG & Smarts InCharge integration
http://www.watch4net.com
ArunDeva
37 Posts
0
July 17th, 2009 02:00
Thanks Fred.
I tried to get the value of the OID ".1.3.6.1.2.1.1.3.0" using snmpActGet function.
but it is not returning any value and is printing the value that I am giving in the varbind definition. Not the value of the OID.
varbind = list(oid, 0, "");
varbind = topo_manager->snmpActGetNext(snmpAct, agentObj, oid)?IGNORE;
print("The varbind value is");
print(varbind[2]);
What can be went wrong?
Could somebody help here please?
I tried without Next also. But still it is not getting the value of the OID that I need.
varbind = topo_manager->snmpActGet(snmpAct, agentObj, oid)?IGNORE;
ArunDeva
37 Posts
0
July 17th, 2009 03:00
agentObj = '172.25.22.157';
default DEBUG=TRUE;
default sysObjName = "";
oids = table();
uptimeoid = ".1.3.6.1.2.1.1.3.0";
START{
}do{
snmpAct = create("ACT_SNMP", "Uptime-ACT-SNMP");
topo_manager = object(getInstances("ICF_TopologyManager")[0]);
timeout = topo_manager->defaultTimeout;
retries = topo_manager->defaultRetries;
snmpAct->stop()?IGNORE;
snmpAct->start(timeout, retries)?IGNORE;
if (DEBUG) { print("System Group for ".sysObjName.topo_manager);}
varbind = list(uptimeoid, 0, -1);
varbind = topo_manager->snmpActGet(snmpAct, agentObj, uptimeoid)?IGNORE;
print("The varbind value is");
print(numeric(varbind[2]));
stop();
}
When I run this asl, I am getting the following result. But I need the value which is returned for the oid.
System Group for MR_Object::ICF-TopologyManager
The varbind value is
-1
alicia2
7 Posts
0
July 31st, 2009 12:00
I got it to work:
START {
.. eol
} do {
print("Starting script...");
snmp_get = object("ACT_SNMP", "SNMP_Get");
if (snmp_get->isNull()) {
snmp_get = create("ACT_SNMP", "SNMP_Get");
}
if ( ! snmp_get->started ) {
snmp_get->start(3000, 1);
}
snmp_get->trace = TRUE;
snmp_target = list(
ip_address, // IP Address of the Device
161, // SNMP Port
"V2C", // SNMP Version "V1" or "V2C"
"community", // Read Community String
"", // Target Username (V3)
"", // Authentication Protocol (V3)
"", // Privacy Protocol (V3)
"", // Authentication Password (V3)
"", // Privacy Password (V3)
"" // VACM Context Name (V3)
);
result = list(".1.3.6.1.2.1.1.3.0", 0, -1);
result = snmp_get->get(
snmp_target,
".1.3.6.1.2.1.1.3.0", //snmpOID
3000, //snmpTimeout
1, //snmpRetries
"unknown", //snmpPolicy
"intOctetStr" //snmpPolicy
);
print("Result: " . result);
if (result[2] != -1) {
value = result[2];
print(value);
}
}
ArunDeva
37 Posts
0
February 10th, 2010 04:00
Thanks a lot Alicia. It really worked.
Regards
Arun
Arun_Warrier
9 Posts
0
August 2nd, 2010 04:00
How do we perform "Error Handling" in this piece of code?
result = snmp_get->get(
snmp_target,
".1.3.6.1.2.1.1.3.0",
3000,
1,
"unknown"
"intOctetStr
); ----------------------------------------------->
print("result: ".result);
if (result[2] != -1 ) {
value = result[2] ;
print(value);
}
I can understand that putting ?LOG at teh arrow section will log the error in the log file.
But if there is any the snmp_get is returning a NULL value, it is logging but it is not proceeding to the print statement. Why? and how can we handle that?
Thanks
Arun
Arun_Warrier
9 Posts
0
August 18th, 2010 03:00
any help here?
FredericMeunier_0588be
143 Posts
0
August 19th, 2010 14:00
Hi Arun,
two ways to handle this :
(1) force a default value to result, before the call to the snmp function :
result = "";
and test for this to be sure you did receive a value from the function
(2) use the defined function :
if ( defined(result) ) {
...
}
HTH,
--Fred
== APG5 ReportPack4Event for Smarts can report on millions of notifications in seconds ==
Frederic Meunier
Solutions Watch4Net Inc
APG & Smarts InCharge integration
http://www.watch4net.com