Skip to content

Instantly share code, notes, and snippets.

View Justinsst's full-sized avatar

Justin Stewart Justinsst

View GitHub Profile
@Justinsst
Justinsst / print_table.py
Created April 4, 2025 19:47
Print a table using Python f-strings
def print_table(data: list[list[str]], headers: list[str]) -> str:
"""Prints a formatted table using f-strings."""
# Calculate column widths based on content and headers
column_widths = [max(len(str(x)) for x in col) for col in zip(*data, headers)]
# Print header
header_string = "| " + " | ".join(f"{header:<{column_widths[i]}}" for i, header in enumerate(headers)) + " |"
print("-" * len(header_string))
print(header_string)
print("-" * len(header_string))
# Print data rows
@Justinsst
Justinsst / ephemeralstorage-report.sh
Created April 4, 2025 18:04
Kubernetes - Get the ephemeral storage usage for every pod on each node. Metrics for ephemeral storage usage are not exported by the kubelet https://github.com/kubernetes/kubernetes/issues/69507
#!/bin/bash
function x()
{
echo "Namespace Pod Ephemeral-used(MB)"
kubectl get --raw "/api/v1/nodes/$1/proxy/stats/summary" | jq -r '.pods[]| [ .podRef.namespace, .podRef.name, (."ephemeral-storage".usedBytes/1000000) ]|@tsv'
}
for i in $(kubectl get node -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
@Justinsst
Justinsst / kube_api.py
Last active November 18, 2023 23:08
This is small snippet of a module I created as part of project related to kubernetes. By wrapping functions with the cluster_config decorator, API calls can be run against any remote cluster (or in-cluster) using the kubeconfig argument.
import functools
import logging
from kubernetes import client, config
logger = logging.getLogger(__name__)
def cluster_config(func):
@functools.wraps
def wrapper(*args, **kwargs):
@Justinsst
Justinsst / cas-manager-add-pool-user.py
Created June 20, 2022 20:52
This is an example of some functions I quickly created in Python when testing Teradici CAS Manager's API. The goal during my testing was to automate adding users to workstation pools when onboarding new employees.
#!/usr/bin/python3
import requests
import json
import sys
api_url = "https://<cas manager hostname>/api/v1"
def get_token():
with open("cas-api-creds.json") as creds_file:
api_creds = json.load(creds_file)
@Justinsst
Justinsst / get-intune-enrollment-user.ps1
Last active May 20, 2022 18:18
This script gets the UPN of the user who enrolled an Intune device. This is useful because you can use this in other Powershell scripts deployed via Intune that work in conjunction with various Policy CSPs applied to a Windows device.
$Join_Info = 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CloudDomainJoin\JoinInfo'
$Enrolled_UPN = ''
if(Test-Path -Path $Join_Info){
$Enrolled_UPN = Get-ItemProperty -Path ('{0}\{1}' -f ($Join_Info,(Get-ChildItem -Path $Join_Info).Name.Split('\')[-1])) `
-Name 'UserEmail' | Select-Object -ExpandProperty 'UserEmail'
Write-Host $Enrolled_UPN
}
else {
@Justinsst
Justinsst / phpipam-list-objects.py
Created February 15, 2022 17:37
List objects in phpIPAM. This script lets you list racks and device types. Useful because some phpIPAM API actions require you specify it's ID (an integer) rather than it's name.
#!/usr/bin/python3
import os
import getpass
import sys
import argparse
import requests
import json
server = "https://your_phpipam_url.com"
appid = "admin"
@Justinsst
Justinsst / phpipam-csv-import.py
Last active February 15, 2022 17:31
Create devices in phpIPAM 1.4 using a CSV as the data source
#!/usr/bin/python3
'''
Note that the "type" (the device type), "rack" and "location" fields
in your CSV must be their respective IDs not their names.
For example, if you have location called Data Center you would use
it's ID (e.g "1") in the CSV instead of "Data Center".
'''
import getpass
import sys