@@ -49,10 +49,15 @@ func (l *CheckWrap) Check(ctx context.Context, snc *Agent, check *CheckData, _ [
4949 var command string
5050 if l .wrapped {
5151 // substitute $ARGn$ in the command
52+ log .Debugf ("command string: %s" , l .commandString )
53+ macros ["ARGS" ] = strings .Join (check .rawArgs , " " )
54+ macros ["ARGS\" " ] = stringJoinQuoted (check .rawArgs , " " )
5255 commandString := ReplaceRuntimeMacros (l .commandString , macros )
56+
5357 cmdToken := utils .Tokenize (commandString )
5458 macros ["SCRIPT" ] = cmdToken [0 ]
5559 macros ["ARGS" ] = strings .Join (cmdToken [1 :], " " )
60+ macros ["ARGS\" " ] = stringJoinQuoted (cmdToken [1 :], " " )
5661 ext := strings .TrimPrefix (filepath .Ext (cmdToken [0 ]), "." )
5762 log .Debugf ("command wrapping for extension: %s" , ext )
5863 wrapping , ok := snc .config .Section ("/settings/external scripts/wrappings" ).GetString (ext )
@@ -62,18 +67,13 @@ func (l *CheckWrap) Check(ctx context.Context, snc *Agent, check *CheckData, _ [
6267 wrapping = l .fixWrappingCmd (ext , wrapping )
6368 log .Debugf ("%s wrapper: %s" , ext , wrapping )
6469 command = ReplaceRuntimeMacros (wrapping , macros )
70+ log .Debugf ("command after macros expanded: %s" , command )
6571 } else {
6672 macros ["ARGS" ] = strings .Join (check .rawArgs , " " )
67- macros ["ARGS\" " ] = strings .Join (func (arr []string ) []string {
68- quoteds := make ([]string , len (arr ))
69- for i , v := range arr {
70- quoteds [i ] = fmt .Sprintf ("%q" , v )
71- }
72-
73- return quoteds
74- }(check .rawArgs ), " " )
73+ macros ["ARGS\" " ] = stringJoinQuoted (check .rawArgs , " " )
7574 log .Debugf ("command before macros expanded: %s" , l .commandString )
7675 command = ReplaceRuntimeMacros (l .commandString , macros )
76+ log .Debugf ("command after macros expanded: %s" , command )
7777 }
7878
7979 timeoutSeconds := check .timeout
@@ -133,3 +133,12 @@ func (l *CheckWrap) fixWrappingCmd(ext, wrapping string) string {
133133
134134 return wrapping
135135}
136+
137+ func stringJoinQuoted (arr []string , sep string ) string {
138+ quoteds := make ([]string , len (arr ))
139+ for i , v := range arr {
140+ quoteds [i ] = fmt .Sprintf ("%q" , v )
141+ }
142+
143+ return strings .Join (quoteds , sep )
144+ }
0 commit comments