Automating Hudu Magic Dash

Automating Hudu Magic Dash
Photo by Uljana Borodina / Unsplash

The Hudu Magic Dash is, in my opinion, one of Hudu's best and most difficult to use features. Magic Dash enables some awesome ways to highlight certain data and build your own dashboards within Hudu, but it requires the API to use it.

As a way to highlight certain customer information, I've recently started using Luke Whitelock's Customer Product Overview script to generate magic dashboards for each client to highlight a few key items for each client, including what types of compliance the customer adheres to, what they for their primary authentication service, and what their primary file storage service is.

Once I had the script working, I had to figure out a way to automatically run it periodically to keep the dashboards up to date. Since Docker Compose supports separating containers into different profiles, I was able to add a new container to run ad-hoc (or in my case through cron).

Automating the script

First download the latest version of Luke's script. You'll have to modify the first few lines that establish the Hudu API Key and Hudu Base URL. In my case, I added the fields to the .env file as HUDU_MAGIC_DASH_BASE_URL and HUDU_MAGIC_DASH_APIKEY.

Along with the Magic Dash script, you'll need to download a copy of the HuduAPI PowerShell module to a directory that will get mounted into the new container.

After those two items are downloaded, add the following to the docker-compose.yml file:

services:
  ...
  # Magic Dash Generator Container
  magicdash:
   container_name: hudu2_magicdash
   # Use the offician Microsoft PowerShell image
   image: mcr.microsoft.com/powershell
   # Populate the enviornment variables
   env_file:
     - '.env'
   # Set a Profile for the container so it doesn't start automatically
   # when running `docker compose up`
   profiles:
     - 'adhoc'
   # We need the app to be running
   depends_on:
     - app
   volumes:
     # Mount the Magic Dash script into the container
     - <Path to Magic Dash Script>:/Hudu-Customer-Products-Magic-Dash.ps1
     # Mount the HuduAPI module into the PowerShell modules path
     - <Path to HuduAPI Module Directory>/HuduAPI:/opt/microsoft/powershell/7/Modules/HuduAPI
   # If the container stops, let it.
   restart: "No"
   # Set the command to run the Hudu Magic Dash script
   command: pwsh -NoLogo -NonInteractive -File /Hudu-Customer-Products-Magic-Dash.ps1

Notes: When mounting the HuduAPI module, you have to mount the HuduAPI subfolder inside the HuduAPI repository, so the volume will likely be something like ./HuduAPI/HuduAPI:/...

With the container added to the compose file, you can execute it by running docker compose run --rm magicdash

In your crontab you can then add a new cronjob to run the container regularly (in this case every hour on the hour:

0 * * * * cd <path to hudu2 directory>; docker compose run --rm magicdash