I'm working with a Powershell script monitor. In this case pulling down some data from an Openshift Prometheus query.
The query data comes back in JSON. I'm using the Powershell ConvertFrom-JSON command to create an array of Powershell objects to format for ingest into Solarwinds.
The JSON conversion part works fine.
My problem: I sometimes the query returns more than one element. I want to use the Powershell newline element "`n" to format my output (for the Solarwinds 'Message' return variable) to look something like this...
Pods not running:
rook-ceph-mgr-a-123
rook-ceph-mgr-b-456
rook-ceph-mgr-c-789
rather than like this...
Pods not running: rook-ceph-mgr-a-123 rook-ceph-mgr-b-456 rook-ceph-mgr-c-789
I'm using a Powershell array similar to the following:
$myObject = @()
foreach ($ob in $obs){
$myObject += New-Object psobject @{
POD = $ob.pod
Status = '3'
MSG = $ob.job
}
}
#
$msg1 = "Pods not running:`n"
for ($i=0; $i -lt $myObject.length; $i++)
{$msg1 = $msg1 + 'Job ' + $myObject[$i].msg + ' pod ' + $myObject[$i].pod + "`n"}
}
Notice use of the newline character (`n) to put the description and array elements on separate lines.
This works perfectly in VSCode or PowerShell ISE - I get a nice block with my header and elements on different lines.
However, attempting to use this in a Solarwinds script monitor the $msg1 variable does not return a block. I get either nothing or just a single line that I suspect is the last item in the array.
Lots of testing the script definitely seems to choke on the newline character (`n) running in Solarwinds (although not in VCCode/ISE).
I'm just curious if anyone has success formatting the 'Message' part of a Solarwinds Powershell monitor to return a block with newline characters.
Thanks.