diff --git a/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1 b/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1 new file mode 100644 index 0000000..1b302c0 --- /dev/null +++ b/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1 @@ -0,0 +1,164 @@ +<# +.SYNOPSIS + 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. + +.PARAMETER Server + The IP or DNS of the Server running Acronis. You can use the %host parameter of PRTG. + +.PARAMETER User + User with login rights to Acronis. + +.PARAMETER Password + The Password for the User. + +.OUTPUTS + PRTG XML to console + +.EXAMPLE + C:\PS> Get-AcronisJobResults.ps1 -Server acronis.company.com -User company\backupAdmin -Password securePhrase1 + +.LINK + https://www.ksite.de + +.NOTES + AUTHOR : Ralf Kirchner + EMAIL : rkirchner@ksite.de + DATE : 30.06.2018 + + + +#> + + +param( + [Parameter(Mandatory=$True)][string]$Server, + [string]$User, + [string]$Password + +) + +#PRTG wants numeric values. Acronis provides the last result as string. +$ResultLookUp=@{"ok" = 0; "Warning" = 1; "Error" = 2; "Failed" = 2} + +#Helper function for writing the same XML format for all kind of jobs. +function Build-XML($Job, $LastResult) +{ + write-host "" + + write-host -NoNewline "" + write-host -NoNewline $Job + write-host "" + + write-host -NoNewline "" + write-host -NoNewline $ResultLookUp[$LastResult] + write-host "" + + write-host "0" + + write-host "ps.acronis.jobState" + + write-host "" + +} + +$command = @' +cmd.exe /C "C:\Program Files\Acronis\CommandLineTool\acrocmd.exe" list plans --host=$HostName --credentials=$LoginName,$LoginPassword --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)) +{ + 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 { +$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 + " ! " + } + $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 + " ! " + } + $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 { + } +} + + + +"" + "" + "" + "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 diff --git a/README.md b/README.md index 75c05d5..b2c7bdc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ # PRTG-AcronisBackup -PRTG Sensor für Acronis Backup Monitoring \ No newline at end of file +PRTG Sensor für Acronis Backup Monitoring + +# Download +[ZIP-Datei mit der Vorlage und den erforderlichen zusätzlichen Dateien.](https://dev.ksite.de/rkirchner/PRTG-AcronisBackup/archive/master.zip) + +# Installation +Alle Dateien im PRTG-Unterverzeichnis müssen in das PRTG-Programmverzeichnis aufgenommen werden. + +Das bedeutet, kopieren Sie die Dateien von "PRTG" in "%programfiles (x86)%\PRTG Network Monitor" und die +Dateien werden an die richtigen Stellen in den Unterverzeichnissen kopiert. + +Wenn das Paket MIB-Dateien enthält, werden diese erst geladen, wenn PRTG neu gestartet wird. +Suchvorgänge können manuell neu geladen werden, indem Sie auf der Seite Admin Tools "*Setup -> Systemverwaltung -> Verwaltung*" klicken, oder im Webbrowser die URL: *https://{PRTGServerIPandPort}/api/loadlookups.htm* aufrufen. + +Die restlichen Dateien dienen zur Dokumentation und zum Testen.