First, we generate the MBeans for our MIBs using the mibgen tool:
$ cd examplesDir/Snmp/Proxy/ $ mibgen -a -d . mib_II_subset.txt mib_demo.txt |
Since the proxy uses the SNMP manager API, the master agent application needs the SNMP manager classes in its classpath, for both compilation and execution. In addition, if the proxy object uses the SNMP OID tables that are generated for its MIBs by the mibgen tool, these classes must also be found in the classpath.
These issues are resolved in our case by having all classes in the example directory and using dot (.) in our usual classpath. Replace the two MIB files with those from the patchfiles directory and then compile all of the classes in the example directory:
$ cp -i patchfiles/*_MIB.java . cp: overwrite ./DEMO_MIB.java (yes/no)? y cp: overwrite ./RFC1213_MIB.java (yes/no)? y $ javac -classpath classpath -d . *.java |
We can run all three applications on the same machine as long as we choose different port numbers. Here we give commands for launching the applications from the same terminal window running the Korn shell. On the Windows NT platform, you will have to launch each application in a separate window, in which case you will not see the sequence of the merged output.
First we launch the subagent; by default it will reply to port 8086, or we can specify a different one on the command line:
$ java -classpath classpath StandAloneAgent 8090 Adding SNMP adaptor using port 8090 Initializing the MIB RFC1213_MIB |
Then we launch the master agent in another terminal window, giving it the subagent's hostname and port number:
$ java -classpath classpath Agent localhost 8090 NOTE: HTML adaptor is bound on TCP port 8082 NOTE: SNMP Adaptor is bound on UDP port 8085 Initializing the MIB snmp:class=DEMO_MIB Initializing the SNMP proxy snmp:class=proxy to query host localhost using port 8090 |
Now you can view the master agent through its HTML adaptor. In your web browser, go to the following URL: http://localhost:8082/.
The class=proxy MBean in the snmp domain is the proxy object, but we cannot see the MBean that it represents. In order to manage the actual MIB, we would have to connect to the subagent, but in our example it is a stand-alone and therefore unreachable.
The name=Demo MBean in the DEMO_MIB domain is the MIB that is served locally. If we click on its name, we can see its initial values.
Finally, we launch the manager application in a third window, giving it the master agent's hostname and port:
$ java -classpath classpath Manager localhost 8085 |
The manager will run through its requests to the master agent. If the output is in the correct order, there are messages from the manager issuing a request, and then the proxy which relays a request for two of the variable to the subagent. The proxy then prints the result it received for the two variables, then the manager receives the final response with all of the variables, including the same two that the proxy just forwarded.
In the name=Demo MBean on the web browser, you should see the new values that were set in the DEMO_MIB as part of the manager's set operation.
Don't forget to stop the agent applications by typing <Control-C> in their terminal windows.