Logik zum Strukturieren des PRTG XML hinzugefügt
This commit is contained in:
@@ -3,10 +3,8 @@
|
|||||||
PRTG Acronis Backup Statusreport
|
PRTG Acronis Backup Statusreport
|
||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Dieses Script wertet den Status der Windows Server Sicherung aus
|
Dieses Script wertet den Status der Acronis Sicherung aus
|
||||||
und versendet auf Basis der Daten eine Mail im HTML-Format über den
|
und übergibt den Status der eingerichteten Jobs an PRTG.
|
||||||
Status der letzten Sicherung. Zusätzlich werden Informationen über das
|
|
||||||
Sicherungsmedium und den freien Speicher übermittelt.
|
|
||||||
|
|
||||||
.PARAMETER Server
|
.PARAMETER Server
|
||||||
The IP or DNS of the Server running Acronis. You can use the %host parameter of PRTG.
|
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 "<float>0</float>"
|
||||||
|
|
||||||
write-host "<ValueLookup>ps.acronis.jobState</ValueLookup>"
|
write-host "<ValueLookup>ps.veeam.jobState</ValueLookup>"
|
||||||
|
|
||||||
write-host "</result>"
|
write-host "</result>"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Test-XMLFile
|
# Test the validity of an XML file
|
||||||
{
|
function Test-XMLFile {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
[parameter(mandatory=$true)][ValidateNotNullorEmpty()][string]$xmlFilePath
|
[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
|
$xml = New-Object System.Xml.XmlDocument
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$xml.Load((Get-ChildItem -Path $xmlFilePath).FullName)
|
$xml.Load((Get-ChildItem -Path $xmlFilePath).FullName)
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
catch [System.Xml.XmlException]
|
catch [System.Xml.XmlException] {
|
||||||
{
|
Write-Verbose "$xmlFilePath : $($_.toString())"
|
||||||
Write-Verbose "$xmlFilePath : $($_.toString())"
|
return $false
|
||||||
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>"
|
write-host "<prtg>"
|
||||||
|
|
||||||
Build-XML Server1 ok
|
ForEach( $Plan in $Data.list_plans.output_data.list.plan ) {
|
||||||
Build-XML Server2 Error
|
# 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>"
|
write-host "</prtg>"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user