How to generate Java code from the IF-MIB using AgenPro

I am currently trying to learn how to generate Java code with the AgenPro application on MacOS Ventura 13.5. I am trying it with the IF-MIB without success. I keep getting the attached 5 errors:

Following is how to reproduce the issue:

MacOS Ventura 13.5 (Safari)

Download AgenPro 5.1.0

https://agentpp.com

Click Download

Click DMG (AgenPro 5.1.0 - Installer for macOS /w OpenJDK 20 included)

Install AgenPro 5.1.0

agp-5.1.0.dmg (double click)

AgenPro License Agreement (Agree)

Drag & Drop AgenPro App to the Applications folder

Eject AgenPro folder

Run AgenPro 5.1.0

Generate Code

Load IF-MIB

  • File → Open/Close MIB

  • Select IF-MIB from the list

  • Click the Add button

  • Click OK button

  • Click the Yes button

Project → Generate

Wait for the running jobs to finish

The above 5 errors are emitted

===
Notice that there is no snmp4j-agent_3_1 directory under the templates directory:

$ ls /var/tmp/agenpro5/templates
README.txt debug snmp4j-agent-v3
agent++v4 snmp++ snmp4j-model
agent++v4_by_selection snmp4j-agent-v2

What I am missing?

Thank you,

Bill

Hi Bill,

I assume that you have a AgenPro configuration file still in your home directory that contains an old project generation configuration, because in your steps, the “Project/Open” step seems to be missing.
In the project file, the correct template paths should be configured.

To fix your setup, you can choose “Project/Edit” and replace the string “snmp4j-agent_3_1” by “snmp4j-agent-v3” in all paths. That will remove the errors from the code generation.
However, the never project file might contain additional code generations or formatting information, that had not been yet included in the “old” project configuration present on your system.

Hope this helps.

Best regards,
Frank

Hello Frank:

I was able to resolve the 5 errors after fixing my setup via Project/Edit as you suggested.

Now the Java code generation process hangs with the following dialog (it’s been there almost 1/2 hour):

Screenshot 2023-07-26 at 2.49.31 PM

Any ideas on how to fix it?

Best Regards,

Bill

Do you see anything in the log panel?
The code generation is very quick, so it will never take more than a couple of seconds.
It is unusual that the progress dialog does not disappear. That’s why I assume a rather fatal error in the log. The job name is a bit unusual - I would have expected an MIB module name here instead of “MimeMhs”. Maybe that points in the right direction?
For SNMP4J agent code generation the first job generates the MIB module names for the second job phase.

Hello Frank:

There is nothing in the log panel. I even tried saving the logging output to a log file and the generated file is empty. I get the same dialog hang with the INET-ADDRESS-MIB. I am not sure why it shows MimeMhs as the MIB module–not sure what that is.

I am currently evaluating AgenPro for a big project that is about to start. Do you know if there is someone from the AgenPro development team that can help? (Not sure if you are part of the AgenPro development team).

Regards,

Bill

Hi Bill,
I am the developer of AgenPro. Maybe you can send screenshots with the content of all the project wizard pages and the log panel (with DEBUG level enabled) to support@agentpp.com
I guess there is some fundamental misunderstanding or misconfiguration.

You can send me as alternative to the screenshots the AgenPro4.cf file to the above email address. That file contains the complete configuration.

BTW, are you able to load MIB files from your repository into the AgenPro UI using File>Open/Close MIB? Then you MIB repository works.

Hello Frank:

Thank you again for all of your help.

I have sent my AgenPro4.cf file as well as some screen shots to support@agentpp.com.

I am able to load the IF-MIB file into the AgenPro UI using File>Open/Close:

Regards,

Bill

To generate code for a specific selected MIB like shown in the below screenshot (e.g., IF-MIB) the checkbox to create code for all MIB modules should be unchecked in the project editor:

The main issue is that the Java Google [built-in] formatter throws an exception with the latest JDKs (those shipped with DMG and MSI packages) because of:

