Example #1
0
             array_push($new_operation['opconditions'], $new_opcondition);
         }
         $_REQUEST['new_operation'] = $new_operation;
         unset($_REQUEST['new_opcondition']);
     }
 } else {
     if (inarr_isset(array('del_opcondition', 'g_opconditionid'))) {
         $new_operation = get_request('new_operation', array());
         foreach ($_REQUEST['g_opconditionid'] as $val) {
             unset($new_operation['opconditions'][$val]);
         }
         $_REQUEST['new_operation'] = $new_operation;
     } else {
         if (inarr_isset(array('add_operation', 'new_operation'))) {
             $new_operation = $_REQUEST['new_operation'];
             if (validate_operation($new_operation)) {
                 zbx_rksort($new_operation);
                 $_REQUEST['operations'] = get_request('operations', array());
                 if ($new_operation['esc_step_from'] <= $new_operation['esc_step_to'] || $new_operation['esc_step_to'] == 0) {
                     if (!isset($new_operation['id'])) {
                         if (!str_in_array($new_operation, $_REQUEST['operations'])) {
                             array_push($_REQUEST['operations'], $new_operation);
                         }
                     } else {
                         $id = $new_operation['id'];
                         unset($new_operation['id']);
                         $_REQUEST['operations'][$id] = $new_operation;
                     }
                     unset($_REQUEST['new_operation']);
                 } else {
                     info(S_INCORRECT_STEPS);
Example #2
0
function update_action($actionid, $name, $eventsource, $esc_period, $def_shortdata, $def_longdata, $recovery_msg, $r_shortdata, $r_longdata, $evaltype, $status, $conditions, $operations)
{
    if (!is_array($conditions) || count($conditions) == 0) {
        /*
        error(S_NO_CONDITIONS_DEFINED);
        return false;
        */
    } else {
        if (!check_permission_for_action_conditions($conditions)) {
            return false;
        }
        foreach ($conditions as $condition) {
            if (!validate_condition($condition['type'], $condition['value'])) {
                return false;
            }
        }
    }
    if (!is_array($operations) || count($operations) == 0) {
        error(S_NO_OPERATIONS_DEFINED);
        return false;
    }
    foreach ($operations as $operation) {
        if (!validate_operation($operation)) {
            return false;
        }
    }
    $result = DBexecute('UPDATE actions SET name=' . zbx_dbstr($name) . ',eventsource=' . $eventsource . ',esc_period=' . $esc_period . ',def_shortdata=' . zbx_dbstr($def_shortdata) . ',def_longdata=' . zbx_dbstr($def_longdata) . ',recovery_msg=' . $recovery_msg . ',r_shortdata=' . zbx_dbstr($r_shortdata) . ',r_longdata=' . zbx_dbstr($r_longdata) . ',evaltype=' . $evaltype . ',status=' . $status . ' WHERE actionid=' . $actionid);
    if ($result) {
        DBexecute('DELETE FROM conditions WHERE actionid=' . $actionid);
        $opers = get_operations_by_actionid($actionid);
        while ($operation = DBFetch($opers)) {
            DBexecute('DELETE FROM opconditions WHERE operationid=' . $operation['operationid']);
        }
        DBexecute('DELETE FROM operations WHERE actionid=' . $actionid);
        foreach ($operations as $operation) {
            if (!($result = add_action_operation($actionid, $operation))) {
                break;
            }
        }
        if ($result) {
            foreach ($conditions as $condition) {
                if (!($result = add_action_condition($actionid, $condition))) {
                    break;
                }
            }
        }
    }
    return $result;
}
 /**
  * add operations
  *
  * @param array $operations multidimensional array with operations data
  * @param array $operations[0,...]['actionid']
  * @param array $operations[0,...]['operationtype']
  * @param array $operations[0,...]['object']
  * @param array $operations[0,...]['objectid']
  * @param array $operations[0,...]['shortdata']
  * @param array $operations[0,...]['longdata']
  * @param array $operations[0,...]['esc_period']
  * @param array $operations[0,...]['esc_step_from']
  * @param array $operations[0,...]['esc_step_to']
  * @param array $operations[0,...]['default_msg']
  * @param array $operations[0,...]['evaltype']
  * @param array $operations[0,...]['mediatypeid']
  * @param array $operations[0,...]['opconditions']
  * @param array $operations[0,...]['opconditions']['conditiontype']
  * @param array $operations[0,...]['opconditions']['operator']
  * @param array $operations[0,...]['opconditions']['value']
  * @return boolean
  */
 protected static function addOperations($operations)
 {
     $operations = zbx_toArray($operations);
     $operation_inserts = array();
     $opcondition_inserts = array();
     $opmediatype_inserts = array();
     foreach ($operations as $onum => $operation) {
         if (!validate_operation($operation)) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
         }
     }
     foreach ($operations as $onum => $operation) {
         $operation_db_fields = array('actionid' => null, 'operationtype' => null);
         if (!check_db_fields($operation_db_fields, $operation)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, S_INCORRECT_PARAMETER_USED_FOR_OPERATIONS);
         }
         $operation_inserts[$onum] = $operation;
     }
     $operationids = DB::insert('operations', $operation_inserts);
     foreach ($operations as $onum => $operation) {
         if (isset($operation['opconditions'])) {
             foreach ($operation['opconditions'] as $opcondition) {
                 $opcondition['operationid'] = $operationids[$onum];
                 $opcondition_inserts[] = $opcondition;
             }
         }
         if ($operation['mediatypeid'] > 0) {
             $opmediatype_inserts[] = array('operationid' => $operationids[$onum], 'mediatypeid' => $operation['mediatypeid']);
         }
     }
     DB::insert('opconditions', $opcondition_inserts);
     DB::insert('opmediatypes', $opmediatype_inserts);
     return true;
 }