Dashboard to Check if Services Are running

Im attempting to create table within a dashboard that checks if services are running. THe way I would normally do this is by running the Command:

"Get-Process -Name "

When I try to run this command within the dashboard script, I get the following errors:

Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=object%20with%20keys%20{}&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

Please see the code below and if you are able to point me in the right direction I would be appreciative.

$MyDashboard = New-UDDashboard -Title “Lenel Communication Server Health” -Content {
New-UDTable -Title “Process Check” -Headers @(" ", " ") -Endpoint{
@{
‘GS-COA-EW1A001P’ = Invoke-Command -ComputerName GS-COA-EW1A001P -ScriptBlock {Get-Process -Name Lnlcomsrvr}

Hi Neer94,

Welcome to the UD community!!!

I would try something like this.

Get-UDDashboard | Stop-UDDashboard

$MyDashboard = New-UDDashboard -Title “Lenel Communication Server Health” -Content {
    New-UDTable -Title “Process Check” -Headers @("Name", "HandleCount", "WorkingSet") -Endpoint 
{
   $TargetDevice = Invoke-Command -ComputerName "GS-COA-EW1A001P" -ScriptBlock {Get-Process -Name 
Lnlcomsrvr}
$TargetDevice | Out-UDTableData -Property Name, HandleCount, WorkingSet
    }
}

Start-UDDashboard -Dashboard $MyDashboard -Port 8080

You will need to pick the properties you are interested in displaying. I hope this helps.
guy

1 Like

Hi @Neer94 just second what @guy said, welcome to the universal dashboard forums. Hope this first post is not your last post…I been on this forum since it opened and have seen this question asked quite a few times…so not saying in anyway shape or form I can beat @guy answer, but instead of re-inventing the wheel I will post you to a tasty cookbook recipe cooked up by the one and only @adam it’s right here:-


There are also a lot of other posts, but I know your question got answered, but just to show how nice we are in here this is my help and advice…I would also recommend visiting poshud as @adam has once again provided neat examples:-
https://poshud.com/New-UDTable
Peace

1 Like

Thank you both for your quick response. I really appreciate the help!

I have one more question.

I took both of your advice and created the following:

  Get-UDDashboard | Stop-UDDashboard
  $LenelComDashboard = New-UDDashboard -Title "Lenel Communication Server Health" -Content {

     New-UDTable -Title "Service Status" -Headers @('Hostname', 'Service Status') -Endpoint {
    $serverlist = get-content -file \\ant\dept\GSS\Serverlist.csv
    foreach ($servername in $serverlist){
  Get-Service -ComputerName $servername -Name 'LS Communication Server' {

        $BgColor = 'green'
        $FontColor = 'white'
        if ($_.Status -ne 'Running') {
            $BgColor = 'red'
            $FontColor = 'white'
        }

        [PSCustomObject]@{
            Name = $servername
            Status = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $_.Status.ToString() }
        }
    } | Out-UDTableData -Property @("Name", "Status")

     }
     }
     }
 Start-UDDashboard -Dashboard $LenelComDashboard -Port 8080 -AutoReload
 #Get-UDDashboard | Stop-UDDashboard

I get the following error:

A positional parameter cannot be found that accepts argument ’ $BgColor = ‘green’ FontColor = 'white' if (.Status -ne ‘Running’) { $BgColor = ‘red’ $FontColor = ‘white’ } [PSCustomObject]@{ Name = $servername Status = New-UDElement -Tag ‘div’ -Attributes @{ style = @{ ‘backgroundColor’ = $BgColor; color = fontColor } } -Content { .Status.ToString() } } '.

Any suggestions?

Evening my dude,

you forgot a “| foreach-object” after your get-service.

Get-UDDashboard | Stop-UDDashboard
$LenelComDashboard = New-UDDashboard -Title “Lenel Communication Server Health” -Content {

    New-UDTable -Title "Service Status" -Headers @('Hostname', 'Service Status') -Endpoint {
    $serverlist = get-content "\\ant\dept\GSS\Serverlist.csv"
    foreach ($servername in $serverlist){
        Get-Service -ComputerName $servername -Name 'LS Communication Server' | ForEach-Object {
            $BgColor = 'green'
            $FontColor = 'white'
            if ($_.Status -ne 'Running') {
                $BgColor = 'red'
                $FontColor = 'white'
            }

            [PSCustomObject]@{
                Name = $servername
                Status = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $_.Status.ToString() }
            }
        } | Out-UDTableData -Property @("Name", "Status")

    }       
}

}
Start-UDDashboard -Dashboard $LenelComDashboard -Port 8080 -AutoReload

Should work.

Have a good one!

1 Like

DOh I just did this:-

Import-Module -Name UniversalDashboard.Community
Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Port 10005 -Dashboard (
New-UDDashboard -Title “Computer Services” -Content {
New-UDTable -Title “Service Status” -Headers @(‘MachineName’, ‘Name’, ‘Status’) -Endpoint {
$Computers = Get-Content -Path C:\UD\sig\computers.txt
Foreach ($computer in $Computers) {
Get-Service -ComputerName $computer | ForEach-Object {
$BgColor = ‘green’
FontColor = 'white' if (_.Status -ne ‘Running’) {
$BgColor = ‘red’
$FontColor = ‘white’
}

                    [PSCustomObject]@{
                        MachineName = $_.MachineName
                        Name        = $_.DisplayName
                        Status      = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $_.Status.ToString() }
                    }
                } | Out-UDTableData -Property @("MachineName", "Name", "Status")
            }
        }
    }
)
1 Like

This gives this


Although @BoSen29 beat me to the buzzer this time, I see that neither of you looked at using the MACHINENAME output from get-service :clown_face: so you would of had a massive list of computer services not having a clue to which computer they related too…thats why it took me that little bit longer than @BoSen29 :grin:
I hope both these examples help you complete this dashboard

1 Like

Pfft, the code runs! :slight_smile:
Nice catch doe, good job bro!

Doh beat me to it man…must be a timezone thing :grin:

With that logic, you should’ve beat me by an hour…
Prolly better fiber from Norway to California, #justsayin

1 Like

@BoSen29 bro it’s 8pm see you at 9pm UK still has crappy internet…especially in my shed :smoking: so you had an hour headstart on me…told you it was a timezone thing :slight_smile:

Touché,

Nuff said above, but 20 character limit…

I did going by time zone :slight_smile:

1 Like

Doh… Nice catch! Thank you guys. You are Rockstars!

2 Likes

It’s really worth hanging about on this forum I have learnt so much by the code people are willing to share, and the questions being asked, and how they are answered…for example this just got posted by @wsl2001 who has good skills in the UD area look at this juicy script he kindly uploaded:-


Scroll right to the bottom but it’s there, only really pointing you to this as using the same colouring on the service, but @wsl2001 has also given it steroids so his dashboard here is monitoring lots of things…this is for one computer…however if you piped your computer list into a select list, then sync’d all the components on the page to the UD selection, you could monitor a load more things than just services for a computer.
I did this to monitor all of our severs, which then displays https://marketplace.universaldashboard.io/Dashboard/ud-bginfo
for the server I select from the drop down list
Hope this gives you some ideas for some of the cool things you can do with UD. Peace

1 Like

