本文整理汇总了Java中org.snmp4j.PDU.getVariable方法的典型用法代码示例。如果您正苦于以下问题:Java PDU.getVariable方法的具体用法?Java PDU.getVariable怎么用?Java PDU.getVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.snmp4j.PDU
的用法示例。
在下文中一共展示了PDU.getVariable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVariableBinding
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static Variable getVariableBinding(PDU pdu, OID varoid){
Variable retVal = null;
if(pdu != null && varoid != null){
retVal = pdu.getVariable(varoid);
}
return retVal;
}
示例2: match
import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
* Returns the matching severity for this PDU, or null if no match.
*/
public EventSeverity match(PDU pdu) {
if (pdu instanceof PDUv1) {
PDUv1 pdu1 = (PDUv1) pdu;
if (genericTrap != UNSET && genericTrap != pdu1.getGenericTrap()) {
log.trace("no match generic trap");
return null;
}
if (specificTrap != UNSET && specificTrap != pdu1.getSpecificTrap()) {
log.trace("no match specific trap");
return null;
}
if (!pdu1.getEnterprise().startsWith(enterprise)) {
log.trace("no match enterprise");
return null;
}
} else {
OID oid = (OID) pdu.getVariable(SnmpConstants.snmpTrapOID);
if (oid != null && oid.startsWith(trapOid)) {
log.trace("no match enterprise");
return null;
}
}
if (varbind.size() != 0) {
Variable v = pdu.getVariable(varbind);
if (v == null) {
log.trace("no required variable found");
return null;
}
if (!value.matcher(v.toString()).find()) {
log.trace("no match variable");
return null;
}
}
return severity;
}
示例3: dispatchPdu
import org.snmp4j.PDU; //导入方法依赖的package包/类
private void dispatchPdu(Address address, PDU pdu) {
if (pdu != null & address != null) {
logger.debug("Received PDU from '{}' '{}'", address, pdu);
for (SnmpBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
// Check the IP address
if (!provider.getAddress(itemName).equals(address)) {
continue;
}
// Check the OID
OID oid = provider.getOID(itemName);
Variable variable = pdu.getVariable(oid);
if (variable != null) {
Class<? extends Item> itemType = provider.getItemType(itemName);
// Do any transformations
String value = variable.toString();
try {
value = provider.doTransformation(itemName, value);
} catch (TransformationException e) {
logger.error("Transformation error with item {}: {}", itemName, e);
}
// Change to a state
State state = null;
if (itemType.isAssignableFrom(StringItem.class)) {
state = StringType.valueOf(value);
} else if (itemType.isAssignableFrom(NumberItem.class)) {
state = DecimalType.valueOf(value);
} else if (itemType.isAssignableFrom(SwitchItem.class)) {
state = OnOffType.valueOf(value);
}
if (state != null) {
eventPublisher.postUpdate(itemName, state);
} else {
logger.debug(
"'{}' couldn't be parsed to a State. Valid State-Types are String and Number",
variable.toString());
}
} else {
logger.trace("PDU doesn't contain a variable with OID ‘{}‘", oid.toString());
}
}
}
}
}