I have taken the out of the box integration code and made some slight adjustments based on our specific company needs. Even still, I don't see why the expected behavior isn't coming through.
Essentially, we have a long list of CI's on the xMatters side, and a much more abbreviated list of Components on the StatusPage side, many of which do not share the exact same name of their associated xMatters CI. Due to this, I needed to create a Hash table to serve as a lookup table.
If a form was submitted for this Comm Plan which included a CI which is found in the Hash Table, it will append the component ID to a variable and then package up in params for the StatusPage create request.
Everything is working except for the components being attached to the incident. For instance, after the incident is created, you realize no notification have gone out so when you enter the Incident in StatusPage you see that notification has been greyed out with the explanation that you need to incldue at least one component for notifications to be sent out -- but I'm fairly certain I am doing that properly in my post request...
Below is my code, and excluded is the hash table due to it's size.
var StatusPage = require( 'StatusPage' );
var callback = JSON.parse(request.body);
var lookup_table = {...};
// 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];
}
}
if (callback.statusChanged) {
if (callback.statusChanged.auditType == 'EVENT_CREATED') {
// Create new StatusPage Event
var components = StatusPage.getComponents();
var props = callback.eventProperties['Configuration Item'].split(', ');
var sp_comp_list = [];
var component_ids = {};
var affected_components = '';
for(var i = 0; i < props.length; i++) {
for(var x = 0; x < components.length; x++) {
if (components[x].name.toLowerCase() == lookup_table[props[i]].toLowerCase()) {
sp_comp_list.push(components[x].name);
// component_ids.push(components[x].id);
var name = components[x].id;
component_ids[name] = 'major_outage';
}
}
}
for(var i = 0; i < sp_comp_list.length; i++) {
affected_components += sp_comp_list[i];
if (i == (sp_comp_list.length - 2)) {
affected_components += ' & ';
} else if (i < (sp_comp_list.length - 1)) {
affected_components += ', ';
}
}
var issues_msg = 'There are reported issues with ';
var apology_msg = 'We apologize for any inconvenience and appreciate your patient as we resolve the issues.';
var msg = issues_msg + affected_components + '. \n\n' + apology_msg;
var statusPageData = StatusPage.createStatusPageIncident(callback.eventIdentifier, msg, component_ids);
}
}
exports.createStatusPageIncident = function(incidentNumber, msg, component_ids) {
console.log('*** Creating StatusPage.io Incident for ' + incidentNumber);
var sPData = this.getStatusPageIncident(incidentNumber);
if (sPData !== null) {
console.log('StatusPage.io Incident already exists for ' + incidentNumber);
return sPData;
} else {
var req = http.request({
'endpoint' : 'StatusPage',
'method' : 'POST',
'path' : '/incidents.json?api_key=' + constants['Status Page Token'],
'headers' : {'Content-Type': 'application/json'}
});
var incident = {};
incident.name = incidentNumber;
incident.message = msg;
incident.components = component_ids;
incident.deliver_notifications = true;
var sPJson = {};
sPJson.incident = incident;
console.log('');
console.log('');
console.log('');
console.log(JSON.stringify(sPJson, null, 2))
console.log('');
console.log('');
console.log('');
var res = req.write(sPJson);
console.log('CreateStatusPage Response ---> ' + res.body);
return JSON.parse(res.body);
}
}
As you can see slightly above, I am printing to the screen my hash payload to verify it is accurate. Here is what it returned...
{ "incident": { "name": 17086053, "message": "There are reported issues with Envestnet, EZ-APP & Wealthscape. \n\nWe apologize for any inconvenience and appreciate your patient as we resolve the issues.", "components": { "ssbw20j440kw": "major_outage", "87x3fm03k5s3": "major_outage", "k3zbmnr7vs1v": "major_outage" }, "deliver_notifications": true } }
This seems to be inline with what the documentations calls for yet it doesn't update the components. Any idea where I am going wrong here?
Comments
Please sign in to leave a comment.
Fixed it. I had to also include the list of strictly ID's in the component_ids field as well as the other field I had listed above.
Thanks for sharing the problem you ran into and what you found to be the solution! Hopefully this sheds a light for those that may come across this as well.