Codota Logo
org.snmp4j.smi
Code IndexAdd Codota to your IDE (free)

How to use org.snmp4j.smi

Best Java code snippets using org.snmp4j.smi (Showing top 20 results out of 333)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ArrayList a =
  • Codota Iconnew ArrayList<String>()
  • Codota Iconnew ArrayList()
  • Codota Iconnew ArrayList<Object>()
  • Smart code suggestions by Codota
}
origin: apache/nifi

/**
 * Method to add {@link FlowFile} attributes from a {@link VariableBinding}
 * @param variableBinding {@link VariableBinding}
 * @param attributes {@link FlowFile} attributes to update
 */
private static void addAttributeFromVariable(VariableBinding variableBinding, Map<String, String> attributes) {
  attributes.put(SNMP_PROP_PREFIX + variableBinding.getOid() + SNMP_PROP_DELIMITER + variableBinding.getVariable().getSyntax(), variableBinding.getVariable().toString());
}
origin: apache/nifi

  /**
   * @see org.apache.nifi.snmp.processors.SNMPWorker#toString()
   */
  @Override
  public String toString() {
    return super.toString() + ", OID:" + this.oid.toString();
  }
}
origin: apache/nifi

/**
 * Method to create the variable from the attribute value and the given SMI syntax value
 * @param value attribute value
 * @param smiSyntax attribute SMI Syntax
 * @return variable
 */
private Variable stringToVariable(String value, int smiSyntax) {
  Variable var = AbstractVariable.createFromSyntax(smiSyntax);
  try {
    if (var instanceof AssignableFromString) {
      ((AssignableFromString) var).setValue(value);
    } else if (var instanceof AssignableFromInteger) {
      ((AssignableFromInteger) var).setValue(Integer.valueOf(value));
    } else if (var instanceof AssignableFromLong) {
      ((AssignableFromLong) var).setValue(Long.valueOf(value));
    } else {
      this.getLogger().error("Unsupported conversion of [" + value +"] to " + var.getSyntaxString());
      var = null;
    }
  } catch (IllegalArgumentException e) {
    this.getLogger().error("Unsupported conversion of [" + value +"] to " + var.getSyntaxString(), e);
    var = null;
  }
  return var;
}
origin: pentaho/pentaho-kettle

UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( servername ), nrPort );
ResponseEvent response = null;
if ( targettype.equals( target_type_Code[0] ) ) {
 target.setCommunity( new OctetString( community ) );
 target.setVersion( SnmpConstants.version1 );
 target.setAddress( udpAddress );
 if ( target.getAddress().isValid() ) {
  if ( log.isDebug() ) {
   logDebug( "Valid IP address" );
 pdu1.setEnterprise( new OID( Oid ) );
 pdu1.add( new VariableBinding( new OID( Oid ), new OctetString( messageString ) ) );
 transMap.listen();
 usertarget.setAddress( udpAddress );
 if ( usertarget.getAddress().isValid() ) {
  if ( log.isDebug() ) {
   logDebug( "Valid IP address" );
 usertarget.setVersion( SnmpConstants.version3 );
 usertarget.setSecurityLevel( SecurityLevel.AUTH_PRIV );
 usertarget.setSecurityName( new OctetString( "MD5DES" ) );
   new OctetString( userName ), AuthMD5.ID, new OctetString( passPhrase ), PrivDES.ID,
   new OctetString( passPhrase ) );
  throw new KettleException( "Null Usm" );
 } else {
origin: apache/nifi

Variable var = null;
if (splits.length == 2) { // no SMI syntax defined
  var = new OctetString(snmpPropValue);
} else {
  int smiSyntax = Integer.valueOf(splits[2]);
  VariableBinding varBind = new VariableBinding(new OID(snmpPropName), var);
  pdu.add(varBind);
  result = true;
origin: stackoverflow.com

 public static void main(String[] args) throws Exception {
   // Create PDU           
   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))); // put your uptime here
   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("10.101.21.32/162");
   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);                      
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

public boolean equals(Object o) {
 if (o instanceof VariableBinding) {
  VariableBinding other = (VariableBinding)o;
  return oid.equals(other.getOid()) &&
    variable.equals(other.getVariable());
 }
 return false;
}
origin: apache/cloudstack

if (alertType > 0) {
  long sysUpTimeTicks = ManagementFactory.getRuntimeMXBean().getUptime() / 10;
  trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(sysUpTimeTicks)));
  trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, getOID(CsSnmpConstants.TRAPS_PREFIX + alertType)));
  if (snmpTrapInfo.getDataCenterId() != 0) {
    trap.add(new VariableBinding(getOID(CsSnmpConstants.DATA_CENTER_ID), new UnsignedInteger32(snmpTrapInfo.getDataCenterId())));
    trap.add(new VariableBinding(getOID(CsSnmpConstants.POD_ID), new UnsignedInteger32(snmpTrapInfo.getPodId())));
    trap.add(new VariableBinding(getOID(CsSnmpConstants.CLUSTER_ID), new UnsignedInteger32(snmpTrapInfo.getClusterId())));
    trap.add(new VariableBinding(getOID(CsSnmpConstants.MESSAGE), new OctetString(snmpTrapInfo.getMessage())));
  } else {
    throw new CloudRuntimeException(" What is the use of alert without message ");
    trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME), new OctetString(snmpTrapInfo.getGenerationTime().toString())));
  } else {
    trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME)));
