Esempio n. 1
0
function delete_template_triggers($hostid, $templateids = null, $unlink_mode = false)
{
    zbx_value2array($templateids);
    $triggers = get_triggers_by_hostid($hostid);
    while ($trigger = DBfetch($triggers)) {
        if ($trigger['templateid'] == 0) {
            continue;
        }
        if ($templateids != null) {
            $db_tmp_hosts = get_hosts_by_triggerid($trigger["templateid"]);
            $tmp_host = DBfetch($db_tmp_hosts);
            if (!uint_in_array($tmp_host["hostid"], $templateids)) {
                continue;
            }
        }
        if ($unlink_mode) {
            if (DBexecute('UPDATE triggers SET templateid=0 WHERE triggerid=' . $trigger['triggerid'])) {
                info('Trigger "' . $trigger["description"] . '" unlinked');
            }
        } else {
            delete_trigger($trigger["triggerid"]);
        }
    }
    return TRUE;
}
 /**
  * Delete triggers
  *
  * @param array $triggerids array with trigger ids
  * @return deleted triggerids
  */
 public static function delete($triggerids)
 {
     $triggerids = zbx_toArray($triggerids);
     try {
         self::BeginTransaction(__METHOD__);
         $options = array('triggerids' => $triggerids, 'editable' => 1, 'extendoutput' => 1, 'preservekeys' => 1);
         $del_triggers = self::get($options);
         foreach ($triggerids as $gnum => $triggerid) {
             if (!isset($del_triggers[$triggerid])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, S_NO_PERMISSIONS);
             }
         }
         if (!empty($triggerids)) {
             $result = delete_trigger($triggerids);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete trigger');
             }
         } else {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Empty input parameter [ triggerids ]');
         }
         self::EndTransaction(true, __METHOD__);
         return array('triggerids' => $triggerids);
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }
Esempio n. 3
0
                                }
                                show_messages($result, S_TRIGGER_ADDED, S_CANNOT_ADD_TRIGGER);
                            } else {
                                if ($_REQUEST['go'] == 'delete' && isset($_REQUEST['g_triggerid'])) {
                                    $_REQUEST['g_triggerid'] = array_intersect($_REQUEST['g_triggerid'], $available_triggers);
                                    DBstart();
                                    foreach ($_REQUEST['g_triggerid'] as $id => $triggerid) {
                                        $row = DBfetch(DBselect('SELECT triggerid,templateid FROM triggers t WHERE t.triggerid=' . $triggerid));
                                        if ($row['templateid'] != 0) {
                                            unset($_REQUEST['g_triggerid'][$id]);
                                            continue;
                                        }
                                        $description = expand_trigger_description($triggerid);
                                        add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_TRIGGER, $triggerid, $description, NULL, NULL, NULL);
                                    }
                                    $result = delete_trigger($_REQUEST['g_triggerid']);
                                    $result = DBend($result);
                                    show_messages($result, S_TRIGGERS_DELETED, S_CANNOT_DELETE_TRIGGERS);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
if (isset($_REQUEST['hostid']) && !isset($_REQUEST['groupid']) && !isset($_REQUEST['triggerid'])) {
    $sql = 'SELECT DISTINCT hg.groupid ' . ' FROM hosts_groups hg ' . ' WHERE hg.hostid=' . $_REQUEST['hostid'];
    if ($group = DBfetch(DBselect($sql, 1))) {
        $_REQUEST['groupid'] = $group['groupid'];
Esempio n. 4
0
 /**
  * Delete triggers
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @param _array $triggerids
  * @return boolean
  */
 public static function delete($triggerids)
 {
     $result = delete_trigger($triggerids);
     if ($result) {
         return $result;
     } else {
         self::$error[] = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }