PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/discovery/entity-physical.inc.php

https://bitbucket.org/MelFlynn/observium
PHP | 88 lines | 66 code | 18 blank | 4 comment | 14 complexity | 098ed073668ef34e1d435f434b654b8f MD5 | raw file
Possible License(s): GPL-3.0, MIT
  1. <?php
  2. echo("Physical Inventory : ");
  3. if ($config['enable_inventory']) {
  4. echo("\nCaching OIDs:");
  5. $entity_array = array();
  6. echo(" entPhysicalEntry");
  7. $entity_array = snmpwalk_cache_oid($device, "entPhysicalEntry", $entity_array, "ENTITY-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB");
  8. echo(" entAliasMappingIdentifier");
  9. $entity_array = snmpwalk_cache_twopart_oid($device, "entAliasMappingIdentifier", $entity_array, "ENTITY-MIB:IF-MIB");
  10. foreach ($entity_array as $entPhysicalIndex => $entry) {
  11. $entPhysicalDescr = $entry['entPhysicalDescr'];
  12. $entPhysicalContainedIn = $entry['entPhysicalContainedIn'];
  13. $entPhysicalClass = $entry['entPhysicalClass'];
  14. $entPhysicalName = $entry['entPhysicalName'];
  15. $entPhysicalSerialNum = $entry['entPhysicalSerialNum'];
  16. $entPhysicalModelName = $entry['entPhysicalModelName'];
  17. $entPhysicalMfgName = $entry['entPhysicalMfgName'];
  18. $entPhysicalVendorType = $entry['entPhysicalVendorType'];
  19. $entPhysicalParentRelPos = $entry['entPhysicalParentRelPos'];
  20. $entPhysicalHardwareRev = $entry['entPhysicalHardwareRev'];
  21. $entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
  22. $entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
  23. $entPhysicalIsFRU = $entry['entPhysicalIsFRU'];
  24. $entPhysicalAlias = $entry['entPhysicalAlias'];
  25. $entPhysicalAssetID = $entry['entPhysicalAssetID'];
  26. if (isset($entity_array['$entPhysicalIndex']['0']['entAliasMappingIdentifier'])) { $ifIndex = $entity_array['$entPhysicalIndex']['0']['entAliasMappingIdentifier']; }
  27. # $ent_data = $config['snmpget'] . " -M ".$config['mibdir']." -m ENTITY-MIB:IF-MIB -Ovqs -";
  28. # $ent_data .= $device['snmpver'] . " -M ".$config['mibdir']." -c " . $device['community'] . " " . $device['hostname'] .":".$device['port'];
  29. # $ent_data .= " entAliasMappingIdentifier." . $entPhysicalIndex. ".0";
  30. # $ifIndex = shell_exec($ent_data);
  31. if (!strpos($ifIndex, "fIndex") || $ifIndex == "") { unset($ifIndex); }
  32. list(,$ifIndex) = explode(".", $ifIndex);
  33. if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName)
  34. {
  35. $entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];
  36. }
  37. if ($entPhysicalDescr || $entPhysicalName)
  38. {
  39. $entPhysical_id = @mysql_result(mysql_query("SELECT entPhysical_id FROM `entPhysical` WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'"),0);
  40. if ($entPhysical_id) {
  41. $sql = "UPDATE `entPhysical` SET `ifIndex` = '$ifIndex'";
  42. $sql .= ", entPhysicalIndex = '$entPhysicalIndex', entPhysicalDescr = '$entPhysicalDescr', entPhysicalClass = '$entPhysicalClass', entPhysicalName = '$entPhysicalName'";
  43. $sql .= ", entPhysicalModelName = '$entPhysicalModelName', entPhysicalSerialNum = '$entPhysicalSerialNum', entPhysicalContainedIn = '$entPhysicalContainedIn'";
  44. $sql .= ", entPhysicalMfgName = '$entPhysicalMfgName', entPhysicalParentRelPos = '$entPhysicalParentRelPos', entPhysicalVendorType = '$entPhysicalVendorType'";
  45. $sql .= ", entPhysicalHardwareRev = '$entPhysicalHardwareRev', entPhysicalFirmwareRev = '$entPhysicalFirmwareRev', entPhysicalSoftwareRev = '$entPhysicalSoftwareRev'";
  46. $sql .= ", entPhysicalIsFRU = '$entPhysicalIsFRU', entPhysicalAlias = '$entPhysicalAlias', entPhysicalAssetID = '$entPhysicalAssetID'";
  47. $sql .= " WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'";
  48. mysql_query($sql);
  49. echo(".");
  50. } else {
  51. $sql = "INSERT INTO `entPhysical` (`device_id` , `entPhysicalIndex` , `entPhysicalDescr` , `entPhysicalClass` , `entPhysicalName` , `entPhysicalModelName` , `entPhysicalSerialNum` , `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalVendorType`, `entPhysicalHardwareRev`,`entPhysicalFirmwareRev`,`entPhysicalSoftwareRev`,`entPhysicalIsFRU`,`entPhysicalAlias`,`entPhysicalAssetID`, `ifIndex`) ";
  52. $sql .= "VALUES ( '" . $device['device_id'] . "', '$entPhysicalIndex', '$entPhysicalDescr', '$entPhysicalClass', '$entPhysicalName', '$entPhysicalModelName', '$entPhysicalSerialNum', '$entPhysicalContainedIn', '$entPhysicalMfgName','$entPhysicalParentRelPos' , '$entPhysicalVendorType', '$entPhysicalHardwareRev', '$entPhysicalFirmwareRev', '$entPhysicalSoftwareRev', '$entPhysicalIsFRU', '$entPhysicalAlias', '$entPhysicalAssetID', '$ifIndex')";
  53. mysql_query($sql);
  54. echo("+");
  55. }
  56. $valid[$entPhysicalIndex] = 1;
  57. }
  58. }
  59. } else { echo("Disabled!"); }
  60. $sql = "SELECT * FROM `entPhysical` WHERE `device_id` = '".$device['device_id']."'";
  61. $query = mysql_query($sql);
  62. while ($test = mysql_fetch_assoc($query)) {
  63. $id = $test['entPhysicalIndex'];
  64. if (!$valid[$id]) {
  65. echo("-");
  66. mysql_query("DELETE FROM `entPhysical` WHERE entPhysical_id = '".$test['entPhysical_id']."'");
  67. }
  68. }
  69. echo("\n");
  70. ?>