phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpsysinfo/includes/mb class.healthd.inc.php, 1.1 cla


From: skwashd
Subject: [Phpgroupware-cvs] phpsysinfo/includes/mb class.healthd.inc.php, 1.1 class.hwsensors.inc.php, 1.1 class.lmsensors.inc.php, 1.1 class.mbm5.inc.php, 1.1 class.mbmon.inc.php, 1.1 index.html, 1.1
Date: Sat, 19 Nov 2005 06:29:00 +0100

Update of phpsysinfo/includes/mb

Added Files:
     Branch: MAIN
            class.healthd.inc.php 
            class.hwsensors.inc.php 
            class.lmsensors.inc.php 
            class.mbm5.inc.php 
            class.mbmon.inc.php 
            index.html 

Log Message:
sync with current stable from upstream - version 2.4.1, added some fixes and 
improvements along the way

====================================================
Index: class.healthd.inc.php
<?php

// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// $Id: class.healthd.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $

class mbinfo {
    var $lines;

  function temperature() {
    $ar_buf = array();
    $results = array();

    if (!isset($this->lines)) {
      $this->lines = execute_program('healthdc', '-t');
    }

    $ar_buf = preg_split("/\t+/", $this->lines);

    $results[0]['label'] = 'temp1';
    $results[0]['value'] = $ar_buf[1];
    $results[0]['limit'] = '70.0';
    $results[0]['percent'] = $results[0]['value'] * 100 / $results[0]['limit'];
    $results[1]['label'] = 'temp2';
    $results[1]['value'] = $ar_buf[2];
    $results[1]['limit'] = '70.0';
    $results[1]['percent'] = $results[1]['value'] * 100 / $results[1]['limit'];
    $results[2]['label'] = 'temp3';
    $results[2]['value'] = $ar_buf[3];
    $results[2]['limit'] = '70.0';
    $results[2]['percent'] = $results[2]['value'] * 100 / $results[2]['limit'];
    return $results;
  }

  function fans() {
    $ar_buf = array();
    $results = array();

    if (!isset($this->lines)) {
      $this->lines = execute_program('healthdc', '-t');
    }

    $ar_buf = preg_split("/\t+/", $this->lines);

    $results[0]['label'] = 'fan1';
    $results[0]['value'] = $ar_buf[4];
    $results[0]['min'] = '3000';
    $results[0]['div'] = '2';
    $results[1]['label'] = 'fan2';
    $results[1]['value'] = $ar_buf[5];
    $results[1]['min'] = '3000';
    $results[1]['div'] = '2';
    $results[2]['label'] = 'fan3';
    $results[2]['value'] = $ar_buf[6];
    $results[2]['min'] = '3000';
    $results[2]['div'] = '2';

    return $results;
  }

  function voltage() {
    $ar_buf = array();
    $results = array();

    if (!isset($this->lines)) {
      $this->lines = execute_program('healthdc', '-t');
    }

    $ar_buf = preg_split("/\t+/", $this->lines);

    $results[0]['label'] = 'Vcore1';
    $results[0]['value'] = $ar_buf[7];
    $results[0]['min'] = '0.00';
    $results[0]['max'] = '0.00';
    $results[1]['label'] = 'Vcore2';
    $results[1]['value'] = $ar_buf[8];
    $results[1]['min'] = '0.00';
    $results[1]['max'] = '0.00';
    $results[2]['label'] = '3volt';
    $results[2]['value'] = $ar_buf[9];
    $results[2]['min'] = '0.00';
    $results[2]['max'] = '0.00';
    $results[3]['label'] = '+5Volt';
    $results[3]['value'] = $ar_buf[10];
    $results[3]['min'] = '0.00';
    $results[3]['max'] = '0.00';
    $results[4]['label'] = '+12Volt';
    $results[4]['value'] = $ar_buf[11];
    $results[4]['min'] = '0.00';
    $results[4]['max'] = '0.00';
    $results[5]['label'] = '-12Volt';
    $results[5]['value'] = $ar_buf[12];
    $results[5]['min'] = '0.00';
    $results[5]['max'] = '0.00';
    $results[6]['label'] = '-5Volt';
    $results[6]['value'] = $ar_buf[13];
    $results[6]['min'] = '0.00';
    $results[6]['max'] = '0.00';

    return $results;
  }
}

?>

====================================================
Index: class.hwsensors.inc.php
<?php

// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// $Id: class.hwsensors.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $

class mbinfo {
    var $lines;

  function temperature() {
    $ar_buf = array();
    $lines = array();
    $results = array();

    if (!isset($this->lines) ) {
        $this->lines = execute_program('sysctl', '-w hw.sensors');
    }

    $lines = explode("\n", $this->lines);

    for ($i = 0, $j = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/[\s,]+/", $lines[$i]);

      if ($ar_buf[2] == 'temp') {
        $results[$j]['label'] = $ar_buf[1];
        $results[$j]['value'] = $ar_buf[3];
        $results[$j]['limit'] = '70.0';
        $results[$j]['percent'] = $results[$j]['value'] * 100 / 
$results[$j]['limit'];
        $j++;
      }
    }

    return $results;
  }

  function fans() {
    $ar_buf = array();
    $lines = array();
    $results = array();

    if (!isset($this->lines) ) {
        $this->lines = execute_program('sysctl', '-w hw.sensors');
    }

    $lines = explode("\n", $this->lines);

    for ($i = 0, $j = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/[\s,]+/", $lines[$i]);

      if ($ar_buf[2] == 'fanrpm') {
        $results[$j]['label'] = $ar_buf[1];
        $results[$j]['value'] = $ar_buf[3];
        $j++;
      }
    }

    return $results;
  }

  function voltage() {
    $ar_buf = array();
    $lines = array();
    $results = array();

    if (!isset($this->lines) ) {
        $this->lines = execute_program('sysctl', '-w hw.sensors');
    }

    $lines = explode("\n", $this->lines);

    for ($i = 0, $j = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/[\s,]+/", $lines[$i]);

      if ($ar_buf[2] == 'volts_dc') {
        $results[$j]['label'] = $ar_buf[1];
        $results[$j]['value'] = $ar_buf[3];
        $results[$j]['min'] = '0.00';
        $results[$j]['max'] = '0.00';
        $j++;
      }
    }

    return $results;
  }
}

?>

====================================================
Index: class.lmsensors.inc.php
<?php

// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// $Id: class.lmsensors.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $

class mbinfo {
    var $lines;

  function temperature() {
    $ar_buf = array();
    $results = array();

    if (!isset($this->lines)) {
        $this->lines = execute_program("sensors", "");
    }

    // Martijn Stolk: Dirty fix for misinterpreted output of sensors,
    // where info could come on next line when the label is too long.
    $sensors_value = $this->lines;
    $sensors_value = preg_replace("/:\n/", ":", $sensors_value);
    $sensors_value = explode("\n", $sensors_value);

    foreach($sensors_value as $line) {
      $data = array();
      if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data))
        ;
      else
        ereg("(.*):(.*)\((.*)=(.*)\)(.*)", $line, $data);

      $temp = substr(rtrim($data[2]), -1);
      switch ($temp) {
        case "C";
        case "F":
          array_push($ar_buf, $line);
          break;
      }
    }

    $i = 0;
    foreach($ar_buf as $line) {
      if (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)\)", $line, 
$data)) ;
      elseif (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)", $line, 
