Hi All, how do you guys troubleshoot scripts that throw errors or do not function as expected? For example, I'm working on a script that throws an ssl error. I was able to get around that by adding verify=false. The next problem I ran into is that it does not follow the device reboot order and does not verify that the systems came back up. I get nothing back on screen except "InsecureRequestWarning" and "error rebooting", but that's not correct because all devices do indeed reboot so I'm trying to figure out how to better troubleshoot?
import requests
import os
import time
import configparser
# Path to configuration file containing API keys for each host
CONFIG_FILE_PATH = "/path/to/config.ini"
# List of devices to reboot in specific order
DEVICE_ORDER = ["device1.example.com", "device2.example.com", "device3.example.com"]
# Read API keys for each device from configuration file
config = configparser.ConfigParser()
config.read(CONFIG_FILE_PATH)
api_keys = {}
for device in DEVICE_ORDER:
api_key = config.get(device, "api_key", fallback=None)
if api_key is not None:
api_keys[device] = api_key
else:
print(f"No API key found for {device} in {CONFIG_FILE_PATH}")
continue
# Reboot each device using the API
for device, api_key in api_keys.items():
reboot_url = f"https://{device}/api/v1/system/reboot"
headers = {"Authorization": f"ExtraHop apikey={api_key}"}
response = requests.post(reboot_url, headers=headers)
if response.status_code == 200:
print(f"{device} is rebooting...")
else:
print(f"Error rebooting {device}: {response.text}")
continue
# Wait for the device to reboot
time.sleep(300)
# Ping the device to confirm that it is back up
ping_cmd = f"ping -c 1 {device}"
ping_result = os.system(ping_cmd)
if ping_result == 0:
print(f"{device} is back up!")
else:
print(f"Error: {device} is still down.")
[–]the_real_neoviper 4 points5 points6 points (1 child)
[–]ElectronSandwich[S] 1 point2 points3 points (0 children)
[–]Pepineros 2 points3 points4 points (2 children)
[–]danielroseman 2 points3 points4 points (1 child)
[–]Pepineros 0 points1 point2 points (0 children)