Subversion Repositories ALCASAR

Rev

Rev 325 | Rev 2976 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log

Rev 325 Rev 2770
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
/**
3
// phpSysInfo - A PHP System Information Script
3
 * mbmon sensor class, getting information from mbmon
-
 
4
 *
4
// http://phpsysinfo.sourceforge.net/
5
 * PHP version 5
5
 
6
 *
-
 
7
 * @category  PHP
-
 
8
 * @package   PSI_Sensor
6
// This program is free software; you can redistribute it and/or
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
-
 
10
 * @copyright 2009 phpSysInfo
7
// modify it under the terms of the GNU General Public License
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
-
 
12
 * @version   Release: 3.0
8
// as published by the Free Software Foundation; either version 2
13
 * @link      http://phpsysinfo.sourceforge.net
-
 
14
 */
9
// of the License, or (at your option) any later version.
15
class MBMon extends Sensors
10
 
16
{
-
 
17
    /**
11
// This program is distributed in the hope that it will be useful,
18
     * content to parse
-
 
19
     *
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20
     * @var array
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
     */
14
// GNU General Public License for more details.
22
    private $_lines = array();
15
 
23
 
-
 
24
    /**
16
// You should have received a copy of the GNU General Public License
25
     * fill the private content var through tcp, command or data access
-
 
26
     */
17
// along with this program; if not, write to the Free Software
27
    public function __construct()
-
 
28
    {
-
 
29
        parent::__construct();
-
 
30
        switch (defined('PSI_SENSOR_MBMON_ACCESS')?strtolower(PSI_SENSOR_MBMON_ACCESS):'command') {
-
 
31
        case 'tcp':
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32
            $fp = fsockopen("localhost", 411, $errno, $errstr, 5);
19
 
-
 
-
 
33
            if ($fp) {
-
 
34
                $lines = "";
-
 
35
                while (!feof($fp)) {
20
// This class was created by Z. Frombach ( zoltan at frombach dot com )
36
                    $lines .= fread($fp, 1024);
21
 
-
 
-
 
37
                }
22
// $Id: class.mbmon.inc.php,v 1.5 2007/02/18 19:11:31 bigmichi1 Exp $
38
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
23
 
-
 
-
 
39
            } else {
-
 
40
                $this->error->addError("fsockopen()", $errno." ".$errstr);
24
class mbinfo {
41
            }
25
	var $lines;
42
            break;
26
 
-
 
27
  function temperature() {
43
        case 'command':
-
 
44
            CommonFunctions::executeProgram('mbmon', '-c 1 -r', $lines, PSI_DEBUG);
-
 
45
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
28
    $results = array();
46
            break;
29
 
-
 
30
	if (!isset($this->lines) ) {
47
        case 'data':
-
 
48
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/mbmon.txt', $lines)) {
31
	    $this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
49
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
-
 
50
            }
-
 
51
            break;
-
 
52
        default:
-
 
53
            $this->error->addConfigError('__construct()', '[sensor_mbmon] ACCESS');
-
 
54
            break;
-
 
55
        }
32
	}
56
    }
33
 
57
 
-
 
58
    /**
-
 
59
     * get temperature information
-
 
60
     *
-
 
61
     * @return void
34
    $i = 0;
62
     */
-
 
63
    private function _temperature()
-
 
64
    {
35
    foreach($this->lines as $line) {
65
        foreach ($this->_lines as $line) {
36
      if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
66
            if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
37
        if ($data[2]<>'0') {
67
                if ($data[2] <> '0') {
38
          $results[$i]['label'] = $data[1];
68
                    $dev = new SensorDevice();
39
          $results[$i]['limit'] = '70.0';
69
                    $dev->setName($data[1]);
40
	  if($data[2] > 250) {
-
 
41
	    $results[$i]['value'] = 0;
70
//                    $dev->setMax(70);
42
	    $results[$i]['percent'] = 0;
71
                    if ($data[2] < 250) {
43
	  } else {
-
 
44
            $results[$i]['value'] = $data[2];
72
                        $dev->setValue($data[2]);
45
            $results[$i]['percent'] = $results[$i]['value'] * 100 / $results[$i]['limit'];
-
 
46
	  }
73
                    }
47
          $i++;
74
                    $this->mbinfo->setMbTemp($dev);
48
        }
75
                }
49
      }
76
            }
50
    }
77
        }
51
    return $results;
-
 
52
  }
-
 
53
 
-
 
54
  function fans() {
-
 
55
    $results = array();
-
 
56
 
-
 
57
	if (!isset($this->lines) ) {
-
 
58
	    $this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
-
 
59
	}
78
    }
60
 
79
 
-
 
80
    /**
-
 
81
     * get fan information
-
 
82
     *
-
 
83
     * @return void
61
    $i = 0;
84
     */
-
 
85
    private function _fans()
-
 
86
    {
62
    foreach($this->lines as $line) {
87
        foreach ($this->_lines as $line) {
63
      if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
88
            if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
64
        if ($data[2]<>'0') {
89
                if ($data[2] <> '0') {
-
 
90
                    $dev = new SensorDevice();
65
          $results[$i]['label'] = $data[1];
91
                    $dev->setName($data[1]);
66
          $results[$i]['value'] = $data[2];
92
                    $dev->setValue($data[2]);
67
          $results[$i]['min'] = '3000';
93
//                    $dev->setMax(3000);
68
          $i++;
94
                    $this->mbinfo->setMbFan($dev);
69
        }
95
                }
70
      }
96
            }
71
    }
97
        }
72
    return $results;
-
 
73
  }
98
    }
74
 
99
 
75
  function voltage() {
100
    /**
76
    $results = array();
101
     * get voltage information
77
 
102
     *
78
	if (!isset($this->lines) ) {
103
     * @return void
-
 
104
     */
79
	    $this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
105
    private function _voltage()
80
	}
-
 
81
 
-
 
82
    $i = 0;
106
    {
83
    foreach($this->lines as $line) {
107
        foreach ($this->_lines as $line) {
84
      if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
108
            if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
85
        if ($data[2]<>'+0.00') {
109
                if ($data[2] <> '+0.00') {
86
          $results[$i]['label'] = $data[1];
110
                    $dev = new SensorDevice();
87
          $results[$i]['value'] = $data[2];
111
                    $dev->setName($data[1]);
88
          $results[$i]['min'] = '0.00';
112
                    $dev->setValue($data[2]);
89
          $results[$i]['max'] = '0.00';
113
                    $this->mbinfo->setMbVolt($dev);
90
          $i++;
114
                }
91
        }
115
            }
92
      }
116
        }
93
    }
117
    }
94
 
118
 
-
 
119
    /**
-
 
120
     * get the information
-
 
121
     *
-
 
122
     * @see PSI_Interface_Sensor::build()
-
 
123
     *
95
    return $results;
124
     * @return void
-
 
125
     */
-
 
126
    public function build()
-
 
127
    {
-
 
128
        $this->_temperature();
-
 
129
        $this->_voltage();
-
 
130
        $this->_fans();
96
  }
131
    }
97
}
132
}
98
 
-
 
99
?>
-