$data)) ;
      else
        ereg("(.*):(.*).C[ ]*\((.*)=(.*).C\)(.*)", $line, $data);

      $alarm = substr(trim($data[7]), 0, 5);

      $results[$i]['label'] = trim($data[1]);
      $results[$i]['value'] = trim($data[2]);
      $results[$i]['limit'] = trim($data[4]);
      $results[$i]['percent'] = trim($data[6]);
      if ($results[$i]['limit'] < $results[$i]['percent']) {
        $results[$i]['limit'] = $results[$i]['percent'];
      }
      $i++;
    }

    asort($results);
    return array_values($results);
  }

  function fans() {
    $ar_buf = array();
    $results = array();

    if (!isset($this->lines)) {
        $this->lines = execute_program("sensors", "");
    }

    $sensors_value = $this->lines;

    foreach($sensors_value as $line) {
      $data = array();
      ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data);
      $temp = explode(" ", trim($data[2]));
      if (count($temp) == 1)
        $temp = explode("\xb0", trim($data[2]));
      switch ($temp[1]) {
        case "RPM":
          array_push($ar_buf, $line);
          break;
      }
    }

    $i = 0;
    foreach($ar_buf as $line) {
      if (ereg("(.*):(.*) RPM  \((.*)=(.*) RPM,(.*)=(.*)\)(.*)\)", $line, 
$data));
      else
        ereg("(.*):(.*) RPM  \((.*)=(.*) RPM,(.*)=(.*)\)(.*)", $line, $data);
      $alarm = substr(trim($data[7]), 0, 5);

      $results[$i]['label'] = trim($data[1]);
      $results[$i]['value'] = trim($data[2]);
      $results[$i]['min'] = trim($data[4]);
      $results[$i]['div'] = trim($data[6]);
      $i++;
    }

    asort($results);
    return array_values($results);
  }

  function voltage() {
    $ar_buf = array();
    $results = array();

    if (!isset($this->lines)) {
        $this->lines = execute_program("sensors", "");
    }

    $sensors_value = $this->lines;

    foreach($sensors_value as $line) {
      $data = array();
      ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data);
      $temp = explode(" ", trim($data[2]));
      if (count($temp) == 1)
        $temp = explode("\xb0", trim($data[2]));
      switch ($temp[1]) {
        case "V":
          array_push($ar_buf, $line);
          break;
      }
    }

    $i = 0;
    foreach($ar_buf as $line) {
      if (ereg("(.*):(.*) V  \((.*)=(.*) V,(.*)=(.*) V\)(.*)\)", $line, $data));
      else
        ereg("(.*):(.*) V  \((.*)=(.*) V,(.*)=(.*) V\)(.*)", $line, $data);
      $alarm = substr(trim($data[7]), 0, 5);

      $results[$i]['label'] = trim($data[1]);
      $results[$i]['value'] = trim($data[2]);
      $results[$i]['min'] = trim($data[4]);
      $results[$i]['max'] = trim($data[6]);
      $i++;
    }

    return $results;
  }
}

?>

====================================================
Index: class.mbm5.inc.php
<?php
//
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// $Id: class.mbm5.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $
//
// Note: Make sure you set MBM5 Interval Logging to csv and to the root of 
PHPSysInfo.
// Also make sure MBM5 doesn't at symbols to the values. Did is a Quick MBM5 
log parser,
// need more csv logs to make it better.
//
class mbinfo {
    var buf_label;
    var buf_value;

  function temperature() {
    $results = array();

    if (!isset($this->buf_label)) {
      if ($fp = fopen('MBM5.csv', 'r')) {
            $this->buf_label = split(';', fgets($fp));
        $this->buf_value = split(';', fgets($fp));
        fclose($fp);
      }
    }

    $results[0]['label'] = $this->buf_label[3];
    $results[0]['value'] = $this->buf_value[3];
    $results[0]['limit'] = '70.0';
    $results[0]['percent'] = $results[0]['value'] * 100 / $results[0]['limit'];
    $results[1]['label'] = $this->buf_label[4];
    $results[1]['value'] = $this->buf_value[4];
    $results[1]['limit'] = '70.0';
    $results[1]['percent'] = $results[1]['value'] * 100 / $results[1]['limit'];
    $results[2]['label'] = $this->buf_label[5];
    $results[2]['value'] = $this->buf_value[5];
    $results[2]['limit'] = '70.0';
    $results[2]['percent'] = $results[2]['value'] * 100 / $results[2]['limit'];
    return $results;
  }