origin: apache/nifi

  final String authProtocol = context.getProperty(SNMP_AUTH_PROTOCOL).getValue();
  final String privProtocol = context.getProperty(SNMP_PRIV_PROTOCOL).getValue();
  OctetString aPwd = authPassword != null ? new OctetString(authPassword) : null;
  OctetString pPwd = privPassword != null ? new OctetString(privPassword) : null;
  this.snmp.getUSM().addUser(new OctetString(username),
      new UsmUser(new OctetString(username), SNMPUtils.getAuth(authProtocol), aPwd, SNMPUtils.getPriv(privProtocol), pPwd));
  final String securityName = context.getProperty(SNMP_SECURITY_NAME).getValue();
  if(securityName != null) {
    ((UserTarget) result).setSecurityName(new OctetString(securityName));
  String community = context.getProperty(SNMP_COMMUNITY).getValue();
  if(community != null) {
    ((CommunityTarget) result).setCommunity(new OctetString(community));
result.setAddress(new UdpAddress(context.getProperty(HOST).getValue() + "/" + context.getProperty(PORT).getValue()));
result.setRetries(context.getProperty(SNMP_RETRIES).asInteger());
result.setTimeout(context.getProperty(SNMP_TIMEOUT).asInteger());
origin: com.addc/addc-alerts

/**
 * Creates a SNMP UnsignedInteger64 variable binding.
 * 
 * @param oid
 *            the SNMP oid of the variable
 * @param val
 *            the long content of the variable
 * @return a new variable binding
 */
public VariableBinding createSnmpLongVar(String oid, long val) {
  return new VariableBinding(new OID(oid), new UnsignedInteger32(val));
}
origin: pentaho/pentaho-kettle

private void test() {
 boolean testOK = false;
 String errMsg = null;
 String hostname = jobMeta.environmentSubstitute( wServerName.getText() );
 int nrPort = Const.toInt( jobMeta.environmentSubstitute( "" + wPort.getText() ), SyslogDefs.DEFAULT_PORT );
 try {
  UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( hostname ), nrPort );
  UserTarget usertarget = new UserTarget();
  usertarget.setAddress( udpAddress );
  testOK = usertarget.getAddress().isValid();
  if ( !testOK ) {
   errMsg = BaseMessages.getString( PKG, "JobEntrySyslog.CanNotGetAddress", hostname );
  }
 } catch ( Exception e ) {
  errMsg = e.getMessage();
 }
 if ( testOK ) {
  MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_INFORMATION );
  mb.setMessage( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.OK", hostname ) + Const.CR );
  mb.setText( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.Title.Ok" ) );
  mb.open();
 } else {
  MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
  mb.setMessage( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.NOK.ConnectionBad", hostname )
   + Const.CR + errMsg + Const.CR );
  mb.setText( BaseMessages.getString( PKG, "JobEntrySyslog.Connected.Title.Bad" ) );
  mb.open();
 }
}
origin: apache/nifi

/**
 * Will create an instance of {@link SNMPGetter}
 */
@Override
protected SNMPGetter finishBuildingTargetResource(ProcessContext context) {
  String oid = context.getProperty(OID).getValue();
  return new SNMPGetter(this.snmp, this.snmpTarget, new OID(oid));
}
origin: apache/nifi

/**
 * Builds target resource.
 * @param context Process context
 */
private void buildTargetResource(ProcessContext context) {
  if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) {
    try {
      this.transportMapping = new DefaultUdpTransportMapping();
      this.snmp = new Snmp(this.transportMapping);
      if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
      }
      this.transportMapping.listen();
    } catch (Exception e) {
      throw new IllegalStateException("Failed to initialize UDP transport mapping", e);
    }
  }
  if (this.snmpTarget == null) {
    this.snmpTarget = this.createSnmpTarget(context);
  }
  if (this.targetResource == null) {
    this.targetResource = this.finishBuildingTargetResource(context);
  }
}
origin: apache/nifi

/**
 * Construct the PDU to perform the SNMP Get request and returns
 * the result in order to create the flow file.
 * @return {@link ResponseEvent}
 */
