How to monitor backups HYCU with powershell ?
In my last business, we needed to determinate if backups are compliances. We used PRTG solution to monitoring devices, but no modules existed. So we decided to create script powershell and used the API Hycu.
$RESTAPIUser =
$RESTAPIPassword =
add-type @ »
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 TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]’Ssl3,Tls,Tls11,Tls12′
$BaseURL = « https://IP_Address:8443/rest/v1.0/vms/manager/vms?pageSize=100&pageNumber=1&forceSync=false »
$Header = @{« Authorization » = « Basic « +[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($RESTAPIUser+ »: »+$RESTAPIPassword))}
$Type = « application/json »
Try
{
$VMListJSON = Invoke-RestMethod -Uri $BaseURL -TimeoutSec 10 -Headers $Header -ContentType $Type
$VMList = $VMListJSON.entities
}
Catch
{
$_.Exception.ToString()
$error[0]
}
→ Replace « IP_Adress » with the ip address of your Hycu server.
This part of the script will allow you to establish the connection with the server.
You have two methods for the credentials, either insert them hard in the script, or go through a secure-string request whose identifiers are hosted in another file.
$Result = @()
foreach($ListeProprietes in ($VMList | Where-Object {$_.protectionGroupName -ne "Exclude"} | Select @{e={$_.vmName};n="NomVm"}, @{e={$_.compliancyStatus};n="Compliance"}))
{
$channel = New-Object PSObject
$channel | Add-Member NoteProperty Channel "$($ListeProprietes.NomVm)"
if ($ListeProprietes.Compliance -eq "RED")
{
$channel | Add-Member NoteProperty Value 1
}
else
{
$channel | Add-Member NoteProperty Value 0
}
$result = $result + $channel
}
$PRTG = New-Object PSObject
$PRTG | Add-Member NoteProperty Result $Result
$Return = New-Object PSObject
$Return | Add-Member NoteProperty Prtg $PRTG
$Return | ConvertTo-Json -Depth 3
This part of the script returns the value 1 or 0 of the compliance status. It will then be necessary to configure the interpretation on the monitoring server side. In idea you can configure retrieve other parameters.