117 lines
2.9 KiB
PowerShell
117 lines
2.9 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
PRTG Acronis Backup Statusreport
|
|
|
|
.DESCRIPTION
|
|
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.
|
|
|
|
.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.veeam.jobState</ValueLookup>"
|
|
|
|
write-host "</result>"
|
|
}
|
|
|
|
# Test the validity of an XML file
|
|
function Test-XMLFile {
|
|
[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
|
|
}
|
|
}
|
|
|
|
& '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>"
|
|
|
|
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>"
|