Created
September 18, 2012 20:08
-
-
Save kamermans/3745534 to your computer and use it in GitHub Desktop.
Replacement for the CyberPower PowerPanel email notify script, which does not work on Ubuntu
This file contains hidden or 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
| #!/usr/bin/php | |
| <?php | |
| class EventWrapper { | |
| public function __construct($vars) { | |
| foreach ($vars as $name => $val) $this->$name = $val; | |
| } | |
| public function __get($name) { | |
| return property_exists($this, $name)? $this->$name: null; | |
| } | |
| } | |
| $e = new EventWrapper($_ENV); | |
| $e->SUBJECT = "PowerPanel Notification - [$e->EVENT]"; | |
| $e->FROM = "PowerPanel Daemon <$e->SENDER_ADDRESS>"; | |
| $e->TO = "$e->RECEIPT_NAME <$e->RECEIPT_ADDRESS>"; | |
| $e->MESSAGE = "Warning: The $e->EVENT event has occurred for a while, system will be shutdown immediately!"; | |
| $e->DATE = date('r'); | |
| $e->RUNTIME = ""; | |
| if ($e->REMAINING_RUNTIME != 'none') { | |
| $e->RUNTIME = "Remaining Runtime: $e->REMAINING_RUNTIME Seconds"; | |
| } | |
| $e->DATA = <<<EOL | |
| ======================================================== | |
| $e->SUBJECT | |
| ======================================================== | |
| $e->MESSAGE | |
| Time: $e->DATE | |
| UPS Model Name: $e->MODEL_NAME | |
| Battery Capacity: $e->BATTERY_CAPACITY % | |
| $e->RUNTIME | |
| EOL; | |
| $headers = "From: $e->FROM\r\n"; | |
| mail($e->TO, $e->SUBJECT, $e->DATA, $headers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment