"""
Playwright Automation Script for Screenshot Captures
---------------------------------------------------
This script automates login and screenshot capturing from multiple services:
- RabbitMQ
- Observium
- Firewall
- SFSSD
- NVMe
- Ceph (Cockpit) & OwnCloud
- Zimbra Mail Admin
Each service has a dedicated function for login, navigation, and screenshot capture.
"""
from playwright.sync_api import sync_playwright, TimeoutError as PWTimeout
import time
import re
def rabbitmq_screenshot(url, username, password, selector, service):
"""
Capture RabbitMQ dashboard screenshot.
Args:
url (str): RabbitMQ login page URL
username (str): RabbitMQ username
password (str): RabbitMQ password
selector (str): CSS selector of main element to capture
service (str): Service name for screenshot filename
"""
output = f"service_{service}.png"
with sync_playwright() as pw:
# Launch browser context
ctx = pw.chromium.launch(headless=True).new_context(ignore_https_errors=True)
page = ctx.new_page()
page.goto(url)
print("Current URL:", page.url)
# Fill login form
page.fill('input[name="username"]', username)
page.fill('input[name="password"]', password)
# Try , fallback to
try:
page.click('input[type="submit"]')
except:
page.click('button[type="submit"]')
# Wait for main page to load
page.wait_for_selector(selector)
time.sleep(2) # give extra stability before capture
# Capture dashboard screenshot
page.locator(selector).screenshot(path=output)
print(f"Saved screenshot: {output}")
def observium_screenshot(url, username, password, service):
"""
Capture Observium memory utilization page screenshot.
"""
output = f"service_{service}.png"
with sync_playwright() as pw:
ctx = pw.chromium.launch(
headless=True
).new_context(ignore_https_errors=True, viewport={"width": 1920, "height": 1080})
page = ctx.new_page()
page.goto(url)
# Login to Observium
page.fill('input[name="username"]', username)
page.fill('input[name="password"]', password)
page.click('button[id="submit"]')
# Wait for home container to confirm login success
page.wait_for_selector(".container")
# Navigate directly to memory health detail page
memory_url = (
"http://observium.brilliant.com.bd/health/metric=mempool/view=detail/"
"device_id=37,40,67,70,72,77,83,84,86,87,95,96,99,103,105,52,106,107,"
"115,31,85,108,50,121/mempool_descr=physical/"
"requesttoken=f092f74f574a9770add7846d444d8ebc6af52ae93e958d41b252c439b48262b1/"
)
page.goto(memory_url, wait_until="networkidle")
# Wait for metrics table
page.wait_for_selector("table.table", timeout=20000)
# Capture screenshot of condensed table
page.locator("table.table-condensed").screenshot(path="service_observium_memory.png")
def firewall_screenshot(url, username, password, service="firewall"):
"""
Capture Firewall dashboard screenshot.
"""
output = f"service_{service}.png"
with sync_playwright() as pw:
ctx = pw.chromium.launch(
headless=True
).new_context(ignore_https_errors=True, viewport={"width": 1920, "height": 1080})
page = ctx.new_page()
page.goto(url)
# Login to firewall
page.fill('input[name="username"]', username)
page.fill('input[name="secretkey"]', password)
page.click('button[type="button"]')
time.sleep(5) # wait for login redirect
# Navigate to dashboard
dashboard_url = "https://118.67.210.46/ng/system/dashboard/2?vdom=IC-CLOUD"
page.goto(dashboard_url, wait_until="networkidle")
# Ensure dashboard is loaded
page.wait_for_selector("ul.module-list", timeout=20000)
# Capture full page screenshot
page.screenshot(path=output, full_page=True)
def sfssd_screenshot(url, username="admin", password="sL1dSt0gE719", service="sfssd"):
"""
Capture SFSSD system overview screenshot (uses basic auth).
"""
output = f"service_{service}.png"
with sync_playwright() as pw:
ctx = pw.chromium.launch(
headless=True
).new_context(
ignore_https_errors=True,
viewport={"width": 1920, "height": 1080},
http_credentials={"username": username, "password": password}
)
page = ctx.new_page()
page.goto(url)
# Wait for overview report to load
page.wait_for_selector("#reporting-overview", timeout=20000)
time.sleep(15) # allow rendering
# Capture full-page screenshot
page.screenshot(path=output, full_page=True)
def NVMe_screenshot(url, username='admin', password='sL1dSt0gE2022', service="nvme"):
"""
Capture NVMe (NetApp) system capacity screenshot.
"""
output = f"service_{service}.png"
with sync_playwright() as pw:
browser = pw.chromium.launch(headless=True)
ctx = browser.new_context(ignore_https_errors=True, viewport={"width": 1920, "height": 1080})
page = ctx.new_page()
page.goto(url)
# Login to NVMe portal
page.fill('input[name="username"]', username)
page.fill('input[name="password"]', password)
page.click('button[type="submit"]')
# Navigate to capacity bar
page.locator('[data-netapp-id="capacity-bar"]').click()
# Capture system capacity screenshot
page.screenshot(path=output, full_page=True)
time.sleep(10)
def ceph_df_screenshot(ip, username='mosiur', password="123Rashik456", service="ceph"):
"""
Capture Ceph dashboard and OwnCloud disk usage from Cockpit terminal.
"""
output = f"service_{service}.png"
url = f"https://{ip}:9090"
with sync_playwright() as pw:
ctx = pw.chromium.launch(
headless=True
).new_context(ignore_https_errors=True, viewport={"width": 1920, "height": 1080})
page = ctx.new_page()
page.goto(url)
# Login to Cockpit
page.fill('input[id="login-user-input"]', username)
page.fill('input[id="login-password-input"]', password)
page.click('button[type="submit"]')
time.sleep(5)
# Open system terminal
page.goto(f"https://{ip}:9090/system/terminal")
# Switch to terminal iframe
terminal = page.frame_locator(
"iframe[title='Terminal'], iframe[name='cockpit1:localhost/system/terminal']"
)
terminal.locator("body").click()
time.sleep(2)
# Run Ceph commands
page.keyboard.type('source controller_creds')
page.keyboard.press("Enter")
page.keyboard.type('clear')
page.keyboard.press("Enter")
page.keyboard.type('scon1 ceph df && scon1 ceph -s')
page.keyboard.press("Enter")
time.sleep(5)
# Capture Ceph output
terminal.locator("body").screenshot(path=output)
# Run OwnCloud disk usage
page.keyboard.type('clear')
page.keyboard.press("Enter")
page.keyboard.type('owncloud df -h')
time.sleep(2)
page.keyboard.press("Enter")
time.sleep(2)
# Capture OwnCloud output
terminal.locator("body").screenshot(path="service_owncloud.png")
def mail_screenshot(url, username, password, service="mail"):
"""
Capture screenshots from Zimbra Mail Admin:
- Monitor dashboard
- Mail Queue
"""
output = f"service_{service}.png"
with sync_playwright() as pw:
ctx = pw.chromium.launch(
headless=True
).new_context(ignore_https_errors=True, viewport={"width": 1920, "height": 1080})
page = ctx.new_page()
page.goto(url)
# Login to Zimbra Admin
page.fill('input[name="ZLoginUserName"]', username)
page.fill('input[name="ZLoginPassword"]', password)
page.click('input[id="ZLoginButton"]')
# Navigate to Monitor dashboard
monitor_tile = page.locator("div[id^='zti__AppAdmin__Home__monHV__']").get_by_text("Monitor")
monitor_tile.wait_for(state="visible", timeout=20000)
monitor_tile.click()
page.screenshot(path=f"1. {output}", full_page=True)
time.sleep(5)
# Navigate to Mail Queue
mail_queue_tile = page.locator("div[id^='zti__AppAdmin__monHV__']").get_by_text("Mail Queue")
mail_queue_tile.click()
time.sleep(5)
page.screenshot(path=output, full_page=True)
################################################################################################
# Main script execution
################################################################################################
if __name__ == "__main__":
# Ask user for WSL IP (required for Ceph Cockpit)
wsl_ip = input("Enter WSL IP address: ")
print("Starting screenshot capture...")
# RabbitMQ
print("Capturing RabbitMQ screenshot...")
rabbitmq_screenshot("http://118.67.215.11:15672/#/", "guest", "guest", "#main", "rmq")
print("RabbitMQ screenshot captured.")
# Observium
print("Capturing Observium screenshot...")
observium_screenshot("http://observium.brilliant.com.bd/", "admin", "0ObBs5e3rv!iuUm@#@!", "observium")
print("Observium screenshot captured.")
# Firewall
print("Capturing Firewall screenshot...")
firewall_screenshot("https://118.67.210.46/login", "mosiur", "AD^%$bhy34Fw26@mnf234@97tr45")
print("Firewall screenshot captured.")
# SFSSD
print("Capturing SFSSD screenshot...")
sfssd_screenshot("https://192.168.12.2/")
print("SFSSD screenshot captured.")
# NVMe
print("Capturing NVMe screenshot...")
NVMe_screenshot("https://192.168.12.20/sysmgr/v4/")
print("NVMe screenshot captured.")
# Ceph & OwnCloud
print("Capturing Ceph and OwnCloud screenshot...")
ceph_df_screenshot(wsl_ip)
print("Ceph and OwnCloud screenshot captured.")
# Mail
print("Capturing Mail screenshot...")
mail_screenshot(
"https://mail.brilliant.com.bd:9071/zimbraAdmin/",
"admin",
"A@dDmMI!N5#$%@B@6NW@#45#$%HGZI!MBbR@A"
)
print("Mail screenshot captured.")