r/PowerShell • • Nov 06 '17

FoxDeploy: Creating Glorious PowerShell Dashboards

https://foxdeploy.com/2017/11/06/glorious-powershell-dashboards/
170 Upvotes

46 comments sorted by

View all comments

3

u/JazDriveOmega Nov 07 '17

OK, I guess I'm stuck. Here is what I'm trying to do:

I export a bunch of data about my printers from my print server and SNMP (to pull toner data). I combine all that together into an array of PSObjects and export that to a JSON file. The object look like this:

{
    "Name":  "LOC-Printer-Color",
    "Type":  "HP Color LaserJet Pro M252dw",
    "Address":  "10.1.6.75",
    "Toner":  {
                  "Cyan":  19,
                  "Yellow":  21,
                  "Name":  "Toner Levels",
                  "Megnta":  26,
                  "Black":  34
              }
}

I want to create a Colum and Chart for each printer, displaying the levels of toner from the toner property.

This is what my dashboard code looks like:

Start-UDDashboard -port $i -Content {
    New-UDDashboard -NavbarLinks $NavBarLinks -Title "PowerShell Pro Tools Universal Dashboard" -NavBarColor '#011721' -NavBarFontColor "#CCEDFD" -BackgroundColor "#66C7F6" -FontColor "#011721" -Content {
        New-UDRow {
            $Printers = Get-Content .\printers.json | ConvertFrom-Json
            foreach ($Printer in $Printers) {
                $Toner = $Printer.Toner
                New-UDColumn -Size 3 {
                    New-UDChart -Title $Printer.Name -type Bar @Colors -RefreshInterval 3 -AutoRefresh -Verbose -Endpoint {
                        $Toner | Out-UDChartData -Verbose -LabelProperty "Name" -Dataset @(
                            New-UDChartDataset -DataProperty "Black" -Label "Black" -BackgroundColor "#080e1c" -HoverBackgroundColor "#080e1c"
                            New-UDChartDataset -DataProperty "Cyan" -Label "Cyan" -BackgroundColor "#42d4f4" -HoverBackgroundColor "#42d4f4"
                            New-UDChartDataset -DataProperty "Magenta" -Label "Magenta" -BackgroundColor "#ce3ef2" -HoverBackgroundColor "#ce3ef2"
                            New-UDChartDataset -DataProperty "Yellow" -Label "Yellow" -BackgroundColor "#f1d03e" -HoverBackgroundColor "#f1d03e"
                        )
                    }
                }
            }
        }
    }
}

but what I get back is a chart that looks like this:

https://imgur.com/a/QafiC

I'm not sure what I'm missing here. Is this some kind of a scoping issue? I've tried debugging in VS Code but it didn't really get me anywhere.

2

u/1RedOne Nov 07 '17

First off, WOW you went way farther than I've gotten so far.

Second, can you share that printers.json file so I can try to play with it?

2

u/JazDriveOmega Nov 07 '17

Thanks! Its funny, a while back I built a tool that used Firebase and AgularFire to generate a dashboard, not unlike this one. This is obviously way easier since I don't have to be the one to keep up with whatever underlying web technology is running the whole thing :P

Here is my JSON file: https://pastebin.com/HNfJEU5R

I've also thought about trying to dump each toner out as a json file and try to work with them that way. But I think I just run in to the same issue. I think once you get down to the Endpoint on New-UDChart, you lose the object from the loop and I'm not sure if you can pass it along.

1

u/tharagz08 Nov 21 '17

Were you able to get your JSon file to be read properly? I am running into the same issue. I wasn't able to get far using your file either.

1

u/JazDriveOmega Nov 22 '17

Yes! It ended up being a bug in UD its self. There were a few bugs actually, but they have all been resolved now.

I've posted the end result on github: https://github.com/AmazingWizard/UD-PrinterDashboard

2

u/saGot3n Nov 08 '17

Try this. https://pastebin.com/5PWR4cn3 Use pscustom object to assign the data from the toner variable, that way the dataproperties can be called from new-udchatdataset. This is what I have been doing for data sets.