mirror of
https://github.com/jprdonnelly/qseow-scripts.git
synced 2025-12-19 09:07:05 -05:00
70 lines
2.8 KiB
PowerShell
70 lines
2.8 KiB
PowerShell
#!/usr/bin/pwsh
|
|
### Set your hostname, apiKey and change paths as desired.
|
|
|
|
$hostname = "cg8fuxcfavt2dog.us.qlikcloud.com"
|
|
$apiKey = "eyJhbGciOiJFUzM4NCIsImtpZCI6IjJlY2M2NWJmLTA4NzUtNDE3Mi05YzE4LTg2ZmZhNmI5Yzk5OSIsInR5cCI6IkpXVCJ9.eyJzdWJUeXBlIjoidXNlciIsInRlbmFudElkIjoiRlVPVl9vZkQ0YmRsejZBNk5PWkQ3UU9JYmF3MjFWSDciLCJqdGkiOiIyZWNjNjViZi0wODc1LTQxNzItOWMxOC04NmZmYTZiOWM5OTkiLCJhdWQiOiJxbGlrLmFwaSIsImlzcyI6InFsaWsuYXBpL2FwaS1rZXlzIiwic3ViIjoiNjIxNjU3MzJmZDIwYjVhMmYzZmVlNWY4In0.XKYFTzBiZ-huSZGVFNBqIlTkkUVw0jdGncD_pNIohzAJ5WNRHFx0lD17H68IPhC4Z1oOuuxfeaAHkqf-8fsjRAIEEGmTnX-b9NDmHk-0BtZEVqYa03LVcyRQ_Eq4bAx1"
|
|
$json = "D:\reloads-list.json"
|
|
$txt = "D:\reloads-list.txt"
|
|
|
|
### Don't change these variables
|
|
# $URL = "https://$hostname/api/v1/reloads?limit=100"
|
|
# $URL = "https://$hostname/api/v1/audits?eventType=com.qlik.app.reload.ended?limit=1000"
|
|
$token = $apiKey | ConvertTo-SecureString -AsPlainText -Force
|
|
|
|
### Invoke the first REST request to the reloads endpoint
|
|
$Body = @{
|
|
eventType = "com.qlik.app.reload.ended"
|
|
limit = 100
|
|
}
|
|
|
|
$Params = @{
|
|
Method = "Get"
|
|
Uri = "https://$hostname/api/v1/audits"
|
|
Body = $Body
|
|
Authentication = "Bearer"
|
|
Token = $token
|
|
# ContentType = "application/json"
|
|
FollowRelLink = $true
|
|
}
|
|
|
|
# $reloads = (Invoke-RestMethod @Params|ConvertFrom-JSON -AsHashtable)
|
|
$reloads = ( ( (Invoke-RestMethod @Params).ToString().Replace("Self", "self") ).ToString().Replace("Next", "next") | ConvertFrom-Json -Depth 6 )
|
|
# $reloads = (Invoke-RestMethod -Uri $URL -Authentication Bearer -Token $token -ContentType 'application/json')
|
|
# $reloads = (qlik raw get --context saasy --raw 'v1/audits?eventType=com.qlik.app.reload.ended?limit=10000000000')
|
|
|
|
### Check if files exist, create if not, carry-on if they already do.
|
|
if (-not(Test-Path -Path $txt -PathType Leaf)) {
|
|
try {
|
|
$null = New-Item -ItemType File -Path $txt -Force -ErrorAction Stop
|
|
Write-Host "The file [$txt] has been created."
|
|
}
|
|
catch {
|
|
throw $_.Exception.Message
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "Cannot create [$txt] because a file with that name already exists."
|
|
}
|
|
|
|
if (-not(Test-Path -Path $json -PathType Leaf)) {
|
|
try {
|
|
$null = New-Item -ItemType File -Path $json -Force -ErrorAction Stop
|
|
Write-Host "The file [$json] has been created."
|
|
}
|
|
catch {
|
|
throw $_.Exception.Message
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "Cannot create [$json] because a file with that name already exists."
|
|
}
|
|
|
|
### While there is a value for the "next" cursor, indicating more output, run again
|
|
while ($reloads.links.next) {
|
|
$reloads | ConvertTo-JSON -Depth 4 >> $json
|
|
$reloads.data | Sort-Object -Property startTime -Descending | Format-Table -Property appId,name,type,status,startTime,endTime |Tee-Object -Append -FilePath $txt
|
|
$URL = $reloads.links.next.href
|
|
sleep 5
|
|
$reloads = (Invoke-RestMethod -Uri $URL -Authentication Bearer -Token $token -ContentType 'application/json')
|
|
}
|