me again
so my script is this
New-UDPage -Name 'VCSA' -Icon cloud -Content {
New-UDRow {
New-UDColumn -Size 6 -Content {
New-UDGrid -Title "vMon services" -FontColor "#cbd9ef" -BackgroundColor "#303235" -Headers @("Key", "State") -Properties @("key","value.state") -AutoRefresh -RefreshInterval 60 -Endpoint {
(Invoke-RestMethod -headers $session -method GET -uri "https://cd-lab-vc1.cragdoo.co.uk/rest/appliance/vmon/service").value | ForEach-Object {
$BgColor = 'green'
$FontColor = 'white'
if ($_.Status -ne 'Started') {
$BgColor = 'red'
$FontColor = 'white'
}
[PSCustomObject]@{
Name = $_.key
Status = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $_.value.state.ToString() }
}
}
} | Out-UDGridData
I’m make REST API calls for the grid data, is there any special format I need to consider when using the PScustomObject?
The output of the REST call is similar to
{
"value": [
{
"value": {
"name_key": "cis.analytics.ServiceName",
"startup_type": "AUTOMATIC",
"health_messages": [],
"health": "HEALTHY",
"description_key": "cis.analytics.ServiceDescription",
"state": "STARTED"
},
"key": "analytics"
},
{
"value": {
"name_key": "cis.applmgmt.ServiceName",
"startup_type": "AUTOMATIC",
"health_messages": [],
"health": "HEALTHY",
"description_key": "cis.applmgmt.ServiceDescription",
"state": "STARTED"
},
"key": "applmgmt"
},
{
"value": {
"name_key": "cis.cis-license.ServiceName",
"startup_type": "AUTOMATIC",
"health_messages": [
{
"args": [],
"default_message": "The License Service is operational.",
"id": "cis.license.health.ok"
}
],
"health": "HEALTHY",
"description_key": "cis.cis-license.ServiceDescription",
"state": "STARTED"
},
"key": "cis-license"
}
So i want just the name of the service (key) and the state , then put them into conditional formatting as per the example above ,i…e Green for started , Red for Stopped