Hudu Magic Dash – Customer Product Overview Dashes

This evening I was chatting on the MSPGeek Slack and someone brought up wanting to have a quick way in Hudu to see what services a customer has. Someone else reminded me about Gavin Stone’s Dashes for IT Glue https://www.gavsto.com/it-glue-make-your-flexible-assets-look-a-little-less-dull-with-a-customized-type-dashboard-feel/

My prefferred way of creating Magic Dashes in Hudu is with a full script that documents assets and then create a Magic Dash summary, but this isn’t suitable for everything (Looking at you Datto SaaS backup with no API!!). Also finding the time to put together scripts to do this is hard for a lot of people. Due to this I thought I would make a small script that will let people define their own customer summary asset layout and then generate Magic Dashes from it.

Instructions

The first step for this is to create a new asset layout in Hudu called something like “Company Services”. For this Asset you will then want to setup fields for each service you want to create a magic dash from. I have created three different definitions you can use for each service to allow you to add more information.

ENABLED – This is required for all services and to be a checkbox type. This will set if the dash is green or blank, based on if it is ticked or not.

NOTE – This is optional and needs to be a text type. This will let you set text in the middle of the Magic Dash.

URL – This is optional and needs to be a text type. This will let you set a URL to be linked from the open link text at the bottom of the Magic Dash.

To name the fields on the Asset layout your would use the format “Service Name:ACTION”. So for example “Duo:ENABLED”, “Duo:NOTE and “DUO:URL”

You should end up with something like this:

Once you have created the Asset Layout you will need to go create assets using the layout under each company you wish to generate the Dashes for. Enter any name you wish this is not used by the script then complete the details for each service:

Once this is created run the script and it will generate Magic Dashes from the Asset.

The Script

The latest version of the script can be found here: https://github.com/lwhitelock/HuduAutomation/blob/main/Hudu-Customer-Products-Magic-Dash.ps1

$VaultName = "Your Key Vault Name"
#### Hudu Settings ####
$HuduAPIKey = Get-AzKeyVaultSecret -vaultName $VaultName -name "HuduAPIKey" -AsPlainText
# Set the base domain of your Hudu instance without a trailing /
$HuduBaseDomain = Get-AzKeyVaultSecret -vaultName $VaultName -name "HuduBaseDomain" -AsPlainText

$DetailsLayoutName = 'Company Details'
$SplitChar = ':'

import-module HuduAPI

#Login to Hudu
New-HuduAPIKey $HuduAPIKey
New-HuduBaseUrl $HuduBaseDomain

$AllowedActions = @('ENABLED', 'NOTE', 'URL')

# Get the Asset Layout
$DetailsLayout = Get-HuduAssetLayouts -name $DetailsLayoutName

# Check we found the layout
if (($DetailsLayout | measure-object).count -ne 1) {
    Write-Error "No / multiple layout(s) found with name $DetailsLayoutName"
} else {
    # Get all the detail assets and loop
    $DetailsAssets = Get-HuduAssets -assetlayoutid $DetailsLayout.id
    foreach ($Asset in $DetailsAssets) {

        # Loop through all the fields on the Asset
        $Fields = foreach ($field in $DetailsAssets.fields) {
            # Split the field name
            $SplitField = $Field.label -split $SplitChar

            # Check the field has an allowed action.
            if ($SplitField[1] -notin $AllowedActions) {
                Write-Error "Field $($Field.label) is not an allowed action"
            } else {

                # Format an object to work with
                [PSCustomObject]@{
                    ServiceName   = $SplitField[0]
                    ServiceAction = $SplitField[1]
                    Value         = $field.value
                }
            }
        }

        Foreach ($Service in $fields.servicename | select-object -unique){
            $EnabledField = $fields | Where-Object {$_.servicename -eq $Service -and $_.serviceaction -eq 'ENABLED'}
            $NoteField = $fields | Where-Object {$_.servicename -eq $Service -and $_.serviceaction -eq 'NOTE'}
            $URLField = $fields | Where-Object {$_.servicename -eq $Service -and $_.serviceaction -eq 'URL'}
            if ($EnabledField){
                $Colour = Switch ($EnabledField.value) {
                    $True {'success'}
                    $False {'grey'}
                    default {'grey'}
                }

                $Param = @{
                    Title = $Service
                    CompanyName = $Asset.company_name
                    Shade = $Colour
                }
                
                if ($NoteField.value){
                    $Param['Message'] = $NoteField.value
                    $Param | Add-Member -MemberType NoteProperty -Name 'Message' -Value $NoteField.value
                } else {
                    $Param['Message'] =Switch ($EnabledField.value) {
                        $True {"Customer has $Service"}
                        $False {"No $Service"}
                        default {"No $Service"}
                    }

                }

                if ($URLField.value){
                    $Param['ContentLink'] = $URLField.value
                }
                
                Set-HuduMagicDash @Param

            } else {
                Write-Error "No Enabled Field was found"
            }
        }

    }

}

You may also like...