📄 snmp_bc_inventory.c
字号:
*
* This function is not suported/implemented for snmp_bc plugin
*
* Return value:
* SA_ERR_HPI_READ_ONLY - Normal - snmp_bc does not allow Inventory Update
**/
SaErrorT snmp_bc_del_idr_field( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
SaHpiEntryIdT AreaId,
SaHpiEntryIdT FieldId)
{
return SA_ERR_HPI_READ_ONLY;
}
/**
* snmp_bc_build_idr:
* @hnd: Pointer to handler's data
* @ResourceId: Resource identifier for this operation
* @IdrId: Identifier for the Inventory Data Repository
* @i_record: Pointer into which inventory data is stored
*
* Build the complete Inventory Record for the resource identifier
*
* Return value:
* SA_OK - Normal
* SA_ERR_HPI_INVALID_PARAMS - If any in pointer is NULL
* SA_ERR_HPI_NOT_PRESENT - If Inventory RDR is not found in rptcache
*
**/
static
SaErrorT snmp_bc_build_idr( void *hnd,
SaHpiResourceIdT ResourceId,
SaHpiIdrIdT IdrId,
struct bc_inventory_record *i_record)
{
SaErrorT rv = SA_OK;
if (!hnd || !i_record)
return(SA_ERR_HPI_INVALID_PARAMS);
struct oh_handler_state *handle = (struct oh_handler_state *) hnd;
struct snmp_bc_hnd *custom_handle = handle->data;
SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, ResourceId, SAHPI_INVENTORY_RDR, IdrId);
gchar *oid = NULL;
struct snmp_value get_value;
/* Local work spaces */
SaHpiIdrFieldT thisField;
struct bc_idr_area thisInventoryArea;
if (rdr != NULL) {
struct InventoryInfo *s =
(struct InventoryInfo *)oh_get_rdr_data(handle->rptcache, ResourceId, rdr->RecordId);
i_record->idrinfo.IdrId = IdrId;
i_record->idrinfo.UpdateCount = 0;
i_record->idrinfo.ReadOnly = SAHPI_TRUE;
i_record->idrinfo.NumAreas = 1; /* pdp - expand to 2 for chassis HW & Firmware */
thisInventoryArea.idrareas.AreaId = 1;
thisInventoryArea.idrareas.Type = s->mib.area_type;
thisInventoryArea.idrareas.ReadOnly = SAHPI_TRUE;
thisInventoryArea.idrareas.NumFields = 0; /* Increment it as we find field */
thisField.AreaId = thisInventoryArea.idrareas.AreaId;
thisField.ReadOnly = SAHPI_TRUE;
thisField.Field.Language = SAHPI_LANG_ENGLISH; /* SaHpiLanguageT */
/**
*
*/
thisField.FieldId = 1;
thisField.Type = SAHPI_IDR_FIELDTYPE_CHASSIS_TYPE;
if(s->mib.oid.OidChassisType != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidChassisType);
if(oid == NULL) {
dbg("NULL SNMP OID returned for Chassis Type\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building Chassis Idr Field, continue to next field.\n");
}
}
/**
*
*/
memset(thisField.Field.Data, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
thisField.FieldId = 2;
thisField.Type = SAHPI_IDR_FIELDTYPE_MFG_DATETIME;
thisField.Field.DataLength = 0; /* SaHpiUint8T */
if (s->mib.oid.OidMfgDateTime != NULL)
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidMfgDateTime);
else
oid = NULL;
if(!oid){
thisField.Field.DataLength = sizeof("SAHPI_TIME_UNSPECIFIED"); /* SaHpiUint8T */
thisField.Field.DataType = SAHPI_TL_TYPE_TEXT; /* SaHpiTextTypeT */
strcpy(thisField.Field.Data,"SAHPI_TIME_UNSPECIFIED");
} else {
rv = snmp_bc_snmp_get(custom_handle, oid, &get_value);
if(rv != SA_OK) {
dbg("SNMP could not read %s; Type=%d.\n",oid,get_value.type);
g_free(oid);
return rv;
} else if((rv == SA_OK) && (get_value.type == ASN_OCTET_STR )) {
thisField.Field.DataLength = get_value.str_len;
thisField.Field.DataType = SAHPI_TL_TYPE_TEXT;
memcpy(thisField.Field.Data, get_value.string, get_value.str_len);
} else
dbg("%s Invalid type for MfgDateTime inventory data\n",oid);
}
if (oid) g_free(oid);
if (thisField.Field.DataLength != 0) {
memcpy(&thisInventoryArea.field[thisInventoryArea.idrareas.NumFields], &thisField, sizeof(SaHpiIdrFieldT));
thisInventoryArea.idrareas.NumFields++;
}
/**
*
*/
thisField.FieldId = 3;
thisField.Type = SAHPI_IDR_FIELDTYPE_MANUFACTURER;
if(s->mib.oid.OidManufacturer != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidManufacturer);
if(oid == NULL) {
dbg("NULL SNMP OID returned for Manufacturer\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building ManufacturerId Idr Field, continue to next field.\n");
}
}
/**
*
*/
thisField.FieldId = 4;
thisField.Type = SAHPI_IDR_FIELDTYPE_PRODUCT_NAME;
if(s->mib.oid.OidProductName != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidProductName);
if(oid == NULL) {
dbg("NULL SNMP OID returned for ProductName\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building ProductName Idr Field, continue to next field.\n");
}
}
/**
*
*/
thisField.FieldId = 5;
thisField.Type = SAHPI_IDR_FIELDTYPE_PRODUCT_VERSION;
if(s->mib.oid.OidProductVersion != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidProductVersion);
if(oid == NULL) {
dbg("NULL SNMP OID returned for ProductVersion\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building ProductVersion Idr Field, continue to next field.\n");
}
}
/**
*
*/
thisField.FieldId = 6;
thisField.Type = SAHPI_IDR_FIELDTYPE_SERIAL_NUMBER;
if(s->mib.oid.OidSerialNumber != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidSerialNumber);
if(oid == NULL) {
dbg("NULL SNMP OID returned for SerialNumber\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building SerialNumber Idr Field, continue to next field.\n");
}
}
/**
*
*/
thisField.FieldId = 7;
thisField.Type = SAHPI_IDR_FIELDTYPE_PART_NUMBER;
if(s->mib.oid.OidPartNumber != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidPartNumber);
if(oid == NULL) {
dbg("NULL SNMP OID returned for PartNumber\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building PartNumber Idr Field, continue to next field.\n");
}
}
/**
*
*/
thisField.FieldId = 8;
thisField.Type = SAHPI_IDR_FIELDTYPE_FILE_ID;
if(s->mib.oid.OidFileId != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidFileId);
if(oid == NULL) {
dbg("NULL SNMP OID returned for FileId\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building FileID Idr Field, continue to next field.\n");
}
}
/**
*
*/
thisField.FieldId = 9;
thisField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG;
if(s->mib.oid.OidAssetTag != NULL) {
oid = oh_derive_string(&(rdr->Entity),s->mib.oid.OidAssetTag);
if(oid == NULL) {
dbg("NULL SNMP OID returned for AssetTag\n");
} else {
rv = snmp_bc_idr_build_field(custom_handle, oid, &thisField, &thisInventoryArea);
if (rv != SA_OK)
dbg("Having problem building AssetTag Idr Field, continue ...\n");
}
}
memcpy( &(i_record->area[0]), &thisInventoryArea, sizeof(struct bc_idr_area));
} else {
rv = SA_ERR_HPI_NOT_PRESENT;
}
return rv;
}
/**
* snmp_bc_idr_build_field:
* @custom_handle: snmp_bc custom handler data
* @oid: SNMP Object Id of the BC Inventory object
* @thisField: Pointer to Inventory Field under construction
* @thisInventoryArea: Pointer to Inventory Record under contruction
*
* Get data from target snmp agent for the corresponding oid.
* Construct IDR Field for the retrieved data and place in Inventory Record
*
* Return value:
* SA_OK - Normal
* SA_ERR_HPI_INVALID_PARAMS - If any in pointer is NULL
* SA_ERR_HPI_INTERNAL_ERROR - If can not process get_value.type from bc snmp agent
*
**/
static
SaErrorT snmp_bc_idr_build_field(struct snmp_bc_hnd *custom_handle, gchar *oid,
SaHpiIdrFieldT *thisField, struct bc_idr_area *thisInventoryArea)
{
if (!custom_handle || !oid || !thisField || !thisInventoryArea)
return(SA_ERR_HPI_INVALID_PARAMS);
struct snmp_value get_value;
SaErrorT rv = SA_OK;
/**
*
*/
memset(thisField->Field.Data, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
thisField->Field.DataLength = 0; /* SaHpiUint8T */
rv = snmp_bc_snmp_get(custom_handle, oid, &get_value);
if(rv != SA_OK) {
dbg("SNMP could not read %s; Type=%d.\n",oid,get_value.type);
g_free(oid);
return(rv);
} else {
if( get_value.type == ASN_OCTET_STR ) {
thisField->Field.DataLength = get_value.str_len;
thisField->Field.DataType = SAHPI_TL_TYPE_TEXT;
memcpy(thisField->Field.Data, get_value.string, get_value.str_len);
} else if ( get_value.type == ASN_INTEGER ){
thisField->Field.DataLength = sizeof(long);
thisField->Field.DataType = SAHPI_TL_TYPE_TEXT;
snprintf(thisField->Field.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH,
"%ld",get_value.integer );
} else
dbg("%s Invalid data type for Chassis data\n",oid);
}
g_free(oid);
if (thisField->Field.DataLength != 0) {
memcpy(&thisInventoryArea->field[thisInventoryArea->idrareas.NumFields],
thisField, sizeof(SaHpiIdrFieldT));
thisInventoryArea->idrareas.NumFields++;
}
return(SA_OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -