/**
  * Validates the given condition formula and checks if the given conditions match the formula.
  *
  * @param array $object
  *
  * @return bool
  */
 public function validate($object)
 {
     // validate only custom expressions
     if ($object['evaltype'] != CONDITION_EVAL_TYPE_EXPRESSION) {
         return true;
     }
     // check if the formula is valid
     $parser = new CConditionFormula();
     if (!$parser->parse($object['formula'])) {
         $this->error($this->messageInvalidFormula, $object['formula'], $parser->error);
         return false;
     }
     // check that all conditions used in the formula are defined in the "conditions" array
     $conditions = zbx_toHash($object['conditions'], 'formulaid');
     $constants = array_unique(zbx_objectValues($parser->constants, 'value'));
     foreach ($constants as $constant) {
         if (!array_key_exists($constant, $conditions)) {
             $this->error($this->messageMissingCondition, $constant, $object['formula']);
             return false;
         }
         unset($conditions[$constant]);
     }
     // check that the "conditions" array has no unused conditions
     if ($conditions) {
         $condition = reset($conditions);
         $this->error($this->messageUnusedCondition, $condition['formulaid'], $object['formula']);
         return false;
     }
     return true;
 }
 protected function doAction()
 {
     $mediatype = [];
     $this->getInputs($mediatype, ['mediatypeid', 'type', 'description']);
     $mediatype['status'] = $this->getInput('status', MEDIA_TYPE_STATUS_DISABLED);
     switch ($mediatype['type']) {
         case MEDIA_TYPE_EMAIL:
             $this->getInputs($mediatype, ['smtp_server', 'smtp_port', 'smtp_helo', 'smtp_email', 'smtp_security', 'smtp_authentication', 'passwd']);
             if ($this->hasInput('smtp_username')) {
                 $mediatype['username'] = $this->getInput('smtp_username');
             }
             $mediatype['smtp_verify_peer'] = $this->getInput('smtp_verify_peer', 0);
             $mediatype['smtp_verify_host'] = $this->getInput('smtp_verify_host', 0);
             break;
         case MEDIA_TYPE_EXEC:
             $this->getInputs($mediatype, ['exec_path']);
             $mediatype['exec_params'] = '';
             if ($this->hasInput('exec_params')) {
                 $exec_params = zbx_objectValues($this->getInput('exec_params'), 'exec_param');
                 foreach ($exec_params as $exec_param) {
                     $mediatype['exec_params'] .= $exec_param . "\n";
                 }
             }
             break;
         case MEDIA_TYPE_SMS:
             $this->getInputs($mediatype, ['gsm_modem']);
             break;
         case MEDIA_TYPE_JABBER:
             $this->getInputs($mediatype, ['passwd']);
             if ($this->hasInput('jabber_username')) {
                 $mediatype['username'] = $this->getInput('jabber_username');
             }
             break;
         case MEDIA_TYPE_EZ_TEXTING:
             $this->getInputs($mediatype, ['passwd']);
             if ($this->hasInput('eztext_username')) {
                 $mediatype['username'] = $this->getInput('eztext_username');
             }
             if ($this->hasInput('eztext_limit')) {
                 $mediatype['exec_path'] = $this->getInput('eztext_limit');
             }
             break;
     }
     DBstart();
     $result = API::Mediatype()->update($mediatype);
     if ($result) {
         add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_MEDIA_TYPE, 'Media type [' . $mediatype['description'] . ']');
     }
     $result = DBend($result);
     if ($result) {
         $response = new CControllerResponseRedirect('zabbix.php?action=mediatype.list&uncheck=1');
         $response->setMessageOk(_('Media type updated'));
     } else {
         $response = new CControllerResponseRedirect('zabbix.php?action=mediatype.edit');
         $response->setFormData($this->getInputAll());
         $response->setMessageError(_('Cannot update media type'));
     }
     $this->setResponse($response);
 }
 protected function doAction()
 {
     // default values
     $data = ['sid' => $this->getUserSID(), 'proxyid' => 0, 'host' => '', 'status' => HOST_STATUS_PROXY_ACTIVE, 'dns' => 'localhost', 'ip' => '127.0.0.1', 'useip' => '1', 'port' => '10051', 'proxy_hostids' => [], 'description' => '', 'tls_accept' => HOST_ENCRYPTION_NONE, 'tls_connect' => HOST_ENCRYPTION_NONE, 'tls_issuer' => '', 'tls_psk' => '', 'tls_psk_identity' => '', 'tls_subject' => '', 'form_refresh' => 0];
     // get values from the dabatase
     if ($this->hasInput('proxyid')) {
         $data['proxyid'] = $this->getInput('proxyid');
         $proxies = API::Proxy()->get(['output' => ['host', 'status', 'description', 'tls_connect', 'tls_accept', 'tls_issuer', 'tls_subject', 'tls_psk_identity', 'tls_psk'], 'selectHosts' => ['hostid'], 'selectInterface' => ['interfaceid', 'dns', 'ip', 'useip', 'port'], 'proxyids' => $data['proxyid']]);
         $proxy = $proxies[0];
         $data['host'] = $proxy['host'];
         $data['status'] = $proxy['status'];
         $data['tls_accept'] = $proxy['tls_accept'];
         $data['tls_connect'] = $proxy['tls_connect'];
         $data['tls_issuer'] = $proxy['tls_issuer'];
         $data['tls_psk'] = $proxy['tls_psk'];
         $data['tls_psk_identity'] = $proxy['tls_psk_identity'];
         $data['tls_subject'] = $proxy['tls_subject'];
         if ($data['status'] == HOST_STATUS_PROXY_PASSIVE) {
             $data['interfaceid'] = $proxy['interface']['interfaceid'];
             $data['dns'] = $proxy['interface']['dns'];
             $data['ip'] = $proxy['interface']['ip'];
             $data['useip'] = $proxy['interface']['useip'];
             $data['port'] = $proxy['interface']['port'];
         }
         $data['proxy_hostids'] = zbx_objectValues($proxy['hosts'], 'hostid');
         $data['description'] = $proxy['description'];
     }
     // overwrite with input variables
     $data['host'] = $this->getInput('host', $data['host']);
     $data['status'] = $this->getInput('status', $data['status']);
     $data['dns'] = $this->getInput('dns', $data['dns']);
     $data['ip'] = $this->getInput('ip', $data['ip']);
     $data['useip'] = $this->getInput('useip', $data['useip']);
     $data['port'] = $this->getInput('port', $data['port']);
     $data['proxy_hostids'] = $this->getInput('proxy_hostids', $data['proxy_hostids']);
     $data['description'] = $this->getInput('description', $data['description']);
     $data['tls_accept'] = $this->getInput('tls_accept', $data['tls_accept']);
     $data['tls_connect'] = $this->getInput('tls_connect', $data['tls_connect']);
     $data['tls_issuer'] = $this->getInput('tls_issuer', $data['tls_issuer']);
     $data['tls_psk'] = $this->getInput('tls_psk', $data['tls_psk']);
     $data['tls_psk_identity'] = $this->getInput('tls_psk_identity', $data['tls_psk_identity']);
     $data['tls_subject'] = $this->getInput('tls_subject', $data['tls_subject']);
     $data['form_refresh'] = $this->getInput('form_refresh', $data['form_refresh']);
     if ($data['status'] == HOST_STATUS_PROXY_PASSIVE && $this->hasInput('interfaceid')) {
         $data['interfaceid'] = $this->getInput('interfaceid');
     }
     // fetch available hosts, skip host prototypes
     $data['all_hosts'] = DBfetchArray(DBselect('SELECT h.hostid,h.proxy_hostid,h.name,h.flags' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND h.flags<>' . ZBX_FLAG_DISCOVERY_PROTOTYPE));
     order_result($data['all_hosts'], 'name');
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Configuration of proxies'));
     $this->setResponse($response);
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     // fetch hosts
     $hosts = API::Host()->get(array('output' => array('hostid', 'status'), 'selectGraphs' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'selectScreens' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'groupids' => $this->screenitem['resourceid'], 'preservekeys' => true));
     $hostIds = array_keys($hosts);
     $options = array('output' => array('description', 'expression', 'priority', 'url', 'value', 'triggerid', 'lastchange', 'flags'), 'selectHosts' => array('hostid', 'name', 'status'), 'hostids' => $hostIds, 'monitored' => true, 'skipDependent' => true, 'sortfield' => 'description');
     // application filter
     if ($this->screenitem['application'] !== '') {
         $applications = API::Application()->get(array('output' => array('applicationid'), 'hostids' => $hostIds, 'search' => array('name' => $this->screenitem['application'])));
         $options['applicationids'] = zbx_objectValues($applications, 'applicationid');
     }
     $triggers = API::Trigger()->get($options);
     return $this->getOutput(getTriggersOverview($hosts, $triggers, $this->pageFile, $this->screenitem['style'], $this->screenid));
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $hostids = array();
     $dbHostGroups = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
     while ($dbHostGroup = DBfetch($dbHostGroups)) {
         $hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
     }
     // application filter
     $applicationIds = null;
     if ($this->screenitem['application'] !== '') {
         $applications = API::Application()->get(array('output' => array('applicationid'), 'hostids' => $hostids, 'search' => array('name' => $this->screenitem['application'])));
         $applicationIds = zbx_objectValues($applications, 'applicationid');
     }
     return $this->getOutput(getItemsDataOverview($hostids, $applicationIds, $this->screenitem['style']));
 }
 protected function doAction()
 {
     $filter = ['groupids' => null, 'maintenance' => null, 'severity' => null, 'trigger_name' => '', 'extAck' => 0];
     if (CProfile::get('web.dashconf.filter.enable', 0) == 1) {
         // groups
         if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) {
             // null mean all groups
             $filter['groupids'] = null;
         } else {
             $filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value');
             $hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value');
             if ($hideHostGroupIds) {
                 // get all groups if no selected groups defined
                 if (!$filter['groupids']) {
                     $dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]);
                     $filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid');
                 }
                 $filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds);
                 // get available hosts
                 $dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]);
                 $availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid');
                 $dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]);
                 $disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid');
                 $filter['hostids'] = array_diff($availableHostIds, $disabledHostIds);
             } else {
                 if (!$filter['groupids']) {
                     // null mean all groups
                     $filter['groupids'] = null;
                 }
             }
         }
         // hosts
         $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1);
         $filter['maintenance'] = $maintenance == 0 ? 0 : null;
         // triggers
         $severity = CProfile::get('web.dashconf.triggers.severity', null);
         $filter['severity'] = zbx_empty($severity) ? null : explode(';', $severity);
         $filter['severity'] = zbx_toHash($filter['severity']);
         $filter['trigger_name'] = CProfile::get('web.dashconf.triggers.name', '');
         $config = select_config();
         $filter['extAck'] = $config['event_ack_enable'] ? CProfile::get('web.dashconf.events.extAck', 0) : 0;
     }
     $this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]]));
 }
 /**
  * Validates the given condition formula and checks if the given conditions match the formula.
  *
  * @param array $object
  *
  * @return bool
  */
 public function validate($object)
 {
     if ($object['evaltype'] == CONDITION_EVAL_TYPE_AND) {
         // get triggers count in formula
         $trigger_count = 0;
         foreach ($object['conditions'] as $condition) {
             if (array_key_exists('conditiontype', $condition) && array_key_exists('operator', $condition) && $condition['conditiontype'] == CONDITION_TYPE_TRIGGER && $condition['operator'] == CONDITION_OPERATOR_EQUAL) {
                 $trigger_count++;
             }
         }
         // check if multiple triggers are compared with AND
         if ($trigger_count > 1) {
             $this->error($this->messageAndWithSeveralTriggers);
             return false;
         }
     }
     // validate only custom expressions
     if ($object['evaltype'] != CONDITION_EVAL_TYPE_EXPRESSION) {
         return true;
     }
     // check if the formula is valid
     $parser = new CConditionFormula();
     if (!$parser->parse($object['formula'])) {
         $this->error($this->messageInvalidFormula, $object['formula'], $parser->error);
         return false;
     }
     // check that all conditions used in the formula are defined in the "conditions" array
     $conditions = zbx_toHash($object['conditions'], 'formulaid');
     $constants = array_unique(zbx_objectValues($parser->constants, 'value'));
     foreach ($constants as $constant) {
         if (!array_key_exists($constant, $conditions)) {
             $this->error($this->messageMissingCondition, $constant, $object['formula']);
             return false;
         }
         unset($conditions[$constant]);
     }
     // check that the "conditions" array has no unused conditions
     if ($conditions) {
         $condition = reset($conditions);
         $this->error($this->messageUnusedCondition, $condition['formulaid'], $object['formula']);
         return false;
     }
     return true;
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $hostids = [];
     $dbHostGroups = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
     while ($dbHostGroup = DBfetch($dbHostGroups)) {
         $hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
     }
     // application filter
     $applicationIds = null;
     if ($this->screenitem['application'] !== '') {
         $applications = API::Application()->get(['output' => ['applicationid'], 'hostids' => $hostids, 'search' => ['name' => $this->screenitem['application']]]);
         $applicationIds = zbx_objectValues($applications, 'applicationid');
     }
     $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
     $header = (new CDiv([new CTag('h4', true, _('Data overview')), (new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']])]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
     $table = getItemsDataOverview($hostids, $applicationIds, $this->screenitem['style']);
     $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
 }
 /**
  * Get screen item data.
  *
  * @param array $options
  * @param array $options['hostid']			Use hostid to get real resource id
  * @param array $options['screenitemids']	Search by screen item IDs
  * @param array $options['screenids']		Search by screen IDs
  * @param array $options['filter']			Result filter
  * @param array $options['limit']			The size of the result set
  *
  * @return array
  */
 public function get(array $options = [])
 {
     $options = zbx_array_merge($this->getOptions, $options);
     // build and execute query
     $sql = $this->createSelectQuery($this->tableName(), $options);
     $res = DBselect($sql, $options['limit']);
     // fetch results
     $result = [];
     while ($row = DBfetch($res)) {
         // count query, return a single result
         if ($options['countOutput'] !== null) {
             $result = $row['rowscount'];
         } else {
             if ($options['preservekeys'] !== null) {
                 $result[$row['screenitemid']] = $row;
             } else {
                 $result[] = $row;
             }
         }
     }
     // fill result with real resourceid
     if ($options['hostids'] && $result) {
         if (empty($options['screenitemid'])) {
             $options['screenitemid'] = zbx_objectValues($result, 'screenitemid');
         }
         $dbTemplateScreens = API::TemplateScreen()->get(['output' => ['screenitemid'], 'screenitemids' => $options['screenitemid'], 'hostids' => $options['hostids'], 'selectScreenItems' => API_OUTPUT_EXTEND]);
         if ($dbTemplateScreens) {
             foreach ($result as &$screenItem) {
                 foreach ($dbTemplateScreens as $dbTemplateScreen) {
                     foreach ($dbTemplateScreen['screenitems'] as $dbScreenItem) {
                         if ($screenItem['screenitemid'] == $dbScreenItem['screenitemid'] && isset($dbScreenItem['real_resourceid']) && $dbScreenItem['real_resourceid']) {
                             $screenItem['real_resourceid'] = $dbScreenItem['real_resourceid'];
                         }
                     }
                 }
             }
             unset($screenItem);
         }
     }
     return $result;
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     // fetch hosts
     $hosts = API::Host()->get(array('output' => array('hostid', 'status'), 'selectGraphs' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'selectScreens' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'groupids' => $this->screenitem['resourceid'], 'preservekeys' => true));
     $hostIds = array_keys($hosts);
     $options = array('output' => array('description', 'expression', 'priority', 'url', 'value', 'triggerid', 'lastchange', 'flags'), 'selectHosts' => array('hostid', 'name', 'status'), 'selectItems' => array('itemid', 'hostid', 'name', 'key_', 'value_type'), 'hostids' => $hostIds, 'monitored' => true, 'skipDependent' => true, 'sortfield' => 'description');
     // application filter
     if ($this->screenitem['application'] !== '') {
         $applications = API::Application()->get(array('output' => array('applicationid'), 'hostids' => $hostIds, 'search' => array('name' => $this->screenitem['application'])));
         $options['applicationids'] = zbx_objectValues($applications, 'applicationid');
     }
     $triggers = API::Trigger()->get($options);
     /*
      * Each screen cell with "Triggers overview" depends on one specific group which in this case is 'resourceid'.
      * Pass it as 'groupid' to menu pop-up "Events" link.
      */
     foreach ($triggers as &$trigger) {
         $trigger['groupid'] = $this->screenitem['resourceid'];
     }
     unset($trigger);
     return $this->getOutput(getTriggersOverview($hosts, $triggers, $this->pageFile, $this->screenitem['style'], $this->screenid));
 }
 protected function doAction()
 {
     $eventids = $this->getInput('eventids');
     $acknowledge_type = $this->getInput('acknowledge_type');
     $result = true;
     if ($acknowledge_type == ZBX_ACKNOWLEDGE_PROBLEM || $acknowledge_type == ZBX_ACKNOWLEDGE_ALL) {
         $events = API::Event()->get(['output' => ['objectid'], 'source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'eventids' => $eventids]);
         $triggerids = zbx_objectValues($events, 'objectid');
         $filter = ['acknowledged' => EVENT_NOT_ACKNOWLEDGED];
         if ($acknowledge_type == ZBX_ACKNOWLEDGE_PROBLEM) {
             $filter['value'] = TRIGGER_VALUE_TRUE;
         }
         while ($result) {
             $events = API::Event()->get(['output' => [], 'source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'objectids' => $triggerids, 'filter' => $filter, 'preservekeys' => true, 'limit' => ZBX_DB_MAX_INSERTS]);
             if ($events) {
                 foreach ($eventids as $i => $eventid) {
                     if (array_key_exists($eventid, $events)) {
                         unset($eventids[$i]);
                     }
                 }
                 $result = API::Event()->acknowledge(['eventids' => array_keys($events), 'message' => $this->getInput('message', '')]);
             } else {
                 break;
             }
         }
     }
     if ($result && $eventids) {
         $result = API::Event()->acknowledge(['eventids' => $eventids, 'message' => $this->getInput('message', '')]);
     }
     if ($result) {
         $response = new CControllerResponseRedirect($this->getInput('backurl', 'tr_status.php'));
         $response->setMessageOk(_n('Event acknowledged', 'Events acknowledged', count($eventids)));
     } else {
         $response = new CControllerResponseRedirect('zabbix.php?action=acknowledge.edit');
         $response->setFormData($this->getInputAll());
         $response->setMessageError(_n('Cannot acknowledge event', 'Cannot acknowledge events', count($eventids)));
     }
     $this->setResponse($response);
 }
 protected function doAction()
 {
     $filter = ['groupids' => null, 'maintenance' => null];
     if (CProfile::get('web.dashconf.filter.enable', 0) == 1) {
         // groups
         if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) {
             // null mean all groups
             $filter['groupids'] = null;
         } else {
             $filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value');
             $hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value');
             if ($hideHostGroupIds) {
                 // get all groups if no selected groups defined
                 if (!$filter['groupids']) {
                     $dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]);
                     $filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid');
                 }
                 $filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds);
                 // get available hosts
                 $dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]);
                 $availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid');
                 $dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]);
                 $disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid');
                 $filter['hostids'] = array_diff($availableHostIds, $disabledHostIds);
             } else {
                 if (!$filter['groupids']) {
                     // null mean all groups
                     $filter['groupids'] = null;
                 }
             }
         }
         // hosts
         $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1);
         $filter['maintenance'] = $maintenance == 0 ? 0 : null;
     }
     $this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]]));
 }
 /**
  * Get templates that don't have not existing linked templates i.e. all templates that must be linked to these templates exist.
  * Returns array with template names (host).
  *
  * @param array $templates
  *
  * @return array
  */
 protected function getIndependentTemplates(array $templates)
 {
     foreach ($templates as $num => $template) {
         if (empty($template['templates'])) {
             continue;
         }
         foreach ($template['templates'] as $linkedTpl) {
             if (!$this->referencer->resolveTemplate($linkedTpl['name'])) {
                 unset($templates[$num]);
                 continue 2;
             }
         }
     }
     return zbx_objectValues($templates, 'host');
 }
