0

Our monitoring system has a REST API that I am trying to retrieve properties from, then output them to a custom object. A couple of the property values are hash tables.

In addition to keeping the custom objects for use in Powershell, I would like to export them to CSV, so I need those hash tables to be something else, so I don't end up with Syste.Object[] in those columns.

The object returned from the API looks like this (truncated):

$allServices[0]

alertStatus               : none
ignoreSSL                 : True
description               : Test service
stopMonitoring            : False
stopMonitoringByFolder    : False
useDefaultLocationSetting : False
serviceProperties         : {}
transition                : 1
alertStatusPriority       : 100000
serviceFolderId           : 1
script                    :
disableAlerting           : False
individualAlertLevel      : warn
checkpoints               : {@{id=1; geoInfo=Overall; smgId=0}, @{id=2; geoInfo=US - Los Angeles; smgId=1}, @{id=3; geoInfo=US - Washington DC; smgId=2}, @{id=4; geoInfo=US - San Francisco; smgId=3}...}
pageLoadAlertTimeInMS     : 30000
sdtStatus                 : none-none-none
serviceStatus             : alive
method                    : tabledriven
id                        : 1

Then checkpoints looks like this:

$allServices[0].checkpoints

id geoInfo            smgId
-- -------            -----
 1 Overall                0
 2 US - Los Angeles       1
 3 US - Washington DC     2
 4 US - San Francisco     3
 5 Europe - Dublin        4
 6 Asia - Singapore       5

What is the best way to deal with the checkpoints property?

Thanks.

2 Answers 2

1

Convert checkpoints (and possibly serviceProperties) to a JSON string.

$allServicesCSV = foreach ($srv in $allServices) {
    $srv = $srv.PSObject.Copy() # shallow copy
    $srv.checkpoints = ConvertTo-Json $srv.checkpoints -Compress
    $srv
}
Sign up to request clarification or add additional context in comments.

Comments

0

Well, the requirements changed, so I only need to output to json/XML and not to CSV, making this much easier. Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.