Skip to content

Instantly share code, notes, and snippets.

@timmcfadden
timmcfadden / oci_vm_alarms.py
Created September 26, 2025 18:00
Finds all running virtual machines (VMs) in your Oracle Cloud compartment. Creates monitoring alarms that detect when VMs become unresponsive or stop Sends email notifications when alarms trigger (notification topic required) Provides a summary of successful and failed alarm creations
#!/usr/bin/env python3
import oci
import sys
import argparse
from typing import List, Dict, Optional
class OCIVMAlarmManager:
def __init__(self, compartment_id: Optional[str] = None, non_interactive: bool = False):
"""
import os
import re
import getpass
# Set new values here
newFanSpeed = "0"
newInfillPattern = "gyroid"
# Get the current user's username (Windows)
username = getpass.getuser()
import os
import json
# Define new values for the first JSON file (infill settings)
new_infill_pattern = "gyroid"
new_infill_density = "15%"
# Define new values for the second JSON file (fan speed)
new_fan_speed = ["0"]
# Get the currently logged in user's username
$username = [Environment]::UserName
# Set the new pattern value here, e.g., "adaptivecubic" or "gyroid"
$newInfillPattern = "gyroid"
# Construct the file path
$filePath = "C:\Users\$username\AppData\Roaming\BambuStudio\system\BBL\process\fdm_process_common.json"
# Check if the file exists
# Get the currently logged in user's username
$username = [Environment]::UserName
# Set the new values here
$newFanSpeed = "0" # Change this to set a different cooling fan speed
$newInfillPattern = "adaptivecubic" # Change this to set a different infill pattern
# Filament file path and regex pattern
$filamentFilePath = "C:\Users\$username\AppData\Roaming\BambuStudio\system\BBL\filament\fdm_filament_pla.json"
$fanSpeedRegexPattern = '"additional_cooling_fan_speed": \[\s*"\d+"\s*\]'
# Get the currently logged in user's username
$username = [Environment]::UserName
# Construct the file path
$filePath = "C:\Users\$username\AppData\Roaming\BambuStudio\system\BBL\filament\fdm_filament_pla.json"
# Check if the file exists
if (Test-Path $filePath) {
try {
# Read the file's content into a variable as a text string
# Login to Azure Account
Connect-AzAccount
# Select Subscription (Optional if you have multiple subscriptions)
# Replace <your_subscription_name> with your actual subscription name
#Select-AzSubscription -SubscriptionName "<your_subscription_name>"
# Define Variables
# Replace <your_resource_group_name>, <your_storage_account_resource_group_name> and <your_vm_name> with your actual values
$resourceGroupName = "<your_resource_group_name>"
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
# Define the file extension and program paths
$fileExtension = ".sap"
$programPath = "C:\\Windows\\System32\\notepad.exe"
# Define the registry paths
$defaultRegPath = "HKCR:\\" + $fileExtension
$commandRegPath = "HKCR:\\" + $fileExtension + "\\shell\\open\\command"
Param
(
[Parameter (Mandatory= $true)]
[string] $VMName,
[string] $UserName
)
$Name=$UserName.Split("@")[0]
$archiveUser = $Name
# Import Azure Storage module
Import-Module Az.Storage
# Set storage account name and key
$storageAccountName = "mystorageaccount"
$storageAccountKey = "mystorageaccountkey"
# Set container name and file name
$containerName = "mycontainer"
$fileName = "myfile.txt"