-
Notifications
You must be signed in to change notification settings - Fork 0
How It Works
APC PowerChute Serial Shutdown for Business uses Java EE form-based authentication. The login flow is:
1. GET /status
→ Redirects to /logon (JSESSIONID cookie is set)
2. Check login page
→ If "already logged on" message: GET /logoff, then retry from step 1
→ Extract formtoken and formtokenid from hidden fields
3. POST /j_security_check
Body: j_username, j_password, login, formtoken, formtokenid
Content-Type: application/x-www-form-urlencoded
→ 302 redirect to /status (success) or /logon (failure)
4. GET /status
→ Returns the UPS status page HTML
- The POST to
/j_security_checkmust not follow redirects automatically. The script uses aNoRedirectHandlerto check the redirect location for success/failure. - PowerChute only allows one active session. If another session exists, the script detects the "already logged on" message and logs off first.
- A CSRF token (
formtoken/formtokenid) is required for login.
The status page contains UPS data in <div> elements with specific IDs:
<div class="value" id="value_RealPowerPct">19.0</div>
<div class="unit">%</div>
<div class="value" id="value_RuntimeRemaining">29</div>
<div class="unit">分</div>The script uses a regex to extract values:
re.search(r'id="element_id"[^>]*>([^<]+)<', html)Units are in separate elements and are not captured.
PowerChute uses a self-signed SSL certificate. The script disables certificate verification:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONEThis is necessary because the certificate is not signed by a trusted CA.
The script always calls /logoff in a finally block to ensure the session is properly closed, even if an error occurs. This prevents the "already logged on" issue for subsequent runs.
When --zabbix-send is used, data is sent via the zabbix_sender command using stdin (-i -):
hostname apc.status Online
hostname apc.load 19.0
hostname apc.runtime 29
hostname apc.voltage 102.0
hostname apc.battery 100.0
hostname apc.batteryvoltage 13.7
All items are sent in a single zabbix_sender invocation for efficiency.