Beispiel #14
0
$dashForm->addVar('form_refresh', 1);
$dashForm->setName('dashconf');
$dashForm->setAttribute('id', 'dashform');
if (isset($_REQUEST['form_refresh'])) {
    $filterEnable = get_request('filterEnable', 0);
    $groupids = get_request('groupids', array());
    $groupids = zbx_toHash($groupids);
    $grpswitch = get_request('grpswitch', 0);
    $maintenance = get_request('maintenance', 0);
    $extAck = get_request('extAck', 0);
    $severity = get_request('trgSeverity', array());
    $severity = array_keys($severity);
} else {
    $filterEnable = CProfile::get('web.dashconf.filter.enable', 0);
    $groupids = get_favorites('web.dashconf.groups.groupids');
    $groupids = zbx_objectValues($groupids, 'value');
    $groupids = zbx_toHash($groupids);
    $grpswitch = CProfile::get('web.dashconf.groups.grpswitch', 0);
    $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1);
    $extAck = CProfile::get('web.dashconf.events.extAck', 0);
    $severity = CProfile::get('web.dashconf.triggers.severity', '0;1;2;3;4;5');
    $severity = zbx_empty($severity) ? array() : explode(';', $severity);
}
$dashForm->addVar('filterEnable', $filterEnable);
if ($filterEnable) {
    $cbFilter = new CSpan(S_ENABLED, 'green underline pointer');
    $cbFilter->setAttribute('onclick', "create_var('" . $dashForm->getName() . "', 'filterEnable', 0, true);");
} else {
    $cbFilter = new CSpan(S_DISABLED, 'red underline pointer');
    $cbFilter->setAttribute('onclick', "\$('dashform').enable(); create_var('" . $dashForm->getName() . "', 'filterEnable', 1, true);");
}
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $this->dataId = 'discovery';
     $sort_field = $this->data['sort'];
     $sort_order = $this->data['sortorder'];
     $druleid = $this->data['druleid'];
     // discovery rules
     $options = ['output' => ['druleid', 'name'], 'selectDHosts' => ['dhostid', 'status', 'lastup', 'lastdown'], 'filter' => ['status' => DRULE_STATUS_ACTIVE]];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
         // set selected discovery rule id
     }
     $drules = API::DRule()->get($options);
     if ($drules) {
         order_result($drules, 'name');
     }
     // discovery services
     $options = ['selectHosts' => ['hostid', 'name', 'status'], 'output' => ['dserviceid', 'type', 'key_', 'port', 'status', 'lastup', 'lastdown', 'ip', 'dns'], 'sortfield' => $sort_field, 'sortorder' => $sort_order, 'limitSelects' => 1];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
     } else {
         $options['druleids'] = zbx_objectValues($drules, 'druleid');
     }
     $dservices = API::DService()->get($options);
     // user macros
     $macros = API::UserMacro()->get(['output' => ['macro', 'value'], 'globalmacro' => true]);
     $macros = zbx_toHash($macros, 'macro');
     // services
     $services = [];
     foreach ($dservices as $dservice) {
         $key_ = $dservice['key_'];
         if ($key_ !== '') {
             if (array_key_exists($key_, $macros)) {
                 $key_ = $macros[$key_]['value'];
             }
             $key_ = ': ' . $key_;
         }
         $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
         $services[$service_name] = 1;
     }
     ksort($services);
     // discovery services to hash
     $dservices = zbx_toHash($dservices, 'dserviceid');
     // discovery hosts
     $dhosts = API::DHost()->get(['druleids' => zbx_objectValues($drules, 'druleid'), 'selectDServices' => ['dserviceid', 'ip', 'dns', 'type', 'status', 'key_'], 'output' => ['dhostid', 'lastdown', 'lastup', 'druleid']]);
     $dhosts = zbx_toHash($dhosts, 'dhostid');
     $header = [make_sorting_header(_('Discovered device'), 'ip', $sort_field, $sort_order, 'zabbix.php?action=discovery.view'), _('Monitored host'), _('Uptime') . '/' . _('Downtime')];
     foreach ($services as $name => $foo) {
         $header[] = (new CColHeader($name))->addClass('vertical_rotation');
     }
     // create table
     $table = (new CTableInfo())->makeVerticalRotation()->setHeader($header);
     foreach ($drules as $drule) {
         $discovery_info = [];
         foreach ($drule['dhosts'] as $dhost) {
             if ($dhost['status'] == DHOST_STATUS_DISABLED) {
                 $hclass = 'disabled';
                 $htime = $dhost['lastdown'];
             } else {
                 $hclass = 'enabled';
                 $htime = $dhost['lastup'];
             }
             // $primary_ip stores the primary host ip of the dhost
             $primary_ip = '';
             foreach ($dhosts[$dhost['dhostid']]['dservices'] as $dservice) {
                 $dservice = $dservices[$dservice['dserviceid']];
                 $hostName = '';
                 $host = reset($dservices[$dservice['dserviceid']]['hosts']);
                 if (!is_null($host)) {
                     $hostName = $host['name'];
                 }
                 if ($primary_ip !== '') {
                     if ($primary_ip === $dservice['ip']) {
                         $htype = 'primary';
                     } else {
                         $htype = 'slave';
                     }
                 } else {
                     $primary_ip = $dservice['ip'];
                     $htype = 'primary';
                 }
                 if (!array_key_exists($dservice['ip'], $discovery_info)) {
                     $discovery_info[$dservice['ip']] = ['ip' => $dservice['ip'], 'dns' => $dservice['dns'], 'type' => $htype, 'class' => $hclass, 'host' => $hostName, 'time' => $htime];
                 }
                 if ($dservice['status'] == DSVC_STATUS_DISABLED) {
                     $class = ZBX_STYLE_INACTIVE_BG;
                     $time = 'lastdown';
                 } else {
                     $class = ZBX_STYLE_ACTIVE_BG;
                     $time = 'lastup';
                 }
                 $key_ = $dservice['key_'];
                 if ($key_ !== '') {
                     if (array_key_exists($key_, $macros)) {
                         $key_ = $macros[$key_]['value'];
                     }
                     $key_ = NAME_DELIMITER . $key_;
                 }
                 $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
                 $discovery_info[$dservice['ip']]['services'][$service_name] = ['class' => $class, 'time' => $dservice[$time]];
             }
         }
         if ($druleid == 0 && $discovery_info) {
             $col = new CCol([bold($drule['name']), SPACE . '(' . _n('%d device', '%d devices', count($discovery_info)) . ')']);
             $col->setColSpan(count($services) + 3);
             $table->addRow($col);
         }
         order_result($discovery_info, $sort_field, $sort_order);
         foreach ($discovery_info as $ip => $h_data) {
             $dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')';
             $row = [$h_data['type'] == 'primary' ? (new CSpan($ip . $dns))->addClass($h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(array_key_exists('host', $h_data) ? $h_data['host'] : ''), (new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(['value' => time() - $h_data['time'], 'units' => 'uptime'])))->addClass($h_data['class'])];
             foreach ($services as $name => $foo) {
                 $class = null;
                 $time = SPACE;
                 $hint = (new CDiv(SPACE))->addClass($class);
                 $hint_table = null;
                 if (array_key_exists($name, $h_data['services'])) {
                     $class = $h_data['services'][$name]['class'];
                     $time = $h_data['services'][$name]['time'];
                     $hint_table = (new CTableInfo())->setAttribute('style', 'width: auto;');
                     if ($class == ZBX_STYLE_ACTIVE_BG) {
                         $hint_table->setHeader(_('Uptime'));
                     } else {
                         $hint_table->setHeader(_('Downtime'));
                     }
                     $hint_table->addRow((new CCol(zbx_date2age($h_data['services'][$name]['time'])))->addClass($class));
                 }
                 $column = (new CCol($hint))->addClass($class);
                 if (!is_null($hint_table)) {
                     $column->setHint($hint_table);
                 }
                 $row[] = $column;
             }
             $table->addRow($row);
         }
     }
     return $this->getOutput($table, true, $this->data);
 }
