Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- [string]$user = "yourUser",
- [string]$password = "yourPassword",
- [string]$serverAndPort = 'http://yourVEM.fqdn:9399',
- [string]$timeout = "10"
- )
- # POST - Authorization
- $Auth = @{uri = "$($serverAndPort)/api/sessionMngr/?v=v1_2";
- Method = 'POST'; #(or POST, or whatever)
- Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($user):$($password)"));
- } #end headers hash table
- } #end $params hash table
- try {
- $AuthXML = Invoke-WebRequest @Auth -TimeoutSec $timeout -UseBasicParsing
- }catch{
- Write-Output "<prtg>"
- Write-Output "<error>1</error>"
- Write-Output "<text>Authentication Failed: $($_.Exception.Message)</text>"
- Write-Output "</prtg>"
- Exit
- }
- # GET - Session Statistics
- $Sessions = @{uri = "$($serverAndPort)/api/reports/summary/job_statistics";
- Method = 'GET';
- Headers = @{'X-RestSvcSessionId' = $AuthXML.Headers['X-RestSvcSessionId'];
- } #end headers hash table
- }
- try {
- [xml]$SessionsXML = invoke-restmethod @Sessions
- }catch{
- Write-Output "<prtg>"
- Write-Output "<error>1</error>"
- Write-Output "<text>Session Query Failed: $($_.Exception.Message)</text>"
- Write-Output "</prtg>"
- Exit
- }
- $SuccessfulJobRuns = $SessionsXML.JobStatisticsReportFrame.SuccessfulJobRuns
- $WarningsJobRuns = $SessionsXML.JobStatisticsReportFrame.WarningsJobRuns
- $FailedJobRuns = $SessionsXML.JobStatisticsReportFrame.FailedJobRuns
- # GET - VM Statistics
- $VMs = @{uri = "$($serverAndPort)/api/reports/summary/vms_overview";
- Method = 'GET';
- Headers = @{'X-RestSvcSessionId' = $AuthXML.Headers['X-RestSvcSessionId'];
- } #end headers hash table
- }
- try {
- [xml]$VMsXML = invoke-restmethod @VMs
- }catch{
- Write-Output "<prtg>"
- Write-Output "<error>1</error>"
- Write-Output "<text>VMs Query Failed: $($_.Exception.Message)</text>"
- Write-Output "</prtg>"
- Exit
- }
- $ProtectedVms = $VMsXML.VmsOverviewReportFrame.ProtectedVms
- $SourceVmsSize = [Math]::round((($VMsXML.VmsOverviewReportFrame.SourceVmsSize) / 1073741824),0)
- # XML Output for PRTG
- Write-Host "<prtg>"
- Write-Host "<result>"
- "<channel>SuccessfulJobRuns</channel>"
- "<value>$SuccessfulJobRuns</value>"
- "<showChart>1</showChart>"
- "<showTable>1</showTable>"
- "</result>"
- Write-Host "<result>"
- "<channel>ProtectedVms</channel>"
- "<value>$ProtectedVms</value>"
- "<showChart>1</showChart>"
- "<showTable>1</showTable>"
- "</result>"
- Write-Host "<result>"
- "<channel>SourceVmsSize</channel>"
- "<value>$SourceVmsSize</value>"
- "<unit>Custom</unit>"
- "<customUnit>GB</customUnit>"
- "<showChart>1</showChart>"
- "<showTable>1</showTable>"
- "</result>"
- Write-Host "<result>"
- "<channel>WarningsJobRuns</channel>"
- "<value>$WarningsJobRuns</value>"
- "<showChart>1</showChart>"
- "<showTable>1</showTable>"
- "<LimitMaxWarning>1</LimitMaxWarning>"
- "<LimitMode>1</LimitMode>"
- "</result>"
- Write-Host "<result>"
- "<channel>FailedJobRuns</channel>"
- "<value>$FailedJobRuns</value>"
- "<showChart>1</showChart>"
- "<showTable>1</showTable>"
- "<LimitMaxError>1</LimitMaxError>"
- "<LimitMode>1</LimitMode>"
- "</result>"
- Write-Host "</prtg>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement