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; }
/** * Add the given dependencies and inherit them on all child triggers. * * @param array $triggersData an array of trigger dependency pairs, each pair in the form of * array('triggerid' => 1, 'dependsOnTriggerid' => 2) * * @return array */ public function addDependencies(array $triggersData) { $triggersData = zbx_toArray($triggersData); $triggerIds = array_unique(zbx_objectValues($triggersData, 'triggerid')); if (!$this->isWritable($triggerIds)) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); } $this->validateAddDependencies($triggersData); foreach ($triggersData as $dep) { $triggerId = $dep['triggerid']; $depTriggerId = $dep['dependsOnTriggerid']; DB::insert('trigger_depends', [['triggerid_down' => $triggerId, 'triggerid_up' => $depTriggerId]]); // propagate the dependencies to the child triggers $childTriggers = API::getApiService()->select($this->tableName(), ['output' => ['triggerid'], 'filter' => ['templateid' => $triggerId]]); if ($childTriggers) { foreach ($childTriggers as $childTrigger) { $childHostsQuery = get_hosts_by_triggerid($childTrigger['triggerid']); while ($childHost = DBfetch($childHostsQuery)) { $newDep = [$childTrigger['triggerid'] => $depTriggerId]; $newDep = replace_template_dependencies($newDep, $childHost['hostid']); $this->addDependencies([['triggerid' => $childTrigger['triggerid'], 'dependsOnTriggerid' => $newDep[$childTrigger['triggerid']]]]); } } } } return ['triggerids' => $triggerIds]; }
/** * Add the given dependencies and inherit them on all child triggers. * * @param array $triggerPrototypes * @param string $triggerPrototypes[]['triggerid'] * @param array $triggerPrototypes[]['dependencies'] * @param string $triggerPrototypes[]['dependencies'][]['triggerid'] */ public function addDependencies(array $triggerPrototypes) { $this->validateAddDependencies($triggerPrototypes); $insert = []; foreach ($triggerPrototypes as $triggerPrototype) { if (!array_key_exists('dependencies', $triggerPrototype)) { continue; } foreach ($triggerPrototype['dependencies'] as $dependency) { $insert[] = ['triggerid_down' => $triggerPrototype['triggerid'], 'triggerid_up' => $dependency['triggerid']]; } } DB::insertBatch('trigger_depends', $insert); foreach ($triggerPrototypes as $triggerPrototype) { // Propagate the dependencies to the child triggers. $childTriggers = API::getApiService()->select($this->tableName(), ['output' => ['triggerid'], 'filter' => ['templateid' => $triggerPrototype['triggerid']]]); if ($childTriggers) { foreach ($childTriggers as &$childTrigger) { $childTrigger['dependencies'] = []; $childHostsQuery = get_hosts_by_triggerid($childTrigger['triggerid']); while ($childHost = DBfetch($childHostsQuery)) { foreach ($triggerPrototype['dependencies'] as $dependency) { $newDependency = [$childTrigger['triggerid'] => $dependency['triggerid']]; $newDependency = replace_template_dependencies($newDependency, $childHost['hostid']); $childTrigger['dependencies'][] = ['triggerid' => $newDependency[$childTrigger['triggerid']]]; } } } unset($childTrigger); $this->addDependencies($childTriggers); } } }
$description[] = ':'; } else { $real_hosts = $realHosts[$triggerid]; $real_host = reset($real_hosts); $description[] = new CLink($real_host['host'], 'triggers.php?&hostid=' . $real_host['hostid'], 'unknown'); $description[] = ':'; } } $description[] = new CLink($trigger['description'], 'triggers.php?form=update&triggerid=' . $triggerid); //add dependencies { $deps = $trigger['dependencies']; if (count($deps) > 0) { $description[] = array(BR(), bold(S_DEPENDS_ON . ' : ')); foreach ($deps as $dnum => $dep_trigger) { $description[] = BR(); $hosts = get_hosts_by_triggerid($dep_trigger['triggerid']); while ($host = DBfetch($hosts)) { $description[] = $host['host']; $description[] = ', '; } array_pop($description); $description[] = ' : '; $description[] = expand_trigger_description_by_data($dep_trigger); } } // } add dependencies if ($trigger['value'] != TRIGGER_VALUE_UNKNOWN) { $trigger['error'] = ''; } $templated = false; foreach ($trigger['hosts'] as $hostid => $host) {
foreach ($triggers as $triggerid => $trigger) { $description = array(); if ($trigger['templateid'] > 0) { $real_hosts = get_realhosts_by_triggerid($triggerid); $real_host = DBfetch($real_hosts); $description[] = new CLink($real_host['host'], 'triggers.php?&hostid=' . $real_host['hostid'], 'unknown'); $description[] = ':'; } $description[] = new CLink(expand_trigger_description($triggerid), 'triggers.php?form=update&triggerid=' . $triggerid); // <<<--- add dependencies --->>> $deps = get_trigger_dependencies_by_triggerid($triggerid); if (count($deps) > 0) { $description[] = array(BR(), bold(S_DEPENDS_ON . ' : ')); foreach ($deps as $num => $dep_triggerid) { $description[] = BR(); $hosts = get_hosts_by_triggerid($dep_triggerid); while ($host = DBfetch($hosts)) { $description[] = $host['host']; $description[] = ', '; } array_pop($description); $description[] = ' : '; $description[] = expand_trigger_description($dep_triggerid); } } // --->>> add dependencies <<<--- if ($trigger['status'] != TRIGGER_STATUS_UNKNOWN) { $trigger['error'] = ''; } if (!zbx_empty($trigger['error']) && HOST_STATUS_TEMPLATE != $trigger['hoststatus']) { $error = new CDiv(SPACE, 'error_icon');
$action .= 'ZBX_SYSMAPS[' . $cmapid . '].map.mselement["label_location"]=' . $db_map['label_location'] . '; ' . "\n"; foreach ($db_map['selements'] as $snum => $selement) { $info = $map_info[$selement['selementid']]; // $element['image'] = get_base64_icon($element); $selement['image'] = get_selement_iconid($selement, $info); $action .= 'ZBX_SYSMAPS[' . $cmapid . '].map.add_selement(' . zbx_jsvalue($selement) . '); ' . "\n"; } foreach ($db_map['links'] as $enum => $link) { foreach ($link as $key => $value) { if (is_int($key)) { unset($link[$key]); } } $link['linktriggers'] = zbx_toHash($link['linktriggers'], 'linktriggerid'); foreach ($link['linktriggers'] as $lnum => $linktrigger) { $hosts = get_hosts_by_triggerid($linktrigger['triggerid']); if ($host = DBfetch($hosts)) { $description = $host['host'] . ':' . expand_trigger_description($linktrigger['triggerid']); } $link['linktriggers'][$lnum]['desc_exp'] = $description; } order_result($link['linktriggers'], 'desc_exp'); $action .= 'ZBX_SYSMAPS[' . $cmapid . '].map.add_link(' . zbx_jsvalue($link) . '); ' . "\n"; } unset($db_map['selements']); unset($db_map['links']); $action .= 'ZBX_SYSMAPS[' . $cmapid . '].map.sysmap = ' . zbx_jsvalue($db_map, true) . ";\n"; $action .= 'ZBX_SYSMAPS[' . $cmapid . '].map.updateMapImage(); ' . "\n"; $action .= 'ZBX_SYSMAPS[' . $cmapid . '].map.updateSelementsIcon(); ' . "\n"; print $action; break;