How to test nagios send_nsca with netcat

nagiosnetcat

I am trying to write a unit test of send_nsca using nc but it is failing.

I want to start nc to listen to the nsca port and then use send_ncsa to send a message to that port.

In one terminal I am running:

nc -l 5667 -v

In the other:

echo -e "foo.example.com\ttest\t0\t0" | ./send_nsca -H localhost -p 5667 -c send_nsca.cfg

My send_nsca.cfg file only contains: encryption_method=0.

On the listening terminal I get:

Connection from 10.1.30.23 port 5667 [tcp/*] accepted

But nothing else. On the send_nsca side I get:

Error: Timeout after 10 seconds

Any ideas?

EDIT:

I recompiled the source and enabled DEBUG output:

Connected okay...
Error: Timeout after 10 seconds
Cleaned up encryption routines

From the code I see I am missing the initialization packet containing the IV and timestamp:

#ifdef DEBUG
    printf("Connected okay...\n");
#endif

/* read the initialization packet containing the IV and timestamp */
result=read_init_packet(sd);
if(result!=OK){
    printf("Error: Could not read init packet from server\n");
    close(sd);
    do_exit(STATE_CRITICAL);
        }

#ifdef DEBUG
    printf("Got init packet from server\n");
#endif

Is there any other way to test send_nsca without a full blown nagios installation?

Best Answer

You don't need a "full blown nagios installation" to test send_nsca...

NSCA is an add-on, and is not part of Nagios core itself. It's packaged as a separate component in Debian/Ubuntu and CentOS (epel or repoforge), for example.

NSCA runs as a daemon or via inetd/xinetd. See the NSCA setup docs for more information about how to run it.

Also, there are several drop-in replacements for NSCA available; NRDP and NSCA-ng may be of interest to you for testing.

Related Topic