Subversion Repositories ALCASAR

Rev

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

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