Esempio n. 1
0
static void
got_thresholds(ipmi_sensor_t     *sensor,
	       int               err,
	       ipmi_thresholds_t *th,
	       void              *cb_data)
{
    sdata_t            *sdata = cb_data;
    enum ipmi_thresh_e thresh;
    int                rv;

    if (err) {
	printf("Error 0x%x getting events for sensor %s\n", err, sdata->name);
	goto out_err;
    }

    printf("Sensor %s threshold settings:\n", sdata->name);
    for (thresh=IPMI_LOWER_NON_CRITICAL;
	 thresh<=IPMI_UPPER_NON_RECOVERABLE;
	 thresh++)
    {
	int    val;
	double dval;

	rv = ipmi_sensor_threshold_readable(sensor, thresh, &val);
	if (rv || !val)
	    /* Threshold not available. */
	    continue;

	rv = ipmi_threshold_get(th, thresh, &dval);
	if (rv) {
	    printf("  threshold %s could not be fetched due to error 0x%x\n",
		   ipmi_get_threshold_string(thresh), rv);
	} else {
	    printf("  threshold %s is %lf\n",
		   ipmi_get_threshold_string(thresh), dval);
	}
    }

    rv = ipmi_get_default_sensor_thresholds(sensor, sdata->th);
    if (rv) {
	printf("Error 0x%x getting def thresholds for sensor %s\n",
	       rv, sdata->name);
	goto out_err;
    }

    rv = ipmi_sensor_set_thresholds(sensor, sdata->th, thresholds_set, sdata);
    if (rv) {
	printf("Error 0x%x setting thresholds for sensor %s\n",
	       rv, sdata->name);
	goto out_err;
    }
    return;

 out_err:
    release_sdata(sdata);
}
Esempio n. 2
0
static SaErrorT set_thresholds(ipmi_sensor_t                 *sensor, 
			  struct ohoi_sensor_thresholds *thres_data)
{
	ipmi_thresholds_t	*info = thres_data->thrhlds;
	int			rv;	
	

	rv = init_thresholeds_info(sensor, &thres_data->sensor_thres, info);
	if (rv != SA_OK) {
		dbg("Unable to init sensor thresholds: 0x%x\n", rv);
		return rv;
	}

	rv = ipmi_sensor_set_thresholds(sensor, info, thres_set_data, 
                                 thres_data);
	if (rv) {
		dbg("Unable to set sensor thresholds: 0x%x\n", rv);
		return SA_ERR_HPI_INTERNAL_ERROR;
	}

	return SA_OK;
}
Esempio n. 3
0
static void
sensor_set_thresholds(ipmi_sensor_t *sensor, void *cb_data)
{
    ipmi_cmd_info_t    *cmd_info = cb_data;
    ipmi_cmdlang_t     *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info);
    int                rv;
    int                curr_arg = ipmi_cmdlang_get_curr_arg(cmd_info);
    int                argc = ipmi_cmdlang_get_argc(cmd_info);
    char               **argv = ipmi_cmdlang_get_argv(cmd_info);
    ipmi_thresholds_t  *th = NULL;
    enum ipmi_thresh_e thresh;
    double             val;

    if ((argc - curr_arg) < 1) {
	/* Not enough parameters */
	cmdlang->errstr = "Not enough parameters";
	cmdlang->err = EINVAL;
	goto out_err;
    }

    th = ipmi_mem_alloc(ipmi_thresholds_size());
    if (!th) {
	cmdlang->errstr = "Out of memory";
	cmdlang->err = ENOMEM;
	goto out_err;
    }
    ipmi_thresholds_init(th);
    while (curr_arg < argc) {
	ipmi_cmdlang_get_threshold(argv[curr_arg], &thresh, cmd_info);
	if (cmdlang->err) {
	    cmdlang->errstr = "Invalid threshold";
	    goto out_err;
	}
	curr_arg++;

	ipmi_cmdlang_get_double(argv[curr_arg], &val, cmd_info);
	if (cmdlang->err) {
	    cmdlang->errstr = "Invalid threshold value";
	    goto out_err;
	}
	curr_arg++;

	rv = ipmi_threshold_set(th, sensor, thresh, val);
	if (rv) {
	    cmdlang->errstr = "Error setting value";
	    cmdlang->err = rv;
	    goto out_err;
	}
    }

    ipmi_cmdlang_cmd_info_get(cmd_info);
    rv = ipmi_sensor_set_thresholds(sensor, th, sensor_set_thresholds_done,
				    cmd_info);
    if (rv) {
	ipmi_cmdlang_cmd_info_put(cmd_info);
	cmdlang->err = rv;
	cmdlang->errstr = "Error setting thresholds";
	goto out_err;
    }
    ipmi_mem_free(th);
    return;

 out_err:
    ipmi_sensor_get_name(sensor, cmdlang->objstr,
			 cmdlang->objstr_len);
    cmdlang->location = "cmd_sensor.c(sensor_set_thresholds)";
    if (th)
	ipmi_mem_free(th);
}