Author Topic: Can't make AppAgent work  (Read 259 times)


  • Newbie
  • *
  • Posts: 16
    • View Profile
Can't make AppAgent work
« on: November 05, 2020, 05:20:21 pm »
I'm trying to integrate AppAgent into a small C app. I'm doing a successful AppAgentInit, and then a AppAgentStart call. There are no obvious indications that it doesn't work, except that "nxappget" says "ERROR: Cannot connect to application agent" when I run it with the app name supplied in the APPAGENT_INIT struct. When configuring the local nxagentd with an AppAgent, it outputs the same error message in the logs periodically.

I've narrowed it down to the fact that it doesn't create a named pipe in /tmp as I would expect from reading the source. But I get no indication as to why. I've tried as root as well without success, so it doesn't seem to be a permission issue.

There's no helpful log output anywhere.

I'm using the libraries from NetXMS 3.5.152 source package on a Ubuntu 18.04 machine.

Init data:

Code: [Select]
static APPAGENT_INIT m_info =

The call in main():
Code: [Select]
        printf("Initializing AppAgent...\n");
        if (!AppAgentInit(&m_info))
                printf("Init failed!\n");
        printf("Starting AppAgent...\n");

At this point I start the rest of the application logic, which works well. But the AppAgent part just won't work. I'm not even sure that the pipe listener thread is running at all, and I'm not sure how to check it.

Do you have any hints on where to look for faults?

Thank you in advance!

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 7137
    • View Profile
Re: Can't make AppAgent work
« Reply #1 on: November 14, 2020, 11:40:53 am »

Most likely problem is with UNICODE. By default NetXMS is build in UNICODE mode, so it uses wchar_t for all characters. I suppose that your program built as non-UNICODE, so it actually passes char to functions from libappagent that actually expects wchar_t. I'd recommend to build app agent separately with UNICODE disabled and link that version with your application.

For example, you can configure NetXMS sources like this:

Code: [Select]
./configure --with-sdk --disable-unicode --prefix=/opt/nxsdk
and then build you application adding
Code: [Select]
-I /opt/nxsdk/include -L /opt/nxsdk/lib -lappagent -lnetxms

You can get slightly more diagnostic from app agent by setting nxlolg debug callback:
Code: [Select]

With debug writer similar to this:
Code: [Select]
static void DebugWriter(const TCHAR *tag, const TCHAR *format, va_list args)
    if (tag != nullptr)
        printf("[%s] ",tag);
    vprintf(format, args);

Attached is functional example for reference. I've compiled it as following:
g++ -o demoapp demoapp.cpp -I /opt/nxsdk/include -L /opt/nxsdk/lib -lappagent -lnetxms

Sample app output:
Code: [Select]
victor@xps13:~/Source/appagentdemo$ LD_LIBRARY_PATH=/opt/nxsdk/lib ./demoapp
Initializing AppAgent...
Starting AppAgent...
Application agent startedApp started
NamedPipeListener(appagent.DEMOAPP): waiting for connection
NamedPipeListener(appagent.DEMOAPP): accepted connection by user victor

nxappget output:
Code: [Select]
victor@xps13:~$ /opt/netxms/bin/nxappget DEMOAPP DemoApp.Metric1

Hope this helps!

Best regards,