diff --git a/getAllEvents.ps1 b/getAllEvents.ps1 new file mode 100644 index 0000000..25045fa --- /dev/null +++ b/getAllEvents.ps1 @@ -0,0 +1,50 @@ +#!/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 = "$HOME\events-list.json" +$txt = "$HOME\events-list.txt" + +### Don't change these variables +# $URL = "https://$hostname/api/v1/reloads?limit=100" +$URL = "https://$hostname/api/v1/audits" +$token = $apiKey | ConvertTo-SecureString -AsPlainText -Force + +### Invoke the first REST request to the reloads endpoint +$reloads = (Invoke-RestMethod -Uri $URL -Authentication Bearer -Token $token -ContentType 'application/json') + +### 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 + $reloads = (Invoke-RestMethod -Uri $URL -Authentication Bearer -Token $token -ContentType 'application/json') +} diff --git a/getAllReloads.ps1 b/getAllReloads.ps1 index bd62054..5d62d13 100644 --- a/getAllReloads.ps1 +++ b/getAllReloads.ps1 @@ -3,15 +3,34 @@ $hostname = "cg8fuxcfavt2dog.us.qlikcloud.com" $apiKey = "eyJhbGciOiJFUzM4NCIsImtpZCI6IjJlY2M2NWJmLTA4NzUtNDE3Mi05YzE4LTg2ZmZhNmI5Yzk5OSIsInR5cCI6IkpXVCJ9.eyJzdWJUeXBlIjoidXNlciIsInRlbmFudElkIjoiRlVPVl9vZkQ0YmRsejZBNk5PWkQ3UU9JYmF3MjFWSDciLCJqdGkiOiIyZWNjNjViZi0wODc1LTQxNzItOWMxOC04NmZmYTZiOWM5OTkiLCJhdWQiOiJxbGlrLmFwaSIsImlzcyI6InFsaWsuYXBpL2FwaS1rZXlzIiwic3ViIjoiNjIxNjU3MzJmZDIwYjVhMmYzZmVlNWY4In0.XKYFTzBiZ-huSZGVFNBqIlTkkUVw0jdGncD_pNIohzAJ5WNRHFx0lD17H68IPhC4Z1oOuuxfeaAHkqf-8fsjRAIEEGmTnX-b9NDmHk-0BtZEVqYa03LVcyRQ_Eq4bAx1" -$json = "$HOME\reloads-list.json" -$txt = "$HOME\reloads-list.txt" +$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/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 -$reloads = (Invoke-RestMethod -Uri $URL -Authentication Bearer -Token $token -ContentType 'application/json') +$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)) { @@ -43,7 +62,8 @@ else { ### 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 -Property startTime | Format-Table -Property id,appId,type,status,startTime,endTime |Tee-Object -Append -FilePath $txt + $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') }