cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to close multiple problem in one go?

We have 50 app pool running on 20 hosts. So when some IIS reset event happens we see more than 700 individual problem occurs.

 

Out of these 700 problems some get auto closed. And some 100-150 problem I have to close manually.

 

Is there any way where I can close such problem in bulk, like close multiple problem in one go.

 

 

 

 

8 REPLIES 8

mgome
Advisor

This is a bit of a brute force approach using the /api/v2/problems API, but here's a command line option using curl to close all open problems:

for i in `curl -X GET "https://{your-domain}/e/{your-environment-id}/api/v2/problems?fields=problemId&pageSize=10&problemSelector=status%28%22open%22%29"  -H "accept: application/json; charset=utf-8" -H "Authorization: Api-Token <API-Token>" | json_pp | grep problemId | awk -F\" '{print $4}'`; do curl -X POST "https://{your-domain}/e/{your-environment-id}/api/v2/problems/$i/close"  -H "accept: application/json; charset=utf-8" -H "Authorization: Api-Token <API-Token>" -H "Content-Type: application/json; charset=utf-8" -d "{\"message\":\"string\"}"; done

 

This assumes you have json_pp on your system which pretty prints JSON.  You can use jq instead if that's available. The above can be modified for specific problems by modifying the problemSelector query parameter.  Here are the options available:

 

  • Status: status("open") or status("closed"). You can specify only one status.
  • Severity level: severityLevel("level-1","level-2"). Find the possible values in the description of the severityLevel field of the response.
  • Impact level: impactLevel("level-11","level-2") Find the possible values in the description of the impactLevel field of the response.
  • Root cause entity: rootCauseEntity("id-1", "id-2").
  • Management zone ID: managementZoneIds("mZId-1", "mzId-2").
  • Management zone name: managementZones("value-1","value-2").
  • Impacted entities: impactedEntities("id-1", "id-2").
  • Affected entities: affectedEntities("id-1", "id-2").
  • Type of affected entities: affectedEntityTypes("value-1","value-2").
  • Problem ID: problemId("id-1", "id-2").
  • Alerting profile ID: problemFilterIds("id-1", "id-2").
  • Alerting profile name (contains, case-insensitive): problemFilterNames("value-1","value-2").
  • Alerting profile name (exact match, case-insensitive): problemFilterNames.equals("value-1","value-2").
  • Entity tags: entityTags("[context]key:value","key:value"). Tags in [context]key:value, key:value, and value formats are detected and parsed automatically. If a value-only tag has a colon (:) in it, you must escape the colon with a backslash(\). Otherwise, the tag will be parsed as a key:value tag. All tag values are case-sensitive.
  • Display ID of the problem: displayId("id-1", "id-2").
  • Under maintenance: underMaintenance(true|false). Shows (true) or hides (false) all problems created during maintenance mode.
  • Text search: text("value"). Text search on the following fields: problem title, event titles, displayId and the id of affected and impacted entities. The text search is case insensitive, partial matching and based on a relevance score. Therefore the relevance sort option should be used to get the most relevant problems first. The special characters ~ and " need to be escaped using a ~ (e.g. double quote search text("~"")). The search value is limited to 30 characters.

 

 

THanks for replying @mgome I will try this solution and let you know.

I don't want to close all problems. But want to close multiple problems in one go.

Any thought how can I do that?

You could use the following in the query string of the first curl command to find problems with IIS in the problem text:

 

Encoded:

problemSelector%3Dtext(%22IIS%22)

 

Decoded:

problemSelector=text("IIS")

 

I use this site to encode and decode URL's

https://meyerweb.com/eric/tools/dencoder/

 

  • Text search: text("value"). Text search on the following fields: problem title, event titles, displayId and the id of affected and impacted entities. The text search is case insensitive, partial matching and based on a relevance score. Therefore the relevance sort option should be used to get the most relevant problems first. The special characters ~ and " need to be escaped using a ~ (e.g. double quote search text("~"")). The search value is limited to 30 characters.

 

