PowerShell script exchange
Post Reply
arteeemp
Lurker
Posts: 1
Liked: never
Joined: Apr 03, 2023 2:52 pm
Full Name: arteeemp
Contact:

Monitoring SOBR repository with PRTG

Post by arteeemp »

Hello,

I would like to know if anyone has had the expiriance with monitoring SOBR repository with PRTG.

I've found this sctipt in this topic powershell-f26/fetching-sobr-details-in ... ml#p463257 :

$sobrs = Get-VBRBackupRepository -Scaleout
$sobrReport = @()
foreach ($sobr in $sobrs) {
$extents = $sobr.Extent
$totalSpace = $null
$totalFreeSpace = $null
foreach ($extent in $extents) {
$repo = $extent.Repository
$container = $repo.GetContainer()
$totalSpace += [Math]::Round($container.CachedTotalSpace.InMegabytes / 1024, 1)
$totalFreeSpace += [Math]::Round($container.CachedFreeSpace.InMegabytes / 1024, 1)
}
$sobrReport += $sobr | select Name, @{n='TotalSpace';e={$totalSpace}}, `
@{n='FreeSpace';e={$totalFreeSpace}}
}
$sobrReport

This script allows me to display the total volume in PowerShell , but when I create I new capture in PRTG with this script I have some XML error
(ex. XML: Junk after document element </prtg> -- JSON: Le fichier JSON renvoyé ne correspond pas à la structure attendue (Invalid JSON.). (code : PE231)

I know that I need to add some XML objects in my script

I've tried to add some outputs lines but it isn't work:


Write-Host "<prtg>"
"<result>"
"<channel>$sobr</channel>"
"<value>$TotalFreeSpace</value>"
"</result>"
"</prtg>"

I don't have more expirience with PowerShell , but maybe there's someone who configured it?

Thank you.
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Monitoring SOBR repository with PRTG

Post by david.domask »

Hi @arteeemp,

I don't work with prtg much so can you explain more a bit on what prtg expects as input?

Your Write-host there likely is failing because when the shell expands your variables, there are PS objects there instead of strings, and I guess it will have invalid XML as a result.

So this is purely just an XML/formatting issue outside of our cmdlets, it's just a matter of what does PTRG expect as input for the capture?

To convert the sobrReport array to XML, you can do:

Code: Select all

PS C:\Users\Administrator> $ReportArray = @() #initialize empty array
PS C:\Users\Administrator> foreach($s in $sobrReport){  #start foreach loop over all elements of array, convert to XML, add to $ReportArray
>> $ritem = $s | Select Name, TotalFreeSpace | ConvertTO-XML
>> $ReportArray += $ritem
>> }
PS C:\Users\Administrator> $ReportArray.OuterXML #this is just a sanity check to see the resulting XML, you won't do this to pass to prtg I suppose
<?xml version="1.0" encoding="utf-8"?><Objects><Object Type="System.Management.Automation.PSCustomObject"><Property Name="Name" Type="System.String">sobr-ct-bb</Property><Property Name="TotalFreeSpace" Type="System.Object" /></Object></Objects>
<?xml version="1.0" encoding="utf-8"?><Objects><Object Type="System.Management.Automation.PSCustomObject"><Property Name="Name" Type="System.String">temp-dummy-sobr</Property><Property Name="TotalFreeSpace" Type="System.Object" /></Object></Objects>
You'll likely pass the individual objects from ReportArray to your prtg capture, but I don't know what ptrg expects so you'll need to tell us what it's expecting and what works :)
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 13 guests