Subversion Repositories ALCASAR

Rev

Rev 3037 | Go to most recent revision | Details | 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':
43
            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/ipmicfg.txt', $lines)) {
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
            break;
50
        }
51
    }
52
 
53
    /**
54
     * get temperature information
55
     *
56
     * @return void
57
     */
58
    private function _temperature()
59
    {
60
        foreach ($this->_lines as $line) {
61
            $buffer = preg_split("/\s*\|\s*/", $line);
62
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
63
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/",$buffer[2], $valbuff)) {
64
                $dev = new SensorDevice();
65
                $dev->setName($namebuff[1]);
66
                if ($valbuff[1]<-128) $valbuff[1]+=256; //+256 correction
67
                $dev->setValue($valbuff[1]);
68
                if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/",$buffer[3], $valbuffmin)) {
69
                    if ($valbuffmin[1]<-128) $valbuffmin[1]+=256; //+256 correction
70
                }
71
                if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/",$buffer[4], $valbuffmax)) {
72
                    if ($valbuffmax[1]<-128) $valbuffmax[1]+=256; //+256 correction
73
                    $dev->setMax($valbuffmax[1]);
74
                }
75
                if ((isset($valbuffmin[1]) && ($valbuff[1]<=$valbuffmin[1])) || (isset($valbuffmax[1]) && ($valbuff[1]>=$valbuffmax[1]))) { //own range test due to errors with +256 correction
76
                    $dev->setEvent("Alarm");
77
                }
78
                $this->mbinfo->setMbTemp($dev);
79
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
80
               (count($buffer)==2) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[1], $valbuff)) {
81
                $dev = new SensorDevice();
82
                $dev->setName(trim($buffer[0])." (psfruinfo)");
83
                $dev->setValue($valbuff[1]);
84
                $this->mbinfo->setMBTemp($dev);
85
            }
86
        }
87
    }
88
 
89
    /**
90
     * get voltage information
91
     *
92
     * @return void
93
     */
94
    private function _voltage()
95
    {
96
        foreach ($this->_lines as $line) {
97
            $buffer = preg_split("/\s*\|\s*/", $line);
98
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
99
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sV\s*$/",$buffer[2], $valbuff)) {
100
                $dev = new SensorDevice();
101
                $dev->setName($namebuff[1]);
102
                $dev->setValue($valbuff[1]);
103
                if (preg_match("/^\s*([\d\.].+)\sV\s*$/",$buffer[3], $valbuffmin)) {
104
                    $dev->setMin($valbuffmin[1]);
105
                }
106
                if (preg_match("/^\s*([\d\.].+)\sV\s*$/",$buffer[4], $valbuffmax)) {
107
                    $dev->setMax($valbuffmax[1]);
108
                }
109
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
110
                $this->mbinfo->setMbVolt($dev);
111
            }
112
        }
113
    }
114
 
115
    /**
116
     * get fan information
117
     *
118
     * @return void
119
     */
120
    private function _fans()
121
    {
122
        foreach ($this->_lines as $line) {
123
            $buffer = preg_split("/\s*\|\s*/", $line);
124
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
125
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sRPM\s*$/",$buffer[2], $valbuff)) {
126
                $dev = new SensorDevice();
127
                $dev->setName($namebuff[1]);
128
                $dev->setValue($valbuff[1]);
129
                if (preg_match("/^\s*(\d+)\sRPM\s*$/",$buffer[3], $valbuffmin)) {
130
                    $dev->setMin($valbuffmin[1]);
131
                }
132
                if ((trim($buffer[0]) != "OK") && isset($valbuffmin[1])) {
133
                    $dev->setEvent(trim($buffer[0]));
134
                }
135
                $this->mbinfo->setMbFan($dev);
136
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
137
               (count($buffer)==2) && preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[1], $valbuff)) {
138
                $dev = new SensorDevice();
139
                $dev->setName(trim($buffer[0])." (psfruinfo)");
140
                $dev->setValue($valbuff[1]);
141
                $this->mbinfo->setMBFan($dev);
142
            }
143
        }
144
    }
145
 
146
    /**
147
     * get power information
148
     *
149
     * @return void
150
     */
151
    private function _power()
152
    {
153
        foreach ($this->_lines as $line) {
154
            $buffer = preg_split("/\s*\|\s*/", $line);
155
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
156
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sWatts\s*$/",$buffer[2], $valbuff)) {
157
                $dev = new SensorDevice();
158
                $dev->setName($namebuff[1]);
159
                $dev->setValue($valbuff[1]);
160
                if (preg_match("/^\s*(\d+)\sWatts\s*$/",$buffer[4], $valbuffmax)) {
161
                    $dev->setMax($valbuffmax[1]);
162
                }
163
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
164
                $this->mbinfo->setMbPower($dev);
165
            }
166
        }
167
    }
168
 
169
    /**
170
     * get current information
171
     *
172
     * @return void
173
     */
174
    private function _current()
175
    {
176
        foreach ($this->_lines as $line) {
177
            $buffer = preg_split("/\s*\|\s*/", $line);
178
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
179
               (count($buffer)==6) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sAmps\s*$/",$buffer[2], $valbuff)) {
180
                $dev = new SensorDevice();
181
                $dev->setName($namebuff[1]);
182
                $dev->setValue($valbuff[1]);
183
                if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/",$buffer[3], $valbuffmin)) {
184
                    $dev->setMin($valbuffmin[1]);
185
                }
186
                if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/",$buffer[4], $valbuffmax)) {
187
                    $dev->setMax($valbuffmax[1]);
188
                }
189
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
190
                $this->mbinfo->setMbCurrent($dev);
191
            }
192
        }
193
    }
194
 
195
    /**
196
     * get other information
197
     *
198
     * @return void
199
     */
200
    private function _other()
201
    {
202
        foreach ($this->_lines as $line) {
203
            $buffer = preg_split("/\s*\|\s*/", $line);
204
            if ((!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (strtolower(PSI_SENSOR_IPMICFG_PSFRUINFO)!=="only")) &&
205
               (count($buffer)==4) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) &&
206
               ($buffer[2]!=="Correctable ECC / other correctable memory error") &&
207
               ($buffer[2]!=="N/A")) {
208
                $dev = new SensorDevice();
209
                $dev->setName($namebuff[1]);
210
                $dev->setValue($buffer[2]);
211
                if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
212
                $this->mbinfo->setMbOther($dev);
213
            } elseif ((defined('PSI_SENSOR_IPMICFG_PSFRUINFO') && (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) &&
214
               (count($buffer)==2) && (trim($buffer[0])=="Status")) {
215
                $dev = new SensorDevice();
216
                $dev->setName(trim($buffer[0])." (psfruinfo)");
217
                $dev->setValue($buffer[1]);
218
                $this->mbinfo->setMbOther($dev);
219
            }
220
        }
221
    }
222
 
223
    /**
224
     * get the information
225
     *
226
     * @see PSI_Interface_Sensor::build()
227
     *
228
     * @return Void
229
     */
230
    public function build()
231
    {
232
        $this->_temperature();
233
        $this->_voltage();
234
        $this->_fans();
235
        $this->_power();
236
        $this->_current();
237
        $this->_other();
238
    }
239
}