Add Juniper inventory support

This commit is contained in:
Chris Freas
2015-04-17 14:59:47 -04:00
parent a608d7648d
commit ab45804e62

View File

@@ -1,123 +1,160 @@
<?php <?php
echo("Physical Inventory : "); if ($config['enable_inventory']) {
if ($config['enable_inventory']) { echo("Physical Inventory : ");
echo("\nCaching OIDs:"); echo("\nCaching OIDs:");
$entity_array = array(); if ($device['os'] == 'junos') {
echo(" entPhysicalEntry");
$entity_array = snmpwalk_cache_oid($device, "entPhysicalEntry", $entity_array, "ENTITY-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB");
echo(" entAliasMappingIdentifier");
$entity_array = snmpwalk_cache_twopart_oid($device, "entAliasMappingIdentifier", $entity_array, "ENTITY-MIB:IF-MIB");
foreach ($entity_array as $entPhysicalIndex => $entry) { $entity_array = array();
echo(" jnxBoxAnatomy");
$entPhysicalDescr = $entry['entPhysicalDescr']; $entity_array = snmpwalk_cache_oid($device, "jnxBoxAnatomy", $entity_array, "JUNIPER-MIB");
$entPhysicalContainedIn = $entry['entPhysicalContainedIn'];
$entPhysicalClass = $entry['entPhysicalClass'];
$entPhysicalName = $entry['entPhysicalName'];
$entPhysicalSerialNum = $entry['entPhysicalSerialNum'];
$entPhysicalModelName = $entry['entPhysicalModelName'];
$entPhysicalMfgName = $entry['entPhysicalMfgName'];
$entPhysicalVendorType = $entry['entPhysicalVendorType'];
$entPhysicalParentRelPos = $entry['entPhysicalParentRelPos'];
$entPhysicalHardwareRev = $entry['entPhysicalHardwareRev'];
$entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
$entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
$entPhysicalIsFRU = $entry['entPhysicalIsFRU'];
$entPhysicalAlias = $entry['entPhysicalAlias'];
$entPhysicalAssetID = $entry['entPhysicalAssetID'];
if (isset($entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier'])) {
$ifIndex = $entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier'];
}
if (!strpos($ifIndex, "fIndex") || $ifIndex == "") {
unset($ifIndex);
} else { } else {
$ifIndex_array = explode(".", $ifIndex);
$ifIndex = $ifIndex_array[1]; $entity_array = array();
echo(" entPhysicalEntry");
$entity_array = snmpwalk_cache_oid($device, "entPhysicalEntry", $entity_array, "ENTITY-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB");
echo(" entAliasMappingIdentifier");
$entity_array = snmpwalk_cache_twopart_oid($device, "entAliasMappingIdentifier", $entity_array, "ENTITY-MIB:IF-MIB");
} }
if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName) foreach ($entity_array as $entPhysicalIndex => $entry) {
{
$entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];
}
// FIXME - dbFacile if ($device['os'] == 'junos') {
if ($entPhysicalDescr || $entPhysicalName) // Juniper's MIB doesn't have the same objects as the Entity MIB, so some values
{ // are made up here.
$entPhysical_id = dbFetchCell("SELECT entPhysical_id FROM `entPhysical` WHERE device_id = ? AND entPhysicalIndex = ?",array($device['device_id'], $entPhysicalIndex)); $entPhysicalDescr = $entry['jnxContentsDescr'];
$entPhysicalContainedIn = $entry['jnxContainersWithin'];
$entPhysicalClass = $entry['jnxBoxClass'];
$entPhysicalName = $entry['jnxOperatingDescr'];
$entPhysicalSerialNum = $entry['jnxContentsSerialNo'];
$entPhysicalModelName = $entry['jnxContentsPartNo'];
$entPhysicalMfgName = 'Juniper';
$entPhysicalVendorType = 'Juniper';
$entPhysicalParentRelPos = -1;
$entPhysicalHardwareRev = $entry['jnxContentsRevision'];
$entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
$entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
$entPhysicalIsFRU = $entry['jnxFruType'];
$entPhysicalAlias = $entry['entPhysicalAlias'];
$entPhysicalAssetID = $entry['entPhysicalAssetID'];
} else {
if ($entPhysical_id) { $entPhysicalDescr = $entry['entPhysicalDescr'];
$update_data = array( $entPhysicalContainedIn = $entry['entPhysicalContainedIn'];
'entPhysicalIndex' => $entPhysicalIndex, $entPhysicalClass = $entry['entPhysicalClass'];
'entPhysicalDescr' => $entPhysicalDescr, $entPhysicalName = $entry['entPhysicalName'];
'entPhysicalClass' => $entPhysicalClass, $entPhysicalSerialNum = $entry['entPhysicalSerialNum'];
'entPhysicalName' => $entPhysicalName, $entPhysicalModelName = $entry['entPhysicalModelName'];
'entPhysicalModelName' => $entPhysicalModelName, $entPhysicalMfgName = $entry['entPhysicalMfgName'];
'entPhysicalSerialNum' => $entPhysicalSerialNum, $entPhysicalVendorType = $entry['entPhysicalVendorType'];
'entPhysicalContainedIn' => $entPhysicalContainedIn, $entPhysicalParentRelPos = $entry['entPhysicalParentRelPos'];
'entPhysicalMfgName' => $entPhysicalMfgName, $entPhysicalHardwareRev = $entry['entPhysicalHardwareRev'];
'entPhysicalParentRelPos' => $entPhysicalParentRelPos, $entPhysicalFirmwareRev = $entry['entPhysicalFirmwareRev'];
'entPhysicalVendorType' => $entPhysicalVendorType, $entPhysicalSoftwareRev = $entry['entPhysicalSoftwareRev'];
'entPhysicalHardwareRev' => $entPhysicalHardwareRev, $entPhysicalIsFRU = $entry['entPhysicalIsFRU'];
'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev, $entPhysicalAlias = $entry['entPhysicalAlias'];
'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev, $entPhysicalAssetID = $entry['entPhysicalAssetID'];
'entPhysicalIsFRU' => $entPhysicalIsFRU, }
'entPhysicalAlias' => $entPhysicalAlias,
'entPhysicalAssetID' => $entPhysicalAssetID
);
dbUpdate($update_data, 'entPhysical', 'device_id=? AND entPhysicalIndex=?',array($device['device_id'],$entPhysicalIndex));
echo(".");
} else {
$insert_data = array(
'device_id' => $device['device_id'],
'entPhysicalIndex' => $entPhysicalIndex,
'entPhysicalDescr' => $entPhysicalDescr,
'entPhysicalClass' => $entPhysicalClass,
'entPhysicalName' => $entPhysicalName,
'entPhysicalModelName' => $entPhysicalModelName,
'entPhysicalSerialNum' => $entPhysicalSerialNum,
'entPhysicalContainedIn' => $entPhysicalContainedIn,
'entPhysicalMfgName' => $entPhysicalMfgName,
'entPhysicalParentRelPos' => $entPhysicalParentRelPos,
'entPhysicalVendorType' => $entPhysicalVendorType,
'entPhysicalHardwareRev' => $entPhysicalHardwareRev,
'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev,
'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev,
'entPhysicalIsFRU' => $entPhysicalIsFRU,
'entPhysicalAlias' => $entPhysicalAlias,
'entPhysicalAssetID' => $entPhysicalAssetID
);
if (!empty($ifIndex)) { if (isset($entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier'])) {
$insert_data['ifIndex'] = $ifIndex; $ifIndex = $entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier'];
}
if (!strpos($ifIndex, "fIndex") || $ifIndex == "") {
unset($ifIndex);
} else {
$ifIndex_array = explode(".", $ifIndex);
$ifIndex = $ifIndex_array[1];
}
if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName) {
$entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];
}
// FIXME - dbFacile
if ($entPhysicalDescr || $entPhysicalName) {
$entPhysical_id = dbFetchCell("SELECT entPhysical_id FROM `entPhysical` WHERE device_id = ? AND entPhysicalIndex = ?",array($device['device_id'], $entPhysicalIndex));
if ($entPhysical_id) {
$update_data = array(
'entPhysicalIndex' => $entPhysicalIndex,
'entPhysicalDescr' => $entPhysicalDescr,
'entPhysicalClass' => $entPhysicalClass,
'entPhysicalName' => $entPhysicalName,
'entPhysicalModelName' => $entPhysicalModelName,
'entPhysicalSerialNum' => $entPhysicalSerialNum,
'entPhysicalContainedIn' => $entPhysicalContainedIn,
'entPhysicalMfgName' => $entPhysicalMfgName,
'entPhysicalParentRelPos' => $entPhysicalParentRelPos,
'entPhysicalVendorType' => $entPhysicalVendorType,
'entPhysicalHardwareRev' => $entPhysicalHardwareRev,
'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev,
'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev,
'entPhysicalIsFRU' => $entPhysicalIsFRU,
'entPhysicalAlias' => $entPhysicalAlias,
'entPhysicalAssetID' => $entPhysicalAssetID
);
dbUpdate($update_data, 'entPhysical', 'device_id=? AND entPhysicalIndex=?',array($device['device_id'],$entPhysicalIndex));
echo(".");
} else {
$insert_data = array(
'device_id' => $device['device_id'],
'entPhysicalIndex' => $entPhysicalIndex,
'entPhysicalDescr' => $entPhysicalDescr,
'entPhysicalClass' => $entPhysicalClass,
'entPhysicalName' => $entPhysicalName,
'entPhysicalModelName' => $entPhysicalModelName,
'entPhysicalSerialNum' => $entPhysicalSerialNum,
'entPhysicalContainedIn' => $entPhysicalContainedIn,
'entPhysicalMfgName' => $entPhysicalMfgName,
'entPhysicalParentRelPos' => $entPhysicalParentRelPos,
'entPhysicalVendorType' => $entPhysicalVendorType,
'entPhysicalHardwareRev' => $entPhysicalHardwareRev,
'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev,
'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev,
'entPhysicalIsFRU' => $entPhysicalIsFRU,
'entPhysicalAlias' => $entPhysicalAlias,
'entPhysicalAssetID' => $entPhysicalAssetID
);
if (!empty($ifIndex)) {
$insert_data['ifIndex'] = $ifIndex;
}
dbInsert($insert_data, 'entPhysical');
echo("+");
}
if ($device['os'] == 'junos') {
// $entPhysicalIndex appears as a numeric OID fragment
// (string), so convert it to an "integer" for the
// validation step below since it is stored in the DB as
// an integer. This should be fixed.
list($first,$second) = explode(".",$entPhysicalIndex);
$entPhysicalIndexNoDots = $first . $second;
$valid[$entPhysicalIndexNoDots] = 1;
} else {
$valid[$entPhysicalIndex] = 1;
}
}
} }
dbInsert($insert_data, 'entPhysical'); } else { echo("Disabled!"); }
echo("+");
}
$valid[$entPhysicalIndex] = 1; $sql = "SELECT * FROM `entPhysical` WHERE `device_id` = '".$device['device_id']."'";
} foreach (dbFetchRows($sql) as $test) {
}
} else { echo("Disabled!"); }
$sql = "SELECT * FROM `entPhysical` WHERE `device_id` = '".$device['device_id']."'";
foreach (dbFetchRows($sql) as $test)
{
$id = $test['entPhysicalIndex']; $id = $test['entPhysicalIndex'];
if (!$valid[$id]) { if (!$valid[$id]) {
echo("-"); echo("-");
dbDelete('entPhysical', 'entPhysical_id = ?', array($test['entPhysical_id'])); dbDelete('entPhysical', 'entPhysical_id = ?', array($test['entPhysical_id']));
} }
} }
echo("\n");
echo("\n");
?> ?>