当前位置: 首页>>代码示例>>Java>>正文


Java Variable类代码示例

本文整理汇总了Java中org.snmp4j.smi.Variable的典型用法代码示例。如果您正苦于以下问题:Java Variable类的具体用法?Java Variable怎么用?Java Variable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Variable类属于org.snmp4j.smi包,在下文中一共展示了Variable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIndexes

import org.snmp4j.smi.Variable; //导入依赖的package包/类
@Override
public Varbind[] getIndexes() {
  if (indexExtractor == null) {
    return new Varbind[0];
  }
  IndexDescriptor[] descriptors = indexExtractor.extractIndexes(getOid());
  Varbind[] varbinds = new Varbind[descriptors.length];
  for (int i = 0; i < descriptors.length; i++) {
    IndexDescriptor descriptor = descriptors[i];
    Variable variable = AbstractVariable.createFromSyntax(
        descriptor.getSyntax());
    variable.fromSubIndex(new OID(descriptor.getEncoded()), 
        descriptor.isImplied());
    VariableBinding vb = new VariableBinding(new OID(descriptor.getOid()), 
        variable);
    varbinds[i] = varbindFactory.newVarbind(vb);
  }
  return varbinds;
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:20,代码来源:Snmp4jVarbind.java

示例2: getDataType

import org.snmp4j.smi.Variable; //导入依赖的package包/类
public static SNMPDataType getDataType(Variable var){
		SNMPDataType retVal = SNMPDataType.INT;
/*		
 * 	org.snmp4j.smi.Variable implementations
 * 		AbstractVariable, BitString, 
 * 		Counter32, Counter64, Gauge32, Integer32, UnsignedInteger32, 
 * 		TimeTicks, 
 * 		OctetString,
 * 		GenericAddress, IpAddress, Null, OID, Opaque, SMIAddress, SshAddress, TcpAddress, TlsAddress, 
 * 		TransportIpAddress, TsmSecurityParameters, UdpAddress, VariantVariable
 * 	SNMPDataType: STRING,INT,LONG,FLOAT,TICKS,OCTIN,OCTOUT,COUNT, OTHER
 */
		if(var instanceof TimeTicks) {
			retVal = SNMPDataType.TICKS;
		} else if(var instanceof Counter64 || var instanceof Counter32) {
			retVal = SNMPDataType.COUNT;
		} else if(var instanceof Integer32 || var instanceof UnsignedInteger32) {
			retVal = SNMPDataType.COUNT;
		} else if(var instanceof Gauge32) {
			retVal = SNMPDataType.COUNT;
		} else if(var instanceof OctetString) {
			retVal = SNMPDataType.STRING;
		}
		return retVal;
	}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:26,代码来源:SNMPUtil.java

示例3: getAvailability

import org.snmp4j.smi.Variable; //导入依赖的package包/类
/**
 * Returns UP if able to obtain one of the defined measurement mib.
 */
@Override
public AvailabilityType getAvailability() {
    Set<MeasurementDefinition> mds = this.definitions;
    if (!mds.isEmpty()) {
        MeasurementDefinition md = mds.iterator().next();
        OID oid = index.getNameRecord(md.getName()).getOid0();
        try {
            Variable variable = snmp.get(oid);
            if (variable.isException())
                return DOWN;
        } catch (IOException e) {
            return DOWN;
        }
    }
    return UP;
}
 
开发者ID:genman,项目名称:rhq-plugins,代码行数:20,代码来源:MibComponent.java

示例4: getAvailability

import org.snmp4j.smi.Variable; //导入依赖的package包/类
/**
 * Returns DOWN if the table row no longer exists or can be read.
 */
@Override
public AvailabilityType getAvailability() {
    Set<MeasurementDefinition> mds = this.definitions;
    if (!mds.isEmpty()) {
        MeasurementDefinition md = mds.iterator().next();
        OID oid = oid(md.getName());
        try {
            Variable variable = snmp.get(oid);
            if (variable.isException())
                return DOWN;
        } catch (IOException e) {
            return DOWN;
        }
    }
    return UP;
}
 
开发者ID:genman,项目名称:rhq-plugins,代码行数:20,代码来源:MibTableComponent.java

示例5: testIt

import org.snmp4j.smi.Variable; //导入依赖的package包/类
public void testIt() throws Exception {
    TestAgent ta = new TestAgent(port);
    ta.start();
    Configuration c = new Configuration();
    c.setSimpleValue("transportAddress", "localhost/" + port);
    c.setSimpleValue("version", "1");
    SnmpComponent snmp = new SnmpComponent(c);

    log.info("SNMP get");
    Variable v = snmp.get(SnmpConstants.sysUpTime);

    OID oid = new OID(TestAgent.sysOID).append(new OID("1.0"));
    ta.register(oid);

    VariableBinding vb = new VariableBinding(oid, new OctetString(HI));
    log.info("SNMP set " + oid);
    snmp.set(vb);

    log.info("SNMP get " + oid);
    v = snmp.get(oid);
    assertEquals(HI, v.toString());

    log.info("SNMP stop");
    snmp.stop();
    ta.stop();
}
 
开发者ID:genman,项目名称:rhq-plugins,代码行数:27,代码来源:TestAgentTest.java

示例6: addCommunities

import org.snmp4j.smi.Variable; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void addCommunities(SnmpCommunityMIB communityMIB) {
    Variable[] com2sec = new Variable[] {
            new OctetString("public"),              // community name
            new OctetString("public"),              // security name
            getAgent().getContextEngineID(),        // local engine ID
            new OctetString(),                      // default context name
            new OctetString(),                      // transport tag
            new Integer32(StorageType.nonVolatile), // storage type
            new Integer32(RowStatus.active)         // row status
    };
    MOTableRow row =
            communityMIB.getSnmpCommunityEntry().createRow(
                                                           new OctetString("public2public").toSubIndex(true), com2sec);
    communityMIB.getSnmpCommunityEntry().addRow(row);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:18,代码来源:MockSnmpAgent.java

示例7: sendTrapV2

import org.snmp4j.smi.Variable; //导入依赖的package包/类
public static void sendTrapV2(String port) throws IOException {
    PDU trap = new PDU();
    trap.setType(PDU.TRAP);

    OID oid = new OID("1.2.3.4.5");
    trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
    trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
    trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description")));

    // Add Payload
    Variable var = new OctetString("some string");
    trap.add(new VariableBinding(oid, var));

    // Specify receiver
    Address targetaddress = new UdpAddress("127.0.0.1/" + port);
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(targetaddress);

    // Send
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    snmp.send(trap, target, null, null);

    snmp.close();
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:27,代码来源:SNMPUtils.java

示例8: addCommunities

import org.snmp4j.smi.Variable; //导入依赖的package包/类
/**
 * to set community
 */
@Override
protected void addCommunities(SnmpCommunityMIB communityMIB) {
	Variable[] com2sec = new Variable[] {
			new OctetString(community),              		// community name
			new OctetString("cpublic"),              	// security name
			getAgent().getContextEngineID(),        	// local engine ID
			new OctetString(community),              		// default context name
			new OctetString(),                      	// transport tag
			new Integer32(StorageType.nonVolatile), 	// storage type
			new Integer32(RowStatus.active)         	// row status
	};
	MOTableRow row =
		communityMIB.getSnmpCommunityEntry().createRow(
				new OctetString("public2public").toSubIndex(true), com2sec);
	communityMIB.getSnmpCommunityEntry().addRow(row);

}
 
开发者ID:wangzijian777,项目名称:snmpTool,代码行数:21,代码来源:MyAgent.java

示例9: getVariableBindings

import org.snmp4j.smi.Variable; //导入依赖的package包/类
@Override
public Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID) {
    if (queryOID != null && context != null && context.getValue().length != 0) {
        if (!queryOID.toString().isEmpty() && !context.toString().isEmpty() && communityContextMapping.containsKey(Long.parseLong(context.toString()))) {
            return new TreeMap<OID, Variable>() {{
                put(queryOID, new Counter32(communityContextMapping.get(Long.parseLong(context.toString()))));
            }};
        }
    } else if (queryOID != null) {
        return new TreeMap<OID, Variable>() {{
            put(queryOID, modify(null));
        }};

    }
    return new TreeMap<>();
}
 
开发者ID:1and1,项目名称:snmpman,代码行数:17,代码来源:CommunityIndexCounter32Modifier.java

示例10: testModify

import org.snmp4j.smi.Variable; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testModify() throws Exception {
    final ModifierProperties modifierProperties = new ModifierProperties();
    modifierProperties.put("minimum", 0L);
    modifierProperties.put("maximum", 3000L);
    modifierProperties.put("minimumStep", 1L);
    modifierProperties.put("maximumStep", 10L);

    final Modifier modifier = new Modifier(".1.3.6.*", "com.oneandone.snmpman.configuration.modifier.Counter32Modifier", modifierProperties);

    final Counter32 counter32 = new Counter32(0L);
    assertEquals(counter32.getValue(), 0L);

    final Variable modifiedVariable = modifier.modify(counter32);
    assertTrue(modifiedVariable instanceof Counter32);
    assertNotEquals(((Counter32) modifiedVariable).getValue(), 0L);
}
 
开发者ID:1and1,项目名称:snmpman,代码行数:19,代码来源:ModifierTest.java

示例11: setMib

import org.snmp4j.smi.Variable; //导入依赖的package包/类
public Variable setMib(String strVarBind) throws ParseException {
  VariableBinding varBind
    = ColonSeparatedOidTypeValueVariableTextFormat.getInstance()
        .parseVariableBinding(strVarBind);
  OID oid = varBind.getOid();

  DefaultMOContextScope scope
    =  new DefaultMOContextScope(
         new OctetString(FILEMIB_CONTEXT),
         oid, true, oid.nextPeer(), false
       );

  ManagedObject mo = server.lookup(new DefaultMOQuery(scope, true));
  if (mo == null) {
    return Null.noSuchObject;
  }

  if (!(mo instanceof MutableStaticMOGroup)) {
    return Null.noSuchObject;
  }

  return ((MutableStaticMOGroup)mo).set(
           oid,
           varBind.getVariable()
         );
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:27,代码来源:FileMibAgent.java

示例12: MutableStaticMOGroup

import org.snmp4j.smi.Variable; //导入依赖的package包/类
/**
 * Creates a static managed object group for the sub-tree with the specified
 * root OID.
 * @param root
 *    the root OID of the sub-tree to be registered by this managed object.
 * @param vbs
 *    the variable bindings to be returned in this sub-tree.
 */
public MutableStaticMOGroup(OID root, VariableBinding[] vbs) {
  this.root = root;
  this.scope = new DefaultMOScope(root, true, root.nextPeer(), false);
  variableBindings = new TreeMap<OID, Variable>();
  for (int i = 0; i < vbs.length; i++) {
    if ((vbs[i].getOid() != null) && (vbs[i].getVariable() != null)) {
      if (
           (vbs[i].getOid().size() >= root.size())
        && (vbs[i].getOid().leftMostCompare(root.size(), root) == 0)
      ) {
        this.variableBindings.put(vbs[i].getOid(), vbs[i].getVariable());
      }
    }
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:24,代码来源:MutableStaticMOGroup.java

示例13: find

import org.snmp4j.smi.Variable; //导入依赖的package包/类
public OID find(MOScope range) {
  OID targetOid = range.getLowerBound();

  SortedMap<OID, Variable> tail;
  if (range.isLowerIncluded()) {
    synchronized (variableBindings) {
      tail = variableBindings.tailMap(targetOid);
    }
  }
  else {
    synchronized (variableBindings) {
      tail = variableBindings.tailMap(targetOid.successor());
    }
  }

  if (tail.size() == 0) {
    return null;
  }

  return tail.firstKey();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:22,代码来源:MutableStaticMOGroup.java

示例14: get

import org.snmp4j.smi.Variable; //导入依赖的package包/类
public void get(SubRequest request) {
  OID oid = request.getVariableBinding().getOid();

  Variable var = get(oid);
  if (var == null) {
    request.getVariableBinding().setVariable(Null.noSuchInstance);
    request.completed();

    if (enableSnmpAccessStatisticsGatherer) {
      snmpAccessStatisticsGatherer
        .snmpGetFailed(request.getRequest().getContext(), oid);
    }

    return;
  }
  request.getVariableBinding().setVariable(var);
  request.completed();

  if (enableSnmpAccessStatisticsGatherer) {
    snmpAccessStatisticsGatherer
      .snmpGetSucceeded(request.getRequest().getContext(), oid);
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:24,代码来源:MutableStaticMOGroup.java

示例15: commit

import org.snmp4j.smi.Variable; //导入依赖的package包/类
/**
 * commit
 * @param request
 *    a request to process commit SET request for.
 */
public void commit(SubRequest request) {
  Variable variable = request.getVariableBinding().getVariable();
  OID oid = request.getVariableBinding().getOid();

  synchronized (variableBindings) {
    request.setUndoValue(variableBindings.get(oid));
    variableBindings.put(oid, variable);
  }

  if (enableSnmpAccessStatisticsGatherer) {
    snmpAccessStatisticsGatherer.snmpSetSucceeded(request.getRequest().getContext(), oid);
  }

  request.completed();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:21,代码来源:MutableStaticMOGroup.java


注:本文中的org.snmp4j.smi.Variable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。