$options = array('select_hosts' => 1, 'editable' => 1, 'extendoutput' => 1); if ($showdisabled == 0) { $options += array('status' => TRIGGER_STATUS_ENABLED); } if ($PAGE_HOSTS['selected'] > 0) { $options += array('hostids' => $PAGE_HOSTS['selected']); } else { if ($PAGE_GROUPS['selected'] > 0) { $options += array('groupids' => $PAGE_GROUPS['selected']); } } $triggers = CTrigger::get($options); 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[] = ', ';
function get_realhosts_by_triggerid($triggerid) { $trigger = get_trigger_by_triggerid($triggerid); if ($trigger['templateid'] > 0) { return get_realhosts_by_triggerid($trigger['templateid']); } return get_hosts_by_triggerid($triggerid); }
} if ($PAGE_HOSTS['selected'] > 0) { $sql_where .= ' AND h.hostid=' . $PAGE_HOSTS['selected']; } $sql = 'SELECT DISTINCT h.hostid,h.host,h.status as hoststatus,t.*' . ' FROM triggers t ' . ' LEFT JOIN functions f ON t.triggerid=f.triggerid ' . ' LEFT JOIN items i ON f.itemid=i.itemid ' . ' LEFT JOIN hosts h ON h.hostid=i.hostid ' . ' WHERE ' . DBin_node('t.triggerid') . $sql_where . ' AND ' . DBcondition('t.triggerid', $available_triggers) . order_by('h.host,t.description,t.priority,t.status'); $result = DBselect($sql); while ($row = DBfetch($result)) { if (is_null($row['host'])) { $row['host'] = ''; } if (is_null($row['hostid'])) { $row['hostid'] = '0'; } $description = array(new CCheckBox('g_triggerid[' . $row['triggerid'] . ']', NULL, NULL, $row['triggerid']), SPACE); if ($row['templateid']) { $real_hosts = get_realhosts_by_triggerid($row['triggerid']); $real_host = DBfetch($real_hosts); if ($real_host) { $description[] = new CLink($real_host['host'], 'triggers.php?&hostid=' . $real_host['hostid'], 'unknown'); } else { $description[] = new CSpan('error', 'on'); } $description[] = ':'; } $description[] = new CLink(expand_trigger_description($row['triggerid']), 'triggers.php?form=update&triggerid=' . $row['triggerid'] . '&hostid=' . $row['hostid'], 'action'); //add dependencies $deps = get_trigger_dependencies_by_triggerid($row['triggerid']); if (count($deps) > 0) { $description[] = array(BR(), bold(S_DEPENDS_ON . ':'), SPACE); foreach ($deps as $num => $dep_triggerid) { // shows host name of depending trigger