This page describes how-to integrate AgenPro generated code for SNMP4J-Agent into an agent's main program.
Although this description uses AgenPro Maven-Plugin files, it steps described herein are not useful when actually also using the AgenPro-Maven-Plugin. The plugin facilitates already many of the below steps. Please read the AgenPro Manual for details. |
The code has been generated by AgenPro into a folder that can be used to further develop the agent software. Otherwise, modifications to the generated code cannot be (easily) integrated into regenerated code, for example if there is a MIB specification update.
For this tutorial that gen-folder is C:\Users\myuser\Documents\agenpro4\generated\snmp4j\src\org\snmp4j\agent\tutorial.
You can replace the name gen-folder in the following by this folder.
C:\Users\myuser\Documents\agenpro4\lib
for that. You can dowload latest release JARs from the AGENT++ Maven repository at: https://oosnmp.net/dist/release.Optionally: Only if you are using your own main agent program implementation, you need first to fix the import section as described in the box below and then add the following function registerMIBs()
to that class:
// Alternatively you can also import the complete package you specified in AgenPro project wizard step 1: // import <package>.*; import org.snmp4j.agent.tutorial.Modules; import org.snmp4j.agent.tutorial.Snmp4jAgentTutorialMib; |
/** * Register your own MIB modules in the specified context of the agent. * The {@link MOFactory} provided to the <code>Modules</code> constructor * is returned by {@link #getFactory()}. */ protected void registerMIBs() { if (modules == null) { modules = new Modules(getFactory()); } try { modules.registerMOs(server, null); } catch (DuplicateRegistrationException drex) { logger.error("Duplicate registration: "+drex.getMessage()+"."+ " MIB object registration may be incomplete!", drex); } } |
Then call the above function in your agent initialization code before the agent is actually started with agent.run():
public void run() { // initialize agent before registering our own modules agent.initialize(); // this requires sysUpTime to be available. registerMIBs(); // <---- here the MIB module registration is called // add proxy forwarder agent.setupProxyForwarder(); // now continue agent setup and launch it. agent.run(); } |
Compile the sources with Maven:
cd C: cd \Users\myuser\Documents\agenpro4\generated\snmp4j\ mvn clean install |
Run the agent:
java -jar target\tutorial-1.0.0-SNAPSHOT-jar-with-dependencies.jar udp:0.0.0.0/161 |
or alternatively without Maven support:
cd ..\..\..\.. java -cp .;..\lib\* org.snmp4j.agent.tutorial.Agent udp:0.0.0.0/161 |
You may also want to use visual panels to communicate related information, tips or things users need to be aware of. |
Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.
|