Created
August 23, 2018 13:30
-
-
Save Tasumin/c9ceb84c1f514d8ffae8b091d2871f62 to your computer and use it in GitHub Desktop.
Disable Execution Plans in Truesight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$appid=1, | |
[string]$tspshost="tsps.bmc.com" | |
) | |
function get_login_headers() { | |
$loginuri = "https://$tspshost/tsws/10.0/api/authenticate/login" | |
$method = "POST" | |
$postParams = @{username='user';password='password';tenantName='bmcrealm'} | |
#we will expect a 200 response and pull the authtoken from the json content | |
$response = Invoke-WebRequest -Uri $loginuri -Method $method -Body $postParams | |
$respjson = $response.Content | ConvertFrom-Json | |
$authtoken = $respjson.response.authToken | |
$headers = @{ | |
"Pragma" = "no-cache"; | |
"Origin" = "https://$tspshost"; | |
"Authorization" = "authToken $authtoken"; | |
"Content-Type" = "application/json"; | |
"Referer" = "https://$tspshost"; | |
} | |
return $headers | |
} | |
function get_exec_plans($appid) { | |
$uri ="https://$tspshost/tsws/10.0/api/appvis/executionplan/list?application=$appid" | |
$response = Invoke-WebRequest -Uri $uri -Headers $headers | |
$respjson = $response.Content | convertfrom-json | |
return $respjson | |
} | |
function get_exec_plan_detail($execplan) { | |
$response = Invoke-WebRequest -Uri "https://$tspshost/tsws/10.0/api/appvis/executionplan/executionById?executionPlanId=$execplan" -Headers $headers | |
$respjson = $response.Content | convertfrom-json | |
return $respjson | |
} | |
function disable_exec_plan($execjson,$execplan,$appid) { | |
$execjson.data.userStatus = 0 | |
$execjson.data.selectedApplicationName = "$appid" | |
$explanname = $($execjson.data.executionPlanName) | |
$appname = $($execjson.data.applications.$appid) | |
$execjson = $execjson.data | ConvertTo-Json | |
$response = Invoke-WebRequest -uri "https://$tspshost/tsws/10.0/api/appvis/executionplan/save?executionPlanId=$execplan" -Headers $headers -Method "PUT" -Body $execjson | |
if ($response.StatusCode -eq 200) { | |
write-host "Disabled [$execplan] $explanname of [$appid] $appname" | |
return 1 | |
} | |
else { | |
$respjson = $response.Content | convertfrom-json | |
write-host $respjson.error | |
return 0 | |
} | |
} | |
function enable_exec_plan($execjson,$execplan,$appid) { | |
$execjson.data.userStatus = 1 | |
$execjson.data.selectedApplicationName = "$appid" | |
$explanname = $($execjson.data.executionPlanName) | |
$appname = $($execjson.data.applications.$appid) | |
$execjson = $execjson.data | ConvertTo-Json | |
$response = Invoke-WebRequest -uri "https://$tspshost/tsws/10.0/api/appvis/executionplan/save?executionPlanId=$execplan" -Headers $headers -Method "PUT" -Body $execjson | |
if ($response.StatusCode -eq 200) { | |
write-host "Enabled [$execplan] $explanname of [$appid] $appname" | |
return 1 | |
} | |
else { | |
$respjson = $response.Content | convertfrom-json | |
write-host $respjson.error | |
return 0 | |
} | |
} | |
#real code starts here | |
$headers = get_login_headers | |
$plans = get_exec_plans $appid | |
foreach ($plan in $plans.data) { | |
$execjson = get_exec_plan_detail $plan.executionPlanId | |
$disablevalue = disable_exec_plan $execjson $execplanid $appid | |
if ($disablevalue -eq 1) { | |
start-sleep 20 | |
$enablevalue = enable_exec_plan $execjson $execplan.executionPlanId $appid | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment