Examples of SNMPSession


Examples of com.sun.management.snmp.manager.SnmpSession

      switch (version) {
        case 1:
        case 2:
          // Create the session
          //
          session = new SnmpSession("Set V" + version + " session");

          // Create an SnmpPeer object for representing the entity
          // to communicate with.
          //
          final SnmpPeer agent = new SnmpPeer(remoteHost, port);

          // Specify the read and write community to be used
          //
          final SnmpParameters params = new SnmpParameters(
                  community,
                  community);

          // Specify the protocol version
          //
          switch (version) {
            case 1:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionOne);
              break;
            case 2:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionTwo);
              break;
            default:
              break;
          }

          // Associate the parameters with the agent
          //
          agent.setTimeout(timeOut);
          agent.setMaxTries(maxRetries);
          agent.setParams(params);

          // Set the default peer (agent) to a SnmpSession
          //
          session.setDefaultPeer(agent);
          break;
        case 3:
          // Custom engine parameters
          final SnmpEngineParameters engineParameters =
                  new SnmpEngineParameters();
         
          // Activate encryption
          engineParameters.activateEncryption();
         
          // Set the security file
          engineParameters.setSecurityFile(securityFile);

          // Create the session
          //
          session = new SnmpSession(
                  engineParameters,
                  null,
                  "Set V3 session",
                  null);
View Full Code Here

Examples of com.sun.management.snmp.manager.SnmpSession

      switch (version) {
        case 1:
        case 2:
          // Create the session
          //
          session = new SnmpSession("Get V" + version + " session");

          // Disable PduFixedOnError option
          //
          session.snmpOptions.setPduFixedOnError(false);

          // Create an SnmpPeer object for representing the entity
          // to communicate with.
          //
          final SnmpPeer agent = new SnmpPeer(remoteHost, port);

          // Specify the read and write community to be used
          //
          final SnmpParameters params = new SnmpParameters(
                  community,
                  community);

          // Specify the protocol version
          //
          switch (version) {
            case 1:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionOne);
              break;
            case 2:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionTwo);
              break;
          }

          // Associate the parameters with the agent
          //
          agent.setTimeout(timeOut);
          agent.setMaxTries(maxRetries);
          agent.setParams(params);

          // Set the default peer (agent) to a SnmpSession
          //
          session.setDefaultPeer(agent);
          break;
        case 3:
          // Custom engine parameters
          final SnmpEngineParameters engineParameters =
                  new SnmpEngineParameters();

          // Activate encryption
          engineParameters.activateEncryption();

          // Set the security file
          engineParameters.setSecurityFile(securityFile);

          // Create the session
          //
          session = new SnmpSession(
                  engineParameters,
                  null,
                  "Get V3 session",
                  null);
View Full Code Here

Examples of com.sun.management.snmp.manager.SnmpSession

        // Build the session. A session creates, controls and
        // manages one or more requests.
        //
        try {

            final SnmpSession session =
                    new SnmpSession("SyncManager session");

            // A default peer (agent) can be associated to a SnmpSession.
            // When invoking a service provided by the SnmpSession, if the
            // agent is not specified, the session will perform the service
            // using the default peer as the target of the service.
            //
            session.setDefaultPeer(agent);

            // Build the list of variables you want to query.
            // For debug purposes, you can associate a name to your list.
            //
            final SnmpVarBindList list =
                    new SnmpVarBindList("SyncManager varbind list");

            // We want to read the "dsServerDescription" variable.
            //
            // We will thus query "dsServerDescription"
            //
            list.addVarBind(attributeName);

            // Make the SNMP get request and wait for the result.
            //
            SnmpRequest request = session.snmpGetNextRequest(null, list);

            final boolean completed = request.waitForCompletion(0);

            // Check for a timeout of the request.
            //
            if (completed == false) {
                fail("SyncManager::main: Request timed out." +
                        " Check reachability of agent");
                return;
            }

            // Now we have a response. Check if the response contains
            // an error.
            //
            final int errorStatus = request.getErrorStatus();
            if (errorStatus != SnmpDefinitions.snmpRspNoError) {
                fail("Error status = " +
                        SnmpRequest.snmpErrorToString(errorStatus));
                fail("Error index = " + request.getErrorIndex());
                return;
            }

            // Now we shall display the content of the result.
            //
            final SnmpVarBindList result = request.getResponseVarBindList();
            assertNotNull(result);
            assertEquals(result.getVarBindCount(), 1);


            // Nicely stop the session
            //
            session.destroySession();

        } catch (Exception exception) {
            fail("CheckAttribute");
        }
View Full Code Here

Examples of com.sun.management.snmp.manager.SnmpSession

            agent.setParams(params);

            // Build the session. A session creates, controls and
            // manages one or more requests.
            //
            final SnmpSession session =
                    new SnmpSession("SyncManager session");

            // A default peer (agent) can be associated to a SnmpSession.
            // When invoking a service provided by the SnmpSession, if the
            // agent is not specified, the session will perform the service
            // using the default peer as the target of the service.
            //
            session.setDefaultPeer(agent);

            // Build the list of variables you want to query.
            // For debug purposes, you can associate a name to your list.
            //
            final SnmpVarBindList list =
                    new SnmpVarBindList("SyncManager varbind list");

            // We want to read the "dsServerDescription" variable.
            //
            // We will thus query "dsServerDescription"
            //
            list.addVarBind("dsServerDescription");

            // Make the SNMP get request and wait for the result.
            //
            SnmpRequest request = session.snmpGetNextRequest(null, list);

            final boolean completed = request.waitForCompletion(0);

            // Check for a timeout of the request.
            //
            if (completed == false) {
                fail("SyncManager::main: Request timed out." +
                        " Check reachability of agent");
                return;
            }

            // Now we have a response. Check if the response contains
            // an error.
            //
            final int errorStatus = request.getErrorStatus();
            if (errorStatus != SnmpDefinitions.snmpRspNoError) {
                fail("Error status = " +
                        SnmpRequest.snmpErrorToString(errorStatus));
                fail("Error index = " + request.getErrorIndex());
                return;
            }

            // Now we shall display the content of the result.
            //
            final SnmpVarBindList result = request.getResponseVarBindList();
            assertNotNull(result);
            assertEquals(result.getVarBindCount(), 1);
            assertEquals(result.getVarBindAt(0).isValidValue(), expectedResult);


            // Nicely stop the session
            //
            session.destroySession();

            //
            // That's all !
            //
            return;
View Full Code Here

Examples of com.sun.management.snmp.manager.SnmpSession

    {
      String host = InetAddress.getLocalHost().getCanonicalHostName();
      SnmpOidTableSupport oidTable = new DIRECTORY_SERVER_MIBOidTable();
      SnmpOid.setSnmpOidTable(oidTable);

      SnmpSession session = new SnmpSession("SyncManagerV3 session");
      SnmpEngine engine = session.getEngine();
      return new SnmpUsmPeer(engine, host, port);
    }
    catch (Exception ex)
    {
      return null;
View Full Code Here

Examples of org.opennms.protocols.snmp.SnmpSession

      }
           
      parameters.setReadCommunity(this.readCommunity);
      peer.setParameters(parameters);
           
      this.session = new SnmpSession(peer);
      this.session.setDefaultHandler(this);
   }
View Full Code Here

Examples of org.rhq.plugins.www.snmp.SNMPSession

        boolean configured = false;

        try {

            SNMPSession snmpSession = getSNMPSession();
            if (!snmpSession.ping()) {
                LOG.warn("Failed to connect to SNMP agent at "
                    + snmpSession
                    + "\n"
                    + ". Make sure\n1) the managed Apache server has been instrumented with the JON SNMP module,\n"
                    + "2) the Apache server is running, and\n"
View Full Code Here

Examples of org.rhq.plugins.www.snmp.SNMPSession

            getBMXValues(report, schedules);
        else
            getSNMPValues(report, schedules);
    }
    private void getSNMPValues(MeasurementReport report, Set<MeasurementScheduleRequest> schedules) throws Exception {
        SNMPSession snmpSession = getSNMPSession();
        boolean snmpPresent = snmpSession.ping();

        for (MeasurementScheduleRequest schedule : schedules) {
            String metricName = schedule.getName();
            if (metricName.equals(SERVER_BUILT_TRAIT)) {
                MeasurementDataTrait trait = new MeasurementDataTrait(schedule, this.binaryInfo.getBuilt());
                report.addData(trait);
            } else if (metricName.equals("rhq_avail_ping_time")) {
                if (availPingTime == -1)
                    continue; // Skip if we have no data
                MeasurementDataNumeric num = new MeasurementDataNumeric(schedule, (double) availPingTime);
                report.addData(num);
            } else {
                // Assume anything else is an SNMP metric.
                if (!snmpPresent)
                    continue; // Skip this metric if no SNMP present

                try {
                    //noinspection UnnecessaryLocalVariable
                    String mibName = metricName;
                    List<SNMPValue> snmpValues = snmpSession.getColumn(mibName);
                    if (snmpValues.isEmpty()) {
                        LOG.error("No values found for MIB name [" + mibName + "].");
                        continue;
                    }
View Full Code Here

Examples of org.rhq.plugins.www.snmp.SNMPSession

        return ApacheServerComponent.getSNMPSession(this.snmpClient, this.resourceContext.getPluginConfiguration());
    }

    @NotNull
    public static SNMPSession getSNMPSession(SNMPClient snmpClient, Configuration pluginConfig) throws Exception {
        SNMPSession snmpSession;
        try {
            String host = pluginConfig.getSimple(PLUGIN_CONFIG_PROP_SNMP_AGENT_HOST).getStringValue();
            String portString = pluginConfig.getSimple(PLUGIN_CONFIG_PROP_SNMP_AGENT_PORT).getStringValue();
            int port = Integer.valueOf(portString);
            String community = pluginConfig.getSimple(PLUGIN_CONFIG_PROP_SNMP_AGENT_COMMUNITY).getStringValue();
View Full Code Here

Examples of org.rhq.plugins.www.snmp.SNMPSession

                    return DOWN;
                }

                //ok, so the vhost is present. Now let's just ping the SNMP module to see
                //if it is reachable and base our availability on that...
                SNMPSession snmpSession = resourceContext.getParentResourceComponent().getSNMPSession();

                return snmpSession.ping() ? UP : DOWN;
            } catch (Exception e) {
                LOG.debug("Determining the availability of the vhost [" + resourceContext.getResourceKey()
                    + "] using SNMP failed.", e);
                return DOWN;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.