PageRenderTime 85ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/discovery/hr-device.inc.php

https://bitbucket.org/MelFlynn/observium
PHP | 61 lines | 53 code | 8 blank | 0 comment | 12 complexity | 09f5deb9dc8044a4a6183c0cdd2475c6 MD5 | raw file
Possible License(s): GPL-3.0, MIT
  1. <?php
  2. echo("hrDevice : ");
  3. $hrDevice_oids = array('hrDeviceEntry','hrProcessorEntry');
  4. if ($debug) { print_r($hrDevices); }
  5. $hrDevices = array();
  6. foreach ($hrDevice_oids as $oid) { $hrDevices = snmpwalk_cache_oid($device, $oid, $hrDevices, "HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES"); }
  7. if ($debug) { print_r($hrDevices); }
  8. if (is_array($hrDevices))
  9. {
  10. $hrDevices = $hrDevices;
  11. foreach ($hrDevices as $hrDevice)
  12. {
  13. if (is_array($hrDevice) && is_numeric($hrDevice['hrDeviceIndex']))
  14. {
  15. if (mysql_result(mysql_query("SELECT COUNT(*) FROM `hrDevice` WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrDevice['hrDeviceIndex']."'"),0))
  16. {
  17. $update_query = "UPDATE `hrDevice` SET";
  18. $update_query .= " `hrDeviceType` = '".mres($hrDevice[hrDeviceType])."'";
  19. $update_query .= ", `hrDeviceDescr` = '".mres($hrDevice[hrDeviceDescr])."'";
  20. $update_query .= ", `hrDeviceStatus` = '".mres($hrDevice[hrDeviceStatus])."'";
  21. $update_query .= ", `hrDeviceErrors` = '".mres($hrDevice[hrDeviceErrors])."'";
  22. if ($hrDevice['hrDeviceType'] == "hrDeviceProcessor")
  23. {
  24. $update_query .= ", `hrProcessorLoad` = '".mres($hrDevice[hrProcessorLoad])."'";
  25. }
  26. $update_query .= " WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrDevice['hrDeviceIndex']."'";
  27. @mysql_query($update_query); echo(".");
  28. }
  29. else
  30. {
  31. $insert_query = "INSERT INTO `hrDevice` (`hrDeviceIndex`,`device_id`,`hrDeviceType`,`hrDeviceDescr`,`hrDeviceStatus`,`hrDeviceErrors`) ";
  32. $insert_query .= " VALUES ('".mres($hrDevice[hrDeviceIndex])."','".mres($device[device_id])."','".mres($hrDevice[hrDeviceType])."','".mres($hrDevice[hrDeviceDescr])."','".mres($hrDevice[hrDeviceStatus])."','".mres($hrDevice[hrDeviceErrors])."')";
  33. @mysql_query($insert_query); echo("+");
  34. if ($debug) { print_r($hrDevice); echo("$insert_query" . mysql_affected_rows() . " row inserted"); }
  35. }
  36. $valid_hrDevice[$hrDevice['hrDeviceIndex']] = 1;
  37. }
  38. }
  39. }
  40. $sql = "SELECT * FROM `hrDevice` WHERE `device_id` = '".$device['device_id']."'";
  41. $query = mysql_query($sql);
  42. while ($test_hrDevice = mysql_fetch_assoc($query))
  43. {
  44. if (!$valid_hrDevice[$test_hrDevice['hrDeviceIndex']])
  45. {
  46. echo("-");
  47. mysql_query("DELETE FROM `hrDevice` WHERE hrDevice_id = '" . $test_hrDevice['hrDevice_id'] . "'");
  48. if ($debug) { print_r($test_hrDevice); echo(mysql_affected_rows() . " row deleted"); }
  49. }
  50. }
  51. unset($valid_hrDevice);
  52. echo("\n");
  53. ?>