Logik zum Strukturieren des PRTG XML hinzugefügt

This commit is contained in:
2020-05-18 09:03:29 +02:00
parent f5b095383e
commit 822e31c382

View File

@@ -3,10 +3,8 @@
PRTG Acronis Backup Statusreport
.DESCRIPTION
Dieses Script wertet den Status der Windows Server Sicherung aus
und versendet auf Basis der Daten eine Mail im HTML-Format über den
Status der letzten Sicherung. Zusätzlich werden Informationen über das
Sicherungsmedium und den freien Speicher übermittelt.
Dieses Script wertet den Status der Acronis Sicherung aus
und übergibt den Status der eingerichteten Jobs an PRTG.
.PARAMETER Server
The IP or DNS of the Server running Acronis. You can use the %host parameter of PRTG.
@@ -59,41 +57,60 @@ function Build-XML($Job, $LastResult)
write-host "<float>0</float>"
write-host "<ValueLookup>ps.acronis.jobState</ValueLookup>"
write-host "<ValueLookup>ps.veeam.jobState</ValueLookup>"
write-host "</result>"
}
function Test-XMLFile
{
[CmdletBinding()]
# Test the validity of an XML file
function Test-XMLFile {
[CmdletBinding()]
param (
[parameter(mandatory=$true)][ValidateNotNullorEmpty()][string]$xmlFilePath
)
if(!(Test-Path -Path $xmlFilePath))
# Check the file exists
if (!(Test-Path -Path $xmlFilePath))
{
throw "$xmlFilePath is not valid. Please provide a valid path to the .xml file"
throw "$xmlFilePath is not valid. Please provide a valid path to the .xml fileh"
}
# Check for Load or Parse errors when loading the XML file
$xml = New-Object System.Xml.XmlDocument
try
{
try {
$xml.Load((Get-ChildItem -Path $xmlFilePath).FullName)
return $true
}
catch [System.Xml.XmlException]
{
Write-Verbose "$xmlFilePath : $($_.toString())"
return $false
catch [System.Xml.XmlException] {
Write-Verbose "$xmlFilePath : $($_.toString())"
return $false
}
}
& 'C:\Program Files\Acronis\CommandLineTool\acrocmd.exe' list plans --host=$Server --credentials=$User,$Password --log=c:\tmp\AcronisBackupStatus.xml >$null | write-host
$Data = New-Object xml
$Data.psbase.PreserveWhitespace = $false
while ((Test-XMLFile "c:\tmp\AcronisBackupStatus.xml") -eq $false ) {
$null = Invoke-Expression -Command:$command
}
$Data.Load("c:\tmp\AcronisBackupStatus.xml")
write-host "<prtg>"
Build-XML Server1 ok
Build-XML Server2 Error
ForEach( $Plan in $Data.list_plans.output_data.list.plan ) {
# check ist backup plan enabled
if($Plan.enabled.Replace("`r`n",""))
{
$Plan.Name = $Plan.Name.Replace("`r`n","")
$Plan.Name = $Plan.Name.Replace(" ","")
$Plan.Status = $Plan.Status.Replace("`r`n","")
$Plan.Status = $Plan.Status.Replace(" ","")
$Plan.Status = $Plan.Status.ToLower()
Build-XML $Plan.Name $Plan.Status.ToString()
}
}
write-host "</prtg>"