The following function takes in user inputs (as
parameters or prompts), logs in to the Delphix Reporting Web Services API (more
information here),
downloads the report (as a JSON string), then outputs to screen as a table, and
outputs to CSV.
I am sharing as a function here because it is super easy
to just paste the entire function into your PowerShell window and then run the
function within that PowerShell session, as many times as you like.
Image: Example: Running Get-DelphixReporting-ResultStorageSummary
with prompts or parameters
The PowerShell Function
FUNCTION
Get-DelphixReporting-ResultStorageSummary{
PARAM(
[Parameter(Mandatory=$TRUE)][String]$Username,
[Parameter(Mandatory=$TRUE)][String]$Password,
[Parameter(Mandatory=$TRUE)][String]$DelphixReportingHostname,
[Parameter(Mandatory=$TRUE)][String]$ReportSavePath
)
## VARIABLES SETUP ##
[String]$Creds =
"password=$Password&user=$Username"
[String]$DelphixReportingAPI =
"https://$DelphixReportingHostname/api/"
## LOGIN TO DELPHIX REPORTING WEB SERVICE API
##
$CurlOut = [String](curl.exe --data $Creds
($DelphixReportingAPI + "login"))
$CurlJson = $CurlOut | ConvertFrom-Json
IF($CurlJson.Success -eq $TRUE){
WRITE-HOST "Login Success!"
-ForegroundColor GREEN
}ELSE{
RETURN "Login failure!"
}
[String]$Login = $CurlJson.LoginToken
[String]$UsrId = $CurlJson.userId
## RECORD DATE ##
[Int64]$DateTicks = (date).ticks
## GET THE 'RESULT STORAGE SUMMARY' REPORT
AND OUTPUT IT ##
$Report_Result_Storage_Summary_Json =
[String](curl.exe -H "X-Login-Token: $Login" -H "X-User-Id:
$UsrId" ($DelphixReportingAPI +
"get_report?report=result_storage_summary"))
$Report_Result_Storage_Summary =
$Report_Result_Storage_Summary_Json | ConvertFrom-Json
$Report_Result_Storage_Summary | FT # Outputs
'Result Storage Summary'
## FILE OUTPUT ##
If(!$ReportSavePath.EndsWith("\")){$ReportSavePath +=
"\"}
[String]$SavePath = ($ReportSavePath +
$DelphixReportingHostname + "." + $DateTicks + ".csv")
If(Test-Path $ReportSavePath){
$Report_Result_Storage_Summary | Export-CSV
-NoTypeInformation -Encoding UTF8 -Path $SavePath
}ELSE{
WRITE-HOST "Test-path $ReportSavePath
failed!" -ForegroundColor RED
}
## LOGOUT ##
$CurlOut = [String](curl.exe -H
"X-Login-Token: $Login" -H "X-User-Id: $UsrId"
($DelphixReportingAPI + "logout"))
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.