2

I'm running ColdFusion with Splunk. Initially I pass a search to Splunk and it returns a job id. Then I must pass that job id into a cfexecute function argument. For example this is how I want the argument to look:

arguments = "-u userid:password -k https://localhost:8089/services/search/jobs/1426104412.198/results/ --get -d output_mode=csv"

The job id is "1426104412.198" and is what is returned from the first step.

This is how I have set up the cfexecute function but I don't believe the job id is being passed into it.

First I build the URL because there is a spurious space that I have to strip between "job/" and the job id.

<cfset args1="https://localhost:8089/services/search/jobs/<cfoutput>#jobid#</cfoutput>/results/">

<cfset args = reReplace(args1, "[[:space:]]", "", "ALL") />

After that I call the cfexecute function like this:

<cfexecute name = "curl.exe" 
 arguments = "-u admin:changeme -k  <cfoutput>#args#</cfoutput>  --get -d output_mode=csv" 
 outputfile="C:\common\searchresults.csv" 
 timeout = "60"> 
</cfexecute>

I have also tried this with no results and every other permutation that I can think of.

<cfexecute name = "curl.exe" 
     arguments = "-u admin:changeme -k " #args# " --get -d output_mode=csv" 
     outputfile="C:\common\searchresults.csv" 
     timeout = "60"> 
</cfexecute>

I can output the args parameter and can see that it is correct. If I hardcode the args into the arguments parameter I get results. But I get nothing when using the examples shown above.

I believe that #args# is not being passed but I do not know how to display that arguments parameter. I have been working with ColdFusion for about 8 hours and so there is much more that I do not know than I know.

So how do I pass #args# into arguments?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
kjmatt
  • 53
  • 6
  • 1
    For the most part, you only need cfoutput tags when displaying data. The code above does not need them at all. Get rid of all the cfoutput tags in the code. Then try using `` Notice there is only a single set of quotes around the arguments value. – Leigh Mar 11 '15 at 21:02
  • 1
    Also, it is a good practice to supply the full path, to ensure cfexecute can find the exe. ie ``. Check for errors as well in the output file or use "errorVariable". – Leigh Mar 11 '15 at 21:17
  • I'm missing something. Why are you using curl instead of ``? Is there something curl does that `` dun't? – Adam Cameron Mar 11 '15 at 21:34
  • (Edit) @AdamCameron - I was wondering that too, but noticed the `-k` (ie insecure). I do not think cfhttp supports that. Not the last time I checked anyway. – Leigh Mar 11 '15 at 21:37
  • @Leigh aha, yeah: fair enough. – Adam Cameron Mar 11 '15 at 21:53
  • Actually I tried using cfhttp but it would not even log into Splunk. Access was denied. – kjmatt Mar 12 '15 at 13:05
  • Thanks for the info. I'll try the first two suggestions. I feel that I'm really close but being such a noob I realize how much I do not know! Actually I have the full path to cURL in my code. Working for DoD I obfuscate as much as possible; force of habit. – kjmatt Mar 12 '15 at 13:05
  • I tried suggestion that @Leigh gave and got no errors, however my .csv file contained the following. Unknown sid. How can I display the full set of arguments for cfexecute? I'm particularly interested in seeing the full URL passed in the args parameter. I have the feeling that is where my problem is. How do you edit these comments so that the formatting works? – kjmatt Mar 12 '15 at 16:28
  • Usually there is a documented "debug" setting or secret java parameter flag you could use, but .. I do not think that kind of debugging is available with cfexecute. The closest I can think of is to use an intermediary .bat file for debugging (klunky). Not quite what you are looking for, but I usually build the whole argument string and store it in a variable. `` Then display it on screen for debugging purposes, before passing it into ``. – Leigh Mar 12 '15 at 16:52
  • Sigh, that's exactly what I do. args = #args#
    How do you format this stuff?
    – kjmatt Mar 12 '15 at 17:11
  • (Edit) No, that is not quite same. Notice my example stores the entire string of arguments in a variable, not just a single arg. Sorry, I just noticed an error in my example. It should have read like this: `` NB: I added double quotes around url string as a test – Leigh Mar 12 '15 at 20:06
  • *sid = xmlparse(response[1])* Oh ... wait a second. I think you are passing in an xml string instead instead of a plain number. Can you dump the raw value? `` – Leigh Mar 12 '15 at 20:09
  • Assuming it is an xml node, you need to extract the text for the jobid so you are constructing the url with a simple number, rather than a complex xml object. See https://wikidocs.adobe.com/wiki/display/coldfusionen/The+XML+document+object – Leigh Mar 12 '15 at 21:52
  • Leigh, I've been out since last Friday but am still struggling with this problem. Would you be willing to go offline to discuss this. If so I'll provide my email and then you can look at my entire source code - not more than 100 lines - and maybe see the error of my ways. – kjmatt Mar 16 '15 at 20:54
  • @kjmatt - Just saw your comment. (I think S.O. only notifies the question/answer author automatically. For everyone else you have to use `@UserName`) Sure. If you are still struggling with it, my email is in my profile. – Leigh Mar 18 '15 at 15:32

0 Answers0