Beispiel #16
0
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
require_once 'include/config.inc.php';
require_once 'include/graphs.inc.php';
$page['file'] = 'chart7.php';
// $page['title']	= "S_CHART";
$page['type'] = PAGE_TYPE_IMAGE;
include_once 'include/page_header.php';
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'from' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'border' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'name' => array(T_ZBX_STR, O_OPT, NULL, null, null), 'width' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'graphtype' => array(T_ZBX_INT, O_OPT, NULL, IN('2,3'), null), 'graph3d' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'legend' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'items' => array(T_ZBX_STR, O_OPT, NULL, null, null));
check_fields($fields);
$items = get_request('items', array());
asort_by_key($items, 'sortorder');
$options = array('webitems' => 1, 'itemids' => zbx_objectValues($items, 'itemid'), 'nodeids' => get_current_nodeid(true));
$db_data = CItem::get($options);
$db_data = zbx_toHash($db_data, 'itemid');
foreach ($items as $id => $gitem) {
    if (!isset($db_data[$gitem['itemid']])) {
        access_deny();
    }
}
$effectiveperiod = navigation_bar_calc();
$graph = new CPie(get_request('graphtype', GRAPH_TYPE_NORMAL));
$graph->setHeader(get_request('name', ''));
$graph3d = get_request('graph3d', 0);
$legend = get_request('legend', 0);
if ($graph3d == 1) {
    $graph->switchPie3D();
}
$fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'httptestid' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'http_item_type' => array(T_ZBX_INT, O_OPT, null, null, null), 'name' => array(T_ZBX_STR, O_OPT, null, null, null), 'width' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null), 'ymin_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymax_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymin_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'ymax_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'legend' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showworkperiod' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showtriggers' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'graphtype' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'yaxismin' => array(T_ZBX_DBL, O_OPT, null, null, null), 'yaxismax' => array(T_ZBX_DBL, O_OPT, null, null, null), 'percent_left' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'percent_right' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'items' => array(T_ZBX_STR, O_OPT, null, null, null));
$isDataValid = check_fields($fields);
if ($httptestid = get_request('httptestid', false)) {
    $color = array('current' => 0, 0 => array('next' => '1'), 1 => array('color' => 'Red', 'next' => '2'), 2 => array('color' => 'Dark Green', 'next' => '3'), 3 => array('color' => 'Blue', 'next' => '4'), 4 => array('color' => 'Dark Yellow', 'next' => '5'), 5 => array('color' => 'Cyan', 'next' => '6'), 6 => array('color' => 'Gray', 'next' => '7'), 7 => array('color' => 'Dark Red', 'next' => '8'), 8 => array('color' => 'Green', 'next' => '9'), 9 => array('color' => 'Dark Blue', 'next' => '10'), 10 => array('color' => 'Yellow', 'next' => '11'), 11 => array('color' => 'Black', 'next' => '1'));
    $items = array();
    $dbItems = DBselect('SELECT i.itemid' . ' FROM httpstepitem hi,items i,httpstep hs' . ' WHERE i.itemid=hi.itemid' . ' AND hs.httptestid=' . $httptestid . ' AND hs.httpstepid=hi.httpstepid' . ' AND hi.type=' . get_request('http_item_type', HTTPSTEP_ITEM_TYPE_TIME) . ' ORDER BY hs.no DESC');
    while ($item = DBfetch($dbItems)) {
        $itemColor = $color[$color['current'] = $color[$color['current']]['next']]['color'];
        $items[] = array('itemid' => $item['itemid'], 'color' => $itemColor);
    }
    $httptest = get_httptest_by_httptestid($httptestid);
    $name = $httptest['name'];
} else {
    $items = get_request('items', array());
    asort_by_key($items, 'sortorder');
    $dbItems = API::Item()->get(array('webitems' => true, 'itemids' => zbx_objectValues($items, 'itemid'), 'nodeids' => get_current_nodeid(true), 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => true, 'filter' => array('flags' => null)));
    $dbItems = zbx_toHash($dbItems, 'itemid');
    foreach ($items as $item) {
        if (!isset($dbItems[$item['itemid']])) {
            access_deny();
        }
    }
    $name = get_request('name', '');
}
/*
 * Display
 */
