diff --git a/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1 b/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1 index 103c21d..195ee29 100644 --- a/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1 +++ b/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1 @@ -65,98 +65,36 @@ function Build-XML($Job, $LastResult) } -$command = @' -cmd.exe /C "C:\Program Files\Acronis\CommandLineTool\acrocmd.exe" list plans --host=$Server --credentials=$User,$Password --log="c:\tmp\AcronisBackupStatus.xml" -'@ - -################# erstellen der XML datei und einlesen - -function Test-XMLFile { -<# -.SYNOPSIS -Test the validity of an XML file -#> -[CmdletBinding()] -param ( -[parameter(mandatory=$true)][ValidateNotNullorEmpty()][string]$xmlFilePath -) - -# Check the file exists -if (!(Test-Path -Path $xmlFilePath)) +function Test-XMLFile { - throw "$xmlFilePath is not valid. Please provide a valid path to the .xml fileh" -} + [CmdletBinding()] + param ( + [parameter(mandatory=$true)][ValidateNotNullorEmpty()][string]$xmlFilePath + ) -# Check for Load or Parse errors when loading the XML file -$xml = New-Object System.Xml.XmlDocument -try { -$xml.Load((Get-ChildItem -Path $xmlFilePath).FullName) -return $true -} -catch [System.Xml.XmlException] { -Write-Verbose "$xmlFilePath : $($_.toString())" -return $false -} -} - -Invoke-Expression -Command:$command - -$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") - -ForEach( $Plan in $Data.list_plans.output_data.list.plan ) { - $Plan.Status = $Plan.Status.Replace("`r`n","") - $Plan.Status = $Plan.Status.Replace(" ","") - $Plan.Status = $Plan.Status.ToLower() - If ($Plan.Status -eq "ok") { - $errorvalue = 0 - } else { - $errorvalue = $errorvalue + 1 - $text = $text + $Plan.Name + "has Status " + $Plan.Status + " ! " + if(!(Test-Path -Path $xmlFilePath)) + { + throw "$xmlFilePath is not valid. Please provide a valid path to the .xml fileh" } - $Readdate = [datetime]::ParseExact($Plan.next_start.substring(0,19), "dd.MM.yyyy HH:mm:ss", $null) - if ($Readdate -ge $curdate) { - } else { - $errorvalue = $errorvalue + 1 - $text = $text + $Plan.Name + "has Next Start Time in the Past : " + $Readdate + " ! " + + $xml = New-Object System.Xml.XmlDocument + try + { + $xml.Load((Get-ChildItem -Path $xmlFilePath).FullName) + return $true } - $Plan.State = $Plan.State.Replace("`r`n","") - $Plan.State = $Plan.State.Replace(" ","") - $Plan.State = $Plan.State.ToLower() - $Plan.State - If ($Plan.State -eq "need_interaction") { - $errorvalue = $errorvalue + 1 - $text = $text + $Plan.Name + "has State Need Interaction ! " - } else { + catch [System.Xml.XmlException] + { + Write-Verbose "$xmlFilePath : $($_.toString())" + return $false } } +write-host "" + +Build-XML Server1 ok +Build-XML Server2 Error + +write-host "" -"" - "" - "" - "BackupStatus" - "" - "Custom" - "Status" - "0" - "" - echo $errorvalue - "" - "0,5" - "1" - "" - "" - If ($errorvalue -eq 0) { - echo "Alles Ok" - } else { - echo $text - } - "" - "" \ No newline at end of file