Last active
September 13, 2021 13:24
-
-
Save aimtiaz11/aa8a17657863286dc03b20c159db1289 to your computer and use it in GitHub Desktop.
Powershell script to disable Cloudhub logging
This file contains hidden or 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
## License: MIT | |
## Configure Cloudhub and app details below | |
$Username = '' # anypoint platform username | |
$Password = 'abc123' # anypoint platform password | |
$OrgId = '542aaff5-116n-433d-fd76-5a24zqfard19' # Anypoint Org ID | |
$EnvName = 'DEV' # Cloudhub environment | |
$AppName = 'example-app' # Application name | |
################################################################## | |
## Start of Script - Below this should remain constant | |
################################################################## | |
## Step 1: Login to get Token | |
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" | |
$Headers.Add("Content-Type", "application/json") | |
$Body = "{ | |
`n `"username`": `"$Username`", | |
`n `"password`": `"$Password`" | |
`n}" | |
$Response = Invoke-RestMethod 'https://anypoint.mulesoft.com/accounts/login' -Method 'POST' -Headers $Headers -Body $Body -ContentType 'application/json' | |
$Token = $Response.access_token | |
# Step 2: Get Environment Id | |
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" | |
$Headers.Add("accept", "application/json,*/*") | |
$Headers.Add("authorization", "Bearer $Token") | |
$Response = Invoke-RestMethod "https://anypoint.mulesoft.com/accounts/api/organizations/$OrgId/environments" -Method 'GET' -Headers $Headers | |
$EnvId = $Response.data | where {$_.name -eq $EnvName} | Select -ExpandProperty 'id' | |
write-host Env ID: $EnvId | |
### Step 3: Disable Cloudhub Log if required | |
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" | |
$Headers.Add("authorization", "bearer $Token") | |
$Headers.Add("content-type", "application/json") | |
$Headers.Add("x-anypnt-env-id", "$EnvId") | |
$Headers.Add("x-anypnt-org-id", "$OrgId") | |
$Body = "{ | |
`n `"loggingCustomLog4JEnabled`": `"true`" | |
`n}" | |
$Response = Invoke-RestMethod "https://anypoint.mulesoft.com/cloudhub/api/v2/applications/$AppName" -Method 'GET' -Headers $Headers | |
$LoggingEnabled = $Response.loggingCustomLog4JEnabled | |
if(!$LoggingEnabled) { | |
$Response = Invoke-RestMethod "https://anypoint.mulesoft.com/cloudhub/api/v2/applications/$AppName" -Method 'PUT' -Headers $Headers -Body $Body | |
$Response | ConvertTo-Json | |
write-host App restarted to disable cloudhub logs. | |
} else { | |
write-host Cloudhub logging already disabled. | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment