Search in sources :

Example 1 with FORGEROCK_OPENAM_SESSION_MIB

use of org.forgerock.openam.monitoring.session.FORGEROCK_OPENAM_SESSION_MIB in project OpenAM by OpenRock.

the class Agent method main.

/**
     * Main entry point.
     * When calling the program, you can specify:
     *  1) nb_traps: number of traps the SNMP agent will send.
     * If not specified, the agent will send traps continuously.
     */
public static void main(String[] args) {
    final MBeanServer server;
    final ObjectName htmlObjName;
    final ObjectName snmpObjName;
    final ObjectName sunMibObjName;
    final ObjectName forgerockCtsMibObjName;
    final ObjectName forgerockPolicyMibObjName;
    final ObjectName forgerockSessionMibObjName;
    final ObjectName trapGeneratorObjName;
    int htmlPort = 8082;
    int snmpPort = 11161;
    //
    if ((args.length != 0) && (args.length != 1)) {
        usage();
        java.lang.System.exit(1);
    } else if (args.length == 1) {
        try {
            nbTraps = (new Integer(args[0])).intValue();
            if (nbTraps < 0) {
                usage();
                System.exit(1);
            }
        } catch (java.lang.NumberFormatException e) {
            usage();
            System.exit(1);
        }
    }
    try {
        List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
        if ((servers != null) && !servers.isEmpty()) {
            server = servers.get(0);
        } else {
            server = MBeanServerFactory.createMBeanServer();
        }
        String domain = server.getDefaultDomain();
        // Create and start the HTML adaptor.
        //
        htmlObjName = new ObjectName(domain + ":class=HtmlAdaptorServer,protocol=html,port=" + htmlPort);
        println("Adding HTML adaptor to MBean server with name \n    " + htmlObjName);
        println("NOTE: HTML adaptor is bound on TCP port " + htmlPort);
        HtmlAdaptorServer htmlAdaptor = new HtmlAdaptorServer(htmlPort);
        server.registerMBean(htmlAdaptor, htmlObjName);
        htmlAdaptor.start();
        //
        // SNMP specific code:
        //
        // Create and start the SNMP adaptor.
        // Specify the port to use in the constructor. 
        // If you want to use the standard port (161) comment out the 
        // following line:
        //   snmpPort = 8085;
        //
        snmpPort = 11161;
        snmpObjName = new ObjectName(domain + ":class=SnmpAdaptorServer,protocol=snmp,port=" + snmpPort);
        println("Adding SNMP adaptor to MBean server with name \n    " + snmpObjName);
        println("NOTE: SNMP Adaptor is bound on UDP port " + snmpPort);
        snmpAdaptor = new SnmpAdaptorServer(snmpPort);
        server.registerMBean(snmpAdaptor, snmpObjName);
        snmpAdaptor.start();
        // Send a coldStart SNMP Trap. 
        // Use port = snmpPort+1.
        //
        print("NOTE: Sending a coldStart SNMP trap" + " to each destination defined in the ACL file...");
        snmpAdaptor.setTrapPort(new Integer(snmpPort + 1));
        snmpAdaptor.snmpV1Trap(0, 0, null);
        println("Done.");
        // Create an RMI connector and start it
        try {
            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");
            JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
            cs.start();
        } catch (Exception ex) {
            println("Error starting RMI : execute rmiregistry 9999; ex=" + ex);
        }
        // Create the MIB II (RFC 1213) and add it to the MBean server.
        //
        sunMibObjName = new ObjectName("snmp:class=SUN_OPENSSO_SERVER_MIB");
        println("Adding SUN_OPENSSO_SERVER_MIB-MIB to MBean server with name" + "\n    " + sunMibObjName);
        // Create an instance of the customized MIB
        //
        SUN_OPENSSO_SERVER_MIB mib2 = new SUN_OPENSSO_SERVER_MIB();
        server.registerMBean(mib2, sunMibObjName);
        forgerockCtsMibObjName = new ObjectName("snmp:class=FORGEROCK_OPENAM_CTS_MIB");
        println("Adding FORGEROCK_OPENAM_CTS_MIB-MIB to MBean server with name" + "\n    " + forgerockCtsMibObjName);
        forgerockPolicyMibObjName = new ObjectName("snmp:class=FORGEROCK_OPENAM_POLICY_MIB");
        println("Adding FORGEROCK_OPENAM_POLICY_MIB-MIB to MBean server with name" + "\n    " + forgerockPolicyMibObjName);
        forgerockSessionMibObjName = new ObjectName("snmp:class=FORGEROCK_OPENAM_SESSION_MIB");
        println("Adding FORGEROCK_OPENAM_SESSION_MIB-MIB to MBean server with name" + "\n    " + forgerockSessionMibObjName);
        FORGEROCK_OPENAM_CTS_MIB mib3 = new FORGEROCK_OPENAM_CTS_MIB();
        server.registerMBean(mib3, forgerockCtsMibObjName);
        FORGEROCK_OPENAM_POLICY_MIB mib4 = new FORGEROCK_OPENAM_POLICY_MIB();
        server.registerMBean(mib4, forgerockPolicyMibObjName);
        FORGEROCK_OPENAM_SESSION_MIB mib5 = new FORGEROCK_OPENAM_SESSION_MIB();
        server.registerMBean(mib5, forgerockSessionMibObjName);
        // Bind the SNMP adaptor to the MIB in order to make the MIB 
        // accessible through the SNMP protocol adaptor.
        // If this step is not performed, the MIB will still live in 
        // the Java DMK agent:
        // its objects will be addressable through HTML but not SNMP.
        //
        mib2.setSnmpAdaptor(snmpAdaptor);
        // Create a LinkTrapGenerator.
        // Specify the ifIndex to use in the object name.
        //
        int ifIndex = 1;
        trapGeneratorObjName = new ObjectName("trapGenerator" + ":class=LinkTrapGenerator,ifIndex=" + ifIndex);
        println("Adding LinkTrapGenerator to MBean server with name" + "\n    " + trapGeneratorObjName);
        LinkTrapGenerator trapGenerator = new LinkTrapGenerator(nbTraps);
        server.registerMBean(trapGenerator, trapGeneratorObjName);
        println("\n>> Press <Enter> if you want to start sending traps.");
        println("   -or-");
        println(">> Press <Ctrl-C> if you want to stop this agent.");
        System.in.read();
        trapGenerator.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) RuntimeOperationsException(javax.management.RuntimeOperationsException) SnmpStatusException(com.sun.management.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) JMXConnectorServer(javax.management.remote.JMXConnectorServer) FORGEROCK_OPENAM_SESSION_MIB(org.forgerock.openam.monitoring.session.FORGEROCK_OPENAM_SESSION_MIB) SnmpAdaptorServer(com.sun.management.comm.SnmpAdaptorServer) FORGEROCK_OPENAM_CTS_MIB(org.forgerock.openam.monitoring.cts.FORGEROCK_OPENAM_CTS_MIB) FORGEROCK_OPENAM_POLICY_MIB(org.forgerock.openam.monitoring.policy.FORGEROCK_OPENAM_POLICY_MIB) HtmlAdaptorServer(com.sun.jdmk.comm.HtmlAdaptorServer) MBeanServer(javax.management.MBeanServer)

Aggregations

HtmlAdaptorServer (com.sun.jdmk.comm.HtmlAdaptorServer)1 SnmpAdaptorServer (com.sun.management.comm.SnmpAdaptorServer)1 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 JMException (javax.management.JMException)1 JMRuntimeException (javax.management.JMRuntimeException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 ObjectName (javax.management.ObjectName)1 RuntimeOperationsException (javax.management.RuntimeOperationsException)1 JMXConnectorServer (javax.management.remote.JMXConnectorServer)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 FORGEROCK_OPENAM_CTS_MIB (org.forgerock.openam.monitoring.cts.FORGEROCK_OPENAM_CTS_MIB)1 FORGEROCK_OPENAM_POLICY_MIB (org.forgerock.openam.monitoring.policy.FORGEROCK_OPENAM_POLICY_MIB)1 FORGEROCK_OPENAM_SESSION_MIB (org.forgerock.openam.monitoring.session.FORGEROCK_OPENAM_SESSION_MIB)1