/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $options = array('monitored' => true, 'value' => array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE), 'triggerLimit' => $this->screenitem['elements'], 'eventLimit' => $this->screenitem['elements']); $item = new CTableInfo(_('No events found.')); $item->setHeader(array(_('Time'), is_show_all_nodes() ? _('Node') : null, _('Host'), _('Description'), _('Value'), _('Severity'))); $events = getLastEvents($options); foreach ($events as $event) { $trigger = $event['trigger']; $host = $event['host']; $statusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); $item->addRow(array(zbx_date2str(_('d M Y H:i:s'), $event['clock']), get_node_name_by_elid($event['objectid']), $host['name'], new CLink($trigger['description'], 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']), $statusSpan, getSeverityCell($trigger['priority']))); } return $this->getOutput($item); }
function get_act_new_cond_form($action = null) { $tblCond = new CTable('', 'nowrap'); if (isset($_REQUEST['actionid']) && empty($action)) { $action = get_action_by_actionid($_REQUEST['actionid']); } if (isset($_REQUEST['actionid']) && !isset($_REQUEST['form_refresh'])) { $eventsource = $action['eventsource']; $evaltype = $action['evaltype']; } else { $evaltype = get_request('evaltype'); $eventsource = get_request('eventsource'); } $allowed_conditions = get_conditions_by_eventsource($eventsource); /* init new_condition variable */ $new_condition = get_request('new_condition', array()); if (!is_array($new_condition)) { $new_condition = array(); } if (!isset($new_condition['type'])) { $new_condition['type'] = CONDITION_TYPE_TRIGGER_NAME; } if (!isset($new_condition['operator'])) { $new_condition['operator'] = CONDITION_OPERATOR_LIKE; } if (!isset($new_condition['value'])) { $new_condition['value'] = ''; } if (!str_in_array($new_condition['type'], $allowed_conditions)) { $new_condition['type'] = $allowed_conditions[0]; } // NEW CONDITION $rowCondition = array(); // add condition type $cmbCondType = new CComboBox('new_condition[type]', $new_condition['type'], 'submit()'); foreach ($allowed_conditions as $cond) { $cmbCondType->addItem($cond, condition_type2str($cond)); } array_push($rowCondition, $cmbCondType); // add condition operation $cmbCondOp = new CComboBox('new_condition[operator]'); foreach (get_operators_by_conditiontype($new_condition['type']) as $op) { $cmbCondOp->addItem($op, condition_operator2str($op)); } array_push($rowCondition, $cmbCondOp); // add condition value switch ($new_condition['type']) { case CONDITION_TYPE_HOST_GROUP: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('group', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=group&srctbl=host_group" . "&srcfld1=groupid&srcfld2=name',450,450);", 'T')); break; case CONDITION_TYPE_HOST_TEMPLATE: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('host', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=host&srctbl=host_templates" . "&srcfld1=hostid&srcfld2=host',450,450);", 'T')); break; case CONDITION_TYPE_HOST: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('host', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=host&srctbl=hosts" . "&srcfld1=hostid&srcfld2=host',450,450);", 'T')); break; case CONDITION_TYPE_TRIGGER: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('trigger', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=trigger&srctbl=triggers" . "&srcfld1=triggerid&srcfld2=description');", 'T')); break; case CONDITION_TYPE_TRIGGER_NAME: $rowCondition[] = new CTextBox('new_condition[value]', "", 40); break; case CONDITION_TYPE_TRIGGER_VALUE: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE) as $tr_val) { $cmbCondVal->addItem($tr_val, trigger_value2str($tr_val)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_TIME_PERIOD: $rowCondition[] = new CTextBox('new_condition[value]', "1-7,00:00-23:59", 40); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER) as $id) { $cmbCondVal->addItem($id, get_severity_description($id)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_MAINTENANCE: $rowCondition[] = new CCol(S_MAINTENANCE_SMALL); break; case CONDITION_TYPE_DHOST_IP: $rowCondition[] = new CTextBox('new_condition[value]', '192.168.0.1-127,192.168.2.1', 50); break; case CONDITION_TYPE_DSERVICE_TYPE: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(SVC_SSH, SVC_LDAP, SVC_SMTP, SVC_FTP, SVC_HTTP, SVC_POP, SVC_NNTP, SVC_IMAP, SVC_TCP, SVC_AGENT, SVC_SNMPv1, SVC_SNMPv2, SVC_ICMPPING) as $svc) { $cmbCondVal->addItem($svc, discovery_check_type2str($svc)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_DSERVICE_PORT: $rowCondition[] = new CTextBox('new_condition[value]', '0-1023,1024-49151', 40); break; case CONDITION_TYPE_DSTATUS: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(DOBJECT_STATUS_UP, DOBJECT_STATUS_DOWN, DOBJECT_STATUS_DISCOVER, DOBJECT_STATUS_LOST) as $stat) { $cmbCondVal->addItem($stat, discovery_object_status2str($stat)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_DUPTIME: $rowCondition[] = new CNumericBox('new_condition[value]', '600', 15); break; case CONDITION_TYPE_DVALUE: $rowCondition[] = new CTextBox('new_condition[value]', "", 40); break; case CONDITION_TYPE_APPLICATION: $rowCondition[] = new CTextBox('new_condition[value]', "", 40); break; } $tblCond->addRow($rowCondition); $tblConditions = new CTableInfo(); $tblConditions->addRow($tblCond); $td = new CCol(array(new CButton('add_condition', S_ADD), new CButton('cancel_new_condition', S_CANCEL))); $td->addOption('colspan', '3'); $td->addOption('style', 'text-align: right;'); $tblConditions->SetFooter($td); unset($grouped_conditions, $cond_el, $cond_buttons); // end of NEW CONDITION return $tblConditions; }
// events foreach ($events as $event) { $trigger = $triggers[$event['objectid']]; $host = reset($trigger['hosts']); $host = $hosts[$host['hostid']]; $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $event['clock'], 'ns' => $event['ns']])); // duration $event['duration'] = ($nextEvent = get_next_event($event, $events)) ? zbx_date2age($event['clock'], $nextEvent['clock']) : zbx_date2age($event['clock']); // action $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : ''; if ($csvExport) { $csvRows[] = [zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), $pageFilter->hostid == 0 ? $host['name'] : null, $description, trigger_value2str($event['value']), getSeverityName($trigger['priority'], $config), $event['duration'], $config['event_ack_enable'] ? $event['acknowledges'] ? _('Yes') : _('No') : null, strip_tags((string) $action)]; } else { $triggerDescription = (new CSpan($description))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getTrigger($trigger, null, $event['clock'])); // add colors and blinking to span depending on configuration and trigger parameters $statusSpan = new CSpan(trigger_value2str($event['value'])); addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); // host JS menu link $hostName = null; if ($pageFilter->hostid == 0) { $hostName = (new CSpan($host['name']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); } $table->addRow([(new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']))->addClass('action'), $hostName, $triggerDescription, $statusSpan, getSeverityCell($trigger['priority'], $config, null, !$event['value']), $event['duration'], $config['event_ack_enable'] ? getEventAckState($event, $page['file']) : null, (new CCol($action))->addClass(ZBX_STYLE_NOWRAP)]); } } } else { if (!$csvExport) { $events = []; $url = (new CUrl('events.php'))->setArgument('fullscreen', getRequest('fullscreen'))->setArgument('groupid', $pageFilter->groupid)->setArgument('hostid', $pageFilter->hostid); $paging = getPagingLine($events, ZBX_SORT_UP, $url); }
/** * Validate conditions. * * @static * * @param array $conditions * @param int $conditions['conditiontype'] * @param array $conditions['value'] * * @return bool */ public static function validateConditions($conditions, $update = false) { $conditions = zbx_toArray($conditions); $hostGroupIdsAll = array(); $templateIdsAll = array(); $triggerIdsAll = array(); $hostIdsAll = array(); $discoveryRuleIdsAll = array(); $proxyIdsAll = array(); $proxyidsAll = array(); // build validators $timePeriodValidator = new CTimePeriodValidator(); $discoveryCheckTypeValidator = new CSetValidator(array('values' => array_keys(discovery_check_type2str()))); $discoveryObjectStatusValidator = new CSetValidator(array('values' => array_keys(discovery_object_status2str()))); $triggerSeverityValidator = new CSetValidator(array('values' => array_keys(getSeverityCaption()))); $discoveryObjectValidator = new CSetValidator(array('values' => array_keys(discovery_object2str()))); $triggerValueValidator = new CSetValidator(array('values' => array_keys(trigger_value2str()))); $eventTypeValidator = new CSetValidator(array('values' => array_keys(eventType()))); foreach ($conditions as $condition) { // on create operator is mandatory and needs validation, but on update it must be validated only if it's set if (!$update || $update && isset($condition['operator'])) { $operatorValidator = new CSetValidator(array('values' => get_operators_by_conditiontype($condition['conditiontype']))); if (!$operatorValidator->validate($condition['operator'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition operator.')); } } if (!$update || $update && isset($condition['value'])) { // validate condition values depending on condition type switch ($condition['conditiontype']) { case CONDITION_TYPE_HOST_GROUP: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $hostGroupIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_TEMPLATE: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $templateIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_TRIGGER: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $triggerIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_HOST: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $hostIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DRULE: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $discoveryRuleIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DCHECK: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $proxyIdsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_PROXY: if (!$condition['value']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } $proxyidsAll[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DOBJECT: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$discoveryObjectValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery object.')); } break; case CONDITION_TYPE_TIME_PERIOD: if (!$timePeriodValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, $timePeriodValidator->getError()); } break; case CONDITION_TYPE_DHOST_IP: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } else { if (!validate_ip_range($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition ip "%1$s".', $condition['value'])); } } break; case CONDITION_TYPE_DSERVICE_TYPE: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$discoveryCheckTypeValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check.')); } break; case CONDITION_TYPE_DSERVICE_PORT: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!validate_port_list($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action condition port "%1$s".', $condition['value'])); } break; case CONDITION_TYPE_DSTATUS: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$discoveryObjectStatusValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery status.')); } break; case CONDITION_TYPE_MAINTENANCE: if (!zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Maintenance action condition value must be empty.')); } break; case CONDITION_TYPE_TRIGGER_SEVERITY: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$triggerSeverityValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger severity.')); } break; case CONDITION_TYPE_TRIGGER_VALUE: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$triggerValueValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger value.')); } break; case CONDITION_TYPE_EVENT_TYPE: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } elseif (!$eventTypeValidator->validate($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition event type.')); } break; case CONDITION_TYPE_TRIGGER_NAME: case CONDITION_TYPE_NODE: case CONDITION_TYPE_DUPTIME: case CONDITION_TYPE_DVALUE: case CONDITION_TYPE_APPLICATION: case CONDITION_TYPE_HOST_NAME: case CONDITION_TYPE_HOST_METADATA: if (zbx_empty($condition['value'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty action condition.')); } break; default: self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition type.')); break; } } } if (!API::HostGroup()->isWritable($hostGroupIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host group. Host group does not exist or you have no access to it.')); } if (!API::Host()->isWritable($hostIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition host. Host does not exist or you have no access to it.')); } if (!API::Template()->isWritable($templateIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition template. Template does not exist or you have no access to it.')); } if (!API::Trigger()->isWritable($triggerIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition trigger. Trigger does not exist or you have no access to it.')); } if (!API::DRule()->isWritable($discoveryRuleIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery rule. Discovery rule does not exist or you have no access to it.')); } if (!API::DCheck()->isWritable($proxyIdsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition discovery check. Discovery check does not exist or you have no access to it.')); } if (!API::Proxy()->isWritable($proxyidsAll)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action condition proxy. Proxy does not exist or you have no access to it.')); } return true; }
break; case CONDITION_TYPE_HOST: $tblNewCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('host', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?writeonly=1&dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=host&srctbl=hosts" . "&srcfld1=hostid&srcfld2=host',450,450);", 'T')); break; case CONDITION_TYPE_TRIGGER: $tblNewCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('trigger', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?writeonly=1&dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=trigger&srctbl=triggers" . "&srcfld1=triggerid&srcfld2=description');", 'T')); break; case CONDITION_TYPE_TRIGGER_NAME: $rowCondition[] = new CTextBox('new_condition[value]', "", 40); break; case CONDITION_TYPE_TRIGGER_VALUE: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE) as $tr_val) { $cmbCondVal->addItem($tr_val, trigger_value2str($tr_val)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_TIME_PERIOD: $rowCondition[] = new CTextBox('new_condition[value]', "1-7,00:00-23:59", 40); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER) as $id) { $cmbCondVal->addItem($id, get_severity_description($id)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_MAINTENANCE: $rowCondition[] = new CCol(S_MAINTENANCE_SMALL);
case CONDITION_TYPE_TEMPLATE: $condition = new CMultiSelect(array('name' => 'new_condition[value][]', 'objectName' => 'templates', 'objectOptions' => array('editable' => true), 'defaultValue' => 0)); break; case CONDITION_TYPE_HOST: $condition = new CMultiSelect(array('name' => 'new_condition[value][]', 'objectName' => 'hosts', 'objectOptions' => array('editable' => true), 'defaultValue' => 0)); break; case CONDITION_TYPE_TRIGGER: $condition = new CMultiSelect(array('name' => 'new_condition[value][]', 'objectName' => 'triggers', 'objectOptions' => array('editable' => true), 'defaultValue' => 0)); break; case CONDITION_TYPE_TRIGGER_NAME: $condition = new CTextBox('new_condition[value]', '', ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_VALUE: $condition = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE) as $trigerValue) { $condition->addItem($trigerValue, trigger_value2str($trigerValue)); } break; case CONDITION_TYPE_TIME_PERIOD: $condition = new CTextBox('new_condition[value]', ZBX_DEFAULT_INTERVAL, ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $condition = new CComboBox('new_condition[value]'); $condition->addItems(getSeverityCaption()); break; case CONDITION_TYPE_MAINTENANCE: $condition = new CCol(_('maintenance')); break; case CONDITION_TYPE_NODE: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $condition = array(new CTextBox('node', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), 'return PopUp("popup.php?srctbl=nodes&srcfld1=nodeid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=node' . '&writeonly=1", 450, 450);', 'link_menu'));
function condition_value2str($conditiontype, $value) { switch ($conditiontype) { case CONDITION_TYPE_HOST_GROUP: $group = get_hostgroup_by_groupid($value); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true); } $str_val .= $group['name']; break; case CONDITION_TYPE_TRIGGER: $str_val = expand_trigger_description($value); break; case CONDITION_TYPE_HOST: case CONDITION_TYPE_HOST_TEMPLATE: $host = get_host_by_hostid($value); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true); } $str_val .= $host['host']; break; case CONDITION_TYPE_TRIGGER_NAME: $str_val = $value; break; case CONDITION_TYPE_TRIGGER_VALUE: $str_val = trigger_value2str($value); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $str_val = get_severity_description($value); break; case CONDITION_TYPE_TIME_PERIOD: $str_val = $value; break; case CONDITION_TYPE_MAINTENANCE: $str_val = S_MAINTENANCE_SMALL; break; case CONDITION_TYPE_DHOST_IP: $str_val = $value; break; case CONDITION_TYPE_DSERVICE_TYPE: $str_val = discovery_check_type2str($value); break; case CONDITION_TYPE_DSERVICE_PORT: $str_val = $value; break; case CONDITION_TYPE_DSTATUS: $str_val = discovery_object_status2str($value); break; case CONDITION_TYPE_DUPTIME: $str_val = $value; break; case CONDITION_TYPE_DVALUE: $str_val = $value; break; case CONDITION_TYPE_EVENT_ACKNOWLEDGED: $str_val = $value ? S_ACK : S_NOT_ACK; break; case CONDITION_TYPE_APPLICATION: $str_val = $value; break; default: return S_UNKNOWN; break; } return '"' . $str_val . '"'; }
function condition_value2str($conditiontype, $value) { switch ($conditiontype) { case CONDITION_TYPE_HOST_GROUP: $group = get_hostgroup_by_groupid($value); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, ': '); } $str_val .= $group['name']; break; case CONDITION_TYPE_TRIGGER: $trig = CTrigger::get(array('triggerids' => $value, 'expandTriggerDescriptions' => true, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true))); $trig = reset($trig); $host = reset($trig['hosts']); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, ': '); } $str_val .= $host['host'] . ':' . $trig['description']; break; case CONDITION_TYPE_HOST: case CONDITION_TYPE_HOST_TEMPLATE: $host = get_host_by_hostid($value); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, ': '); } $str_val .= $host['host']; break; case CONDITION_TYPE_TRIGGER_NAME: case CONDITION_TYPE_HOST_NAME: $str_val = $value; break; case CONDITION_TYPE_TRIGGER_VALUE: $str_val = trigger_value2str($value); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $str_val = get_severity_description($value); break; case CONDITION_TYPE_TIME_PERIOD: $str_val = $value; break; case CONDITION_TYPE_MAINTENANCE: $str_val = S_MAINTENANCE_SMALL; break; case CONDITION_TYPE_NODE: $node = get_node_by_nodeid($value); $str_val = $node['name']; break; case CONDITION_TYPE_DRULE: $drule = get_discovery_rule_by_druleid($value); $str_val = $drule['name']; break; case CONDITION_TYPE_DCHECK: $row = DBfetch(DBselect('SELECT DISTINCT r.name,c.dcheckid,c.type,c.key_,c.snmp_community,c.ports' . ' FROM drules r,dchecks c WHERE r.druleid=c.druleid AND c.dcheckid=' . $value)); $str_val = $row['name'] . ':' . discovery_check2str($row['type'], $row['snmp_community'], $row['key_'], $row['ports']); break; case CONDITION_TYPE_DOBJECT: $str_val = discovery_object2str($value); break; case CONDITION_TYPE_PROXY: $host = get_host_by_hostid($value); $str_val = $host['host']; break; case CONDITION_TYPE_DHOST_IP: $str_val = $value; break; case CONDITION_TYPE_DSERVICE_TYPE: $str_val = discovery_check_type2str($value); break; case CONDITION_TYPE_DSERVICE_PORT: $str_val = $value; break; case CONDITION_TYPE_DSTATUS: $str_val = discovery_object_status2str($value); break; case CONDITION_TYPE_DUPTIME: $str_val = $value; break; case CONDITION_TYPE_DVALUE: $str_val = $value; break; case CONDITION_TYPE_EVENT_ACKNOWLEDGED: $str_val = $value ? S_ACK : S_NOT_ACK; break; case CONDITION_TYPE_APPLICATION: $str_val = $value; break; default: return S_UNKNOWN; break; } return '"' . $str_val . '"'; }
} $statusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); // host JS menu link $hostSpan = null; if ($_REQUEST['hostid'] == 0) { $hostSpan = new CSpan($host['name'], 'link_menu menu-host'); $scripts = $hostScripts[$host['hostid']]; $hostSpan->setAttribute('data-menu', hostMenuData($host, $scripts)); } // action $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : ' - '; $table->addRow(array(new CLink(zbx_date2str(EVENTS_ACTION_TIME_FORMAT, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid'], 'action'), is_show_all_nodes() ? get_node_name_by_elid($event['objectid']) : null, $hostSpan, new CSpan($tr_desc, 'link_menu'), $statusSpan, getSeverityCell($trigger['priority'], null, !$event['value']), $event['duration'], $config['event_ack_enable'] ? $ack : null, $action)); if ($CSV_EXPORT) { $csvRows[] = array(zbx_date2str(EVENTS_ACTION_TIME_FORMAT, $event['clock']), is_show_all_nodes() ? get_node_name_by_elid($event['objectid']) : null, $_REQUEST['hostid'] == 0 ? $host['name'] : null, $description, trigger_value2str($event['value']), getSeverityCaption($trigger['priority']), $event['duration'], $config['event_ack_enable'] ? $event['acknowledges'] ? _('Yes') : _('No') : null, strip_tags((string) $action)); } } } else { $events = array(); $paging = getPagingLine($events); } } if ($CSV_EXPORT) { print zbx_toCSV($csvRows); exit; } $table = array($paging, $table, $paging); } $events_wdgt->addItem($table); // NAV BAR
/** * Create table with trigger description and events. * * @param array $trigger An array of trigger data. * @param string $trigger['triggerid'] Trigger ID to select events. * @param string $trigger['description'] Trigger description. * @param string $trigger['url'] Trigger URL. * @param string $trigger['lastEvent']['eventid'] Last event ID * @param string $backurl URL to return to. * * @return CDiv */ function make_popup_eventlist($trigger, $backurl) { // Show trigger description and URL. $div = new CDiv(); if ($trigger['comments'] !== '') { $div->addItem((new CDiv())->addItem(zbx_str2links($trigger['comments']))->addClass(ZBX_STYLE_OVERLAY_DESCR)); } if ($trigger['url'] !== '') { $div->addItem((new CDiv())->addItem(new CLink($trigger['url'], $trigger['url']))->addClass(ZBX_STYLE_OVERLAY_DESCR_URL)); } // Select and show events. $config = select_config(); $table = new CTableInfo(); // If acknowledges are turned on, we show 'ack' column. if ($config['event_ack_enable']) { $table->setHeader([_('Time'), _('Status'), _('Duration'), _('Age'), _('Ack')]); } else { $table->setHeader([_('Time'), _('Status'), _('Duration'), _('Age')]); } if ($trigger['lastEvent']) { $events = API::Event()->get(['source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'output' => API_OUTPUT_EXTEND, 'objectids' => [$trigger['triggerid']], 'eventid_till' => $trigger['lastEvent']['eventid'], 'select_acknowledges' => API_OUTPUT_COUNT, 'sortfield' => ['clock', 'eventid'], 'sortorder' => ZBX_SORT_DOWN, 'limit' => ZBX_WIDGET_ROWS]); $lclock = time(); foreach ($events as $event) { $duration = zbx_date2age($lclock, $event['clock']); $lclock = $event['clock']; $eventStatusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($eventStatusSpan, $event['value'], $event['clock'], $event['acknowledged']); $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), $eventStatusSpan, $duration, zbx_date2age($event['clock']), $config['event_ack_enable'] ? getEventAckState($event, $backurl) : null]); } } $div->addItem($table); return $div; }
if ($show_event_col) { $severity_col->setColSpan(2); } // Unknown triggers $unknown = SPACE; if ($trigger['value_flags'] == TRIGGER_VALUE_FLAG_UNKNOWN) { $unknown = new CDiv(SPACE, 'status_icon iconunknown'); $unknown->setHint($trigger['error'], '', 'on'); } //---- $table->addRow(array($open_close, $config['event_ack_enable'] ? $show_event_col ? null : new CCheckBox('triggers[' . $trigger['triggerid'] . ']', 'no', null, $trigger['triggerid']) : null, $severity_col, $statusSpan, $unknown, $lastchange, zbx_date2age($trigger['lastchange']), $show_event_col ? SPACE : NULL, $to_ack, get_node_name_by_elid($trigger['triggerid']), $host, $tr_desc, new CLink(zbx_empty($trigger['comments']) ? _('Add') : _('Show'), 'tr_comments.php?triggerid=' . $trigger['triggerid'])), 'even_row'); if ($show_events != EVENTS_OPTION_NOEVENT) { $i = 1; foreach ($trigger['events'] as $enum => $row_event) { $i++; $eventStatusSpan = new CSpan(trigger_value2str($row_event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($eventStatusSpan, $row_event['value'], $row_event['clock'], $row_event['acknowledged']); $statusSpan = new CCol($eventStatusSpan); $statusSpan->setColSpan(2); $ack = getEventAckState($row_event, true); if ($row_event['acknowledged'] == 0 && $row_event['value'] == TRIGGER_VALUE_TRUE) { $ack_cb = new CCheckBox('events[' . $row_event['eventid'] . ']', 'no', NULL, $row_event['eventid']); } else { $ack_cb = SPACE; } $clock = new CLink(zbx_date2str(_('d M Y H:i:s'), $row_event['clock']), 'tr_events.php?triggerid=' . $trigger['triggerid'] . '&eventid=' . $row_event['eventid']); $next_clock = isset($trigger['events'][$enum - 1]) ? $trigger['events'][$enum - 1]['clock'] : time(); $empty_col = new CCol(SPACE); $empty_col->setColSpan(3); $ack_cb_col = new CCol($ack_cb);
function get_history_of_discovery_events($end_time, $limit, &$last_clock = null) { $table = new CTableInfo(S_NO_EVENTS_FOUND); $table->setHeader(array(S_TIME, S_IP, S_DESCRIPTION, S_STATUS)); $col = 0; $clock = array(); $dsc_events = array(); $sql = 'SELECT DISTINCT e.source,e.object,e.objectid,e.clock,e.value ' . ' FROM events e' . ' WHERE e.source=' . EVENT_SOURCE_DISCOVERY . ' AND e.clock<' . $end_time . ' ORDER BY e.clock DESC'; $db_events = DBselect($sql, $limit); while ($event_data = DBfetch($db_events)) { switch ($event_data['object']) { case EVENT_OBJECT_DHOST: $sql = 'SELECT ip FROM dhosts WHERE dhostid=' . $event_data['objectid']; if ($object_data = DBfetch(DBselect($sql))) { $event_data['object_data'] = $object_data; } else { $event_data['object_data']['ip'] = S_UNKNOWN; } $event_data['description'] = SPACE; break; case EVENT_OBJECT_DSERVICE: $sql = 'SELECT h.ip,s.type,s.port ' . ' FROM dhosts h,dservices s ' . ' WHERE h.dhostid=s.dhostid ' . ' AND s.dserviceid=' . $event_data['objectid']; if ($object_data = DBfetch(DBselect($sql))) { $event_data['object_data'] = $object_data; } else { $event_data['object_data']['ip'] = S_UNKNOWN; $event_data['object_data']['type'] = S_UNKNOWN; $event_data['object_data']['port'] = S_UNKNOWN; } $event_data['description'] = S_SERVICE . ': ' . discovery_check_type2str($event_data['object_data']['type']) . '; ' . S_PORT . ': ' . $event_data['object_data']['port']; break; default: continue; } if (!isset($event_data['object_data'])) { continue; } $clock[] = $event_data['clock']; $dsc_events[] = $event_data; } $last_clock = !empty($clock) ? min($clock) : null; order_page_result($dsc_events, 'clock', ZBX_SORT_DOWN); foreach ($dsc_events as $num => $event_data) { $value = new CCol(trigger_value2str($event_data['value']), get_trigger_value_style($event_data['value'])); $table->addRow(array(date('Y.M.d H:i:s', $event_data['clock']), $event_data['object_data']['ip'], $event_data['description'], $value)); } return $table; }
function get_history_of_discovery_events($start, $end) { $sql_cond = ' AND e.clock>' . $start; $sql_cond .= ' AND e.clock<' . $end; $sql = 'SELECT DISTINCT e.source,e.object,e.objectid,e.clock,e.value ' . ' FROM events e' . ' WHERE e.source=' . EVENT_SOURCE_DISCOVERY . $sql_cond . order_by('e.clock'); $db_events = DBselect($sql); $table = new CTableInfo(S_NO_EVENTS_FOUND); $table->SetHeader(array(S_TIME, S_IP, S_DESCRIPTION, S_STATUS)); $col = 0; while ($event_data = DBfetch($db_events)) { $value = new CCol(trigger_value2str($event_data['value']), get_trigger_value_style($event_data['value'])); switch ($event_data['object']) { case EVENT_OBJECT_DHOST: $object_data = DBfetch(DBselect('SELECT ip FROM dhosts WHERE dhostid=' . $event_data['objectid'])); $description = SPACE; break; case EVENT_OBJECT_DSERVICE: $object_data = DBfetch(DBselect('SELECT h.ip,s.type,s.port ' . ' FROM dhosts h,dservices s ' . ' WHERE h.dhostid=s.dhostid ' . ' AND s.dserviceid=' . $event_data['objectid'])); $description = S_SERVICE . ': ' . discovery_check_type2str($object_data['type']) . '; ' . S_PORT . ': ' . $object_data['port']; break; default: continue; } if (!$object_data) { continue; } $table->AddRow(array(date('Y.M.d H:i:s', $event_data['clock']), $object_data['ip'], $description, $value)); $col++; } return $table; }
function make_popup_eventlist($eventid, $trigger_type, $triggerid) { $config = select_config(); $table = new CTableInfo(); //if acknowledges are turned on, we show 'ack' column if ($config['event_ack_enable']) { $table->setHeader(array(S_TIME, S_STATUS, S_DURATION, S_AGE, S_ACK)); } else { $table->setHeader(array(S_TIME, S_STATUS, S_DURATION, S_AGE)); } $table->setAttribute('style', 'width: 400px;'); $event_list = array(); $sql = 'SELECT * ' . ' FROM events ' . ' WHERE eventid<=' . $eventid . ' AND object=' . EVENT_OBJECT_TRIGGER . ' AND objectid=' . $triggerid . ' ORDER BY eventid DESC'; $db_events = DBselect($sql, ZBX_WIDGET_ROWS); $count = 0; while ($event = DBfetch($db_events)) { if (!empty($event_list) && $event_list[$count]['value'] != $event['value']) { $count++; } else { if (!empty($event_list) && $event_list[$count]['value'] == $event['value'] && $trigger_type == TRIGGER_MULT_EVENT_ENABLED && $event['value'] == TRIGGER_VALUE_TRUE) { $count++; } } $event_list[$count] = $event; } $lclock = time(); foreach ($event_list as $id => $event) { $duration = zbx_date2age($lclock, $event['clock']); $lclock = $event['clock']; $value = new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value'])); // ack +++ $ack = new CSpan(S_NO, 'on'); if ($event['acknowledged']) { $ack = new CSpan(S_YES, 'off'); } // --- $table->addRow(array(zbx_date2str(S_EVENTS_POPUP_EVENT_LIST_DATE_FORMAT, $event['clock']), $value, $duration, zbx_date2age($event['clock']), $config['event_ack_enable'] ? $ack : NULL)); } return $table; }
/** * Returns true if the given $value is valid, or set's an error and returns false otherwise. * * * @param $condition * * @return bool */ public function validate($condition) { // build validators $timePeriodValidator = new CTimePeriodValidator(); $discoveryCheckTypeValidator = new CLimitedSetValidator(array('values' => array_keys(discovery_check_type2str()))); $discoveryObjectStatusValidator = new CLimitedSetValidator(array('values' => array_keys(discovery_object_status2str()))); $triggerSeverityValidator = new CLimitedSetValidator(array('values' => array(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER))); $discoveryObjectValidator = new CLimitedSetValidator(array('values' => array_keys(discovery_object2str()))); $triggerValueValidator = new CLimitedSetValidator(array('values' => array_keys(trigger_value2str()))); $eventTypeValidator = new CLimitedSetValidator(array('values' => array_keys(eventType()))); $conditionValue = $condition['value']; // validate condition values depending on condition type switch ($condition['conditiontype']) { case CONDITION_TYPE_HOST_GROUP: if (!$conditionValue) { $this->setError(_('Empty action condition.')); } break; case CONDITION_TYPE_TEMPLATE: if (!$conditionValue) { $this->setError(_('Empty action condition.')); } break; case CONDITION_TYPE_TRIGGER: if (!$conditionValue) { $this->setError(_('Empty action condition.')); } break; case CONDITION_TYPE_HOST: if (!$conditionValue) { $this->setError(_('Empty action condition.')); } break; case CONDITION_TYPE_DRULE: if (!$conditionValue) { $this->setError(_('Empty action condition.')); } break; case CONDITION_TYPE_DCHECK: if (!$conditionValue) { $this->setError(_('Empty action condition.')); } break; case CONDITION_TYPE_PROXY: if (!$conditionValue) { $this->setError(_('Empty action condition.')); } break; case CONDITION_TYPE_DOBJECT: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!$discoveryObjectValidator->validate($conditionValue)) { $this->setError(_('Incorrect action condition discovery object.')); } break; case CONDITION_TYPE_TIME_PERIOD: if (!$timePeriodValidator->validate($conditionValue)) { $this->setError($timePeriodValidator->getError()); } break; case CONDITION_TYPE_DHOST_IP: $ipRangeValidator = new CIPRangeValidator(); if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!$ipRangeValidator->validate($conditionValue)) { $this->setError($ipRangeValidator->getError()); } break; case CONDITION_TYPE_DSERVICE_TYPE: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!$discoveryCheckTypeValidator->validate($conditionValue)) { $this->setError(_('Incorrect action condition discovery check.')); } break; case CONDITION_TYPE_DSERVICE_PORT: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!validate_port_list($conditionValue)) { $this->setError(_s('Incorrect action condition port "%1$s".', $conditionValue)); } break; case CONDITION_TYPE_DSTATUS: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!$discoveryObjectStatusValidator->validate($conditionValue)) { $this->setError(_('Incorrect action condition discovery status.')); } break; case CONDITION_TYPE_MAINTENANCE: if (!zbx_empty($conditionValue)) { $this->setError(_('Maintenance action condition value must be empty.')); } break; case CONDITION_TYPE_TRIGGER_SEVERITY: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!$triggerSeverityValidator->validate($conditionValue)) { $this->setError(_('Incorrect action condition trigger severity.')); } break; case CONDITION_TYPE_TRIGGER_VALUE: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!$triggerValueValidator->validate($conditionValue)) { $this->setError(_('Incorrect action condition trigger value.')); } break; case CONDITION_TYPE_EVENT_TYPE: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } elseif (!$eventTypeValidator->validate($conditionValue)) { $this->setError(_('Incorrect action condition event type.')); } break; case CONDITION_TYPE_TRIGGER_NAME: case CONDITION_TYPE_DUPTIME: case CONDITION_TYPE_DVALUE: case CONDITION_TYPE_APPLICATION: case CONDITION_TYPE_HOST_NAME: case CONDITION_TYPE_HOST_METADATA: if (zbx_empty($conditionValue)) { $this->setError(_('Empty action condition.')); } break; default: $this->setError(_('Incorrect action condition type.')); } // If no error is not set, return true. return !(bool) $this->getError(); }
function get_screen($screenid, $editmode, $effectiveperiod = NULL) { global $USER_DETAILS; if ($screenid == 0) { return new CTableInfo(S_NO_SCREENS_DEFINED); } $r = CScreen::get(array('screenids' => $screenid, 'editable' => $editmode == 1 ? 1 : null, 'output' => API_OUTPUT_SHORTEN)); if (empty($r)) { access_deny(); } if (is_null($effectiveperiod)) { $effectiveperiod = ZBX_MIN_PERIOD; } $result = DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid=' . $screenid); $row = DBfetch($result); if (!$row) { return new CTableInfo(S_NO_SCREENS_DEFINED); } $sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid; $iresult = DBSelect($sql); $skip_field = array(); $irows = array(); while ($irow = DBfetch($iresult)) { $irows[] = $irow; for ($i = 0; $i < $irow['rowspan'] || $i == 0; $i++) { for ($j = 0; $j < $irow['colspan'] || $j == 0; $j++) { if ($i != 0 || $j != 0) { if (!isset($skip_field[$irow['y'] + $i])) { $skip_field[$irow['y'] + $i] = array(); } $skip_field[$irow['y'] + $i][$irow['x'] + $j] = 1; } } } } $table = new CTable(new CLink(S_NO_ROWS_IN_SCREEN . SPACE . $row['name'], 'screenconf.php?config=0&form=update&screenid=' . $screenid), $editmode == 0 || $editmode == 2 ? 'screen_view' : 'screen_edit'); $table->setAttribute('id', 'iframe'); if ($editmode == 1) { $new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); for ($c = 0; $c < $row['hsize'] + 1; $c++) { $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_col={$c}';"); array_push($new_cols, new Ccol($add_icon)); } $table->addRow($new_cols); } $empty_screen_col = array(); for ($r = 0; $r < $row['vsize']; $r++) { $new_cols = array(); $empty_screen_row = true; if ($editmode == 1) { $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$r}';"); array_push($new_cols, new Ccol($add_icon)); } for ($c = 0; $c < $row['hsize']; $c++) { $item = array(); if (isset($skip_field[$r][$c])) { continue; } $item_form = false; $irow = false; foreach ($irows as $tmprow) { if ($tmprow['x'] == $c && $tmprow['y'] == $r) { $irow = $tmprow; break; } } if ($irow) { $screenitemid = $irow['screenitemid']; $resourcetype = $irow['resourcetype']; $resourceid = $irow['resourceid']; $width = $irow['width']; $height = $irow['height']; $colspan = $irow['colspan']; $rowspan = $irow['rowspan']; $elements = $irow['elements']; $valign = $irow['valign']; $halign = $irow['halign']; $style = $irow['style']; $url = $irow['url']; $dynamic = $irow['dynamic']; } else { $screenitemid = 0; $resourcetype = 0; $resourceid = 0; $width = 0; $height = 0; $colspan = 0; $rowspan = 0; $elements = 0; $valign = VALIGN_DEFAULT; $halign = HALIGN_DEFAULT; $style = 0; $url = ''; $dynamic = 0; } if ($screenitemid > 0) { $empty_screen_row = false; $empty_screen_col[$c] = 1; } if ($editmode == 1 && $screenitemid != 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&screenitemid=' . $screenitemid . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitemid . '#form'; } else { if ($editmode == 1 && $screenitemid == 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&x=' . $c . '&y=' . $r . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r . '#form'; } else { $action = NULL; } } if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['x']) && $_REQUEST['x'] == $c && isset($_REQUEST['y']) && $_REQUEST['y'] == $r) { // click on empty field $item = get_screen_item_form(); $item_form = true; } else { if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['screenitemid']) && bccomp($_REQUEST['screenitemid'], $screenitemid) == 0) { // click on element $item = get_screen_item_form(); $item_form = true; } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_GRAPH) { if ($editmode == 0) { $action = 'charts.php?graphid=' . $resourceid . url_param('period') . url_param('stime'); } // GRAPH & ZOOM features $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid; $graphDims = getGraphDims($resourceid); $graphDims['graphHeight'] = $height; $graphDims['width'] = $width; $graph = get_graph_by_graphid($resourceid); $graphid = $graph['graphid']; $legend = $graph['show_legend']; $graph3d = $graph['show_3d']; //------------- // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { $options = array('hostids' => $_REQUEST['hostid'], 'output' => array('hostid', 'host')); $hosts = CHost::get($options); $host = reset($hosts); $options = array('graphids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_REFER, 'select_graph_items' => API_OUTPUT_EXTEND); $graph = CGraph::get($options); $graph = reset($graph); if (count($graph['hosts']) == 1) { // if items from one host we change them, or set calculated if not exist on that host if ($graph['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymax_itemid']) { $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymax_itemid'])), $_REQUEST['hostid'], false); $new_dinamic = reset($new_dinamic); if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) { $graph['ymax_itemid'] = $new_dinamic['itemid']; } else { $graph['ymax_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } if ($graph['ymin_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymin_itemid']) { $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymin_itemid'])), $_REQUEST['hostid'], false); $new_dinamic = reset($new_dinamic); if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) { $graph['ymin_itemid'] = $new_dinamic['itemid']; } else { $graph['ymin_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } } $url = $graph['graphtype'] == GRAPH_TYPE_PIE || $graph['graphtype'] == GRAPH_TYPE_EXPLODED ? 'chart7.php' : 'chart3.php'; $url = new Curl($url); foreach ($graph as $name => $value) { if ($name == 'width' || $name == 'height') { continue; } $url->setArgument($name, $value); } $new_items = get_same_graphitems_for_host($graph['gitems'], $_REQUEST['hostid'], false); foreach ($new_items as $gitem) { unset($gitem['gitemid']); unset($gitem['graphid']); foreach ($gitem as $name => $value) { $url->setArgument('items[' . $gitem['itemid'] . '][' . $name . ']', $value); } } $url->setArgument('name', $host['host'] . ': ' . $graph['name']); $url = $url->getUrl(); } //------------- $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0); $default = false; if ($graphDims['graphtype'] == GRAPH_TYPE_PIE || $graphDims['graphtype'] == GRAPH_TYPE_EXPLODED) { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart6.php?graphid=' . $resourceid; $default = true; } $timeline = array(); $timeline['period'] = $effectiveperiod; $timeline['starttime'] = date('YmdHis', get_min_itemclock_by_graphid($resourceid)); if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } // $src = $url.'&width='.$width.'&height='.$height.'&legend='.$legend.'&graph3d='.$graph3d; $src = $url . '&width=' . $width . '&height=' . $height . '&legend=' . $legend . '&graph3d=' . $graph3d . '&period=' . $effectiveperiod . url_param('stime'); $objData['src'] = $src; } else { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart2.php?graphid=' . $resourceid; $default = true; } $src = $url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime'); $timeline = array(); if (isset($graphid) && !is_null($graphid) && $editmode != 1) { $timeline['period'] = $effectiveperiod; $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD); //get_min_itemclock_by_graphid($graphid); if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } $objData['loadSBox'] = 1; } $objData['src'] = $src; } if ($editmode || !$default) { $item = new CDiv(); } else { $item = new CLink(null, $action); } $item->setAttribute('id', $containerid); $item = array($item); if ($editmode == 1) { $item[] = BR(); $item[] = new CLink(S_CHANGE, $action); } if ($editmode == 2) { insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } else { zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) { $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid; $graphDims = getGraphDims(); $graphDims['graphHeight'] = $height; $graphDims['width'] = $width; $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0); // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = ''; } } //------------- if ($editmode == 0 && !empty($resourceid)) { $action = 'history.php?action=showgraph&itemid=' . $resourceid . url_param('period') . url_param('stime'); } $timeline = array(); $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD); if (!zbx_empty($resourceid) && $editmode != 1) { $timeline['period'] = $effectiveperiod; if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } $objData['loadSBox'] = 1; } $src = zbx_empty($resourceid) ? 'chart3.php?' : 'chart.php?itemid=' . $resourceid . '&'; $src .= $url . 'width=' . $width . '&height=' . $height; $objData['src'] = $src; if ($editmode) { $item = new CDiv(); } else { $item = new CLink(null, $action); } $item->setAttribute('id', $containerid); $item = array($item); if ($editmode == 1) { $item[] = BR(); $item[] = new CLink(S_CHANGE, $action); } if ($editmode == 2) { insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } else { zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_MAP) { $image_map = new CImg("map.php?noedit=1&sysmapid={$resourceid}" . "&width={$width}&height={$height}&curtime=" . time()); if ($editmode == 0) { $options = array('sysmapids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_selements' => API_OUTPUT_EXTEND, 'nopermissions' => 1); $sysmaps = CMap::get($options); $sysmap = reset($sysmaps); $action_map = getActionMapBySysmap($sysmap); $image_map->setMap($action_map->getName()); $item = array($action_map, $image_map); } else { $item = $image_map; // $item = new CLink($image_map, $action); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) { // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = 0; } } //------------- $item = array(get_screen_plaintext($resourceid, $elements, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTGROUP_TRIGGERS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements); $tr_form = S_ALL_S; if ($resourceid > 0) { $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND); $hostgroups = CHostgroup::get($options); $hostgroup = reset($hostgroups); $tr_form = new CSpan(S_GROUP . ': ' . $hostgroup['name'], 'white'); $params['groupids'] = $hostgroup['groupid']; } else { $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0)); $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0)); CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID); CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); order_result($groups, 'name'); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); if ($groupid > 0) { $options['groupids'] = $groupid; } $hosts = CHost::get($options); $hosts = zbx_toHash($hosts, 'hostid'); order_result($hosts, 'host'); if (!isset($hosts[$hostid])) { $hostid = 0; } $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); foreach ($groups as $gnum => $group) { $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']); } foreach ($hosts as $hnum => $host) { $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); if ($groupid > 0) { $params['groupids'] = $groupid; } if ($hostid > 0) { $params['hostids'] = $hostid; } } $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form)); $item[] = make_latest_issues($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } ///----------------------- } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOST_TRIGGERS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements); $tr_form = S_ALL_S; if ($resourceid > 0) { $options = array('hostids' => $resourceid, 'output' => API_OUTPUT_EXTEND); $hosts = CHost::get($options); $host = reset($hosts); $tr_form = new CSpan(S_HOST . ': ' . $host['host'], 'white'); $params['hostids'] = $host['hostid']; } else { $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0)); $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0)); CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID); CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); order_result($groups, 'name'); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); if ($groupid > 0) { $options['groupids'] = $groupid; } $hosts = CHost::get($options); $hosts = zbx_toHash($hosts, 'hostid'); order_result($hosts, 'host'); if (!isset($hosts[$hostid])) { $hostid = 0; } $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); foreach ($groups as $gnum => $group) { $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']); } foreach ($hosts as $hnum => $host) { $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); if ($groupid > 0) { $params['groupids'] = $groupid; } if ($hostid > 0) { $params['hostids'] = $hostid; } } ///----------------------- $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form)); $item[] = make_latest_issues($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SYSTEM_STATUS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => null, 'extAck' => 0); $item = array(get_table_header(array(S_SYSTEM_STATUS, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)))); $item[] = make_system_status($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTS_INFO) { $item = array(new CHostsInfo($resourceid, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) { $item = new CTriggersInfo($resourceid, null, $style); $item = array($item); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SERVER_INFO) { // $item = array(get_table_header(S_STATUS_OF_ZABBIX_BIG),make_status_of_zbx()); $item = array(new CServerInfo()); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_CLOCK) { $item = new CFlashClock($width, $height, $style, $action); } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SCREEN) { $item = array(get_screen($resourceid, 2, $effectiveperiod)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_triggers_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_DATA_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_items_data_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_URL) { $item = array(new CIFrame($url, $width, $height, "auto")); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_ACTIONS) { $item = array(get_history_of_actions($elements)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_EVENTS) { $options = array('monitored' => 1, 'value' => array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE), 'limit' => $elements); $hide_unknown = CProfile::get('web.events.filter.hide_unknown', 0); if ($hide_unknown) { $options['value'] = array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE); } $item = new CTableInfo(S_NO_EVENTS_FOUND); $item->SetHeader(array(S_TIME, is_show_all_nodes() ? S_NODE : null, S_HOST, S_DESCRIPTION, S_VALUE, S_SEVERITY)); $events = getLastEvents($options); foreach ($events as $enum => $event) { $trigger = $event['trigger']; $host = $event['host']; $value = new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value'])); // $row = zbx_array_merge($triggers[$row['triggerid']],$row); // if((1 == $hide_unknown) && (!event_initial_time($row,$hide_unknown))) continue; $item->addRow(array(zbx_date2str(S_EVENTS_TRIGGERS_EVENTS_HISTORY_LIST_DATE_FORMAT, $event['clock']), get_node_name_by_elid($event['objectid']), $host['host'], new CLink($trigger['description'], 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']), $value, new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority'])))); } $item = array($item); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { $item = array(SPACE); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } } } } } } } } } } } } } } } } } } } $str_halign = 'def'; if ($halign == HALIGN_CENTER) { $str_halign = 'cntr'; } if ($halign == HALIGN_LEFT) { $str_halign = 'left'; } if ($halign == HALIGN_RIGHT) { $str_halign = 'right'; } $str_valign = 'def'; if ($valign == VALIGN_MIDDLE) { $str_valign = 'mdl'; } if ($valign == VALIGN_TOP) { $str_valign = 'top'; } if ($valign == VALIGN_BOTTOM) { $str_valign = 'bttm'; } if ($editmode == 1 && !$item_form) { $item = new CDiv($item, 'draggable'); $item->setAttribute('id', 'position_' . $r . '_' . $c); if ($editmode == 1) { $item->setAttribute('onclick', 'javascript: ' . $onclick_action); } } $new_col = new CCol($item, $str_halign . '_' . $str_valign); if ($colspan) { $new_col->SetColSpan($colspan); } if ($rowspan) { $new_col->SetRowSpan($rowspan); } array_push($new_cols, $new_col); } if ($editmode == 1) { $rmv_icon = new Cimg('images/general/opened.gif', NULL, NULL, NULL, 'pointer'); if ($empty_screen_row) { $rmv_row_link = "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_row={$r}';"; } else { $rmv_row_link = "javascript: if(Confirm('" . S_THIS_SCREEN_ROW_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_row={$r}';}"; } $rmv_icon->addAction('onclick', $rmv_row_link); array_push($new_cols, new Ccol($rmv_icon)); } $table->addRow(new CRow($new_cols)); } if ($editmode == 1) { $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$row['vsize']}';"); $new_cols = array(new Ccol($add_icon)); for ($c = 0; $c < $row['hsize']; $c++) { $rmv_icon = new Cimg('images/general/opened.gif', NULL, NULL, NULL, 'pointer'); if (isset($empty_screen_col[$c])) { $rmv_col_link = "javascript: if(Confirm('" . S_THIS_SCREEN_COLUMN_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_col={$c}';}"; } else { $rmv_col_link = "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_col={$c}';"; } $rmv_icon->addAction('onclick', $rmv_col_link); array_push($new_cols, new Ccol($rmv_icon)); } array_push($new_cols, new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); $table->addRow($new_cols); } return $table; }
function make_popup_eventlist($triggerId, $eventId) { $config = select_config(); $table = new CTableInfo(); $table->setAttribute('style', 'width: 400px;'); // if acknowledges are turned on, we show 'ack' column if ($config['event_ack_enable']) { $table->setHeader(array(_('Time'), _('Status'), _('Duration'), _('Age'), _('Ack'))); } else { $table->setHeader(array(_('Time'), _('Status'), _('Duration'), _('Age'))); } $events = API::Event()->get(array('source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'output' => API_OUTPUT_EXTEND, 'objectids' => $triggerId, 'eventid_till' => $eventId, 'select_acknowledges' => API_OUTPUT_COUNT, 'sortfield' => array('clock', 'eventid'), 'sortorder' => ZBX_SORT_DOWN, 'limit' => ZBX_WIDGET_ROWS)); $lclock = time(); foreach ($events as $event) { $duration = zbx_date2age($lclock, $event['clock']); $lclock = $event['clock']; $eventStatusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($eventStatusSpan, $event['value'], $event['clock'], $event['acknowledged']); $table->addRow(array(zbx_date2str(_('d M Y H:i:s'), $event['clock']), $eventStatusSpan, $duration, zbx_date2age($event['clock']), getEventAckState($event, false, false))); } return $table; }
/** * Converts numerical action condition values to their corresponding string values according to action condition type. * * For action condition types such as: hosts, host groups, templates, proxies, triggers, discovery rules * and discovery checks, action condition values contain IDs. All unique IDs are first collected and then queried. * For other action condition types values are returned as they are or converted using simple string convertion * functions according to action condition type. * * @param array $actions array of actions * @param array $action['filter'] array containing arrays of action conditions and other data * @param array $action['filter']['conditions'] array of action conditions * @param array $config array containing configuration parameters for getting trigger * severity names * * @return array returns an array of actions condition string values */ function actionConditionValueToString(array $actions, array $config) { $result = []; $groupIds = []; $triggerIds = []; $hostIds = []; $templateIds = []; $proxyIds = []; $dRuleIds = []; $dCheckIds = []; foreach ($actions as $i => $action) { $result[$i] = []; foreach ($action['filter']['conditions'] as $j => $condition) { // unknown types and all of the default values for other types are 'Unknown' $result[$i][$j] = _('Unknown'); switch ($condition['conditiontype']) { case CONDITION_TYPE_HOST_GROUP: $groupIds[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_TRIGGER: $triggerIds[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_HOST: $hostIds[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_TEMPLATE: $templateIds[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_PROXY: $proxyIds[$condition['value']] = $condition['value']; break; // return values as is for following condition types // return values as is for following condition types case CONDITION_TYPE_TRIGGER_NAME: case CONDITION_TYPE_HOST_METADATA: case CONDITION_TYPE_HOST_NAME: case CONDITION_TYPE_TIME_PERIOD: case CONDITION_TYPE_DHOST_IP: case CONDITION_TYPE_DSERVICE_PORT: case CONDITION_TYPE_DUPTIME: case CONDITION_TYPE_DVALUE: case CONDITION_TYPE_APPLICATION: $result[$i][$j] = $condition['value']; break; case CONDITION_TYPE_EVENT_ACKNOWLEDGED: $result[$i][$j] = $condition['value'] ? _('Ack') : _('Not Ack'); break; case CONDITION_TYPE_MAINTENANCE: $result[$i][$j] = _('maintenance'); break; case CONDITION_TYPE_TRIGGER_VALUE: $result[$i][$j] = trigger_value2str($condition['value']); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $result[$i][$j] = getSeverityName($condition['value'], $config); break; case CONDITION_TYPE_DRULE: $dRuleIds[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DCHECK: $dCheckIds[$condition['value']] = $condition['value']; break; case CONDITION_TYPE_DOBJECT: $result[$i][$j] = discovery_object2str($condition['value']); break; case CONDITION_TYPE_DSERVICE_TYPE: $result[$i][$j] = discovery_check_type2str($condition['value']); break; case CONDITION_TYPE_DSTATUS: $result[$i][$j] = discovery_object_status2str($condition['value']); break; case CONDITION_TYPE_EVENT_TYPE: $result[$i][$j] = eventType($condition['value']); break; } } } $groups = []; $triggers = []; $hosts = []; $templates = []; $proxies = []; $dRules = []; $dChecks = []; if ($groupIds) { $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupIds, 'preservekeys' => true]); } if ($triggerIds) { $triggers = API::Trigger()->get(['output' => ['description'], 'triggerids' => $triggerIds, 'expandDescription' => true, 'selectHosts' => ['name'], 'preservekeys' => true]); } if ($hostIds) { $hosts = API::Host()->get(['output' => ['name'], 'hostids' => $hostIds, 'preservekeys' => true]); } if ($templateIds) { $templates = API::Template()->get(['output' => ['name'], 'templateids' => $templateIds, 'preservekeys' => true]); } if ($proxyIds) { $proxies = API::Proxy()->get(['output' => ['host'], 'proxyids' => $proxyIds, 'preservekeys' => true]); } if ($dRuleIds) { $dRules = API::DRule()->get(['output' => ['name'], 'druleids' => $dRuleIds, 'preservekeys' => true]); } if ($dCheckIds) { $dChecks = API::DCheck()->get(['output' => ['type', 'key_', 'ports'], 'dcheckids' => $dCheckIds, 'selectDRules' => ['name'], 'preservekeys' => true]); } if ($groups || $triggers || $hosts || $templates || $proxies || $dRules || $dChecks) { foreach ($actions as $i => $action) { foreach ($action['filter']['conditions'] as $j => $condition) { $id = $condition['value']; switch ($condition['conditiontype']) { case CONDITION_TYPE_HOST_GROUP: if (isset($groups[$id])) { $result[$i][$j] = $groups[$id]['name']; } break; case CONDITION_TYPE_TRIGGER: if (isset($triggers[$id])) { $host = reset($triggers[$id]['hosts']); $result[$i][$j] = $host['name'] . NAME_DELIMITER . $triggers[$id]['description']; } break; case CONDITION_TYPE_HOST: if (isset($hosts[$id])) { $result[$i][$j] = $hosts[$id]['name']; } break; case CONDITION_TYPE_TEMPLATE: if (isset($templates[$id])) { $result[$i][$j] = $templates[$id]['name']; } break; case CONDITION_TYPE_PROXY: if (isset($proxies[$id])) { $result[$i][$j] = $proxies[$id]['host']; } break; case CONDITION_TYPE_DRULE: if (isset($dRules[$id])) { $result[$i][$j] = $dRules[$id]['name']; } break; case CONDITION_TYPE_DCHECK: if (isset($dChecks[$id])) { $drule = reset($dChecks[$id]['drules']); $type = $dChecks[$id]['type']; $key_ = $dChecks[$id]['key_']; $ports = $dChecks[$id]['ports']; $dCheck = discovery_check2str($type, $key_, $ports); $result[$i][$j] = $drule['name'] . NAME_DELIMITER . $dCheck; } break; } } } } return $result; }
function condition_value2str($conditiontype, $value) { switch ($conditiontype) { case CONDITION_TYPE_HOST_GROUP: $groups = API::HostGroup()->get(array('groupids' => $value, 'output' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1)); if ($groups) { $group = reset($groups); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER); } $str_val .= $group['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_TRIGGER: $trigs = API::Trigger()->get(array('triggerids' => $value, 'expandDescription' => true, 'output' => array('description'), 'selectHosts' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1)); if ($trigs) { $trig = reset($trigs); $host = reset($trig['hosts']); $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER); } $str_val .= $host['name'] . NAME_DELIMITER . $trig['description']; } else { return _('Unknown'); } break; case CONDITION_TYPE_HOST: case CONDITION_TYPE_TEMPLATE: if ($host = get_host_by_hostid($value)) { $str_val = ''; if (id2nodeid($value) != get_current_nodeid()) { $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER); } $str_val .= $host['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_TRIGGER_NAME: case CONDITION_TYPE_HOST_METADATA: case CONDITION_TYPE_HOST_NAME: $str_val = $value; break; case CONDITION_TYPE_TRIGGER_VALUE: $str_val = trigger_value2str($value); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $str_val = getSeverityCaption($value); break; case CONDITION_TYPE_TIME_PERIOD: $str_val = $value; break; case CONDITION_TYPE_MAINTENANCE: $str_val = _('maintenance'); break; case CONDITION_TYPE_NODE: if ($node = get_node_by_nodeid($value)) { $str_val = $node['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_DRULE: if ($drule = get_discovery_rule_by_druleid($value)) { $str_val = $drule['name']; } else { return _('Unknown'); } break; case CONDITION_TYPE_DCHECK: $row = DBfetch(DBselect('SELECT dr.name,c.dcheckid,c.type,c.key_,c.ports' . ' FROM drules dr,dchecks c' . ' WHERE dr.druleid=c.druleid' . ' AND c.dcheckid=' . zbx_dbstr($value))); if ($row) { $str_val = $row['name'] . NAME_DELIMITER . discovery_check2str($row['type'], $row['key_'], $row['ports']); } else { return _('Unknown'); } break; case CONDITION_TYPE_DOBJECT: $str_val = discovery_object2str($value); break; case CONDITION_TYPE_PROXY: if ($host = get_host_by_hostid($value)) { $str_val = $host['host']; } else { return _('Unknown'); } break; case CONDITION_TYPE_DHOST_IP: $str_val = $value; break; case CONDITION_TYPE_DSERVICE_TYPE: $str_val = discovery_check_type2str($value); break; case CONDITION_TYPE_DSERVICE_PORT: $str_val = $value; break; case CONDITION_TYPE_DSTATUS: $str_val = discovery_object_status2str($value); break; case CONDITION_TYPE_DUPTIME: $str_val = $value; break; case CONDITION_TYPE_DVALUE: $str_val = $value; break; case CONDITION_TYPE_EVENT_ACKNOWLEDGED: $str_val = $value ? _('Ack') : _('Not Ack'); break; case CONDITION_TYPE_APPLICATION: $str_val = $value; break; case CONDITION_TYPE_EVENT_TYPE: $str_val = eventType($value); break; default: return _('Unknown'); } return $str_val; }
break; case CONDITION_TYPE_HOST: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('hostname', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), 'return PopUp("popup.php?srctbl=hosts&srcfld1=hostid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=hostname' . '&real_hosts=1&writeonly=1&noempty=1", 450, 450);', 'link_menu')); break; case CONDITION_TYPE_TRIGGER: $conditionFormList->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('trigger', '', ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), SPACE, new CButton('btn1', _('Select'), "return PopUp('popup.php?writeonly=1&dstfrm=" . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=trigger&srctbl=triggers' . "&srcfld1=triggerid&srcfld2=description');", 'link_menu')); break; case CONDITION_TYPE_TRIGGER_NAME: $rowCondition[] = new CTextBox('new_condition[value]', '', ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_VALUE: $conditionValueComboBox = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE) as $trigerValue) { $conditionValueComboBox->addItem($trigerValue, trigger_value2str($trigerValue)); } $rowCondition[] = $conditionValueComboBox; break; case CONDITION_TYPE_TIME_PERIOD: $rowCondition[] = new CTextBox('new_condition[value]', ZBX_DEFAULT_INTERVAL, ZBX_TEXTBOX_STANDARD_SIZE); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $conditionValueComboBox = new CComboBox('new_condition[value]'); $conditionValueComboBox->addItems(getSeverityCaption()); $rowCondition[] = $conditionValueComboBox; break; case CONDITION_TYPE_MAINTENANCE: $rowCondition[] = new CCol(_('maintenance')); break; case CONDITION_TYPE_NODE:
$ack = new CLink(S_YES, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $page['file']); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $page['file'], 'on'); } } $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $event['clock'])), ZBX_FLAG_EVENT); $tr_desc = new CSpan($description, 'pointer'); $tr_desc->addAction('onclick', "create_mon_trigger_menu(event, " . " new Array({'triggerid': '" . $trigger['triggerid'] . "', 'lastchange': '" . $event['clock'] . "'})," . zbx_jsvalue($items, true) . ");"); // Duration $tr_event = $event + $trigger; if ($next_event = get_next_event($tr_event, $events, $_REQUEST['hide_unknown'])) { $event['duration'] = zbx_date2age($tr_event['clock'], $next_event['clock']); } else { $event['duration'] = zbx_date2age($tr_event['clock']); } $table->addRow(array(new CLink(zbx_date2str(S_EVENTS_ACTION_TIME_FORMAT, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid'], 'action'), is_show_all_nodes() ? get_node_name_by_elid($event['objectid']) : null, $_REQUEST['hostid'] == 0 ? $host['host'] : null, new CSpan($tr_desc, 'link_menu'), new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value'])), new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority'], $event['value'])), $event['duration'], $config['event_ack_enable'] ? $ack : NULL, $actions)); } } $table = array($paging, $table, $paging); $jsmenu = new CPUMenu(null, 170); $jsmenu->InsertJavaScript(); } $events_wdgt->addItem($table); // NAV BAR $timeline = array('period' => $effectiveperiod, 'starttime' => date('YmdHis', $starttime), 'usertime' => date('YmdHis', $till)); $dom_graph_id = 'scroll_events_id'; $objData = array('id' => 'timeline_1', 'loadSBox' => 0, 'loadImage' => 0, 'loadScroll' => 1, 'dynamic' => 0, 'mainObject' => 1); zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); zbx_add_post_js('timeControl.processObjects();'); $events_wdgt->show(); include_once 'include/page_footer.php';
if (!empty($triggers)) { $clock = array(); $events = array(); $sql = 'SELECT e.eventid, e.objectid as triggerid, e.clock, e.value, e.acknowledged ' . ' FROM events e ' . ' WHERE ' . DBcondition('e.objectid', $triggerids) . ' AND (e.object+0)=' . EVENT_OBJECT_TRIGGER . $sql_cond . ' ORDER BY e.clock DESC'; $result = DBselect($sql, 0 == $show_unknown ? $limit * 50 : $limit); while (($row = DBfetch($result)) && $col < $limit) { $row = array_merge($triggers[$row['triggerid']], $row); if (0 == $show_unknown && !event_initial_time($row, $show_unknown)) { continue; } $row['desc'] = expand_trigger_description_by_data($row, ZBX_FLAG_EVENT); $row['duration'] = zbx_date2age($row['clock']); if ($next_event = get_next_event($row, $show_unknown)) { $row['duration'] = zbx_date2age($row['clock'], $next_event['clock']); } $row['value'] = new CCol(trigger_value2str($row['value']), get_trigger_value_style($row['value'])); $col++; $clock[] = $row['clock']; $events[] = $row; } $last_clock = !empty($clock) ? min($clock) : null; order_page_result($events, 'clock', ZBX_SORT_DOWN); foreach ($events as $num => $row) { // Actions $actions = get_event_actions_status($row['eventid']); //-------- if ($config['event_ack_enable']) { if ($row['acknowledged'] == 1) { $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row['eventid'], 'action'); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row['eventid'], 'on');
if ($show_events == EVENTS_OPTION_NOEVENT) { $open_close = null; } else { $open_close = SPACE; } } $severity_col = new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority'], $trigger['value'])); if ($show_event_col) { $severity_col->setColSpan(2); } $table->addRow(array($open_close, $config['event_ack_enable'] ? $show_event_col ? null : new CCheckBox('triggers[' . $trigger['triggerid'] . ']', 'no', null, $trigger['triggerid']) : null, $severity_col, $status, $lastchange, zbx_date2age($trigger['lastchange']), $show_event_col ? SPACE : NULL, $to_ack, get_node_name_by_elid($trigger['triggerid']), $host, $tr_desc, new CLink(zbx_empty($trigger['comments']) ? S_ADD : S_SHOW, 'tr_comments.php?triggerid=' . $trigger['triggerid'])), 'even_row'); if ($show_events != EVENTS_OPTION_NOEVENT) { $i = 1; foreach ($trigger['events'] as $enum => $row_event) { $i++; $status = new CSpan(trigger_value2str($row_event['value']), get_trigger_value_style($row_event['value'])); if ($config['event_ack_enable']) { if ($row_event['value'] == TRIGGER_VALUE_TRUE) { if ($row_event['acknowledged'] == 1) { $acks_cnt = DBfetch(DBselect('SELECT COUNT(*) as cnt FROM acknowledges WHERE eventid=' . $row_event['eventid'])); $ack = array(new CSpan(S_YES, 'off'), SPACE . '(' . $acks_cnt['cnt'] . SPACE, new CLink(S_SHOW, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file']), ')'); } else { $ack = new CLink(S_NOT_ACKNOWLEDGED, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'on'); } } else { $ack = SPACE; } } if ($row_event['acknowledged'] == 0 && $row_event['value'] == TRIGGER_VALUE_TRUE) { $ack_cb = new CCheckBox('events[' . $row_event['eventid'] . ']', 'no', NULL, $row_event['eventid']); } else {
case CONDITION_TYPE_TEMPLATE: $condition = (new CMultiSelect(['name' => 'new_condition[value][]', 'objectName' => 'templates', 'objectOptions' => ['editable' => true], 'defaultValue' => 0, 'popup' => ['parameters' => 'srctbl=templates&srcfld1=hostid&srcfld2=host&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value_&templated_hosts=1&multiselect=1&writeonly=1']]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH); break; case CONDITION_TYPE_HOST: $condition = (new CMultiSelect(['name' => 'new_condition[value][]', 'objectName' => 'hosts', 'objectOptions' => ['editable' => true], 'defaultValue' => 0, 'popup' => ['parameters' => 'srctbl=hosts&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value_' . '&srcfld1=hostid&writeonly=1&multiselect=1']]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH); break; case CONDITION_TYPE_TRIGGER: $condition = (new CMultiSelect(['name' => 'new_condition[value][]', 'objectName' => 'triggers', 'objectOptions' => ['editable' => true], 'defaultValue' => 0, 'popup' => ['parameters' => 'srctbl=triggers&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value_' . '&srcfld1=triggerid&writeonly=1&multiselect=1&noempty=1']]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH); break; case CONDITION_TYPE_TRIGGER_NAME: $condition = (new CTextBox('new_condition[value]', ''))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH); break; case CONDITION_TYPE_TRIGGER_VALUE: $triggerValues = []; foreach ([TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE] as $triggerValue) { $triggerValues[$triggerValue] = trigger_value2str($triggerValue); } $condition = new CComboBox('new_condition[value]', null, null, $triggerValues); break; case CONDITION_TYPE_TIME_PERIOD: $condition = (new CTextBox('new_condition[value]', ZBX_DEFAULT_INTERVAL))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $severityNames = []; for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { $severityNames[] = getSeverityName($severity, $this->data['config']); } $condition = new CComboBox('new_condition[value]', null, null, $severityNames); break; case CONDITION_TYPE_MAINTENANCE: $condition = _('maintenance');