rc8d
April 24, 2022, 7:11am
#1
Hello,
I am running into an issue with the Graylog integration as documented under GitHub - jeanmorais/rocketchat-graylog-hook: Add Graylog alerts via a new WebHook in Rocket.Chat . The error that pops up through the logs is “Error running Script in Trigger” - “TypeError: Cannot read property ‘triggered_condition’ of undefined”.
Looking for pointers at this stage or if someone else has encountered the same issue. Worth noting that a “Curl” test or using a basic Powershell script to invoke the API works using a test integration.
Any help is appreciated.
Server Setup Information
Version of Rocket.Chat Server: 4.6.2
Operating System: Ubuntu 20.4
Deployment Method:
Number of Running Instances: 1
DB Replicaset Oplog: wiredTiger (oplog Enabled)
NodeJS Version: v14.18.3
MongoDB Version: 4.2.17
Firewalls involved: N/A
rc8d
April 24, 2022, 7:17am
#2
Below is the log captured at the time of Graylog attempting to send a webhook.
{"level":30,"time":"2022-04-24T01:33:21.190Z","pid":32448,"hostname":"RC-Server","name":"Integrations","section":"Incoming WebHook","msg":"Post integration:","name":"Graylog-Webhook"}
{"level":30,"time":"2022-04-24T01:33:21.191Z","pid":32448,"hostname":"RC-Server","name":"Integrations","section":"Incoming WebHook","msg":"Will evaluate script of Trigger","name":"Graylog-Webhook"}
{"level":50,"time":"2022-04-24T01:33:21.193Z","pid":32448,"hostname":"RC-Server","name":"Integrations","section":"Incoming WebHook","msg":"Error running Script in Trigger","name":"Graylog-Webhook","script":"var GRAYLOG_URL=\"https://Graylog-Server.com:9000\";var createPermalink=function(m,index){var label=index===0?\"Display complete message\":\"#\"+(index+1);return\"[\"+label+\"](\"+GRAYLOG_URL+\"/messages/\"+m.index+\"/\"+m.id+\")\"};var formatMessages=function(messages){var grouped=messages.reduce(function(acc,m){if(!acc.hasOwnProperty(m.message)){acc[m.message]=[]}acc[m.message].push(m);return acc},{});var result=[];for(var mType in grouped){if(grouped.hasOwnProperty(mType)){var line=\"*Message*: \"+mType+\"\<br>*Source*: \"+grouped[mType][0].source+\"\<br>\"+grouped[mType].map(createPermalink).join(\", \");result.push(line)}}return result.join(\"\<br>-------------\<br>\")};var parseText=function(result){if(result.matching_messages.length>0){return formatMessages(result.matching_messages)}else{return result.result_description}};var createAlertMessageEvent=function(result){return\":warning: *Alert*: \"+result.triggered_condition.title+\"\<br>\"+parseText(result)};var makeAttachment=function(text){return{text:text,color:\"#e8d612\"}};var Script=function(){function Script(){}var _proto=Script.prototype;_proto.process_incoming_request=function process_incoming_request(_ref){var request=_ref.request;return{content:{attachments:[makeAttachment(createAlertMessageEvent(request.content.check_result))]}}};return Script}();","err":{},"msg":"TypeError: Cannot read property 'triggered_condition' of undefined"}
{"level":35,"time":"2022-04-24T01:33:21.194Z","pid":32448,"hostname":"RC-Server","name":"API","method":"POST","url":"/hooks/727d4cf65fd626491526f828/zyTEobhd78f7LWB5yKmpJuA8sG56SMgwJzHoTBss5XSkhApd","userAgent":"okhttp/3.14.6","length":"2209","host":"RC-Server.com:3000","remoteIP":"x.x.x.x","status":400,"responseTime":4}
Hi!
Can you share an example of the payload your graylog is sending? Can you confirm if it’s the same one you are using with curl?
The scripts renders the message based at the contents at request.content.check_result, so you need to first make sure the content it’s there and also sent with json headers as well.
A great way to debug this is to set your graylog to point to a website like https://webhook.site/ and match that with your curl command.
Also, if you want to help and/or get help, please, join us at our Community Support Channel
rc8d
May 2, 2022, 12:23pm
#4
Thanks @dudanogueira , let me try the webhook.site and report back with the Graylog output.
When you say Rocket.Chat , what channel?
The link is already pointing to our #support channel
Hi!
I have sent a PR to the integration webhook script that will hopefully work with newer version of graylog:
jeanmorais:master
← dudanogueira:fix/newer-graylog-payloads
opened 08:39PM - 02 May 22 UTC
Newer versions of graylog seems to have a slight change in it's structure.
Thi… s PR will allow old and new versions to work.
Some related links:
- [Thread in Rocket.Chat's forum](https://forums.rocket.chat/t/graylog-integration-webhook-error-running-script-in-trigger/13944/2)
- [Issue at Rocket.Chat's Doc.](https://github.com/RocketChat/docs/issues/1830)
- [Graylog latest payload](https://archivedocs.graylog.org/en/2.4/pages/streams/alerts.html#http-alert-notification)