1 | <?php |
||
2 | |||
3 | $hrDevice_oids = [ |
||
4 | 'hrDeviceEntry', |
||
5 | 'hrProcessorEntry', |
||
6 | ]; |
||
7 | d_echo($hrDevices); |
||
8 | |||
9 | $hrDevices = []; |
||
10 | foreach ($hrDevice_oids as $oid) { |
||
11 | $hrDevices = snmpwalk_cache_oid($device, $oid, $hrDevices, 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES'); |
||
12 | } |
||
13 | |||
14 | d_echo($hrDevices); |
||
15 | |||
16 | if (is_array($hrDevices)) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
17 | foreach ($hrDevices as $hrDevice) { |
||
18 | if (is_array($hrDevice) && is_numeric($hrDevice['hrDeviceIndex'])) { |
||
19 | if (dbFetchCell('SELECT COUNT(*) FROM `hrDevice` WHERE device_id = ? AND hrDeviceIndex = ?', [$device['device_id'], $hrDevice['hrDeviceIndex']])) { |
||
20 | $update_array = [ |
||
21 | 'hrDeviceType' => $hrDevice['hrDeviceType'], |
||
22 | 'hrDeviceDescr' => $hrDevice['hrDeviceDescr'], |
||
23 | 'hrDeviceStatus' => $hrDevice['hrDeviceStatus'], |
||
24 | 'hrDeviceErrors' => $hrDevice['hrDeviceErrors'], |
||
25 | ]; |
||
26 | if ($hrDevice['hrDeviceType'] == 'hrDeviceProcessor') { |
||
27 | $update_array['hrProcessorLoad'] = $hrDevice['hrProcessorLoad']; |
||
28 | } |
||
29 | |||
30 | dbUpdate($update_array, 'hrDevice', 'device_id=? AND hrDeviceIndex=?', [$device['device_id'], $hrDevice['hrDeviceIndex']]); |
||
31 | echo '.'; |
||
32 | } else { |
||
33 | $inserted_rows = dbInsert(['hrDeviceIndex' => $hrDevice['hrDeviceIndex'], 'device_id' => $device['device_id'], 'hrDeviceType' => $hrDevice['hrDeviceType'], 'hrDeviceDescr' => $hrDevice['hrDeviceDescr'], 'hrDeviceStatus' => $hrDevice['hrDeviceStatus'], 'hrDeviceErrors' => (int) $hrDevice['hrDeviceErrors']], 'hrDevice'); |
||
34 | echo '+'; |
||
35 | d_echo($hrDevice); |
||
36 | d_echo("$inserted_rows row inserted"); |
||
37 | }//end if |
||
38 | |||
39 | $valid_hrDevice[$hrDevice['hrDeviceIndex']] = 1; |
||
40 | }//end if |
||
41 | }//end foreach |
||
42 | }//end if |
||
43 | |||
44 | $sql = "SELECT * FROM `hrDevice` WHERE `device_id` = '" . $device['device_id'] . "'"; |
||
45 | |||
46 | foreach (dbFetchRows($sql) as $test_hrDevice) { |
||
47 | if (! $valid_hrDevice[$test_hrDevice['hrDeviceIndex']]) { |
||
48 | echo '-'; |
||
49 | dbDelete('hrDevice', '`hrDevice_id` = ?', [$test_hrDevice['hrDevice_id']]); |
||
50 | d_echo($test_hrDevice); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | unset($valid_hrDevice); |
||
55 | echo "\n"; |
||
56 |