NagiosEnterprises/nrdp

how to use JSONDATA check in Webhook body

Closed this issue · 6 comments

Hi

I would like use JSONDATA nrpe check with the webhook. Here is my curl command which works fine.

curl -f -d 'token=TOKEN&cmd=submitcheck&JSONDATA={
  "checkresults": [
    {
      "checkresult": {
        "type": "service",
        "checktype": "1"
      },
      "hostname": "node2",
      "servicename": "Cron_Err",
      "state": "1",
      "output": "Cron_Err in Warning state"
    }
  ]
}'  http://nagios.domain.com/nrdp/

But when I use it in Webhook it gives me error as

TypeError: Invalid template! Template should be a \"string\" but \"object\" was given as the first argument for mustache#render(template, view, partials)\n

Here is my Webhook

        "body": {
          "dataType": "json",
          "data": {
            "cmd": "submitcheck",
            "token": “TOKEN”,
            "JSONDATA": {
              "checkresults": [
                {
                  "checkresult": {
                    "type": "service",
                    "checktype": "1"
                  },
                  "hostname": “node2",
                  "servicename": "Cron_Err",
                  "state": "1",
                  "output": "Cron_Err in Warning state"
                }
              ]
            }
          }
        }

So, I am not sure what should be the right body section and how to define the token and cmd section in the body section.

Any help is appreciated.

Hi,

Any help on this!

Hello, sorry for the slow response, what are you using for that webhook? The dataType should not be set as json. When you're sending the request with the data that you've shown above you're sending raw json into NRDP. NRDP uses the normal POST or GET functionality to pass json via the JSONDATA argument. I think the only change is changing the dataType and making sure it's being sent as a GET or POST request.

Hi, sorry for late reply. So do I need to have post option in body of the webhook?

So here is my curl webhook

"actions": {
    "New webhook action h0r0p2zatnu": {
      "throttle_period": "0h0m1s",
      "webhook": {
        "method": "PUT",
        "host": "nagios.domain.com",
        "port": 80,
        "use_https": false,
        "proxy": false,
        "path": "/nrdp/",
        "priority": "high",
        "body": "token=TOKEN&cmd=submitcheck&XMLDATA=<?xml version='1.0'?><checkresults><checkresult type='service' checktype='1'><hostname>Cron_Error</hostname> <servicename>Cron_Error</servicename><state>1</state><output>Cron_Error in Warning state</output></checkresult></checkresults>",
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
    }

How would be the JSONDATA format for this webhook, specially for the body part if I want to use the jsondata format.

So you've pasted an example which is for XML check results. Was this intentional? Are you posting this as an example of something that does work with webhook? What is your JSON example that isn't working?

Yes the XML check which works fine and it was an example for XML webhook which is working, so how would be the webhook for JSON data check. Yes my JSON data check is not working. Here is the JSON check webhook.

"actions": {
    "New webhook action h0r0p2zatnu": {
      "throttle_period": "0h0m1s",
      "webhook": {
        "method": "PUT",
        "host": "nagios.domain.com",
        "port": 80,
        "use_https": false,
        "proxy": false,
        "path": "/nrdp/",
        "priority": "high",
 "body": {
          "dataType": "json",
          "data": {
            "cmd": "submitcheck",
            "token": “TOKEN”,
            "JSONDATA": {
              "checkresults": [
                {
                  "checkresult": {
                    "type": "service",
                    "checktype": "1"
                  },
                  "hostname": “node2",
                  "servicename": "Cron_Err",
                  "state": "1",
                  "output": "Cron_Err in Warning state"
                }
              ]
            }
          }
        }
    }
  }
}

Look at the curl examples here, they define the format:
https://github.com/NagiosEnterprises/nrdp

I think you need to remove dataType and change JSONDATA to json and some other minor changes:

"actions": {
    "New webhook action h0r0p2zatnu": {
      "throttle_period": "0h0m1s",
      "webhook": {
        "method": "PUT",
        "host": "nagios.domain.com",
        "port": 80,
        "use_https": false,
        "proxy": false,
        "path": "/nrdp/",
        "priority": "high",
 "body": {
          "data": {
            "cmd": "submitcheck",
            "token": “TOKEN”,
            "json": {
              "checkresults": [
                {
                  "checkresult": {
                    "type": "service",
                  },
                  "hostname": “node2",
                  "servicename": "Cron_Err",
                  "state": "1",
                  "output": "Cron_Err in Warning state"
                }
              ]
            }
          }
        }
    }
  }
}

The dataType should not be set as json. When you're sending the request with the data that you've shown above you're sending raw json into NRDP.

This is important, you are just sending raw data, not a JSON object.