Subversion Repositories ALCASAR

Rev

Rev 3037 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3037 Rev 3100
1
<?php
1
<?php
2
/**
2
/**
3
 * ipmicfg sensor class, getting information from ipmicfg -sdr
3
 * ipmicfg sensor class, getting information from ipmicfg -sdr
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI_Sensor
8
 * @package   PSI_Sensor
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2021 phpSysInfo
10
 * @copyright 2021 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
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
12
 * @version   Release: 3.0
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
class IPMIcfg extends Sensors
15
class IPMIcfg extends Sensors
16
{
16
{
17
    /**
17
    /**
18
     * content to parse
18
     * content to parse
19
     *
19
     *
20
     * @var array
20
     * @var array
21
     */
21
     */
22
    private $_lines = array();
22
    private $_lines = array();
23
 
23
 
24
    /**
24
    /**
25
     * fill the private content var through command or data access
25
     * fill the private content var through command or data access
26
     */
26
     */
27
    public function __construct()
27
    public function __construct()
28
    {
28
    {
29
        parent::__construct();
29
        parent::__construct();
30
        if (!defined('PSI_EMU_HOSTNAME')) switch (defined('PSI_SENSOR_IPMICFG_ACCESS')?strtolower(PSI_SENSOR_IPMICFG_ACCESS):'command') {
30
        if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) switch (defined('PSI_SENSOR_IPMICFG_ACCESS')?strtolower(PSI_SENSOR_IPMICFG_ACCESS):'command') {
31
        case 'command':
31
        case 'command':
32
            if (!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) {
32
            if (!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) {
33
                CommonFunctions::executeProgram('ipmicfg', '-sdr', $lines);
33
                CommonFunctions::executeProgram('ipmicfg', '-sdr', $lines);
34
            }
34
            }
35
            if (defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) {
35
            if (defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) {
36
                if (CommonFunctions::executeProgram('ipmicfg', '-psfruinfo', $lines2, PSI_DEBUG)) {
36
                if (CommonFunctions::executeProgram('ipmicfg', '-psfruinfo', $lines2, PSI_DEBUG)) {
37
                    $lines.=$lines2;
37
                    $lines.=$lines2;
38
                }
38
                }
39
            }
39
            }
40
            $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
40
            $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
41
            break;
41
            break;
42
        case 'data':
42
        case 'data':
43
            if (CommonFunctions::rftsdata('ipmicfg.tmp', $lines)) {
43
            if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('ipmicfg.tmp', $lines)) {
44
                $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
44
                $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
45
            }
45
            }
46
            break;
46
            break;
47
        default:
47
        default:
48
            $this->error->addConfigError('__construct()', '[sensor_ipmicfg] ACCESS');
48
            $this->error->addConfigError('__construct()', '[sensor_ipmicfg] ACCESS');
49
        }
49
        }
50
    }
50
    }
51
 
51
 
52
    /**
52
    /**
53
     * get temperature information
53
     * get temperature information
54
     *
54
     *
55
     * @return void
55
     * @return void
56
     */
56
     */
57
    private function _temperature()
57
    private function _temperature()
58
    {
58
    {
59
        foreach ($this->_lines as $line) {
59
        foreach ($this->_lines as $line) {
60
            $buffer = preg_split("/\s*\|\s*/", $line);
60
            $buffer = preg_split("/\s*\|\s*/", $line);
61
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
61
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
62
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[2], $valbuff)) {
62
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[2], $valbuff)) {
63
                $dev = new SensorDevice();
63
                $dev = new SensorDevice();
64
                $dev->setName($namebuff[1]);
64
                $dev->setName($namebuff[1]);
65
                if ($valbuff[1]<-128) $valbuff[1]+=256; //+256 correction
65
                if ($valbuff[1]<-128) $valbuff[1]+=256; //+256 correction
66
                $dev->setValue($valbuff[1]);
66
                $dev->setValue($valbuff[1]);
67
                if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[3], $valbuffmin)) {
67
                if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[3], $valbuffmin)) {
68
                    if ($valbuffmin[1]<-128) $valbuffmin[1]+=256; //+256 correction
68
                    if ($valbuffmin[1]<-128) $valbuffmin[1]+=256; //+256 correction
69
                }
69
                }
70
                if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[4], $valbuffmax)) {
70
                if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[4], $valbuffmax)) {
71
                    if ($valbuffmax[1]<-128) $valbuffmax[1]+=256; //+256 correction
71
                    if ($valbuffmax[1]<-128) $valbuffmax[1]+=256; //+256 correction
72
                    $dev->setMax($valbuffmax[1]);
72
                    $dev->setMax($valbuffmax[1]);
73
                }
73
                }
74
                if ((isset($valbuffmin[1]) && ($valbuff[1]<=$valbuffmin[1])) || (isset($valbuffmax[1]) && ($valbuff[1]>=$valbuffmax[1]))) { //own range test due to errors with +256 correction
74
                if ((isset($valbuffmin[1]) && ($valbuff[1]<=$valbuffmin[1])) || (isset($valbuffmax[1]) && ($valbuff[1]>=$valbuffmax[1]))) { //own range test due to errors with +256 correction
75
                    $dev->setEvent("Alarm");
75
                    $dev->setEvent("Alarm");
76
                }
76
                }
77
                $this->mbinfo->setMbTemp($dev);
77
                $this->mbinfo->setMbTemp($dev);
78
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
78
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
79
               (count($buffer)==2) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[1], $valbuff)) {
79
               (count($buffer)==2) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[1], $valbuff)) {
80
                $dev = new SensorDevice();
80
                $dev = new SensorDevice();
81
                $dev->setName(trim($buffer[0])." (psfruinfo)");
81
                $dev->setName(trim($buffer[0])." (psfruinfo)");
82
                $dev->setValue($valbuff[1]);
82
                $dev->setValue($valbuff[1]);
83
                $this->mbinfo->setMBTemp($dev);
83
                $this->mbinfo->setMBTemp($dev);
84
            }
84
            }
85
        }
85
        }
86
    }
86
    }
87
 
87
 
88
    /**
88
    /**
89
     * get voltage information
89
     * get voltage information
90
     *
90
     *
91
     * @return void
91
     * @return void
92
     */
92
     */
93
    private function _voltage()
93
    private function _voltage()
94
    {
94
    {
95
        foreach ($this->_lines as $line) {
95
        foreach ($this->_lines as $line) {
96
            $buffer = preg_split("/\s*\|\s*/", $line);
96
            $buffer = preg_split("/\s*\|\s*/", $line);
97
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
97
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
98
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sV\s*$/", $buffer[2], $valbuff)) {
98
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sV\s*$/", $buffer[2], $valbuff)) {
99
                $dev = new SensorDevice();
99
                $dev = new SensorDevice();
100
                $dev->setName($namebuff[1]);
100
                $dev->setName($namebuff[1]);
101
                $dev->setValue($valbuff[1]);
101
                $dev->setValue($valbuff[1]);
102
                if (preg_match("/^\s*([\d\.].+)\sV\s*$/", $buffer[3], $valbuffmin)) {
102
                if (preg_match("/^\s*([\d\.].+)\sV\s*$/", $buffer[3], $valbuffmin)) {
103
                    $dev->setMin($valbuffmin[1]);
103
                    $dev->setMin($valbuffmin[1]);
104
                }
104
                }
105
                if (preg_match("/^\s*([\d\.].+)\sV\s*$/", $buffer[4], $valbuffmax)) {
105
                if (preg_match("/^\s*([\d\.].+)\sV\s*$/", $buffer[4], $valbuffmax)) {
106
                    $dev->setMax($valbuffmax[1]);
106
                    $dev->setMax($valbuffmax[1]);
107
                }
107
                }
108
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
108
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
109
                $this->mbinfo->setMbVolt($dev);
109
                $this->mbinfo->setMbVolt($dev);
110
            }
110
            }
111
        }
111
        }
112
    }
112
    }
113
 
113
 
114
    /**
114
    /**
115
     * get fan information
115
     * get fan information
116
     *
116
     *
117
     * @return void
117
     * @return void
118
     */
118
     */
119
    private function _fans()
119
    private function _fans()
120
    {
120
    {
121
        foreach ($this->_lines as $line) {
121
        foreach ($this->_lines as $line) {
122
            $buffer = preg_split("/\s*\|\s*/", $line);
122
            $buffer = preg_split("/\s*\|\s*/", $line);
123
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
123
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
124
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[2], $valbuff)) {
124
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[2], $valbuff)) {
125
                $dev = new SensorDevice();
125
                $dev = new SensorDevice();
126
                $dev->setName($namebuff[1]);
126
                $dev->setName($namebuff[1]);
127
                $dev->setValue($valbuff[1]);
127
                $dev->setValue($valbuff[1]);
128
                if (preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[3], $valbuffmin)) {
128
                if (preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[3], $valbuffmin)) {
129
                    $dev->setMin($valbuffmin[1]);
129
                    $dev->setMin($valbuffmin[1]);
130
                }
130
                }
131
                if ((trim($buffer[0]) != "OK") && isset($valbuffmin[1])) {
131
                if ((trim($buffer[0]) != "OK") && isset($valbuffmin[1])) {
132
                    $dev->setEvent(trim($buffer[0]));
132
                    $dev->setEvent(trim($buffer[0]));
133
                }
133
                }
134
                $this->mbinfo->setMbFan($dev);
134
                $this->mbinfo->setMbFan($dev);
135
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
135
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
136
               (count($buffer)==2) && preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[1], $valbuff)) {
136
               (count($buffer)==2) && preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[1], $valbuff)) {
137
                $dev = new SensorDevice();
137
                $dev = new SensorDevice();
138
                $dev->setName(trim($buffer[0])." (psfruinfo)");
138
                $dev->setName(trim($buffer[0])." (psfruinfo)");
139
                $dev->setValue($valbuff[1]);
139
                $dev->setValue($valbuff[1]);
140
                $this->mbinfo->setMBFan($dev);
140
                $this->mbinfo->setMBFan($dev);
141
            }
141
            }
142
        }
142
        }
143
    }
143
    }
144
 
144
 
145
    /**
145
    /**
146
     * get power information
146
     * get power information
147
     *
147
     *
148
     * @return void
148
     * @return void
149
     */
149
     */
150
    private function _power()
150
    private function _power()
151
    {
151
    {
152
        foreach ($this->_lines as $line) {
152
        foreach ($this->_lines as $line) {
153
            $buffer = preg_split("/\s*\|\s*/", $line);
153
            $buffer = preg_split("/\s*\|\s*/", $line);
154
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
154
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
155
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sWatts\s*$/", $buffer[2], $valbuff)) {
155
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sWatts\s*$/", $buffer[2], $valbuff)) {
156
                $dev = new SensorDevice();
156
                $dev = new SensorDevice();
157
                $dev->setName($namebuff[1]);
157
                $dev->setName($namebuff[1]);
158
                $dev->setValue($valbuff[1]);
158
                $dev->setValue($valbuff[1]);
159
                if (preg_match("/^\s*(\d+)\sWatts\s*$/", $buffer[4], $valbuffmax)) {
159
                if (preg_match("/^\s*(\d+)\sWatts\s*$/", $buffer[4], $valbuffmax)) {
160
                    $dev->setMax($valbuffmax[1]);
160
                    $dev->setMax($valbuffmax[1]);
161
                }
161
                }
162
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
162
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
163
                $this->mbinfo->setMbPower($dev);
163
                $this->mbinfo->setMbPower($dev);
164
            }
164
            }
165
        }
165
        }
166
    }
166
    }
167
 
167
 
168
    /**
168
    /**
169
     * get current information
169
     * get current information
170
     *
170
     *
171
     * @return void
171
     * @return void
172
     */
172
     */
173
    private function _current()
173
    private function _current()
