Skip to content

Instantly share code, notes, and snippets.

@hospitableit
Created July 15, 2017 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hospitableit/a91c42702cddc182e99a6f41a44b8456 to your computer and use it in GitHub Desktop.
Save hospitableit/a91c42702cddc182e99a6f41a44b8456 to your computer and use it in GitHub Desktop.
$User = "AD Domain Name\Name of Zerto Viewer Service Account"
$EncryptedPassword = "Encrypted Password"
$SecurePassword = $EncryptedPassword | ConvertTo-SecureString
$Marshal = [System.Runtime.InteropServices.Marshal]
$Bstr = $Marshal::SecureStringToBSTR($SecurePassword)
$Password = $Marshal::PtrToStringAuto($Bstr)
$Marshal::ZeroFreeBSTR($Bstr)
$ZertoServerURI = "https://zertoserver.domain.local:9669"
#Supress SSL check to allow Invoke-WebRequest to work with non trusted SSL certs
Add-Type @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
"@
[ServerCertificateValidationCallback]::Ignore();
# POST Authorization to grab x-zerto-session header
$Auth = @{uri = "$ZertoServerURI/v1/session/add";
Method = 'POST';
Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($User):$($Password)"));}
}
$AuthXML = Invoke-WebRequest @Auth -UseBasicParsing
# GET Zerto Virtual Manager Errors
$ZvmErrors = @{uri = "$ZertoServerURI/v1/alerts?entity=Zvm&level=error";
Method = 'GET';
Headers = @{'x-zerto-session' = $AuthXML.Headers['x-zerto-session']; 'Accept' = 'application/xml';}
}
[xml]$ZvmErrorsXML = invoke-restmethod @ZvmErrors
# GET Zerto Virtual Manager Warnings
$ZvmWarnings = @{uri = "$ZertoServerURI/v1/alerts?entity=Zvm&level=warning";
Method = 'GET';
Headers = @{'x-zerto-session' = $AuthXML.Headers['x-zerto-session']; 'Accept' = 'application/xml';}
}
[xml]$ZvmWarningsXML = invoke-restmethod @ZvmWarnings
# GET Zerto Virtual Appliance Errors
$VraErrors = @{uri = "$ZertoServerURI/v1/alerts?entity=Vra&level=error";
Method = 'GET';
Headers = @{'x-zerto-session' = $AuthXML.Headers['x-zerto-session']; 'Accept' = 'application/xml';}
}
[xml]$VraErrorsXML = invoke-restmethod @VraErrors
# GET Zerto Virtual Appliance Warnings
$VraWarnings = @{uri = "$ZertoServerURI/v1/alerts?entity=Vra&level=warning";
Method = 'GET';
Headers = @{'x-zerto-session' = $AuthXML.Headers['x-zerto-session']; 'Accept' = 'application/xml';}
}
[xml]$VraWarningsXML = invoke-restmethod @VraWarnings
# GET Zerto Virtual Protection Group Errors
$VpgErrors = @{uri = "$ZertoServerURI/v1/alerts?entity=Vpg&level=error";
Method = 'GET';
Headers = @{'x-zerto-session' = $AuthXML.Headers['x-zerto-session']; 'Accept' = 'application/xml';}
}
[xml]$VpgErrorsXML = invoke-restmethod @VpgErrors
# GET Zerto Virtual Protection Group Warnings
$VpgWarnings = @{uri = "$ZertoServerURI/v1/alerts?entity=Vpg&level=warning";
Method = 'GET';
Headers = @{'x-zerto-session' = $AuthXML.Headers['x-zerto-session']; 'Accept' = 'application/xml';}
}
[xml]$VpgWarningsXML = invoke-restmethod @VpgWarnings
#Count the number of error or warning values for each result
$ZVMErrorCount = $ZvmErrorsXML.ArrayOfAlertApi.ChildNodes.Count
$ZVMWarningCount = $ZvmWarningsXML.ArrayOfAlertApi.ChildNodes.Count
$VraErrorCount = $VraErrorsXML.ArrayOfAlertApi.ChildNodes.Count
$VraWarningCount = $VraWarningsXML.ArrayOfAlertApi.ChildNodes.Count
$VpgErrorCount = $VpgErrorsXML.ArrayOfAlertApi.ChildNodes.Count
$VpgWarningCount = $VpgWarningsXML.ArrayOfAlertApi.ChildNodes.Count
# XML Output for PRTG
Write-Host "<prtg>"
Write-Host "<result>"
"<channel>ZVMErrors</channel>"
"<value>$ZVMErrorCount</value>"
"<showChart>1</showChart>"
"<showTable>1</showTable>"
"<LimitMaxError>0</LimitMaxError>"
"<LimitMode>1</LimitMode>"
"</result>"
Write-Host "<result>"
"<channel>ZVMWarnings</channel>"
"<value>$ZVMWarningCount</value>"
"<showChart>1</showChart>"
"<showTable>1</showTable>"
"<LimitMaxWarning>0</LimitMaxWarning>"
"<LimitMode>1</LimitMode>"
"</result>"
Write-Host "<result>"
"<channel>VRAErrors</channel>"
"<value>$VraErrorCount</value>"
"<showChart>1</showChart>"
"<showTable>1</showTable>"
"<LimitMaxError>0</LimitMaxError>"
"<LimitMode>1</LimitMode>"
"</result>"
Write-Host "<result>"
"<channel>VRAWarnings</channel>"
"<value>$VraWarningCount</value>"
"<showChart>1</showChart>"
"<showTable>1</showTable>"
"<LimitMaxWarning>0</LimitMaxWarning>"
"<LimitMode>1</LimitMode>"
"</result>"
Write-Host "<result>"
"<channel>VPGErrors</channel>"
"<value>$VpgErrorCount</value>"
"<showChart>1</showChart>"
"<showTable>1</showTable>"
"<LimitMaxError>0</LimitMaxError>"
"<LimitMode>1</LimitMode>"
"</result>"
Write-Host "<result>"
"<channel>VPGWarnings</channel>"
"<value>$VpgWarningCount</value>"
"<showChart>1</showChart>"
"<showTable>1</showTable>"
"<LimitMaxWarning>0</LimitMaxWarning>"
"<LimitMode>1</LimitMode>"
"</result>"
Write-Host "</prtg>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment