News:

We really need your input in this questionnaire

Main Menu

Can't make AppAgent work

Started by MarkusW, November 05, 2020, 05:20:21 PM

Previous topic - Next topic

MarkusW

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:

static APPAGENT_INIT m_info =
{
        _T("VRECLIENT"),
        _T("root"),
        handleMessage,
        logger,
        1,
        m_parameters,
        0,
        NULL,
        0,
        NULL
};


The call in main():
        printf("Initializing AppAgent...\n");
        if (!AppAgentInit(&m_info))
        {
                printf("Init failed!\n");
        }
        printf("Starting AppAgent...\n");
        AppAgentStart();


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

Hi!

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:


./configure --with-sdk --disable-unicode --prefix=/opt/nxsdk

and then build you application adding

-I /opt/nxsdk/include -L /opt/nxsdk/lib -lappagent -lnetxms


You can get slightly more diagnostic from app agent by setting nxlolg debug callback:

    nxlog_set_debug_writer(DebugWriter);
    nxlog_set_debug_level(9);


With debug writer similar to this:

static void DebugWriter(const TCHAR *tag, const TCHAR *format, va_list args)
{
    if (tag != nullptr)
        printf("[%s] ",tag);
    vprintf(format, args);
    printf("\n");
}


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:

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:

victor@xps13:~$ /opt/netxms/bin/nxappget DEMOAPP DemoApp.Metric1
OK
victor@xps13:~$


Hope this helps!

Best regards,
Victor