We have updated our Terms of Service, Code of Conduct, and Addendum.

Question about formatting date in REST collector for JSON body.

Options

OK I have another REST collector question. My collect section I am using POST with body. The body is JSON and it has to provide the time there (start and end). I was trying `${earliest}` and `${latest}` but it does not seem to work. I think it is expecting the date to be in a certain format. This collector is currently a bash script but I was thinking it would work as a REST collector. The bash script sets and start and end variable like this: start="$(date --date=-1days '+%F %H:%M:%S')" end="$(date --date=last-minute '+%F %H:%M:%S')" How can I do this with the REST collector? Ideas?

Answers

  • Shawn Cannon
    Shawn Cannon Posts: 130 ✭✭
    Options

    <@U01C35EMQ01&gt; you know of anyone that can help me?

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Options

    Remember that you must set earliest and latest fields in the job config for those variables to be defined

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Options

    Or use a fallback like this:

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Options

    ```Earliest: `${C.Time.strftime(new Date((earliest * 1000 || Date.now() - (246060*1000))), "%Y-%m-%d %H:%M:%S")}` Latest: `${C.Time.strftime(new Date((latest * 1000 || Date.now() - (60 * 1000))), "%Y-%m-%d %H:%M:%S")}````

  • Shawn Cannon
    Shawn Cannon Posts: 130 ✭✭
    Options

    If my collect method is POST with body, I do not have any collect parameters. Lets say this is the POST body: {"list": "value", "start": "this need to be earliest", "end": "this needs to be latest" }

  • Shawn Cannon
    Shawn Cannon Posts: 130 ✭✭
    Options

    How can I use what you provided in the POST body?

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Options

    ````{"list": "value", "start": "${C.Time.strftime(new Date((earliest * 1000 || Date.now() - (246060*1000))), "%Y-%m-%d %H:%M:%S")}", "end": "${C.Time.strftime(new Date((latest * 1000 || Date.now() - (60 * 1000))), "%Y-%m-%d %H:%M:%S")}" }````

  • Shawn Cannon
    Shawn Cannon Posts: 130 ✭✭
    Options

    thanks! I will give it a whirl

  • Shawn Cannon
    Shawn Cannon Posts: 130 ✭✭
    Options

    good stuff, it worked. that stuff with time and date javascript is the stuff I need to learn more about