Outbound integration message content and limiting post volumes

Not Yet Reviewed

Hello

Firstly, thanks for all of your help to date. It's been really useful to me. I am a coding novice and so have been trying to learn from scratch in order to set up an integration.

I have created the below script (I have changed some of the details for security reasons) in order to send messages to a Slack channel, so that as well as comms going out to people, we gather them into a channel that people can follow.

I have set up the script to run when the event status changes, but want to limit it so that the script only runs once. I have tried to follow advice here (https://support.xmatters.com/hc/en-us/community/posts/215431986-Limiting-the-integration-to-running-only-once), after pasting in the callback.status suggested by Travis, I don't know what to write to say only POST if the status is active. Also, should it be callback.status or req.status for me?

Secondly, I want my payload to include xMatters eventProperties from the message I am sending out in the comms (ie Incident Summary, ticket number etc), but don't know how to do that. So far I can only work out how to set the message manually in the script. (As per the image below). But I need the message to change depending on what I write in the fields of the message.

Any advice you can give me would be much appreciated!

 

if( "status" == "active" )
var req = JSON.parse(request.body);

var msg = 'Heads-up from the TMG SDMs:' + " ";

var eventProperties = 'Incident Summary'

var payload = {};

payload.channel = '#channel name';
payload.text = msg + eventProperties;

var req = http.request({
"method": "POST",
"endpoint": "Slack",
"path": "/slackpath/",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
}
});

req.write(payload);

 

UPDATE: 

Update: I have now seemingly managed to make it only post once, using the script below after trial and error with the tips in the other article (linked to above)

 

 

var callback = JSON.parse(request.body);
console.log('Executing outbound integration for xMatters event ID: ' + callback.eventIdentifier);

// Convert list of event properties to an eventProperties object
if (callback.eventProperties && Array.isArray(callback.eventProperties)) {
var eventProperties = callback.eventProperties;
callback.eventProperties = {};

for (var i = 0; i < eventProperties.length; i++) {
var eventProperty = eventProperties[i];
var key = Object.keys(eventProperty)[0];
callback.eventProperties[key] = eventProperty[key];
}
}

var req = JSON.parse(request.body);

var msg = 'Heads-up from the TMG SDMs \n';

var eventProperties = "Incident Summary";

var payload = {};

payload.channel = '#sm-problems';
payload.text = msg + eventProperties;

if( callback.status == 'active' ) {
var req = http.request({
"method": "POST",
"endpoint": "Slack",
"path": "/SlackPath",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
}
});
// Do stuff
}
else {
// Do nothing
}

req.write(payload);

This seems to result in a message to the Slack channel when creating the event. When I then terminate the event, I get the following message:

"Executing outbound integration for xMatters event ID: 380100 Script failed with message: TypeError: req.write is not a function"

I don't know if this is correct or not, but it does seem to result in doing what I wanted.

However, I still can't work out how to include the body of the message in the outbound payload text. Any assistance you can give me would be much appreciated!!

 

 

0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post