4 Using Default Templates

This chapter provides details on the default ticket templates shipped along with the PagerDuty Connector. The ticket templates specify the mappings between an Enterprise Manager incident and underlying event attributes and PagerDuty ticket attributes.

Template Process

All out-of-box templates cause the following actions to occur when you create a ticket for an incident:

  • Write incident information to Description (PagerDuty ticket description).

  • Set the PagerDuty ticket summary based on the incident message.

The out-of-box templates are as follows:

  • pagerDutyCreateUpdateAndResolve.xsl

    The pagerDutyCreateUpdateAndResolve.xsl template sets the ticket status to Resolved when the event severity value becomes clear.

  • pagerDutyCreateAndUpdate.xsl

    The pagerDutyCreateAndUpdate.xsl template will update the ticket as details change in Oracle Enterprise Manager but does not close the ticket when the event severity becomes clear.

Reading Ticket Templates

The following table illustrates the creation of a ticket using pagerDutyCreateUpdateAndResolve.xsl. This illustration will help you to read a ticket template. In the tables, * denotes a literal string and ** indicates if the attribute applies. Additionally, the table also shows PagerDuty ticket attributes and corresponding Enterprise Manager incident values for ticket creation mappings.

Ticket creation mappings are the same for pagerDutyCreateUpdateAndResolve.xsl, and pagerDutyCreateAndUpdate.xsl.

Table 4-1 Ticket Creation Mappings (for all templates)

PagerDuty Ticket Attributes Enterprise Manager incident Attributes Value

type

.

“incident” *

service/id

$SERVICE_ID$

Set to the value of Service ID during configuration

service/type

.

"service_reference" *

body/type

.

“incident_body” *

body/details

Summary

Severity Code

Priority

Notification Rule Name

Notification Rule Owner

Target Type

Target Name

Obj Owner

Target Properties

Last Updated Date

Incident URL

Summary – The details about the incident that has fired

Severity Code – The severity of the incident in Oracle Enterprise Manager

Priority – The priority of the incident in Oracle Enterprise Manager

Notification Rule Name – Name of the rule that created the ticket (Auto ticketing only)

Notification Rule Owner – Name of the user that owns the rule that created the ticket (Auto ticketing only)

Target Type – The type of target that the incident fired on

Target Name – The name of the target that the incident fired on

Obj Owner – Name of the user that owns the object the incident is fired on

Target Properties – Additional names and values about the incident. Includes things like host, version, OS and platform

Last Updated Date – Date the incident was created in Oracle Enterprise Manager

Incident URL – A URL link that directs the user to the Oracle Enterprise Manager Incident

Title

Severity Code

Summary

Severity Code – The severity of the incident in Oracle Enterprise Manager

Summary – The details about the incident that has fired.

Urgency

Severity Code

The severity of the incident in Oracle Enterprise Manager. If the severity is Fatal or Critical, set Urgency to ‘High’ Otherwise, set the Urgency to ‘Low’

Status

.

Hardcoded to ‘resolve’.

Note:

This is only in the pagerDutyCreateUpdateAndResolve.xsl

