Last active
April 1, 2022 17:40
-
-
Save pikatenor/f40a66ef8c4da4c2d0e23b1b6bf79b88 to your computer and use it in GitHub Desktop.
CyberPower PowerPanel to Slack Webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function q() { | |
jq -r $1 <<-EOF | |
{ | |
"color": { | |
"OCCUR": "danger", | |
"FINISH": "good" | |
}, | |
"event": { | |
"BATTERY_CRITICAL_LOW": { | |
"message": "Battery capacity is critically low." | |
}, | |
"ENTER_BYPASS": { | |
"message": "Enters bypass mode." | |
}, | |
"BATTERY_EXHAUSTED": { | |
"message": "The battery has been exhausted." | |
}, | |
"EMERGENCY_OFF": { | |
"message": "EPO is active." | |
}, | |
"BATTERY_FULL": { | |
"message": "Battery is fully charged." | |
}, | |
"SHUTDOWN": { | |
"message": "Shutdown initiated." | |
}, | |
"BYPASS_FAILURE": { | |
"message": "Bypass power is failure." | |
}, | |
"CAPACITY_INSUFFICIENT": { | |
"message": "Inverter capacity is insufficient." | |
}, | |
"LOSS_REDUNDANT": { | |
"message": "Power redundancy is not enough." | |
}, | |
"ABNORMAL": { | |
"message": "UPS is abnormal.", | |
"condition": { | |
"NO_NEUTRAL":{ | |
"message": "Input is no neutral." | |
}, | |
"WIRING_FAULT":{ | |
"message": "Site wiring fault." | |
} | |
} | |
}, | |
"FATAL_ABNORMAL": { | |
"message": "UPS is fatal abnormal.", | |
"condition": { | |
"OUTPUT_OVERLOAD": { | |
"message": "Output is overloaded." | |
}, | |
"BYPASS_OVERLOAD": { | |
"message": "Bypass is overloaded." | |
}, | |
"MODULE_OVERLOAD": { | |
"message": "Module is overloaded." | |
}, | |
"SHORT_CIRCUIT": { | |
"message": "Output circuit-short." | |
}, | |
"MODULE_RECTIFIER_OVERHEAT": { | |
"message": "Module rectifier is overheated." | |
}, | |
"MODULE_INVERTER_OVERHEAT": { | |
"message": "Module inverter is overheated." | |
}, | |
"MODULE_INVERTER_PROTECTED": { | |
"message": "Module inverter is protected." | |
}, | |
"BATTERY_REVERSED": { | |
"message": "The polarity of battery is reversed." | |
}, | |
"BYPASS_SEQUENCE_ERROR": { | |
"message": "The phase sequence of bypass is wrong." | |
} | |
} | |
}, | |
"COMMUNICATION_FAILURE": { | |
"condition": { | |
"LOST_IN_LOCAL": { | |
"message": "Local communication lost." | |
}, | |
"LOST_IN_NETWORK": { | |
"message": "Network communication lost." | |
} | |
} | |
}, | |
"FAULT": { | |
"condition": { | |
"GENERIC_FAULT": { | |
"message": "UPS is faulty." | |
}, | |
"BYPASS_FAN_FAULT": { | |
"message": "Bypass fan is faulty." | |
}, | |
"BYPASS_FAULT": { | |
"message": "Bypass is faulty." | |
}, | |
"MODULE_RECTIFIER_FAULT": { | |
"message": "Module rectifier is faulty." | |
}, | |
"MODULE_INVERTER_FAULT": { | |
"message": "Module inverter is faulty." | |
}, | |
"MODULE_FAN_FAULT": { | |
"message": "Module fan is faulty." | |
} | |
} | |
}, | |
"NO_BATTERY": { | |
"message": "Battery is not present." | |
}, | |
"RUNTIME_INSUFFICIENT": { | |
"message": "Available runtime is insufficient." | |
}, | |
"UTILITY_FAILURE": { | |
"message": "Utility power failure." | |
}, | |
"URGENT_COMMUNICATION_FAILURE": { | |
"condition": { | |
"LOST_IN_LOCAL": { | |
"message": "Local communication lost in a power event." | |
}, | |
"LOST_IN_NETWORK": { | |
"message": "Network communication lost in a power event." | |
} | |
} | |
}, | |
"RUNTIME_WILL_EXHAUST": { | |
"message": "Remaining runtime will be exhausted." | |
}, | |
"OUTPUT_WILL_STOP": { | |
"message": "The output power is going to stop soon." | |
}, | |
"INPUT_NEAR_OVERLOAD": { | |
"message": "Input is near overload." | |
}, | |
"INPUT_OVERLOAD": { | |
"message": "Input is overload." | |
}, | |
"SHUTDOWN_TIME_INSUFFICIENT": { | |
"message": "Shutdown time is in insufficient." | |
}, | |
"ATS_FAULT": { | |
"message": "ATS is faulty." | |
}, | |
"ALL_SOURCE_FAILURE": { | |
"message": "Both input sources have power loss, ATS will not change input source." | |
}, | |
"CURRENT_SOURCE_FAILURE": { | |
"message": "ATS has automatically switched to redundant power source." | |
}, | |
"REDUNDANT_SOURCE_FAILURE": { | |
"message": "ATS redundant power source has experienced a power failure." | |
}, | |
"ENV_SENSOR_LOST": { | |
"message": "Environmental sensor is not responsive." | |
}, | |
"ENV_SENSOR_OVERHEAT": { | |
"message": "Temperature is over the high threshold." | |
}, | |
"ENV_SENSOR_UNDERCOOL": { | |
"message": "Temperature is under the low threshold." | |
}, | |
"ENV_SENSOR_OVERWET": { | |
"message": "Humidity is over the high threshold." | |
}, | |
"ENV_SENSOR_OVERDRY": { | |
"message": "Humidity is under the low threshold." | |
}, | |
"POWER_LOST": { | |
"message": "Power supply redundancy has been lost." | |
}, | |
"MBO_OUTLET_OVERLOAD": { | |
"message": "A PDU outlet is overloaded." | |
}, | |
"MBO_OUTLET_NEAR_OVERLOAD": { | |
"message": "A PDU outlet is near overload." | |
} | |
} | |
} | |
EOF | |
} | |
function m() { | |
cat <<-EOF | |
{ | |
"attachments":[ | |
{ | |
"fallback": "${message}", | |
"pretext": "Here's some notice from UPS. <@pikatenor>", | |
"color": "${color}", | |
"title": "${EVENT}", | |
"title_link": "http://ppbe.juno.dii/local/assets/helpManual/en/setting.html#advance", | |
"text": "${message}", | |
"fields": [ | |
{ | |
"title": "EVENT", | |
"value": "${EVENT}", | |
"short": true | |
}, | |
{ | |
"title": "EVENT_CONDITION", | |
"value": "${EVENT_CONDITION}", | |
"short": true | |
} | |
], | |
"footer": "CyberPower CPJ1200", | |
"ts": "$(date +%s)" | |
} | |
] | |
} | |
EOF | |
} | |
SLACK_WEBHOOK="" | |
color=$(q ".color.$EVENT_STAGE") | |
if test -n "$EVENT_CONDITION" | |
then | |
message=$(q ".event.$EVENT.condition.$EVENT_CONDITION.message") | |
else | |
message=$(q ".event.$EVENT.message") | |
fi | |
curl -X POST --data-urlencode "payload=$(m)" $SLACK_WEBHOOK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment