static int alerter_executor(struct sm_instance *smi, const char *implements, const policy_action_t *action, /* arguments for the action : */ const entry_id_t *p_id, attr_set_t *p_attrs, const action_params_t *params, post_action_e *what_after, db_cb_func_t db_cb_fn, void *db_cb_arg) { const char *val; const char *status_str = NULL; int rc = 0; bool alert = false; if (params == NULL) { DisplayLog(LVL_MAJOR, TAG, "Missing action parameters for 'alerter' status manager"); return -EINVAL; } val = rbh_param_get(params, "alert"); if (val == NULL) { DisplayLog(LVL_MAJOR, TAG, "Missing action parameter 'alert = yes/clear' for 'alerter' status manager"); return -EINVAL; } if (!strcasecmp(val, "clear")) { /* if the action succeed new status will be: clear */ status_str = alerter_status2str(STATUS_CLEAR); } else if (!strcasecmp(val, "raise")) { /* if the action succeed new status will be: alert */ status_str = alerter_status2str(STATUS_ALERT); alert = true; } else { DisplayLog(LVL_MAJOR, TAG, "Invalid value for 'alert' action parameter: 'raise' or 'clear' expected"); return -EINVAL; } /* set it now, at it may be modified by the specified function */ *what_after = PA_UPDATE; rc = action_helper(action, "alert", p_id, p_attrs, params, smi, NULL, what_after, db_cb_fn, db_cb_arg); if (rc) return rc; set_uint_info(smi, p_attrs, ATTR_LAST_CHECK, (unsigned int)time(NULL)); if (alert) set_uint_info(smi, p_attrs, ATTR_LAST_ALERT, (unsigned int)time(NULL)); return set_status_attr(smi, p_attrs, status_str); }
static int check_executor(struct sm_instance *smi, const char *implements, const policy_action_t *action, /* arguments for the action : */ const entry_id_t *p_id, attr_set_t *p_attrs, const action_params_t *params, post_action_e *what_after, db_cb_func_t db_cb_fn, void *db_cb_arg) { int rc = 0; time_t t; bool use_str = false; GString *out = NULL; *what_after = PA_UPDATE; /* Run the action. * Functions (defined in modules): * o As input, a function action should use 'output' attribute to compare * the result of the last execution. * o As output, a function action can store its result to 'output' * attribute. * Commands: * o As input, a command can retrieve the last output by using '{output}' * placeholder. * o As output, output will be set as the contents of stdout * (truncated to 255 char). */ out = g_string_new(""); rc = action_helper(action, "check", p_id, p_attrs, params, smi, out, what_after, db_cb_fn, db_cb_arg); /* update the value of last_check */ t = time(NULL); set_uint_info(smi, p_attrs, ATTR_LAST_CHECK, (unsigned int)t); /* depending on the action status, update the value of last_success */ if (rc == 0) { set_status_attr(smi, p_attrs, check_status2str(STATUS_OK)); set_uint_info(smi, p_attrs, ATTR_LAST_SUCCESS, (unsigned int)t); /* set output if the action was a successful command */ if (action->type == ACTION_COMMAND) { int rc2; DisplayLog(LVL_DEBUG, "check_exec", "check command output='%s'", out->str); rc2 = set_sm_info(smi, p_attrs, ATTR_OUTPUT, out->str); if (rc2 == 0) /* str is now owner by p_attrs */ use_str = true; } } else { set_status_attr(smi, p_attrs, check_status2str(STATUS_FAILED)); DisplayLog(LVL_EVENT, "check_exec", "check command FAILED on: " DFID_NOBRACE " (%s)", PFID(p_id), ATTR(p_attrs, fullpath)); } g_string_free(out, use_str ? FALSE : TRUE); return rc; }