Page 1 of 1

NSCA Win32 Client - echo problem

Posted: Thu Jan 16, 2014 12:43 pm
by drocha
I apologize beforehand if this is not the right place to put this.
I am developping an application in Windows with C++ and I want to send the changes from specific hosts to
a remote RedHat machine (system with nagios) through the "NSCA Win32 Client - send_nsca.exe" plugin.
In nagios system, I have passive services associated with the specific hosts.

If I put the information (with send_nsca syntax) in a file and if I make, for example:

Code: Select all

system("send_nsca.exe -H <host_NAGIOS_IP> -c send_nsca.cfg < file.txt");
This works fine. But, if I make:

Code: Select all

char send_nsca[512];
std::string my_string = std::string("<monitoring_hostIP>\t<passive_service>\t0\tOK - Value Received: 1|val=1");
sprintf(send_nsca, "echo %s | send_nsca.exe -H <host_NAGIOS_IP> -c send_nsca.cfg", my_string.c_str());
system((char *)send_nsca);
It gives me the following error:
'val' is not recognized as an internal or external command
If I take away the "|val=1" everything works fine.
The problem is that the echo is processing the '|' character as a 'pipe' and Windows cannot find a 'val' command.

Can you guys please help me with this question?
Thanks.

Re: NSCA Win32 Client - echo problem

Posted: Thu Jan 16, 2014 12:49 pm
by tmcdonald

Re: NSCA Win32 Client - echo problem

Posted: Thu Jan 16, 2014 1:02 pm
by drocha
Thanks for replying. I already tried that, but it gives me the following message:
0 data packet(s) sent to host successfully.

Re: NSCA Win32 Client - echo problem

Posted: Thu Jan 16, 2014 1:07 pm
by tmcdonald
You need to track down the code that outputs the message and add some debugging output to see why the value is not what it should be.

Re: NSCA Win32 Client - echo problem

Posted: Thu Jan 16, 2014 1:34 pm
by drocha
Thanks for everything. I already found a way. Basically, I open send_nsca.exe with a pipe in write mode and I write the message through the pipe (with the send_nsca syntax).

http://bytes.com/topic/c/answers/646015 ... din-stdout

http://stackoverflow.com/questions/3348 ... -is-closed

Re: NSCA Win32 Client - echo problem

Posted: Thu Jan 16, 2014 1:58 pm
by sreinhardt
Interesting way of doing this, but cool. I will lock it up for now.