rgarzon1
Mentor

Hi roushan.

 

if you can use python its pretty easy.. you only have to create a api token with read and write rights, replace where it marks on the script and its done

 

 

 

import requests
import json
 
# body header for api request
tenant = "{replace_tenant}"

headers = {
    'accept': 'application/json; charset=utf-8',
    'Authorization': '{replace_api_token}}',
    'Content-Type': 'application/json; charset=utf-8'
}
# request url wihout parameters

def parseParameters(parametersquery):
    url = "https://" + tenant + ".live.dynatrace.com/api/v2/problems"
    if parametersquery["problemSelector"] == "true":
        criteria = "?problemSelector="
        for key, value in parametersquery["criteria"].items():
            criteria = criteria + key + "("
            for key2, value2 in value.items():
                if value2 == 1:
                    criteria = criteria +'"'+ key2+'"' + ","
            criteria = criteria[:-1] + "),"
        criteria = criteria[:-1]
        #encode critedria html format 
        dict_html_format = {" ": "%20", "(": "%28", ")": "%29", ",": "%2C", '"': "%22"}
        for key, value in dict_html_format.items():
            criteria = criteria.replace(key, value)
        url = url + criteria
    return url

def closeProblem(list_problemId, tenant, headers):
    try :
        for problemId in list_problemId:
            url = "https://" + tenant + ".live.dynatrace.com/api/v2/problems/" + problemId + "/close"
            payload = "{\"message\": \"close problem by api\"}"
            response = requests.post(url , headers=headers , data=payload)
            print(response.text)
            print("problem Closed : " + problemId)
    except Exception as e:
        print(e)
#define parameters query for select problem to close using criteria
parametersquery = {
    "problemSelector": "true",
    "criteria" : { 
        "status": {
            "OPEN": 1,
            "ACKNOWLEDGED": 0,
            "RESOLVED": 0
        },
        "impactLevel": {
            "SERVICE": 0,
            "APPLICATION": 1,
            "INFRASTRUCTURE": 1,
            "ENVIRONMENT": 0
        },
        "managementZones": {
            "{replace_iis_mngmzone_name}": 1
        },
    }
}

# generate url with parameters
url = parseParameters(parametersquery)
# get list of problem to close 
response = requests.get(url, headers=headers)
# convert response to json
json_response = json.loads(response.text)
# get list of  problemId from json_response
list_problemId = []
for problem in json_response["problems"]:
    list_problemId.append(problem["problemId"])
# close problem by list_problemId
if len(list_problemId) > 0:
    closeProblem(list_problemId, tenant, headers)
else:
    print("no problem to close")
 

 

 

 

its some script that i did sometime ago and adapted to your question.  maybe you can set a tag or allready you have this process in a management zone you can use this to close those problems in bulk with a nice comment

 

hope it helps

have fun

fuelled by coffee and curiosity.

Thank you everyone.

I was able to do it through a powershell script.

===========================================================================

$dtToken = "$(DynatraceToken)"
$inputFile = "$(ProblemInputFile)"

$ProblemID = Get-Content "$inputFile"

$bodyJSON =
@"
{
"message": "auto-close"
}
"@

foreach ($Entry in $ProblemID)
{
$url = "https://{environmentid}.live.dynatrace.com/api/v2/problems/$Entry/close"
Invoke-RestMethod -Method Post -URI $url -Body $bodyJSON -ContentType 'application/json' -Headers @{Authorization=("Api-Token {0}" -f $dtToken)}
write-verbose "Closed - $entry" -verbose
}

xtraspecialj
Guide

How in the world is this not built into the Problems GUI already??  This shouldn't even have to be a feature request...

  Just put a Close button at the top of the table and then some check boxes beside each problem with the inclusion of a Select-All check box at the top, and boom... Users can then select one, multiple, or all problems and close them in one go.  

 

I feel like this is a pretty standard feature.  It's quite perplexing that this isn't included already...

Yes, agreed.  Absolutely poorly done.  C'mon guys.

Featured Posts