Advertisement
llingnau

Untitled

Jan 25th, 2018
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param(
  2.     [string]$user = "yourUser",
  3.     [string]$password = "yourPassword",
  4.     [string]$serverAndPort = 'http://yourVEM.fqdn:9399',
  5.     [string]$timeout = "10"
  6. )
  7.  
  8. # POST - Authorization
  9. $Auth = @{uri = "$($serverAndPort)/api/sessionMngr/?v=v1_2";
  10.                    Method = 'POST'; #(or POST, or whatever)
  11.                    Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($user):$($password)"));
  12.            } #end headers hash table
  13.    } #end $params hash table
  14.  
  15. try {
  16. $AuthXML = Invoke-WebRequest @Auth -TimeoutSec $timeout -UseBasicParsing
  17. }catch{
  18.     Write-Output "<prtg>"
  19.     Write-Output "<error>1</error>"
  20.     Write-Output "<text>Authentication Failed: $($_.Exception.Message)</text>"
  21.     Write-Output "</prtg>"
  22.     Exit
  23. }
  24.  
  25. # GET - Session Statistics
  26. $Sessions = @{uri = "$($serverAndPort)/api/reports/summary/job_statistics";
  27.                    Method = 'GET';
  28.                    Headers = @{'X-RestSvcSessionId' = $AuthXML.Headers['X-RestSvcSessionId'];
  29.            } #end headers hash table
  30.     }
  31.  
  32. try {
  33. [xml]$SessionsXML = invoke-restmethod @Sessions
  34. }catch{
  35.     Write-Output "<prtg>"
  36.     Write-Output "<error>1</error>"
  37.     Write-Output "<text>Session Query Failed: $($_.Exception.Message)</text>"
  38.     Write-Output "</prtg>"
  39.     Exit
  40. }
  41.  
  42. $SuccessfulJobRuns = $SessionsXML.JobStatisticsReportFrame.SuccessfulJobRuns
  43. $WarningsJobRuns = $SessionsXML.JobStatisticsReportFrame.WarningsJobRuns
  44. $FailedJobRuns = $SessionsXML.JobStatisticsReportFrame.FailedJobRuns
  45.  
  46. # GET - VM Statistics
  47. $VMs = @{uri = "$($serverAndPort)/api/reports/summary/vms_overview";
  48.                    Method = 'GET';
  49.                    Headers = @{'X-RestSvcSessionId' = $AuthXML.Headers['X-RestSvcSessionId'];
  50.            } #end headers hash table
  51.     }
  52.  
  53. try {
  54. [xml]$VMsXML = invoke-restmethod @VMs
  55. }catch{
  56.     Write-Output "<prtg>"
  57.     Write-Output "<error>1</error>"
  58.     Write-Output "<text>VMs Query Failed: $($_.Exception.Message)</text>"
  59.     Write-Output "</prtg>"
  60.     Exit
  61. }
  62.  
  63. $ProtectedVms = $VMsXML.VmsOverviewReportFrame.ProtectedVms
  64. $SourceVmsSize = [Math]::round((($VMsXML.VmsOverviewReportFrame.SourceVmsSize) / 1073741824),0)
  65.  
  66. # XML Output for PRTG
  67. Write-Host "<prtg>"
  68. Write-Host "<result>"
  69.                "<channel>SuccessfulJobRuns</channel>"
  70.                "<value>$SuccessfulJobRuns</value>"
  71.                "<showChart>1</showChart>"
  72.                "<showTable>1</showTable>"
  73.                "</result>"
  74. Write-Host "<result>"
  75.                "<channel>ProtectedVms</channel>"
  76.                "<value>$ProtectedVms</value>"
  77.                "<showChart>1</showChart>"
  78.                "<showTable>1</showTable>"
  79.                "</result>"
  80. Write-Host "<result>"
  81.                "<channel>SourceVmsSize</channel>"
  82.                "<value>$SourceVmsSize</value>"
  83.                "<unit>Custom</unit>"
  84.                "<customUnit>GB</customUnit>"
  85.                "<showChart>1</showChart>"
  86.                "<showTable>1</showTable>"
  87.                "</result>"
  88. Write-Host "<result>"
  89.                "<channel>WarningsJobRuns</channel>"
  90.                "<value>$WarningsJobRuns</value>"
  91.                "<showChart>1</showChart>"
  92.                "<showTable>1</showTable>"
  93.                "<LimitMaxWarning>1</LimitMaxWarning>"
  94.                "<LimitMode>1</LimitMode>"
  95.                "</result>"
  96. Write-Host "<result>"
  97.                "<channel>FailedJobRuns</channel>"
  98.                "<value>$FailedJobRuns</value>"
  99.                "<showChart>1</showChart>"
  100.                "<showTable>1</showTable>"
  101.                "<LimitMaxError>1</LimitMaxError>"
  102.                "<LimitMode>1</LimitMode>"
  103.                "</result>"
  104. Write-Host "</prtg>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement