Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * freeipmi sensor class, getting information from ipmi-sensors
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Sensor
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2014 phpSysInfo
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
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
class FreeIPMI extends Sensors
16
{
17
    /**
18
     * content to parse
19
     *
20
     * @var array
21
     */
22
    private $_lines = array();
23
 
24
    /**
25
     * fill the private content var through command or data access
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct();
2976 rexy 30
        if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) switch (defined('PSI_SENSOR_FREEIPMI_ACCESS')?strtolower(PSI_SENSOR_FREEIPMI_ACCESS):'command') {
2770 rexy 31
        case 'command':
32
            CommonFunctions::executeProgram('ipmi-sensors', '--output-sensor-thresholds', $lines);
2976 rexy 33
            $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
2770 rexy 34
            break;
35
        case 'data':
3037 rexy 36
            if (CommonFunctions::rftsdata('freeipmi.tmp', $lines)) {
2976 rexy 37
                $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
2770 rexy 38
            }
39
            break;
40
        default:
41
            $this->error->addConfigError('__construct()', '[sensor_freeipmi] ACCESS');
42
        }
43
    }
44
 
45
    /**
46
     * get temperature information
47
     *
48
     * @return void
49
     */
50
    private function _temperature()
51
    {
52
        foreach ($this->_lines as $line) {
53
            $buffer = preg_split("/\s*\|\s*/", $line);
54
            if ($buffer[2] == "Temperature" && $buffer[11] != "N/A" && $buffer[4] == "C") {
55
                $dev = new SensorDevice();
56
                $dev->setName($buffer[1]);
57
                $dev->setValue($buffer[3]);
58
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
59
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
60
                $this->mbinfo->setMbTemp($dev);
61
            }
62
        }
63
    }
64
 
65
    /**
66
     * get voltage information
67
     *
68
     * @return void
69
     */
70
    private function _voltage()
71
    {
72
        foreach ($this->_lines as $line) {
73
            $buffer = preg_split("/\s*\|\s*/", $line);
74
            if ($buffer[2] == "Voltage" && $buffer[11] != "N/A" && $buffer[4] == "V") {
75
                $dev = new SensorDevice();
76
                $dev->setName($buffer[1]);
77
                $dev->setValue($buffer[3]);
78
                if ($buffer[6] != "N/A") $dev->setMin($buffer[6]);
79
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
80
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
81
                $this->mbinfo->setMbVolt($dev);
82
            }
83
        }
84
    }
85
 
86
    /**
87
     * get fan information
88
     *
89
     * @return void
90
     */
91
    private function _fans()
92
    {
93
        foreach ($this->_lines as $line) {
94
            $buffer = preg_split("/\s*\|\s*/", $line);
95
            if ($buffer[2] == "Fan" && $buffer[11] != "N/A" && $buffer[4] == "RPM") {
96
                $dev = new SensorDevice();
97
                $dev->setName($buffer[1]);
98
                $dev->setValue($buffer[3]);
99
                if ($buffer[6] != "N/A") {
100
                    $dev->setMin($buffer[6]);
101
                } elseif (($buffer[9] != "N/A") && ($buffer[9]<$buffer[3])) { //max instead min issue
102
                    $dev->setMin($buffer[9]);
103
                }
104
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
105
                $this->mbinfo->setMbFan($dev);
106
            }
107
        }
108
    }
109
 
110
    /**
111
     * get power information
112
     *
113
     * @return void
114
     */
115
    private function _power()
116
    {
117
        foreach ($this->_lines as $line) {
118
            $buffer = preg_split("/\s*\|\s*/", $line);
119
            if ($buffer[2] == "Current" && $buffer[11] != "N/A" && $buffer[4] == "W") {
120
                $dev = new SensorDevice();
121
                $dev->setName($buffer[1]);
122
                $dev->setValue($buffer[3]);
123
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
124
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
125
                $this->mbinfo->setMbPower($dev);
126
            }
127
        }
128
    }
129
 
130
    /**
131
     * get current information
132
     *
133
     * @return void
134
     */
135
    private function _current()
136
    {
137
        foreach ($this->_lines as $line) {
138
            $buffer = preg_split("/\s*\|\s*/", $line);
139
            if ($buffer[2] == "Current" && $buffer[11] != "N/A" && $buffer[4] == "A") {
140
                $dev = new SensorDevice();
141
                $dev->setName($buffer[1]);
142
                $dev->setValue($buffer[3]);
143
                if ($buffer[6] != "N/A") $dev->setMin($buffer[6]);
144
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
145
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
146
                $this->mbinfo->setMbCurrent($dev);
147
            }
148
        }
149
    }
150
 
151
    /**
152
     * get other information
153
     *
154
     * @return void
155
     */
156
    private function _other()
157
    {
158
        foreach ($this->_lines as $line) {
159
            $buffer = preg_split("/\s*\|\s*/", $line);
160
             if ($buffer[4] == "N/A"
161
                && $buffer[2] != "OEM Reserved" && $buffer[11] != "N/A") {
162
                $dev = new SensorDevice();
163
                $dev->setName($buffer[1].' ('.$buffer[2].')');
164
                $dev->setValue(trim($buffer[11], '\''));
165
                $this->mbinfo->setMbOther($dev);
166
            }
167
        }
168
    }
169
 
170
    /**
171
     * get the information
172
     *
173
     * @see PSI_Interface_Sensor::build()
174
     *
3037 rexy 175
     * @return void
2770 rexy 176
     */
177
    public function build()
178
    {
179
        $this->_temperature();
180
        $this->_voltage();
181
        $this->_fans();
182
        $this->_power();
183
        $this->_current();
184
        $this->_other();
185
    }
186
}