How do I get _value Webhook to be in Json format

alerting

(Jason Esposito) #1

How do I get my "_value" from my webhook to be in a Json format or even better would be just to display the output of the GET query in a Json format.

Current watcher:

{
  "trigger": {
    "schedule": {
      "interval": "2m"
    }
  },
  "input": {
    "http": {
      "request": {
        "scheme": "http",
        "host": "host.eu-west-1.aws.found.io",
        "port": 9200,
        "method": "GET",
        "path": "_cat/indices/tid*?format=json",
        "params": {},
        "headers": {},
        "auth": {
          "basic": {
            "username": "test",
            "password": "A"
          }
        }
      }
    }
  },
  "actions": {
    "web_hook": {
      "webhook": {
        "scheme": "https",
        "host": "api.test.com",
        "port": 443,
        "method": "POST",
        "path": "/private/staging/tenant/index/size",
        "params": {},
        "headers": {
        "x-api-key": "password",
        "Content-Type": "application/json"
        
        },
        "body": "{{#toJson}}ctx.payload{{/toJson}}_value"
      }
    }
  },
  "throttle_period_in_millis": 120000
}

Current output:

{
  "_headers": {
    "date": [
      "Fri, 01 Jun 2018 11:45:22 GMT"
    ],
    "server": [
      "123"
    ],
    "connection": [
      "keep-alive"
    ],
    "content-type": [
      "text\/plain; charset=UTF-8"
    ],
    "x-found-handling-server": [
      "1.1.1.1"
    ],
    "x-found-handling-cluster": [
      "Test"
    ],
    "x-found-handling-instance": [
      "instance-ID"
    ]
  },
  "_value": "green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.14 cvQK61shSBCJd8DzFSlOwA 5 1 235899 0 560.7mb  281.2mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.1  QH4m8jiBTnGDLQWsmFfgcQ 5 1 724745 0   1.4gb  762.8mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.7  cNo3wIlkR1yCh6bqQZC9wA 5 1 248536 0 568.9mb  284.4mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.22 l7L7DZ3cSz6idcYAfmid5A 5 1 666160 0   1.3gb  695.4mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.29 i9Gmj95jRDWMQ0xhWuJ6ew 5 1 611943 0   1.2gb    641mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.15 wy0xRG5dSgezr2dZ0e6GYA 5 1 217476 0 544.7mb  272.3mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.21 ZKYOei6xQ6CDoQmrMgG7iA 5 1 773255 0   1.5gb    807mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.11 UXmMH9DjQKCbUaxPJbxkAQ 5 1 825112 0   1.7gb  880.8mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.5  hFUsci4VTcqoVtzZYV3RkA 5 1 499594 0     1gb  528.7mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.24 l6Qsk7dmQw-cELv_R5sZrw 5 1 836594 0   1.6gb    848mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.15 5R_xbylFSv-bTY-5L9hZmQ 5 1 794937 0   1.5gb  810.2mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.5  x6McWd3TQYakPoN5gXcuMw 5 1 257549 0 590.9mb  295.4mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.30 cv-wKJ5tSROGreoy5_hzdg 5 1 180000 0 514.3mb  257.1mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.6  F-0YJspPRZmGdlKsCa8WFg 5 1 230211 0 559.7mb  280.6mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.16 iASteWyLTdunmr05vpUfLw 5 1 743229 0   1.6gb  849.3mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.10 9C0PrrnIT8KMc2GxsHd4Yw 5 1 768519 0   1.5gb  800.1mb\n 
}

Any help is appreciated.


(Alexander Reelsen) #2

have you tried "{{#toJson}}ctx.payload._value{{/toJson}}" ?

also, please include outputs in your samples, that will ease debugging a million times. Thanks a lot!

--Alex


(Jason Esposito) #3

Hi @spinscale

Thanks for your help again.

I tried that and the get the data I want from the GET query but it's not in a Json format.

Snippet from webhook:

green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.14 cvQK61shSBCJd8DzFSlOwA 5 1 235899 0 560.7mb 281.1mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.1 QH4m8jiBTnGDLQWsmFfgcQ 5 1 724745 0 1.4gb 763.8mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.7 cNo3wIlkR1yCh6bqQZC9wA 5 1 248536 0 568.9mb 284.5mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.22 l7L7DZ3cSz6idcYAfmid5A 5 1 666160 0 1.3gb 694.8mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.06.5 cB7xb45YQbukrxnLubIXFw 5 1 151331 0 348.1mb 191.5mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.29 i9Gmj95jRDWMQ0xhWuJ6ew 5 1 611943 0 1.2gb 639.7mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.15 wy0xRG5dSgezr2dZ0e6GYA 5 1 217476 0 544.7mb 272.4mb\ngreen open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.21 ZKYOei6xQ6CDoQmrMgG7iA 5 1 773255 0 1.5gb 808.6mb

In Laymans terms by output do you mean the right hand side of my screen when I execute my watcher? Or just the "response" part for example?

Jason


(Alexander Reelsen) #4

as already mentioned in another post, the output of the execute watch API would help a lot here. Also, you should move the format=json into parameters and not as part of the path to make sure the parameter is applied correctly.

Thanks!

--Alex


(Jason Esposito) #5

Hi @spinscale

Thanks again,