So here is how I am currently monitoring any given server in my environment…please note I used a tabbed menu for this dashboard, and this is ONE of many tabs…

  New-UDTab -Text "Server Info" -Content {
        New-UDLayout -Columns 2 -Content {
            New-UDInput -Title "Select" -Id "card1" -Content {
                New-UDInputField -Type 'select' -Name 'Servers' -Values @("Select Server","Server1","Server2","Server3","Server4")
                          } -Endpoint {
                              param($Servers)
                              $Cache:Loading = $True
                              Set-UDElement -Id 'output' -Content {$Servers}
                              $Session:ServerName = $Servers
                              @("Table1","Chart2","Monitor1","Monitor2","Monitor3","Monitor4","Grid1","Heading","Loading") | Sync-UDElement

                        }
    New-UDElement -Id Loading -Tag div -Endpoint {
        If ( $Cache:Loading -eq $True)
            {
            New-UDCard -Content {
                New-UDHeading -Text 'Loading data background components please wait' -Size 3
                New-UDPreloader -Size medium }
            }
        } -AutoRefresh -RefreshInterval 5
    }

    New-UDRow -Columns {
                    New-UdColumn -Size 6 -AutoRefresh -Endpoint {
                        if (-not($Session:ServerName -eq $null)) {
                    New-UdTable -Id Table1 -Title "Server Information" -Headers @(" ", " ") -Endpoint {
                        Sync-UDElement -Id card1
                        @{
                            'Computer Name'         = "$Session:ServerName"
                            'Operating System'      = (Get-WmiObject Win32_OperatingSystem -ComputerName "$Session:ServerName").Caption
                            'Total Disk Space (C:)' = (Get-WmiObject Win32_LogicalDisk -ComputerName "$Session:ServerName" -Filter "DeviceID = 'C:'").Size / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
                            'Free Disk Space (C:)'  = (Get-WmiObject Win32_LogicalDisk -ComputerName "$Session:ServerName" -Filter "DeviceID = 'C:'").FreeSpace / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
                        }.GetEnumerator() | Out-UDTableData -Property @("Name", "Value")

                    } -AutoRefresh
                }
                }

                   New-UdColumn -Size 6 -AutoRefresh -Endpoint {
                    Sync-UDElement -Id card1
                    if (-not($Session:ServerName -eq $null)) {
                    New-UdChart -Id Chart2 -Title "Disk Space by Drive" -Type Bar -AutoRefresh -RefreshInterval 5 -Endpoint {
                        Get-WmiObject Win32_LogicalDisk -ComputerName "$Session:ServerName" | ForEach-Object {
                            [PSCustomObject]@{ DeviceId = $_.DeviceID;
                                Size                    = [Math]::Round($_.Size / 1GB, 2);
                                FreeSpace               = [Math]::Round($_.FreeSpace / 1GB, 2);
                            } } | Out-UDChartData -LabelProperty "DeviceID" -Dataset @(
                            New-UdChartDataset -DataProperty "Size" -Label "Size" -BackgroundColor "#80962F23" -HoverBackgroundColor "#80962F23"
                            New-UdChartDataset -DataProperty "FreeSpace" -Label "Free Space" -BackgroundColor "#8014558C" -HoverBackgroundColor "#8014558C"
                        )

                    }
                }
                }
            }

    New-UdRow {
                New-UdColumn -Size 6 -AutoRefresh -Endpoint {
                    Sync-UDElement -Id card1
                    if (-not($Session:ServerName -eq $null)) {
                    New-UdMonitor -Id Monitor1 -Title "CPU (% processor time)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#80FF6B63' -ChartBorderColor '#FFFF6B63'  -Endpoint {
                        try {
                            Get-Counter '\Processor(_Total)\% Processor Time' -ComputerName "$Session:ServerName" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            0 | Out-UDMonitorData
                        }
                    }
                }
            }
                New-UdColumn -Size 6 -AutoRefresh -Endpoint {
                    Sync-UDElement -Id card1
                    if (-not($Session:ServerName -eq $null)) {
                    New-UdMonitor -Id Monitor2 -Title "Memory (% in use)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#8028E842' -ChartBorderColor '#FF28E842'  -Endpoint {
                        try {
                            Get-Counter '\memory\% committed bytes in use' -ComputerName "$Session:ServerName" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            0 | Out-UDMonitorData
                        }
                    }
                }
            }

            New-UdRow {
                New-UdColumn -Size 6 -AutoRefresh -Endpoint {
                    Sync-UDElement -Id card1
                    if (-not($Session:ServerName -eq $null)) {
                    New-UdMonitor -Id Monitor3 -Title "Network (IO Read Bytes/sec)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#4392f1' -ChartBorderColor '#3d85dc'  -Endpoint {
                        try {
                            Get-Counter '\Process(_Total)\IO Read Bytes/sec' -ComputerName "$Session:ServerName" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            0 | Out-UDMonitorData
                        }
                    }
                }
            }
                New-UdColumn -Size 6 -AutoRefresh -Endpoint {
                    Sync-UDElement -Id card1
                    if (-not($Session:ServerName -eq $null)) {
                    New-UdMonitor -Id Monitor4 -Title "Disk (% disk time)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#80E8611D' -ChartBorderColor '#FFE8611D'  -Endpoint {
                        try {
                            Get-Counter '\physicaldisk(_total)\% disk time' -ComputerName "$Session:ServerName" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            0 | Out-UDMonitorData
                        }

                    }
                }
            }
        }
        }

    New-UDRow {
            New-UDColumn -size 12 -AutoRefresh -Endpoint {
                Sync-UDElement -Id card1
                if ($Session:ServerName -eq $null)
                {New-UDHeading -id Heading -Text "Waiting for selection..."}
                if (-not($Session:ServerName -eq $null)) {
                New-UdGrid -Id Grid1 -Title "Processes" -Headers @("Name", "ID", "Working Set", "MachineName") -Properties @("Name", "Id", "WorkingSet", "MachineName") -AutoRefresh -Endpoint {
                    Get-Process -ComputerName "$Session:ServerName" | Out-UDGridData
                    $Cache:Loading = $False
                        Sync-UDElement -ID Loading

                }
            }

        }
}
}
1 Like