本文整理汇总了Java中org.snmp4j.smi.TimeTicks类的典型用法代码示例。如果您正苦于以下问题:Java TimeTicks类的具体用法?Java TimeTicks怎么用?Java TimeTicks使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimeTicks类属于org.snmp4j.smi包,在下文中一共展示了TimeTicks类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendPDU
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
/**
* 向接收器发送Trap 信息
*
* @throws IOException
*/
public void sendPDU() throws IOException {
PDU pdu = new PDU();
pdu.add(new VariableBinding(
new OID(".1.3.6.1.2.1.1.1.0"),
new OctetString("SNMP Trap Test.see more:http://www.micmiu.com")));
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(
new UnsignedInteger32(System.currentTimeMillis() / 1000)
.getValue())));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(
".1.3.6.1.6.3.1.1.4.3")));
// 向Agent发送PDU
pdu.setType(PDU.TRAP);
snmp.send(pdu, target);
System.out.println("----> Trap Send END <----");
}
示例2: getDataType
import org.snmp4j.smi.TimeTicks; //导入依赖的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;
}
示例3: testTimeTickVariable
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
@Test
public void testTimeTickVariable() throws InterruptedException {
String expectedOid = "1.3.6.1.2.1.1.3.0";
Number expectedValue = 2929358;
String expectedSource = "www.myweb.com";
String expectedMetricId = "MY_FAVORITE_METRIC";
VariableBinding vb = new VariableBinding();
TimeTicks v = new TimeTicks();
v.setValue(expectedValue.longValue());
vb.setOid(new OID(expectedOid));
vb.setVariable(v);
SnmpPollerConfiguration config = getSnmpPollerConfiguration(
expectedSource,expectedMetricId,expectedOid);
out.expectedMessageCount(1);
in.sendBodyAndHeaders(vb,setScriptHeaders(SNMP_TO_MEASURE_SCRIPT,config));
out.assertIsSatisfied();
Measurement m = getMeasurement(out);
assertNotNull("check event for null",m);
assertEquals("check source",expectedSource,m.getSource());
assertEquals("check metric",expectedMetricId,m.getMetric());
assertEquals("check measure",v.getValue(),m.getMeasure().intValue());
}
示例4: getTimeStamp
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
protected long getTimeStamp() {
if (log().isDebugEnabled()) {
log().debug("V2 "+m_pduTypeString+" first varbind value: " + getVarBindAt(0).getVariable().toString());
}
switch (getVarBindAt(SNMP_SYSUPTIME_OID_INDEX).getVariable().getSyntax()) {
case SMIConstants.SYNTAX_TIMETICKS:
log().debug("V2 "+m_pduTypeString+" first varbind value is of type TIMETICKS (correct)");
return ((TimeTicks) getVarBindAt(SNMP_SYSUPTIME_OID_INDEX).getVariable()).getValue();
case SMIConstants.SYNTAX_INTEGER32:
log().debug("V2 "+m_pduTypeString+" first varbind value is of type INTEGER, casting to TIMETICKS");
return ((Integer32) getVarBindAt(SNMP_SYSUPTIME_OID_INDEX).getVariable()).getValue();
default:
throw new IllegalArgumentException("V2 "+m_pduTypeString+" does not have the required first varbind as TIMETICKS - cannot process "+m_pduTypeString);
}
}
示例5: sendTrapV2
import org.snmp4j.smi.TimeTicks; //导入依赖的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();
}
示例6: getFormattedTimeForTimeTicks
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
/**
* Returns time in days:HH:mm:ss format if input time is greater than 0 else
* returns empty string. The input time is in hundredth of a seconds. The
* same output from SNMP.
*
*
* @param upTimeInHundredthSec
* @return
*/
public static String getFormattedTimeForTimeTicks( final long upTimeInHundredthSec )
{
String result = "";
if ( upTimeInHundredthSec >= 0 )
{
TimeTicks timeTicks = new TimeTicks( upTimeInHundredthSec );
result = timeTicks.toString( TIMETICK_PATTERN );
}
return result;
}
示例7: testGetVariableBindings
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
@Test
public void testGetVariableBindings() {
SnmpTrap trap = new SnmpTrap();
Vector<VariableBinding> varBinds = new Vector<VariableBinding>();
varBinds.add(new VariableBinding(SnmpConstants.linkUp,new OctetString("Network link is now up")));
varBinds.add(new VariableBinding(SnmpConstants.sysUpTime,new TimeTicks(100000L)));
trap.setVariableBindings(varBinds);
assertTrue("check getVariableBindings()",varBinds.containsAll(trap.getVariableBindings()));
}
示例8: testGetVarBindInt
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
@Test
public void testGetVarBindInt() {
SnmpTrap trap = new SnmpTrap();
Vector<VariableBinding> varBinds = new Vector<VariableBinding>();
varBinds.add(new VariableBinding(SnmpConstants.linkUp,new OctetString("Network link is now up")));
varBinds.add(new VariableBinding(SnmpConstants.sysUpTime,new TimeTicks(100000L)));
trap.setVariableBindings(varBinds);
VariableBinding variableBinding = trap.getVarBind(0);
assertEquals("check variableBinding","linkUp = Network link is now up",variableBinding.toString());
}
示例9: testGetVarBindOID
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
@Test
public void testGetVarBindOID() {
SnmpTrap trap = new SnmpTrap();
Vector<VariableBinding> varBinds = new Vector<VariableBinding>();
varBinds.add(new VariableBinding(SnmpConstants.linkUp,new OctetString("Network link is now up")));
varBinds.add(new VariableBinding(SnmpConstants.sysUpTime,new TimeTicks(100000L)));
trap.setVariableBindings(varBinds);
VariableBinding variableBinding = trap.getVarBind(SnmpConstants.linkUp);
assertEquals("check variableBinding","linkUp = Network link is now up",variableBinding.toString());
}
示例10: asMeasurement
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
/**
* Converts an SNMP variable into an RHQ measurement value.
* This includes mapping integer values into string constants,
* converting strings to doubles, etc.
*
* @param request measurement request
* @param variable SNMP variable
* @return data as a trait or numeric (or complex)
*/
private MeasurementData asMeasurement(MeasurementScheduleRequest request, Variable variable) {
if (variable == null)
throw new NullPointerException("variable");
if (request == null)
throw new NullPointerException("request");
DataType dataType = request.getDataType();
String name = request.getName();
if (variable instanceof Integer32) {
int i = ((Integer32)variable).toInt();
Map<Integer, String> mapping = index.getMapping(name);
if (mapping != null && !mapping.isEmpty()) {
return new MeasurementDataTrait(request, mapping.get(i));
}
}
if (dataType == DataType.TRAIT) {
return new MeasurementDataTrait(request, variable.toString());
}
if (variable instanceof OctetString && dataType == DataType.MEASUREMENT) {
// interpret as String
return new MeasurementDataNumeric(request, new Double(variable.toString()));
}
if (variable instanceof TimeTicks) {
long ms = ((TimeTicks)variable).toMilliseconds();
return new MeasurementDataNumeric(request, (double)ms);
}
return new MeasurementDataNumeric(request, (double)variable.toLong());
}
示例11: setUp
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
protected void setUp() throws Exception {
MockUtil.println("------------ Begin Test "+getName()+" --------------------------");
MockLogAppender.setupLogging();
m_network = new MockNetwork();
m_network.setCriticalService("ICMP");
m_network.addNode(1, "Router");
m_network.addInterface("192.168.1.1");
m_network.addService("ICMP");
m_network.addService("SMTP");
m_network.addInterface("192.168.1.2");
m_network.addService("ICMP");
m_network.addService("SMTP");
m_network.addNode(2, "Server");
m_network.addInterface("192.168.1.3");
m_network.addService("ICMP");
m_network.addService("HTTP");
m_network.addInterface("192.168.1.2");
MapSubAgent systemGroup = new MapSubAgent("1.3.6.1.2.1.1");
systemGroup.put("1.0", new OctetString("MockAgent!"));
systemGroup.put("2.0", new OID("1.3.6.1.4.1.5813.1"));
systemGroup.put("3.0", new TimeTicks(1234));
systemGroup.put("4.0", new OctetString("Mr. Personality"));
systemGroup.put("5.0", new OctetString("mockhost"));
systemGroup.put("6.0", new OctetString("Wouldn't you like to know"));
// what happened to 7.0?
MapSubAgent interfaces = new MapSubAgent("1.3.6.1.2.1.2");
interfaces.put("1.0", new Integer32(2));
m_proxy = new MockProxy(9161);
MockAgent agent = new MockAgent();
agent.addSubAgent(systemGroup);
agent.addSubAgent(interfaces);
m_proxy.addAgent(agent);
}
示例12: sendTrapV1
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
public static void sendTrapV1(String port) throws IOException {
TransportMapping<?> transport = new DefaultUdpTransportMapping();
transport.listen();
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(new OctetString("public")));
comtarget.setVersion(SnmpConstants.version1);
comtarget.setAddress(new UdpAddress("127.0.0.1/" + port));
comtarget.setRetries(2);
comtarget.setTimeout(5000);
PDU trap = new PDUv1();
trap.setType(PDU.V1TRAP);
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));
// Send
Snmp snmp = new Snmp(transport);
snmp.send(trap, comtarget);
transport.close();
snmp.close();
}
示例13: moToPdu
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
public static PDU moToPdu(TrapData trap) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
PDU pdu = new PDU();
pdu.setType(PDU.TRAP);
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(trap.getSysUpTime())));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(trap.getTrapOid())));
addVarBindings(trap, pdu);
return pdu;
}
示例14: generateRowData
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
private static Variable[] generateRowData(List<MyMibNode> columnNodes) {
Variable[] rowValues = new Variable[columnNodes.size()];
for (int i = 0; i < columnNodes.size(); i++) {
MyMibNode columnNode = columnNodes.get(i);
String rule = columnNode.getRule();
if("Counter32".equals(columnNode.getType())){
rowValues[i] = new Counter32(Long.parseLong("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("Gauge32".equals(columnNode.getType())){
rowValues[i] = new Gauge32(Long.parseLong("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("Integer32".equals(columnNode.getType()) || "INTEGER".equals(columnNode.getType())){
rowValues[i] = new Integer32(Integer.parseInt("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("TimeTicks".equals(columnNode.getType())){
rowValues[i] = new TimeTicks();
}
if("Unsigned32".equals(columnNode.getType())){
rowValues[i] = new Integer32(Integer.parseInt("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("IpAddress".equals(columnNode.getType())){
rowValues[i] = new IpAddress("10.10.10.10");
}
if("OCTET STRING".equals(columnNode.getType())){
rowValues[i] = new OctetString("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomString(5)}") : TestDataUtil.parseInnerMethod(rule));
}
}
return rowValues;
}
示例15: modify
import org.snmp4j.smi.TimeTicks; //导入依赖的package包/类
@Override
public TimeTicks modify(final TimeTicks variable) {
TimeTicks timeTicks = new TimeTicks();
final long timeTicksInMilliseconds = variable.toMilliseconds();
final long upTime = (System.currentTimeMillis() - initTime) + timeTicksInMilliseconds;
timeTicks.fromMilliseconds(timeTicksInMilliseconds + upTime);
return timeTicks;
}