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

how to use JSONDATA check in Webhook body #41

Open
manish2479 opened this issue Feb 25, 2019 · 6 comments
Open

how to use JSONDATA check in Webhook body #41

manish2479 opened this issue Feb 25, 2019 · 6 comments
Labels

Comments

@manish2479
Copy link

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.

@manish2479
Copy link
Author

Hi,

Any help on this!

@jomann09
Copy link
Contributor

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.

@manish2479
Copy link
Author

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.

@box293
Copy link
Contributor

box293 commented Jul 15, 2019

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?

@manish2479
Copy link
Author

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"
                }
              ]
            }
          }
        }
    }
  }
}

@box293
Copy link
Contributor

box293 commented Jul 23, 2019

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.

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

No branches or pull requests

3 participants