本文整理汇总了Java中org.snmp4j.util.TableEvent类的典型用法代码示例。如果您正苦于以下问题:Java TableEvent类的具体用法?Java TableEvent怎么用?Java TableEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TableEvent类属于org.snmp4j.util包,在下文中一共展示了TableEvent类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: querySingleSNMPTableByOID
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
public List<SNMPTriple> querySingleSNMPTableByOID(String oid) throws IOException
{
if(oid == null || oid.isEmpty())return null;
if(!oid.startsWith("."))oid = "."+oid;
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
List<TableEvent> events = tUtils.getTable(getTarget(), new OID[]{new OID(oid)}, null, null);
List<SNMPTriple> snmpList = new ArrayList<SNMPTriple>();
for (TableEvent event : events) {
if(event.isError()) {
logger.warning("SNMP event error: "+event.getErrorMessage());
continue;
//throw new RuntimeException(event.getErrorMessage());
}
for(VariableBinding vb: event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
snmpList.add(new SNMPTriple(key, "", value));
}
}
return snmpList;
}
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:24,代码来源:SNMPClient.java
示例2: getDiskIndex
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
private int getDiskIndex(String device) throws IOException {
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
logger.fine("Query "+this.address+" for disk data: "+device);
@SuppressWarnings("unchecked")
List<TableEvent> events = tUtils.getTable(getTarget(), new OID[]{new OID("."+DISK_TABLE_DEVICE_OID)}, null, null);
for (TableEvent event : events) {
if(event.isError()) {
logger.warning("SNMP event error: "+event.getErrorMessage());
continue;
//throw new RuntimeException(event.getErrorMessage());
}
for(VariableBinding vb: event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
if(value!=null && value.equals(device))
{
logger.fine("Find device OID entry: "+key);
int index = -1;
String[] strs = key.split("\\.");
try
{
index = Integer.parseInt(strs[strs.length-1]);
}catch(Exception ex){}
return index;
}
}
}
return -1;
}
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:33,代码来源:SNMPClient.java
示例3: getNetIfIndexes
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
private Map<Integer, String> getNetIfIndexes(String device) throws IOException {
Map<Integer, String> ifMaps = new HashMap<Integer, String> ();
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
logger.fine("Query "+this.address+" for network interface, excluding lo");
@SuppressWarnings("unchecked")
List<TableEvent> events = tUtils.getTable(getTarget(), new OID[]{new OID("."+IF_TABLE_DEVICE_OID)}, null, null);
for (TableEvent event : events) {
if(event.isError()) {
logger.warning("SNMP event error: "+event.getErrorMessage());
continue;
//throw new RuntimeException(event.getErrorMessage());
}
for(VariableBinding vb: event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
if(device!=null && !device.isEmpty() && !value.equalsIgnoreCase(device))
continue;
if(value!=null && !value.equalsIgnoreCase("lo"))
{
logger.fine("Find device OID entry: "+key);
int index = -1;
String[] strs = key.split("\\.");
try
{
index = Integer.parseInt(strs[strs.length-1]);
ifMaps.put(index, value);
}catch(Exception ex){}
}
}
}
return ifMaps;
}
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:36,代码来源:SNMPClient.java
示例4: getProcessIndexes
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
/**
* Query index for given process name. Note the parameter only provides 128 characters,
* so it could be difficult for us to differentiate each other if multi processes with same name exist.
* So we will return this list and use the sum from all processes for our metrics
* @param process
* @return
* @throws IOException
*/
private List<Integer> getProcessIndexes(String process) throws IOException {
List<Integer> indexes = new ArrayList<Integer> ();
if(process == null || process.isEmpty())return indexes;
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
logger.fine("Query "+this.address+" for process " + process);
@SuppressWarnings("unchecked")
List<TableEvent> events = tUtils.getTable(getTarget(), new OID[]{new OID("."+PROCESS_TABLE_OID)}, null, null);
for (TableEvent event : events) {
if(event.isError()) {
logger.warning("SNMP event error: "+event.getErrorMessage());
continue;
//throw new RuntimeException(event.getErrorMessage());
}
for(VariableBinding vb: event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
if(process!=null && !process.isEmpty() && !value.equalsIgnoreCase(process))
continue;
if(value!=null)
{
logger.fine("Find process OID entry: "+key);
int index = -1;
String[] strs = key.split("\\.");
try
{
index = Integer.parseInt(strs[strs.length-1]);
indexes.add(index);
}catch(Exception ex){}
}
}
}
return indexes;
}
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:44,代码来源:SNMPClient.java
示例5: row
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
/**
* Decodes a row into name-value pairs; assuming the columns are supplied in
* order of table OID.
*
* @throws IllegalStateException if OIDs don't correspond
*/
public Map<String, Variable> row(TableEvent te) {
Map<String, Variable> map = new HashMap<String, Variable>();
for (int i = 0; i < te.getColumns().length; i++) {
String colName = columns.get(i);
VariableBinding vb = te.getColumns()[i];
if (!vb.getOid().startsWith(oids[i]))
throw new IllegalStateException(vb + " does not start with " + oids[i]);
map.put(colName, vb.getVariable());
}
return map;
}
开发者ID:genman,项目名称:rhq-plugins,代码行数:18,代码来源:TableRecord.java
示例6: decode
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
/**
* Decode a table event for a table, assuming the columns are as ordered in the
* call to {@link #getTable(String)}.
*
* @param tableName
* @param te
* @return
*/
public Map<String, Variable> decode(String tableName, TableEvent te) {
HashMap<String, Variable> hm = new HashMap<String, Variable>();
log.debug(te);
for (VariableBinding vb : te.getColumns()) {
String key = oids.get(vb.getOid());
Variable var = vb.getVariable();
hm.put(key, var);
}
return hm;
}
开发者ID:genman,项目名称:rhq-plugins,代码行数:19,代码来源:MibIndex.java
示例7: testWalkSystem
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
public void testWalkSystem() throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
TableUtils walker = new TableUtils(snmp, new DefaultPDUFactory());
snmp.listen();
Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
//Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
Target target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version1);
target.setTimeout(3000);
target.setRetries(3);
// Implements snmp4j API
@SuppressWarnings("unchecked")
List results = walker.getTable(target, new OID[] {new OID("1.3.6.1.2.1.1")}, null, null);
assertNotNull(results);
assertFalse(results.isEmpty());
assertTrue(results.get(results.size()-1) instanceof TableEvent);
TableEvent lastEvent = (TableEvent)results.get(results.size()-1);
MockUtil.println("Status of lastEvent is "+lastEvent.getStatus());
assertEquals(TableEvent.STATUS_OK, lastEvent.getStatus());
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:30,代码来源:MockAgentTest.java
示例8: testSnmpGetBulk
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
@Test
public void testSnmpGetBulk() throws Exception {
List<TableEvent> responses = SnmpmanTest.getResponse(new OID("1.3.6.1.2.1"), 10000);
assertEquals(responses.size(), 19);
responses = SnmpmanTest.getResponse(new OID("1.3.6.1.2.1.31"), 10000);
assertEquals(responses.size(), 10);
responses = SnmpmanTest.getResponse(new OID(".1.3.6.1.2.1.2"), 10000);
assertEquals(responses.size(), 7);
}
开发者ID:1and1,项目名称:snmpman,代码行数:12,代码来源:SnmpmanIntegrationTest.java
示例9: testWithCommunityIndex
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
@Test
public void testWithCommunityIndex() throws Exception {
final String oid = "1.3.6.1.2.1.17.2.4";
List<TableEvent> responses1 = SnmpmanTest.getResponse(new OID(oid), 10009, "[email protected]");
assertEquals(responses1.size(), 1);
assertTrue(SnmpmanTest.containsColumn(responses1, oid, "150"));
List<TableEvent> responses2 = SnmpmanTest.getResponse(new OID(oid), 10009, "[email protected]");
assertEquals(responses2.size(), 1);
assertTrue(SnmpmanTest.containsColumn(responses2, oid, "120"));
List<TableEvent> responses3 = SnmpmanTest.getResponse(new OID(oid), 10009, "public");
assertEquals(responses3.size(), 1);
assertTrue(SnmpmanTest.containsColumn(responses3, oid, "0"));
}
开发者ID:1and1,项目名称:snmpman,代码行数:16,代码来源:SnmpmanIntegrationTest.java
示例10: getDiskIndexes
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
private Map<Integer, String> getDiskIndexes() throws IOException {
Map<Integer, String> diskIndexes = new HashMap<Integer, String>();
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
logger.fine("Query "+this.address+" for disk oids");
@SuppressWarnings("unchecked")
List<TableEvent> events = tUtils.getTable(getTarget(), new OID[]{new OID("."+DISK_TABLE_DEVICE_OID)}, null, null);
for (TableEvent event : events) {
if(event.isError()) {
logger.warning("SNMP event error: "+event.getErrorMessage());
continue;
//throw new RuntimeException(event.getErrorMessage());
}
for(VariableBinding vb: event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
if(value == null || value.isEmpty() || value.startsWith("dm-"))continue;//ignore dm disk
if(value.startsWith("ram") || value.startsWith("loop") )continue;//ignore dm disk
char c = value.charAt(value.length()-1);
if(c>='0' && c<='9' )
{
if(value.startsWith("sd"))
{
if(value.length()>2)
{
char d = value.charAt(2);
if(d>='a' && d<='z')continue;
}
}
}
logger.fine("Find device OID entry: "+key);
int index = -1;
String[] strs = key.split("\\.");
try
{
index = Integer.parseInt(strs[strs.length-1]);
diskIndexes.put(index, value);
}catch(Exception ex){}
}
}
return diskIndexes;
}
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:45,代码来源:SNMPClient.java
示例11: getTable
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
public List<TableEvent> getTable(OID oids[]) {
TableUtils tableUtils = getTableUtils();
return tableUtils.getTable(target, oids, null, null);
}
开发者ID:genman,项目名称:rhq-plugins,代码行数:5,代码来源:SnmpComponent.java
示例12: discoverResources
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
/**
* Discover table rows by querying the table name, which is either the resource name
* or 'table' configuration value.
*/
@Override
public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<MibComponent> rdc) throws Exception {
Set<DiscoveredResourceDetails> drd = new HashSet<DiscoveredResourceDetails>();
Configuration conf = rdc.getDefaultPluginConfiguration();
MibComponent mibComponent = rdc.getParentResourceComponent();
String tableName = rdc.getResourceType().getName();
tableName = conf.getSimpleValue(TABLE, tableName);
log.debug("discover table " + tableName);
MibIndex index = mibComponent.getIndex();
TableRecord tableRecord = index.getTableRecord(tableName);
OID oids[] = { tableRecord.getOids()[0] };
List<TableEvent> events = mibComponent.getSnmpComponent().getTable(oids);
for (TableEvent event : events) {
conf = conf.deepCopy();
log.debug("events " + event);
if (event.getIndex() == null) {
log.debug("empty index");
continue;
}
log.debug("event index " + event.getIndex());
String name = toString(tableRecord.index(event));
log.debug("decode " + name);
String version = null;
String key = event.getIndex().toString();
conf.put(new PropertySimple(INDEX, key));
conf.put(new PropertySimple(TABLE, tableName));
DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
rdc.getResourceType(), // ResourceType
key, // key
name, // help resource name
version, // Version
"SNMP table " + tableName + ", row index " + name, // description
conf,
null // process information
);
drd.add(detail);
}
return drd;
}
开发者ID:genman,项目名称:rhq-plugins,代码行数:51,代码来源:MibTableDiscovery.java
示例13: testWalkSystem
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
public void testWalkSystem() throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
TableUtils walker = new TableUtils(snmp, new DefaultPDUFactory());
snmp.listen();
Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
//Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
Target target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version1);
target.setTimeout(3000);
target.setRetries(3);
@SuppressWarnings("unchecked")
List results = walker.getTable(target, new OID[] {new OID("1.3.6.1.2.1.1")}, null, null);
assertNotNull(results);
assertFalse(results.isEmpty());
assertTrue(results.get(results.size()-1) instanceof TableEvent);
TableEvent lastEvent = (TableEvent)results.get(results.size()-1);
MockUtil.println("Status of lastEvent is "+lastEvent.getStatus());
assertEquals(TableEvent.STATUS_OK, lastEvent.getStatus());
}
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:29,代码来源:MockAgentTest.java
示例14: index
import org.snmp4j.util.TableEvent; //导入依赖的package包/类
/**
* Based on the table index type, returns the columns of the index with their value.
* The values are either String, Number, or ???
*
* @throws IOException if decode fails
*/
public Map<String, Object> index(TableEvent te) throws IOException {
return index(te.getIndex());
}
开发者ID:genman,项目名称:rhq-plugins,代码行数:10,代码来源:TableRecord.java
注:本文中的org.snmp4j.util.TableEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论