public ResponseEvent get() {
  try {
    PDU pdu = null;
    if(this.target.getVersion() == SnmpConstants.version3) {
      pdu = new ScopedPDU();
    } else {
      pdu = new PDU();
    }
    pdu.add(new VariableBinding(this.oid));
    pdu.setType(PDU.GET);
    return this.snmp.get(pdu, this.target);
  } catch (IOException e) {
    logger.error("Failed to get information from SNMP agent; " + this, e);
    throw new ProcessException(e);
  }
}
origin: org.kaazing/snmp4j

 public boolean equals(Object o) {
  if (o instanceof VariableBinding) {
   VariableBinding other = (VariableBinding)o;
   return oid.equals(other.getOid()) &&
     variable.equals(other.getVariable());
  }
  return false;
 }
}
origin: apache/cloudstack

public SnmpHelper(String address, String community) {
  _target = new CommunityTarget();
  _target.setCommunity(new OctetString(community));
  _target.setVersion(SnmpConstants.version2c);
  _target.setAddress(new UdpAddress(address));
  try {
    _snmp = new Snmp(new DefaultUdpTransportMapping());
  } catch (IOException e) {
    _snmp = null;
    throw new CloudRuntimeException(" Error in crearting snmp object, " + e.getMessage());
  }
}
origin: pentaho/pentaho-kettle

private void test() {
 boolean testOK = false;
 String errMsg = null;
 String hostname = transMeta.environmentSubstitute( wServerName.getText() );
 int nrPort = Const.toInt( transMeta.environmentSubstitute( "" + wPort.getText() ), SyslogDefs.DEFAULT_PORT );
 try {
  UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( hostname ), nrPort );
  UserTarget usertarget = new UserTarget();
  usertarget.setAddress( udpAddress );
  testOK = usertarget.getAddress().isValid();
  if ( !testOK ) {
   errMsg = BaseMessages.getString( PKG, "SyslogMessageDialog.CanNotGetAddress", hostname );
  }
 } catch ( Exception e ) {
  errMsg = e.getMessage();
 }
 if ( testOK ) {
  MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_INFORMATION );
  mb.setMessage( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.OK", hostname ) + Const.CR );
  mb.setText( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.Title.Ok" ) );
  mb.open();
 } else {
  MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
  mb.setMessage( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.NOK.ConnectionBad", hostname )
   + Const.CR + errMsg + Const.CR );
  mb.setText( BaseMessages.getString( PKG, "SyslogMessageDialog.Connected.Title.Bad" ) );
  mb.open();
 }
}
origin: apache/cloudstack

  private OID getOID(String oidString) {
    return new OID(oidString);
  }
}
origin: org.snmp4j/snmp4j

public boolean equals(Object o) {
 if (o instanceof VariableBinding) {
  VariableBinding other = (VariableBinding)o;
  return oid.equals(other.getOid()) &&
    variable.equals(other.getVariable());
 }
 return false;
}
origin: pentaho/pentaho-kettle

private void test() {
 boolean testOK = false;
 String errMsg = null;
 String hostname = jobMeta.environmentSubstitute( wServerName.getText() );
 int nrPort =
  Const.toInt( jobMeta.environmentSubstitute( "" + wPort.getText() ), JobEntrySNMPTrap.DEFAULT_PORT );
 try {
  UdpAddress udpAddress = new UdpAddress( InetAddress.getByName( hostname ), nrPort );
  UserTarget usertarget = new UserTarget();
  usertarget.setAddress( udpAddress );
  testOK = usertarget.getAddress().isValid();
  if ( !testOK ) {
   errMsg = BaseMessages.getString( PKG, "JobSNMPTrap.CanNotGetAddress", hostname );
  }
 } catch ( Exception e ) {
  errMsg = e.getMessage();
 }
 if ( testOK ) {
  MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_INFORMATION );
  mb.setMessage( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.OK", hostname ) + Const.CR );
  mb.setText( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.Title.Ok" ) );
  mb.open();
 } else {
  MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
  mb.setMessage( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.NOK.ConnectionBad", hostname )
   + Const.CR + errMsg + Const.CR );
  mb.setText( BaseMessages.getString( PKG, "JobSNMPTrap.Connected.Title.Bad" ) );
  mb.open();
 }
}
org.snmp4j.smi

Most used classes

  • OctetString
  • OID
  • VariableBinding
  • UdpAddress
  • Integer32
  • GenericAddress,
  • TimeTicks,
  • IpAddress,
  • Counter64,
  • Null,
  • UnsignedInteger32,
  • Counter32,
  • AbstractVariable,
  • Gauge32,
  • AssignableFromLong,
  • Opaque,
  • TcpAddress,
  • AssignableFromString,
  • TransportIpAddress
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now