Use the mapping table above as a reference to read the following XSLT file.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:emcf="http://xmlns.oracle.com/sysman/connector" version="1.0">
  <xsl:template match="emcf:EMIncident">
    <!-- Please remember to backup all files before editing -->
    <!--
        This area is where variables are set to be used in the rest of the template.
        By default there have two variables set:
          * Action: Used to figure out if the the connector is 'creating', 'updating' or 'closing' the PagerDuty Ticket.
          * Severity: Used to set the Urgency of the PagerDuty ticket.

          If you want to add or change variables, do so below.
       -->
    <xsl:variable name="action">
      <xsl:choose>
        <xsl:when test="normalize-space(emcf:TicketID) = ''">CREATE</xsl:when>
        <xsl:when test="(emcf:SystemAttributes/emcf:SeverityCode = 'CLEAR')">CLOSE</xsl:when>
        <xsl:otherwise>UPDATE</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="severity">
      <xsl:choose>
        <xsl:when test="emcf:SystemAttributes/emcf:SeverityCode = 'FATAL'">high</xsl:when>
        <xsl:when test="emcf:SystemAttributes/emcf:SeverityCode = 'CRITICAL'">high</xsl:when>
        <xsl:otherwise>low</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <Message>
      <!--
          The following areas (Method, Variables, and Headers) should not be edited.
          They are used to make communication work between Oracle Enterprise Manager and PagerDuty.
        -->
      <Method>
        <xsl:choose>
          <xsl:when test="$action = 'CREATE'">POST</xsl:when>
          <xsl:when test="$action = 'UPDATE'">PUT</xsl:when>
          <xsl:when test="$action = 'CLOSE'">PUT</xsl:when>
          <xsl:otherwise>ERROR</xsl:otherwise>
        </xsl:choose>
      </Method>
      <Variables>
        <Variable>
          <Name>TKT_ID</Name>
          <Value>
            <xsl:value-of select="normalize-space(emcf:TicketID)" />
          </Value>
        </Variable>
      </Variables>
      <Headers>
        <Header>
          <Name>Authorization</Name>
          <Value>Token token=$TOKEN$</Value>
        </Header>
        <Header>
          <Name>Accept</Name>
          <Value>application/vnd.pagerduty+json;version=2</Value>
        </Header>
        <Header>
          <Name>From</Name>
          <Value>$USER_EMAIL$</Value>
        </Header>
      </Headers>
      <!--
        The body is used to send data to PagerDuty. By default the connector sends data either On Create, Update or Close.
        
        Fields that are sent when the ticket is created are found under the following header: <xsl:if test="$action = 'CREATE'">
          * Details: This fills in the 'details' section of the ticket in PagerDuty.

        Fields that are sent when the ticket is created or updated are found under the following header: <xsl:if test="$action = 'CREATE' or $action = 'UPDATE'">
          * Title: This is the title of the ticket in PagerDuty.
          * Urgency: This sets the urgency ('High' or 'Low') based on the incident's severity.

        Fields that are sent when the ticket is closed are found under the following header: <xsl:if test="$action = 'CLOSE'">
          * Status: This is hard-coded to 'resolved' to close the ticket in PagerDuty.
        -->
      <Body>
        <object>
          <object name="incident">
            <string name="type">incident</string>
            <object name="service">
              <string name="id">$SERVICE_ID$</string>
              <string name="type">service_reference</string>
            </object>
            <xsl:if test="$action = 'CREATE'">
              <object name="body">
                <string name="type">incident_body</string>
                <string name="details">Incident created in Enterprise Manager: <xsl:value-of select="emcf:SystemAttributes/emcf:Summary" />
Original Severity: <xsl:value-of select="emcf:SystemAttributes/emcf:SeverityCode" />
Original Priority: <xsl:value-of select="emcf:SystemAttributes/emcf:Priority" />
<xsl:choose>
  <xsl:when test="normalize-space(emcf:NotificationRuleName) != ''">
Incident trigged by the following rule: <xsl:value-of select="emcf:NotificationRuleName" />
  </xsl:when>
</xsl:choose>
<xsl:choose>
  <xsl:when test="normalize-space(emcf:NotificationRuleOwner) != ''">
Rule is owned by: <xsl:value-of select="emcf:NotificationRuleOwner" />
  </xsl:when>
</xsl:choose>

Target Type: <xsl:value-of select="emcf:SystemAttributes/emcf:SourceInfo/emcf:TargetInfo/emcf:TargetType" />
Target Name: <xsl:value-of select="emcf:SystemAttributes/emcf:SourceInfo/emcf:TargetInfo/emcf:TargetName" />
Original Owner: <xsl:value-of select="emcf:SystemAttributes/emcf:SourceInfo/emcf:SourceObjInfo/emcf:ObjOwner" />

Additional Properties: <xsl:for-each select="emcf:SystemAttributes/emcf:SourceInfo/emcf:TargetInfo/emcf:TargetProperty">
  * <xsl:value-of select="./emcf:Name" />: <xsl:value-of select="./emcf:Value" />
</xsl:for-each>

This incident was created at: <xsl:value-of select="emcf:SystemAttributes/emcf:LastUpdatedDate" />
To manage the incident in Enterprise Manager, click here: <xsl:value-of select="emcf:SystemAttributes/emcf:IncidentURL" />
                </string>
              </object>
            </xsl:if>
            <xsl:if test="$action = 'CREATE' or $action = 'UPDATE'">
              <string name="title">
                <xsl:value-of select="emcf:SystemAttributes/emcf:SeverityCode" />: <xsl:value-of select="emcf:SystemAttributes/emcf:Summary" />
              </string>
              <string name="urgency">
                <xsl:value-of select="$severity" />
              </string>
            </xsl:if>
            <xsl:if test="$action = 'CLOSE'">
              <string name="status">resolved</string>
            </xsl:if>
          </object>
        </object>
      </Body>
    </Message>
  </xsl:template>
