File: class.raid.inc.php

package info (click to toggle)
phpsysinfo 3.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,900 kB
  • sloc: javascript: 22,511; php: 20,651; xml: 18,293; sh: 196; python: 58; makefile: 12
file content (2553 lines) | stat: -rw-r--r-- 170,481 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
<?php
/**
 * Raid Plugin, which displays RAID status
 *
 * @category  PHP
 * @package   PSI_Plugin_Raid
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
 * @copyright 2009 phpSysInfo
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
 * @version   Release: 3.0
 * @link      http://phpsysinfo.sourceforge.net
 */
class Raid extends PSI_Plugin
{
    /**
     * variable, which holds the content of the command
     * @var array
     */
    private $_filecontent = array();

    /**
     * variable, which holds the result before the xml is generated out of this array
     * @var array
     */
    private $_result = array();

    private $prog_items = array('mdstat','dmraid','megactl','megasasctl','megaclisas-status','3ware-status','graid','zpool','storcli','perccli','idrac');

    /**
     * read the data into an internal array and also call the parent constructor
     *
     * @param String $enc encoding
     */
    public function __construct($enc)
    {
        parent::__construct(__CLASS__, $enc);

        $this->prog_items = array();
        if (defined('PSI_PLUGIN_RAID_PROGRAM') && is_string(PSI_PLUGIN_RAID_PROGRAM)) {
            if (is_string(PSI_PLUGIN_RAID_PROGRAM)) {
                if (preg_match(ARRAY_EXP, PSI_PLUGIN_RAID_PROGRAM)) {
                    $this->prog_items = eval(strtolower(PSI_PLUGIN_RAID_PROGRAM));
                } else {
                    $this->prog_items = array(strtolower(PSI_PLUGIN_RAID_PROGRAM));
                }
            } else {
                $this->global_error->addConfigError("__construct()", "[raid] PROGRAM");

                return;
            }
        }

        $notwas = true;
        switch (strtolower(PSI_PLUGIN_RAID_ACCESS)) {
        case 'command':
        case 'php-snmp':
            if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) {
                if ((PSI_OS == 'Linux') && in_array('mdstat', $this->prog_items)) {
                    CommonFunctions::rfts("/proc/mdstat", $this->_filecontent['mdstat'], 0, 4096, PSI_DEBUG);
                    $notwas = false;
                }
                if ((PSI_OS == 'Linux') && in_array('dmraid', $this->prog_items)) {
                    CommonFunctions::executeProgram("dmraid", "-s -vv 2>&1", $this->_filecontent['dmraid'], PSI_DEBUG);
                    $notwas = false;
                }
                if ((PSI_OS == 'Linux') && in_array('megactl', $this->prog_items)) {
                    CommonFunctions::executeProgram("megactl", "-vv", $this->_filecontent['megactl'], PSI_DEBUG);
                    $notwas = false;
                }
                if ((PSI_OS == 'Linux') && in_array('megasasctl', $this->prog_items)) {
                    CommonFunctions::executeProgram("megasasctl", "-vv", $this->_filecontent['megasasctl'], PSI_DEBUG);
                    $notwas = false;
                }
                if (in_array('megaclisas-status', $this->prog_items)) {
                    if (PSI_OS == 'WINNT') {
                        if (!WINNT::isAdmin()) {
                             if (CommonFunctions::_findProgram("megaclisas-status.py")) {
                                 $this->global_error->addError("RAID megaclisas-status.py error", "Program allowed for users with administrator privileges (run as administrator)");
                             } elseif (PSI_DEBUG) {
                                 $this->global_error->addError('find_program("megaclisas-status.py")', "program not found on the machine");
                             }
                        } else {
                            CommonFunctions::executeProgram("megaclisas-status.py", "", $this->_filecontent['megaclisas-status'], PSI_DEBUG);
                        }
                    } else {
                        CommonFunctions::executeProgram("megaclisas-status", "", $this->_filecontent['megaclisas-status'], PSI_DEBUG);
                    }
                    $notwas = false;
                }
                if (in_array('3ware-status', $this->prog_items)) {
                    if (PSI_OS == 'WINNT') {
                        if (!WINNT::isAdmin()) {
                             if (CommonFunctions::_findProgram("3ware-status.py")) {
                                 $this->global_error->addError("RAID 3ware-status.py error", "Program allowed for users with administrator privileges (run as administrator)");
                             } elseif (PSI_DEBUG) {
                                 $this->global_error->addError('find_program("3ware-status.py")', "program not found on the machine");
                             }
                        } else {
                            CommonFunctions::executeProgram("3ware-status.py", "", $this->_filecontent['3ware-status'], PSI_DEBUG);
                        }
                    } else {
                        CommonFunctions::executeProgram("3ware-status", "", $this->_filecontent['3ware-status'], PSI_DEBUG);
                    }
                    $notwas = false;
                }
                if ((PSI_OS == 'FreeBSD') && in_array('graid', $this->prog_items)) {
                    CommonFunctions::executeProgram("graid", "list", $this->_filecontent['graid'], PSI_DEBUG);
                    $notwas = false;
                }
                if (in_array('zpool', $this->prog_items)) {
                    CommonFunctions::executeProgram("zpool", "status", $this->_filecontent['zpool'], PSI_DEBUG);
                    $notwas = false;
                }
                if (in_array('storcli', $this->prog_items)) {
                    if ((PSI_OS == 'WINNT') && !WINNT::isAdmin() && (CommonFunctions::_findProgram("storcli64") || CommonFunctions::_findProgram("storcli"))) {
                      $this->global_error->addError("RAID storcli error", "Program allowed for users with administrator privileges (run as administrator)");
                    }
                    $call = "";
                    $vall = "";
                    $raidcmd = "";
                    if (!(CommonFunctions::_findProgram("storcli64") && CommonFunctions::executeProgram($raidcmd = "storcli64", "/call show all", $call, PSI_DEBUG))) {
                        if (!CommonFunctions::executeProgram($raidcmd = "storcli", "/call show all", $call, PSI_DEBUG)) {
                            $raidcmd = "";
                        }
                    }
                    if ($raidcmd !== "") {
                        CommonFunctions::executeProgram($raidcmd, "/call /vall show all", $vall, PSI_DEBUG);
                    }
                    $this->_filecontent['storcli'] = $call.$vall;
                    $notwas = false;
                }
                if (in_array('perccli', $this->prog_items)) {
                    if ((PSI_OS == 'WINNT') && !WINNT::isAdmin() && (CommonFunctions::_findProgram("perccli64") || CommonFunctions::_findProgram("perccli"))) {
                      $this->global_error->addError("RAID perccli error", "Program allowed for users with administrator privileges (run as administrator)");
                    }
                    $call = "";
                    $vall = "";
                    $raidcmd = "";
                    if (!(CommonFunctions::_findProgram("perccli64") && CommonFunctions::executeProgram($raidcmd = "perccli64", "/call show all", $call, PSI_DEBUG))) {
                        if (!CommonFunctions::executeProgram($raidcmd = "perccli", "/call show all", $call, PSI_DEBUG)) {
                            $raidcmd = "";
                        }
                    }
                    if ($raidcmd !== "") {
                        CommonFunctions::executeProgram($raidcmd, "/call /vall show all", $vall, PSI_DEBUG);
                    }
                    $this->_filecontent['perccli'] = $call.$vall;
                    $notwas = false;
                }
            }
            if (in_array('idrac', $this->prog_items)) {
                if (defined('PSI_PLUGIN_RAID_IDRAC_DEVICES') && is_string(PSI_PLUGIN_RAID_IDRAC_DEVICES)) {
                    if (preg_match(ARRAY_EXP, PSI_PLUGIN_RAID_IDRAC_DEVICES)) {
                        $devices = eval(PSI_PLUGIN_RAID_IDRAC_DEVICES);
                    } else {
                        $devices = array(PSI_PLUGIN_RAID_IDRAC_DEVICES);
                    }
                    if (strtolower(PSI_PLUGIN_RAID_ACCESS)=="command") {
                        foreach ($devices as $device) {
                            CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$device." .1.3.6.1.4.1.674.10892.5.5.1.20", $buffer, PSI_DEBUG);
                            if (strlen($buffer) > 0) {
                                $this->_filecontent['idrac'][$device] = $buffer;
                            }
                        }
                    } else {
                        snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
                        snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
                        foreach ($devices as $device) {
                            if (! PSI_DEBUG) {
                                restore_error_handler(); /* default error handler */
                                $old_err_rep = error_reporting();
                                error_reporting(E_ERROR); /* fatal errors only */
                            }
                            $bufferarr=snmprealwalk($device, "public", ".1.3.6.1.4.1.674.10892.5.5.1.20", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
                            if (! PSI_DEBUG) {
                                error_reporting($old_err_rep); /* restore error level */
                                set_error_handler('errorHandlerPsi'); /* restore error handler */
                            }
                            if (! empty($bufferarr)) {
                                $buffer="";
                                foreach ($bufferarr as $id=>$string) {
                                    $buffer .= $id." = ".$string."\n";
                                }
                                if (strlen($buffer) > 0) {
                                    $this->_filecontent['idrac'][$device] = $buffer;
                                }
                            }
                        }
                    }
                }

                $notwas = false;
            }
            if ($notwas) {
                $this->global_error->addConfigError("__construct()", "[raid] PROGRAM");
            }
            break;
        case 'data':
            if (!defined('PSI_EMU_HOSTNAME')) foreach ($this->prog_items as $item) {
                if (in_array($item, $this->prog_items)) {
                    if ($item !== 'idrac') {
                        CommonFunctions::rftsdata("raid".$item.".tmp", $this->_filecontent[$item], 0, 4096, false);
                    } elseif (defined('PSI_PLUGIN_RAID_IDRAC_DEVICES') && is_string(PSI_PLUGIN_RAID_IDRAC_DEVICES)) {
                        if (preg_match(ARRAY_EXP, PSI_PLUGIN_RAID_IDRAC_DEVICES)) {
                            $devices = eval(PSI_PLUGIN_RAID_IDRAC_DEVICES);
                        } else {
                            $devices = array(PSI_PLUGIN_RAID_IDRAC_DEVICES);
                        }
                        $pn=0;
                        foreach ($devices as $device) {
                            $buffer="";
                            if (CommonFunctions::rftsdata("raid".$item.$pn.".tmp", $buffer) && !empty($buffer)) {
                                $this->_filecontent['idrac'][$device] = $buffer;
                            }
                            $pn++;
                        }
                    }
                    $notwas = false;
                }
            }
            if ($notwas) {
                $this->global_error->addConfigError("__construct()", "[raid] PROGRAM");
            }
            break;
        default:
            $this->global_error->addConfigError("__construct()", "[raid] ACCESS");
        }
    }

    private function execute_mdstat($buffer)
    {
        $raiddata = preg_split("/\r?\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
        if (!empty($raiddata)) {
            // get the supported types
            $supported = '';
            if (preg_match('/^[a-zA-Z]+ :( \[[a-z0-9]+\])+/', $raiddata[0], $res)) {
                $parts = preg_split("/ : /", $res[0]);
                if (isset($parts[1]) && (trim($parts[1]) !== '')) {
                    $supported = preg_replace('/[\[\]]/', '', trim($parts[1]));
                }
            }
            // get disks
            if (preg_match("/^read_ahead/", $raiddata[1])) {
                $count = 2;
            } else {
                $count = 1;
            }
            $cnt_filecontent = count($raiddata);
            do {
                $parts = preg_split("/ : /", $raiddata[$count]);
                $dev = trim($parts[0]);
                if (count($parts) == 2) {
                    if ($supported !== '') $this->_result['mdstat'][$dev]['supported'] = $supported;
                    $this->_result['mdstat'][$dev]['items'][0]['raid_index'] = -1; //must by first
                    $details = preg_split('/ /', $parts[1]);
                    if (!strstr($details[0], 'inactive')) {
                        if (isset($details[2]) && strstr($details[1], '(auto-read-only)')) {
                            $this->_result['mdstat'][$dev]['level'] = $details[2];
                            $this->_result['mdstat'][$dev]['status'] = $details[0]." ".$details[1];
                            //$this->_result['mdstat'][$dev]['items'][0]['name'] = $dev." ".$details[2];
                            $this->_result['mdstat'][$dev]['items'][0]['name'] = $details[2];
                            $this->_result['mdstat'][$dev]['items'][0]['status'] = "W";
                            $i = 3;
                        } else {
                            $this->_result['mdstat'][$dev]['level'] = $details[1];
                            $this->_result['mdstat'][$dev]['status'] = $details[0];
                            //$this->_result['mdstat'][$dev]['items'][0]['name'] = $dev." ".$details[1];
                            $this->_result['mdstat'][$dev]['items'][0]['name'] = $details[1];
                            $this->_result['mdstat'][$dev]['items'][0]['status'] = "ok";
                            $i = 2;
                        }
                    } else {
                        $this->_result['mdstat'][$dev]['level'] = "none";
                        $this->_result['mdstat'][$dev]['status'] = $details[0];
                        $this->_result['mdstat'][$dev]['items'][0]['name'] = $dev;
                        $this->_result['mdstat'][$dev]['items'][0]['status'] = "F";
                        $i = 1;
                    }
                    $this->_result['mdstat'][$dev]['items'][0]['parentid'] = 0;

                    for ($cnt_details = count($details); $i < $cnt_details; $i++) {
                        preg_match('/(([a-z0-9])+)(\[([0-9]+)\])(\([SF ]\))?/', trim($details[$i]), $partition);
                        if (count($partition) == 5 || count($partition) == 6) {
                            $this->_result['mdstat'][$dev]['items'][$partition[1]]['raid_index'] = intval(substr(trim($partition[3]), 1, -1));
                            if (isset($partition[5])) {
                                $search = array("(", ")");
                                $replace = array("", "");
                                $dstat = str_replace($search, $replace, trim($partition[5]));
                                $this->_result['mdstat'][$dev]['items'][$partition[1]]['status'] = $dstat;
                                if (($dstat === "F") && ($this->_result['mdstat'][$dev]['items'][0]['status'] === "ok")) $this->_result['mdstat'][$dev]['items'][0]['status'] = "W";
                            } else {
                                $this->_result['mdstat'][$dev]['items'][$partition[1]]['status'] = "ok";
                            }
                            $this->_result['mdstat'][$dev]['items'][$partition[1]]['name'] = $partition[1];
                            $this->_result['mdstat'][$dev]['items'][$partition[1]]['parentid'] = 1;
                            $this->_result['mdstat'][$dev]['items'][$partition[1]]['type'] = "disk";
                        }
                    }
                    $optionline = $raiddata[$count].$raiddata[$count+1];
                    $count++;
                    if (preg_match('/(\d+)k chunk/', $optionline, $chunksize)) {
                        $this->_result['mdstat'][$dev]['chunk_size'] = $chunksize[1];
                    }
                    if ($pos = strpos($optionline, "super non-persistent")) {
                        $this->_result['mdstat'][$dev]['pers_superblock'] = 0;
                    } else {
                        $this->_result['mdstat'][$dev]['pers_superblock'] = 1;
                    }
                    if ($pos = strpos($optionline, "algorithm")) {
                        $this->_result['mdstat'][$dev]['algorithm'] = trim(substr($optionline, $pos + 9, 2));
                    }
                    if (preg_match('/\[([0-9]+)\/([0-9]+)\]/', $optionline, $res)) {
                        $this->_result['mdstat'][$dev]['registered'] = $res[1];
                        $this->_result['mdstat'][$dev]['active'] = $res[2];
                    }

                    if (isset($this->_result['mdstat'][$dev]['items'])) {
                        asort($this->_result['mdstat'][$dev]['items']);
                    }
                    if ((!isset($this->_result['mdstat'][$dev]['registered']) || ($this->_result['mdstat'][$dev]['registered']<24)) && preg_match('/\[([_U]+)\]/', $optionline, $res) && (($reslen=strlen($res[1])) > 0)) {
                        $notsparecount = 0;
                        foreach ($this->_result['mdstat'][$dev]['items'] as $diskkey=>$disk) {
                            if (($diskkey!==0) && ($this->_result['mdstat'][$dev]['items'][$diskkey]['status']!=="S")) {
                                $notsparecount++;
                            }
                        }
                        if ($notsparecount == $reslen) {
                            $partnr = 0;
                            foreach ($this->_result['mdstat'][$dev]['items'] as $diskkey=>$disk) {
                                if (($diskkey!==0) && ($this->_result['mdstat'][$dev]['items'][$diskkey]['status']!=="S")) {
                                    if (($res[1][$partnr]=='_') && ($this->_result['mdstat'][$dev]['items'][$diskkey]['status']=="ok")) {
                                        $this->_result['mdstat'][$dev]['items'][$diskkey]['status']="W";
                                        if ($this->_result['mdstat'][$dev]['items'][0]['status'] === "ok") $this->_result['mdstat'][$dev]['items'][0]['status'] = "W";
                                    }
                                    $partnr++;
                                }
                            }
                        } elseif ($reslen-$notsparecount == 1) {
                            $partnr = 0;
                            foreach ($this->_result['mdstat'][$dev]['items'] as $diskkey=>$disk) {
                                if (($diskkey!==0) && ($this->_result['mdstat'][$dev]['items'][$diskkey]['status']!=="S")) {
                                    if ($res[1][$partnr]=='_') {
                                        $this->_result['mdstat'][$dev]['items']['none']['raid_index']=$this->_result['mdstat'][$dev]['items'][$diskkey]['raid_index']-1;
                                        $this->_result['mdstat'][$dev]['items']['none']['status']="E";
                                        $this->_result['mdstat'][$dev]['items']['none']['name']="none";
                                        $this->_result['mdstat'][$dev]['items']['none']['parentid'] = 1;
                                        $this->_result['mdstat'][$dev]['items']['none']['type'] = "disk";
                                    }
                                    $partnr++;
                                }
                            }
                            if ($res[1][$partnr]=='_') {
                                $this->_result['mdstat'][$dev]['items']['none']['raid_index']=$this->_result['mdstat'][$dev]['items'][$diskkey]['raid_index']+1;
                                $this->_result['mdstat'][$dev]['items']['none']['status']="E";
                                $this->_result['mdstat'][$dev]['items']['none']['name']="none";
                                $this->_result['mdstat'][$dev]['items']['none']['parentid'] = 1;
                                $this->_result['mdstat'][$dev]['items']['none']['type']="disk";
                                if ($this->_result['mdstat'][$dev]['items'][0]['status'] === "ok") $this->_result['mdstat'][$dev]['items'][0]['status'] = "W";
                            }
                            asort($this->_result['mdstat'][$dev]['items']);
                            foreach ($this->_result['mdstat'][$dev]['items'] as $diskkey=>$disk) {
                                if ($diskkey=="none") {
                                    $this->_result['mdstat'][$dev]['items'][$diskkey]['raid_index']="unknown";
                                }
                            }
                        } else {
                            foreach ($this->_result['mdstat'][$dev]['items'] as $diskkey=>$disk) {
                                if ($this->_result['mdstat'][$dev]['items'][$diskkey]['status']=="ok") {
                                    $this->_result['mdstat'][$dev]['items'][$diskkey]['status']="W";
                                }
                            }
                            for ($partnr=0; $partnr<$reslen-$notsparecount; $partnr++) {
                                    $this->_result['mdstat'][$dev]['items']['none'.$partnr]['raid_index']="unknown";
                                    $this->_result['mdstat'][$dev]['items']['none'.$partnr]['status']="E";
                                    $this->_result['mdstat'][$dev]['items']['none'.$partnr]['name'] = "none".$partnr;
                                    $this->_result['mdstat'][$dev]['items']['none'.$partnr]['parentid'] = 1;
                                    $this->_result['mdstat'][$dev]['items']['none'.$partnr]['type'] = "disk";
                            }
                        }
                    }
                    if (preg_match(('/([a-z]+)( *)=( *)([0-9\.]+)%/'), $raiddata[$count + 1], $res) || (preg_match(('/([a-z]+)( *)=( *)([0-9\.]+)/'), $optionline, $res))) {
                        list($this->_result['mdstat'][$dev]['action']['name'], $this->_result['mdstat'][$dev]['action']['percent']) = preg_split("/=/", str_replace("%", "", $res[0]));
                        if (preg_match(('/([a-z]*=[0-9\.]+[a-z]+)/'), $raiddata[$count + 1], $res)) {
                            $time = preg_split("/=/", $res[0]);
                            list($this->_result['mdstat'][$dev]['action']['finish_time'], $this->_result['mdstat'][$dev]['action']['finish_unit']) = sscanf($time[1], '%f%s');
                        }
                    } elseif (preg_match(('/^( *)([a-z]+)( *)=( *)([A-Z]+)$/'), $raiddata[$count + 1], $res)) {
                       $this->_result['mdstat'][$dev]['status'] .= " ".trim($raiddata[$count + 1]);
                    }
                } else {
                    $count++;
                }
            } while ($cnt_filecontent > $count);
            $lastline = $raiddata[$cnt_filecontent - 1];
            if (strpos($lastline, "unused devices") !== false) {
                $parts = preg_split("/:/", $lastline);
                $unused = trim($parts[1]);
                if ($unused !== "<none>") {
                    $details = preg_split('/ /', $parts[1], -1, PREG_SPLIT_NO_EMPTY);
                    $this->_result['mdstat']['spare']['status'] = "spare";
                    $this->_result['mdstat']['spare']['items'][0]['name'] = "spare";
                    $this->_result['mdstat']['spare']['items'][0]['parentid'] = 0;
                    $this->_result['mdstat']['spare']['items'][0]['status'] = "S";
                    foreach ($details as $id=>$disk) {
                        $this->_result['mdstat']['spare']['items'][$id+1]['name'] = $disk;
                        $this->_result['mdstat']['spare']['items'][$id+1]['parentid'] = 1;
                        $this->_result['mdstat']['spare']['items'][$id+1]['status'] = "S";
                        $this->_result['mdstat']['spare']['items'][$id+1]['type'] = "disk";
                    }
                }
            }
        }
    }

    private function execute_dmraid($buffer)
    {
        $raiddata = preg_split("/(\r?\n\*\*\* )|(\r?\n--> )/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
        if (!empty($raiddata)) {
            $group = "";
            foreach ($raiddata as $block) {
                if (preg_match('/^(NOTICE: )|(ERROR: )/m', $block)) {
                    $group = "";
                    $lines = preg_split("/\r?\n/", $block, -1, PREG_SPLIT_NO_EMPTY);
                    foreach ($lines as $line) {
                        if (preg_match('/^NOTICE: added\s+\/dev\/(.+)\s+to RAID set\s+\"(.+)\"/', $line, $partition)) {
                            if (!isset($this->_result['dmraid'][$partition[2]]['items'][0]['parentid'])) {
                                $this->_result['dmraid'][$partition[2]]['items'][0]['parentid'] = 0;
                                $this->_result['dmraid'][$partition[2]]['items'][0]['name'] = $partition[2];
                            }
                            $this->_result['dmraid'][$partition[2]]['items'][$partition[1]]['status'] = "ok";
                            $this->_result['dmraid'][$partition[2]]['items'][$partition[1]]['type'] = "disk";
                            $this->_result['dmraid'][$partition[2]]['items'][$partition[1]]['parentid'] = 1;
                            $this->_result['dmraid'][$partition[2]]['items'][$partition[1]]['name'] = $partition[1];
                            $this->_result['dmraid'][$partition[2]]['status'] = "ok";
                            $this->_result['dmraid'][$partition[2]]['level'] = "unknown";
                        } elseif (preg_match('/^ERROR: .* device\s+\/dev\/(.+)\s+(.+)\s+in RAID set\s+\"(.+)\"/', $line, $partition)) {
                            if (!isset($this->_result['dmraid'][$partition[3]]['items'][0]['parentid'])) {
                                $this->_result['dmraid'][$partition[3]]['items'][0]['parentid'] = 0;
                                $this->_result['dmraid'][$partition[3]]['items'][0]['name'] = $partition[3];
                            }
                            $this->_result['dmraid'][$partition[3]]['level'] = "unknown";
                            $this->_result['dmraid'][$partition[3]]['items'][$partition[1]]['type'] = "disk";
                            $this->_result['dmraid'][$partition[3]]['items'][$partition[1]]['parentid'] = 1;
                            if ($partition[2]=="broken") {
                                $this->_result['dmraid'][$partition[3]]['items'][$partition[1]]['status'] = "F";
                                $this->_result['dmraid'][$partition[3]]['status'] = "F";
                            } else {
                                $this->_result['dmraid'][$partition[3]]['items'][$partition[1]]['status'] = "W";
                                $this->_result['dmraid'][$partition[3]]['status'] = "W";
                            }
                            $this->_result['dmraid'][$partition[3]]['items'][$partition[1]]['name'] = $partition[1];
                        }
                    }
                } else {
                    if (preg_match('/^Group superset\s+(.+)/m', $block, $arrname)) {
                        $group = trim($arrname[1]);
                    }
                    if (preg_match('/^name\s*:\s*(.*)/m', $block, $arrname)) {
                        if ($group=="") {
                            $group = trim($arrname[1]);
                        }
                        $this->_result['dmraid'][$group]['name'] = trim($arrname[1]);

                        $this->_result['dmraid'][$group]['items'][0]['name'] = trim($arrname[1]);

                        if (preg_match('/^size\s*:\s*(.*)/m', $block, $capacity)) {
                            $this->_result['dmraid'][$group]['capacity'] = trim($capacity[1]);
                        }
                        if (preg_match('/^stride\s*:\s*(.*)/m', $block, $stride)) {
                                $this->_result['dmraid'][$group]['stride'] = trim($stride[1]);
                        }
                        if (preg_match('/^type\s*:\s*(.*)/m', $block, $type)) {
                            $this->_result['dmraid'][$group]['level'] = trim($type[1]);
                            //$this->_result['dmraid'][$group]['items'][0]['name'] .= " ".trim($type[1]);
                            $this->_result['dmraid'][$group]['items'][0]['name'] = trim($type[1]);
                        }
                        if (preg_match('/^status\s*:\s*(.*)/m', $block, $status)) {
                            $this->_result['dmraid'][$group]['status'] = trim($status[1]);
                            switch (trim($status[1])) {
                            case "broken":
                                $this->_result['dmraid'][$group]['items'][0]['status'] = "F";
                                break;
                            case "inconsistent":
                                $this->_result['dmraid'][$group]['items'][0]['status'] = "W";
                                break;
                            default:
                                $this->_result['dmraid'][$group]['items'][0]['status'] = trim($status[1]);
                            }
                        }
                        if (preg_match('/^subsets\s*:\s*(.*)/m', $block, $subsets)) {
                            $this->_result['dmraid'][$group]['subsets'] = trim($subsets[1]);
                        }
                        if (preg_match('/^devs\s*:\s*(.*)/m', $block, $devs)) {
                            $this->_result['dmraid'][$group]['devs'] = trim($devs[1]);
                        }
                        if (preg_match('/^spares\s*:\s*(.*)/m', $block, $spares)) {
                                $this->_result['dmraid'][$group]['spares'] = trim($spares[1]);
                        }

                        if (!isset($this->_result['dmraid'][$group]['items'][0]['parentid'])) {
                            $this->_result['dmraid'][$group]['items'][0]['parentid'] = 0;
                        }

                        $group = "";
                    }
                }
            }
            if (isset($this->_result['dmraid'])) {
                foreach ($this->_result['dmraid'] as $gid=>$group) {
                    $id = 1;
                    if (isset($group['devs']) && ($group['devs']>0) &&
                       (!isset($group['items']) || (count($group['items'])<$group['devs'])) &&
                       isset($group['subsets']) && ($group['subsets']>0)) for ($i = 0; $i < $group['subsets']; $i++) {
                        if (isset($this->_result['dmraid'][$gid."-".$i]['items'][0]['parentid'])) {
                            foreach ($this->_result['dmraid'][$gid."-".$i]['items'] as $fid=>$from) {
                                if ($fid===0) {
                                    $this->_result['dmraid'][$gid]['items'][$gid."-".$i]['parentid'] = 1;
                                    $this->_result['dmraid'][$gid]['items'][$gid."-".$i]['status'] = $from['status'];
                                    $this->_result['dmraid'][$gid]['items'][$gid."-".$i]['name'] = $gid."-".$i." ".$from['name'];
                                    if (isset($from['type'])) $this->_result['dmraid'][$gid]['items'][$gid."-".$i]['type'] = $from['type'];
                                } else {
                                    $this->_result['dmraid'][$gid]['items'][$from['name']]['parentid'] = 1+$id;
                                    $this->_result['dmraid'][$gid]['items'][$from['name']]['status'] = $from['status'];
                                    $this->_result['dmraid'][$gid]['items'][$from['name']]['name'] = $from['name'];
                                    if (isset($from['type'])) $this->_result['dmraid'][$gid]['items'][$from['name']]['type'] = $from['type'];
                                }
                            }
                            $id+=count($this->_result['dmraid'][$gid."-".$i]['items']);
                            unset($this->_result['dmraid'][$gid."-".$i]);
                        } else {
                            $this->_result['dmraid'][$gid]['items'][$gid."-".$i]['parentid'] = 1;
                            $this->_result['dmraid'][$gid]['items'][$gid."-".$i]['status'] = "unknown";
                            $this->_result['dmraid'][$gid]['items'][$gid."-".$i]['name'] = $gid."-".$i;
                            $id++;
                        }
                    }
                }
                foreach ($this->_result['dmraid'] as $gid=>$group) {
                    if (($group['name'] !== $gid) && isset($group['items'][0]['parentid'])) {
                        $this->_result['dmraid'][$gid]['items'][0]['name'] = $group['name']." ".$group['items'][0]['name'];
                    }
                }
            }
        }
    }

    private function execute_megactl($buffer, $sas = false)
    {
        if ($sas === true) {
            $prog = "megasasctl";
        } else {
            $prog = "megactl";
        }
        $raiddata = preg_split("/(\r?\n)+(?=[a-z]\d+ )/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
        if (!empty($raiddata)) foreach ($raiddata as $raidgroup) {
            if (preg_match("/^([a-z]\d+) /", $raidgroup, $buff)) {
                if (preg_match("/^[a-z]\d+ ([^:\r\n]+) [^:\r\n]+:/", $raidgroup, $geom) || preg_match("/^[a-z]\d+ ([^:\r\n]+)/", $raidgroup, $geom)) {
                    $controller = trim($geom[1]);
                } else {
                    $controller = '';
                }
                if (preg_match("/^[a-z]\d+ .+ batt:([^:\r\n,]+)/", $raidgroup, $batt)) {
                    if (preg_match("/^([^\/]+)\/((\d+)mV\/(-?\d+)C)$/", trim($batt[1]), $battarr) && ($battarr !== "0mV/0C")) {
                        $battery = trim($battarr[1]);
                        $battvolt = $battarr[3]/1000;
                        $batttemp = $battarr[4];
                    } else {
                        $battery = trim($batt[1]);
                        $battvolt = '';
                        $batttemp = '';
                    }
                } else {
                    $battery = '';
                    $battvolt = '';
                    $batttemp = '';
                }
                if (preg_match("/^[a-z]\d+ .+ mem:(\d+)MiB/", $raidgroup, $batt)) {
                    $cache_size = $batt[1]*1024*1024;
                } else {
                    $cache_size = '';
                }
                $group = $buff[1];
                $lines = preg_split("/\r?\n/", $raidgroup, -1, PREG_SPLIT_NO_EMPTY);
                if (!empty($lines)) {
                    unset($lines[0]);
                    foreach ($lines as $line) {
                        $details = preg_split('/ /', preg_replace('/^hot spares +:/', 'hotspare:', preg_replace('/errs:.+$/','',$line)), -1, PREG_SPLIT_NO_EMPTY);
                        if (($countdet = count($details)) >= 2) {
                            $size[0] = -1;
                            for ($ind = $countdet; $ind > 1;) {
                               if (preg_match('/(\d+)((B)|(KiB)|(MiB)|(GiB)|(TiB)|(PiB))/', $details[--$ind], $size)) { //Find size
                                    $size[0] = $ind;
                                    break;
                                } else {
                                   $size[0] = -1;
                                }
                            }
                            $model = '';
                            $serial = '';
                            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && ($size[0] >= 2)) {
                                for ($ind = 1; $ind < $size[0]; $ind++) {
                                    if (preg_match('/:/', $details[$ind])) {
                                        break;
                                    }
                                    $model .= " ".$details[$ind];
                                }
                                $model = trim($model);
                                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                                    for (; $ind < $size[0]; $ind++) {
                                        if (preg_match('/^s\/n:(.+)$/', $details[$ind], $ser)) {
                                            $serial = $ser[1];
                                            break;
                                        }
                                    }
                                }
                            }
                            if (($countdet == 6) && ($details[2] === "RAID") && ($size[0] == 1)) {
                                switch ($size[2]) {
                                case 'B':
                                    $this->_result[$prog][$details[0]]['capacity'] = $size[1];
                                    break;
                                case 'KiB':
                                    $this->_result[$prog][$details[0]]['capacity'] = 1024*$size[1];
                                    break;
                                case 'MiB':
                                    $this->_result[$prog][$details[0]]['capacity'] = 1024*1024*$size[1];
                                    break;
                                case 'GiB':
                                    $this->_result[$prog][$details[0]]['capacity'] = 1024*1024*1024*$size[1];
                                    break;
                                case 'TiB':
                                    $this->_result[$prog][$details[0]]['capacity'] = 1024*1024*1024*1024*$size[1];
                                    break;
                                case 'PiB':
                                    $this->_result[$prog][$details[0]]['capacity'] = 1024*1024*1024*1024*1024*$size[1];
                                }
                                $this->_result[$prog][$details[0]]['level'] = "RAID".$details[3]." ".$details[4];
                                $this->_result[$prog][$details[0]]['status'] = $details[5];
                                if ($controller !== '') $this->_result[$prog][$details[0]]['controller'] = $controller;
                                if ($battery !== '') $this->_result[$prog][$details[0]]['battery'] = $battery;
                                if ($battvolt !== '') $this->_result[$prog][$details[0]]['battvolt'] = $battvolt;
                                if ($batttemp !== '') $this->_result[$prog][$details[0]]['batttemp'] = $batttemp;
                                if ($cache_size !== '') $this->_result[$prog][$details[0]]['cache_size'] = $cache_size;
                                $this->_result[$prog][$details[0]]['items'][$details[0]]['parentid'] = 0;
                                $this->_result[$prog][$details[0]]['items'][$details[0]]['name'] = "RAID".$details[3]." ".$details[4];
                                if ($details[5] !== 'optimal') {
                                    $this->_result[$prog][$details[0]]['items'][$details[0]]['info'] = $details[5];
                                }
                                switch ($details[5]) {
                                case 'optimal':
                                    $this->_result[$prog][$details[0]]['items'][$details[0]]['status'] = "ok";
                                    break;
                                case 'OFFLINE':
                                    $this->_result[$prog][$details[0]]['items'][$details[0]]['status'] = "F";
                                    break;
                                default:
                                    $this->_result[$prog][$details[0]]['items'][$details[0]]['status'] = "W";
                                }
                            } elseif (($countdet >= 2) && (($details[0]==='unconfigured:') || ($details[0]==='hotspare:'))) {
                                $itemn0 = rtrim($details[0], ':');
                                $itemn = $group .'-'.$itemn0;
                                $this->_result[$prog][$itemn]['status'] = $itemn0;
                                if ($controller !== '') $this->_result[$prog][$itemn]['controller'] = $controller;
                                if ($battery !== '') $this->_result[$prog][$itemn]['battery'] = $battery;
                                if ($battvolt !== '') $this->_result[$prog][$itemn]['battvolt'] = $battvolt;
                                if ($batttemp !== '') $this->_result[$prog][$itemn]['batttemp'] = $batttemp;
                                if ($cache_size !== '') $this->_result[$prog][$itemn]['cache_size'] = $cache_size;
                                $this->_result[$prog][$itemn]['items'][$itemn]['parentid'] = 0;
                                $this->_result[$prog][$itemn]['items'][$itemn]['name'] = $itemn0;
                                if ($details[0]==='unconfigured:') {
                                    $this->_result[$prog][$itemn]['items'][$itemn]['status'] = "U";
                                } else {
                                    $this->_result[$prog][$itemn]['items'][$itemn]['status'] = "S";
                                }
                            } elseif (($countdet >= 4) && ($size[0] >= 1) && ($countdet - $size[0] == 3)) {
                                if (isset($this->_result[$prog][$details[$countdet-2]])) {
                                    $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['parentid'] = 1;
                                    $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['type'] = "disk";
                                    $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['name'] = $details[0];
                                    if ($details[$countdet-1] !== 'online') {
                                        $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['info'] = $details[$countdet-1];
                                    }
                                    switch ($details[$countdet-1]) {
                                    case 'online':
                                        $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['status'] = "ok";
                                        break;
                                    case 'hotspare':
                                        $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['status'] = "S";
                                        break;
                                    case 'rdy/fail':
                                        $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['status'] = "F";
                                        break;
                                    default:
                                        $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['status'] = "W";
                                    }
                                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                                        switch ($size[2]) {
                                        case 'B':
                                            $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['capacity'] = $size[1];
                                            break;
                                        case 'KiB':
                                            $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['capacity'] = 1024*$size[1];
                                            break;
                                        case 'MiB':
                                            $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['capacity'] = 1024*1024*$size[1];
                                            break;
                                        case 'GiB':
                                            $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['capacity'] = 1024*1024*1024*$size[1];
                                            break;
                                        case 'TiB':
                                            $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['capacity'] = 1024*1024*1024*1024*$size[1];
                                            break;
                                        case 'PiB':
                                            $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['capacity'] = 1024*1024*1024*1024*1024*$size[1];
                                        }
                                        if ($model !== '') $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['model'] = $model;
                                        if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                                            if ($serial !== '') $this->_result[$prog][$details[$countdet-2]]['items'][$details[0]]['serial'] = $serial;
                                        }
                                    }
                                }
                            } elseif (($countdet >= 3) && ($size[0] >= 1) && ($countdet - $size[0] == 2)) {
                                $itemn = '';
                                switch ($details[$countdet-1]) {
                                case 'BAD':
                                case 'ready':
                                    $itemn = $group .'-unconfigured';
                                    break;
                                case 'hotspare':
                                    $itemn = $group .'-hotspare';
                                }
                                if (($itemn !== '') && isset($this->_result[$prog][$itemn])) {
                                    $this->_result[$prog][$itemn]['items'][$details[0]]['parentid'] = 1;
                                    $this->_result[$prog][$itemn]['items'][$details[0]]['type'] = "disk";
                                    $this->_result[$prog][$itemn]['items'][$details[0]]['name'] = $details[0];
                                    $this->_result[$prog][$itemn]['items'][$details[0]]['info'] = $details[$countdet-1];
                                    switch ($details[$countdet-1]) {
                                    case 'ready':
                                        $this->_result[$prog][$itemn]['items'][$details[0]]['status'] = "U";
                                        break;
                                    case 'hotspare':
                                        $this->_result[$prog][$itemn]['items'][$details[0]]['status'] = "S";
                                        break;
                                    default:
                                        $this->_result[$prog][$itemn]['items'][$details[0]]['status'] = "F";
                                    }
                                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                                        switch ($size[2]) {
                                        case 'B':
                                            $this->_result[$prog][$itemn]['items'][$details[0]]['capacity'] = $size[1];
                                            break;
                                        case 'KiB':
                                            $this->_result[$prog][$itemn]['items'][$details[0]]['capacity'] = 1024*$size[1];
                                            break;
                                        case 'MiB':
                                            $this->_result[$prog][$itemn]['items'][$details[0]]['capacity'] = 1024*1024*$size[1];
                                            break;
                                        case 'GiB':
                                            $this->_result[$prog][$itemn]['items'][$details[0]]['capacity'] = 1024*1024*1024*$size[1];
                                            break;
                                        case 'TiB':
                                            $this->_result[$prog][$itemn]['items'][$details[0]]['capacity'] = 1024*1024*1024*1024*$size[1];
                                            break;
                                        case 'PiB':
                                            $this->_result[$prog][$itemn]['items'][$details[0]]['capacity'] = 1024*1024*1024*1024*1024*$size[1];
                                        }
                                        if ($model !== '') $this->_result[$prog][$itemn]['items'][$details[0]]['model'] = $model;
                                        if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                                            if ($serial !== '') $this->_result[$prog][$itemn]['items'][$details[0]]['serial'] = $serial;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private function execute_status($buffer, $_3ware = false)
    {
        $carr=array();
        if ($_3ware === true) {
            $prog = "3ware-status";
            $split = "/\t/";
        } else {
            $prog = "megaclisas-status";
            $split = "/[\s]?\|[\s]?/";
        }
        $buffLines = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
        foreach ($buffLines as $buffLine) {
            if (preg_match("/^(c\d+)[ |]/", $buffLine, $cbuff)) {
                $cname = $cbuff[1];
                $buffArgs = preg_split("/[\s]?\|[\s]?/", $buffLine, -1, PREG_SPLIT_NO_EMPTY);
                if ((($countargs = count($buffArgs)) == 2) || ($countargs == 5) || ($countargs == 6)) {
                    $carr[$cname]['controller'] = trim($buffArgs[1]);
                    if ($countargs == 6) {
                        $carr[$cname]['battery'] = trim($buffArgs[4]);
                    }
                    if ($countargs > 2) {
                        $carr[$cname]['cache_size'] = trim($buffArgs[2]);
                        if (preg_match("/^FW:\s+(\S+)$/", trim($buffArgs[$countargs - 1]), $pregout)) {
                            $carr[$cname]['firmware'] = $pregout[1];
                        } else {
                            $carr[$cname]['firmware'] = trim($buffArgs[$countargs -1]);
                        }
                        if (preg_match("/^(\d+)C$/", trim($buffArgs[3]), $pregout)) {
                            $carr[$cname]['temperature'] = $pregout[1];
                        }
                        $unit = preg_replace("/^[\d\s]+/", "", trim($buffArgs[2]));
                        $value = preg_replace("/[\D\s]+$/", "", trim($buffArgs[2]));
                        switch ($unit) {
                        case 'B':
                            $carr[$cname]['cache_size'] = $value;
                            break;
                        case 'KB':
                            $carr[$cname]['cache_size'] = 1024*$value;
                            break;
                        case 'MB':
                            $carr[$cname]['cache_size'] = 1024*1024*$value;
                            break;
                        case 'Gb':
                        case 'GB':
                            $carr[$cname]['cache_size'] = 1024*1024*1024*$value;
                            break;
                        case 'TB':
                            $carr[$cname]['cache_size'] = 1024*1024*1024*1024*$value;
                            break;
                        case 'PB':
                            $carr[$cname]['cache_size'] = 1024*1024*1024*1024*1024*$value;
                        }
                    }
                } elseif ($countargs == 3) {
                    $carr[$cname]['controller'] = trim($buffArgs[1]);
                    if (preg_match("/^FW:\s+(\S+)$/", trim($buffArgs[2]), $pregout)) {
                        $carr[$cname]['firmware'] = $pregout[1];
                    } else {
                        $carr[$cname]['firmware'] = trim($buffArgs[2]);
                    }
                }
            } elseif (preg_match("/^((c\d+)u\d+)[\t |]/", $buffLine, $ubuff)) {
                $uname = $ubuff[1];
                $cname = $ubuff[2];
                $buffArgs = preg_split($split, $buffLine, -1, PREG_SPLIT_NO_EMPTY);
                if (((count($buffArgs) == 4) || (count($buffArgs) == 5) || (count($buffArgs) == 9) || (count($buffArgs) == 10)) && isset($carr[$cname])) {
                    $this->_result[$prog][$uname]['level'] = trim($buffArgs[1]);
                    $this->_result[$prog][$uname]['controller'] = $carr[$cname]['controller'];
                    if (isset($carr[$cname]['battery'])) $this->_result[$prog][$uname]['battery'] = $carr[$cname]['battery'];
                    if (isset($carr[$cname]['cache_size'])) $this->_result[$prog][$uname]['cache_size'] = $carr[$cname]['cache_size'];
                    if (isset($carr[$cname]['firmware'])) $this->_result[$prog][$uname]['firmware'] = $carr[$cname]['firmware'];
                    if (isset($carr[$cname]['temperature'])) $this->_result[$prog][$uname]['temperature'] = $carr[$cname]['temperature'];
                    $unit = preg_replace("/^[\d\s]+/", "", trim($buffArgs[2]));
                    $value = preg_replace("/[\D\s]+$/", "", trim($buffArgs[2]));
                    switch ($unit) {
                    case 'B':
                        $this->_result[$prog][$uname]['capacity'] = $value;
                        break;
                    case 'K':
                        $this->_result[$prog][$uname]['capacity'] = 1024*$value;
                        break;
                    case 'M':
                        $this->_result[$prog][$uname]['capacity'] = 1024*1024*$value;
                        break;
                    case 'G':
                        $this->_result[$prog][$uname]['capacity'] = 1024*1024*1024*$value;
                        break;
                    case 'T':
                        $this->_result[$prog][$uname]['capacity'] = 1024*1024*1024*1024*$value;
                        break;
                    case 'P':
                        $this->_result[$prog][$uname]['capacity'] = 1024*1024*1024*1024*1024*$value;
                    }
                    if ((count($buffArgs) == 4) || (count($buffArgs) == 5)) {
                        $this->_result[$prog][$uname]['status'] = trim($buffArgs[3]);
                    } else {
                        $this->_result[$prog][$uname]['status'] = trim($buffArgs[6]);
                        $this->_result[$prog][$uname]['diskcache'] = trim($buffArgs[5]);
                        $this->_result[$prog][$uname]['name'] = trim($buffArgs[7]);
                        if (preg_match("/^(\d+) KB$/", trim($buffArgs[3]), $strsize)) {
                            $this->_result[$prog][$uname]['stripe_size'] = $strsize[1] * 1024;
                        }
                        $ctype = trim($buffArgs[4]);
                        if (preg_match("/^NORA,/", $ctype)) $this->_result[$prog][$uname]['readpolicy'] = "noReadAhead";
                        elseif (preg_match("/^RA,/", $ctype)) $this->_result[$prog][$uname]['readpolicy'] = "readAhead";
                        elseif (preg_match("/^ADRA,/", $ctype)) $this->_result[$prog][$uname]['readpolicy'] = "adaptiveReadAhead";
                        if (preg_match("/,WT$/", $ctype)) $this->_result[$prog][$uname]['writepolicy'] = "writeThrough";
                        elseif (preg_match("/,WB$/", $ctype)) $this->_result[$prog][$uname]['writepolicy'] = "writeBack";
                        elseif (preg_match("/,WBF$/", $ctype)) $this->_result[$prog][$uname]['writepolicy'] = "writeBackForce";
                    }
                    $this->_result[$prog][$uname]['items'][$uname]['parentid'] = 0;
                    $this->_result[$prog][$uname]['items'][$uname]['name'] = trim($buffArgs[1]);
                    if (preg_match("/(.+) : Completed (\d+)%/", trim($buffArgs[count($buffArgs)-1]), $progarr)) {
                        $this->_result[$prog][$uname]['action']['name'] = trim($progarr[1]);
                        $this->_result[$prog][$uname]['action']['percent'] = trim($progarr[2]);
                    }
                    switch ($this->_result[$prog][$uname]['status']) {
                    case 'OK':
                    case 'Optimal':
                        $this->_result[$prog][$uname]['items'][$uname]['status'] = "ok";
                        break;
                    case 'Offline':
                        $this->_result[$prog][$uname]['items'][$uname]['status'] = "F";
                        break;
                    default:
                        $this->_result[$prog][$uname]['items'][$uname]['status'] = "W";
                    }
                }
            } elseif (preg_match("/^(((c\d+)u\d+)p\d+)[\t |]/", $buffLine, $pbuff)) {
                $pname = $pbuff[1];
                $uname = $pbuff[2];
                $buffArgs = preg_split($split, $buffLine, -1, PREG_SPLIT_NO_EMPTY);
                if (((count($buffArgs) == 3) || (count($buffArgs) == 9)) && (isset($this->_result[$prog][$uname]))) {
                    $this->_result[$prog][$uname]['items'][$pname]['parentid'] = 1;
                    $this->_result[$prog][$uname]['items'][$pname]['name'] = $pname;
                    if (count($buffArgs) == 3) {
                        $this->_result[$prog][$uname]['items'][$pname]['type'] = "disk";
                        $dskstat = trim($buffArgs[2]);
                        /* too long
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) { // due to mixing name and serial number
                            $this->_result[$prog][$uname]['items'][$pname]['model'] = trim($buffArgs[1]);
                        }
                        */
                    } else {
                        if (preg_match("/^(\d+)C$/", trim($buffArgs[6]), $pregout)) {
                            $this->_result[$prog][$uname]['items'][$pname]['temperature'] = $pregout[1];
                        }
                        if (trim($buffArgs[1])==="SSD") {
                            $this->_result[$prog][$uname]['items'][$pname]['type'] = "ssd";
                        } else {
                            $this->_result[$prog][$uname]['items'][$pname]['type'] = "disk";
                        }
                        $dskstat = trim($buffArgs[4]);
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                            /* too long
                            if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) { // due to mixing name and serial number
                                $this->_result[$prog][$uname]['items'][$pname]['model'] = trim($buffArgs[2]);
                            }
                            */
                            $capacity = preg_replace("/,/", ".", trim($buffArgs[3]));
                            $unit = preg_replace("/^[\d\.\s]+/", "", $capacity);
                            $value = preg_replace("/[\D\s]+$/", "", $capacity);
                            switch ($unit) {
                            case 'B':
                                $this->_result[$prog][$uname]['items'][$pname]['capacity'] = $value;
                                break;
                            case 'KB':
                                $this->_result[$prog][$uname]['items'][$pname]['capacity'] = round(1024*$value);
                                break;
                            case 'MB':
                                $this->_result[$prog][$uname]['items'][$pname]['capacity'] = round(1024*1024*$value);
                                break;
                            case 'Gb':
                            case 'GB':
                                $this->_result[$prog][$uname]['items'][$pname]['capacity'] = round(1024*1024*1024*$value);
                                break;
                            case 'TB':
                                $this->_result[$prog][$uname]['items'][$pname]['capacity'] = round(1024*1024*1024*1024*$value);
                                break;
                            case 'PB':
                                $this->_result[$prog][$uname]['items'][$pname]['capacity'] = round(1024*1024*1024*1024*1024*$value);
                            }
                        }
                    }
                    switch ($dskstat) {
                    case 'OK':
                    case 'Online':
                    case 'Online, Spun Up':
                        $this->_result[$prog][$uname]['items'][$pname]['status'] = "ok";
                        break;
/*                    case 'JBOD':
                    case 'Unconfigured(good), Spun Up':
                    case 'Unconfigured(good), Spun down':
                        $this->_result[$prog][$uname]['items'][$pname]['status'] = "U";
                        break;
                    case 'Hotspare, Spun Up':
                    case 'Hotspare, Spun down':
                        $this->_result[$prog][$uname]['items'][$pname]['status'] = "S";
                        break;*/
                    default:
                        if (preg_match("/^(\S+) \((\d+)%\)/", $dskstat, $progarr)) {
                            $this->_result[$prog][$uname]['items'][$pname]['status'] = "W";
                            $this->_result[$prog][$uname]['action']['name'] = trim($progarr[1]);
                            $this->_result[$prog][$uname]['action']['percent'] = trim($progarr[2]);
                        }
                    }
                    if ($dskstat !== "OK") $this->_result[$prog][$uname]['items'][$pname]['info'] = $dskstat;
                }
            } elseif (preg_match("/^((c\d+)uXpY)[\t |]/", $buffLine, $pbuff)) {
                $pname = $pbuff[1];
                $cname = $pbuff[2];
                $uname = $cname."-unconfigured";
                $this->_result[$prog][$uname]['controller'] = $carr[$cname]['controller'];
                if (isset($carr[$cname]['battery'])) $this->_result[$prog][$uname]['battery'] = $carr[$cname]['battery'];
                if (isset($carr[$cname]['cache_size'])) $this->_result[$prog][$uname]['cache_size'] = $carr[$cname]['cache_size'];
                if (isset($carr[$cname]['firmware'])) $this->_result[$prog][$uname]['firmware'] = $carr[$cname]['firmware'];
                if (isset($carr[$cname]['temperature'])) $this->_result[$prog][$uname]['temperature'] = $carr[$cname]['temperature'];
                $this->_result[$prog][$uname]['status'] = "unconfigured";
                $this->_result[$prog][$uname]['items'][$uname]['parentid'] = 0;
                $this->_result[$prog][$uname]['items'][$uname]['name'] = "unconfigured";
                $this->_result[$prog][$uname]['items'][$uname]['status'] = "U";
                if (!isset($this->_result[$prog][$uname]['items'][$uname]['count'])) {
                    $id = 0;
                } else {
                    $id = $this->_result[$prog][$uname]['items'][$uname]['count'];
                    $id++;
                }
                $this->_result[$prog][$uname]['items'][$uname]['count'] = $id;

                $buffArgs = preg_split($split, $buffLine, -1, PREG_SPLIT_NO_EMPTY);
                if (((count($buffArgs) == 3) || (count($buffArgs) == 9) || (count($buffArgs) == 10))) {
                    $this->_result[$prog][$uname]['items'][$uname."-".$id]['parentid'] = 1;
                    $this->_result[$prog][$uname]['items'][$uname."-".$id]['name'] = $pname;
                    if (count($buffArgs) == 3) {
                        $this->_result[$prog][$uname]['items'][$uname."-".$id]['type'] = "disk";
                        $dskstat = trim($buffArgs[2]);
                    } else {
                        if (trim($buffArgs[1])==="SSD") {
                            $this->_result[$prog][$uname]['items'][$uname."-".$id]['type'] = "ssd";
                        } else {
                            $this->_result[$prog][$uname]['items'][$uname."-".$id]['type'] = "disk";
                        }
                        $dskstat = trim($buffArgs[4]);
                    }
                    switch ($dskstat) {
/*                        case 'Online':
                        case 'Online, Spun Up':*/
                    case 'JBOD':
                        $this->_result[$prog][$uname]['items'][$uname."-".$id]['status'] = "ok";
                        break;
                    case 'Unconfigured(bad)':
                        $this->_result[$prog][$uname]['items'][$uname."-".$id]['status'] = "F";
                        break;
                    case 'Unconfigured(good), Spun Up':
                    case 'Unconfigured(good), Spun down':
                        $this->_result[$prog][$uname]['items'][$uname."-".$id]['status'] = "U";
                        break;
                    case 'Hotspare, Spun Up':
                    case 'Hotspare, Spun down':
                        $this->_result[$prog][$uname]['items'][$uname."-".$id]['status'] = "S";
                    }
                    $this->_result[$prog][$uname]['items'][$uname."-".$id]['info'] = $dskstat;
                    if ((count($buffArgs) == 10) && (trim($buffArgs[9]) != 'N/A')) $this->_result[$prog][$uname]['items'][$uname."-".$id]['info'].=" ".trim($buffArgs[9]);
                }
            }
        }
    }

    private function execute_graid($buffer)
    {
        if (preg_match('/^Geom name: +([^\n\r]+)/', $buffer, $geom)) {
            $controller = trim($geom[1]);
        } else {
            $controller = '';
        }
        $raiddata = preg_split("/Consumers:\r?\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
        if (!empty($raiddata)) {
            $disksinfo = array();
            if (isset($raiddata[1]) && (trim($raiddata[1])!=="")) {
                $lines = preg_split("/\r?\n/", trim($raiddata[1]), -1, PREG_SPLIT_NO_EMPTY);
                $disk = "";
                foreach ($lines as $line) {
                    if (preg_match("/^\d+\.\s+Name:\s+(.+)/", $line, $data)) {
                        $disk = $data[1];
                    } elseif (($disk!=="") && preg_match('/^\s+State:\s+(\S+)\s+\(([^\)\s]+)\s*([\d]*)(%*)([^\)]*)\)/', $line, $data)) {
                        $disksinfo[$disk]['status'] = trim($data[1]);
                        $disksinfo[$disk]['substatus'] = trim($data[2]);
                        if (trim($data[4])=="%") {
                            $disksinfo[$disk]['percent'] = trim($data[3]);
                        }
                    } elseif (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
                       && ($disk !== "") && preg_match('/^\s+Mediasize:\s+(\d+)/', $line, $data)) {
                        $disksinfo[$disk]['capacity'] = trim($data[1]);
                    }
                }
            }
            $lines = preg_split("/\r?\n/", trim($raiddata[0]), -1, PREG_SPLIT_NO_EMPTY);
            $group = "";
            foreach ($lines as $line) {
                if (preg_match("/^\d+\.\s+Name:\s+(.+)/", $line, $data)) {
                    $group = $data[1];
                    if ($controller !== '') $this->_result['graid'][$group]['controller'] = $controller;
                } elseif ($group!=="") {
                    if (preg_match('/^\s+Mediasize:\s+(\d+)/', $line, $data)) {
                        $this->_result['graid'][$group]['capacity'] = trim($data[1]);
                    } elseif (preg_match('/^\s+State:\s+(.+)/', $line, $data)) {
                        $this->_result['graid'][$group]['status'] = trim($data[1]);
                    } elseif (preg_match('/^\s+RAIDLevel:\s+(.+)/', $line, $data)) {
                        $this->_result['graid'][$group]['level'] = trim($data[1]);
                    } elseif (preg_match('/^\s+Components:\s+(\d+)/', $line, $data)) {
                        $this->_result['graid'][$group]['devs'] = trim($data[1]);
                    } elseif (preg_match('/^\s+Label:\s+(.+)/', $line, $data)) {
                        $this->_result['graid'][$group]['name'] = trim($data[1]);
                    } elseif (preg_match('/^\s+Stripesize:\s+(.+)/', $line, $data)) {
                        $this->_result['graid'][$group]['stripe_size'] = trim($data[1]);
                    } elseif (preg_match('/^\s+Subdisks:\s+(.+)/', $line, $data)) {
                        $disks = preg_split('/\s*,\s*/', trim($data[1]), -1, PREG_SPLIT_NO_EMPTY);
                        $nones = 0;
                        $this->_result['graid'][$group]['items'][0]['parentid'] = 0;
                        foreach ($disks as $disk) {
                            if (preg_match("/^(\S+)\s+\(([^\)]+)\)/", $disk, $partition)) {
                                $this->_result['graid'][$group]['items'][$partition[1]]['parentid'] = 1;
                                $this->_result['graid'][$group]['items'][$partition[1]]['type'] = "disk";
                                if ($partition[2]=="ACTIVE") {
                                    if (isset($disksinfo[$partition[1]]["status"])) {
                                        if ($disksinfo[$partition[1]]["status"]!=="ACTIVE") {
                                            $this->_result['graid'][$group]['items'][$partition[1]]['status'] = "W";
                                        } elseif ($disksinfo[$partition[1]]["substatus"]=="ACTIVE") {
                                            $this->_result['graid'][$group]['items'][$partition[1]]['status'] = "ok";
                                        } else {
                                            $this->_result['graid'][$group]['items'][$partition[1]]['status'] = "W";
                                            if (isset($disksinfo[$partition[1]]["percent"])) {
                                                $this->_result['graid'][$group]['action']['name'] = $disksinfo[$partition[1]]["substatus"];
                                                $this->_result['graid'][$group]['action']['percent'] = $disksinfo[$partition[1]]["percent"];
                                            }
                                        }
                                    } else {
                                        $this->_result['graid'][$group]['items'][$partition[1]]['status'] = "ok";
                                        $this->_result['graid'][$group]['items'][$partition[1]]['name'] = $partition[1];
                                    }
                                    $this->_result['graid'][$group]['items'][$partition[1]]['name'] = $partition[1];
                                } elseif ($partition[2]=="NONE") {
                                    $this->_result['graid'][$group]['items']["none".$nones]['status'] = 'E';
                                    $this->_result['graid'][$group]['items']["none".$nones]['name'] = "none".$nones;
                                    $nones++;
                                }
                            }
                        }
                    }
                }
            }
            if (isset($this->_result['graid'][$group]['items'][0]['parentid'])) {
                $name = "";
                if (isset($this->_result['graid'][$group]['name'])) {
                    $name = $this->_result['graid'][$group]['name'];
                }
                if (isset($this->_result['graid'][$group]['level'])) {
                    $name .= " " .$this->_result['graid'][$group]['level'];
                }
                $this->_result['graid'][$group]['items'][0]['name'] = trim($name);
                if (isset($this->_result['graid'][$group]['status'])) {
                      if ($this->_result['graid'][$group]['status']==="OPTIMAL") {
                          $this->_result['graid'][$group]['items'][0]['status'] = "ok";
                      } else {
                          $this->_result['graid'][$group]['items'][0]['status'] = "W";
                          $this->_result['graid'][$group]['items'][0]['info'] = $this->_result['graid'][$group]['status'];
                      }
                } else {
                    $this->_result['graid'][$group]['items'][0]['status'] = "ok";
                }
            }
        }
    }

    private function execute_zpool($buffer)
    {
        $raiddata = preg_split("/(\r?\n)+ +(?=pool: )/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
        if (!empty($raiddata)) foreach ($raiddata as $raid) {
            if (preg_match("/^pool: (\S+)/", $raid, $buff)) {
                $group = $buff[1];
                if (preg_match("/^ +state: (\S+)/m", $raid, $buff)) {
                    $this->_result['zpool'][$group]['status'] = $buff[1];
                }
                $databegin = preg_split("/\n[ \t]+NAME +STATE +READ +WRITE +CKSUM\r?\n/", $raid, -1, PREG_SPLIT_NO_EMPTY);
                if (!empty($databegin) && (count($databegin)==2)) {
                    $datas = preg_split("/\r?\n[ \t]*\r?\n/", $databegin[1], -1, PREG_SPLIT_NO_EMPTY);
                    $datalines = preg_split("/\r?\n/", $datas[0], -1, PREG_SPLIT_NO_EMPTY);
                    $rootoffset = false;
                    $lastparentids = array(0=>-1);
                    $lastindent = 0;
                    $lastid = 0;
                    foreach ($datalines as $id=>$data) {
                        if (preg_match("/^([ \t]+)\S/", $data, $buff)) {;
                            $fullbuff = preg_split("/[ \t]+/", $data, 6, PREG_SPLIT_NO_EMPTY);
                            $offset=strlen($buff[1]);
                            if ($rootoffset === false) { // first line means root
                                $rootoffset = $offset;
                                $this->_result['zpool'][$group]['items'][$id]['name'] = "";//$fullbuff[0];
                                if (count($fullbuff) > 1) {
                                    $this->_result['zpool'][$group]['items'][$id]['status'] = $fullbuff[1];
                                }
                                $this->_result['zpool'][$group]['items'][$id]['parentid'] = -2;
                                continue;
                            }
                            if ($offset < $rootoffset) { // some errors
                                continue;
                            }

                            $this->_result['zpool'][$group]['items'][$id]['name'] = $fullbuff[0];

                            if (count($fullbuff) > 1) {
                                $this->_result['zpool'][$group]['items'][$id]['status'] = $fullbuff[1];
                            }
                            if (count($fullbuff) > 5) {
                                $this->_result['zpool'][$group]['items'][$id]['info'] = $fullbuff[5];
                            }

                            $indent = ($offset - $rootoffset)/2;
                            if ($indent > $lastindent) {
                                $lastparentids[$indent] = $lastid;
                            }
                            $this->_result['zpool'][$group]['items'][$id]['parentid'] = $lastparentids[$indent];

                            if ($lastparentids[$indent] >= 0) {
                                if (isset($this->_result['zpool'][$group]['items'][$lastparentids[$indent]]['childs'])) {
                                    $this->_result['zpool'][$group]['items'][$lastparentids[$indent]]['childs']++;
                                } else {
                                    $this->_result['zpool'][$group]['items'][$lastparentids[$indent]]['childs'] = 1;
                                }
                            }

                            $lastindent = $indent;
                            $lastid = $id;
                        }
                    }
                    foreach ($this->_result['zpool'][$group]['items'] as $id=>$data) { // type analize
                        if ((!isset($data['childs']) || ($data['childs']<1)) && ($data['parentid']>=0) && !preg_match("/^mirror$|^mirror-|^spare$|^spare-|^replacing$|^replacing-|^raidz[123]$|^raidz[123]-/", $data['name'])) {
                            $this->_result['zpool'][$group]['items'][$id]['type'] = "disk";
                        } elseif (isset($data['childs']) && !preg_match("/^spares$|^mirror$|^mirror-|^spare$|^spare-|^replacing$|^replacing-|^raidz[123]$|^raidz[123]-/", $data['name'])) {
                            if (($data['childs']==1) && ($data['parentid']==-2) && isset($this->_result['zpool'][$group]['items'][$id+1]) && !preg_match("/^mirror$|^mirror-|^spare$|^spare-|^replacing$|^replacing-|^raidz[123]$|^raidz[123]-/", $this->_result['zpool'][$group]['items'][$id+1]['name'])) {
                                $this->_result['zpool'][$group]['items'][$id]['name2'] = "jbod";
                            } elseif ($data['childs']>1) {
                                $this->_result['zpool'][$group]['items'][$id]['name2'] = "stripe";
                            }
                        }
                    }

                    foreach ($this->_result['zpool'][$group]['items'] as $id=>$data) { // size optimize
                        if (($data['parentid']<0) && isset($data['childs']) && ($data['childs']==1) && (!isset($data['name2']) || ($data['name2']!=="jbod"))) {
                            if ($data['parentid']==-2) {
                                unset($this->_result['zpool'][$group]['items'][$id]);
                            } elseif (($data['parentid'] == -1) && !isset($this->_result['zpool'][$group]['items'][$id+1]['type'])) {
                                $this->_result['zpool'][$group]['items'][$id+1]['name2'] = $data['name'];
                                $this->_result['zpool'][$group]['items'][$id+1]['parentid'] = $data['parentid'];
                                unset($this->_result['zpool'][$group]['items'][$id]);
                                foreach ($this->_result['zpool'][$group]['items'] as $id2=>$data2) {
                                    if ($data2['parentid']>$id) {
                                        $this->_result['zpool'][$group]['items'][$id2]['parentid'] = $data2['parentid'] - 1;
                                    }
                                }
                            }
                        }
                    }

                    if (isset($this->_result['zpool'][$group]['items'][0])) {
                        $shift = true;
                    } else {
                        $shift = false;
                    }
                    foreach ($this->_result['zpool'][$group]['items'] as $id=>$data) {
                        // reindex
                        if ($shift) {
                            $this->_result['zpool'][$group]['items'][$id]['parentid']++;
                        }
                        if ($data['parentid']<0) {
                            $this->_result['zpool'][$group]['items'][$id]['parentid'] = 0;
                        }

                         // name append
                        if (isset($data['name2'])) {
                            if (($data['name2']==="cache") || ($data['name2']==="logs")) {
                                $this->_result['zpool'][$group]['items'][$id]['name'] = trim($data['name2']." ".$data['name']);
                            } else {
                                $this->_result['zpool'][$group]['items'][$id]['name'] = trim($data['name']." ".$data['name2']);
                            }
                            unset($this->_result['zpool'][$group]['items'][$id]['name2']);
                        }

                        // status and info normalize
                        if (isset($data['status'])) {
                                switch ($data['status']) {
                                case 'AVAIL':
                                    if (isset($data['info'])) {
                                        $this->_result['zpool'][$group]['items'][$id]['info'] = $data['status']." ".$data['info'];
                                    } else {
                                        $this->_result['zpool'][$group]['items'][$id]['info'] = $data['status'];
                                    }
                                    $this->_result['zpool'][$group]['items'][$id]['status'] = "S";
                                    break;
                                case 'INUSE':
                                case 'DEGRADED':
                                    if (isset($data['info'])) {
                                        $this->_result['zpool'][$group]['items'][$id]['info'] = $data['status']." ".$data['info'];
                                    } else {
                                        $this->_result['zpool'][$group]['items'][$id]['info'] = $data['status'];
                                    }
                                    $this->_result['zpool'][$group]['items'][$id]['status'] = "W";
                                    break;
                                case 'UNAVAIL':
                                case 'FAULTED':
                                    if (isset($data['info'])) {
                                        $this->_result['zpool'][$group]['items'][$id]['info'] = $data['status']." ".$data['info'];
                                    } else {
                                        $this->_result['zpool'][$group]['items'][$id]['info'] = $data['status'];
                                    }
                                    $this->_result['zpool'][$group]['items'][$id]['status'] = "F";
                                    break;
                                default:
                                    $this->_result['zpool'][$group]['items'][$id]['status'] = "ok";
                                }
                        } else {
                            if ($this->_result['zpool'][$group]['items'][$id]['name'] == "spares") {
                                $this->_result['zpool'][$group]['items'][$id]['status'] = "S";
                            } else {
                                $this->_result['zpool'][$group]['items'][$id]['status'] = "ok";
                            }
                        }
                    }
                }
            }
        }
    }

    private function execute_idrac($buffer, $device)
    {
        $snmptablec = array(); //controller table
        $snmptableb = array(); //battery table
        $snmptablev = array(); //virtual disks table
        $snmptablep = array(); //physical disks table

        $buffer = preg_replace('/End of MIB\r?\n/', '', $buffer);
        $buffer = preg_replace('/\s\r?\n([^\.])/', ' $1', $buffer);
        $raiddata = preg_split("/\r?\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
        if (!empty($raiddata)) {
            foreach ($raiddata as $line) {
                if (preg_match('/^(.+) = Hex-STRING:\s(.+)/', $line, $linetmp)) {
                    $hexchars = explode(" ", trim($linetmp[2]));
                    $newstring = "";
                    foreach ($hexchars as $hexchar) {
                        $hexint = hexdec($hexchar);
                        if (($hexint<32) || ($hexint>126)) {
                            $newstring .= ".";
                        } else {
                            $newstring .= chr($hexint);
                        }
                    }
                    if ($newstring!=="") {
                        $line = $linetmp[1]." = STRING: ".$newstring;
                    }
                }
                if (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.1\.1\.2\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablec[$data[1]]['controllerName']=trim($data[2], "\"");
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.1\.1\.8\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablec[$data[1]]['controllerFWVersion']=trim($data[2], "\"");
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.1\.1\.9\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablec[$data[1]]['controllerCacheSizeInMB']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.1\.1\.37\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablec[$data[1]]['controllerRollUpStatus']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.1\.1\.78\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablec[$data[1]]['controllerFQDD']=trim($data[2], "\"");

                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.15\.1\.4\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptableb[$data[1]]['batteryState']=$data[2];
//                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.15\.1\.6\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
//                    $snmptableb[$data[1]]['batteryComponentStatus']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.15\.1\.20\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptableb[$data[1]]['batteryFQDD']=trim($data[2], "\"");

                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.2\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskName']=trim($data[2], "\"");
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.3\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskManufacturer']=trim($data[2], "\"");
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.4\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskState']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.6\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskProductID']=trim($data[2], "\"");
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.7\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskSerialNo']=trim($data[2], "\"");
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.11\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskCapacityInMB']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.21\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskBusType']=$data[2];
//                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.22\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
//                    $snmptablep[$data[1]]['physicalDiskSpareState']=$data[2];
//                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.24\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
//                    $snmptablep[$data[1]]['physicalDiskComponentStatus']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.50\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskOperationalState']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.51\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskProgress']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.130\.4\.1\.54\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablep[$data[1]]['physicalDiskFQDD']=trim($data[2], "\"");

                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.2\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskName']=trim($data[2], "\"");
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.4\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskState']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.6\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskSizeInMB']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.10\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskWritePolicy']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.11\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskReadPolicy']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.13\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskLayout']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.14\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskStripeSize']=$data[2];
//                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.20\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
//                    $snmptablev[$data[1]]['virtualDiskComponentStatus']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.23\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskBadBlocksDetected']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.26\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskDiskCachePolicy']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.30\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskOperationalState']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.31\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskProgress']=$data[2];
                } elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.674\.10892\.5\.5\.1\.20\.140\.1\.1\.35\.(.*) = STRING:\s(.*)/', $line, $data)) {
                    $snmptablev[$data[1]]['virtualDiskFQDD']=trim($data[2], "\"");
                }
            }

            foreach ($snmptablec as $raid_controller) {
                $tablec = array(); //controller result table
                if (isset($raid_controller['controllerRollUpStatus'])) {
                    switch ($raid_controller['controllerRollUpStatus']) {
                    case 1:
                        $tablec['status'] = "W";
                        $tablec['info'] = "Other";
                        break;
                    case 2:
                        $tablec['status'] = "W";
                        $tablec['info'] = "Unknown";
                        break;
                    case 3:
                        $tablec['status'] ="ok";
                        break;
                    case 4:
                        $tablec['status'] ="W";
                        $tablec['info'] ="Non-critical";
                        break;
                    case 5:
                        $tablec['status'] = "F";
                        $tablec['info'] = "Critical";
                        break;
                    case 6:
                        $tablec['status'] = "F";
                        $tablec['info'] = "Non-recoverable";
                    }
                }
                if (isset($raid_controller['controllerName'])) {
                    $tablec['controller'] = $raid_controller['controllerName'];
                }
                if (isset($raid_controller['controllerFWVersion'])) {
                    $tablec['firmware'] = $raid_controller['controllerFWVersion'];
                }
                if (isset($raid_controller['controllerCacheSizeInMB'])) {
                    $tablec['cache_size'] = $raid_controller['controllerCacheSizeInMB'] * 1024 * 1024;
                }
                foreach ($snmptableb as $raid_battery) {
                    if (isset($raid_battery['batteryFQDD'])
                       && isset($raid_controller['controllerFQDD'])
                       && preg_match("/:".$raid_controller['controllerFQDD']."$/", $raid_battery['batteryFQDD'])) {
                        if (isset($raid_battery['batteryState'])) {
                            switch ($raid_battery['batteryState']) {
                            case 1:
                                $tablec['battery'] = "unknown";
                                break;
                            case 2:
                                $tablec['battery'] = "ready";
                                break;
                            case 3:
                                $tablec['battery'] = "failed";
                                break;
                            case 4:
                                $tablec['battery'] = "degraded";
                                break;
                            case 5:
                                $tablec['battery'] = "missing";
                                break;
                            case 6:
                                $tablec['battery'] = "charging";
                                break;
                            case 7:
                                $tablec['battery'] = "bellowThreshold";
                            }
                        }
                        break;
                    }
                }
                foreach ($snmptablep as $raid_physical) {
                    if (isset($raid_physical['physicalDiskFQDD'])
                       && isset($raid_controller['controllerFQDD'])
                       && preg_match("/:".$raid_controller['controllerFQDD']."$/", $raid_physical['physicalDiskFQDD'])) {
                        $devname = $device.'-'.preg_replace('/[a-zA-Z\.]/', '', $raid_controller['controllerFQDD']);
                        $this->_result['idrac'][$devname]['name']=$raid_controller['controllerFQDD'];
                        if (isset($tablec['controller'])) {
                            $this->_result['idrac'][$devname]['controller'] = $tablec['controller'];
                        }
                        if (isset($tablec['firmware'])) {
                            $this->_result['idrac'][$devname]['firmware'] = $tablec['firmware'];
                        }
                        if (isset($tablec['battery'])) {
                            $this->_result['idrac'][$devname]['battery'] = $tablec['battery'];
                        }
                        if (isset($tablec['cache_size'])) {
                            $this->_result['idrac'][$devname]['cache_size'] = $tablec['cache_size'];
                        }
                        if (isset($tablec['info'])) {
                            $this->_result['idrac'][$devname]['status'] = $tablec['info'];
                        } elseif (isset($tablec['status'])) {
                            $this->_result['idrac'][$devname]['status'] = $tablec['status'];
                        }
                        $this->_result['idrac'][$devname]['items'][0]['name']=$raid_controller['controllerFQDD'];
                        $this->_result['idrac'][$devname]['items'][0]['parentid'] = 0;
                        if (isset($tablec['status'])) {
                            $this->_result['idrac'][$devname]['items'][0]['status'] = $tablec['status'];
                            if (isset($tablec['info'])) {
                                $this->_result['idrac'][$devname]['items'][0]['info'] = $tablec['info'];
                            }
                        }
                        $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['name']=$raid_physical['physicalDiskName'];
                        $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['parentid'] = 1;
                        if (preg_match("/^Solid State Disk /", $raid_physical['physicalDiskName'])) {
                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['type'] = "ssd";
                        } else {
                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['type'] = "disk";
                        }

                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                            if (isset($raid_physical['physicalDiskCapacityInMB'])) {
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['capacity'] = $raid_physical['physicalDiskCapacityInMB'] * 1024 * 1024;
                            }

                            $model = "";
                            if (isset($raid_physical['physicalDiskManufacturer'])) {
                                $model = $raid_physical['physicalDiskManufacturer'];
                            }
                            if (isset($raid_physical['physicalDiskProductID'])) {
                                $model .= " ".$raid_physical['physicalDiskProductID'];
                            }
                            if (($model = trim($model)) !== '') {
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['model'] = $model;
                            }
                            if (isset($raid_physical['physicalDiskBusType'])) {
                                switch ($raid_physical['physicalDiskBusType']) {
//                              case 1:
//                                  $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['bus'] = "unknown";
//                                  break;
                                case 2:
                                    $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['bus'] = "SCSI";
                                    break;
                                case 3:
                                    $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['bus'] = "SAS";
                                    break;
                                case 4:
                                    $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['bus'] = "SATA";
                                    break;
                                case 5:
                                    $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['bus'] = "Fibre";
                                }
                            }
                            if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                                if (isset($raid_physical['physicalDiskSerialNo'])) {
                                    $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['serial'] = " ".$raid_physical['physicalDiskSerialNo'];
                                }
                            }
                        }
                        if (isset($raid_physical['physicalDiskState'])) {
                            switch ($raid_physical['physicalDiskState']) {
                            case 1:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "W";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "unknown";
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "W";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "ready";
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "ok";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "online";
                                if (isset($raid_physical['physicalDiskOperationalState'])) {
                                    switch ($raid_physical['physicalDiskOperationalState']) {
                                    case 1:
                                        break;
                                    case 2:
                                        $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "W";
                                        if (isset($raid_physical['physicalDiskProgress'])) {
                                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = 'Rebuilding ('.$raid_physical['physicalDiskProgress'].'%)';
                                            $this->_result['idrac'][$devname]['action']['name'] = 'Rebuilding';
                                            $this->_result['idrac'][$devname]['action']['percent'] = $raid_physical['physicalDiskProgress'];
                                        } else {
                                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = 'Rebuilding';
                                        }
                                        break;
                                    case 3:
                                        $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "W";
                                        if (isset($raid_physical['physicalDiskProgress'])) {
                                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = 'Erasing ('.$raid_physical['physicalDiskProgress'].'%)';
                                            $this->_result['idrac'][$devname]['action']['name'] = 'Erasing';
                                            $this->_result['idrac'][$devname]['action']['percent'] = $raid_physical['physicalDiskProgress'];
                                        } else {
                                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = 'Erasing';
                                        }
                                        break;
                                    case 4:
                                        $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "W";
                                        if (isset($raid_physical['physicalDiskProgress'])) {
                                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = 'Copying ('.$raid_physical['physicalDiskProgress'].'%)';
                                            $this->_result['idrac'][$devname]['action']['name'] = 'Copying';
                                            $this->_result['idrac'][$devname]['action']['percent'] = $raid_physical['physicalDiskProgress'];
                                        } else {
                                            $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = 'Copying';
                                        }
                                    }
                                }
                                break;
                            case 4:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "W";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "foreign";
                                break;
                            case 5:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "F";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "offline";
                                break;
                            case 6:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "F";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "blocked";
                                break;
                            case 7:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "F";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "failed";
                                break;
                            case 8:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "S";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "non-raid";
                                break;
                            case 9:
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['status'] = "F";
                                $this->_result['idrac'][$devname]['items'][$raid_physical['physicalDiskName']]['info'] = "removed";
                            }
                        }
                    }
                }
                foreach ($snmptablev as $raid_virtual) {
                    if (isset($raid_virtual['virtualDiskFQDD'])
                       && isset($raid_controller['controllerFQDD'])
                       && preg_match("/:".$raid_controller['controllerFQDD']."$/", $raid_virtual['virtualDiskFQDD'])) {
                        $devname = $device.'-'.preg_replace('/[a-zA-Z\.]/', '', $raid_virtual['virtualDiskFQDD']);
                        $this->_result['idrac'][$devname]['name']=$raid_virtual['virtualDiskFQDD'];
                        $this->_result['idrac'][$devname]['items'][0]['name']=$raid_virtual['virtualDiskFQDD'];
                        $this->_result['idrac'][$devname]['items'][0]['parentid'] = 0;
                        if (isset($tablec['controller'])) {
                            $this->_result['idrac'][$devname]['controller'] = $tablec['controller'];
                        }
                        if (isset($tablec['firmware'])) {
                            $this->_result['idrac'][$devname]['firmware'] = $tablec['firmware'];
                        }
                        if (isset($tablec['battery'])) {
                            $this->_result['idrac'][$devname]['battery'] = $tablec['battery'];
                        }
                        if (isset($tablec['cache_size'])) {
                            $this->_result['idrac'][$devname]['cache_size'] = $tablec['cache_size'];
                        }
                        if (isset($raid_virtual['virtualDiskLayout'])) {
                            switch ($raid_virtual['virtualDiskLayout']) {
                            case 1:
                                $this->_result['idrac'][$devname]['level'] = "other";
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['level'] = "raid0";
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['level'] = "raid1";
                                break;
                            case 4:
                                $this->_result['idrac'][$devname]['level'] = "raid5";
                                break;
                            case 5:
                                $this->_result['idrac'][$devname]['level'] = "raid6";
                                break;
                            case 6:
                                $this->_result['idrac'][$devname]['level'] = "raid10";
                                break;
                            case 7:
                                $this->_result['idrac'][$devname]['level'] = "raid50";
                                break;
                            case 8:
                                $this->_result['idrac'][$devname]['level'] = "raid60";
                                break;
                            case 9:
                                $this->_result['idrac'][$devname]['level'] = "concatraid1";
                                break;
                            case 10:
                                $this->_result['idrac'][$devname]['level'] = "concatraid5";
                                break;
                            default:
                                $this->_result['idrac'][$devname]['level'] = "unknown";
                            }
                            if (isset($this->_result['idrac'][$devname]['level'])) {
                                $this->_result['idrac'][$devname]['items'][0]['name'] = $this->_result['idrac'][$devname]['level'];
                            }
                        }
                        if (isset($raid_virtual['virtualDiskState'])) {
                            switch ($raid_virtual['virtualDiskState']) {
                            case 1:
                                $this->_result['idrac'][$devname]['status'] = "unknown";
                                $this->_result['idrac'][$devname]['items'][0]['status']="W";
                                $this->_result['idrac'][$devname]['items'][0]['info'] = $this->_result['idrac'][$devname]['status'];
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['status'] = "online";
                                $this->_result['idrac'][$devname]['items'][0]['status']="ok";
                                $this->_result['idrac'][$devname]['items'][0]['info'] = $this->_result['idrac'][$devname]['status'];
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['status'] = "failed";
                                $this->_result['idrac'][$devname]['items'][0]['status']="F";
                                $this->_result['idrac'][$devname]['items'][0]['info'] = $this->_result['idrac'][$devname]['status'];
                                break;
                            case 4:
                                $this->_result['idrac'][$devname]['status'] = "degraded";
                                $this->_result['idrac'][$devname]['items'][0]['status']="W";
                                $this->_result['idrac'][$devname]['items'][0]['info'] = $this->_result['idrac'][$devname]['status'];
                            }
                        }
                        if (isset($raid_virtual['virtualDiskOperationalState'])) {
                            switch ($raid_virtual['virtualDiskOperationalState']) {
                            case 1:
                                //$this->_result['idrac'][$devname]['action']['name'] = "notApplicable";
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['action']['name'] = "reconstructing";
                                if (isset($raid_virtual['virtualDiskProgress'])) {
                                    $this->_result['idrac'][$devname]['action']['percent'] = $raid_virtual['virtualDiskProgress'];
                                } else {
                                    $this->_result['idrac'][$devname]['action']['percent'] = 0;
                                }
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['action']['name'] = "resyncing";
                                if (isset($raid_virtual['virtualDiskProgress'])) {
                                    $this->_result['idrac'][$devname]['action']['percent'] = $raid_virtual['virtualDiskProgress'];
                                } else {
                                    $this->_result['idrac'][$devname]['action']['percent'] = 0;
                                }
                                break;
                            case 4:
                                $this->_result['idrac'][$devname]['action']['name'] = "initializing";
                                if (isset($raid_virtual['virtualDiskProgress'])) {
                                    $this->_result['idrac'][$devname]['action']['percent'] = $raid_virtual['virtualDiskProgress'];
                                } else {
                                    $this->_result['idrac'][$devname]['action']['percent'] = 0;
                                }
                                break;
                            case 5:
                                $this->_result['idrac'][$devname]['action']['name'] = "backgroundInit";
                                if (isset($raid_virtual['virtualDiskProgress'])) {
                                    $this->_result['idrac'][$devname]['action']['percent'] = $raid_virtual['virtualDiskProgress'];
                                } else {
                                    $this->_result['idrac'][$devname]['action']['percent'] = 0;
                                }
                            }
                        }

                        if (isset($raid_virtual['virtualDiskSizeInMB'])) {
                            $this->_result['idrac'][$devname]['capacity'] = $raid_virtual['virtualDiskSizeInMB'] * 1024 * 1024;
                        }

                        if (isset($raid_virtual['virtualDiskReadPolicy'])) {
                            switch ($raid_virtual['virtualDiskReadPolicy']) {
                            case 1:
                                $this->_result['idrac'][$devname]['readpolicy'] = "noReadAhead";
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['readpolicy'] = "readAhead";
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['readpolicy'] = "adaptiveReadAhead";
                            }
                        }
                        if (isset($raid_virtual['virtualDiskWritePolicy'])) {
                            switch ($raid_virtual['virtualDiskWritePolicy']) {
                            case 1:
                                $this->_result['idrac'][$devname]['writepolicy'] = "writeThrough";
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['writepolicy'] = "writeBack";
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['writepolicy'] = "writeBackForce";
                            }
                        }
                        if (isset($raid_virtual['virtualDiskState'])) {
                            switch ($raid_virtual['virtualDiskState']) {
                            case 1:
                                $this->_result['idrac'][$devname]['status'] = "unknown";
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['status'] = "online";
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['status'] = "failed";
                                break;
                            case 4:
                                $this->_result['idrac'][$devname]['status'] = "degraded";
                            }
                        }
                        if (isset($raid_virtual['virtualDiskDiskCachePolicy'])) {
                            switch ($raid_virtual['virtualDiskDiskCachePolicy']) {
                            case 1:
                                $this->_result['idrac'][$devname]['diskcache'] = "enabled";
                                break;
                            case 2:
                                $this->_result['idrac'][$devname]['diskcache'] = "disabled";
                                break;
                            case 3:
                                $this->_result['idrac'][$devname]['diskcache'] = "default";
                            }
                        }
                        if (isset($raid_virtual['virtualDiskBadBlocksDetected'])) {
                            $this->_result['idrac'][$devname]['bad_blocks'] = $raid_virtual['virtualDiskBadBlocksDetected'];
                        }
                        if (isset($raid_virtual['virtualDiskStripeSize'])) {
                            $virtualDiskStripeSize = $raid_virtual['virtualDiskStripeSize'];
                            if ($virtualDiskStripeSize >= 3) {
                                $this->_result['idrac'][$devname]['stripe_size'] = 512<<($virtualDiskStripeSize - 3);
                            }
                        }

                    }
                }
            }
        }
    }

    private function execute_storcli($buffer, $_perccli = false)
    {

        if ($_perccli === true) {
            $prog = "perccli";
        } else {
            $prog = "storcli";
        }

        if (!empty($buffer)) {
            $raiddata = preg_split("/\n(?=.+\s+:\r?\n===)/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
            $carr = array();
            $cnr = -1;
            if (count($raiddata) > 2) foreach ($raiddata as $items) {
                if (preg_match("/^(.+)\s+:\r?\n===+\r?\n([\s\S]+)$/", $items, $buff)) {
                    if ($buff[1] === "Basics") {
                        $cnr++;
                    }
                    if ($cnr >= 0) {
                        $stage = 0;
                        $lines = preg_split('/\r?\n/', preg_replace("/, \r?\n/", ", ", $buff[2]), -1, PREG_SPLIT_NO_EMPTY);
                        foreach ($lines as $line) {
                            if (($line = trim($line)) !== '') {
                                $parts = preg_split("/ = /", $line);
                                switch ($stage) {
                                case 0:
                                    if (count($parts) == 2) {
                                        $carr[$cnr][$buff[1]][trim($parts[0])] = trim($parts[1]);
                                    } elseif (preg_match("/^---/", $line)) {
                                        $stage = 1;
                                    }
                                    break;
                                case 1:
                                    $args = preg_split("/ /", preg_replace("/ Next Learn$/", " NextLearn", preg_replace("/ RetentionTime /", " Retention Hours ", preg_replace("/ Size /", " Size Unit ", $line))), -1, PREG_SPLIT_NO_EMPTY);
                                    $stage = 2;
                                    break;
                                case 2:
                                    if (preg_match("/^---/", $line)) {
                                        $stage = 3;
                                    }
                                    break;
                                case 3:
                                    if (preg_match("/^---/", $line)) {
                                        $stage = 4;
                                    } else {
                                        $values = preg_split("/ /", preg_replace("/ (\d+\/\d+\/\d+) +(\d+:\d+:\d+)$/", " $1-$2", preg_replace("/ hours \+ /", " hours+ ", $line)), -1, PREG_SPLIT_NO_EMPTY);
                                        if (count($values) == count($args)-1) { //no Name
                                            $values[] = "";
                                        }
                                        $diffc = count($values) - count($args);
                                        if (($diffc >= 0) && (count($values) > 4)) {
                                            $valarr = array();
                                            for ($vnr = 0; $vnr < count($args); $vnr++) {
                                                if (($diffc == 0) || (($args[$vnr] !== "Name") && ($args[$vnr] !== "Model"))) {
                                                    $valarr[$args[$vnr]] = $values[$vnr];
                                                } else {
                                                    $valarr[$args[$vnr]] = $values[$vnr];
                                                    break;
                                                }
                                            }
                                            if (($diffc > 0) && ($vnr < count($args))) {
                                                for ($enr = count($values)-1; $enr >= 0; $enr--) {
                                                    if (($args[$enr-$diffc] !== "Name") && ($args[$enr-$diffc] !== "Model")) {
                                                        $valarr[$args[$enr-$diffc]] = $values[$enr];
                                                    } else {
                                                        break;
                                                    }
                                                }
                                                if ($vnr < $enr) {
                                                    for ($xnr = $vnr + 1; $xnr <= $enr; $xnr++) {
                                                        $valarr[$args[$vnr]] .= " ".$values[$xnr];
                                                    }
                                                }
                                            }
                                            $carr[$cnr][$buff[1]]['values'][] = $valarr;
                                        } else {
                                            $stage = 4;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach ($carr as $controller) if (isset($controller["Basics"]["Controller"])
               && (($cnr = $controller["Basics"]["Controller"]) >= 0)) {
                $dg = -1;
                if (isset($controller["TOPOLOGY"]["values"])) foreach ($controller["TOPOLOGY"]["values"] as $topol) {
                    if (isset($topol["Arr"]) && ($topol["Arr"] !== "-")) {
                        if ($topol["DG"] != $dg) {
                            $dg = $topol["DG"];
                            $uname = 'c'.$cnr.'u'.$dg;
                            if (isset($controller["VD".$dg." Properties"]["Strip Size"]) && preg_match("/^(\d+)\s*(\S+)$/", $controller["VD".$dg." Properties"]["Strip Size"], $value)) {
                                switch ($value[2]) {
                                case 'B':
                                    $this->_result[$prog][$uname]['stripe_size'] = $value[1];
                                    break;
                                case 'KB':
                                    $this->_result[$prog][$uname]['stripe_size'] = 1024*$value[1];
                                    break;
                                case 'MB':
                                    $this->_result[$prog][$uname]['stripe_size'] = 1024*1024*$value[1];
                                    break;
                                case 'GB':
                                    $this->_result[$prog][$uname]['stripe_size'] = 1024*1024*1024*$value[1];
                                    break;
                                case 'TB':
                                    $this->_result[$prog][$uname]['stripe_size'] = 1024*1024*1024*1024*$value[1];
                                    break;
                                case 'PB':
                                    $this->_result[$prog][$uname]['stripe_size'] = 1024*1024*1024*1024*1024*$value[1];
                                }
                            }
                            if (isset($controller["VD".$dg." Properties"]["Active Operations"]) && preg_match("/^(.+) \((\d+)%\)/", $controller["VD".$dg." Properties"]["Active Operations"], $progarr)) {
                                //$this->_result[$prog][$uname]['items'][$pname]['status'] = "W";
                                $this->_result[$prog][$uname]['action']['name'] = trim($progarr[1]);
                                $this->_result[$prog][$uname]['action']['percent'] = trim($progarr[2]);
                            }
                            if (isset($controller["Basics"]["Model"])) $this->_result[$prog][$uname]['controller'] = $controller["Basics"]["Model"];
                            if (isset($controller["Version"]["Firmware Package Build"])) $this->_result[$prog][$uname]['firmware'] = $controller["Version"]["Firmware Package Build"];
                            if (isset($controller["Status"]["Controller Status"])) {
                                $this->_result[$prog][$uname]['status'] = $controller["Status"]["Controller Status"];
                            } else {
                                $this->_result[$prog][$uname]['status'] = 'Unknown';
                            }
                            if (isset($controller["HwCfg"]["BBU"]) && ($controller["HwCfg"]["BBU"] === "Present")) {
                                if (isset($controller["BBU_Info"]["values"][0])) {
                                    $bbuinfo = "BBU_Info";
                                } elseif (isset($controller["Cachevault_Info"]["values"][0])) {
                                    $bbuinfo = "Cachevault_Info";
                                } else {
                                    $bbuinfo = "";
                                }
                                if ($bbuinfo !== "") {
                                    if (isset($controller[$bbuinfo]["values"][0]["State"])) {
                                        if (($state = $controller[$bbuinfo]["values"][0]["State"]) === "Optimal") {
                                            $this->_result[$prog][$uname]['battery'] = "good";
                                        } else {
                                            $this->_result[$prog][$uname]['battery'] = $state;
                                        }
                                    }
                                    if (isset($controller[$bbuinfo]["values"][0]["Temp"]) && preg_match("/^(\d+)C$/", $controller[$bbuinfo]["values"][0]["Temp"], $batt)) {
                                        $this->_result[$prog][$uname]['batttemp'] = $batt[1];
                                    }
                                }
                            }
                            if (isset($controller["Capabilities"]["RAID Level Supported"])) $this->_result[$prog][$uname]['supported'] = $controller["Capabilities"]["RAID Level Supported"];
                            if (isset($controller["HwCfg"]["ROC temperature(Degree Celsius)"])) $this->_result[$prog][$uname]['temperature'] = $controller["HwCfg"]["ROC temperature(Degree Celsius)"];
                            if (isset($controller["HwCfg"]["On Board Memory Size"]) && preg_match("/^(\d+)\s*(\S+)$/", $controller["HwCfg"]["On Board Memory Size"], $value)) {
                                switch ($value[2]) {
                                case 'B':
                                    $this->_result[$prog][$uname]['cache_size'] = $value[1];
                                    break;
                                case 'KB':
                                    $this->_result[$prog][$uname]['cache_size'] = 1024*$value[1];
                                    break;
                                case 'MB':
                                    $this->_result[$prog][$uname]['cache_size'] = 1024*1024*$value[1];
                                    break;
                                case 'GB':
                                    $this->_result[$prog][$uname]['cache_size'] = 1024*1024*1024*$value[1];
                                    break;
                                case 'TB':
                                    $this->_result[$prog][$uname]['cache_size'] = 1024*1024*1024*1024*$value[1];
                                    break;
                                case 'PB':
                                    $this->_result[$prog][$uname]['cache_size'] = 1024*1024*1024*1024*1024*$value[1];
                                }
                            }
                            if (isset($controller["HwCfg"]["CacheVault Flash Size"]) && preg_match("/^([\d\.]+)\s*(\S+)$/", $controller["HwCfg"]["CacheVault Flash Size"], $value)) {
                                switch ($value[2]) {
                                case 'B':
                                    $this->_result[$prog][$uname]['cachevault_size'] = $value[1];
                                    break;
                                case 'KB':
                                    $this->_result[$prog][$uname]['cachevault_size'] = 1024*$value[1];
                                    break;
                                case 'MB':
                                    $this->_result[$prog][$uname]['cachevault_size'] = 1024*1024*$value[1];
                                    break;
                                case 'GB':
                                    $this->_result[$prog][$uname]['cachevault_size'] = 1024*1024*1024*$value[1];
                                    break;
                                case 'TB':
                                    $this->_result[$prog][$uname]['cachevault_size'] = 1024*1024*1024*1024*$value[1];
                                    break;
                                case 'PB':
                                    $this->_result[$prog][$uname]['cachevault_size'] = 1024*1024*1024*1024*1024*$value[1];
                                }
                            }
                            if (isset($topol["Size"]) && isset($topol["Unit"])) {
                                switch ($topol["Unit"]) {
                                case 'B':
                                    $this->_result[$prog][$uname]['capacity'] = $topol["Size"];
                                    break;
                                case 'KB':
                                    $this->_result[$prog][$uname]['capacity'] = 1024*$topol["Size"];
                                    break;
                                case 'MB':
                                    $this->_result[$prog][$uname]['capacity'] = 1024*1024*$topol["Size"];
                                    break;
                                    case 'GB':
                                    $this->_result[$prog][$uname]['capacity'] = 1024*1024*1024*$topol["Size"];
                                    break;
                                case 'TB':
                                    $this->_result[$prog][$uname]['capacity'] = 1024*1024*1024*1024*$topol["Size"];
                                    break;
                                case 'PB':
                                    $this->_result[$prog][$uname]['capacity'] = 1024*1024*1024*1024*1024*$topol["Size"];
                                }
                            }
                            if (isset($topol["PDC"])) {
                                switch ($topol["PDC"]) {
                                case 'dflt':
                                    $this->_result[$prog][$uname]['diskcache'] = "default";
                                    break;
                                case 'dsbl':
                                    $this->_result[$prog][$uname]['diskcache'] = "disabled";
                                    break;
                                case 'enbl':
                                    $this->_result[$prog][$uname]['diskcache'] = "enabled";
                                    break;
                                default:
                                    $this->_result[$prog][$uname]['diskcache'] = strtolower($topol["PDC"]);
                                }
                            }
                            if (isset($controller["VD LIST"]["values"])) foreach ($controller["VD LIST"]["values"] as $vdlist) {
                                if (isset($vdlist["DG/VD"])) {
                                    if ($vdlist["DG/VD"] === $dg."/".$dg) {
                                        if (isset($vdlist["TYPE"])) {
                                            $this->_result[$prog][$uname]['items'][-1]['parentid'] = 0;
                                            $this->_result[$prog][$uname]['level'] = $vdlist["TYPE"];
                                            if (isset($vdlist["Name"]) && (trim($vdlist["Name"]) !== "")) {
                                                $this->_result[$prog][$uname]['items'][-1]['name'] = trim($vdlist["Name"]);
                                            } else {
                                                $this->_result[$prog][$uname]['items'][-1]['name'] = $vdlist["TYPE"];
                                            }
                                            if (isset($vdlist["State"])) {
                                                switch ($vdlist["State"]) {
                                                case 'Rec':
                                                    $this->_result[$prog][$uname]['status'] = "Recovery";
                                                    $this->_result[$prog][$uname]['items'][-1]['status'] = "W";
                                                    break;
                                                case 'OfLn':
                                                    $this->_result[$prog][$uname]['status'] = "OffLine";
                                                    $this->_result[$prog][$uname]['items'][-1]['status'] = "F";
                                                    break;
                                                case 'Pdgd':
                                                    $this->_result[$prog][$uname]['status'] = "Partially Degraded";
                                                    $this->_result[$prog][$uname]['items'][-1]['status'] = "W";
                                                    break;
                                                case 'Dgrd':
                                                    $this->_result[$prog][$uname]['status'] = "Degraded";
                                                    $this->_result[$prog][$uname]['items'][-1]['status'] = "W";
                                                    break;
                                                case 'Optl':
                                                    $this->_result[$prog][$uname]['status'] = "Optimal";
                                                    $this->_result[$prog][$uname]['items'][-1]['status'] = "ok";
                                                    break;
                                                default:
                                                    $this->_result[$prog][$uname]['status'] = "Unknown";
                                                    $this->_result[$prog][$uname]['items'][-1]['status'] = "F";
                                                }
                                            }
                                            if (isset($vdlist["Cache"])) {
                                                $ctype = $vdlist["Cache"];
                                                if (preg_match("/^NR/", $ctype)) $this->_result[$prog][$uname]['readpolicy'] = "noReadAhead";
                                                elseif (preg_match("/^R/", $ctype)) $this->_result[$prog][$uname]['readpolicy'] = "readAhead";
                                                elseif (preg_match("/^AR/", $ctype)) $this->_result[$prog][$uname]['readpolicy'] = "adaptiveReadAhead";
                                                if (preg_match("/WT[DC]$/", $ctype)) $this->_result[$prog][$uname]['writepolicy'] = "writeThrough";
                                                elseif (preg_match("/WB[DC]$/", $ctype)) $this->_result[$prog][$uname]['writepolicy'] = "writeBack";
                                                elseif (preg_match("/FWB[DC]$/", $ctype)) $this->_result[$prog][$uname]['writepolicy'] = "writeBackForce";
                                            }
                                        }
                                        break;
                                    }
                                } else {
                                        break;
                                }
                            }
                        } elseif (($dg >= 0) && isset($topol["Row"]) && ($topol["Row"] !== '-')
                           /*&& isset($topol["DID"]) && ($topol["DID"] !== '-'))*/) {
                            $uname = 'c'.$cnr.'u'.$dg;
                            $this->_result[$prog][$uname]['items'][$topol["DID"]]['parentid'] = 1;
                            $this->_result[$prog][$uname]['items'][$topol["DID"]]['name'] = $uname.'p'.($topol["Row"]);
                            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && isset($topol["Size"]) && isset($topol["Unit"])) {
                                switch ($topol["Unit"]) {
                                case 'B':
                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['capacity'] = $topol["Size"];
                                    break;
                                case 'KB':
                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['capacity'] = 1024*$topol["Size"];
                                    break;
                                case 'MB':
                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['capacity'] = 1024*1024*$topol["Size"];
                                    break;
                                case 'GB':
                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['capacity'] = 1024*1024*1024*$topol["Size"];
                                    break;
                                case 'TB':
                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['capacity'] = 1024*1024*1024*1024*$topol["Size"];
                                    break;
                                case 'PB':
                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['capacity'] = 1024*1024*1024*1024*1024*$topol["Size"];
                                }
                            }
                            if (isset($topol["DID"])) {
                                if ($topol["DID"] === '-') {
                                    if (isset($topol["State"]) && ($topol["State"] === "Msng")) {
                                        $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Missing";
                                        $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "E";
                                        $this->_result[$prog][$uname]['items'][$topol["DID"]]['type'] = "disk";
                                     }
                                } elseif (isset($controller["PD LIST"]["values"])) foreach ($controller["PD LIST"]["values"] as $pdlist) {
                                    if (isset($pdlist["DID"])) {
                                        if ($pdlist["DID"] === $topol["DID"]) {
                                            if (isset($pdlist["State"])) {
                                                switch ($pdlist["State"]) {
                                                case 'DHS':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Dedicated Hot Spare";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "S";
                                                    break;
                                                case 'UGood':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Unconfigured Good";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "U";
                                                    break;
                                                case 'GHS':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Global Hotspare";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "S";
                                                    break;
                                                case 'UBad':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Unconfigured Bad";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "F";
                                                    break;
                                                case 'Onln':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Online";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "ok";
                                                    break;
                                                case 'Offln':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Offline";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "F";
                                                    break;
                                                case 'Rbld':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Rebuild";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "W";
                                                    break;
                                                default:
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] = "Unknown";
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['status'] = "F";
                                                }
                                                if (isset($pdlist["Sp"])) {
                                                    switch ($pdlist["Sp"]) {
                                                    case 'U':
                                                        $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] .= ", Spun Up";
                                                        break;
                                                    case 'D':
                                                       $this->_result[$prog][$uname]['items'][$topol["DID"]]['info'] .= ", Spun Down";
                                                    }
                                                }
                                            }
                                            if (isset($pdlist["Med"])) {
                                                switch ($pdlist["Med"]) {
                                                case 'HDD':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['type'] = "disk";
                                                    break;
                                                case 'SSD':
                                                    $this->_result[$prog][$uname]['items'][$topol["DID"]]['type'] = "ssd";
                                                }
                                            }
                                            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                                                if (isset($pdlist["Model"])) $this->_result[$prog][$uname]['items'][$topol["DID"]]['model'] = $pdlist["Model"];
                                                if (isset($pdlist["Intf"])) $this->_result[$prog][$uname]['items'][$topol["DID"]]['bus'] = $pdlist["Intf"];
                                            }
                                            break;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (isset($controller["PD LIST"]["values"])) foreach ($controller["PD LIST"]["values"] as $pdlist) {
                    if (isset($pdlist["DG"]) && preg_match("/\D/", $pdlist["DG"])) {
                        if (isset($pdlist["State"]) && isset($pdlist["DID"])) {
                            $cname = '';
                            switch ($pdlist["State"]) {
                            case 'DHS':
                                $cname = 'c'.$cnr.'-hotspare';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "S";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "Dedicated Hot Spare";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "S";
                                break;
                            case 'UGood':
                                $cname = 'c'.$cnr.'-unconfigured';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "U";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "Unconfigured Good";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "U";
                                $this->_result[$prog][$cname]['status'] = "Unconfigured";
                                break;
                            case 'GHS':
                                $cname = 'c'.$cnr.'-hotspare';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "S";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "Global Hotspare";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "S";
                                $this->_result[$prog][$cname]['status'] = "Hotspare";
                                break;
                            case 'UBad':
                                $cname = 'c'.$cnr.'-unconfigured';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "U";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "Unconfigured Bad";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "F";
                                $this->_result[$prog][$cname]['status'] = "Unconfigured";
                                break;
                          /*  case 'Onln':
                                $cname = 'c'.$cnr.'-online';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "ok";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "Online";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "ok";
                                $this->_result[$prog][$cname]['status'] = "Online";
                                break;*/
                            case 'Offln':
                                $cname = 'c'.$cnr.'-offine';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "F";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "Offline";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "F";
                                $this->_result[$prog][$cname]['status'] = "Offline";
                                break;
                            case 'JBOD':
                                $cname = 'c'.$cnr.'-jbod';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "ok";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "JBOD";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "ok";
                                $this->_result[$prog][$cname]['level'] = "JBOD";
                                $this->_result[$prog][$cname]['status'] = "JBOD";
                                break;
                            default:
                                $cname = 'c'.$cnr.'-unknown';
                                $this->_result[$prog][$cname]['items'][-1]['status'] = "F";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] = "Unknown";
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['status'] = "F";
                                $this->_result[$prog][$cname]['status'] = "Unknown";
                            }
                            if ($cname !== '') {
                                $this->_result[$prog][$cname]['items'][-1]['parentid'] = 0;
                                $this->_result[$prog][$cname]['items'][-1]['name'] = $this->_result[$prog][$cname]['status'];
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['parentid'] = 1;
                                $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['name'] = 'c'.$cnr.'p'.$pdlist["DID"];
                                if (isset($pdlist["Med"])) {
                                    switch ($pdlist["Med"]) {
                                    case 'HDD':
                                        $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['type'] = "disk";
                                        break;
                                    case 'SSD':
                                        $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['type'] = "ssd";
                                    }
                                }
                                if (isset($pdlist["Sp"])) {
                                    switch ($pdlist["Sp"]) {
                                    case 'U':
                                        $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] .= ", Spun Up";
                                        break;
                                    case 'D':
                                        $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['info'] .= ", Spun Down";
                                    }
                                }
                                if (isset($controller["Basics"]["Model"])) $this->_result[$prog][$cname]['controller'] = $controller["Basics"]["Model"];
                                if (isset($controller["Version"]["Firmware Package Build"])) $this->_result[$prog][$cname]['firmware'] = $controller["Version"]["Firmware Package Build"];
                                if (isset($controller["Status"]["Controller Status"])) {
                                    $this->_result[$prog][$cname]['status'] = $controller["Status"]["Controller Status"];
                                } else {
                                    $this->_result[$prog][$cname]['status'] = 'Unknown';
                                }
                                if (isset($controller["HwCfg"]["BBU"]) && ($controller["HwCfg"]["BBU"] === "Present")) {
                                    if (isset($controller["BBU_Info"]["values"][0])) {
                                        $bbuinfo = "BBU_Info";
                                    } elseif (isset($controller["Cachevault_Info"]["values"][0])) {
                                        $bbuinfo = "Cachevault_Info";
                                    } else {
                                        $bbuinfo = "";
                                    }
                                    if ($bbuinfo !== "") {
                                        if (isset($controller[$bbuinfo]["values"][0]["State"])) {
                                            if (($state = $controller[$bbuinfo]["values"][0]["State"]) === "Optimal") {
                                                $this->_result[$prog][$cname]['battery'] = "good";
                                            } else {
                                                $this->_result[$prog][$cname]['battery'] = $state;
                                            }
                                        }
                                        if (isset($controller[$bbuinfo]["values"][0]["Temp"]) && preg_match("/^(\d+)C$/", $controller[$bbuinfo]["values"][0]["Temp"], $batt)) {
                                            $this->_result[$prog][$cname]['batttemp'] = $batt[1];
                                        }
                                    }
                                }
                                if (isset($controller["Capabilities"]["RAID Level Supported"])) $this->_result[$prog][$cname]['supported'] = $controller["Capabilities"]["RAID Level Supported"];
                                if (isset($controller["HwCfg"]["On Board Memory Size"]) && preg_match("/^(\d+)\s*(\S+)$/", $controller["HwCfg"]["On Board Memory Size"], $value)) {
                                    switch ($value[2]) {
                                    case 'B':
                                        $this->_result[$prog][$cname]['cache_size'] = $value[1];
                                        break;
                                    case 'KB':
                                        $this->_result[$prog][$cname]['cache_size'] = 1024*$value[1];
                                        break;
                                    case 'MB':
                                        $this->_result[$prog][$cname]['cache_size'] = 1024*1024*$value[1];
                                        break;
                                    case 'GB':
                                        $this->_result[$prog][$cname]['cache_size'] = 1024*1024*1024*$value[1];
                                        break;
                                    case 'TB':
                                        $this->_result[$prog][$cname]['cache_size'] = 1024*1024*1024*1024*$value[1];
                                        break;
                                    case 'PB':
                                        $this->_result[$prog][$cname]['cache_size'] = 1024*1024*1024*1024*1024*$value[1];
                                    }
                                }
                                if (isset($controller["HwCfg"]["CacheVault Flash Size"]) && preg_match("/^([\d\.]+)\s*(\S+)$/", $controller["HwCfg"]["CacheVault Flash Size"], $value)) {
                                    switch ($value[2]) {
                                    case 'B':
                                        $this->_result[$prog][$cname]['cachevault_size'] = $value[1];
                                        break;
                                    case 'KB':
                                        $this->_result[$prog][$cname]['cachevault_size'] = 1024*$value[1];
                                        break;
                                    case 'MB':
                                        $this->_result[$prog][$cname]['cachevault_size'] = 1024*1024*$value[1];
                                        break;
                                    case 'GB':
                                        $this->_result[$prog][$cname]['cachevault_size'] = 1024*1024*1024*$value[1];
                                        break;
                                    case 'TB':
                                        $this->_result[$prog][$cname]['cachevault_size'] = 1024*1024*1024*1024*$value[1];
                                        break;
                                    case 'PB':
                                        $this->_result[$prog][$cname]['cachevault_size'] = 1024*1024*1024*1024*1024*$value[1];
                                    }
                                }

                                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                                    if (isset($pdlist["Size"]) && isset($pdlist["Unit"])) {
                                        switch ($pdlist["Unit"]) {
                                        case 'B':
                                            $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['capacity'] = $pdlist["Size"];
                                            break;
                                        case 'KB':
                                            $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['capacity'] = 1024*$pdlist["Size"];
                                            break;
                                        case 'MB':
                                            $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['capacity'] = 1024*1024*$pdlist["Size"];
                                            break;
                                        case 'GB':
                                            $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['capacity'] = 1024*1024*1024*$pdlist["Size"];
                                            break;
                                        case 'TB':
                                            $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['capacity'] = 1024*1024*1024*1024*$pdlist["Size"];
                                            break;
                                        case 'PB':
                                            $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['capacity'] = 1024*1024*1024*1024*1024*$pdlist["Size"];
                                        }
                                    }
                                    if (isset($pdlist["Model"])) $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['model'] = $pdlist["Model"];
                                    if (isset($pdlist["Intf"])) $this->_result[$prog][$cname]['items'][$pdlist["DID"]]['bus'] = $pdlist["Intf"];
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * doing all tasks to get the required informations that the plugin needs
     * result is stored in an internal array<br>the array is build like a tree,
     * so that it is possible to get only a specific process with the childs
     *
     * @return void
     */
    public function execute()
    {
        if (count($this->_filecontent)>0) {
            foreach ($this->prog_items as $item) if (isset($this->_filecontent[$item])) {
                if ($item !== 'idrac') {
                    if ((($buffer = $this->_filecontent[$item]) !== null) && (($buffer = trim($buffer)) != "")) {
                        switch ($item) {
                        case 'mdstat':
                            $this->execute_mdstat($buffer);
                            break;
                        case 'dmraid':
                            $this->execute_dmraid($buffer);
                            break;
                        case 'megactl':
                            $this->execute_megactl($buffer, false);
                            break;
                        case 'megasasctl':
                            $this->execute_megactl($buffer, true);
                            break;
                        case 'megaclisas-status':
                            $this->execute_status($buffer, false);
                            break;
                        case '3ware-status':
                            $this->execute_status($buffer, true);
                            break;
                        case 'graid':
                            $this->execute_graid($buffer);
                            break;
                        case 'zpool':
                            $this->execute_zpool($buffer);
                            break;
                        case 'storcli':
                            $this->execute_storcli($buffer, false);
                            break;
                        case 'perccli':
                            $this->execute_storcli($buffer, true);
                        }
                    }
                } else {
                    if (is_array($this->_filecontent[$item])) {
                        foreach ($this->_filecontent[$item] as $device=>$buffer) if (($buffer = trim($buffer)) != "") {
                            $this->execute_idrac($buffer, /*'idrac-'.*/$device);
                        }
                    }
                }
            }
        }
    }

    /**
     * generates the XML content for the plugin
     *
     * @return SimpleXMLElement entire XML content for the plugin
     */
    public function xml()
    {
        if (empty($this->_result)) {
            return $this->xml->getSimpleXmlElement();
        }
        $hideRaids = array();
        if (defined('PSI_PLUGIN_RAID_HIDE_DEVICES') && is_string(PSI_PLUGIN_RAID_HIDE_DEVICES)) {
            if (preg_match(ARRAY_EXP, PSI_PLUGIN_RAID_HIDE_DEVICES)) {
                $hideRaids = eval(PSI_PLUGIN_RAID_HIDE_DEVICES);
            } else {
                $hideRaids = array(PSI_PLUGIN_RAID_HIDE_DEVICES);
            }
        }

        foreach ($this->prog_items as $item) if (isset($this->_result[$item])) {
            foreach ($this->_result[$item] as $key=>$device) {
                if (!in_array($key, $hideRaids, true)) {
                    $dev = $this->xml->addChild("Raid");
                    $dev->addAttribute("Device_Name", $key);
                    $dev->addAttribute("Program", $item);
                    if (isset($device['level'])) $dev->addAttribute("Level", strtolower($device["level"]));
                    $dev->addAttribute("Status", strtolower($device["status"]));
                    if (isset($device['name'])) $dev->addAttribute("Name", $device["name"]);
                    if (isset($device['capacity'])) $dev->addAttribute("Capacity", $device["capacity"]);
                    if (isset($device['stride'])) $dev->addAttribute("Stride", $device["stride"]);
                    if (isset($device['subsets'])) $dev->addAttribute("Subsets", $device["subsets"]);
                    if (isset($device['devs'])) $dev->addAttribute("Devs", $device["devs"]);
                    if (isset($device['spares'])) $dev->addAttribute("Spares", $device["spares"]);

                    if (isset($device['chunk_size'])) $dev->addAttribute("Chunk_Size", $device["chunk_size"]);
                    if (isset($device['stripe_size'])) $dev->addAttribute("Stripe_Size", $device["stripe_size"]);
                    if (isset($device['pers_superblock'])) $dev->addAttribute("Persistend_Superblock", $device["pers_superblock"]);
                    if (isset($device['algorithm'])) $dev->addAttribute("Algorithm", $device["algorithm"]);
                    if (isset($device['registered'])) $dev->addAttribute("Disks_Registered", $device["registered"]);
                    if (isset($device['active'])) $dev->addAttribute("Disks_Active", $device["active"]);
                    if (isset($device['controller'])) $dev->addAttribute("Controller", $device["controller"]);
                    if (isset($device['firmware'])) $dev->addAttribute("Firmware", $device["firmware"]);
                    if (isset($device['temperature'])) $dev->addAttribute("Temperature", $device["temperature"]);
                    if (isset($device['battery'])) $dev->addAttribute("Battery", $device["battery"]);
                    if (isset($device['battvolt'])) $dev->addAttribute("Batt_Volt", $device["battvolt"]);
                    if (isset($device['batttemp'])) $dev->addAttribute("Batt_Temp", $device["batttemp"]);
                    if (isset($device['supported'])) $dev->addAttribute("Supported", $device["supported"]);
                    if (isset($device['readpolicy'])) $dev->addAttribute("ReadPolicy", $device["readpolicy"]);
                    if (isset($device['writepolicy'])) $dev->addAttribute("WritePolicy", $device["writepolicy"]);
                    if (isset($device['cache_size'])) $dev->addAttribute("Cache_Size", $device["cache_size"]);
                    if (isset($device['cachevault_size'])) $dev->addAttribute("Cachevault_Size", $device["cachevault_size"]);
                    if (isset($device['diskcache'])) $dev->addAttribute("DiskCache", $device["diskcache"]);
                    if (isset($device['bad_blocks'])) $dev->addAttribute("Bad_Blocks", $device["bad_blocks"]);

                    if (isset($device['action'])) {
                        $action = $dev->addChild("Action");
                        $action->addAttribute("Name", $device['action']['name']);
                        if (isset($device['action']['percent'])) $action->addAttribute("Percent", $device['action']['percent']);

                        if (isset($device['action']['finish_time'])) $action->addAttribute("Time_To_Finish", $device['action']['finish_time']);
                        if (isset($device['action']['finish_unit'])) $action->addAttribute("Time_Unit", $device['action']['finish_unit']);

                    }
                    $disks = $dev->addChild("RaidItems");
                    if (isset($device['items']) && (sizeof($device['items'])>0)) foreach ($device['items'] as $disk) {
                        if (isset($disk['name'])) {
                            $disktemp = $disks->addChild("Item");
                            $disktemp->addAttribute("Name", $disk['name']);
                            // if (isset($disk['raid_index'])) $disktemp->addAttribute("Index", $disk['raid_index']);
                            if (isset($disk['parentid'])) $disktemp->addAttribute("ParentID", $disk['parentid']);
                            if (isset($disk['type'])) $disktemp->addAttribute("Type", $disk['type']);
                            // if (in_array(strtolower($device["status"]), array('ok', 'optimal', 'active', 'online', 'degraded'))) {
                            if (isset($disk['status'])) $disktemp->addAttribute("Status", $disk['status']);
                            //} else {
                            //    $disktemp->addAttribute("Status", "W");
                            //}
                            if (isset($disk['info'])) $disktemp->addAttribute("Info", $disk['info']);
                            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
                                if (isset($disk['bus'])) $disktemp->addAttribute("Bus", $disk['bus']);
                                if (isset($disk['capacity'])) $disktemp->addAttribute("Capacity", $disk['capacity']);
                                if (isset($disk['model'])) $disktemp->addAttribute("Model", $disk['model']);
                                if (isset($disk['temperature'])) $disktemp->addAttribute("Temperature", $disk['temperature']);
                                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
                                    if (isset($disk['serial'])) $disktemp->addAttribute("Serial", $disk['serial']);
                                }
                            }
                        }
                    }
                }
            }
            $this->_result[$item] = array(); // clear preventing duplicate items
        }

        return $this->xml->getSimpleXmlElement();
    }
}