if ($isDataValid) {
    $graph = new CChart(get_request('graphtype', GRAPH_TYPE_NORMAL));
    $graph->setHeader($name);
    navigation_bar_calc();
Beispiel #18
0
         $period_start = mktime(0, 0, 0, date('n'), 1, date('Y'));
         break;
     case 'year':
         $period_start = mktime(0, 0, 0, 1, 1, date('Y'));
         break;
     case 24:
     case 24 * 7:
     case 24 * 30:
     case 24 * DAY_IN_YEAR:
         $period_start = $period_end - $period * 3600;
         break;
 }
 // fetch services
 $services = API::Service()->get(array('output' => array('name', 'serviceid', 'showsla', 'goodsla', 'algorithm'), 'selectParent' => array('serviceid'), 'selectDependencies' => array('servicedownid', 'soft', 'linkid'), 'selectTrigger' => array('description', 'triggerid', 'expression'), 'preservekeys' => true, 'sortfield' => 'sortorder', 'sortorder' => ZBX_SORT_UP));
 // expand trigger descriptions
 $triggers = zbx_objectValues($services, 'trigger');
 $triggers = CMacrosResolverHelper::resolveTriggerNames($triggers);
 foreach ($services as &$service) {
     if ($service['trigger']) {
         $service['trigger'] = $triggers[$service['trigger']['triggerid']];
     }
 }
 unset($service);
 // fetch sla
 $slaData = API::Service()->getSla(array('intervals' => array(array('from' => $period_start, 'to' => $period_end))));
 // expand problem trigger descriptions
 foreach ($slaData as &$serviceSla) {
     foreach ($serviceSla['problems'] as &$problemTrigger) {
         $problemTrigger['description'] = $triggers[$problemTrigger['triggerid']]['description'];
     }
     unset($problemTrigger);
Beispiel #19
0
             continue;
         }
         $macrosToUpdate[$newMacro['globalmacroid']] = $newMacro;
     }
 }
 if (!empty($macrosToUpdate)) {
     if (!API::UserMacro()->updateGlobal($macrosToUpdate)) {
         throw new Exception(_('Cannot update macro.'));
     }
     foreach ($macrosToUpdate as $macro) {
         add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_MACRO, $macro['globalmacroid'], $macro['macro'] . SPACE . RARR . SPACE . $macro['value'], null, null, null);
     }
 }
 // delete the remaining global macros
 if ($globalMacros) {
     $ids = zbx_objectValues($globalMacros, 'globalmacroid');
     if (!API::UserMacro()->deleteGlobal($ids)) {
         throw new Exception(_('Cannot remove macro.'));
     }
     foreach ($globalMacros as $macro) {
         add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_MACRO, $macro['globalmacroid'], $macro['macro'] . SPACE . RARR . SPACE . $macro['value'], null, null, null);
     }
 }
 // create
 if (!empty($newMacros)) {
     // mark marcos as new
     foreach ($newMacros as $number => $macro) {
         $_REQUEST['macros'][$number]['type'] = 'new';
     }
     $newMacrosIds = API::UserMacro()->createGlobal(array_values($newMacros));
     if (!$newMacrosIds) {
$sortLink->setArgument('parent_discoveryid', $this->data['parent_discoveryid']);
$sortLink = $sortLink->getUrl();
$itemTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $itemForm->getName() . "', 'all_items', 'group_itemid');"), make_sorting_header(_('Name'), 'name', $sortLink), make_sorting_header(_('Key'), 'key_', $sortLink), make_sorting_header(_('Interval'), 'delay', $sortLink), make_sorting_header(_('History'), 'history', $sortLink), make_sorting_header(_('Trends'), 'trends', $sortLink), make_sorting_header(_('Type'), 'type', $sortLink), _('Applications'), make_sorting_header(_('Status'), 'status', $sortLink)));
foreach ($this->data['items'] as $item) {
    $description = array();
    if (!empty($item['templateid'])) {
        $template_host = get_realhost_by_itemid($item['templateid']);
        $templateDiscoveryRuleId = get_realrule_by_itemid_and_hostid($this->data['parent_discoveryid'], $template_host['hostid']);
        $description[] = new CLink($template_host['name'], '?parent_discoveryid=' . $templateDiscoveryRuleId, 'unknown');
        $description[] = NAME_DELIMITER;
    }
    $description[] = new CLink($item['name_expanded'], '?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid']);
    $status = new CLink(itemIndicator($item['status']), '?group_itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&go=' . ($item['status'] ? 'activate' : 'disable'), itemIndicatorStyle($item['status']));
    if (!empty($item['applications'])) {
        order_result($item['applications'], 'name');
        $applications = zbx_objectValues($item['applications'], 'name');
        $applications = implode(', ', $applications);
        if (empty($applications)) {
            $applications = '-';
        }
    } else {
        $applications = '-';
    }
    $itemTable->addRow(array(new CCheckBox('group_itemid[' . $item['itemid'] . ']', null, null, $item['itemid']), $description, $item['key_'], $item['delay'], $item['history'], in_array($item['value_type'], array(ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_TEXT)) ? '' : $item['trends'], item_type2str($item['type']), new CCol($applications, 'wraptext'), $status));
}
// create go buttons
$goComboBox = new CComboBox('go');
$goOption = new CComboItem('activate', _('Enable selected'));
$goOption->setAttribute('confirm', _('Enable selected item prototypes?'));
$goComboBox->addItem($goOption);
$goOption = new CComboItem('disable', _('Disable selected'));
 /**
  * Delete Host
  *
  * @param array $hosts
  * @param array $hosts[0, ...]['hostid'] Host ID to delete
  * @return array|boolean
  */
 public static function delete($hosts)
 {
     $hosts = zbx_toArray($hosts);
     $hostids = zbx_objectValues($hosts, 'hostid');
     if (empty($hostids)) {
         return true;
     }
     try {
         self::BeginTransaction(__METHOD__);
         $options = array('hostids' => $hostids, 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1);
         $del_hosts = self::get($options);
         foreach ($hostids as $hnum => $hostid) {
             if (!isset($del_hosts[$hostid])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
             }
         }
         $result = delete_host($hostids, false);
         if (!$result) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete host');
         }
         self::EndTransaction(true, __METHOD__);
         return array('hostids' => $hostids);
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }
 protected function inherit(array $items, array $hostids = null)
 {
     if (!$items) {
         return true;
     }
     // fetch the corresponding discovery rules for the child items
     $ruleids = array();
     $dbResult = DBselect('SELECT i.itemid AS ruleid,id.itemid,i.hostid' . ' FROM items i,item_discovery id' . ' WHERE i.templateid=id.parent_itemid' . ' AND ' . dbConditionInt('id.itemid', zbx_objectValues($items, 'itemid')));
     while ($rule = DBfetch($dbResult)) {
         if (!isset($ruleids[$rule['itemid']])) {
             $ruleids[$rule['itemid']] = array();
         }
         $ruleids[$rule['itemid']][$rule['hostid']] = $rule['ruleid'];
     }
     // prepare the child items
     $newItems = $this->prepareInheritedItems($items, $hostids);
     if (!$items) {
         return true;
     }
     $insertItems = array();
     $updateItems = array();
     foreach ($newItems as $newItem) {
         if (isset($newItem['itemid'])) {
             unset($newItem['ruleid']);
             $updateItems[] = $newItem;
         } else {
             // set the corresponding discovery rule id for the new items
             $newItem['ruleid'] = $ruleids[$newItem['templateid']][$newItem['hostid']];
             $newItem['flags'] = ZBX_FLAG_DISCOVERY_PROTOTYPE;
             $insertItems[] = $newItem;
         }
     }
     // save the new items
     $this->createReal($insertItems);
     $this->updateReal($updateItems);
     // propagate the inheritance to the children
     $this->inherit(array_merge($insertItems, $updateItems));
 }