</xsl:stylesheet>

Customizing Ticket Templates

If the out-of-box ticket templates do not satisfy your requirements, you can modify them. To do this, Oracle recommends that you use one of the existing templates as the base template. Copy this ticket template to a new file, modify, and register the new ticket template.

You can edit a template directly on Enterprise Manager instead of using the EM CLI command. See Editing Templates and Restoring Templates for more information. See Editing Templates and Restoring Templates for more information.

In most cases, when you modify the ticket template, you might only be changing the mappings. The following examples illustrate this concept:

Example 4-1 Make Warning Severity High Urgency

To create a template to change warning severity to high urgency in PagerDuty, add the following attribute in the template under the variable severity:

<xsl:when test="emcf:SystemAttributes/emcf:SeverityCode = 'WARNING'">high</xsl:when> 

Example 4-2 Altering the Title Name

If you only want the incident summary to appear as a PagerDuty ticket title instead of both message and severity, modify the following attribute:

<string name="title">
 <xsl:value-of select="emcf:SystemAttributes/emcf:Summary" />
</string>

The templates are highly customizable. Oracle recommends that only users with advanced knowledge of XSLT make complex changes.

You can use incident or event rules as a filter to associate proper ticket templates with incidents. You can have as many tickets templates as desired. One incident or event rule can have only one ticket template.

Defining New Templates

The out-of-box templates are based on the default HPD:IncidentInterface_Create,HPD:IncidentInterface forms. If the new ticket templates you define are based on these forms, Customizing Ticket Templates applies.

However, if you use a different form, you need to define a new ticket template.

Enterprise Manager Attributes

The following table provides the Enterprise Manager fields that you can map when using PagerDuty:

Table 4-2 Enterprise Manager Attributes

Data Fields Description

EMUser

  • For auto-ticketing, this is the incident rule owner.

  • For manual ticketing, this is the console user that triggered the ticket creation.

TicketID

Identifies the ticket associated with the current incident (available after ticket creation).

TargetType

Type of target that the incident is associated with, such as host.

TargetName

Name of the target that the incident is associated with. For example, Database1 or yourhost.example.com.

TargetProperties

TargetProperties store environmental or usage context information specific to the target. For example, for Host Target, the name /value pair of TargetProperties are:

  • Comment — Host running the management service and repository.

  • Contact — John Doe

  • Deployment Type — Production

  • Line of Business — Development

  • Location — Redwood Shores

These are out-of-box user-defined target properties. If additional target properties are added, they are displayed with ticket information.

Summary

Description of the incident. For example: CPU Utilization is 100%, crossed warning (80) or critical (95) threshold.

Severity

Severity of the incident: critical, warning, clear, or down.

CollectionTime

Timestamp of an incident occurrence.

IncidentURL

URL to the incident details page of the incident.

NotificationRuleName

Name of the incident rule that generated the notification during auto-ticketing.

TargetTimezone

Timezone of the target associated with the incident.

Format for Creating Ticket Templates

To create ticket templates for custom PagerDuty forms, adhere to the following format:

Example 4-3 Template Format for Custom PagerDuty Forms

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:emcf="http://xmlns.oracle.com/sysman/connector" version="1.0">
  <xsl:template match="emcf:EMIncident">
* [Insert any variables needed here]
 <Message>
      <Method>
        <xsl:choose>
          <xsl:when test="$action = 'CREATE'">POST</xsl:when>
          <xsl:when test="$action = 'UPDATE'">PUT</xsl:when>
          <xsl:when test="$action = 'CLOSE'">PUT</xsl:when>
          <xsl:otherwise>ERROR</xsl:otherwise>
        </xsl:choose>
      </Method>
      <Variables>
        <Variable>
          <Name>TKT_ID</Name>
          <Value>
            <xsl:value-of select="normalize-space(emcf:TicketID)" />
          </Value>
        </Variable>
      </Variables>
      <Headers>
        <Header>
          <Name>Authorization</Name>
          <Value>Token token=$TOKEN$</Value>
        </Header>
        <Header>
          <Name>Accept</Name>
          <Value>application/vnd.pagerduty+json;version=2</Value>
        </Header>
        <Header>
          <Name>From</Name>
          <Value>$USER_EMAIL$</Value>
        </Header>
      </Headers>
      <Body>
* [Insert body changes (details you are sending to PagerDuty) here]
      </Body>
    </Message>
  </xsl:template>
</xsl:stylesheet>