Ejemplo n.º 1
0
static void add_sensor_event_sensor_rec(ipmi_sensor_t	*sensor,
					SaHpiSensorRecT	*rec)
{
	ipmi_entity_t *ent;	


	rec->Type = (SaHpiSensorTypeT)ipmi_sensor_get_sensor_type(sensor);
	rec->Category = (SaHpiEventCategoryT)
		ohoi_sensor_get_event_reading_type(sensor);
	rec->EventCtrl = (SaHpiSensorEventCtrlT)
		ipmi_sensor_get_event_support(sensor);
	/* Cannot find Events in IPMI. */
	rec->Events = 0xffff;

	ent = ipmi_sensor_get_entity(sensor);
#if 0
	if (ipmi_entity_is_present(ent)) 
		rec->Ignore = SAHPI_FALSE;
	else
		rec->Ignore = SAHPI_TRUE;
#endif

	add_sensor_event_data_format(sensor, rec);

	add_sensor_event_thresholds(sensor, rec);
	
	/* We do not care about oem. */
	rec->Oem = 0;
}
Ejemplo n.º 2
0
static void sensor_discrete_event(ipmi_sensor_t		*sensor,
				  enum ipmi_event_dir_e	dir,
				  int			offset,
				  int			severity,
				  int			prev_severity,
				  void			*cb_data,
				  ipmi_event_t		*event)
{
	struct oh_event         *e;
        struct oh_handler_state *handler;
	ipmi_entity_id_t        entity_id;
        SaHpiRptEntryT          *rpt_entry;
        unsigned char           *data;
 
        data = ipmi_event_get_data_ptr(event);

        handler    = cb_data;
        entity_id  = ipmi_entity_convert_to_id(ipmi_sensor_get_entity(sensor));
        rpt_entry  = ohoi_get_resource_by_entityid(handler->rptcache, &entity_id);

        if (!rpt_entry) {
                dump_entity_id("Discrete Sensor without RPT?!", entity_id);
                return;
        }

        e = malloc(sizeof(*e));
	if (!e) {
	dbg("Out of space");
		return;
	}

	memset(e, 0, sizeof(*e));
	e->type = OH_ET_HPI;
	e->u.hpi_event.parent = rpt_entry->ResourceId;
	
	e->u.hpi_event.event.Source = rpt_entry->ResourceId;
	/* Do not find EventType in IPMI */
	e->u.hpi_event.event.EventType = SAHPI_ET_SENSOR;
	e->u.hpi_event.event.Timestamp 
                = (SaHpiTimeT)ipmi_get_uint32(data) * 1000000000;

	e->u.hpi_event.event.Severity = (SaHpiSeverityT)severity;

	e->u.hpi_event.event.EventDataUnion.SensorEvent.SensorNum = 0;
	e->u.hpi_event.event.EventDataUnion.SensorEvent.SensorType = data[7];
	e->u.hpi_event.event.EventDataUnion.SensorEvent.EventCategory 
                = data[9] & 0x7f;
	e->u.hpi_event.event.EventDataUnion.SensorEvent.Assertion 
                = !(dir);
	
        e->u.hpi_event.event.EventDataUnion.SensorEvent.EventState = severity;
        e->u.hpi_event.event.EventDataUnion.SensorEvent.PreviousState = prev_severity;


	set_discrete_sensor_misc_event
		(event, &e->u.hpi_event.event.EventDataUnion.SensorEvent);
	
	handler->eventq = g_slist_append(handler->eventq, e);
	
}
Ejemplo n.º 3
0
/* callback function invoked from OpenIPMI */
static void	got_discrete_states(ipmi_sensor_t *sensor, int err, ipmi_states_t *states, void *cb_data)
{
	const char		*__function_name = "got_discrete_states";
	char			id_str[2 * IPMI_SENSOR_ID_SZ + 1];

	int			id, i, val, ret, is_state_set;
	ipmi_entity_t		*ent;
	zbx_ipmi_host_t		*h = cb_data;
	zbx_ipmi_sensor_t	*s;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	s = get_ipmi_sensor(h, sensor);

	if (NULL == s)
	{
		THIS_SHOULD_NEVER_HAPPEN;
		h->err = zbx_strdup(h->err, "fatal error");
		h->ret = NOTSUPPORTED;
		goto out;
	}

	if (0 != err)
	{
		h->err = zbx_dsprintf(h->err, "error 0x%x while reading a discrete sensor %s@[%s]:%d", err,
				sensor_id_to_str(id_str, sizeof(id_str), s->id, s->id_type, s->id_sz), h->ip, h->port);
		h->ret = NOTSUPPORTED;
		goto out;
	}

	ent = ipmi_sensor_get_entity(sensor);
	id = ipmi_entity_get_entity_id(ent);

	/* Discrete values are 16-bit. We're storing them into a 64-bit uint. */
#define MAX_DISCRETE_STATES	15

	s->value.discrete = 0;
	for (i = 0; i < MAX_DISCRETE_STATES; i++)
	{
		ret = ipmi_sensor_discrete_event_readable(sensor, i, &val);
		if (0 != ret || 0 == val)
			continue;

		is_state_set = ipmi_is_state_set(states, i);

		zabbix_log(LOG_LEVEL_DEBUG, "State [%s | %s | %s | %s | state %d value is %d]",
				sensor_id_to_str(id_str, sizeof(id_str), s->id, s->id_type, s->id_sz),
				ipmi_get_entity_id_string(id), ipmi_sensor_get_sensor_type_string(sensor),
				ipmi_sensor_get_event_reading_type_string(sensor), i, is_state_set);

		if (0 != is_state_set)
			s->value.discrete |= 1 << i;
	}
#undef MAX_DISCRETE_STATES
out:
	h->done = 1;

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(h->ret));
}
Ejemplo n.º 4
0
static int ignore_sensor(ipmi_sensor_t *sensor)
{
        ipmi_entity_t *ent;

        if ( ipmi_sensor_get_ignore_if_no_entity(sensor) )
                return 0;

        ent = ipmi_sensor_get_entity(sensor);

        if (ent && ipmi_entity_is_present(ent))
                return 0;

        return 1;
}
Ejemplo n.º 5
0
static int ignore_sensor(ipmi_sensor_t *sensor)
{
        ipmi_entity_t *ent;

        if (ipmi_sensor_get_ignore_if_no_entity(sensor)) {
		dbg("ignore if no entity");
                return 0;
	}
        ent = ipmi_sensor_get_entity(sensor);
	if (ent == NULL) {
		dbg("ipmi_sensor_get_entity = NULL");
		return 1;
	}
        if (!ipmi_entity_is_present(ent)) {
		dbg("!ipmi_entity_is_present. (%d,%d,%d,%d) %s",
		ipmi_entity_get_entity_id(ent), 
		ipmi_entity_get_entity_instance(ent),
		ipmi_entity_get_device_channel(ent),
		ipmi_entity_get_device_address(ent),
		ipmi_entity_get_entity_id_string(ent));
                return 0;
	}
        return 0;
}
Ejemplo n.º 6
0
/* callback function invoked from OpenIPMI */
static void	got_thresh_reading(ipmi_sensor_t *sensor, int err, enum ipmi_value_present_e value_present,
		unsigned int raw_value, double val, ipmi_states_t *states, void *cb_data)
{
	const char		*__function_name = "got_thresh_reading";
	char			id_str[2 * IPMI_SENSOR_ID_SZ + 1];
	const char		*e_string, *s_type_string, *s_reading_type_string;
	ipmi_entity_t		*ent;
	const char		*percent = "", *base, *mod_use = "", *modifier = "", *rate;
	zbx_ipmi_host_t		*h = cb_data;
	zbx_ipmi_sensor_t	*s;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	if (0 != err)
	{
		zabbix_log(LOG_LEVEL_DEBUG, "%s() fail: %s", __function_name, zbx_strerror(err));

		h->err = zbx_dsprintf(h->err, "error 0x%x while reading threshold sensor", err);
		h->ret = NETWORK_ERROR;
		h->done = 1;
		goto out;
	}

	s = get_ipmi_sensor(h, sensor);

	if (NULL == s)
	{
		THIS_SHOULD_NEVER_HAPPEN;
		h->err = zbx_dsprintf(h->err, "fatal error");
		h->ret = NOTSUPPORTED;
		h->done = 1;
		goto out;
	}

	switch (value_present)
	{
		case IPMI_NO_VALUES_PRESENT:
		case IPMI_RAW_VALUE_PRESENT:
			h->err = zbx_dsprintf(h->err, "no value present for threshold sensor");
			h->ret = NOTSUPPORTED;
			break;
		case IPMI_BOTH_VALUES_PRESENT:
			s->value.threshold = val;

			/* next lines only for debug logging */
			ent = ipmi_sensor_get_entity(sensor);
			e_string = ipmi_entity_get_entity_id_string(ent);
			s_type_string = ipmi_sensor_get_sensor_type_string(sensor);
			s_reading_type_string = ipmi_sensor_get_event_reading_type_string(sensor);

			base = ipmi_sensor_get_base_unit_string(sensor);
			if (ipmi_sensor_get_percentage(sensor))
				percent = "%";
			switch (ipmi_sensor_get_modifier_unit_use(sensor))
			{
				case IPMI_MODIFIER_UNIT_NONE:
					break;
				case IPMI_MODIFIER_UNIT_BASE_DIV_MOD:
					mod_use = "/";
					modifier = ipmi_sensor_get_modifier_unit_string(sensor);
					break;
				case IPMI_MODIFIER_UNIT_BASE_MULT_MOD:
					mod_use = "*";
					modifier = ipmi_sensor_get_modifier_unit_string(sensor);
					break;
			}
			rate = ipmi_sensor_get_rate_unit_string(sensor);

			zabbix_log(LOG_LEVEL_DEBUG, "Value [%s | %s | %s | %s | " ZBX_FS_DBL "%s %s%s%s%s]",
					sensor_id_to_str(id_str, sizeof(id_str), s->id, s->id_type, s->id_sz),
					e_string, s_type_string, s_reading_type_string, val, percent, base,
					mod_use, modifier, rate);
			break;
	}
	h->done = 1;
out:
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(h->ret));
}
Ejemplo n.º 7
0
static void sensor_threshold_event(ipmi_sensor_t		*sensor,
				   enum ipmi_event_dir_e	dir,
				   enum ipmi_thresh_e		threshold,
				   enum ipmi_event_value_dir_e	high_low,
				   enum ipmi_value_present_e	value_present,
				   unsigned int			raw_value,
				   double			value,
				   void				*cb_data,
				   ipmi_event_t			*event)
{
	struct oh_event		*e;
        struct oh_handler_state *handler;
	ipmi_entity_id_t	entity_id;
        ipmi_sensor_id_t        sensor_id;
	SaHpiSeverityT		severity;
        SaHpiRptEntryT          *rpt_entry;
        SaHpiRdrT               *rdr;
        unsigned char           *data;
 
        data = ipmi_event_get_data_ptr(event);

      
        handler    = cb_data;
        entity_id  = ipmi_entity_convert_to_id(ipmi_sensor_get_entity(sensor));
        sensor_id = ipmi_sensor_convert_to_id(sensor);
        rpt_entry  = ohoi_get_resource_by_entityid(handler->rptcache, &entity_id);
	
        
        rdr  = ohoi_get_rdr_by_data(handler->rptcache,
                                    rpt_entry->ResourceId,
                                    SAHPI_SENSOR_RDR,
                                    &sensor_id);
        if (!rdr) {
                dbg("No rdr in resource:%d\n",  rpt_entry->ResourceId);
                return;
        }

	e = malloc(sizeof(*e));
	if (!e) {
		dbg("Out of space");
		return;
	}

	memset(e, 0, sizeof(*e));
	e->type = OH_ET_HPI;
	e->u.hpi_event.parent = rpt_entry->ResourceId;
	
	e->u.hpi_event.event.Source = 0;
	/* Do not find EventType in IPMI */
	e->u.hpi_event.event.EventType = SAHPI_ET_SENSOR;
	e->u.hpi_event.event.Timestamp 
                = (SaHpiTimeT)ipmi_get_uint32(data) * 1000000000;

        e->u.hpi_event.event.EventDataUnion.SensorEvent.SensorNum
                = rdr->RdrTypeUnion.SensorRec.Num;

	e->u.hpi_event.event.EventDataUnion.SensorEvent.SensorType 
                = data[7];
	e->u.hpi_event.event.EventDataUnion.SensorEvent.EventCategory 
                = data[9] & 0x7f;
	
	set_thresholed_sensor_event_state(threshold, dir, high_low,
			&e->u.hpi_event.event.EventDataUnion.SensorEvent,
			&severity);
	e->u.hpi_event.event.Severity = severity;

	set_thresholds_sensor_misc_event
		(event, &e->u.hpi_event.event.EventDataUnion.SensorEvent);
        handler->eventq = g_slist_append(handler->eventq, e);

}
Ejemplo n.º 8
0
static void	got_thresh_reading(ipmi_sensor_t *sensor, int err, enum ipmi_value_present_e value_present,
		unsigned int raw_value, double val, ipmi_states_t *states, void *cb_data)
{
	const char		*e_string, *s_type_string, *s_reading_type_string;
	ipmi_entity_t		*ent;
	const char		*percent = "", *base, *mod_use = "", *modifier = "", *rate;
	zbx_ipmi_host_t	*h = cb_data;
	zbx_ipmi_sensor_t	*s;

	zabbix_log(LOG_LEVEL_DEBUG, "In got_thresh_reading()");

	if (err) {
		h->err = zbx_dsprintf(h->err, "Error 0x%x while read threshold sensor", err);
		h->ret = NETWORK_ERROR;
		h->done = 1;
		return;
	}

	s = get_ipmi_sensor(h, sensor);

	if (NULL == s)
	{
		/* this should never happen */
		h->err = zbx_dsprintf(h->err, "Fatal error");
		h->ret = NOTSUPPORTED;
		h->done = 1;
		return;
	}

	switch (value_present)
	{
		case IPMI_NO_VALUES_PRESENT:
		case IPMI_RAW_VALUE_PRESENT:
			h->err = zbx_dsprintf(h->err, "No value present for threshold sensor");
			h->ret = NOTSUPPORTED;
			break;
		case IPMI_BOTH_VALUES_PRESENT:
			s->value = val;

			/* next lines only for debug logging */
			ent = ipmi_sensor_get_entity(sensor);
			e_string = ipmi_entity_get_entity_id_string(ent);
			s_type_string = ipmi_sensor_get_sensor_type_string(sensor);
			s_reading_type_string = ipmi_sensor_get_event_reading_type_string(sensor);

			base = ipmi_sensor_get_base_unit_string(sensor);
			if (ipmi_sensor_get_percentage(sensor))
				percent = "%";
			switch (ipmi_sensor_get_modifier_unit_use(sensor)) {
				case IPMI_MODIFIER_UNIT_NONE:
					break;
				case IPMI_MODIFIER_UNIT_BASE_DIV_MOD:
					mod_use = "/";
					modifier = ipmi_sensor_get_modifier_unit_string(sensor);
					break;
				case IPMI_MODIFIER_UNIT_BASE_MULT_MOD:
					mod_use = "*";
					modifier = ipmi_sensor_get_modifier_unit_string(sensor);
					break;
			}
			rate = ipmi_sensor_get_rate_unit_string(sensor);

			zabbix_log(LOG_LEVEL_DEBUG, "Value [%s | %s | %s | %s | " ZBX_FS_DBL "%s %s%s%s%s]",
					s->s_name, e_string, s_type_string, s_reading_type_string,
					val, percent, base, mod_use, modifier, rate);
			break;
	}
	h->done = 1;
}