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

Andreas Ericsson ae at op5.se
Sun Apr 17 20:49:02 CEST 2005


I can only guess that this is another issue with embedded perl. The code 
checks out OK, so it sort of has to be something concerning perl and the 
way it works in threads.

Stanley Hopcroft wrote:
> 
> 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, <DATA> 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, <DATA> 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, <DATA> 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 process ..
> 
> Yours sincerely.
> 
> 
>  -- 
> Stanley Hopcroft
> 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> --
> This message contains privileged and confidential information only 
> for use by the intended recipient.  If you are not the intended 
> recipient of this message, you must not disseminate, copy or use 
> it in any manner.  If you have received this message in error, 
> please advise the sender by reply e-mail.  Please ensure all 
> e-mail attachments are scanned for viruses prior to opening or 
> using.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click




More information about the Developers mailing list