Java SubAgent and OPC UA

Started by Sash, September 19, 2022, 03:12:33 PM

Previous topic - Next topic

Sash

Could someone explainme how to use Java Subagent to get Informations from OPC UA please?
I have configured my nxagentd.conf on the NetXMS Server, and Oracle Java 1.8 is installed.:

#
# NetXMS agent configuration file
# Created by agent installer at ********
#

MasterServers = *******
ConfigIncludeDir = C:\NetXMS\etc\nxagentd.conf.d
LogFile = C:\NetXMS\log\nxagentd.log
FileStore = C:\NetXMS\var
SubAgent = portcheck.nsm
SubAgent = ssh.nsm
SubAgent = winperf.nsm
SubAgent = wmi.nsm
SubAgent = java.nsm

[JAVA]
Plugin = opcua.jar

Seems that the Java Subagent is not loaded...

Alex Kirhenshtein

Check agent's log on debug level 1 or higher, there should be lines like
2022.09.19 15:47:54.074 *D* [                  ] Initializing Java subagent
2022.09.19 15:47:54.074 *D* [                  ] JAVA: Default JVM: /Users/alk/.asdf/installs/java/zulu-17.32.13/zulu-17.jdk/Contents/Home/lib//server/libjvm.dylib
2022.09.19 15:47:54.074 *D* [                  ] JAVA: using JVM /Users/alk/.asdf/installs/java/zulu-17.32.13/zulu-17.jdk/Contents/Home/lib//server/libjvm.dylib
2022.09.19 15:47:54.095 *D* [                  ] Java SubAgent created

If JVM is not found, you can set it with parameter "JVM=..." in "JAVA" section.

Alex Kirhenshtein

Also I found an issue with plugin packaging, so bundled jar might not work.
Replace $NETXMS_HOME/lib/netxms/java/opcua.jar with this version: https://cloud.radensolutions.com/s/WazFQAC3KrnJpTM.

Sash

Thanks a lot Alex!
The Agent is loaded now.
Could you please explain me, where I have to define the OPC UA Servers, and how I could connect to them and get data?

Here is my Log:
2022.09.20 09:27:31.565 *D* [                  ] Initializing Java subagent
2022.09.20 09:27:31.565 *D* [                  ] JAVA: Default JVM: C:\Program Files\Eclipse Adoptium\jdk-17.0.4.101-hotspot\\bin\server\jvm.dll
2022.09.20 09:27:31.565 *D* [                  ] JAVA: using JVM C:\Program Files\Eclipse Adoptium\jdk-17.0.4.101-hotspot\\bin\server\jvm.dll
2022.09.20 09:27:32.035 *D* [java.runtime      ] JavaBridge: Java VM created
2022.09.20 09:27:32.136 *D* [                  ] Java SubAgent created
2022.09.20 09:27:32.136 *D* [                  ] SubAgent.loadPlugin(opcua.jar)
2022.09.20 09:27:32.151 *D* [                  ] Loading plugin file "C:\NetXMS\lib\java\opcua.jar"
2022.09.20 09:27:32.220 *D* [                  ] Java plugin OPCUA (com.radensolutions.netxms.agent.opcua.OpcUaPlugin) loaded
2022.09.20 09:27:32.220 *D* [                  ] JAVA: subagent initialization started
2022.09.20 09:27:32.220 *D* [                  ] JAVA: exception in plugin OPCUA initialization handler: org.netxms.agent.PluginInitException: OPCUA servers not defined
2022.09.20 09:27:32.220 *D* [                  ] JAVA: subagent initialization completed
2022.09.20 09:27:32.220 *I* [subagents          ] Subagent "JAVA" (java.nsm) loaded successfully (version 4.1.420)

Alex Kirhenshtein

#4
You need to define section "OPCUA" and add one or more "Server" parameters. Format for server record is "name:[login[/password]@]url" (parts in square brackets are optional)
You can also change timeout from defaul 5 seconds (parameter "Timeout", in ms).

Example:

[OPCUA]
Timeout=5000 # timeout for network operations
Server=s1:opc.tcp://milo.digitalpetri.com:62541/milo # anonymous connection
Server=s2:[email protected]://milo.digitalpetri.com:62541/milo # login "user1", empty password
Server=s3:user1/[email protected]://milo.digitalpetri.com:62541/milo # login "user1", password "password"

Once configured, you can collect metric OPCUA.NodeValue(server name, node id), where "server name" is s1, s2, etc. (values from configuration).

Example:
❯ nxget 127.0.0.1 'OPCUA.NodeValue(s1,ns=0;i=2257)'
Variant{value=DateTime{utcTime=133058236247170000, javaDate=Wed Aug 24 17:07:04 EEST 2022}}

Alex Kirhenshtein

I just realised that we do not support Variant in the responce - we'll add support in future releases

Alex Kirhenshtein

Fixed in ee84926388, will be included in upcoming 4.2 release

Sash