Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems to handover a none json string #702

Open
StephanHarrer opened this issue Oct 12, 2024 · 3 comments
Open

Problems to handover a none json string #702

StephanHarrer opened this issue Oct 12, 2024 · 3 comments

Comments

@StephanHarrer
Copy link

Hello,

I have to handly a webhook from a network system where the content is not json like. Here a example:

date=2024-10-12 time=23:52:08 devid="FGVMEV-CTZXP2_8F" devname="FGVMEV-CTZXP2_8F" eventtime=1728769927878132716 tz="+0200" logid="0100026001" type="event" subtype="system" level="information" vd="root" logdesc="DHCP Ack log" interface="port2" dhcp_msg="Ack" mac="00:XC:29:F4:XX:XX" ip=10.98.0.2 lease=300 hostname="CL" msg="DHCP server sends a DHCPACK"

As far as I see the content is not well json formated.

webhook tells me:
[webhook] 2024/10/13 00:30:51 [20b296] 200 | 0 B | 104.629µs | 10.5.5.5 | POST /hooks/FS
[webhook] 2024/10/13 00:30:51 [20b296] error extracting command arguments: couldn't retrieve argument for {Source:payload Name: EnvName: Base64Decode:false}
[webhook] 2024/10/13 00:30:51 [20b296] executing /tmp/test.py (/tmp/test.py) with arguments ["/tmp/test.py" ""] and environment [] using /tmp as cwd
[webhook] 2024/10/13 00:30:51 [20b296] command output:

My question how can I tell webhook to do NOT parse the content as json and handover the string (content) to my python program?

Regards
Stephan

@StephanHarrer
Copy link
Author

To be more clear:

Here is the relevant part of hook.json:

   {
    "id": "FS",
    "execute-command": "/tmp/test.py",
    "command-working-directory": "/tmp",
    "pass-arguments-to-command":
    [
      {
        "source": "entire-payload"
      }
    ],
    "trigger-rule":
      { "match": { "type": "ip-whitelist", "ip-range": "10.5.5.5/32" } }
   },

In that case I receive:

[webhook] 2024/10/13 11:11:45 [e34378] incoming HTTP POST request from 10.5.5.5:23384
[webhook] 2024/10/13 11:11:45 [e34378] FS got matched
[webhook] 2024/10/13 11:11:45 [e34378] error parsing JSON payload invalid character 'd' looking for beginning of value
[webhook] 2024/10/13 11:11:45 [e34378] FSc hook triggered successfully
[webhook] 2024/10/13 11:11:45 [e34378] 200 | 0 B | 86.836µs | 192.168.100.3 | POST /hooks/FS
[webhook] 2024/10/13 11:11:45 [e34378] executing /tmp/test.py (/tmp/test.py) with arguments ["/tmp/test.py" "null"] and environment [] using /tmp/ as cwd

As written above, I think the json format that is passed does not fit. I would therefore like to read in the data as a string and then take care of the further processing myself.

@ianroberts
Copy link
Contributor

{
    "source": "raw-request-body"
}

should give you the complete text as one argument. You'll still get the "error parsing JSON payload" message in the log but that's only happening because the sender that is calling your webhook is sending it with a Content-Type header that claims it is JSON - the actual execute-command should still work.

@adnanh
Copy link
Owner

adnanh commented Oct 24, 2024

{
    "source": "raw-request-body"
}

should give you the complete text as one argument. You'll still get the "error parsing JSON payload" message in the log but that's only happening because the sender that is calling your webhook is sending it with a Content-Type header that claims it is JSON - the actual execute-command should still work.

You can use the incoming-payload-content-type - sets the Content-Type of the incoming HTTP request (ie. application/json); useful when the request lacks a Content-Type or sends an erroneous value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants