How you look when you read this article

In order to start writing code you need to get a working installation of BigIPReport. The setup guide here is a good place to start.

Once you have executed the script and have a functioning copy of BigIPReport using underlay/ as ReportRoot you can return to this article knowing that this will likely be a bit of a confusing experience. 🙂

If you need help you can find us here:

https://discord.gg/3AXHctJ8

The project layout

BigIPReport consists of three main components

  • PowerShell Script
  • Json data files
  • Web Application

Essentially the Powershell script generates the Json data files, which works a bit like a database for the web application. Let’s dive a bit deeper into each of them.

The Powershell script

The script uses the REST API to fetch data regarding the configuration on the BigIPs and uses threads. The layout of the script is a bit convoluted due to the limitations of threads in Powershell. We would probably not have used Powershell if BigIPReport was written from scratch today but here we are. 🙂

The script is very big but pretty well documented but the thing that would catch most people off guard is the threads part. Essentially the main script spawns copies of itself with parameters letting the copies know they are a child of the main script.

Updating the script

Update the classes or add a new one

We can’t cover every scenario here but let’s bring up the example of adding new data to the report. To do this we need to first update an existing class or create a new one (search the code for public class). Below is an example class for iRules:

    public class iRule {
        public string name;
        public string[] pools;
        public string[] datagroups;
        public string[] virtualservers;
        public string definition;
        public string loadbalancer;
    }

Add a path for the json file

This is only needed for new data types. Example could be adding a type for AFM configuration which at the time of writing this does not exist.

Here’s an example for iRules:

$Global:paths.irules = $Global:bigipreportconfig.Settings.ReportRoot + "json/irules.json"

Update the data collection function

It’s time to have a look at the function called Get-LTMInformation. Copy existing implementations in Get-LTMInformation and you’ll do fine.

Example for the iRules section in the function

# Initiate a dictionary property of $LoadBalancer objects called iRules
$LoadBalancerObjects.iRules = c@ {}

# Fetch all the data you need using Invoke-RestMethod
# and create an object representing an iRule
# < removed the actual code for brevity >

# Add the object to the dictionary using name as key
$LoadBalancerObjects.iRules.add($ObjiRule.name, $ObjiRule)

Update $Global:out and update the json export functions

Only applicable for new data types. The parent script is storing the data from the child processes in a dictionary called $Global:Out. In order for the new data type to be collected we need to store it in a key with the name of said data. Example follows for iRules:

$Global:Out.iRules = @()

You also need to update the statements exporting the data as json to the path mentioned above. Example follows:

$WriteStatuses += Write-JSONFile -DestinationFile $Global:paths.irules -Data @($Global:Out.iRules | Sort-Object loadbalancer, name )

You also need to handle missing data:

$Global:Out.iRules += $TemporaryCache['irules'] | Where-Object { $_.loadbalancer -eq $LoadBalancerName }

And finally update the message showing the stats:

$StatsMsg += " R:" + $Global:Out.iRules.Length

Running the script against a single device

Because of the way Powershell handles threading you’ll need to run the report against a single device when developing/debugging the data collection code:

# pwsh bigipreport.ps1 <config file name> <device ip|dns>
# Example
pwsh bigipreport.ps1 bigipreportconfig.xml bigip.corp.com

This makes any console output visible from the data collection functions but will not write any files to disk.

Updating the Webapp

The web app is written in Typescript. The source code resides in js-src and the transpiled code ends up in underlay/js. To update the web app you’d need to first install the node modules by running the following command in the BigIPReport root folder:

npm install

Then you issue this command to have web pack watch the code and transpiles it once it detects changes:

npm run build:dev

Now you just need a simple web server to serve the application. I can highly recommend http-server. To use it navigate to the underlay/ folder which contains the application build.

Slower but easier

First you need to generate a key pair. The web server needs https since Brotli is not served over http.

# Run this command and pick the default options, except for Common name where you'll enter localhost
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem

Then run the web server with the following command:

npx http-server -b -S -p 8443 -C ./cert.pem
Starting up http-server, serving ./

http-server version: 14.1.0

http-server settings: 
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none

Available on:
  http://127.0.0.1:8080
  http://192.168.70.26:8080
Hit CTRL-C to stop the server

Now the BigIPReport application should be available on https://localhost:8443/ and you’re ready to test your code with the following routine:

  1. Update the code
  2. webpack will automatically transpile it and create a new build in underlay/
  3. Refresh the browser to see the changes
  4. Rince, repeat

Related Posts

Leave a Reply

Your email address will not be published.