Files
PRTG-AcronisBackup/PRTG/Custom Sensors/EXEXML/Get-AcronisJobResults.ps1

100 lines
2.2 KiB
PowerShell
Raw Normal View History

2018-11-18 14:18:52 +01:00
<#
.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 "<result>"
write-host -NoNewline "<channel>"
write-host -NoNewline $Job
write-host "</channel>"
write-host -NoNewline "<value>"
write-host -NoNewline $ResultLookUp[$LastResult]
write-host "</value>"
write-host "<float>0</float>"
write-host "<ValueLookup>ps.acronis.jobState</ValueLookup>"
write-host "</result>"
}
2018-11-18 22:56:16 +01:00
function Test-XMLFile
2018-11-18 14:18:52 +01:00
{
2018-11-18 22:56:16 +01:00
[CmdletBinding()]
param (
[parameter(mandatory=$true)][ValidateNotNullorEmpty()][string]$xmlFilePath
)
if(!(Test-Path -Path $xmlFilePath))
{
2018-11-18 23:07:17 +01:00
throw "$xmlFilePath is not valid. Please provide a valid path to the .xml file"
2018-11-18 14:18:52 +01:00
}
2018-11-18 22:56:16 +01:00
$xml = New-Object System.Xml.XmlDocument
try
{
$xml.Load((Get-ChildItem -Path $xmlFilePath).FullName)
return $true
2018-11-18 14:18:52 +01:00
}
2018-11-18 22:56:16 +01:00
catch [System.Xml.XmlException]
{
Write-Verbose "$xmlFilePath : $($_.toString())"
return $false
2018-11-18 14:18:52 +01:00
}
}
2018-11-18 22:56:16 +01:00
write-host "<prtg>"
Build-XML Server1 ok
Build-XML Server2 Error
write-host "</prtg>"
2018-11-18 14:18:52 +01:00