174
    {
174
    {
175
        foreach ($this->_lines as $line) {
175
        foreach ($this->_lines as $line) {
176
            $buffer = preg_split("/\s*\|\s*/", $line);
176
            $buffer = preg_split("/\s*\|\s*/", $line);
177
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
177
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
178
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sAmps\s*$/", $buffer[2], $valbuff)) {
178
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sAmps\s*$/", $buffer[2], $valbuff)) {
179
                $dev = new SensorDevice();
179
                $dev = new SensorDevice();
180
                $dev->setName($namebuff[1]);
180
                $dev->setName($namebuff[1]);
181
                $dev->setValue($valbuff[1]);
181
                $dev->setValue($valbuff[1]);
182
                if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/", $buffer[3], $valbuffmin)) {
182
                if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/", $buffer[3], $valbuffmin)) {
183
                    $dev->setMin($valbuffmin[1]);
183
                    $dev->setMin($valbuffmin[1]);
184
                }
184
                }
185
                if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/", $buffer[4], $valbuffmax)) {
185
                if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/", $buffer[4], $valbuffmax)) {
186
                    $dev->setMax($valbuffmax[1]);
186
                    $dev->setMax($valbuffmax[1]);
187
                }
187
                }
188
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
188
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
189
                $this->mbinfo->setMbCurrent($dev);
189
                $this->mbinfo->setMbCurrent($dev);
190
            }
190
            }
191
        }
191
        }
192
    }
192
    }
193
 
193
 
194
    /**
194
    /**
195
     * get other information
195
     * get other information
196
     *
196
     *
197
     * @return void
197
     * @return void
198
     */
198
     */
199
    private function _other()
199
    private function _other()
200
    {
200
    {
201
        foreach ($this->_lines as $line) {
201
        foreach ($this->_lines as $line) {
202
            $buffer = preg_split("/\s*\|\s*/", $line);
202
            $buffer = preg_split("/\s*\|\s*/", $line);
203
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
203
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
204
               (count($buffer)==4) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) &&
204
               (count($buffer)==4) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) &&
205
               ($buffer[2]!=="Correctable ECC / other correctable memory error") &&
205
               ($buffer[2]!=="Correctable ECC / other correctable memory error") &&
206
               ($buffer[2]!=="N/A")) {
206
               ($buffer[2]!=="N/A")) {
207
                $dev = new SensorDevice();
207
                $dev = new SensorDevice();
208
                $dev->setName($namebuff[1]);
208
                $dev->setName($namebuff[1]);
209
                $dev->setValue($buffer[2]);
209
                $dev->setValue($buffer[2]);
210
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
210
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
211
                $this->mbinfo->setMbOther($dev);
211
                $this->mbinfo->setMbOther($dev);
212
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
212
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
213
               (count($buffer)==2) && (trim($buffer[0])=="Status")) {
213
               (count($buffer)==2) && (trim($buffer[0])=="Status")) {
214
                $dev = new SensorDevice();
214
                $dev = new SensorDevice();
215
                $dev->setName(trim($buffer[0])." (psfruinfo)");
215
                $dev->setName(trim($buffer[0])." (psfruinfo)");
216
                $dev->setValue($buffer[1]);
216
                $dev->setValue($buffer[1]);
217
                $this->mbinfo->setMbOther($dev);
217
                $this->mbinfo->setMbOther($dev);
218
            }
218
            }
219
        }
219
        }
220
    }
220
    }
221
 
221
 
222
    /**
222
    /**
223
     * get the information
223
     * get the information
224
     *
224
     *
225
     * @see PSI_Interface_Sensor::build()
225
     * @see PSI_Interface_Sensor::build()
226
     *
226
     *
227
     * @return void
227
     * @return void
228
     */
228
     */
229
    public function build()
229
    public function build()
230
    {
230
    {
231
        $this->_temperature();
231
        $this->_temperature();
232
        $this->_voltage();
232
        $this->_voltage();
233
        $this->_fans();
233
        $this->_fans();
234
        $this->_power();
234
        $this->_power();
235
        $this->_current();
235
        $this->_current();
236
        $this->_other();
236
        $this->_other();
237
    }
237
    }
238
}
238
}
239
 
239