java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x5cc73178) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x5cc73178

As a workaround you can remove the Google formatter from the configuration as follows:

Another issue with the job template configuration (it is not the best possible): To update it to the latest predefined one, you can use the “predefined job template” named snmp4j-agent-v3.jobs as shown by the following screenshot:

A workaround for the code formatter issue is running AgenPro 5.1.0 JAR with the following start scripts:

Unix/MacOS:

#//bin/sh
java --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED -jar agenpro4.jar $*

Windows

@echo OFF
java --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED -jar agenpro4.jar %*

Hello Frank:

I am now able to generate Java code from the IF-MIB module after applying your suggested workarounds. Thanks!

I could not run your suggested start scripts because I do not have the agenpro4.jar file. I am using the DMG version of AgenPro 5.1.0 on the Mac.

Anyway, next I would like to try out the SNMP agent to see if I am able to make SNMP calls against the code that was generated for the IF-MIB module. Is there a quick tutorial on that? (I’ll also take a look at the manual).

Regards,

Bill

Hello Bill,

AgenPro 5.1.1 is now available. If you start AgenPro now, the new version will be suggested for upgrade.
It fixes the code formatter issue.

Have you already successfully compiled the agent?
Or do you want to explore the simulation agent built-into AgenPro?

If you would like to run the generated and compiled agent, you can execute:

java -jar snmp4j-agenpro-agent-1.0-SNAPSHOT-jar-with-dependencies.jar udp:0.0.0.0/4700

and access it using a SNMP tool (like MIB Explorer) using IP 127.0.0.1 and port 4700 with community “public”.

Best regards,
Frank

Hello Frank:

Yes, I was able to upgrade to AgentPro 5.1.1 but it prompted me to install it again & again even though it was already installed. I finally just cancelled the prompt to get me out of the infinite loop.

I am not able to successfully compile the agent. I am getting the following error:

╭─bdurant@Macbook2 /var/tmp/agenpro5/generated/snmp4j 
╰─$ mvn --version
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T00:58:13-07:00)
Maven home: /Applications/apache-maven-3.5.2
Java version: 11.0.16.1, vendor: Amazon.com Inc.
Java home: /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "13.5", arch: "x86_64", family: "mac"

╭─bdurant@Macbook2 /var/tmp/agenpro5/generated/snmp4j 
╰─$ mvn clean install
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Malformed POM /private/var/tmp/agenpro5/generated/snmp4j/pom.xml: Unrecognised tag: 'exclusions' (position: START_TAG seen ...</exclusion>\n\t\t\t\t<exclusions>... @55:17)  @ /private/var/tmp/agenpro5/generated/snmp4j/pom.xml, line 55, column 17
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project org.snmp4j.agent:snmp4j-agent-gen:1.0.0-SNAPSHOT (/private/var/tmp/agenpro5/generated/snmp4j/pom.xml) has 1 error
[ERROR]     Malformed POM /private/var/tmp/agenpro5/generated/snmp4j/pom.xml: Unrecognised tag: 'exclusions' (position: START_TAG seen ...</exclusion>\n\t\t\t\t<exclusions>... @55:17)  @ /private/var/tmp/agenpro5/generated/snmp4j/pom.xml, line 55, column 17 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException

Here are the contents of the generated pom.xml file:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!-- |:AgenPro|=pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.snmp4j.agent</groupId>
<artifactId>snmp4j-agent-gen</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>AgenProAgent</name>
<url>https://snmp4j.org</url>
<properties>
<sourceEncoding>UTF-8</sourceEncoding>
<resourceEncoding>UTF-8</resourceEncoding>
</properties>
<organization>
<name>SNMP4J.org</name>
<url>https://snmp4j.org</url>
</organization>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>3.7.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j-agent</artifactId>
<version>3.6.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<!--  Exclude transitive dependency to SNMP4J  -->
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j-agent-db</artifactId>
<version>3.6.3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<!--  Exclude transitive dependency to SNMP4J  -->
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
</exclusion>
<exclusions>
<exclusion>
<!--  Exclude transitive dependency to SNMP4J  -->
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
</exclusion>
<exclusion>
<!--  Exclude transitive dependency to SNMP4J  -->
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j.agent</artifactId>
</exclusion>
</exclusions>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<stylesheet>java</stylesheet>
<doctitle>${project.name} ${project.version}</doctitle>
<windowtitle>${project.name} ${project.version}</windowtitle>
<docfilessubdirs>true</docfilessubdirs>
<show>protected</show>
<version/>
<author/>
<encoding>UTF-8</encoding>
<additionalOptions>-html5 -Xdoclint:-html</additionalOptions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>9</source>
<target>9</target>
<release>9</release>
<encoding>UTF-8</encoding>
<compilerArgument>-Xlint:all</compilerArgument>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.snmp4j.agent.tutorial.Agent</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<!-- |AgenPro:| -->

I also explored the simulation agent built-into AgenPro and it just hangs as follows:
AgenPro-Agent-Stuck

On another note, I am wondering why the project template setting defaults to snmp4j-agent_3_1 when it is clearly invalid/non-existent.

To fix that error, you can remove all

<exclusions>
...
</exclusions>

sections from the generated pom.xml file (or from the template to fix it permanently). I have to check why this isn’t working anymore.

In addition, there seems to be a problem with the

module-info.java:[13,29] package is empty or does not exist: org.snmp4j.agent.gen

You can change that line to

    exports org.snmp4j.agent.tutorial;

to match your package settings in the code generation project.

The simulation agent is working for me. It takes a few seconds to finish the starting, because the port needs to be bound, but hen it is running. You can check the progress in the Log panel if you have activated at least the INFO level.

Note: Please disable “code generation preview” if you are using maven while AgenPro is open. Maven triggers a lot of operating system file update events that “overload” the diff view of AgenPro with update events. Although I tried to mitigate this issue by some queuing techniques, it does not seem to finally help a lot. I am still working on it.

Hello Frank:

I was able to compile the agent after removing the exclusions from the generated POM file manually–not sure how about the process for modifying the templates to do the same.

So I started the agent and while it throws a java exception at the end, it appears to be running:

─bdurant@Macbook2 /var/tmp/agenpro5/generated/snmp4j/target 
╰─$ java -jar snmp4j-agent-gen-1.0.0-SNAPSHOT-jar-with-dependencies.jar udp:0.0.0.0/4700
Jul 27, 2023 5:56:22 PM org.snmp4j.log.JavaLogAdapter log
INFO: Engine boots is: 1 for engine ID: null
Jul 27, 2023 5:56:22 PM org.snmp4j.log.JavaLogAdapter log
...
...
INFO: Registered MO [DefaultMOTable] in default context with scope DefaultMOTable[id=1.3.6.1.2.1.31.1.4.1,index=MOTableIndex{subindexes=[MOTableSubIndex{smiSyntax=2, minLength=1, maxLength=1, oid=1.3.6.1.2.1.2.2.1.1}, MOTableSubIndex{smiSyntax=4, minLength=0, maxLength=128, oid=1.3.6.1.2.1.31.1.4.1.1}], impliedLength=false, validator=org.snmp4j.agent.tutorial.IfMib$5@306e95ec},columns=[org.snmp4j.agent.mo.snmp.RowStatus[columnID=2,syntax=2,default=null,mutableInService=true,mandatory=true], org.snmp4j.agent.mo.snmp.Enumerated[columnID=3,syntax=2,default=2,mutableInService=true,mandatory=true]]]
Exception in thread "main" java.lang.NumberFormatException: For input string: "1#--|AgenPro:|--#"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.base/java.lang.Integer.parseInt(Integer.java:652)
	at java.base/java.lang.Integer.parseInt(Integer.java:770)
	at org.snmp4j.agent.io.prop.PropertyMOInput.createVariableFromString(PropertyMOInput.java:506)
	at org.snmp4j.agent.io.prop.PropertyMOInput.scanDataIndexVariables(PropertyMOInput.java:326)
	at org.snmp4j.agent.io.prop.PropertyMOInput.readSequence(PropertyMOInput.java:423)
	at org.snmp4j.agent.mo.DefaultMOTable.load(DefaultMOTable.java:1600)
	at org.snmp4j.agent.io.MOServerPersistence.readData(MOServerPersistence.java:162)
	at org.snmp4j.agent.io.MOServerPersistence.loadData(MOServerPersistence.java:104)
	at org.snmp4j.agent.AgentConfigManager.configure(AgentConfigManager.java:787)
	at org.snmp4j.agent.AgentConfigManager.run(AgentConfigManager.java:322)
	at org.snmp4j.agent.tutorial.Agent.run(Agent.java:131)
	at org.snmp4j.agent.tutorial.Agent.defaultMain(Agent.java:309)
	at org.snmp4j.agent.tutorial.Agent.main(Agent.java:334)

However, I not able to access it even though the Firewall is disabled:

╰─$ snmpget -v2c -c public 127.0.0.1:4700 IF-MIB::ifDescr.1                 1 ↵
Timeout: No Response from 127.0.0.1:4700.
╭─bdurant@Macbook2 ~/scripts 
╰─$ snmpwalk -v 2c -c public 127.0.0.1:4700                                 1 ↵
Timeout: No Response from 127.0.0.1:4700
╭─bdurant@Macbook2 ~/scripts 
╰─$ sudo lsof -i :4700                                                      1 ↵
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    37244 bdurant    5u  IPv6 0x8cde41d1b00b35f5      0t0  UDP *:netxms-agent

As for the simulation agent issue, I am still getting the hang. I looked into the UI and did not find any way to activate INFO log level. Nothing is showing up in the log panel.

Regarding the templates, there will be a fix available soon (with 5.1.2).

The exception comes from a template issue too, in the agent properties file where its initial configuration is stored, some data has not been generated appropriately. I will check that too.

For the simulation agent log: Please got the the log panel and click on the small + or arrow sign on the categories:

and select DEBUG on the Agent category at least. Alternatively doing it on the root level would work too.

This error I cannot reproduce on my system. The properties AgenPro generates for me ends with:

snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.3={i}1
#--|AgenPro:|--#

Here the line break is correct. That does not seem to be the case on your system. Either the corresponding template was edited, or there is an issue with the newline and carriage return interpretation on your system (can be caused by moving a Windows file to Unix or vice versa)

Hello Frank:

I am using only MacOS Ventura 13.5. I am not using Windows or Linux.

Here are last 5 lines of my AgenPro properties file:

╰─$ tail -5 /var/tmp/agenpro5/generated/snmp4j/target/classes/org/snmp4j/agent/tutorial/AgentConfig.properties 
snmp4j.agent.cfg.index.1.3.6.1.6.3.13.1.3.1.1={o}8.'filtered'.1.3.6
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.0={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.1={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.2={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.3={i}1#--|AgenPro:|--#

And here is the same last 5 lines displaying all non-printing characters:

╰─$ tail -5 /var/tmp/agenpro5/generated/snmp4j/target/classes/org/snmp4j/agent/tutorial/AgentConfig.properties | cat -e
snmp4j.agent.cfg.index.1.3.6.1.6.3.13.1.3.1.1={o}8.'filtered'.1.3.6$
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.0={s}$
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.1={i}1$
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.2={i}4$
snmp4j.agent.cfg.value.1.3.6.1.6.3.13.1.3.1.1.3={i}1#--|AgenPro:|--#$

Regards,

Bill

Hello Frank:

I was able to configure DEBUG for the Agent category via the Logging Properties but I am still not seeing any logs while the Simulation Agent is running. The Simulation Agent still hangs for me. I am on MacOS Ventura 13.5. I am not using any other operating system. I am not seeing a way to set the log level to DEBUG at the root level.

Regards,

Bill