10 Nov 2022 07:06 PM
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.
Solved! Go to Solution.
10 Nov 2022 07:29 PM
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:
11 Nov 2022 05:13 PM
THanks for replying @mgome I will try this solution and let you know.
11 Nov 2022 06:33 PM
I don't want to close all problems. But want to close multiple problems in one go.
Any thought how can I do that?
11 Nov 2022 07:18 PM
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/
12 Nov 2022 06:09 AM - edited 13 Nov 2022 07:17 AM
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
09 Dec 2022 06:38 PM
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
}
10 Jun 2023 04:55 PM
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...
05 Dec 2023 08:52 PM
Yes, agreed. Absolutely poorly done. C'mon guys.