Subversion Repositories ALCASAR

Rev

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