Beispiel #23
0
/**
 * Prepare map elements data.
 * Calculate problem triggers and priorities. Populate map elements with automatic icon mapping, acknowledging and
 * recent change markers.
 *
 * @param array $sysmap
 * @param int   $options
 * @param int   $options['severity_min'] Minimum trigger severity, default value is maximal (Disaster)
 *
 * @return array
 */
function getSelementsInfo($sysmap, array $options = array())
{
    if (!isset($options['severity_min'])) {
        $options['severity_min'] = TRIGGER_SEVERITY_NOT_CLASSIFIED;
    }
    $config = select_config();
    $showUnacknowledged = $config['event_ack_enable'] ? $sysmap['show_unack'] : EXTACK_OPTION_ALL;
    $triggerIdToSelementIds = array();
    $subSysmapTriggerIdToSelementIds = array();
    $hostGroupIdToSelementIds = array();
    $hostIdToSelementIds = array();
    if ($sysmap['sysmapid']) {
        $iconMap = API::IconMap()->get(array('sysmapids' => $sysmap['sysmapid'], 'selectMappings' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND));
        $iconMap = reset($iconMap);
    }
    $hostsToGetInventories = array();
    $selements = $sysmap['selements'];
    $selementIdToSubSysmaps = array();
    foreach ($selements as $selementId => &$selement) {
        $selement['hosts'] = array();
        $selement['triggers'] = array();
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $sysmapIds = array($selement['elementid']);
                while (!empty($sysmapIds)) {
                    $subSysmaps = API::Map()->get(array('sysmapids' => $sysmapIds, 'output' => array('sysmapid'), 'selectSelements' => API_OUTPUT_EXTEND, 'nopermissions' => true, 'preservekeys' => true));
                    if (!isset($selementIdToSubSysmaps[$selementId])) {
                        $selementIdToSubSysmaps[$selementId] = array();
                    }
                    $selementIdToSubSysmaps[$selementId] += $subSysmaps;
                    $sysmapIds = array();
                    foreach ($subSysmaps as $subSysmap) {
                        foreach ($subSysmap['selements'] as $subSysmapSelement) {
                            switch ($subSysmapSelement['elementtype']) {
                                case SYSMAP_ELEMENT_TYPE_MAP:
                                    $sysmapIds[] = $subSysmapSelement['elementid'];
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                                    $hostGroupIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST:
                                    $hostIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_TRIGGER:
                                    $subSysmapTriggerIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                            }
                        }
                    }
                }
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $hostGroupId = $selement['elementid'];
                $hostGroupIdToSelementIds[$hostGroupId][$selementId] = $selementId;
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $hostId = $selement['elementid'];
                $hostIdToSelementIds[$hostId][$selementId] = $selementId;
                // if we have icon map applied, we need to get inventories for all hosts,
                // where automatic icon selection is enabled.
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $hostsToGetInventories[] = $hostId;
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $triggerId = $selement['elementid'];
                $triggerIdToSelementIds[$triggerId][$selementId] = $selementId;
                break;
        }
    }
    unset($selement);
    // get host inventories
    if ($sysmap['iconmapid']) {
        $hostInventories = API::Host()->get(array('hostids' => $hostsToGetInventories, 'output' => array('hostid'), 'nopermissions' => true, 'preservekeys' => true, 'selectInventory' => API_OUTPUT_EXTEND));
    }
    $allHosts = array();
    if (!empty($hostIdToSelementIds)) {
        $hosts = API::Host()->get(array('hostids' => array_keys($hostIdToSelementIds), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'nopermissions' => true, 'preservekeys' => true));
        $allHosts = array_merge($allHosts, $hosts);
        foreach ($hosts as $hostId => $host) {
            foreach ($hostIdToSelementIds[$hostId] as $selementId) {
                $selements[$selementId]['hosts'][$hostId] = $hostId;
            }
        }
    }
    $hostsFromHostGroups = array();
    if (!empty($hostGroupIdToSelementIds)) {
        $hostsFromHostGroups = API::Host()->get(array('groupids' => array_keys($hostGroupIdToSelementIds), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'selectGroups' => array('groupid'), 'nopermissions' => true, 'preservekeys' => true));
        foreach ($hostsFromHostGroups as $hostId => $host) {
            foreach ($host['groups'] as $group) {
                $groupId = $group['groupid'];
                if (isset($hostGroupIdToSelementIds[$groupId])) {
                    foreach ($hostGroupIdToSelementIds[$groupId] as $selementId) {
                        $selement =& $selements[$selementId];
                        $selement['hosts'][$hostId] = $hostId;
                        // add hosts to hosts_map for trigger selection;
                        if (!isset($hostIdToSelementIds[$hostId])) {
                            $hostIdToSelementIds[$hostId] = array();
                        }
                        $hostIdToSelementIds[$hostId][$selementId] = $selementId;
                        unset($selement);
                    }
                }
            }
        }
        $allHosts = array_merge($allHosts, $hostsFromHostGroups);
    }
    $allHosts = zbx_toHash($allHosts, 'hostid');
    // get triggers data, triggers from current map, select all
    $allTriggers = array();
    if (!empty($triggerIdToSelementIds)) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'triggerids' => array_keys($triggerIdToSelementIds), 'filter' => array('state' => null), 'nopermissions' => true, 'preservekeys' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggers = API::Trigger()->get($triggerOptions);
        $allTriggers = array_merge($allTriggers, $triggers);
        foreach ($triggers as $triggerId => $trigger) {
            foreach ($triggerIdToSelementIds[$triggerId] as $selementId) {
                $selements[$selementId]['triggers'][$triggerId] = $triggerId;
            }
        }
    }
    // triggers from submaps, skip dependent
    if (!empty($subSysmapTriggerIdToSelementIds)) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'triggerids' => array_keys($subSysmapTriggerIdToSelementIds), 'filter' => array('state' => null), 'skipDependent' => true, 'nopermissions' => true, 'preservekeys' => true, 'only_true' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggers = API::Trigger()->get($triggerOptions);
        $allTriggers = array_merge($allTriggers, $triggers);
        foreach ($triggers as $triggerId => $trigger) {
            foreach ($subSysmapTriggerIdToSelementIds[$triggerId] as $selementId) {
                $selements[$selementId]['triggers'][$triggerId] = $triggerId;
            }
        }
    }
    $monitoredHostIds = array();
    foreach ($allHosts as $hostId => $host) {
        if ($host['status'] == HOST_STATUS_MONITORED) {
            $monitoredHostIds[$hostId] = $hostId;
        }
    }
    // triggers from all hosts/hostgroups, skip dependent
    if ($monitoredHostIds) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'selectHosts' => array('hostid'), 'selectItems' => array('itemid'), 'hostids' => $monitoredHostIds, 'filter' => array('state' => null), 'monitored' => true, 'skipDependent' => true, 'nopermissions' => true, 'preservekeys' => true, 'only_true' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggersFromMonitoredHosts = API::Trigger()->get($triggerOptions);
        foreach ($triggersFromMonitoredHosts as $triggerId => $trigger) {
            foreach ($trigger['hosts'] as $host) {
                $hostId = $host['hostid'];
                if (isset($hostIdToSelementIds[$hostId])) {
                    foreach ($hostIdToSelementIds[$hostId] as $selementId) {
                        $selements[$selementId]['triggers'][$triggerId] = $triggerId;
                    }
                }
            }
        }
        $subSysmapHostApplicationFilters = getSelementHostApplicationFilters($selements, $selementIdToSubSysmaps, $hostsFromHostGroups);
        $selements = filterSysmapTriggers($selements, $subSysmapHostApplicationFilters, $triggersFromMonitoredHosts, $subSysmapTriggerIdToSelementIds);
        $allTriggers = array_merge($allTriggers, $triggersFromMonitoredHosts);
    }
    $allTriggers = zbx_toHash($allTriggers, 'triggerid');
    $info = array();
    foreach ($selements as $selementId => $selement) {
        $i = array('disabled' => 0, 'maintenance' => 0, 'problem' => 0, 'problem_unack' => 0, 'priority' => 0, 'trigger_disabled' => 0, 'latelyChanged' => false, 'ack' => true);
        foreach ($selement['hosts'] as $hostId) {
            $host = $allHosts[$hostId];
            $last_hostid = $hostId;
            if ($host['status'] == HOST_STATUS_NOT_MONITORED) {
                $i['disabled']++;
            } elseif ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
                $i['maintenance']++;
            }
        }
        foreach ($selement['triggers'] as $triggerId) {
            $trigger = $allTriggers[$triggerId];
            if ($options['severity_min'] <= $trigger['priority']) {
                if ($trigger['status'] == TRIGGER_STATUS_DISABLED) {
                    $i['trigger_disabled']++;
                } else {
                    if ($trigger['value'] == TRIGGER_VALUE_TRUE) {
                        $i['problem']++;
                        $lastProblemId = $triggerId;
                        if ($i['priority'] < $trigger['priority']) {
                            $i['priority'] = $trigger['priority'];
                        }
                    }
                    if ($showUnacknowledged && $trigger['lastEvent'] && !$trigger['lastEvent']['acknowledged']) {
                        $i['problem_unack']++;
                    }
                    $i['latelyChanged'] |= time() - $trigger['lastchange'] < $config['blink_period'];
                }
            }
        }
        $i['ack'] = (bool) (!$i['problem_unack']);
        if ($sysmap['expandproblem'] && $i['problem'] == 1) {
            if (!isset($lastProblemId)) {
                $lastProblemId = null;
            }
            $i['problem_title'] = CMacrosResolverHelper::resolveTriggerName($allTriggers[$lastProblemId]);
        }
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $i['maintenance'] == 1) {
            $mnt = get_maintenance_by_maintenanceid($allHosts[$last_hostid]['maintenanceid']);
            $i['maintenance_title'] = $mnt['name'];
        }
        // replace default icons
        if (!$selement['iconid_on']) {
            $selement['iconid_on'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_maintenance']) {
            $selement['iconid_maintenance'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_disabled']) {
            $selement['iconid_disabled'] = $selement['iconid_off'];
        }
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $info[$selementId] = getMapsInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $info[$selementId] = getHostGroupsInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $info[$selementId] = getHostsInfo($selement, $i, $showUnacknowledged);
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $info[$selementId]['iconid'] = getIconByMapping($iconMap, $hostInventories[$selement['elementid']]);
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $info[$selementId] = getTriggersInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_IMAGE:
                $info[$selementId] = getImagesInfo($selement);
                break;
        }
    }
    if ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF) {
        $hlabel = $hglabel = $tlabel = $mlabel = $sysmap['label_type'] == MAP_LABEL_TYPE_NAME;
    } else {
        $hlabel = $sysmap['label_type_host'] == MAP_LABEL_TYPE_NAME;
        $hglabel = $sysmap['label_type_hostgroup'] == MAP_LABEL_TYPE_NAME;
        $tlabel = $sysmap['label_type_trigger'] == MAP_LABEL_TYPE_NAME;
        $mlabel = $sysmap['label_type_map'] == MAP_LABEL_TYPE_NAME;
    }
    // get names if needed
    $elems = separateMapElements($sysmap);
    if (!empty($elems['sysmaps']) && $mlabel) {
        $subSysmaps = API::Map()->get(array('sysmapids' => zbx_objectValues($elems['sysmaps'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $subSysmaps = zbx_toHash($subSysmaps, 'sysmapid');
        foreach ($elems['sysmaps'] as $elem) {
            $info[$elem['selementid']]['name'] = $subSysmaps[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['hostgroups']) && $hglabel) {
        $hostgroups = API::HostGroup()->get(array('groupids' => zbx_objectValues($elems['hostgroups'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $hostgroups = zbx_toHash($hostgroups, 'groupid');
        foreach ($elems['hostgroups'] as $elem) {
            $info[$elem['selementid']]['name'] = $hostgroups[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['triggers']) && $tlabel) {
        foreach ($elems['triggers'] as $elem) {
            $info[$elem['selementid']]['name'] = CMacrosResolverHelper::resolveTriggerName($allTriggers[$elem['elementid']]);
        }
    }
    if (!empty($elems['hosts']) && $hlabel) {
        foreach ($elems['hosts'] as $elem) {
            $info[$elem['selementid']]['name'] = $allHosts[$elem['elementid']]['name'];
        }
    }
    return $info;
}
Beispiel #24
0
 /**
  * Update map.
  *
  * @param array  $maps						multidimensional array with Hosts data
  * @param string $maps['sysmapid']
  * @param string $maps['name']
  * @param array  $maps['width']
  * @param int    $maps['height']
  * @param string $maps['backgroundid']
  * @param array  $maps['label_type']
  * @param int    $maps['label_location']
  * @param int    $maps['grid_size']			size of one grid cell. 100 refers to 100x100 and so on.
  * @param int    $maps['grid_show']			does grid need to be shown. Constants: SYSMAP_GRID_SHOW_ON / SYSMAP_GRID_SHOW_OFF
  * @param int    $maps['grid_align']		do elements need to be aligned to the grid. Constants: SYSMAP_GRID_ALIGN_ON / SYSMAP_GRID_ALIGN_OFF
  *
  * @return array
  */
 public function update(array $maps)
 {
     $maps = zbx_toArray($maps);
     $sysmapIds = zbx_objectValues($maps, 'sysmapid');
     $dbMaps = $this->checkInput($maps, __FUNCTION__);
     $updateMaps = array();
     $urlIdsToDelete = $urlsToUpdate = $urlsToAdd = array();
     $selementsToDelete = $selementsToUpdate = $selementsToAdd = array();
     $linksToDelete = $linksToUpdate = $linksToAdd = array();
     foreach ($maps as $map) {
         $updateMaps[] = array('values' => $map, 'where' => array('sysmapid' => $map['sysmapid']));
         $dbMap = $dbMaps[$map['sysmapid']];
         // urls
         if (isset($map['urls'])) {
             $urlDiff = zbx_array_diff($map['urls'], $dbMap['urls'], 'name');
             foreach ($urlDiff['both'] as $updateUrl) {
                 $urlsToUpdate[] = array('values' => $updateUrl, 'where' => array('name' => $updateUrl['name'], 'sysmapid' => $map['sysmapid']));
             }
             foreach ($urlDiff['first'] as $newUrl) {
                 $newUrl['sysmapid'] = $map['sysmapid'];
                 $urlsToAdd[] = $newUrl;
             }
             $urlIdsToDelete = array_merge($urlIdsToDelete, zbx_objectValues($urlDiff['second'], 'sysmapurlid'));
         }
         // elements
         if (isset($map['selements'])) {
             $selementDiff = zbx_array_diff($map['selements'], $dbMap['selements'], 'selementid');
             // we need sysmapid for add operations
             foreach ($selementDiff['first'] as $newSelement) {
                 $newSelement['sysmapid'] = $map['sysmapid'];
                 $selementsToAdd[] = $newSelement;
             }
             $selementsToUpdate = array_merge($selementsToUpdate, $selementDiff['both']);
             $selementsToDelete = array_merge($selementsToDelete, $selementDiff['second']);
         }
         // links
         if (isset($map['links'])) {
             $linkDiff = zbx_array_diff($map['links'], $dbMap['links'], 'linkid');
             // we need sysmapId for add operations
             foreach ($linkDiff['first'] as $newLink) {
                 $newLink['sysmapid'] = $map['sysmapid'];
                 $linksToAdd[] = $newLink;
             }
             $linksToUpdate = array_merge($linksToUpdate, $linkDiff['both']);
             $linksToDelete = array_merge($linksToDelete, $linkDiff['second']);
         }
     }
     DB::update('sysmaps', $updateMaps);
     // urls
     DB::insert('sysmap_url', $urlsToAdd);
     DB::update('sysmap_url', $urlsToUpdate);
     if ($urlIdsToDelete) {
         DB::delete('sysmap_url', array('sysmapurlid' => $urlIdsToDelete));
     }
     // selements
     $newSelementIds = array('selementids' => array());
     if ($selementsToAdd) {
         $newSelementIds = $this->createSelements($selementsToAdd);
     }
     if ($selementsToUpdate) {
         $this->updateSelements($selementsToUpdate);
     }
     if ($selementsToDelete) {
         $this->deleteSelements($selementsToDelete);
     }
     // links
     if ($linksToAdd || $linksToUpdate) {
         $selementsNames = array();
         foreach ($newSelementIds['selementids'] as $key => $selementId) {
             $selementsNames[$selementsToAdd[$key]['selementid']] = $selementId;
         }
         foreach ($selementsToUpdate as $selement) {
             $selementsNames[$selement['selementid']] = $selement['selementid'];
         }
         foreach ($linksToAdd as $key => $link) {
             if (isset($selementsNames[$link['selementid1']])) {
                 $linksToAdd[$key]['selementid1'] = $selementsNames[$link['selementid1']];
             }
             if (isset($selementsNames[$link['selementid2']])) {
                 $linksToAdd[$key]['selementid2'] = $selementsNames[$link['selementid2']];
             }
         }
         foreach ($linksToUpdate as $key => $link) {
             if (isset($selementsNames[$link['selementid1']])) {
                 $linksToUpdate[$key]['selementid1'] = $selementsNames[$link['selementid1']];
             }
             if (isset($selementsNames[$link['selementid2']])) {
                 $linksToUpdate[$key]['selementid2'] = $selementsNames[$link['selementid2']];
             }
         }
         unset($selementsNames);
     }
     $newLinkIds = $updateLinkIds = array('linkids' => array());
     if ($linksToAdd) {
         $newLinkIds = $this->createLinks($linksToAdd);
     }
     if ($linksToUpdate) {
         $updateLinkIds = $this->updateLinks($linksToUpdate);
     }
     if ($linksToDelete) {
         $this->deleteLinks($linksToDelete);
     }
     // link triggers
     $linkTriggersToDelete = $linkTriggersToUpdate = $linkTriggersToAdd = array();
     foreach ($newLinkIds['linkids'] as $key => $linkId) {
         if (!isset($linksToAdd[$key]['linktriggers'])) {
             continue;
         }
         foreach ($linksToAdd[$key]['linktriggers'] as $linkTrigger) {
             $linkTrigger['linkid'] = $linkId;
             $linkTriggersToAdd[] = $linkTrigger;
         }
     }
     $dbLinks = array();
     $linkTriggerResource = DBselect('SELECT slt.* FROM sysmaps_link_triggers slt WHERE ' . dbConditionInt('slt.linkid', $updateLinkIds['linkids']));
     while ($dbLinkTrigger = DBfetch($linkTriggerResource)) {
         zbx_subarray_push($dbLinks, $dbLinkTrigger['linkid'], $dbLinkTrigger);
     }
     foreach ($updateLinkIds['linkids'] as $key => $linkId) {
         if (!isset($linksToUpdate[$key]['linktriggers'])) {
             continue;
         }
         $dbLinkTriggers = isset($dbLinks[$linkId]) ? $dbLinks[$linkId] : array();
         $dbLinkTriggersDiff = zbx_array_diff($linksToUpdate[$key]['linktriggers'], $dbLinkTriggers, 'linktriggerid');
         foreach ($dbLinkTriggersDiff['first'] as $newLinkTrigger) {
             $newLinkTrigger['linkid'] = $linkId;
             $linkTriggersToAdd[] = $newLinkTrigger;
         }
         $linkTriggersToUpdate = array_merge($linkTriggersToUpdate, $dbLinkTriggersDiff['both']);
         $linkTriggersToDelete = array_merge($linkTriggersToDelete, $dbLinkTriggersDiff['second']);
     }
     if ($linkTriggersToDelete) {
         $this->deleteLinkTriggers($linkTriggersToDelete);
     }
     if ($linkTriggersToAdd) {
         $this->createLinkTriggers($linkTriggersToAdd);
     }
     if ($linkTriggersToUpdate) {
         $this->updateLinkTriggers($linkTriggersToUpdate);
     }
     return array('sysmapids' => $sysmapIds);
 }
Beispiel #25
0
/**
 * Create and return a DIV with web monitoring overview.
 *
 * @param array $filter
 * @param array $filter['groupids']
 * @param bool  $filter['maintenance']
 *
 * @return CDiv
 */
function make_webmon_overview($filter)
{
    $groups = API::HostGroup()->get(array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'output' => array('groupid', 'name'), 'preservekeys' => true));
    foreach ($groups as &$group) {
        $group['nodename'] = get_node_name_by_elid($group['groupid']);
    }
    unset($group);
    CArrayHelper::sort($groups, array(array('field' => 'nodename', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP)));
    $groupIds = array_keys($groups);
    $availableHosts = API::Host()->get(array('groupids' => $groupIds, 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid'), 'preservekeys' => true));
    $availableHostIds = array_keys($availableHosts);
    $table = new CTableInfo(_('No web scenarios found.'));
    $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host group'), _('Ok'), _('Failed'), _('Unknown')));
    $data = array();
    // fetch links between HTTP tests and host groups
    $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds)));
    // fetch HTTP test execution data
    $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid'));
    foreach ($result as $row) {
        if (!isset($httpTestData[$row['httptestid']])) {
            $data[$row['groupid']]['unknown'] = empty($data[$row['groupid']]['unknown']) ? 1 : ++$data[$row['groupid']]['unknown'];
        } elseif ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) {
            $data[$row['groupid']]['failed'] = empty($data[$row['groupid']]['failed']) ? 1 : ++$data[$row['groupid']]['failed'];
        } else {
            $data[$row['groupid']]['ok'] = empty($data[$row['groupid']]['ok']) ? 1 : ++$data[$row['groupid']]['ok'];
        }
    }
    foreach ($groups as $group) {
        if (!empty($data[$group['groupid']])) {
            $table->addRow(array(is_show_all_nodes() ? $group['nodename'] : null, $group['name'], new CSpan(empty($data[$group['groupid']]['ok']) ? 0 : $data[$group['groupid']]['ok'], 'off'), new CSpan(empty($data[$group['groupid']]['failed']) ? 0 : $data[$group['groupid']]['failed'], empty($data[$group['groupid']]['failed']) ? 'off' : 'on'), new CSpan(empty($data[$group['groupid']]['unknown']) ? 0 : $data[$group['groupid']]['unknown'], 'unknown')));
        }
    }
    $script = new CJSScript(get_js("jQuery('#hat_webovr_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')"));
    return new CDiv(array($table, $script));
}
Beispiel #26
0
    foreach ($triggers as $tnum => $trigger) {
        $options = array('countOutput' => 1, 'triggerids' => $trigger['triggerid'], 'object' => EVENT_OBJECT_TRIGGER, 'acknowledged' => 0, 'value' => TRIGGER_VALUE_TRUE, 'nopermissions' => 1);
        $triggers[$tnum]['event_count'] = CEvent::get($options);
    }
}
$tr_hostids = array();
foreach ($triggers as $tnum => $trigger) {
    $triggers[$tnum]['events'] = array();
    //getting all host ids and names
    foreach ($trigger['hosts'] as $tr_hosts) {
        $tr_hostids[$tr_hosts['hostid']] = $tr_hosts['hostid'];
    }
}
$scripts_by_hosts = Cscript::getScriptsByHosts($tr_hostids);
if ($show_events != EVENTS_OPTION_NOEVENT) {
    $ev_options = array('nodeids' => get_current_nodeid(), 'triggerids' => zbx_objectValues($triggers, 'triggerid'), 'nopermissions' => 1, 'output' => API_OUTPUT_EXTEND, 'time_from' => time() - $config['event_expire'] * 86400, 'time_till' => time(), 'sortfield' => 'eventid', 'sortorder' => ZBX_SORT_DOWN);
    switch ($show_events) {
        case EVENTS_OPTION_ALL:
            break;
        case EVENTS_OPTION_NOT_ACK:
            $ev_options['acknowledged'] = 0;
            $ev_options['value'] = TRIGGER_VALUE_TRUE;
            break;
    }
    $events = CEvent::get($ev_options);
    order_result($events, 'clock', ZBX_SORT_DOWN);
    foreach ($events as $enum => $event) {
        $triggers[$event['objectid']]['events'][] = $event;
    }
}
foreach ($triggers as $tnum => $trigger) {
Beispiel #27
0
 /**
  * Update scripts.
  *
  * @param array $scripts
  * @param array $scripts['name']
  * @param array $scripts['hostid']
  *
  * @return array
  */
 public function update(array $scripts)
 {
     $scripts = zbx_toArray($scripts);
     $this->validateUpdate($scripts);
     $scripts = $this->trimMenuPath($scripts);
     $this->validateMenuPath($scripts, __FUNCTION__);
     $scripts = $this->unsetExecutionType($scripts);
     $update = array();
     foreach ($scripts as $script) {
         $scriptId = $script['scriptid'];
         unset($script['scriptid']);
         $update[] = array('values' => $script, 'where' => array('scriptid' => $scriptId));
     }
     DB::update('scripts', $update);
     return array('scriptids' => zbx_objectValues($scripts, 'scriptid'));
 }
Beispiel #28
0
 /**
  * Fetches the fields given in $fields from the database and extends the objects with the loaded data.
  *
  * @param string $tableName
  * @param array  $objects
  * @param array  $fields
  *
  * @return array
  */
 protected function extendObjects($tableName, array $objects, array $fields)
 {
     if ($objects) {
         $dbObjects = API::getApiService()->select($tableName, ['output' => $fields, $this->pkOption($tableName) => zbx_objectValues($objects, $this->pk($tableName)), 'preservekeys' => true]);
         foreach ($objects as &$object) {
             $pk = $object[$this->pk($tableName)];
             if (isset($dbObjects[$pk])) {
                 check_db_fields($dbObjects[$pk], $object);
             }
         }
         unset($object);
     }
     return $objects;
 }
Beispiel #29
0
$httpmon_wdgt->addHeader(_('Web scenarios'), $r_form);
$httpmon_wdgt->addHeaderRowNumber();
// TABLE
$table = new CTableInfo(_('No web scenarios found.'));
$table->SetHeader(array($displayNodes ? _('Node') : null, $_REQUEST['hostid'] == 0 ? make_sorting_header(_('Host'), 'hostname') : null, make_sorting_header(_('Name'), 'name'), _('Number of steps'), _('Last check'), _('Status')));
$paging = null;
if ($pageFilter->hostsSelected) {
    $options = array('output' => array('httptestid'), 'templated' => false, 'filter' => array('status' => HTTPTEST_STATUS_ACTIVE), 'limit' => $config['search_limit'] + 1);
    if ($pageFilter->hostid > 0) {
        $options['hostids'] = $pageFilter->hostid;
    } elseif ($pageFilter->groupid > 0) {
        $options['groupids'] = $pageFilter->groupid;
    }
    $httpTests = API::HttpTest()->get($options);
    $paging = getPagingLine($httpTests);
    $httpTests = API::HttpTest()->get(array('httptestids' => zbx_objectValues($httpTests, 'httptestid'), 'preservekeys' => true, 'output' => API_OUTPUT_EXTEND, 'selectHosts' => array('name', 'status'), 'selectSteps' => API_OUTPUT_COUNT));
    foreach ($httpTests as &$httpTest) {
        $httpTest['host'] = reset($httpTest['hosts']);
        $httpTest['hostname'] = $httpTest['host']['name'];
        unset($httpTest['hosts']);
    }
    unset($httpTest);
    $httpTests = resolveHttpTestMacros($httpTests, true, false);
    order_result($httpTests, getPageSortField('name'), getPageSortOrder());
    // fetch the latest results of the web scenario
    $lastHttpTestData = Manager::HttpTest()->getLastData(array_keys($httpTests));
    foreach ($httpTests as $httpTest) {
        $lastData = isset($lastHttpTestData[$httpTest['httptestid']]) ? $lastHttpTestData[$httpTest['httptestid']] : null;
        // test has history data
        if ($lastData) {
            $lastcheck = zbx_date2str(_('d M Y H:i:s'), $lastData['lastcheck']);
 /**
  * Get screens that don't have screen items that reference not existing screen i.e. screen items references can be resolved.
  * Returns array with screen names.
  *
  * @param array $screens
  *
  * @return array
  */
 protected function getIndependentScreens(array $screens)
 {
     foreach ($screens as $num => $screen) {
         if (empty($screen['screenitems'])) {
             continue;
         }
         foreach ($screen['screenitems'] as $screenItem) {
             if ($screenItem['resourcetype'] == SCREEN_RESOURCE_SCREEN) {
                 if (!$this->referencer->resolveScreen($screenItem['resource']['name'])) {
                     unset($screens[$num]);
                     continue 2;
                 }
             }
         }
     }
     return zbx_objectValues($screens, 'name');
 }