use of org.forgerock.openam.monitoring.cts.FORGEROCK_OPENAM_CTS_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();
}
}
Aggregations