Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-RubrikReportData Requires Overhaul #549

Closed
Draper1 opened this issue Jan 17, 2020 · 1 comment · Fixed by #635
Closed

Get-RubrikReportData Requires Overhaul #549

Draper1 opened this issue Jan 17, 2020 · 1 comment · Fixed by #635

Comments

@Draper1
Copy link
Member

Draper1 commented Jan 17, 2020

Is your feature request related to a problem? Please describe.

No. Currently when running Get-RubrikReportData with the reporting ID, it returns a valid response, however, Rubrik Reporting keeps the Column names separated to the actual data, meaning when you loop through the dataGrid object, you are unable to correlate the columns.

It's difficult for users of the SDK to easily handle reporting data. For example:

Get-RubrikReportData -id $report.id

columns        : {ObjectId, ObjectName, ObjectType, ObjectState...}
cursor         : eyJyb3dJZCI6NzY3LCJjb2x1bW5Tb3J0VmFsdWUiOiJ7XCJ0eXBcIjpcIk5vVmFsdWVcIn0ifQ==
dataGrid       : {ManagedVolume:::8422c959-cc22-4be4-aec1-8bdd70d72a39 mv-owdb1 ManagedVolume Active  1d4ea8d1-8a10-4277-9266-5701aad40482 OracleTest Active InCompliance 32141520896 2020-01-16 
                 06:04:47 14 0 22271181929 0 0, Fileset:::2c715e71-6a61-4fea-97b2-bbb0f32fe402 orclhome LinuxFileset Active 172.21.10.50 b437c400-e091-4884-8225-43ea2704f490 SrOra-DB-Prod 
                 Active InCompliance 14067171328 2020-01-17 00:00:59 33 0 7085334161 0 0, Fileset:::24f2227e-2a73-40d1-b22f-01bb200127f2 th-allthethings LinuxFileset Active 172.21.11.120 
                 8e6f6618-6af0-4833-a94d-6b32f00ca9b0 Gold Active InCompliance 14623768576 2020-01-17 01:09:29 49 0 5188655075 0 0, Fileset:::e08d5f6a-d4ff-4a65-a3aa-20e99fc36896 fox_xfs_test 
                 LinuxFileset Active 172.21.11.38 4747838d-d9d5-43c9-9895-3252223f4c2c Bronze Active InCompliance 5540872192 2020-01-17 00:01:13 34 0 428008247 0 0...}
reportTemplate : ObjectProtectionSummary
hasMore        : false

However, when looping through dataGrid, this is the output:

$reportExample = Get-RubrikReportData -id $report.id
$reportExample.dataGrid
ManagedVolume:::8422c959-cc22-4be4-aec1-8bdd70d72a39
mv-owdb1
ManagedVolume
Active

1d4ea8d1-8a10-4277-9266-5701aad40482
OracleTest
Active
InCompliance
32141520896
2020-01-16 06:04:47
14
0
22271181929
0
0
Fileset:::2c715e71-6a61-4fea-97b2-bbb0f32fe402
orclhome
LinuxFileset
Active
172.21.10.50
b437c400-e091-4884-8225-43ea2704f490
SrOra-DB-Prod
Active
InCompliance
14067171328
2020-01-17 00:00:59
33
0
7085334161

Describe the solution you'd like

Currently, I am using this block of code instead of the cmdlet Get-RubrikReportData as this returns the report data in a formatted PS Object.

function Get-RubrikReportDataFull () {
    [CmdletBinding()]
    Param (
        [string]$rubrik_ip,
        [string]$rubrik_user,
        [string]$rubrik_pass,
        [string]$report_id,
    )

    $headers = @{
        Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $rubrik_user,$rubrik_pass)))
        Accept = 'application/json'
    }
    if ($psversiontable.PSVersion.Major -le 5) {
        try {
            # This block prevents errors from self-signed certificates
            Add-Type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
    }
}
"@
            [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy
            [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        }
        catch {

        }
    }
    $report_output = @()
    $report_query = @{
        limit = 9999
    }

    $has_more = $true
    while ($has_more -eq $true) {
        if ($null -ne $cursor) {
            $report_query['cursor'] = $cursor
        }
        if ($psversiontable.PSVersion.Major -le 5) {
            $report_response = Invoke-WebRequest -Uri $("https://"+$rubrik_ip+"/api/internal/report/"+$report_id+"/table") -Headers $headers -Method POST -Body $(ConvertTo-Json $report_query)
        } else {
            $report_response = Invoke-WebRequest -Uri $("https://"+$rubrik_ip+"/api/internal/report/"+$report_id+"/table") -Headers $headers -Method POST -Body $(ConvertTo-Json $report_query) -SkipCertificateCheck
        }
        $report_data = $report_response.Content | ConvertFrom-Json
        $has_more = $report_data.hasMore
        $cursor = $report_data.cursor
        foreach ($report_entry in $report_data.dataGrid) {
            $row = '' | Select-Object $report_data.columns
            for ($i = 0; $i -lt $report_entry.count; $i++) {
                $row.$($report_data.columns[$i]) = $($report_entry[$i])
            }
            $report_output += $row
        }
    }
    return $report_output
}

The output of this function provides the following as a PS Object, that can be used in a for loop:

ObjectId          : MssqlDatabase:::3c9d0af1-fb3c-4871-9834-4db244c9665c
ObjectName        : dataSanitise
ObjectType        : Mssql
ObjectState       : Active
Location          : th-az-devops-sql\MSSQLSERVER
SlaDomainId       : cbf0962f-db5a-4172-bae6-1e3f6749a0fe
SlaDomain         : Silver
SlaDomainState    : Active
ComplianceStatus  : InCompliance
LogicalObjectSize : 43581440
LastSnapshot      : 2020-01-17 00:26:13
TotalSnapshots    : 45
MissedSnapshots   : 0
LocalStorage      : 23917373
ArchiveStorage    : 0
ReplicaStorage    : 0

ObjectId          : Fileset:::344f029c-d1da-4e6f-96d9-245d40e4d8e1
ObjectName        : th-test
ObjectType        : LinuxFileset
ObjectState       : Active
Location          : th-chef-linux
SlaDomainId       : cbf0962f-db5a-4172-bae6-1e3f6749a0fe
SlaDomain         : Silver
SlaDomainState    : Active
ComplianceStatus  : InCompliance
LogicalObjectSize : 5154209792
LastSnapshot      : 2020-01-17 00:34:59
@jaapbrasser
Copy link
Contributor

That looks like a valuable addition Andy, thanks for the suggestion I will pick this up and will take a look at the best way to integrate this into the module.

@jaapbrasser jaapbrasser self-assigned this Jan 17, 2020
jaapbrasser added a commit that referenced this issue May 24, 2020
mwpreston added a commit that referenced this issue Jun 8, 2020
Added structured output to Get-RubrikReportData - #549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants