Closed anfoe1111 closed 8 years ago
maybe thats not neccessary anymore for naemon
Could you provide a fix or should I try to comment the corresponding code-lines?
From: Sven Nierlein [mailto:notifications@github.com] Sent: Tuesday, August 23, 2016 2:40 PM To: sni/mod_gearman mod_gearman@noreply.github.com Cc: anfoe1111 andreas.foerster.koeln@web.de; Author author@noreply.github.com Subject: Re: [sni/mod_gearman] problem with backslashes in commandline (e.g.'C:\' windows volume check) (#99)
maybe thats not neccessary anymore for naemon
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sni/mod_gearman/issues/99#issuecomment-241717354 , or mute the thread https://github.com/notifications/unsubscribe-auth/ASXrmEsbJjwTbUEYsbxZLu0ZzU3NowM9ks5qiuo5gaJpZM4Jq1qF . https://github.com/notifications/beacon/ASXrmPlQmUwHMJnnXXZvJ9pYbCcyFVSNks5qiuo5gaJpZM4Jq1qF.gif
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/sni/mod_gearman","title":"sni/mod_gearman","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/sni/mod_gearman"}},"updates":{"snippets":[{"icon":"PERSON","message":"@sni in #99: maybe thats not neccessary anymore for naemon"}],"action":{"name":"View Issue","url":"https://github.com/sni/mod_gearman/issues/99#issuecomment-241717354"}}}
right now i don't have the time to investigate possible side effects of removing the double slash. So i'd be glad if you try that yourself and send a pull request if you found a solution.
After commenting the related lines and rebuilding mod_gearman, everything works fine so far. As we are testing at the moment, I'll keep you informed if we observe any side-effects. Thanks for your help.
I'm not quite sure that I understand all of the programming logic of mod_gearman. I tested two variants for a pull-request, both work fine for our distributed naemon-config.
Here is what I tried so far:
Variant 1: I put comments on the "escape backslashes" section of function "gm_escape_newlines" in common/utils.c. This function is called by function "extract_check_results" called by procedure "run_check" called by procedure "execute_safe_command" called by the worker-process. I'm not sure if this change is compatible to Nagios 3.X or 4.X-configurations, because the worker-binary created is used for nagios (3.X/4.X) and for naemon as well. Inside the same function newlines are escaped as well. For neamon-environments (#ifdef USENAEMON), these newlines are removed later in the neb-module, it seems they are not necessary for naemon. --> Result: everything works fine, backslashes do not appear on the central server (= dupserver) and on the remote server.
Variant 2: I did not change function "gm_escape_newlines", instead I changed the neb-module and substitued two backslashes by one backslash in procedures "handle_perfdata" of mod_gearman.c, where the escaped newlines are un-escaped. I did the same change in "get_results" of file result_thread.c. Advantage: This can be surrounded by a "#ifdef USENAEMON", to make the change naemon-specific. --> Result: everything works fine, backslashes do not appear on the central server (= dupserver) and on the remote server.
I would prefer variant 2 for the pull-request, what do you think?
By the way, for performance reasons it would be nice to eliminate all of this newline/backslash escaping-coding for naemon environments. Would that be an option?
Should be fixed now. Thanks.
Yes, removing all the unnecessary escaping for naemon would be a good thing. But i doubt this is possible without breaking backwards compatibility.
mod_gearman: 3.0.0.b2-1.el7 installed from labs_consol_testing naemon: 1.0.5-1.el7 installed from labs_consol_stable NSClient++ 0.5.0.45 running on a monitored windows-server
Problem: When a check-command is executed by mod_gearman containing a backslash surrounded by single quotes (e.g. 'C:\'), the backslash will be duplicated in checkresults. Running the same command by a naemon worker dows not show duplicate backslashes.
Example (NSClient++, windows-server): check_nrpe -H -p 5666 -c check_drivesize -a 'drive=C:\' 'perf-config=*(unit:G)' 'crit=used>95' 'warn=used>90%'
Result (running manually from commandline):
OK All 1 drive(s) are ok|'C:\ used'=63.49453G;72.00033;76.00035;0;80.00037 'C:\ used %'=79%;90;95;0;100 (which is ok)
Result when the same command is executed by mod_gearman (extracted from status-file or as observed in thruk): OK All 1 drive(s) are ok|'C:\ used'=63.49453G;72.00033;76.00035;0;80.00037 'C:\ used %'=79%;90;95;0;100 (which is not ok)
When using a normal slash insted of a backslash, the results are ok, no duplication takes place.
I took a look at the sources of mod_gearman (common/utils.c) and found function "gm_escape_newlines". Inside this function backslashes are duplicated. Could this eventually be the source of my problem? ... /* escape backslashes */ if(tmpbuf[x]=='\'){ newbuf[y++]='\'; newbuf[y++]='\'; } ...
Any ideas are appreciated!