Subversion Repositories ALCASAR

Rev

Rev 2775 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2775 Rev 3037
Line 37... Line 37...
37
     * get all information from all configured ups in phpsysinfo.ini and store output in internal array
37
     * get all information from all configured ups in phpsysinfo.ini and store output in internal array
38
     */
38
     */
39
    public function __construct()
39
    public function __construct()
40
    {
40
    {
41
        parent::__construct();
41
        parent::__construct();
-
 
42
        if (!defined('PSI_UPS_SNMPUPS_ACCESS')) {
-
 
43
             define('PSI_UPS_SNMPUPS_ACCESS', 'php-snmp');
-
 
44
        }
42
        switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
45
        switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
-
 
46
        case 'data':
-
 
47
                if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
-
 
48
                    if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
-
 
49
                        $upss = eval(PSI_UPS_SNMPUPS_LIST);
-
 
50
                    } else {
-
 
51
                        $upss = array(PSI_UPS_SNMPUPS_LIST);
-
 
52
                    }
-
 
53
                } else {
-
 
54
                   $upss = array('UPS');
-
 
55
                }
-
 
56
                $un = 0;
-
 
57
                foreach ($upss as $ups) {
-
 
58
                    $temp = "";
-
 
59
                    CommonFunctions::rftsdata("upssnmpups{$un}.tmp", $temp);
-
 
60
                    if (! empty($temp)) {
-
 
61
                        $this->_output[] = $temp;
-
 
62
                    }
-
 
63
                    $un++;
-
 
64
                }
-
 
65
                break;
43
        case 'command':
66
        case 'command':
44
                if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
67
                if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
45
                    if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
68
                    if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
46
                        $upss = eval(PSI_UPS_SNMPUPS_LIST);
69
                        $upss = eval(PSI_UPS_SNMPUPS_LIST);
47
                    } else {
70
                    } else {
48
                        $upss = array(PSI_UPS_SNMPUPS_LIST);
71
                        $upss = array(PSI_UPS_SNMPUPS_LIST);
49
                    }
72
                    }
50
                    foreach ($upss as $ups) {
73
                    foreach ($upss as $ups) {
-
 
74
                        $buffer = "";
51
                        CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG);
75
                        CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG);
52
                        if (strlen($buffer) > 0) {
76
                        if (strlen($buffer) > 0) {
53
                            $this->_output[$ups] = $buffer;
77
                            $this->_output[$ups] = $buffer;
54
                            $buffer = "";
78
                            $buffer = "";
55
                            CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG);
79
                            CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG);
Line 114... Line 138...
114
                            }
138
                            }
115
                            if (! empty($bufferarr2)) {
139
                            if (! empty($bufferarr2)) {
116
                                foreach ($bufferarr2 as $id=>$string) {
140
                                foreach ($bufferarr2 as $id=>$string) {
117
                                    $buffer .= $id." = ".$string."\n";
141
                                    $buffer .= $id." = ".$string."\n";
118
                                }
142
                                }
-
 
143
                            }
119
                            if (! empty($bufferarr3)) {
144
                            if (! empty($bufferarr3)) {
120
                                foreach ($bufferarr3 as $id=>$string) {
145
                                foreach ($bufferarr3 as $id=>$string) {
121
                                    $buffer .= $id." = ".$string."\n";
146
                                    $buffer .= $id." = ".$string."\n";
122
                                }
147
                                }
123
                            }                            }
148
                            }
124
                            if (! empty($bufferarr4)) {
149
                            if (! empty($bufferarr4)) {
125
                                foreach ($bufferarr4 as $id=>$string) {
150
                                foreach ($bufferarr4 as $id=>$string) {
126
                                    $buffer .= $id." = ".$string."\n";
151
                                    $buffer .= $id." = ".$string."\n";
127
                                }
152
                                }
128
                            }
153
                            }
Line 133... Line 158...
133
                    }
158
                    }
134
                }
159
                }
135
                break;
160
                break;
136
            default:
161
            default:
137
                $this->error->addError("switch(PSI_UPS_SNMPUPS_ACCESS)", "Bad SNMPups configuration in phpsysinfo.ini");
162
                $this->error->addError("switch(PSI_UPS_SNMPUPS_ACCESS)", "Bad SNMPups configuration in phpsysinfo.ini");
138
                break;
-
 
139
        }
163
        }
140
    }
164
    }
141
 
165
 
142
    /**
166
    /**
143
     * parse the input and store data in resultset for xml generation
167
     * parse the input and store data in resultset for xml generation
144
     *
168
     *
145
     * @return Void
169
     * @return void
146
     */
170
     */
147
    private function _info()
171
    private function _info()
148
    {
172
    {
149
        if (empty($this->_output)) {
173
        if (empty($this->_output)) {
150
            return;
174
            return;
Line 161... Line 185...
161
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.1\.1\.1\.0 = STRING:\s(.*)/m', $result, $data)) {
185
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.1\.1\.1\.0 = STRING:\s(.*)/m', $result, $data)) {
162
                $dev->setModel(trim($data[1], "\" \r\t"));
186
                $dev->setModel(trim($data[1], "\" \r\t"));
163
            }
187
            }
164
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
188
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
165
                switch (trim($data[1])) {
189
                switch (trim($data[1])) {
166
                    case 1: $status = "Unknown";
190
                case 1: $status = "Unknown"; break;
167
                            break;
-
 
168
                    case 2: $status = "On Line";
191
                case 2: $status = "On Line"; break;
169
                            break;
-
 
170
                    case 3: $status = "On Battery";
192
                case 3: $status = "On Battery"; break;
171
                            break;
-
 
172
                    case 4: $status = "On Smart Boost";
193
                case 4: $status = "On Smart Boost"; break;
173
                            break;
-
 
174
                    case 5: $status = "Timed Sleeping";
194
                case 5: $status = "Timed Sleeping"; break;
175
                            break;
-
 
176
                    case 6: $status = "Software Bypass";
195
                case 6: $status = "Software Bypass"; break;
177
                            break;
-
 
178
                    case 7: $status = "Off";
196
                case 7: $status = "Off"; break;
179
                            break;
-
 
180
                    case 8: $status = "Rebooting";
197
                case 8: $status = "Rebooting"; break;
181
                            break;
-
 
182
                    case 9: $status = "Switched Bypass";
198
                case 9: $status = "Switched Bypass"; break;
183
                            break;
-
 
184
                    case 10:$status = "Hardware Failure Bypass";
199
                case 10:$status = "Hardware Failure Bypass"; break;
185
                            break;
-
 
186
                    case 11:$status = "Sleeping Until Power Returns";
200
                case 11:$status = "Sleeping Until Power Returns"; break;
187
                            break;
-
 
188
                    case 12:$status = "On Smart Trim";
201
                case 12:$status = "On Smart Trim"; break;
189
                            break;
-
 
190
                   default: $status = "Unknown state (".trim($data[1]).")";
202
                default: $status = "Unknown state (".trim($data[1]).")";
191
                            break;
-
 
192
                }
203
                }
193
            }
204
            }
194
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
205
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
195
                $batstat = "";
206
                $batstat = "";
196
                switch (trim($data[1])) {
207
                switch (trim($data[1])) {
197
                    case 1: $batstat = "Battery Unknown";
208
                case 1: $batstat = "Battery Unknown"; break;
198
                            break;
-
 
199
                    case 2: break;
209
                case 2: break;
200
                    case 3: $batstat = "Battery Low";
210
                case 3: $batstat = "Battery Low"; break;
201
                            break;
-
 
202
                   default: $batstat = "Battery Unknown (".trim($data[1]).")";
211
                default: $batstat = "Battery Unknown (".trim($data[1]).")";
203
                            break;
-
 
204
                }
212
                }
205
                if ($batstat !== "") {
213
                if ($batstat !== "") {
206
                    if ($status !== "") {
214
                    if ($status !== "") {
207
                        $status .= ", ".$batstat;
215
                        $status .= ", ".$batstat;
208
                    } else {
216
                    } else {
Line 211... Line 219...
211
                }
219
                }
212
            }
220
            }
213
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.4\.0 = INTEGER:\s(.*)/m', $result, $data)) {
221
            if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.4\.0 = INTEGER:\s(.*)/m', $result, $data)) {
214
                $batstat = "";
222
                $batstat = "";
215
                switch (trim($data[1])) {
223
                switch (trim($data[1])) {
216
                    case 1: break;
224
                case 1: break;
217
                    case 2: $batstat = "Replace Battery";
225
                case 2: $batstat = "Replace Battery"; break;
218
                            break;
-
 
219
                   default: $batstat = "Replace Battery (".trim($data[1]).")";
226
                default: $batstat = "Replace Battery (".trim($data[1]).")";
220
                            break;
-
 
221
                }
227
                }
222
                if ($batstat !== "") {
228
                if ($batstat !== "") {
223
                    if ($status !== "") {
229
                    if ($status !== "") {
224
                        $status .= ", ".$batstat;
230
                        $status .= ", ".$batstat;
225
                    } else {
231
                    } else {
Line 275... Line 281...
275
    /**
281
    /**
276
     * get the information
282
     * get the information
277
     *
283
     *
278
     * @see PSI_Interface_UPS::build()
284
     * @see PSI_Interface_UPS::build()
279
     *
285
     *
280
     * @return Void
286
     * @return void
281
     */
287
     */
282
    public function build()
288
    public function build()
283
    {
289
    {
284
        $this->_info();
290
        $this->_info();
285
    }
291
    }