📄 snmp_bc_sensor.c
字号:
dbg("Cannot define both delta and total negative hysteresis. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (lower_thresholds > 1) { dbg("Multiple lower thresholds defined for total negative hysteresis. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (lower_thresholds == 0) { dbg("No lower thresholds are defined for total negative hysteresis. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Get negative hysteresis value */ SaErrorT err = snmp_bc_get_sensor_oid_reading(hnd, rid, sid, sinfo->mib.threshold_oids.TotalNegThdHysteresis, &reading); if (err) return(err); switch (rdr->RdrTypeUnion.SensorRec.DataFormat.ReadingType) { case SAHPI_SENSOR_READING_TYPE_INT64: { SaHpiInt64T delta; if (found_thresholds & SAHPI_STM_LOW_CRIT) { delta = reading.Value.SensorInt64 - working.LowCritical.Value.SensorInt64; } else { if (found_thresholds & SAHPI_STM_LOW_MAJOR) { delta = reading.Value.SensorInt64 - working.LowMajor.Value.SensorInt64; } else { delta = reading.Value.SensorInt64 - working.LowMinor.Value.SensorInt64; } } if (delta < 0) { dbg("Negative hysteresis delta is less than 0"); working.NegThdHysteresis.IsSupported = SAHPI_FALSE; } else { working.NegThdHysteresis.IsSupported = SAHPI_TRUE; working.NegThdHysteresis.Type = SAHPI_SENSOR_READING_TYPE_INT64; working.NegThdHysteresis.Value.SensorInt64 = delta; } break; } case SAHPI_SENSOR_READING_TYPE_FLOAT64: { SaHpiFloat64T delta; if (found_thresholds & SAHPI_STM_LOW_CRIT) { delta = reading.Value.SensorFloat64 - working.LowCritical.Value.SensorFloat64; } else { if (found_thresholds & SAHPI_STM_LOW_MAJOR) { delta = reading.Value.SensorFloat64 - working.LowMajor.Value.SensorFloat64; } else { delta = reading.Value.SensorFloat64 - working.LowMinor.Value.SensorFloat64; } } if (delta < 0) { dbg("Negative hysteresis delta is less than 0"); working.NegThdHysteresis.IsSupported = SAHPI_FALSE; } else { working.NegThdHysteresis.IsSupported = SAHPI_TRUE; working.NegThdHysteresis.Type = SAHPI_SENSOR_READING_TYPE_FLOAT64; working.NegThdHysteresis.Value.SensorFloat64 = delta; } break; } case SAHPI_SENSOR_READING_TYPE_UINT64: case SAHPI_SENSOR_READING_TYPE_BUFFER: default: dbg("Invalid reading type for threshold. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } } /* Positive Total Hysteresis - applies to upper thresholds */ if (sinfo->mib.threshold_oids.TotalPosThdHysteresis) { SaHpiSensorReadingT reading; if (found_thresholds & SAHPI_STM_UP_HYSTERESIS) { dbg("Cannot define both delta and total positive hysteresis. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (upper_thresholds > 1) { dbg("Multiple upper thresholds defined for total positive hysteresis. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (upper_thresholds == 0) { dbg("No upper thresholds are defined for total positive hysteresis. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Get positive hysteresis value */ SaErrorT err = snmp_bc_get_sensor_oid_reading(hnd, rid, sid, sinfo->mib.threshold_oids.TotalPosThdHysteresis, &reading); if (err) return(err); switch (rdr->RdrTypeUnion.SensorRec.DataFormat.ReadingType) { case SAHPI_SENSOR_READING_TYPE_INT64: { SaHpiInt64T delta; if (found_thresholds & SAHPI_STM_UP_CRIT) { delta = working.UpCritical.Value.SensorInt64 - reading.Value.SensorInt64; } else { if (found_thresholds & SAHPI_STM_UP_MAJOR) { delta = working.UpMajor.Value.SensorInt64 - reading.Value.SensorInt64; } else { delta = working.UpMinor.Value.SensorInt64 - reading.Value.SensorInt64; } } if (delta < 0) { dbg("Positive hysteresis delta is less than 0"); working.PosThdHysteresis.IsSupported = SAHPI_FALSE; } else { working.PosThdHysteresis.IsSupported = SAHPI_TRUE; working.PosThdHysteresis.Type = SAHPI_SENSOR_READING_TYPE_INT64; working.PosThdHysteresis.Value.SensorInt64 = delta; } break; } case SAHPI_SENSOR_READING_TYPE_FLOAT64: { SaHpiFloat64T delta; if (found_thresholds & SAHPI_STM_UP_CRIT) { delta = working.UpCritical.Value.SensorFloat64 - reading.Value.SensorFloat64; } else { if (found_thresholds & SAHPI_STM_UP_MAJOR) { delta = working.UpMajor.Value.SensorFloat64 - reading.Value.SensorFloat64; } else { delta = working.UpMinor.Value.SensorFloat64 - reading.Value.SensorFloat64; } } if (delta < 0) { dbg("Positive hysteresis delta is less than 0"); working.PosThdHysteresis.IsSupported = SAHPI_FALSE; } else { working.PosThdHysteresis.IsSupported = SAHPI_TRUE; working.PosThdHysteresis.Type = SAHPI_SENSOR_READING_TYPE_FLOAT64; working.PosThdHysteresis.Value.SensorFloat64 = delta; } break; } case SAHPI_SENSOR_READING_TYPE_UINT64: case SAHPI_SENSOR_READING_TYPE_BUFFER: default: dbg("Invalid reading type for threshold. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } } if (found_thresholds == 0) { dbg("No readable thresholds found. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } memcpy(thres, &working, sizeof(SaHpiSensorThresholdsT)); return(SA_OK);}#define merge_threshold(thdname) \do { \ if (thres->thdname.IsSupported) { \ working.thdname.IsSupported = SAHPI_TRUE; \ working.thdname.Type = thres->thdname.Type; \ switch(thres->thdname.Type) { \ case SAHPI_SENSOR_READING_TYPE_INT64: \ working.thdname.Value.SensorInt64 = thres->thdname.Value.SensorInt64; \ break; \ case SAHPI_SENSOR_READING_TYPE_FLOAT64: \ working.thdname.Value.SensorFloat64 = thres->thdname.Value.SensorFloat64; \ break; \ case SAHPI_SENSOR_READING_TYPE_UINT64: \ working.thdname.Value.SensorUint64 = thres->thdname.Value.SensorUint64; \ break; \ case SAHPI_SENSOR_READING_TYPE_BUFFER: \ default: \ dbg("Invalid threshold reading type."); \ return(SA_ERR_HPI_INVALID_CMD); \ } \ } \} while(0)#define write_valid_threshold(thdname) \do { \ if (thres->thdname.IsSupported) { \ if (sinfo->mib.threshold_write_oids.thdname == NULL || \ sinfo->mib.threshold_oids.thdname[0] == '\0') { \ dbg("No writable threshold OID defined for thdname."); \ return(SA_ERR_HPI_INTERNAL_ERROR); \ } \ err = snmp_bc_set_threshold_reading(hnd, rid, sid, \ sinfo->mib.threshold_write_oids.thdname, \ &(working.thdname)); \ if (err) return(err); \ } \} while(0)/** * snmp_bc_set_sensor_thresholds: * @hnd: Handler data pointer. * @rid: Resource ID. * @sid: Sensor ID. * @thres: Location of sensor's settable threshold values. * * Sets sensor's threshold values. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_CAPABILITY - Resource doesn't have SAHPI_CAPABILITY_SENSOR. * SA_ERR_HPI_INVALID_CMD - Non-writable thresholds or invalid thresholds. * SA_ERR_HPI_INVALID_DATA - Threshold values out of order; negative hysteresis * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. * SA_ERR_HPI_NOT_PRESENT - Sensor doesn't exist. **/SaErrorT snmp_bc_set_sensor_thresholds(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const SaHpiSensorThresholdsT *thres){ SaErrorT err; SaHpiSensorThresholdsT working; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct SensorInfo *sinfo; if (!hnd || !thres) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exists and has writable thresholds */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (rdr->RdrTypeUnion.SensorRec.Category != SAHPI_EC_THRESHOLD || rdr->RdrTypeUnion.SensorRec.ThresholdDefn.IsAccessible == SAHPI_FALSE || rdr->RdrTypeUnion.SensorRec.ThresholdDefn.WriteThold == 0) return(SA_ERR_HPI_INVALID_CMD); /* Overlay proposed thresholds on top of existing ones and validate */ err = snmp_bc_get_sensor_thresholds(hnd, rid, sid, &working); if (err) return(err); merge_threshold(LowCritical); merge_threshold(LowMajor); merge_threshold(LowMinor); merge_threshold(UpCritical); merge_threshold(UpMajor); merge_threshold(UpMinor); merge_threshold(PosThdHysteresis); merge_threshold(NegThdHysteresis); err = oh_valid_thresholds(&working, &(rdr->RdrTypeUnion.SensorRec.DataFormat), rdr->RdrTypeUnion.SensorRec.ThresholdDefn.WriteThold); if (err) return(err); /************************ * Write valid thresholds ************************/ write_valid_threshold(UpCritical); write_valid_threshold(UpMajor); write_valid_threshold(UpMinor); write_valid_threshold(LowCritical); write_valid_threshold(LowMajor); write_valid_threshold(LowMinor); /* We don't support writing total value hysteresis only deltas */ write_valid_threshold(NegThdHysteresis); write_valid_threshold(PosThdHysteresis); return(SA_OK);}SaErrorT snmp_bc_get_sensor_oid_reading(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const char *raw_oid, SaHpiSensorReadingT *reading){ gchar *oid; SaHpiSensorReadingT working; struct SensorInfo *sinfo; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; struct snmp_value get_value; SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Normalize and read sensor's raw SNMP OID */ oid = oh_derive_string(&(rdr->Entity), raw_oid); if (oid == NULL) { dbg("NULL SNMP OID returned for %s", raw_oid); return(SA_ERR_HPI_INTERNAL_ERROR); } if (snmp_get(custom_handle->ss, oid, &get_value) != 0) { dbg("SNMP cannot read sensor OID=%s. Type=%d", oid, get_value.type); g_free(oid); return(SA_ERR_HPI_NO_RESPONSE); } g_free(oid); /* Convert SNMP value to HPI reading value */ working.IsSupported = SAHPI_TRUE; if (get_value.type == ASN_INTEGER) { working.Type = SAHPI_SENSOR_READING_TYPE_INT64; working.Value.SensorInt64 = (SaHpiInt64T)get_value.integer; } else { SaHpiTextBufferT buffer; oh_init_textbuffer(&buffer); oh_append_textbuffer(&buffer, get_value.string); SaErrorT err = oh_encode_sensorreading(&buffer, rdr->RdrTypeUnion.SensorRec.DataFormat.ReadingType, &working); if (err) { dbg("Cannot convert sensor OID=%s value=%s. Error=%s", sinfo->mib.oid, buffer.Data, oh_lookup_error(err)); return(SA_ERR_HPI_INTERNAL_ERROR); } } memcpy(reading, &working, sizeof(SaHpiSensorReadingT)); return(SA_OK);}SaErrorT snmp_bc_set_threshold_reading(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const char *raw_oid, const SaHpiSensorReadingT *reading){ gchar *oid; SaErrorT err; SaHpiTextBufferT buffer; SaHpiFloat64T tmp_num; struct SensorInfo *sinfo; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; struct snmp_value set_value; if (!hnd || !reading || !raw_oid) { dbg("Invalid parameter."); return(SA_ERR_HPI_INTERNAL_ERROR); } SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Convert reading into SNMP string structure */ err = oh_init_textbuffer(&buffer); if (err) return(err); switch (reading->Type) { case SAHPI_SENSOR_READING_TYPE_INT64: tmp_num = (SaHpiFloat64T)reading->Value.SensorInt64; break; case SAHPI_SENSOR_READING_TYPE_FLOAT64: tmp_num = reading->Value.SensorFloat64; break; case SAHPI_SENSOR_READING_TYPE_UINT64: tmp_num = (SaHpiFloat64T)reading->Value.SensorUint64; break; case SAHPI_SENSOR_READING_TYPE_BUFFER: default: dbg("Invalid type for threshold. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } /************************************************************* * NOTE! Assuming max format for writable thresholds is ddd.dd *************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -