/****************************************************************************** * * * Function: check_operation_conditions * * * * Purpose: * * * * Parameters: event - event to check * * actionid - action ID for matching * * * * Return value: SUCCEED - matches, FAIL - otherwise * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ static int check_operation_conditions(DB_EVENT *event, zbx_uint64_t operationid, unsigned char evaltype) { const char *__function_name = "check_operation_conditions"; DB_RESULT result; DB_ROW row; DB_CONDITION condition; int ret = SUCCEED; /* SUCCEED required for ACTION_EVAL_TYPE_AND_OR */ int cond, old_type = -1, exit = 0; zabbix_log(LOG_LEVEL_DEBUG, "In %s() operationid:" ZBX_FS_UI64, __function_name, operationid); result = DBselect("select conditiontype,operator,value" " from opconditions" " where operationid=" ZBX_FS_UI64 " order by conditiontype", operationid); while (NULL != (row = DBfetch(result)) && 0 == exit) { memset(&condition, 0, sizeof(condition)); condition.conditiontype = atoi(row[0]); condition.operator = atoi(row[1]); condition.value = row[2]; switch (evaltype) { case ACTION_EVAL_TYPE_AND_OR: if (old_type == condition.conditiontype) /* OR conditions */ { if (SUCCEED == check_action_condition(event, &condition)) ret = SUCCEED; } else /* AND conditions */ { /* Break if PREVIOUS AND condition is FALSE */ if (ret == FAIL) exit = 1; else if (FAIL == check_action_condition(event, &condition)) ret = FAIL; } old_type = condition.conditiontype; break; case ACTION_EVAL_TYPE_AND: cond = check_action_condition(event, &condition); /* Break if any of AND conditions is FALSE */ if (cond == FAIL) { ret = FAIL; exit = 1; } else ret = SUCCEED; break; case ACTION_EVAL_TYPE_OR: cond = check_action_condition(event, &condition); /* Break if any of OR conditions is TRUE */ if (cond == SUCCEED) { ret = SUCCEED; exit = 1; } else ret = FAIL; break; default: ret = FAIL; exit = 1; break; } } DBfree_result(result); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: check_operation_conditions * * * * Purpose: * * * * Parameters: event - event to check * * actionid - action ID for matching * * * * Return value: SUCCEED - matches, FAIL - otherwise * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ static int check_operation_conditions(DB_EVENT *event, DB_OPERATION *operation) { DB_RESULT result; DB_ROW row; DB_CONDITION condition; /* SUCCEED required for ACTION_EVAL_TYPE_AND_OR */ int ret = SUCCEED; int old_type = -1; int cond; int num = 0; int exit = 0; zabbix_log(LOG_LEVEL_DEBUG, "In check_opeartion_conditions (operationid:" ZBX_FS_UI64 ")", operation->operationid); result = DBselect("select conditiontype,operator,value from opconditions where operationid=" ZBX_FS_UI64 " order by conditiontype", operation->operationid); while (NULL != (row = DBfetch(result)) && (0 == exit)) { num++; memset(&condition, 0, sizeof(condition)); condition.conditiontype = atoi(row[0]); condition.operator = atoi(row[1]); condition.value = row[2]; switch (operation->evaltype) { case ACTION_EVAL_TYPE_AND_OR: if (old_type == condition.conditiontype) { /* OR conditions */ if (SUCCEED == check_action_condition(event, &condition)) ret = SUCCEED; } else { /* AND conditions */ /* Break if PREVIOUS AND condition is FALSE */ if (ret == FAIL) exit = 1; else if (FAIL == check_action_condition(event, &condition)) ret = FAIL; } old_type = condition.conditiontype; break; case ACTION_EVAL_TYPE_AND: cond = check_action_condition(event, &condition); /* Break if any of AND conditions is FALSE */ if(cond == FAIL) { ret = FAIL; exit = 1; } else ret = SUCCEED; break; case ACTION_EVAL_TYPE_OR: cond = check_action_condition(event, &condition); /* Break if any of OR conditions is TRUE */ if (cond == SUCCEED) { ret = SUCCEED; exit = 1; } else ret = FAIL; break; default: ret = FAIL; exit = 1; break; } } DBfree_result(result); zabbix_log(LOG_LEVEL_DEBUG, "End check_opeartion_conditions():%s", zbx_result_string(ret)); return ret; }