static int sensor_threshold_event_handler(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) { ipmi_cmd_info_t *evi; char sensor_name[IPMI_SENSOR_NAME_LEN]; int rv; char *errstr; ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); evi = ipmi_cmdlang_alloc_event_info(); if (!evi) { rv = ENOMEM; errstr = "Out of memory"; goto out_err; } ipmi_cmdlang_out(evi, "Object Type", "Sensor"); ipmi_cmdlang_out(evi, "Name", sensor_name); ipmi_cmdlang_out(evi, "Operation", "Event"); ipmi_cmdlang_out(evi, "Threshold", ipmi_get_threshold_string(threshold)); ipmi_cmdlang_out(evi, "High/Low", ipmi_get_value_dir_string(high_low)); ipmi_cmdlang_out(evi, "Direction", ipmi_get_event_dir_string(dir)); switch (value_present) { case IPMI_BOTH_VALUES_PRESENT: ipmi_cmdlang_out_double(evi, "Value", value); /* FALLTHRU */ case IPMI_RAW_VALUE_PRESENT: ipmi_cmdlang_out_int(evi, "Raw Value", raw_value); break; default: break; } if (event) { ipmi_cmdlang_out(evi, "Event", NULL); ipmi_cmdlang_down(evi); ipmi_cmdlang_event_out(event, evi); ipmi_cmdlang_up(evi); } ipmi_cmdlang_cmd_info_put(evi); return IPMI_EVENT_NOT_HANDLED; out_err: ipmi_cmdlang_global_err(sensor_name, "cmd_sensor.c(sensor_threshold_event_handler)", errstr, rv); if (evi) ipmi_cmdlang_cmd_info_put(evi); return IPMI_EVENT_NOT_HANDLED; }
static void sensor_get_event_enables_done(ipmi_sensor_t *sensor, int err, ipmi_event_state_t *states, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); char sensor_name[IPMI_SENSOR_NAME_LEN]; int rv; int val; ipmi_cmdlang_lock(cmd_info); if (err) { cmdlang->errstr = "Error reading sensor event enables"; cmdlang->err = err; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_get_event_enables_done)"; goto out; } ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); ipmi_cmdlang_out(cmd_info, "Sensor", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", sensor_name); ipmi_cmdlang_out_bool(cmd_info, "Event Messages Enabled", ipmi_event_state_get_events_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Sensor Scanning Enabled", ipmi_event_state_get_scanning_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Busy", ipmi_event_state_get_busy(states)); if (ipmi_sensor_get_event_reading_type(sensor) == IPMI_EVENT_READING_TYPE_THRESHOLD) { enum ipmi_thresh_e thresh; enum ipmi_event_value_dir_e value_dir; enum ipmi_event_dir_e dir; for (thresh = IPMI_LOWER_NON_CRITICAL; thresh <= IPMI_UPPER_NON_RECOVERABLE; thresh++) { for (value_dir = IPMI_GOING_LOW; value_dir <= IPMI_GOING_HIGH; value_dir++) { for (dir = IPMI_ASSERTION; dir <= IPMI_DEASSERTION; dir++) { char th_name[50]; rv = ipmi_sensor_threshold_event_supported(sensor, thresh, value_dir, dir, &val); if (rv || !val) continue; ipmi_cmdlang_out(cmd_info, "Threshold", NULL); ipmi_cmdlang_down(cmd_info); snprintf(th_name, sizeof(th_name), "%s %s %s", ipmi_get_threshold_string(thresh), ipmi_get_value_dir_string(value_dir), ipmi_get_event_dir_string(dir)); ipmi_cmdlang_out(cmd_info, "Name", th_name); ipmi_cmdlang_out_bool(cmd_info, "Enabled", ipmi_is_threshold_event_set (states, thresh, value_dir, dir)); ipmi_cmdlang_up(cmd_info); } } } } else { int offset; const char *str; for (offset=0; offset<15; offset++) { rv = ipmi_sensor_discrete_event_readable(sensor, offset, &val); if (rv || !val) continue; ipmi_cmdlang_out(cmd_info, "Event", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out_int(cmd_info, "Offset", offset); str = ipmi_sensor_reading_name_string(sensor, offset); if (strcmp(str, "unknown") != 0) ipmi_cmdlang_out(cmd_info, "Name", str); rv = ipmi_sensor_discrete_event_supported(sensor, offset, IPMI_ASSERTION, &val); if (!rv && val) { ipmi_cmdlang_out_bool(cmd_info, "Assertion Enabled", ipmi_is_discrete_event_set (states, offset, IPMI_ASSERTION)); } rv = ipmi_sensor_discrete_event_supported(sensor, offset, IPMI_DEASSERTION, &val); if (!rv && val) { ipmi_cmdlang_out_bool(cmd_info, "Deassertion Enabled", ipmi_is_discrete_event_set (states, offset, IPMI_DEASSERTION)); } ipmi_cmdlang_up(cmd_info); } } ipmi_cmdlang_up(cmd_info); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); }
static void sensor_dump(ipmi_sensor_t *sensor, ipmi_cmd_info_t *cmd_info) { ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int num, lun; char *str; const char *cstr; int event_support; int event_reading_type; int len; int rv; int val; event_reading_type = ipmi_sensor_get_event_reading_type(sensor); ipmi_sensor_get_num(sensor, &lun, &num); ipmi_cmdlang_out_int(cmd_info, "LUN", lun); ipmi_cmdlang_out_int(cmd_info, "Number", num); ipmi_cmdlang_out_int(cmd_info, "Event Reading Type", ipmi_sensor_get_event_reading_type(sensor)); ipmi_cmdlang_out(cmd_info, "Event Reading Type Name", ipmi_sensor_get_event_reading_type_string(sensor)); ipmi_cmdlang_out_int(cmd_info, "Type", ipmi_sensor_get_sensor_type(sensor)); ipmi_cmdlang_out(cmd_info, "Type Name", ipmi_sensor_get_sensor_type_string(sensor)); val = ipmi_sensor_get_sensor_direction(sensor); if (val != IPMI_SENSOR_DIRECTION_UNSPECIFIED) ipmi_cmdlang_out(cmd_info, "Direction", ipmi_get_sensor_direction_string(val)); event_support = ipmi_sensor_get_event_support(sensor); switch (event_support) { case IPMI_EVENT_SUPPORT_PER_STATE: ipmi_cmdlang_out(cmd_info, "Event Support", "per state"); break; case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR: ipmi_cmdlang_out(cmd_info, "Event Support", "entire sensor"); break; case IPMI_EVENT_SUPPORT_GLOBAL_ENABLE: ipmi_cmdlang_out(cmd_info, "Event Support", "global"); break; default: break; } ipmi_cmdlang_out_bool(cmd_info, "Init Scanning", ipmi_sensor_get_sensor_init_scanning(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Init Events", ipmi_sensor_get_sensor_init_events(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Init Thresholds", ipmi_sensor_get_sensor_init_thresholds(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Init Hysteresis", ipmi_sensor_get_sensor_init_hysteresis(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Init Type", ipmi_sensor_get_sensor_init_type(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Init Power Up Events", ipmi_sensor_get_sensor_init_pu_events(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Init Power Up Scanning", ipmi_sensor_get_sensor_init_pu_scanning(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Ignore If No Entity", ipmi_sensor_get_ignore_if_no_entity(sensor)); ipmi_cmdlang_out_bool(cmd_info, "Auto Rearm", ipmi_sensor_get_supports_auto_rearm(sensor)); ipmi_cmdlang_out_int(cmd_info, "OEM1", ipmi_sensor_get_oem1(sensor)); len = ipmi_sensor_get_id_length(sensor); if (len) { str = ipmi_mem_alloc(len); if (!str) { cmdlang->err = ENOMEM; cmdlang->errstr = "Out of memory"; goto out_err; } len = ipmi_sensor_get_id(sensor, str, len); ipmi_cmdlang_out_type(cmd_info, "Id", ipmi_sensor_get_id_type(sensor), str, len); ipmi_mem_free(str); } if (event_reading_type == IPMI_EVENT_READING_TYPE_THRESHOLD) { int access = ipmi_sensor_get_threshold_access(sensor); enum ipmi_thresh_e thresh; enum ipmi_event_value_dir_e value_dir; enum ipmi_event_dir_e dir; int rv; char th_name[50]; double dval; ipmi_cmdlang_out(cmd_info, "Threshold Access", ipmi_get_threshold_access_support_string(access)); for (thresh = IPMI_LOWER_NON_CRITICAL; thresh <= IPMI_UPPER_NON_RECOVERABLE; thresh++) { rv = ipmi_sensor_threshold_reading_supported(sensor, thresh, &val); if ((rv) || !val) continue; ipmi_cmdlang_out(cmd_info, "Threshold", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", ipmi_get_threshold_string(thresh)); rv = ipmi_sensor_threshold_readable(sensor, thresh, &val); if (rv) val = 0; ipmi_cmdlang_out_bool(cmd_info, "Readable", val); rv = ipmi_sensor_threshold_settable(sensor, thresh, &val); if (rv) val = 0; ipmi_cmdlang_out_bool(cmd_info, "Settable", val); for (value_dir = IPMI_GOING_LOW; value_dir <= IPMI_GOING_HIGH; value_dir++) { for (dir = IPMI_ASSERTION; dir <= IPMI_DEASSERTION; dir++) { rv = ipmi_sensor_threshold_event_supported(sensor, thresh, value_dir, dir, &val); if (rv || !val) continue; snprintf(th_name, sizeof(th_name), "%s %s", ipmi_get_value_dir_string(value_dir), ipmi_get_event_dir_string(dir)); ipmi_cmdlang_out(cmd_info, "Supports", th_name); } } ipmi_cmdlang_up(cmd_info); } val = ipmi_sensor_get_hysteresis_support(sensor); ipmi_cmdlang_out(cmd_info, "Hysteresis Support", ipmi_get_hysteresis_support_string(val)); #if 0 /* FIXME - no accuracy handling */ int ipmi_sensor_get_accuracy(ipmi_sensor_t *sensor, int val, double *accuracy); #endif rv = ipmi_sensor_get_nominal_reading(sensor, &dval); if (!rv) ipmi_cmdlang_out_double(cmd_info, "Nominal Reading", dval); rv = ipmi_sensor_get_normal_max(sensor, &dval); if (!rv) ipmi_cmdlang_out_double(cmd_info, "Normal Max", dval); rv = ipmi_sensor_get_normal_min(sensor, &dval); if (!rv) ipmi_cmdlang_out_double(cmd_info, "Normal Min", dval); rv = ipmi_sensor_get_sensor_max(sensor, &dval); if (!rv) ipmi_cmdlang_out_double(cmd_info, "Sensor Max", dval); rv = ipmi_sensor_get_sensor_min(sensor, &dval); if (!rv) ipmi_cmdlang_out_double(cmd_info, "Sensor Min", dval); ipmi_cmdlang_out_int(cmd_info, "Base Unit", ipmi_sensor_get_base_unit(sensor)); ipmi_cmdlang_out(cmd_info, "Base Unit Name", ipmi_sensor_get_base_unit_string(sensor)); cstr = ipmi_sensor_get_rate_unit_string(sensor); if (strlen(cstr)) { ipmi_cmdlang_out_int(cmd_info, "Rate Unit", ipmi_sensor_get_rate_unit(sensor)); ipmi_cmdlang_out(cmd_info, "Rate Unit Name", cstr); } switch (ipmi_sensor_get_modifier_unit_use(sensor)) { case IPMI_MODIFIER_UNIT_BASE_DIV_MOD: ipmi_cmdlang_out(cmd_info, "Modifier Use", "/"); ipmi_cmdlang_out_int(cmd_info, "Modifier Unit", ipmi_sensor_get_modifier_unit(sensor)); ipmi_cmdlang_out(cmd_info, "Modifier Unit Name", ipmi_sensor_get_modifier_unit_string(sensor)); break; case IPMI_MODIFIER_UNIT_BASE_MULT_MOD: ipmi_cmdlang_out(cmd_info, "Modifier Use", "*"); ipmi_cmdlang_out_int(cmd_info, "Modifier Unit", ipmi_sensor_get_modifier_unit(sensor)); ipmi_cmdlang_out(cmd_info, "Modifier Unit Name", ipmi_sensor_get_modifier_unit_string(sensor)); break; default: break; } if (ipmi_sensor_get_percentage(sensor)) ipmi_cmdlang_out(cmd_info, "Percentage", "%"); } else { int event; enum ipmi_event_dir_e dir; for (event=0; event<15; event++) { rv = ipmi_sensor_discrete_event_readable(sensor, event, &val); if (rv || !val) continue; ipmi_cmdlang_out(cmd_info, "Event", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out_int(cmd_info, "Offset", event); cstr = ipmi_sensor_reading_name_string(sensor, event); if (strcmp(cstr, "unknown") != 0) ipmi_cmdlang_out(cmd_info, "Name", cstr); for (dir = IPMI_ASSERTION; dir <= IPMI_DEASSERTION; dir++) { rv = ipmi_sensor_discrete_event_supported(sensor, event, dir, &val); if (rv || !val) continue; ipmi_cmdlang_out(cmd_info, "Supports", ipmi_get_event_dir_string(dir)); } ipmi_cmdlang_up(cmd_info); } } return; out_err: ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_dump)"; }
static void got_events(ipmi_sensor_t *sensor, int err, ipmi_event_state_t *states, void *cb_data) { sdata_t *sdata = cb_data; int rv; if (err) { printf("Error 0x%x getting events for sensor %s\n", err, sdata->name); goto out_err; } /* Turn on the general events for a sensor, since this at least supports per-sensor enables. */ ipmi_event_state_set_events_enabled(sdata->es, 1); ipmi_event_state_set_scanning_enabled(sdata->es, 1); printf("Sensor %s event settings:\n", sdata->name); if (sdata->state_sup != IPMI_EVENT_SUPPORT_PER_STATE) { /* No per-state sensors, just do the global enable. */ } else if (ipmi_sensor_get_event_reading_type(sensor) == IPMI_EVENT_READING_TYPE_THRESHOLD) { /* Check each event, print out the current state, and turn it on in the events to set if it is available. */ enum ipmi_event_value_dir_e value_dir; enum ipmi_event_dir_e dir; enum ipmi_thresh_e thresh; int val; for (value_dir=IPMI_GOING_LOW; value_dir<=IPMI_GOING_HIGH; value_dir++) { for (dir=IPMI_ASSERTION; dir<=IPMI_DEASSERTION; dir++) { for (thresh=IPMI_LOWER_NON_CRITICAL; thresh<=IPMI_UPPER_NON_RECOVERABLE; thresh++) { char *v; rv = ipmi_sensor_threshold_event_supported (sensor, thresh, value_dir, dir, &val); if (rv || !val) continue; if (ipmi_is_threshold_event_set(states, thresh, value_dir, dir)) v = ""; else v = " not"; printf(" %s %s %s was%s enabled\n", ipmi_get_threshold_string(thresh), ipmi_get_value_dir_string(value_dir), ipmi_get_event_dir_string(dir), v); ipmi_threshold_event_set(sdata->es, thresh, value_dir, dir); } } } } else { /* Check each event, print out the current state, and turn it on in the events to set if it is available. */ enum ipmi_event_dir_e dir; int i; for (dir=IPMI_ASSERTION; dir<=IPMI_DEASSERTION; dir++) { for (i=0; i<15; i++) { char *v; int val; rv = ipmi_sensor_discrete_event_supported (sensor, i, dir, &val); if (rv || !val) continue; if (ipmi_is_discrete_event_set(states, i, dir)) v = ""; else v = " not"; printf(" bit %d %s was%s enabled\n", i, ipmi_get_event_dir_string(dir), v); ipmi_discrete_event_set(sdata->es, i, dir); } } } rv = ipmi_sensor_set_event_enables(sensor, sdata->es, event_set_done, sdata); if (rv) { printf("Error 0x%x enabling events for sensor %s\n", err, sdata->name); goto out_err; } return; out_err: release_sdata(sdata); }