Is this the output you want? Sorry for screen dump.

But I guess you can see what I want, the _value to be in Json format.

},
    "result": {
      "execution_time": "2018-06-05T09:13:53.397Z",
      "execution_duration": 3025,
      "input": {
        "type": "http",
        "status": "success",
        "payload": {
          "_headers": {
            "date": [
              "Tue, 05 Jun 2018 09:13:56 GMT"
            ],
            "server": [
              "fp/b7dd8d"
            ],
            "connection": [
              "keep-alive"
            ],
            "content-type": [
              "text/plain; charset=UTF-8"
            ],
            "x-found-handling-server": [
              "1.1.1.1"
            ],
            "x-found-handling-cluster": [
              "1234"
            ],
            "x-found-handling-instance": [
              "instance-0000000036"
            ]
          },
          "_value": """
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.14 cvQK61shSBCJd8DzFSlOwA 5 1 235899 0 560.7mb  281.1mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.1  QH4m8jiBTnGDLQWsmFfgcQ 5 1 724745 0   1.4gb  763.8mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.7  cNo3wIlkR1yCh6bqQZC9wA 5 1 248536 0 568.9mb  284.5mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.22 l7L7DZ3cSz6idcYAfmid5A 5 1 666160 0   1.3gb  694.8mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.06.5  cB7xb45YQbukrxnLubIXFw 5 1 170561 0 375.3mb  198.8mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.29 i9Gmj95jRDWMQ0xhWuJ6ew 5 1 611943 0   1.2gb  639.7mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.15 wy0xRG5dSgezr2dZ0e6GYA 5 1 217476 0 544.7mb  272.4mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.21 ZKYOei6xQ6CDoQmrMgG7iA 5 1 773255 0   1.5gb  808.6mb
""",
          "_status_code": 200
        },
        "http": {
          "request": {
            "host": "5d1f1d4221de39b3988b45613b1f667f.eu-west-1.aws.found.io",
            "port": 9200,
            "scheme": "http",
            "method": "get",
            "path": "_cat/indices/tid*?format=json",
            "auth": {
              "basic": {
                "username": "test"
              }
            }
          },
          "status_code": 200
        }
      },
      "condition": {
        "type": "always",
        "status": "success",
        "met": true
      },
      "actions": [
        {
          "id": "web_hook",
          "type": "webhook",
          "status": "success",
          "webhook": {
            "request": {
              "host": "api.test.com",
              "port": 443,
              "scheme": "https",
              "method": "post",
              "path": "/private/staging/tenant/index/size",
              "headers": {
                "x-api-key": "password",
                "Content-Type": "application/json"
              },
              "body": """
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.14 cvQK61shSBCJd8DzFSlOwA 5 1 235899 0 560.7mb  281.1mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.1  QH4m8jiBTnGDLQWsmFfgcQ 5 1 724745 0   1.4gb  763.8mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.7  cNo3wIlkR1yCh6bqQZC9wA 5 1 248536 0 568.9mb  284.5mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.22 l7L7DZ3cSz6idcYAfmid5A 5 1 666160 0   1.3gb  694.8mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.06.5  cB7xb45YQbukrxnLubIXFw 5 1 170561 0 375.3mb  198.8mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.29 i9Gmj95jRDWMQ0xhWuJ6ew 5 1 611943 0   1.2gb  639.7mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.04.15 wy0xRG5dSgezr2dZ0e6GYA 5 1 217476 0 544.7mb  272.4mb
green open tid.67a76f18-487b-4033-a3d7-b706a8aa04f0.2018.05.21 ZKYOei6xQ6CDoQmrMgG7iA 5 1 773255 0   1.5gb  808.6mb

"""
            },
            "response": {
              "status": 200,
              "headers": {
                "date": [
                  "Tue, 05 Jun 2018 09:13:56 GMT"
                ],
                "content-length": [
                  "276"
                ],
                "x-amz-apigw-id": [
                  "123="
                ],
                "x-amzn-trace-id": [
                  "Root=1"
                ],
                "x-amzn-requestid": [
                  "c134"
                ],
                "connection": [
                  "keep-alive"
                ],
                "content-type": [
                  "application/json"
                ]
              },
              "body": """{"SendMessageResponse":{"ResponseMetadata":{"RequestId":"afaf"},"SendMessageResult":{"MD5OfMessageAttributes":null,"MD5OfMessageBody":"afaf","MessageId":"0c5f2514-2951-44a9-9ac9-0b4dd261abcb","SequenceNumber":null}}}"""
            }
          }
        }
      ]
    },
    "messages": []
  }
}

I tried to move the format=json into the params like this:

{
  "trigger": {
    "schedule": {
      "interval": "2m"
    }
  },
  "input": {
    "http": {
      "request": {
        "scheme": "http",
        "host": "1234.eu-west-1.aws.found.io",
        "port": 9200,
        "method": "GET",
        "path": "_cat/indices/tid*?",
        "params": "format=json",
        "headers": {},
        "auth": {
          "basic": {
            "username": "test",
            "password": "password"
          }
        }
      }
    }
  },

But I get this error:

"type": "illegal_argument_exception",
"reason": "must specify either [source] for an inline script or [id] for a stored script"

(Alexander Reelsen) #6

See the http input docs for an example how to use the params field.


(system) #7

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.