[Nagios-devel] 2.0b3 hacks: checks.c - failure message from one plugin as output of (2) others ...

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] 2.0b3 hacks: checks.c - failure message from one plugin as output of (2) others ...

Post by Guest »

This is a multi-part message in MIME format...

------------=_1113616537-80928-106
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline



Dear Folks,

I hoping for some enlightenment on what I may have done to checks.c to
cause one plugins output to appear in the logs as the output of another
(couple) of plugins.

[1113611613] EXTERNAL COMMAND: DISABLE_SVC_NOTIFICATIONS;external;ATMOSS
search
[1113611627] EXTERNAL COMMAND: SCHEDULE_FORCED_SVC_CHECK;external;ATMOSS
search;1113611624

.. modified Perl plugin 'check_atmoss' to raise a syntax error (to
check that checks.c reports it and recovers when the error is
corrected)

[1113611638] SERVICE ALERT: external;ATMOSS search;UNKNOWN;SOFT;1;"**ePN
failed to compile "/usr/local/nagios/libexec/check_atmoss": "syntax
error at (eval 68) line 50, near "use Getopt::Long"" at
/usr/local/nagios/bin/p1.pl line 255, line 225.


.. Ok so far.

[1113611638] SERVICE ALERT: foo-internet;Internet access to
foo;UNKNOWN;SOFT;1;"**ePN failed to compile
"/usr/local/nagios/libexec/check_atmoss": "syntax error at (eval 68)
line 50, near "use Getopt::Long"" at /usr/local/nagios/bin/p1.pl line
255, line 225.

[1113611638] SERVICE ALERT: foo-prod;prod access to
foo;UNKNOWN;SOFT;1;"**ePN failed to compile
"/usr/local/nagios/libexec/check_atmoss": "syntax error at (eval 68)
line 50, near "use Getopt::Long"" at /usr/local/nagios/bin/p1.pl line
255, line 225.

.. Whoops ! foo-internet and foo-prod are both check_tcp ! The normal
plugin output of check_tcp has been replaced by that from the
Perl plugin check_atmoss.

[1113611698] SERVICE ALERT: foo-internet;Internet access to
foo;OK;SOFT;2;TCP OK - 0 second response time on port 514
[1113611698] SERVICE ALERT: foo-prod;prod access to
foo;OK;SOFT;2;TCP OK - 0 second response time on port 514

.. Now back to normal.

[1113611818] SERVICE ALERT: external;ATMOSS search;UNKNOWN;SOFT;2;**ePN
"/usr/local/nagios/libexec/check_atmoss": "syntax error at (eval 68)
line 50, near "use Getopt::Long"".
[1113611998] SERVICE ALERT: external;ATMOSS search;UNKNOWN;HARD;3;**ePN
"/usr/local/nagios/libexec/check_atmoss": "syntax error at (eval 68)
line 50, near "use Getopt::Long"".
[1113612066] EXTERNAL COMMAND: SCHEDULE_FORCED_SVC_CHECK;external;ATMOSS
search;1113612062
[1113612068] SERVICE ALERT: external;ATMOSS search;OK;HARD;3;ATMOSS
Transaction completed Ok.


The context of these remarks is embedded Perl.

I have changed checks.c to return immediately after a failure of
perl_call_argv(). In other words, when Perl reports that a plugin fails
to compile, it sets ERRSV (to report the syntax error) and this causes
checks.c to

- fill out the remaining fields in struct svc_msg

- write the struct to the IPC pipe

- return

This saves the futile running of a plugin with syntax errors in the
grandchild process (and an equally futile extra call to Perl to run the
plugin in perl_call_pv()). Currently, checks.c caches the error in
memory and when the grandchild calls perl_call_pv() to run it, Perl
inspects the cached error and either returns immediately or runs and
returns the plugin output).

Obviously I fail to understand something here, so any clues are
welcome.

Here is the hacked checks.c

if ( SvTRUE(ERRSV) ) {
/*
* if
SvTRUE(ERRSV)
* write
failure to IPC pipe
* return
*/

pclose_result=STATE_UNKNOWN;
perl_plugin_output=SvPVX(ERRSV);
#ifdef DEBUG1
printf("embedded perl ran %s with compile error
%s - skipping plugin\n",fname,perl_plugin_output);
#endif

/* get the check finish time */
gettimeofday(&end_time,NULL);

/* record check result info */

strncpy(svc_msg.output,perl_plugin_output,sizeof(svc_msg.output)-1);
svc_msg.output[sizeof(svc_msg.output)-1]='\x0';
svc_msg.return_code=pclose_result;
svc_msg.exited_ok=TRUE;
svc_msg.check_type=SERVICE_CHECK_ACTIVE;
svc_msg.finish_time=end_time;
svc_msg.early_timeout=FALSE;

/* write check results to message queue */
write_svc_message(&svc_msg);

return ;

}
#endif

/*
* Plugin is a C
plugin or a Perl plugin _without_ compilation errors
*/

.. contine to run the plugin in grandchild

...[email truncated]...


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