[Nagios-devel] check_by_ssh frustration!

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] check_by_ssh frustration!

Post by Guest »

------=_Part_41309_5958979.1218732040029
Content-Type: multipart/alternative;
boundary="----=_Part_41310_5583862.1218732040029"

------=_Part_41310_5583862.1218732040029
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,
First of all, I'm rather weak in C. So please be gentle. :)

I have been working on a modification to check_by_ssh that will append a
couple of html links to the end of the output. Basically, whenever a check
runs I want to get back:


The links will go to an internal wiki we use at my organization.

I got this working fine, or so I thought, a couple of nights ago. However,
upon deployment, a number of checks caused my build to fail with a
segmentation fault. This would make sense if the output of these failing
checks were largely different from the output of the succeeding checks, but
they aren't.

It's roughly the same number of characters. The string with the html links
is much larger than the output of the checks that are not working.

Here is the code: (an experienced C programmer is probably going to have a
visceral reaction to some of my methods!)
######################################################
/* run the command */
if (verbose)
printf ("%s\n", comm);

/* my modifications start here*/
char* startString = "check"; /* I get the name of the check
by searching the output to find this string*/
char* endString = " "; /* and then I look for the next single
space */
char* startLocation;
char* endLocation;
char* endLocation2;
char* strCheck;
char* temp = comm; /* the string I search for the name of the check
running *
char* strHost; /* this will hold the name of the host the
check is being run on...*/
char* strLinks; /*the links...generated below*/
int tempLength1;
char* tempString;
char* holder; /*copy of output to parse through for host name*/

startLocation = strstr(temp,startString);
endLocation = strstr(startLocation,endString);
tempLength1 = (int)startLocation-(int)endLocation;
/* make sure the answer is positive */
if(tempLength1 (Wiki Article) (Wiki
Search)", strCheck, strHost, strCheck); */generate links */

strcat(chld_out.buf, strLinks);
#########################################################

And here is where I modify the command being run to get the hostname
prepended:
#########################################################
process_arguments (int argc, char **argv)
{
char* cmdHost = "echo -n $HOSTNAME;echo -n :;"; /*echo hostname and
a colon */

............skipping down......

case
'C':
/* Command for remote machine */
commands++;
if (commands > 1)
asprintf (&remotecmd, "%s;echo STATUS CODE:
$?;", remotecmd);
asprintf(&remotecmd, "%s%s%s",cmdHost,remotecmd,
optarg); /* my mod */
//asprintf (&remotecmd, "%s%s", remotecmd, optarg);
<---Original code
#########################################################

That's it. For the checks that fail, I can change strcat(chld_out.buf,
strLinks) to strncat(chld_out.buf, strLinks, 10) and it works...ie, no
segmentation fault. However, at 11 characters it fails.

Any ideas? I'm attaching check_by_ssh.c. It doesn't have all of these
comments and I removed some lines that were for my testing, but it is
basically the same.

I will be eternally grateful to anyone who can either:
1. Show me what I'm doing wrong.
OR
2. Help me understand how chld_out.buf works better so I can understand why
this

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked