Page 1 of 1

[Nagios-devel] check_by_ssh frustration!

Posted: Thu Aug 14, 2008 8:44 am
by Guest
--_000_3679AE44D8C04547A4F3EB83E779056237E089F6BEMBX01ldschurc_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Just off the top of my head, I believe startlocation and endlocation should=
be int not char* same with all the variables intended to hold numerical va=
lues.


From: [email protected] [mailto:nagios-devel-bounc=
[email protected]] On Behalf Of Clifton Griffin
Sent: Thursday, August 14, 2008 10:41 AM
To: [email protected]
Subject: [Nagios-devel] check_by_ssh frustration!

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 co=
uple of html links to the end of the output. Basically, whenever a check ru=
ns 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 segmenta=
tion fault. This would make sense if the output of these failing checks wer=
e 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 =3D "check"; /* I get the name of the chec=
k by searching the output to find this string*/
char* endString =3D " "; /* and then I look for the next sin=
gle space */
char* startLocation;
char* endLocation;
char* endLocation2;
char* strCheck;
char* temp =3D comm; /* the string I search for the name of the che=
ck running *
char* strHost; /* this will hold the name of the host the ch=
eck 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 =3D strstr(temp,startString);
endLocation =3D strstr(startLocation,endString);
tempLength1 =3D (int)startLocation-(int)endLocation;
/* make sure the answer is positive */
if(tempLength1 ">(Wi=
ki Article) ">(Wiki Se=
arch)", strCheck, strHost, strCheck); */generate links */

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

And here is where I modify the command being run to get the hostname prepen=
ded:
#########################################################
process_arguments (int argc, char **argv)
{
char* cmdHost =3D "echo -n $HOSTNAME;echo -n :;"; /*echo hostname a=
nd 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, op=
targ); /* my mod */
//asprintf (&remotecmd, "%s%s", remotecmd, optarg);=
<---Original code
############################

...[email truncated]...


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