This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Incident Creation in PagerDuty
The first use case in the PagerDuty business scenario is used for incident creation. This page describes the relevant tasks and the operations you use in the PagerDuty connector and the other ESB connectors. It contains the following sections:
Overview
The flow for incident creation is illustrated in the following diagram. The ESB connectors for Gmail, LiveChat, Nexmo and Podio will be used to connect to each service.Â
Note
New lines in the message body are replaced by spaces.
Prerequisite
The messages which need to be created as incidents should be labelled as "Incidents" in Gmail.
Initiate incident
Retrieve selected messages from the Gmail API (where the client has reported the incidents) using the getAMail operation and create an incident in the PagerDuty API using the createIncident operation.Â
Note
Client e-mail should be mapped with the PagerDuty API.
Using the listAllMails operation, retrieve a list of all e-mails from the Gmail API.
Modify existing messages in the Gmail API using the modifyExistingMessages operation.
Retrieve tickets daily from the LiveChat API using the listTickets operation and create an incident in the PagerDuty API using the createIncident operation.
Note
The requester e-mail ID should be mapped with the PagerDuty API.
Create the incident directly in the PagerDuty API when a client logs a call / informs about any incident.
PagerDuty operations
LiveChat operations
Gmail operations
Samples
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. WSO2 Inc. licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- The template creates an incident in pagerduty. --> <template xmlns="http://ws.apache.org/ns/synapse" name="pagerduty_initiateIncidentFromLivechat"> <parameter name="serviceKey" description="Service Key of the Pagerduty API." /> <parameter name="eventType" description="The type of the event to be created." /> <parameter name="description" description="The detailed description of the incident." /> <parameter name="client" description="Client information of the incident." /> <parameter name="ticketId" description="The ID of the Livechat ticket." /> <sequence> <property name="uri.var.serviceKey" expression="$func:serviceKey" /> <property name="uri.var.eventType" expression="$func:eventType" /> <property name="uri.var.description" expression="$func:description" /> <property name="uri.var.client" expression="$func:client" /> <property name="uri.var.ticketId" expression="$func:ticketId" /> <!-- Create an Incident in Pagerduty --> <filter source="boolean(get-property('uri.var.serviceKey'))" regex="true"> <then> <pagerduty.createIncident> <serviceKey>{$ctx:uri.var.serviceKey}</serviceKey> <eventType>{$ctx:uri.var.eventType}</eventType> <description>{$ctx:uri.var.description}</description> <client>{$ctx:uri.var.client}</client> </pagerduty.createIncident> <property name="uri.var.incidentKey" expression="json-eval($.incident_key)" /> <!-- Set error if no mail is not sent --> <filter source="boolean(get-property('uri.var.incidentKey'))" regex="false"> <then> <property name="uri.var.id" expression="fn:concat('ticket Id:', get-property('uri.var.ticketId') )" /> <property name="uri.var.status" value="Error" /> <property name="uri.var.message" expression="json-eval($.errors)" scope="operation" /> </then> <else> <property name="uri.var.id" expression="fn:concat('incident Key:', get-property('uri.var.incidentKey') )" /> <property name="uri.var.status" value="Success" /> <property name="uri.var.message" value="Incident has been successfully created" /> </else> </filter> </then> <else> <property name="uri.var.status" value="Skipped" /> <property name="uri.var.message" value="Pagerduty service key is not provided in the request." /> </else> </filter> <property name="uri.var.activity" value="pageduty_initiateIncident" /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="{$ctx:uri.var.activity}" /> <with-param name="id" value="{$ctx:uri.var.id}" /> <with-param name="status" value="{$ctx:uri.var.status}" /> <with-param name="message" value="{$ctx:uri.var.message}" /> </call-template> </sequence> </template>
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. WSO2 Inc. licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <proxy xmlns="http://ws.apache.org/ns/synapse" name="pagerduty_initiateIncidentFromLivechat" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence onError="faultHandlerSeq"> <!-- LiveChat parameters --> <property name="liveChatApiUrl" value="https://api.livechatinc.com" /> <property name="liveChatApiKey" expression="json-eval($.liveChatApiKey)" /> <property name="liveChatLogin" expression="json-eval($.liveChatLogin)" /> <!-- Pagerduty parameters --> <property name="pagerdutyServiceKey" expression="json-eval($.pagerdutyServiceKey)" /> <!-- Get current date and previous date --> <script language="js"> <![CDATA[ var currentDate = new Date(); var responseDateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd"); var currentDateFormatted = responseDateFormat.format(currentDate); mc.setProperty('currentDate' , currentDateFormatted); ]]> </script> <!-- List tickets in livechat --> <livechat.init> <apiUrl>{$ctx:liveChatApiUrl}</apiUrl> <login>{$ctx:liveChatLogin}</login> <apiKey>{$ctx:liveChatApiKey}</apiKey> </livechat.init> <livechat.listTickets> <dateFrom>{$ctx:currentDate}</dateFrom> <status>open,pending</status> </livechat.listTickets> <sequence key="removeResponseHeaders" /> <property name="ticketsCount" expression="count(//tickets)" scope="operation" /> <!-- Set error if no ticket was found --> <filter xpath="0 = get-property('operation', 'ticketsCount')"> <then> <property name="message" value="No tickets were found." /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="livechat_listTickets" /> <with-param name="status" value="Skipped" /> <with-param name="message" value="{$ctx:message}" /> </call-template> <loopback /> </then> </filter> <property name="responseString" value="" scope="operation" /> <property name="index" expression="0" scope="operation" /> <!-- Subscriptions iterater --> <iterate continueParent="true" id="subscriptionIterator" expression="//tickets" sequential="true"> <target> <sequence> <property name="messageType" value="application/json" scope="axis2" /> <property name="subject" expression="//tickets/subject" /> <property name="pagerdutyClient" expression="//tickets/requester/mail" /> <property name="ticketMessage" expression="//tickets/events[1]/message/text()" /> <!-- Replace new lines in mail body to space --> <script language="js"> <![CDATA[ //request body optional parameters var ticketMessage = mc.getProperty('ticketMessage'); var ticketMessageEncoded = encodeURIComponent(ticketMessage); var ticketMessageNewLineRemoved = ticketMessageEncoded.replace( /%0d%0a/g , '%20'); var ticketMessage = decodeURIComponent(ticketMessageNewLineRemoved); mc.setProperty('ticketMessage' , ticketMessage); ]]> </script> <property name="ticketId" expression="//tickets/id" /> <property name="pagerdutyDescription" expression="fn:concat(get-property('subject'), ' : ', get-property('ticketMessage'))" /> <!-- Call pagerduty_initiateIncidentFromLivechat template --> <call-template target="pagerduty_initiateIncidentFromLivechat"> <with-param name="serviceKey" value="{$ctx:pagerdutyServiceKey}" /> <with-param name="description" value="{$ctx:pagerdutyDescription}" /> <with-param name="client" value="{$ctx:pagerdutyClient}" /> <with-param name="ticketId" value="{$ctx:ticketId}" /> <with-param name="eventType" value="trigger" /> </call-template> <property name="index" expression="get-property('operation','index') + 1" scope="operation" /> </sequence> </target> </iterate> <!-- Check for all the iterations has completed --> <filter xpath="get-property('operation', 'index') = get-property('operation', 'ticketsCount')"> <then> <loopback /> </then> </filter> </inSequence> <outSequence> <payloadFactory media-type="json"> <format> { "Response":{ "activity":"pagerduty_initiateIncidentFromLivechat", "activityResponse":[$1] } } </format> <args> <arg expression="get-property('operation','responseString')" /> </args> </payloadFactory> <property name="messageType" value="application/json" scope="axis2" /> <send /> </outSequence> </target> <description /> </proxy>
{ "liveChatApiKey":"2060213b6509858b4ba2a2cdc1153966", "liveChatLogin":"testapp.mahesh3@gmail.com", "pagerdutyServiceKey":"987a1788c7654030a9f1d8dd1020f67c" }
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. WSO2 Inc. licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- The template creates an incident in pagerduty. --> <template xmlns="http://ws.apache.org/ns/synapse" name="pagerduty_initiateIncidentFromGmail"> <parameter name="serviceKey" description="Service Key of the pagerduty API." /> <parameter name="eventType" description="The type of the event to be created." /> <parameter name="description" description="The detailed description of the incident." /> <parameter name="client" description="Client information of the incident." /> <parameter name="gmailMessageId" description="ID of the email in Gmail API." /> <parameter name="gmailAccessToken" description="The access token of the Gmail API." /> <parameter name="gmailUserId" description="The ID of the user." /> <parameter name="gmailIncidentLabelId" description="The ID of the incidents label." /> <parameter name="gmailArchivedIncidentLabelId" description="The ID of the archived incidents label." /> <sequence> <property name="uri.var.serviceKey" expression="$func:serviceKey" /> <property name="uri.var.eventType" expression="$func:eventType" /> <property name="uri.var.description" expression="$func:description" /> <property name="uri.var.client" expression="$func:client" /> <property name="uri.var.gmailMessageId" expression="$func:gmailMessageId" /> <property name="uri.var.gmailAccessToken" expression="$func:gmailAccessToken" /> <property name="uri.var.gmailUserId" expression="$func:gmailUserId" /> <property name="uri.var.gmailIncidentLabelId" expression="$func:gmailIncidentLabelId" /> <property name="uri.var.gmailArchivedIncidentLabelId" expression="$func:gmailArchivedIncidentLabelId" /> <!-- Create an Incident in pagerduty --> <filter source="boolean(get-property('uri.var.serviceKey'))" regex="true"> <then> <pagerduty.createIncident> <serviceKey>{$ctx:uri.var.serviceKey}</serviceKey> <eventType>{$ctx:uri.var.eventType}</eventType> <description>{$ctx:uri.var.description}</description> <client>{$ctx:uri.var.client}</client> </pagerduty.createIncident> <property name="uri.var.incidentKey" expression="json-eval($.incident_key)" /> <!-- Set error if incident was created --> <filter source="boolean(get-property('uri.var.incidentKey'))" regex="false"> <then> <property name="uri.var.id" expression="fn:concat('message Id:', get-property('uri.var.gmailMessageId') )" /> <property name="uri.var.status" value="Error" /> <property name="uri.var.message" expression="json-eval($.errors)" /> </then> <else> <!-- Constructing JSON Objects --> <payloadFactory media-type="json"> <format> { "addLabelIds":["$1"], "removeLabelIds":["$2"] } </format> <args> <arg expression="get-property('uri.var.gmailArchivedIncidentLabelId')" /> <arg expression="get-property('uri.var.gmailIncidentLabelId')" /> </args> </payloadFactory> <property name="uri.var.addLabelIds" expression="json-eval($.addLabelIds)" /> <property name="uri.var.removeLabelIds" expression="json-eval($.removeLabelIds)" /> <!-- Move to archived Incident label --> <gmail.gmailinit> <access_token>{$ctx:uri.var.gmailAccessToken}</access_token> <userId>{$ctx:uri.var.gmailUserId}</userId> </gmail.gmailinit> <gmail.modifyExistingMessages> <id>{$ctx:uri.var.gmailMessageId}</id> <addLabelIds>{$ctx:uri.var.addLabelIds}</addLabelIds> <removeLabelIds>{$ctx:uri.var.removeLabelIds}</removeLabelIds> </gmail.modifyExistingMessages> <property name="responseStatus" expression="$axis2:HTTP_SC" /> <filter xpath="get-property('responseStatus') = 200"> <then> <property name="uri.var.id" expression="fn:concat('incident Key:', get-property('uri.var.incidentKey') )" /> <property name="uri.var.status" value="Success" /> <property name="uri.var.message" value="Incident has been successfully created and the mail has been labeled as archivedIncident" /> </then> <else> <property name="uri.var.id" expression="fn:concat('incident Key:', get-property('uri.var.incidentKey') )" /> <property name="uri.var.status" value="Success" /> <property name="uri.var.message" value="Incident has been successfully created but the mail could not be labeled as archivedIncident. Please label this as manually. " /> </else> </filter> </else> </filter> </then> <else> <property name="uri.var.status" value="Skipped" /> <property name="uri.var.message" value="Pagerduty service key is not provided in the request." /> </else> </filter> <property name="uri.var.activity" value="pageduty_initiateIncident" /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="{$ctx:uri.var.activity}" /> <with-param name="id" value="{$ctx:uri.var.id}" /> <with-param name="status" value="{$ctx:uri.var.status}" /> <with-param name="message" value="{$ctx:uri.var.message}" /> </call-template> </sequence> </template>
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. WSO2 Inc. licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <proxy xmlns="http://ws.apache.org/ns/synapse" name="pagerduty_initiateIncidentFromGmail" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence onError="faultHandlerSeq"> <!-- Gmail parameters --> <property name="gmailAccessToken" expression="json-eval($.gmailAccessToken)" /> <property name="gmailUserId" expression="json-eval($.gmailUserId)" /> <property name="gmailIncidentLabelId" expression="json-eval($.gmailIncidentLabelId)" /> <property name="gmailArchivedIncidentLabelId" expression="json-eval($.gmailArchivedIncidentLabelId)" /> <!-- Pagerduty parameters --> <property name="pagerdutyServiceKey" expression="json-eval($.pagerdutyServiceKey)" /> <!-- List all mails in Gmail --> <gmail.gmailinit> <access_token>{$ctx:gmailAccessToken}</access_token> <userId>{$ctx:gmailUserId}</userId> </gmail.gmailinit> <gmail.listAllMails> <q>label:Incidents</q> </gmail.listAllMails> <property name="responseStatus" expression="$axis2:HTTP_SC" /> <filter xpath="get-property('responseStatus') != 200"> <then> <property name="status" value="Failed" /> <filter xpath="get-property('responseStatus') = 404"> <then> <property name="message" value="Invalid Credentials" /> </then> <else> <property name="message" expression="//jsonObject/error/message/text()" /> </else> </filter> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="gmail_listMails" /> <with-param name="status" value="Skipped" /> <with-param name="message" value="{$ctx:message}" /> </call-template> <loopback /> </then> </filter> <property name="messagesCount" expression="count(//messages)" scope="operation" /> <!-- Set error if no mail was found --> <filter xpath="get-property('operation', 'messagesCount') = 0"> <then> <property name="message" value="No messages were found." /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="gmail_listMails" /> <with-param name="status" value="Skipped" /> <with-param name="message" value="{$ctx:message}" /> </call-template> <loopback /> </then> </filter> <property name="responseString" value="" scope="operation" /> <property name="index" expression="0" scope="operation" /> <!-- messages iterater --> <iterate continueParent="true" id="messagesIterator" expression="//messages" sequential="true"> <target> <sequence> <property name="messageType" value="application/json" scope="axis2" /> <property name="gmailMessageId" expression="json-eval($.messages.id)" /> <!-- Retrieve an email --> <gmail.gmailinit> <access_token>{$ctx:gmailAccessToken}</access_token> <userId>{$ctx:gmailUserId}</userId> </gmail.gmailinit> <gmail.getAMail> <id>{$ctx:gmailMessageId}</id> </gmail.getAMail> <property name="gmailDescription" expression="//parts[mimeType='text/plain']/body/data" /> <property name="email" expression="fn:substring-before(fn:substring-after(//headers[name='From']/value/text(), '<'), '>')" /> <!-- Base64Decode and get the JSON object from Base64Encoded String. --> <script language="js"> <![CDATA[ function base64_decode(data) { var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = '', tmp_arr = []; if (data.trim().length == 0) { return data; } else { data += ''; } do { // unpack four hexets into three octets using index points in b64 h1 = b64.indexOf(data.charAt(i++)); h2 = b64.indexOf(data.charAt(i++)); h3 = b64.indexOf(data.charAt(i++)); h4 = b64.indexOf(data.charAt(i++)); bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; o1 = bits >> 16 & 0xff; o2 = bits >> 8 & 0xff; o3 = bits & 0xff; if (h3 == 64) { tmp_arr[ac++] = String.fromCharCode(o1); } else if (h4 == 64) { tmp_arr[ac++] = String.fromCharCode(o1, o2); } else { tmp_arr[ac++] = String.fromCharCode(o1, o2, o3); } } while (i < data.length); dec = tmp_arr.join(''); return dec.replace(/\0+$/, ''); } var binaryString = mc.getProperty('gmailDescription'); if(binaryString != null && binaryString != ""){ var gmailDescription = base64_decode(binaryString); mc.setProperty('gmailDescription' , gmailDescription); } ]]> </script> <!-- Replace new lines in mail body to space --> <script language="js"> <![CDATA[ //request body optional parameters var gmailDescription = mc.getProperty('gmailDescription'); var gmailDescriptionEncoded = encodeURIComponent(gmailDescription); var gmailDescriptionNewLineRemoved = gmailDescriptionEncoded.replace( /%0d%0a/g , '%20'); var gmailDescription = decodeURIComponent(gmailDescriptionNewLineRemoved); mc.setProperty('gmailDescription' , gmailDescription); ]]> </script> <!-- Call pagerduty_initiateIncidentFromGmail template --> <call-template target="pagerduty_initiateIncidentFromGmail"> <with-param name="serviceKey" value="{$ctx:pagerdutyServiceKey}" /> <with-param name="description" value="{$ctx:gmailDescription}" /> <with-param name="client" value="{$ctx:email}" /> <with-param name="gmailMessageId" value="{$ctx:gmailMessageId}" /> <with-param name="eventType" value="trigger" /> <with-param name="gmailAccessToken" value="{$ctx:gmailAccessToken}" /> <with-param name="gmailUserId" value="{$ctx:gmailUserId}" /> <with-param name="gmailIncidentLabelId" value="{$ctx:gmailIncidentLabelId}" /> <with-param name="gmailArchivedIncidentLabelId" value="{$ctx:gmailArchivedIncidentLabelId}" /> </call-template> <property name="index" expression="get-property('operation','index') + 1" scope="operation" /> </sequence> </target> </iterate> <!-- Check for all the iterations has completed --> <filter xpath="get-property('operation', 'index') = get-property('operation', 'messagesCount')"> <then> <loopback /> </then> </filter> </inSequence> <outSequence> <payloadFactory media-type="json"> <format> { "Response":{ "activity":"pagerduty_initiateIncidentFromGmail", "activityResponse":[$1] } } </format> <args> <arg expression="get-property('operation','responseString')" /> </args> </payloadFactory> <property name="messageType" value="application/json" scope="axis2" /> <send /> </outSequence> </target> <description /> </proxy>
{ "gmailAccessToken":"ya29.OgH8caLfYPy14T5450POD8bv-kniti6q-MS49bItOwCo_I-79FhE5JzbEmm2DpotWJo4mfaMGIXokg", "gmailUserId":"anuradhika.wije@gmail.com", "gmailIncidentLabelId":"Label_6", "gmailArchivedIncidentLabelId":"Label_7", "pagerdutyServiceKey":"987a1788c7654030a9f1d8dd1020f67c" }
Task Assignment
Assign an incident to a user in the PagerDuty API using the reassignIncident operation.
- Retrieve the contact methods for the user from PagerDuty using the listContactMethods operation.
 Notify the assignee by sending an SMS using the sendMessage operation in the Nexmo API.
 Using the getIncidentById operation, retrieve the incident details from the PagerDuty API.Â
- Create a task in the Podio API using the createTask operation with the incident details in order to track it in a detailed manner.Â
PagerDuty operations
Podio operations
Nexmo operations
Samples
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. WSO2 Inc. licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <proxy xmlns="http://ws.apache.org/ns/synapse" name="pagerduty_reassignIncident" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence onError="faultHandlerSeq"> <!-- PagerDuty API call related properties --> <property name="pagerdutyApiUrl" expression="json-eval($.pagerdutyApiUrl)"/> <property name="pagerdutyApiToken" expression="json-eval($.pagerdutyApiToken)"/> <property name="pagerdutyIncidentId" expression="json-eval($.pagerdutyIncidentId)"/> <property name="pagerdutyAssignedToUser" expression="json-eval($.pagerdutyAssignedToUser)"/> <property name="pagerdutyRequesterId" expression="json-eval($.pagerdutyRequesterId)"/> <!-- Nexmo API call related properties --> <property name="nexmoApiUrl" value="https://rest.nexmo.com"/> <property name="nexmoApiKey" expression="json-eval($.nexmoApiKey)"/> <property name="nexmoApiSecret" expression="json-eval($.nexmoApiSecret)"/> <property name="nexmoFrom" expression="json-eval($.nexmoFrom)"/> <!-- Podio API call related properties --> <property name="podioApiUrl" value="https://api.podio.com" /> <property name="podioAccessToken" expression="json-eval($.podioAccessToken)" /> <property name="responseString" value="" scope="operation" /> <!-- Reassign incident in PagerDuty --> <pagerduty.init> <apiUrl>{$ctx:pagerdutyApiUrl}</apiUrl> <apiToken>{$ctx:pagerdutyApiToken}</apiToken> </pagerduty.init> <pagerduty.reassignIncident> <incidentId>{$ctx:pagerdutyIncidentId}</incidentId> <requesterId>{$ctx:pagerdutyRequesterId}</requesterId> <assignedToUser>{$ctx:pagerdutyAssignedToUser}</assignedToUser> </pagerduty.reassignIncident> <property name="responseStatus" expression="$axis2:HTTP_SC" /> <filter xpath="get-property('responseStatus') != 200"> <then> <property name="id" expression="fn:concat('pagerdutyIncidentId:', get-property('pagerdutyIncidentId'), ',pagerdutyAssignedToUser:', get-property('pagerdutyAssignedToUser'))" /> <property name="errorMessage" expression="fn:concat('(',$axis2:HTTP_SC,'), Cannot reassign the incident in PagerDuty')" /> <filter xpath="get-property('responseStatus') = 400"> <then> <property name="apiResponseError" expression="json-eval($.error.message)" /> <property name="errorMessage" expression="fn:concat(get-property('errorMessage'), '. Error: ', get-property('apiResponseError'))" /> </then> </filter> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="pagerduty_reassignIncident" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Error" /> <with-param name="message" value="{$ctx:errorMessage}" /> </call-template> <loopback /> </then> <else> <!-- Incident reassigned successfully --> <property name="id" expression="fn:concat('pagerdutyIncidentId:', get-property('pagerdutyIncidentId'), ',pagerdutyAssignedToUser:', get-property('pagerdutyAssignedToUser'))" /> <property name="errorMessage" value="The incident has been successfully reassigned" /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="pagerduty_reassignIncident" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Success" /> <with-param name="message" value="{$ctx:errorMessage}" /> </call-template> <!-- Retrieve user contact method of type SMS --> <pagerduty.init> <apiUrl>{$ctx:pagerdutyApiUrl}</apiUrl> <apiToken>{$ctx:pagerdutyApiToken}</apiToken> </pagerduty.init> <pagerduty.listContactMethods> <userId>{$ctx:pagerdutyAssignedToUser}</userId> </pagerduty.listContactMethods> <property name="id" expression="fn:concat('pagerdutyIncidentId:', get-property('pagerdutyIncidentId'), ',pagerdutyAssignedToUser:', get-property('pagerdutyAssignedToUser'))" /> <property name="responseStatus" expression="$axis2:HTTP_SC" /> <filter xpath="get-property('responseStatus') != 200"> <then> <property name="errorMessage" expression="fn:concat('(',$axis2:HTTP_SC,'), Cannot retrieve contact information from PagerDuty')" /> <filter xpath="get-property('responseStatus') = 400"> <then> <property name="apiResponseError" expression="json-eval($.error.message)" /> <property name="errorMessage" expression="fn:concat(get-property('errorMessage'), '. Error: ', get-property('apiResponseError'))" /> </then> </filter> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="nexmo_sendMessage" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Error" /> <with-param name="message" value="{$ctx:errorMessage}" /> </call-template> </then> <else> <property name="countryCode" expression="//contact_methods[type = 'SMS']/country_code" /> <property name="phoneNumber" expression="//contact_methods[type = 'SMS']/address" /> <property name="nexmoMessageTo" expression="fn:concat(get-property('countryCode'), get-property('phoneNumber'))"/> <!-- Construct the message to be sent --> <property name="nexmoMessageText" expression="fn:concat('You have been assigned an incident in PagerDuty. Incident Id: ', get-property('pagerdutyIncidentId'))" /> <!-- Send message to the assignee --> <nexmo.init> <responseType>json</responseType> <apiUrl>{$ctx:nexmoApiUrl}</apiUrl> <apiSecret>{$ctx:nexmoApiSecret}</apiSecret> <apiKey>{$ctx:nexmoApiKey}</apiKey> </nexmo.init> <nexmo.sendMessage> <to>{$ctx:nexmoMessageTo}</to> <text>{$ctx:nexmoMessageText}</text> <from>{$ctx:nexmoFrom}</from> </nexmo.sendMessage> <property name="id" expression="fn:concat('pagerdutyIncidentId:', get-property('pagerdutyIncidentId'), ',recipientPhoneNumber:', get-property('nexmoMessageTo'))" /> <property name="apiResponseError" expression="json-eval($.messages[0].error-text)" /> <filter source="boolean(get-property('apiResponseError'))" regex="true"> <then> <property name="errorMessage" expression="fn:concat('Cannot send message via Nexmo. Error: ', get-property('apiResponseError'))" /> <property name="status" value="Error" /> </then> <else> <property name="errorMessage" value="Message has been successfully sent to the assignee via Nexmo" /> <property name="status" value="Success" /> </else> </filter> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="nexmo_sendMessage" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="{$ctx:status}" /> <with-param name="message" value="{$ctx:errorMessage}" /> </call-template> </else> </filter> <!-- Task creation in Podio happens along side with send message --> <pagerduty.init> <apiUrl>{$ctx:pagerdutyApiUrl}</apiUrl> <apiToken>{$ctx:pagerdutyApiToken}</apiToken> </pagerduty.init> <pagerduty.getIncidentById> <incidentId>{$ctx:pagerdutyIncidentId}</incidentId> </pagerduty.getIncidentById> <property name="id" expression="fn:concat('pagerdutyIncidentId:', get-property('pagerdutyIncidentId'))" /> <property name="responseStatus" expression="$axis2:HTTP_SC" /> <filter xpath="get-property('responseStatus') != 200"> <then> <property name="errorMessage" expression="fn:concat('(',$axis2:HTTP_SC,'), Cannot retreive incident details from PagerDuty')" /> <filter xpath="get-property('responseStatus') = 400"> <then> <property name="apiResponseError" expression="json-eval($.error.message)" /> <property name="errorMessage" expression="fn:concat(get-property('errorMessage'), '. Error: ', get-property('apiResponseError'))" /> </then> </filter> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="podio_createTask" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Error" /> <with-param name="message" value="{$ctx:errorMessage}" /> </call-template> </then> <else> <property name="incidentText" expression="json-eval($.trigger_summary_data.description)" /> <!-- Create the task in Podio. --> <podio.init> <apiUrl>{$ctx:podioApiUrl}</apiUrl> <accessToken>{$ctx:podioAccessToken}</accessToken> </podio.init> <podio.createTask> <text>{$ctx:incidentText}</text> <externalId>{$ctx:pagerdutyIncidentId}</externalId> </podio.createTask> <property name="responseStatus" expression="$axis2:HTTP_SC" /> <filter xpath="get-property('responseStatus') != 200"> <then> <property name="apiResponseError" expression="json-eval($.error_description)" /> <property name="errorMessage" expression="fn:concat('(',$axis2:HTTP_SC,'), Cannot create a task in Podio. Error: ', get-property('apiResponseError'))" /> <property name="status" value="Error" /> </then> <else> <property name="podioTaskId" expression="json-eval($.task_id)" /> <property name="id" expression="fn:concat(get-property('id'), ',podioTaskId:', get-property('podioTaskId'))" /> <property name="errorMessage" value="Task has been successfully created in Podio" /> <property name="status" value="Success" /> </else> </filter> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="podio_createTask" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="{$ctx:status}" /> <with-param name="message" value="{$ctx:errorMessage}" /> </call-template> </else> </filter> <loopback /> </else> </filter> </inSequence> <outSequence> <property name="messageType" value="application/json" scope="axis2" /> <!-- Generate the chained response of all the API calls in createLeads --> <payloadFactory media-type="json"> <format> { "Response":{ "process":"pagerduty_reassignIncident", "activityResponse":[$1] } } </format> <args> <arg expression="get-property('operation', 'responseString')" /> </args> </payloadFactory> <send /> </outSequence> </target> <description /> </proxy>
{ "pagerdutyApiUrl":"https://testapp.pagerduty.com", "pagerdutyApiToken":"jgdo99z92Tf8NfpBAVbK", "pagerdutyIncidentId":"PK215L6", "pagerdutyAssignedToUser":"PTP0EVW", "pagerdutyRequesterId":"PQ95A5D", "nexmoApiKey":"3e6f0549", "nexmoApiSecret":"b2072665", "nexmoFrom":"PagerDuty Admin", "podioAccessToken":"70d0449cf781416aad67a1ad4629858e" }