Create a ticket in Jira Service Management Cloud when an alert is created in Opsgenie


Get Started

Not the template you're looking for? Browse more.

About the template


This template demonstrates how to create a new request in Jira Service Management Cloud when an alert is created in Opsgenie with a configurable priority mapping. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnOpsgenieAlertIsCreated
Alert is created

README


๐Ÿ“‹ Overview

This template demonstrates how to create a new request in Jira Service Management Cloud when an alert is created in Opsgenie with a configurable priority mapping.

๐Ÿ–Š๏ธ Setup

  • Configure an API Connection and Event Listener by creating a connector for JSM Cloud and optionally also for the Opsgenie Event Listener, or use existing ones.
  • To pass priority level when creating a JSM request with the API, you need to add the Priority field to the chosen request type form in the Project settings -> Request types -> Chosen-request-type settings.
  • Go to Parameters and configure parameters to meet you needs.
  • Add a value to SERVICE_DESK_NAME variable by providing the JSM project name.
  • Add a value to SERVICE_DESK_REQUEST_TYPE_NAME variable by providing the JSM Request type name.
  • (Optional) Rearrange prioprity mappings by changing values in PRIORITY_MAPPING variable.
  • (Optional) Fill out JSM_SUMMARY_PREFIX variable to add certian prefix that will be used in the summary field in JSM. Example: Created from Opsgenie Alert: <Message from alert>.

๐Ÿš€ Usage

  • Create a new alert in an Opsgenie instance, after successful event processing a new request should be created in JSM Cloud instance.

API Connections


TypeScriptOnOpsgenieAlertIsCreated

import JiraServiceManagementCloud from "./api/jsm/cloud";
import { AlertCreatedEvent } from '@sr-connect/opsgenie/events';

export default async function (event: AlertCreatedEvent, context: Context): Promise<void> {
    if (context.triggerType === 'MANUAL') {
        console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
        return;
    }

    const { SERVICE_DESK_NAME, SERVICE_DESK_REQUEST_TYPE_NAME, JSM_SUMMARY_PREFIX, PRIORITY_MAPPING } = getEnvVars(context);

    // Find Service Desk ID
    const serviceDesks = await JiraServiceManagementCloud.Servicedesk.getServicedesks();
    const serviceDeskId = serviceDesks.values?.find(desk => desk.projectName?.localeCompare(SERVICE_DESK_NAME, 'en', { sensitivity: 'base' }) === 0)?.id;
    if (!serviceDeskId) {
        throw new Error(`Failed to find Service Desk ID. Please check if project name is correct: ${SERVICE_DESK_NAME}.`);
    }

    // Find Request Type ID
    const serviceDeskTypes = await JiraServiceManagementCloud.Request.Type.getTypes({
        serviceDeskId: [+serviceDeskId]
    });
    const requestTypeId = serviceDeskTypes.values?.find(type => type.name?.localeCompare(SERVICE_DESK_REQUEST_TYPE_NAME, 'en', { sensitivity: 'base' }) === 0)?.id;
    if (!requestTypeId) {
        throw new Error(`Failed to find Request Type ID. Please check if Request Type Name is correct: ${SERVICE_DESK_REQUEST_TYPE_NAME}.`);
    }

    const calculatedPriority = PRIORITY_MAPPING[event.alert.priority];

    // Create request in JSM
    const createdRequest = await JiraServiceManagementCloud.Request.createRequest({
        body: {
            requestFieldValues: {
                description: event.alert.description ?? '',
                summary: JSM_SUMMARY_PREFIX ? JSM_SUMMARY_PREFIX + event.alert.message : event.alert.message,
                priority: { name: calculatedPriority } // need to add to the Request type user gonna use
            },
            requestTypeId,
            serviceDeskId,
        }
    });

    console.log(`Created JSM Request ${createdRequest.issueKey} from Opsgenie alert ${event.alert.message} - Alert ID: ${event.alert.alertId}.`);
}

type OpsgeniePriorityId = string;
type JsmPriorityLevel = string;
interface EnvVars {
    SERVICE_DESK_NAME: string;
    SERVICE_DESK_REQUEST_TYPE_NAME: string;
    PRIORITY_MAPPING: Record<OpsgeniePriorityId, JsmPriorityLevel>
    JSM_SUMMARY_PREFIX?: string;
}

export function getEnvVars(context: Context) {
    return context.environment.vars as EnvVars;
}
Documentation ยท Support ยท Suggestions & feature requests