Dynatrace & SNOW integration

devendar koduri
Tera Contributor

Provide the SNOW incident number back into the Dynatrace record as a comment.

 

Problem API v2 - POST a comment-- Dynatrace Docs Post a comment to a problem via Problem v2 API.

Can anyone please help on this stroy.

6 REPLIES 6

Viraj Hudlikar
Giga Sage

Hello @devendar koduri 

To provide the ServiceNow incident number back into the Dynatrace record as a comment, you can use the Dynatrace Problems API v2 to post a comment.

 

  1. Get the ServiceNow Incident Number: Ensure you have the incident number from ServiceNow that you want to post as a comment in Dynatrace.
  2. Prepare the API Request: You need to make a POST request to the Dynatrace Problems API v2 to add a comment to a specific problem.
  3. API Endpoint: The endpoint for posting a comment is: https://{your-environment-id}.live.dynatrace.com/api/v2/problems/{problemId}/comments
  4. Request Headers: It will have your Authorization: Api-Token {your-api-token} and Content-Type: application/json
  5. Request Body: In body of the request we should include the comment with the ServiceNow incident number. Below is sample sricpt which you can include in Business Rule or Script Include.
var problemId = 'YOUR_PROBLEM_ID'; // Replace with the actual problem ID
    var incidentNumber = 'INC1234567'; // Replace with the actual ServiceNow incident number, I have just hardcoded for explaination you can pass it as per requirement.
    var dynatraceApiToken = 'YOUR_API_TOKEN'; // Replace with your Dynatrace API token
    var dynatraceEnvironmentId = 'YOUR_ENVIRONMENT_ID'; // Replace with your Dynatrace environment ID

    var url = 'https://' + dynatraceEnvironmentId + '.live.dynatrace.com/api/v2/problems/' + problemId + '/comments';
    var requestBody = {
        comment: 'ServiceNow Incident Number: ' + incidentNumber
    };

    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint(url);
    request.setHttpMethod('POST');
    request.setRequestHeader('Authorization', 'Api-Token ' + dynatraceApiToken);
    request.setRequestHeader('Content-Type', 'application/json');
    request.setRequestBody(JSON.stringify(requestBody));

    var response = request.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();

    gs.log('Dynatrace API response: ' + httpStatus + ' - ' + responseBody); //This is just for testing purpose whether our API hit is happening with what status sucess or failure. 

 

Refer below for more details:

Dynatrace documentation link - Problems API v2 — Dynatrace Docs

For your requirement this is proper API needed - Problems API v2 - POST a comment — Dynatrace Docs

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Hello @devendar koduri 

 

Thank you for marking my response as helpful! 😊

 

I hope your concern has been fully addressed. If it resolves your issue, please consider marking it as the accepted solution. This will ensure others in the community can benefit from the solution too.

Thanks & Regards
Viraj Hudlikar.

Hello @devendar koduri 

Now as per your latest statement and if I got your correctly then we can follow below steps which will help you.

1) Use a query to find incidents where the monitoring tool is Dynatrace. Extract the problem ID from the incident description field.

2) Use the Dynatrace Problems API v2 to post a comment to the specific problem.

3) Use a Business Rule or Script Include to automate the process.

 

Now your sample script can be as below:

// Extract the problem ID from the incident description
    var description = current.description;
    var problemIdMatch = description.match(/pid:=(\d+_\d+V2)/);
    if (!problemIdMatch) {
        gs.log('No problem ID found in the incident description.');
        return;
    }
    var problemId = problemIdMatch[1];

    // Prepare the API request
    var incidentNumber = current.number;
    var dynatraceApiToken = 'YOUR_API_TOKEN'; // Replace with your Dynatrace API token
    var dynatraceEnvironmentId = 'YOUR_ENVIRONMENT_ID'; // Replace with your Dynatrace environment ID

    var url = 'https://' + dynatraceEnvironmentId + '.live.dynatrace.com/api/v2/problems/' + problemId + '/comments';
    var requestBody = {
        comment: 'ServiceNow Incident Number: ' + incidentNumber
    };

    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint(url);
    request.setHttpMethod('POST');
    request.setRequestHeader('Authorization', 'Api-Token ' + dynatraceApiToken);
    request.setRequestHeader('Content-Type', 'application/json');
    request.setRequestBody(JSON.stringify(requestBody));

    var response = request.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();

    gs.log('Dynatrace API response: ' + httpStatus + ' - ' + responseBody);

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

@devendar koduri 

Thank you for marking my response as helpful! 😊

 

I hope your concern has been fully addressed. If it resolves your issue, please consider marking it as the accepted solution. This will ensure others in the community can benefit from the solution too.

Thanks & Regards
Viraj Hudlikar.