  function fans() {
    $results = array();

    if (!isset($this->buf_label)) {
      if ($fp = fopen('MBM5.csv', 'r')) {
            $this->buf_label = split(';', fgets($fp));
        $this->buf_value = split(';', fgets($fp));
        fclose($fp);
      }
    }

    $results[0]['label'] = $this->buf_label[13];
    $results[0]['value'] = $this->buf_value[13];
    $results[0]['min'] = '3000';
    $results[0]['div'] = '2';
    $results[1]['label'] = $this->buf_label[14];
    $results[1]['value'] = $this->buf_value[14];
    $results[1]['min'] = '3000';
    $results[1]['div'] = '2';
    $results[2]['label'] = $this->buf_label[15];
    $results[2]['value'] = $this->buf_value[15];
    $results[2]['min'] = '3000';
    $results[2]['div'] = '2';

    return $results;
  }

  function voltage() {
    $results = array();

    if (!isset($this->buf_label)) {
      if ($fp = fopen('MBM5.csv', 'r')) {
            $this->buf_label = split(';', fgets($fp));
        $this->buf_value = split(';', fgets($fp));
        fclose($fp);
      }
    }

    $results[0]['label'] = $this->buf_label[6];
    $results[0]['value'] = $this->buf_value[6];
    $results[0]['min'] = '0.00';
    $results[0]['max'] = '0.00';
    $results[1]['label'] = $this->buf_label[7];
    $results[1]['value'] = $this->buf_value[7];
    $results[1]['min'] = '0.00';
    $results[1]['max'] = '0.00';
    $results[2]['label'] = $this->buf_label[8];
    $results[2]['value'] = $this->buf_value[8];
    $results[2]['min'] = '0.00';
    $results[2]['max'] = '0.00';
    $results[3]['label'] = $this->buf_label[9];
    $results[3]['value'] = $this->buf_value[9];
    $results[3]['min'] = '0.00';
    $results[3]['max'] = '0.00';
    $results[4]['label'] = $this->buf_label[10];
    $results[4]['value'] = $this->buf_value[10];
    $results[4]['min'] = '0.00';
    $results[4]['max'] = '0.00';
    $results[5]['label'] = $this->buf_label[11];
    $results[5]['value'] = $this->buf_value[11];
    $results[5]['min'] = '0.00';
    $results[5]['max'] = '0.00';
    $results[6]['label'] = $this->buf_label[12];
    $results[6]['value'] = $this->buf_value[12];
    $results[6]['min'] = '0.00';
    $results[6]['max'] = '0.00';

    return $results;
  }
}

?>

====================================================
Index: class.mbmon.inc.php
<?php

// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// This class was created by Z. Frombach ( zoltan at frombach dot com )

// $Id: class.mbmon.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $

class mbinfo {
        var $lines;

  function temperature() {
    $results = array();

        if (!isset($this->lines) ) {
            $this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
        }

    $i = 0;
    foreach($this->lines as $line) {
      if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
        if ($data[2]<>'0') {
          $results[$i]['label'] = $data[1];
          $results[$i]['value'] = $data[2];
          $results[$i]['limit'] = '70.0';
          $results[$i]['percent'] = $results[$i]['value'] * 100 / 
$results[$i]['limit'];
          $i++;
        }
      }
    }
    return $results;
  }

  function fans() {
    $results = array();

        if (!isset($this->lines) ) {
            $this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
        }

    $i = 0;
    foreach($this->lines as $line) {
      if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
        if ($data[2]<>'0') {
          $results[$i]['label'] = $data[1];
          $results[$i]['value'] = $data[2];
          $results[$i]['min'] = '3000';
          $results[$i]['div'] = '2';
          $i++;
        }
      }
    }
    return $results;
  }

  function voltage() {
    $results = array();

        if (!isset($this->lines) ) {
            $this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
        }

    $i = 0;
    foreach($this->lines as $line) {
      if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
        if ($data[2]<>'+0.00') {
          $results[$i]['label'] = $data[1];
          $results[$i]['value'] = $data[2];
          $results[$i]['min'] = '0.00';
          $results[$i]['max'] = '0.00';
          $i++;
        }
      }
    }

    return $results;
  }
}

?>

====================================================
Index: index.html






reply via email to

[Prev in Thread] Current Thread [Next in Thread]