Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ----------------------------------------------------
- PowerChute Personal Edition 3.0.2 EventLog File Parser
- ©2013 by (v) Vadym Gulyi | http://vady.kiev.ua/
- -- credits:
- http://johnwbartlett.com/PowerChute.html
- http://www.seltron.net/apc/powerchute.php
- http://vady.kiev.ua/tweets/1106
- -- license:
- GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- ---------------------------------------------------- */
- $events = array(
- '172' => "Battery backup transferred to battery power due to overvoltage",
- '173' => "Battery backup transferred to battery power due to undervoltage",
- '174' => "Battery backup transferred to battery power due to blackout",
- '177' => "PowerChute causing PC to hibernate",
- '61451' => "Self-test Failed",
- '61452' => "Self-test Passed",
- '61453' => "Battery backup transferred to battery power due to electrical noise",
- '61455' => "Battery backup transferred to AC utility power",
- '61456' => "PowerChute not communicating with battery backup",
- '61459' => "Battery connected in the battery backup",
- '61460' => "UPS has been disconnected",
- '61465' => "PowerChute recommenced communicating with the battery backup",
- '61483' => "PowerChute not communicating with the battery backup while on battery power",
- '61501' => "PowerChute regained communication with the battery backup while on battery power"
- );
- $onbattery = array(
- '172' => true,
- '173' => true,
- '174' => true,
- '177' => false,
- '61453' => true,
- '61455' => false,
- '61456' => false,
- // '61459' => "Battery connected in the battery backup",
- '61460' => false,
- '61465' => false,
- '61483' => true,
- '61501' => true
- );
- function getmicrotime() {
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
- $file = (!empty($_FILES['eventlog'])) ? $_FILES['eventlog']['tmp_name'] : 'C:\Program Files\PowerChute Personal Edition\eventlog.dat';
- $html = '<html><head><title>PowerChute Personal Edition EventLog File Parser</title></head><body>';
- if(file_exists($file)) {
- $timer = getmicrotime();
- setlocale(LC_ALL, 'ru_RU.CP1251', 'rus_RUS.CP1251', 'Russian_Russia.1251');
- $html .= '<table border="1" cellpadding="5" cellspacing="0"><tr><th scope="col">#</th><th scope="col">Date</th><th scope="col"> </th><th scope="col"> </th><th scope="col">On Battery?</th><th scope="col">Event</th></tr>';
- $nn = 1;
- foreach(array_chunk(array_slice(unpack("v*", "\0\0".file_get_contents($file)), 1),10) as $data) {
- $date = mktime($data[4], $data[5], $data[6], $data[1], $data[3], $data[0]);
- $timestamp = sprintf('<span title="%s">%s</span>', strftime("%A, %d %B %Y", $date)." @ ".date("H:i:s", $date), date("Y-m-d H:i:s", $date));
- $event = (isset($events[$data[8]])) ? $events[$data[8]] : 'Event #'.$data[8];
- $event = sprintf('<span title="EventID #%d">%s</span>', $data[8], $event);
- $unknown = sprintf('<span title="Duration: %s">%s</span>', date('i:s',$data[7]), $data[7]);
- $accuse = array_key_exists($data[8], $onbattery) ? ($onbattery[$data[8]]===true) ? 'Yes' : 'No' : 'N/A';
- $html .= sprintf('<tr valign="top"><td align="right">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', $nn++, $timestamp, $data[2], $unknown, $accuse, $event);
- }
- $html .= '</table>';
- echo $html;
- if($nn>1) printf("<p>%d total records parsed in %s seconds!</p>", $nn-1, (number_format(getmicrotime()-$timer,2)));
- else echo '<p>No data found in eventlog.dat.</p>';
- } else {
- echo $html.'<form enctype="multipart/form-data" method="post" action="'.$_SERVER['PHP_SELF'].'"><label for="eventlog">Provide <strong>eventlog.dat</strong> file:</label><input type="file" name="eventlog" id="eventlog" /><input type="submit" value="Parse" /></form>';
- }
- echo '</body></html>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement