Note:

Use OCI Functions and Python to Open Tickets in Jira Service Management

Introduction

The following tutorial is addressed to Oracle Cloud Infrastructure (OCI) users who use both the OCI Monitoring service and Jira Service Management to open tickets and track incidents. Let us say you have an OCI instance and you want to know when the instance goes down unexpectedly due to some error. You want to be notified and a ticket opened in Jira Service Management immediately so that the on-duty engineer can start investigating and fix the issue as soon as possible. Using the OCI Functions service, tickets can be automatically opened in Jira Service Management when problems are detected with your organization systems.

Objectives

Prerequisites

Task 1: Create a Virtual Cloud Network

A virtual cloud network (VCN) is a network that you define in OCI. It includes subnets, route tables, and gateways.

  1. Click the services menu Services menu near the upper left corner of the OCI Console.

  2. Under Networking, select Virtual Cloud Networks.

  3. In the Virtual Cloud Networks page, click Start VCN Wizard.

  4. Select Create VCN with Internet Connectivity and click Start VCN Wizard.

  5. Complete the VCN configuration, click Next and Create.

Task 2: Create a Dynamic Group

Dynamic groups allow you to group OCI Compute instances as principal actors (similar to user groups).

Note: You need Administrator privileges in order to create dynamic groups.

  1. From the services menu, navigate to Identity & Security, Identity and click Dynamic Groups.

  2. Click Create Dynamic Group.

  3. Enter a meaningful Name and Description.

  4. In the Rule 1 section, add the following line:

    ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.compartment.oc1', instance.compartment.id = 'ocid1.compartment.oc1'}

    Note: Replace compartment ID with your desired compartment ID.

  5. Click Create.

Task 3: Create OCI IAM Policies

Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) enables you to control who has access to your cloud resources. In order for this integration to work we need to grant access for the Function as a service (FaaS) services (function service) to the vault, repos and several other services.

  1. From the services menu, navigate to Identity & Security, Identity and click Policies.

  2. Click Create Policy.

  3. Enter an appropriate Name and Description and make sure to pick the correct compartment, (in this example, we will use the compartment named DEV).

  4. In the Policy Builder section, make sure to enable Show manual editor and add the following lines:

    Allow service faas to read repos in tenancy
    
    Allow service faas to read secret-family in compartment DEV
    
    Allow service faas to read vaults in compartment DEV
    
    Allow service faas to use keys in compartment DEV
    
    Allow service faas to use apm-domains in compartment DEV
    
    Allow dynamic-group DGNAME to read secret-family in compartment DEV
    
    Allow dynamic-group DGNAME to read vaults in compartment DEV
    
    Allow dynamic-group DGNAME to use keys in compartment DEV
    

    Note: Replace the dynamic group (DGNAME) name and compartment (DEV) name with your desired names.

  5. Click Create.

Task 4: Create a Repository to Store the Function

OCI Container Registry enables you to store, share, and manage container images (such as Docker images) in an Oracle-managed registry.

  1. Go to the OCI Console, open the service menu and click Developer Services. Under Containers, click Container Registry.

  2. Click Create Repository.

  3. In the Create Repository dialog box, specify Compartment and Repository Name of your choice and leave it Private.

  4. Click Create Repository.

Task 5: Create a Vault to Store the User and API Token for the Jira Service Management Login

Oracle Cloud Infrastructure Vault is a key management service that stores and manages master encryption keys and secrets for secure access to resources.

  1. Open the service menu, click Identity & Security and Vault.

  2. Click Create Vault.

  3. In the Create Vault dialog box, select the compartment of your choice, and enter an appropriate Name of your choice. You can also chose if you want to make it private or not.

    Note: You cannot change the vault type after the vault is created.

  4. When you are finished, click Create Vault.

    Note: Save the Jira Service Management api-token and api-user separately in the vault.

Task 6: Create an Application

  1. Open the service menu and click Developer Services. Under Functions, click Applications.

  2. Click Create Application.

  3. In the Create Application window, enter the Name of the application (for example, Jira-Ticketing), select the VCN created in Task 1 and select public subnet.

  4. Click Create.

Task 7: Deploy the Function

This task will use the zip archive that can be downloaded from the Prerequisites section.

  1. Select the newly created application in Task 6 from the list.

  2. In the Application windows, follow the steps that are available on the Getting started option under Resources.

    Note:

    • In this tutorial, we use the OCI Cloud Shell setup.

    • In step 4 of the setup, make sure to specify the repository name created in Task 4.

  3. Once you click Launch Cloud Shell, a new small shell window will display on the bottom of the page. In the right upper corner of that window, click the cogwheel menu and select Upload

  4. Drag and drop the jsm-ticket-function.zip file which will be uploaded in the home directory.

  5. Unzip the archive using the following command.

    unzip jsm-ticket-function.zip
    
  6. Switch to the function directory using the cd jsm-ticket-function command and proceed with the steps described in the OCI Console.

Task 8: Edit the Function Configuration

The functions have a few configurable parameters that must be edited in order for the function to work properly.

  1. In the OCI Console, go to the application created in Task 6 and select Functions from the left side under Resources.

  2. Click the name of the function jsm-ticket-function.

  3. Click Configuration under Resources. You will be able to see five keys: api-token, api-user, service_desk_id, request_type_id and vault_ocid.

    All these keys must be edited with your configuration:

    • api-token: Name of the secret from the vault where the api-token of the user account that the ticket is created on behalf of is stored. For more information, see Manage API tokens for your Atlassian account.

    • api-user: Name of the secret from the vault were the email address of the user that the ticket will be created on behalf of is stored.

    • service_desk_id: Project where the ticket will be created.

    • request_type_id: Request type that the ticket will be created as (This must have a title and a description).

    • vault_ocid: vault_ocid where the api-token and api-user secrets are stored.

    The quick and easy way to get the service_desk_id and request_type_id is to visit the portal you want to use and look at the URLs. For example, go to a portal, and click on a request to raise and you will see a URL like: https://somewhere.atlassian.net/servicedesk/customer/portal/10/group/229/create/664

    The numbers in there are:

    • 10: The portal/servicedesk.
    • 229: The group the request is coming in by (only used by navigation, you do not care about that in REST).
    • 664: The id of the request type I have clicked on.

Task 9: Subscribe the Function to a Topic

  1. Open the service menu and click Developer Services. Under Application Integration, click Notifications.

    Note: Make sure to be in the right compartment.

  2. Click Create Topic.

  3. Enter an appropriate name and click Create.

  4. After the topic is created, select it from the list of topics.

  5. In the Topics window, select Subscriptions from the left side under Resources and click Create Subscription.

  6. In the Create Subscription window, select the protocol to be Functions, select the compartment, the application and the function created in Task 6.

  7. Click Create.

Task 10: Create an Alarm for the Desired Metric you need Monitored

You can create multiple types of alarms. In this tutorial, we have chosen an absence alarm.

  1. Open the service menu and click Observability & Management. Under Monitoring, click Alarm Definitions.

  2. Click Create Alarm.

  3. In the Create Alarm page, under Define alarm, enter or update the alarm settings.

  4. Under Define Alarm Notifications, make sure to select the topic created in Task 9.

  5. Select the Message Format as Send Pretty JSON messages (raw text with line breaks).

  6. Click Save alarm.

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.