Ejemplo n.º 1
1
 public function bodyToString()
 {
     $this->cleanItems();
     $total = 0;
     // fetch accessible host ids
     $hosts = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'output' => array('hostid'), 'preservekeys' => true));
     $hostIds = array_keys($hosts);
     if (remove_nodes_from_id($this->groupid) > 0) {
         $cond_from = ',hosts_groups hg';
         $cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->groupid);
     } else {
         $cond_from = '';
         $cond_where = andDbNode('h.hostid', $this->nodeid);
     }
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $avail = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $notav = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $uncn = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $node = get_node_by_nodeid($this->nodeid);
     $header_str = _('Hosts info') . SPACE;
     if ($node > 0) {
         $header_str .= '(' . $node['name'] . ')' . SPACE;
     }
     if (remove_nodes_from_id($this->groupid) > 0) {
         $group = get_hostgroup_by_groupid($this->groupid);
         $header_str .= _('Group') . SPACE . '"' . $group['name'] . '"';
     } else {
         $header_str .= _('All groups');
     }
     $header = new CCol($header_str, 'header');
     if ($this->style == STYLE_HORISONTAL) {
         $header->setColspan(4);
     }
     $this->addRow($header);
     $avail = new CCol($avail . '  ' . _('Available'), 'avail');
     $notav = new CCol($notav . '  ' . _('Not available'), 'notav');
     $uncn = new CCol($uncn . '  ' . _('Unknown'), 'uncn');
     $total = new CCol($total . '  ' . _('Total'), 'total');
     if ($this->style == STYLE_HORISONTAL) {
         $this->addRow(array($avail, $notav, $uncn, $total));
     } else {
         $this->addRow($avail);
         $this->addRow($notav);
         $this->addRow($uncn);
         $this->addRow($total);
     }
     return parent::bodyToString();
 }
Ejemplo n.º 2
0
function get_events_unacknowledged($db_element, $value_trigger = null, $value_event = null, $ack = false)
{
    $elements = array('hosts' => array(), 'hosts_groups' => array(), 'triggers' => array());
    get_map_elements($db_element, $elements);
    if (empty($elements['hosts_groups']) && empty($elements['hosts']) && empty($elements['triggers'])) {
        return 0;
    }
    $config = select_config();
    $options = array('nodeids' => get_current_nodeid(), 'output' => API_OUTPUT_SHORTEN, 'monitored' => 1, 'skipDependent' => 1, 'limit' => $config['search_limit'] + 1);
    if (!is_null($value_trigger)) {
        $options['filter'] = array('value' => $value_trigger);
    }
    if (!empty($elements['hosts_groups'])) {
        $options['groupids'] = array_unique($elements['hosts_groups']);
    }
    if (!empty($elements['hosts'])) {
        $options['hostids'] = array_unique($elements['hosts']);
    }
    if (!empty($elements['triggers'])) {
        $options['triggerids'] = array_unique($elements['triggers']);
    }
    $triggerids = CTrigger::get($options);
    $options = array('countOutput' => 1, 'triggerids' => zbx_objectValues($triggerids, 'triggerid'), 'object' => EVENT_OBJECT_TRIGGER, 'acknowledged' => $ack ? 1 : 0, 'value' => is_null($value_event) ? array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE) : $value_event, 'nopermissions' => 1);
    $event_count = CEvent::get($options);
    return $event_count;
}
Ejemplo n.º 3
0
function slideshow_accessible($slideshowid, $perm)
{
    $result = false;
    $sql = 'SELECT s.slideshowid' . ' FROM slideshows s' . ' WHERE s.slideshowid=' . zbx_dbstr($slideshowid) . andDbNode('s.slideshowid', get_current_nodeid(null, $perm));
    if (DBselect($sql)) {
        $result = true;
        $screenids = array();
        $db_screens = DBselect('SELECT DISTINCT s.screenid' . ' FROM slides s' . ' WHERE s.slideshowid=' . zbx_dbstr($slideshowid));
        while ($slide_data = DBfetch($db_screens)) {
            $screenids[$slide_data['screenid']] = $slide_data['screenid'];
        }
        $options = array('screenids' => $screenids);
        if ($perm == PERM_READ_WRITE) {
            $options['editable'] = true;
        }
        $screens = API::Screen()->get($options);
        $screens = zbx_toHash($screens, 'screenid');
        foreach ($screenids as $screenid) {
            if (!isset($screens[$screenid])) {
                return false;
            }
        }
    }
    return $result;
}
Ejemplo n.º 4
0
function getImageByIdent($ident)
{
    zbx_value2array($ident);
    if (!isset($ident['name'])) {
        return 0;
    }
    static $images;
    if (is_null($images)) {
        $images = array();
        $dbImages = API::Image()->get(array('output' => array('imageid', 'name'), 'nodeids' => get_current_nodeid(true)));
        foreach ($dbImages as $image) {
            if (!isset($images[$image['name']])) {
                $images[$image['name']] = array();
            }
            $nodeName = get_node_name_by_elid($image['imageid'], true);
            if (!is_null($nodeName)) {
                $images[$image['name']][$nodeName] = $image;
            } else {
                $images[$image['name']][] = $image;
            }
        }
    }
    $ident['name'] = trim($ident['name'], ' ');
    if (!isset($images[$ident['name']])) {
        return 0;
    }
    $searchedImages = $images[$ident['name']];
    if (!isset($ident['node'])) {
        return reset($searchedImages);
    } elseif (isset($searchedImages[$ident['node']])) {
        return $searchedImages[$ident['node']];
    } else {
        return 0;
    }
}
Ejemplo n.º 5
0
 /**
  * Initializes nodes.
  *
  * @static
  */
 public static function init()
 {
     global $ZBX_LOCALNODEID;
     if (is_null(self::$nodeId)) {
         self::$nodeId = get_current_nodeid(false);
         self::$minNodeId = bcadd(bcmul(self::$nodeId, '100000000000000'), bcmul($ZBX_LOCALNODEID, '100000000000'), 0);
         self::$maxNodeId = bcadd(self::$minNodeId, '99999999999', 0);
     }
 }
Ejemplo n.º 6
0
 public function bodyToString()
 {
     global $USER_DETAILS;
     $this->cleanItems();
     $total = 0;
     $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
     $cond_from = '';
     if (remove_nodes_from_id($this->groupid) > 0) {
         $cond_from = ', hosts_groups hg ';
         $cond_where = 'AND hg.hostid=h.hostid AND hg.groupid=' . $this->groupid;
     } else {
         $cond_where = ' AND ' . DBin_node('h.hostid', $this->nodeid);
     }
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $avail = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $notav = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $uncn = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $node = get_node_by_nodeid($this->nodeid);
     $header_str = S_HOSTS_INFO . SPACE;
     $header_str .= S_FOR_GROUP_SMALL . SPACE . '"';
     if ($node > 0) {
         $header_str .= '(' . $node['name'] . ')' . SPACE;
     }
     if (remove_nodes_from_id($this->groupid) > 0) {
         $group = get_hostgroup_by_groupid($this->groupid);
         $header_str .= $group['name'] . '"';
     } else {
         $header_str .= S_ALL_S . '"';
     }
     $header = new CCol($header_str, "header");
     if ($this->style == STYLE_HORISONTAL) {
         $header->SetColspan(4);
     }
     $this->addRow($header);
     $avail = new CCol($avail . '  ' . S_AVAILABLE, 'avail');
     $notav = new CCol($notav . '  ' . S_NOT_AVAILABLE, 'notav');
     $uncn = new CCol($uncn . '  ' . S_UNKNOWN, 'uncn');
     $total = new CCol($total . '  ' . S_TOTAL, 'total');
     if ($this->style == STYLE_HORISONTAL) {
         $this->addRow(array($avail, $notav, $uncn, $total));
     } else {
         $this->addRow($avail);
         $this->addRow($notav);
         $this->addRow($uncn);
         $this->addRow($total);
     }
     return parent::bodyToString();
 }
Ejemplo n.º 7
0
function get_events_unacknowledged($db_element, $value_trigger = null, $value_event = null, $ack = false)
{
    $elements = array('hosts' => array(), 'hosts_groups' => array(), 'triggers' => array());
    get_map_elements($db_element, $elements);
    if (empty($elements['hosts_groups']) && empty($elements['hosts']) && empty($elements['triggers'])) {
        return 0;
    }
    $config = select_config();
    $options = array('nodeids' => get_current_nodeid(), 'output' => array('triggerid'), 'monitored' => 1, 'skipDependent' => 1, 'limit' => $config['search_limit'] + 1);
    if (!is_null($value_trigger)) {
        $options['filter'] = array('value' => $value_trigger);
    }
    if (!empty($elements['hosts_groups'])) {
        $options['groupids'] = array_unique($elements['hosts_groups']);
    }
    if (!empty($elements['hosts'])) {
        $options['hostids'] = array_unique($elements['hosts']);
    }
    if (!empty($elements['triggers'])) {
        $options['triggerids'] = array_unique($elements['triggers']);
    }
    $triggerids = API::Trigger()->get($options);
    return API::Event()->get(array('source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'countOutput' => true, 'objectids' => zbx_objectValues($triggerids, 'triggerid'), 'filter' => array('value' => $value_event, 'acknowledged' => $ack ? 1 : 0)));
}
Ejemplo n.º 8
0
function sysmap_accessible($sysmapid, $perm)
{
    global $USER_DETAILS;
    $nodes = get_current_nodeid(null, $perm);
    $result = (bool) count($nodes);
    $sql = 'SELECT * ' . ' FROM sysmaps_elements ' . ' WHERE sysmapid=' . $sysmapid . ' AND ' . DBin_node('sysmapid', $nodes);
    $db_result = DBselect($sql);
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
    //SDI($available_hosts);
    while (($se_data = DBfetch($db_result)) && $result) {
        switch ($se_data['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_HOST:
                if (!isset($available_hosts[$se_data['elementid']])) {
                    $result = false;
                }
                break;
            case SYSMAP_ELEMENT_TYPE_MAP:
                $result = sysmap_accessible($se_data['elementid'], $perm);
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $available_triggers = get_accessible_triggers($perm, array(), PERM_RES_IDS_ARRAY);
                if (!isset($available_triggers[$se_data['elementid']])) {
                    $result = false;
                }
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $available_groups = get_accessible_groups_by_user($USER_DETAILS, $perm);
                if (!isset($available_groups[$se_data['elementid']])) {
                    $result = false;
                }
                break;
        }
    }
    //SDI($se_data['elementid']);
    return $result;
}
Ejemplo n.º 9
0
function make_hoststat_summary($filter)
{
    $table = new CTableInfo(_('No host groups found.'));
    $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host group'), _('Without problems'), _('With problems'), _('Total')));
    // get host groups
    $groups = API::HostGroup()->get(array('nodeids' => get_current_nodeid(), 'groupids' => $filter['groupids'], 'monitored_hosts' => 1, 'output' => array('groupid', 'name')));
    $groups = zbx_toHash($groups, 'groupid');
    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)));
    // get hosts
    $hosts = API::Host()->get(array('nodeids' => get_current_nodeid(), 'groupids' => zbx_objectValues($groups, 'groupid'), 'hostids' => !empty($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid', 'name'), 'selectGroups' => array('groupid')));
    $hosts = zbx_toHash($hosts, 'hostid');
    CArrayHelper::sort($hosts, array('name'));
    // get triggers
    $triggers = API::Trigger()->get(array('nodeids' => get_current_nodeid(), 'monitored' => true, 'maintenance' => $filter['maintenance'], 'expandData' => true, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'output' => array('triggerid', 'priority'), 'selectHosts' => array('hostid')));
    if ($filter['extAck']) {
        $triggers_unack = API::Trigger()->get(array('nodeids' => get_current_nodeid(), 'monitored' => true, 'maintenance' => $filter['maintenance'], 'withLastEventUnacknowledged' => true, 'selectHosts' => API_OUTPUT_REFER, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'output' => API_OUTPUT_REFER));
        $triggers_unack = zbx_toHash($triggers_unack, 'triggerid');
        foreach ($triggers_unack as $tunack) {
            foreach ($tunack['hosts'] as $unack_host) {
                $hosts_with_unack_triggers[$unack_host['hostid']] = $unack_host['hostid'];
            }
        }
    }
    $hosts_data = array();
    $problematic_host_list = array();
    $lastUnack_host_list = array();
    $highest_severity = array();
    $highest_severity2 = array();
    foreach ($triggers as $trigger) {
        foreach ($trigger['hosts'] as $trigger_host) {
            if (!isset($hosts[$trigger_host['hostid']])) {
                continue;
            } else {
                $host = $hosts[$trigger_host['hostid']];
            }
            if ($filter['extAck'] && isset($hosts_with_unack_triggers[$host['hostid']])) {
                if (!isset($lastUnack_host_list[$host['hostid']])) {
                    $lastUnack_host_list[$host['hostid']] = array();
                    $lastUnack_host_list[$host['hostid']]['host'] = $host['name'];
                    $lastUnack_host_list[$host['hostid']]['hostid'] = $host['hostid'];
                    $lastUnack_host_list[$host['hostid']]['severities'] = array();
                    $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_DISASTER] = 0;
                    $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_HIGH] = 0;
                    $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_AVERAGE] = 0;
                    $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_WARNING] = 0;
                    $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_INFORMATION] = 0;
                    $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0;
                }
                if (isset($triggers_unack[$trigger['triggerid']])) {
                    $lastUnack_host_list[$host['hostid']]['severities'][$trigger['priority']]++;
                }
                foreach ($host['groups'] as $gnum => $group) {
                    if (!isset($highest_severity2[$group['groupid']])) {
                        $highest_severity2[$group['groupid']] = 0;
                    }
                    if ($trigger['priority'] > $highest_severity2[$group['groupid']]) {
                        $highest_severity2[$group['groupid']] = $trigger['priority'];
                    }
                    if (!isset($hosts_data[$group['groupid']])) {
                        $hosts_data[$group['groupid']] = array('problematic' => 0, 'ok' => 0, 'lastUnack' => 0, 'hostids_all' => array(), 'hostids_unack' => array());
                    }
                    if (!isset($hosts_data[$group['groupid']]['hostids_unack'][$host['hostid']])) {
                        $hosts_data[$group['groupid']]['hostids_unack'][$host['hostid']] = $host['hostid'];
                        $hosts_data[$group['groupid']]['lastUnack']++;
                    }
                }
            }
            if (!isset($problematic_host_list[$host['hostid']])) {
                $problematic_host_list[$host['hostid']] = array();
                $problematic_host_list[$host['hostid']]['host'] = $host['name'];
                $problematic_host_list[$host['hostid']]['hostid'] = $host['hostid'];
                $problematic_host_list[$host['hostid']]['severities'] = array();
                $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_DISASTER] = 0;
                $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_HIGH] = 0;
                $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_AVERAGE] = 0;
                $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_WARNING] = 0;
                $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_INFORMATION] = 0;
                $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0;
            }
            $problematic_host_list[$host['hostid']]['severities'][$trigger['priority']]++;
            foreach ($host['groups'] as $gnum => $group) {
                if (!isset($highest_severity[$group['groupid']])) {
                    $highest_severity[$group['groupid']] = 0;
                }
                if ($trigger['priority'] > $highest_severity[$group['groupid']]) {
                    $highest_severity[$group['groupid']] = $trigger['priority'];
                }
                if (!isset($hosts_data[$group['groupid']])) {
                    $hosts_data[$group['groupid']] = array('problematic' => 0, 'ok' => 0, 'lastUnack' => 0, 'hostids_all' => array(), 'hostids_unack' => array());
                }
                if (!isset($hosts_data[$group['groupid']]['hostids_all'][$host['hostid']])) {
                    $hosts_data[$group['groupid']]['hostids_all'][$host['hostid']] = $host['hostid'];
                    $hosts_data[$group['groupid']]['problematic']++;
                }
            }
        }
    }
    foreach ($hosts as $host) {
        foreach ($host['groups'] as $group) {
            if (!isset($groups[$group['groupid']])) {
                continue;
            }
            if (!isset($groups[$group['groupid']]['hosts'])) {
                $groups[$group['groupid']]['hosts'] = array();
            }
            $groups[$group['groupid']]['hosts'][$host['hostid']] = array('hostid' => $host['hostid']);
            if (!isset($highest_severity[$group['groupid']])) {
                $highest_severity[$group['groupid']] = 0;
            }
            if (!isset($hosts_data[$group['groupid']])) {
                $hosts_data[$group['groupid']] = array('problematic' => 0, 'ok' => 0, 'lastUnack' => 0);
            }
            if (!isset($problematic_host_list[$host['hostid']])) {
                $hosts_data[$group['groupid']]['ok']++;
            }
        }
    }
    foreach ($groups as $group) {
        if (!isset($hosts_data[$group['groupid']])) {
            continue;
        }
        $group_row = new CRow();
        if (is_show_all_nodes()) {
            $group_row->addItem($group['nodename']);
        }
        $name = new CLink($group['name'], 'tr_status.php?groupid=' . $group['groupid'] . '&hostid=0&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE);
        $group_row->addItem($name);
        $group_row->addItem(new CCol($hosts_data[$group['groupid']]['ok'], 'normal'));
        if ($filter['extAck']) {
            if ($hosts_data[$group['groupid']]['lastUnack']) {
                $table_inf = new CTableInfo();
                $table_inf->setAttribute('style', 'width: 400px;');
                $table_inf->setHeader(array(_('Host'), is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? getSeverityCaption(TRIGGER_SEVERITY_DISASTER) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? getSeverityCaption(TRIGGER_SEVERITY_HIGH) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? getSeverityCaption(TRIGGER_SEVERITY_AVERAGE) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? getSeverityCaption(TRIGGER_SEVERITY_WARNING) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? getSeverityCaption(TRIGGER_SEVERITY_INFORMATION) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED) : null));
                $popup_rows = 0;
                foreach ($group['hosts'] as $host) {
                    $hostid = $host['hostid'];
                    if (!isset($lastUnack_host_list[$hostid])) {
                        continue;
                    }
                    if ($popup_rows >= ZBX_WIDGET_ROWS) {
                        break;
                    }
                    $popup_rows++;
                    $host_data = $lastUnack_host_list[$hostid];
                    $r = new CRow();
                    $r->addItem(new CLink($host_data['host'], 'tr_status.php?groupid=' . $group['groupid'] . '&hostid=' . $hostid . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE));
                    foreach ($lastUnack_host_list[$host['hostid']]['severities'] as $severity => $trigger_count) {
                        if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) {
                            continue;
                        }
                        $r->addItem(new CCol($trigger_count, getSeverityStyle($severity, $trigger_count)));
                    }
                    $table_inf->addRow($r);
                }
                $lastUnack_count = new CSpan($hosts_data[$group['groupid']]['lastUnack'], 'pointer red bold');
                $lastUnack_count->setHint($table_inf);
            } else {
                $lastUnack_count = 0;
            }
        }
        // if hostgroup contains problematic hosts, hint should be built
        if ($hosts_data[$group['groupid']]['problematic']) {
            $table_inf = new CTableInfo();
            $table_inf->setAttribute('style', 'width: 400px;');
            $table_inf->setHeader(array(_('Host'), is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? getSeverityCaption(TRIGGER_SEVERITY_DISASTER) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? getSeverityCaption(TRIGGER_SEVERITY_HIGH) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? getSeverityCaption(TRIGGER_SEVERITY_AVERAGE) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? getSeverityCaption(TRIGGER_SEVERITY_WARNING) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? getSeverityCaption(TRIGGER_SEVERITY_INFORMATION) : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED) : null));
            $popup_rows = 0;
            foreach ($group['hosts'] as $host) {
                $hostid = $host['hostid'];
                if (!isset($problematic_host_list[$hostid])) {
                    continue;
                }
                if ($popup_rows >= ZBX_WIDGET_ROWS) {
                    break;
                }
                $popup_rows++;
                $host_data = $problematic_host_list[$hostid];
                $r = new CRow();
                $r->addItem(new CLink($host_data['host'], 'tr_status.php?groupid=' . $group['groupid'] . '&hostid=' . $hostid . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE));
                foreach ($problematic_host_list[$host['hostid']]['severities'] as $severity => $trigger_count) {
                    if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) {
                        continue;
                    }
                    $r->addItem(new CCol($trigger_count, getSeverityStyle($severity, $trigger_count)));
                }
                $table_inf->addRow($r);
            }
            $problematic_count = new CSpan($hosts_data[$group['groupid']]['problematic'], 'pointer');
            $problematic_count->setHint($table_inf);
        } else {
            $problematic_count = 0;
        }
        switch ($filter['extAck']) {
            case EXTACK_OPTION_ALL:
                $group_row->addItem(new CCol($problematic_count, getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic'])));
                $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']);
                break;
            case EXTACK_OPTION_UNACK:
                $group_row->addItem(new CCol($lastUnack_count, getSeverityStyle(isset($highest_severity2[$group['groupid']]) ? $highest_severity2[$group['groupid']] : 0, $hosts_data[$group['groupid']]['lastUnack'])));
                $group_row->addItem($hosts_data[$group['groupid']]['lastUnack'] + $hosts_data[$group['groupid']]['ok']);
                break;
            case EXTACK_OPTION_BOTH:
                $unackspan = $lastUnack_count ? new CSpan(array($lastUnack_count, SPACE . _('of') . SPACE)) : null;
                $group_row->addItem(new CCol(array($unackspan, $problematic_count), getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic'])));
                $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']);
                break;
        }
        $table->addRow($group_row);
    }
    $script = new CJSScript(get_js("jQuery('#hat_hoststat_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')"));
    return new CDiv(array($table, $script));
}
Ejemplo n.º 10
0
 /**
  * Get Service data
  *
  * @param _array $options
  * @param array $options['nodeids'] Node IDs
  * @param array $options['groupids'] ServiceGroup IDs
  * @param array $options['hostids'] Service IDs
  * @param boolean $options['monitored_hosts'] only monitored Services
  * @param boolean $options['templated_hosts'] include templates in result
  * @param boolean $options['with_items'] only with items
  * @param boolean $options['with_historical_items'] only with historical items
  * @param boolean $options['with_triggers'] only with triggers
  * @param boolean $options['with_httptests'] only with http tests
  * @param boolean $options['with_graphs'] only with graphs
  * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
  * @param boolean $options['selectGroups'] select ServiceGroups
  * @param boolean $options['selectTemplates'] select Templates
  * @param boolean $options['selectItems'] select Items
  * @param boolean $options['selectTriggers'] select Triggers
  * @param boolean $options['selectGraphs'] select Graphs
  * @param boolean $options['selectApplications'] select Applications
  * @param boolean $options['selectMacros'] select Macros
  * @param int $options['count'] count Services, returned column name is rowscount
  * @param string $options['pattern'] search hosts by pattern in Service name
  * @param string $options['extendPattern'] search hosts by pattern in Service name, ip and DNS
  * @param int $options['limit'] limit selection
  * @param string $options['sortfield'] field to sort by
  * @param string $options['sortorder'] sort order
  * @return array|boolean Service data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $nodeCheck = false;
     $userType = self::$userData['type'];
     // allowed columns for sorting
     $sortColumns = array('dserviceid', 'dhostid', 'ip');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
     $sqlParts = array('select' => array('dservices' => 'ds.dserviceid'), 'from' => array('dservices' => 'dservices ds'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'dserviceids' => null, 'dhostids' => null, 'dcheckids' => null, 'druleids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectDRules' => null, 'selectDHosts' => null, 'selectDChecks' => null, 'selectHosts' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['dservices']);
         $dbTable = DB::getSchema('dservices');
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 's.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if (USER_TYPE_SUPER_ADMIN == $userType) {
     } elseif (is_null($options['editable']) && self::$userData['type'] == USER_TYPE_ZABBIX_ADMIN) {
     } elseif (!is_null($options['editable']) && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
         return array();
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // dserviceids
     if (!is_null($options['dserviceids'])) {
         zbx_value2array($options['dserviceids']);
         $sqlParts['where']['dserviceid'] = dbConditionInt('ds.dserviceid', $options['dserviceids']);
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('ds.dserviceid', $nodeids);
         }
     }
     // dhostids
     if (!is_null($options['dhostids'])) {
         zbx_value2array($options['dhostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['dhostid'] = 'ds.dhostid';
         }
         $sqlParts['where'][] = dbConditionInt('ds.dhostid', $options['dhostids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['dhostid'] = 'ds.dhostid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('ds.dhostid', $nodeids);
         }
     }
     // dcheckids
     if (!is_null($options['dcheckids'])) {
         zbx_value2array($options['dcheckids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['dcheckid'] = 'dc.dcheckid';
         }
         $sqlParts['from']['dhosts'] = 'dhosts dh';
         $sqlParts['from']['dchecks'] = 'dchecks dc';
         $sqlParts['where'][] = dbConditionInt('dc.dcheckid', $options['dcheckids']);
         $sqlParts['where']['dhds'] = 'dh.hostid=ds.hostid';
         $sqlParts['where']['dcdh'] = 'dc.druleid=dh.druleid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['dcheckid'] = 'dc.dcheckid';
         }
     }
     // druleids
     if (!is_null($options['druleids'])) {
         zbx_value2array($options['druleids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['druleid'] = 'dh.druleid';
         }
         $sqlParts['from']['dhosts'] = 'dhosts dh';
         $sqlParts['where']['druleid'] = dbConditionInt('dh.druleid', $options['druleids']);
         $sqlParts['where']['dhds'] = 'dh.dhostid=ds.dhostid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['druleid'] = 'dh.druleid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sqlParts['where'][] = DBin_node('dh.druleid', $nodeids);
         }
     }
     // node check !!!!!
     // should last, after all ****IDS checks
     if (!$nodeCheck) {
         $nodeCheck = true;
         $sqlParts['where'][] = DBin_node('ds.dserviceid', $nodeids);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['dservices'] = 'ds.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(DISTINCT ds.dserviceid) as rowscount');
         //groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sqlParts['group'] as $key => $fields) {
                 $sqlParts['select'][$key] = $fields;
             }
         }
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('dservices ds', $options, $sqlParts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('dservices ds', $options, $sqlParts);
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 'ds');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     //-------
     $dserviceids = array();
     $sqlParts['select'] = array_unique($sqlParts['select']);
     $sqlParts['from'] = array_unique($sqlParts['from']);
     $sqlParts['where'] = array_unique($sqlParts['where']);
     $sqlParts['group'] = array_unique($sqlParts['group']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
     $sqlFrom = '';
     $sqlWhere = '';
     $sqlGroup = '';
     $sqlOrder = '';
     if (!empty($sqlParts['select'])) {
         $sqlSelect .= implode(',', $sqlParts['select']);
     }
     if (!empty($sqlParts['from'])) {
         $sqlFrom .= implode(',', $sqlParts['from']);
     }
     if (!empty($sqlParts['where'])) {
         $sqlWhere .= implode(' AND ', $sqlParts['where']);
     }
     if (!empty($sqlParts['group'])) {
         $sqlWhere .= ' GROUP BY ' . implode(',', $sqlParts['group']);
     }
     if (!empty($sqlParts['order'])) {
         $sqlOrder .= ' ORDER BY ' . implode(',', $sqlParts['order']);
     }
     $sqlLimit = $sqlParts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sqlParts) . ' ' . $sqlSelect . ' FROM ' . $sqlFrom . ' WHERE ' . $sqlWhere . $sqlGroup . $sqlOrder;
     //SDI($sql);
     $res = DBselect($sql, $sqlLimit);
     while ($dservice = DBfetch($res)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $dservice;
             } else {
                 $result = $dservice['rowscount'];
             }
         } else {
             $dserviceids[$dservice['dserviceid']] = $dservice['dserviceid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$dservice['dserviceid']] = array('dserviceid' => $dservice['dserviceid']);
             } else {
                 if (!isset($result[$dservice['dserviceid']])) {
                     $result[$dservice['dserviceid']] = array();
                 }
                 if (!is_null($options['selectDRules']) && !isset($result[$dservice['dserviceid']]['drules'])) {
                     $result[$dservice['dserviceid']]['drules'] = array();
                 }
                 if (!is_null($options['selectDHosts']) && !isset($result[$dservice['dserviceid']]['dhosts'])) {
                     $result[$dservice['dserviceid']]['dhosts'] = array();
                 }
                 if (!is_null($options['selectDChecks']) && !isset($result[$dservice['dserviceid']]['dchecks'])) {
                     $result[$dservice['dserviceid']]['dchecks'] = array();
                 }
                 if (!is_null($options['selectHosts']) && !isset($result[$dservice['dserviceid']]['hosts'])) {
                     $result[$dservice['dserviceid']]['hosts'] = array();
                 }
                 // druleids
                 if (isset($dservice['druleid']) && is_null($options['selectDRules'])) {
                     if (!isset($result[$dservice['dserviceid']]['drules'])) {
                         $result[$dservice['dserviceid']]['drules'] = array();
                     }
                     $result[$dservice['dserviceid']]['drules'][] = array('druleid' => $dservice['druleid']);
                 }
                 // dhostids
                 if (isset($dservice['dhostid']) && is_null($options['selectDHosts'])) {
                     if (!isset($result[$dservice['dserviceid']]['dhosts'])) {
                         $result[$dservice['dserviceid']]['dhosts'] = array();
                     }
                     $result[$dservice['dserviceid']]['dhosts'][] = array('dhostid' => $dservice['dhostid']);
                 }
                 // dcheckids
                 if (isset($dservice['dcheckid']) && is_null($options['selectDChecks'])) {
                     if (!isset($result[$dservice['dserviceid']]['dchecks'])) {
                         $result[$dservice['dserviceid']]['dchecks'] = array();
                     }
                     $result[$dservice['dserviceid']]['dchecks'][] = array('dcheckid' => $dservice['dcheckid']);
                 }
                 $result[$dservice['dserviceid']] += $dservice;
             }
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     // Adding Objects
     // select_drules
     if (!is_null($options['selectDRules'])) {
         $objParams = array('nodeids' => $nodeids, 'dserviceids' => $dserviceids, 'preservekeys' => 1);
         if (is_array($options['selectDRules']) || str_in_array($options['selectDRules'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectDRules'];
             $drules = API::DRule()->get($objParams);
             if (!is_null($options['limitSelects'])) {
                 order_result($drules, 'name');
             }
             foreach ($drules as $druleid => $drule) {
                 unset($drules[$druleid]['dservices']);
                 $count = array();
                 foreach ($drule['dservices'] as $dnum => $dservice) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$dservice['dserviceid']])) {
                             $count[$dservice['dserviceid']] = 0;
                         }
                         $count[$dservice['dserviceid']]++;
                         if ($count[$dservice['dserviceid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$dservice['dserviceid']]['drules'][] =& $drules[$druleid];
                 }
             }
         } elseif (API_OUTPUT_COUNT == $options['selectDRules']) {
             $objParams['countOutput'] = 1;
             $objParams['groupCount'] = 1;
             $drules = API::DRule()->get($objParams);
             $drules = zbx_toHash($drules, 'dserviceid');
             foreach ($result as $dserviceid => $dservice) {
                 if (isset($drules[$dserviceid])) {
                     $result[$dserviceid]['drules'] = $drules[$dserviceid]['rowscount'];
                 } else {
                     $result[$dserviceid]['drules'] = 0;
                 }
             }
         }
     }
     // selectDHosts
     if (!is_null($options['selectDHosts'])) {
         $objParams = array('nodeids' => $nodeids, 'dserviceids' => $dserviceids, 'preservekeys' => 1);
         if (is_array($options['selectDHosts']) || str_in_array($options['selectDHosts'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectDHosts'];
             $dhosts = API::DHost()->get($objParams);
             if (!is_null($options['limitSelects'])) {
                 order_result($dhosts, 'dhostid');
             }
             foreach ($dhosts as $dhostid => $dhost) {
                 unset($dhosts[$dhostid]['dservices']);
                 foreach ($dhost['dservices'] as $snum => $dservice) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$dservice['dserviceid']])) {
                             $count[$dservice['dserviceid']] = 0;
                         }
                         $count[$dservice['dserviceid']]++;
                         if ($count[$dservice['dserviceid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$dservice['dserviceid']]['dhosts'][] =& $dhosts[$dhostid];
                 }
             }
         } elseif (API_OUTPUT_COUNT == $options['selectDHosts']) {
             $objParams['countOutput'] = 1;
             $objParams['groupCount'] = 1;
             $dhosts = API::DHost()->get($objParams);
             $dhosts = zbx_toHash($dhosts, 'dhostid');
             foreach ($result as $dserviceid => $dservice) {
                 if (isset($dhosts[$dserviceid])) {
                     $result[$dserviceid]['dhosts'] = $dhosts[$dserviceid]['rowscount'];
                 } else {
                     $result[$dserviceid]['dhosts'] = 0;
                 }
             }
         }
     }
     // selectHosts
     if (!is_null($options['selectHosts'])) {
         $objParams = array('nodeids' => $nodeids, 'dserviceids' => $dserviceids, 'preservekeys' => 1, 'sortfield' => 'status');
         if (is_array($options['selectHosts']) || str_in_array($options['selectHosts'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectHosts'];
             $hosts = API::Host()->get($objParams);
             if (!is_null($options['limitSelects'])) {
                 order_result($hosts, 'hostid');
             }
             foreach ($hosts as $hostid => $host) {
                 unset($hosts[$hostid]['dservices']);
                 foreach ($host['dservices'] as $dnum => $dservice) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$dservice['dserviceid']])) {
                             $count[$dservice['dserviceid']] = 0;
                         }
                         $count[$dservice['dserviceid']]++;
                         if ($count[$dservice['dserviceid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$dservice['dserviceid']]['hosts'][] =& $hosts[$hostid];
                 }
             }
         } elseif (API_OUTPUT_COUNT == $options['selectHosts']) {
             $objParams['countOutput'] = 1;
             $objParams['groupCount'] = 1;
             $hosts = API::Host()->get($objParams);
             $hosts = zbx_toHash($hosts, 'hostid');
             foreach ($result as $dserviceid => $dservice) {
                 if (isset($hosts[$dserviceid])) {
                     $result[$dserviceid]['hosts'] = $hosts[$dserviceid]['rowscount'];
                 } else {
                     $result[$dserviceid]['hosts'] = 0;
                 }
             }
         }
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Ejemplo n.º 11
0
 /**
  * Get history data
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8.3
  * @version 1.3
  *
  * @param array $options
  * @param array $options['itemids']
  * @param boolean $options['editable']
  * @param string $options['pattern']
  * @param int $options['limit']
  * @param string $options['order']
  * @return array|int item data as array or false if error
  */
 public static function get($options = array())
 {
     global $USER_DETAILS;
     $nodeCheck = false;
     $result = array();
     $sort_columns = array('itemid', 'clock');
     // allowed columns for sorting
     $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     // allowed output options for [ select_* ] params
     $sql_parts = array('select' => array('history' => 'h.itemid'), 'from' => array(), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
     $def_options = array('history' => ITEM_VALUE_TYPE_UINT64, 'nodeids' => null, 'hostids' => null, 'itemids' => null, 'triggerids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'time_from' => null, 'time_till' => null, 'output' => API_OUTPUT_REFER, 'countOutput' => null, 'groupCount' => null, 'groupOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($def_options, $options);
     switch ($options['history']) {
         case ITEM_VALUE_TYPE_LOG:
             $sql_parts['from']['history'] = 'history_log h';
             $sort_columns[] = 'id';
             break;
         case ITEM_VALUE_TYPE_TEXT:
             $sql_parts['from']['history'] = 'history_text h';
             $sort_columns[] = 'id';
             break;
         case ITEM_VALUE_TYPE_STR:
             $sql_parts['from']['history'] = 'history_str h';
             break;
         case ITEM_VALUE_TYPE_UINT64:
             $sql_parts['from']['history'] = 'history_uint h';
             break;
         case ITEM_VALUE_TYPE_FLOAT:
         default:
             $sql_parts['from']['history'] = 'history h';
     }
     // editable + PERMISSION CHECK
     if (USER_TYPE_SUPER_ADMIN == $USER_DETAILS['type'] || $options['nopermissions']) {
     } else {
         $itemOptions = array('editable' => $options['editable'], 'preservekeys' => 1);
         if (!is_null($options['itemids'])) {
             $itemOptions['itemids'] = $options['itemids'];
         }
         $items = CItem::get($itemOptions);
         $options['itemids'] = array_keys($items);
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // itemids
     if (!is_null($options['itemids'])) {
         zbx_value2array($options['itemids']);
         $sql_parts['where']['itemid'] = DBcondition('h.itemid', $options['itemids']);
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('h.itemid', $nodeids);
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['hostid'] = 'i.hostid';
         }
         $sql_parts['from']['items'] = 'items i';
         $sql_parts['where']['i'] = DBcondition('i.hostid', $options['hostids']);
         $sql_parts['where']['hi'] = 'h.itemid=i.itemid';
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('i.hostid', $nodeids);
         }
     }
     // node check !!!!!
     // should be last, after all ****IDS checks
     if (!$nodeCheck) {
         $nodeCheck = true;
         $sql_parts['where'][] = DBin_node('h.itemid', $nodeids);
     }
     // time_from
     if (!is_null($options['time_from'])) {
         $sql_parts['select']['clock'] = 'h.clock';
         $sql_parts['where']['clock_from'] = 'h.clock>=' . $options['time_from'];
     }
     // time_till
     if (!is_null($options['time_till'])) {
         $sql_parts['select']['clock'] = 'h.clock';
         $sql_parts['where']['clock_till'] = 'h.clock<=' . $options['time_till'];
     }
     // filter
     if (is_array($options['filter'])) {
         zbx_db_filter($sql_parts['from']['history'], $options, $sql_parts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search($sql_parts['from']['history'], $options, $sql_parts);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         unset($sql_parts['select']['clock']);
         $sql_parts['select']['history'] = 'h.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sql_parts['select'] = array('count(DISTINCT h.hostid) as rowscount');
         //groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sql_parts['group'] as $key => $fields) {
                 $sql_parts['select'][$key] = $fields;
             }
         }
     }
     // groupOutput
     $groupOutput = false;
     if (!is_null($options['groupOutput'])) {
         if (str_in_array('h.' . $options['groupOutput'], $sql_parts['select']) || str_in_array('h.*', $sql_parts['select'])) {
             $groupOutput = true;
         }
     }
     // order
     // restrict not allowed columns for sorting
     $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
     if (!zbx_empty($options['sortfield'])) {
         $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
         if ($options['sortfield'] == 'clock') {
             $sql_parts['order']['itemid'] = 'h.itemid ' . $sortorder;
         }
         $sql_parts['order'][$options['sortfield']] = 'h.' . $options['sortfield'] . ' ' . $sortorder;
         if (!str_in_array('h.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('h.*', $sql_parts['select'])) {
             $sql_parts['select'][$options['sortfield']] = 'h.' . $options['sortfield'];
         }
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sql_parts['limit'] = $options['limit'];
     }
     //---------------
     $itemids = array();
     $triggerids = array();
     $sql_parts['select'] = array_unique($sql_parts['select']);
     $sql_parts['from'] = array_unique($sql_parts['from']);
     $sql_parts['where'] = array_unique($sql_parts['where']);
     $sql_parts['order'] = array_unique($sql_parts['order']);
     $sql_select = '';
     $sql_from = '';
     $sql_where = '';
     $sql_order = '';
     if (!empty($sql_parts['select'])) {
         $sql_select .= implode(',', $sql_parts['select']);
     }
     if (!empty($sql_parts['from'])) {
         $sql_from .= implode(',', $sql_parts['from']);
     }
     if (!empty($sql_parts['where'])) {
         $sql_where .= implode(' AND ', $sql_parts['where']);
     }
     if (!empty($sql_parts['order'])) {
         $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']);
     }
     $sql_limit = $sql_parts['limit'];
     $sql = 'SELECT ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . $sql_where . $sql_order;
     $db_res = DBselect($sql, $sql_limit);
     //SDI($sql);
     $count = 0;
     $group = array();
     while ($data = DBfetch($db_res)) {
         if ($options['countOutput']) {
             $result = $data;
         } else {
             $itemids[$data['itemid']] = $data['itemid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$count] = array('itemid' => $data['itemid']);
             } else {
                 $result[$count] = array();
                 // hostids
                 if (isset($data['hostid'])) {
                     if (!isset($result[$count]['hosts'])) {
                         $result[$count]['hosts'] = array();
                     }
                     $result[$count]['hosts'][] = array('hostid' => $data['hostid']);
                     unset($data['hostid']);
                 }
                 // triggerids
                 if (isset($data['triggerid'])) {
                     if (!isset($result[$count]['triggers'])) {
                         $result[$count]['triggers'] = array();
                     }
                     $result[$count]['triggers'][] = array('triggerid' => $data['triggerid']);
                     unset($data['triggerid']);
                 }
                 // itemids
                 //					if(isset($data['itemid']) && !is_null($options['itemids'])){
                 //						if(!isset($result[$count]['items'])) $result[$count]['items'] = array();
                 //						$result[$count]['items'][] = array('itemid' => $data['itemid']);
                 //					}
                 $result[$count] += $data;
                 // grouping
                 if ($groupOutput) {
                     $dataid = $data[$options['groupOutput']];
                     if (!isset($group[$dataid])) {
                         $group[$dataid] = array();
                     }
                     $group[$dataid][] = $result[$count];
                 }
                 $count++;
             }
         }
     }
     COpt::memoryPick();
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Ejemplo n.º 12
0
** GNU General Public License for more details.
**
** 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);
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
$items = get_request('items', array());
asort_by_key($items, 'sortorder');
foreach ($items as $gitem) {
    if (!($host = DBfetch(DBselect('SELECT h.* FROM hosts h,items i WHERE h.hostid=i.hostid AND i.itemid=' . $gitem['itemid'])))) {
        fatal_error(S_NO_ITEM_DEFINED);
    }
    if (!isset($available_hosts[$host['hostid']])) {
        access_deny();
    }
}
$effectiveperiod = navigation_bar_calc();
if (count($items) == 1) {
    $_REQUEST['period'] = get_request('period', get_profile('web.item.graph.period', ZBX_PERIOD_DEFAULT, null, $items['itemid']));
    if ($_REQUEST['period'] >= ZBX_MIN_PERIOD) {
        update_profile('web.item.graph.period', $_REQUEST['period'], PROFILE_TYPE_INT, $items['itemid']);
Ejemplo n.º 13
0
    $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);");
}
$dashForm->addRow(S_DASHBOARD_FILTER, $cbFilter);
$dashForm->addVar('groupids', $groupids);
$cmbGroups = new CComboBox('grpswitch', $grpswitch, 'submit();');
$cmbGroups->addItem(0, S_ALL_S);
$cmbGroups->addItem(1, S_SELECTED);
if (!$filterEnable) {
    $cmbGroups->setAttribute('disabled', 'disabled');
}
$dashForm->addRow(S_HOST_GROUPS, $cmbGroups);
if ($grpswitch == 1) {
    $options = array('nodeids' => get_current_nodeid(true), 'groupids' => $groupids, 'output' => API_OUTPUT_EXTEND);
    $groups = CHostGroup::get($options);
    order_result($groups, 'name');
    $lstGroups = new CListBox('del_groups[]', null, 15);
    $lstGroups->setAttribute('style', 'width: 200px;');
    foreach ($groups as $gnum => $group) {
        $lstGroups->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], true, ':') . $group['name']);
    }
    if (!$filterEnable) {
        $lstGroups->setAttribute('disabled', 'disabled');
    }
    $addButton = new CButton('add', S_ADD, "return PopUp('popup_right.php?dstfrm=" . $dashForm->getName() . "&permission=" . PERM_READ_WRITE . "',450,450);");
    if (!$filterEnable) {
        $addButton->setAttribute('disabled', 'disabled');
    }
    $delButton = new CButton('delete', S_DELETE_SELECTED);
Ejemplo n.º 14
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();
}
Ejemplo n.º 15
0
function get_triggers_unacknowledged($db_element, $count_problems = null, $ack = false)
{
    $elements = array('hosts' => array(), 'hosts_groups' => array(), 'triggers' => array());
    get_map_elements($db_element, $elements);
    if (empty($elements['hosts_groups']) && empty($elements['hosts']) && empty($elements['triggers'])) {
        return 0;
    }
    $config = select_config();
    $options = array('nodeids' => get_current_nodeid(), 'monitored' => true, 'countOutput' => true, 'filter' => array(), 'limit' => $config['search_limit'] + 1);
    if ($ack) {
        $options['withAcknowledgedEvents'] = 1;
    } else {
        $options['withUnacknowledgedEvents'] = 1;
    }
    if ($count_problems) {
        $options['filter']['value'] = TRIGGER_VALUE_TRUE;
    }
    if (!empty($elements['hosts_groups'])) {
        $options['groupids'] = array_unique($elements['hosts_groups']);
    }
    if (!empty($elements['hosts'])) {
        $options['hostids'] = array_unique($elements['hosts']);
    }
    if (!empty($elements['triggers'])) {
        $options['triggerids'] = array_unique($elements['triggers']);
    }
    return API::Trigger()->get($options);
}
Ejemplo n.º 16
0
function rm4favorites($favobj, $favid, $favcnt = null, $source = null)
{
    $favorites = get_favorites($favobj, get_current_nodeid(true));
    $favcnt = is_null($favcnt) ? 0 : $favcnt;
    if ($favid == 0) {
        $favcnt = ZBX_FAVORITES_ALL;
    }
    foreach ($favorites as $key => $favorite) {
        if ((bccomp($favid, $favorite['value']) == 0 || $favid == 0) && $favorite['source'] == $source) {
            if ($favcnt < 1) {
                unset($favorites[$key]);
                if ($favcnt > ZBX_FAVORITES_ALL) {
                    break;
                }
                // foreach
            }
        }
        $favcnt--;
    }
    $result = update_profile($favobj, $favorites, PROFILE_TYPE_ARRAY_ID);
    return $result;
}
Ejemplo n.º 17
0
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
$page['file'] = 'chart.php';
$page['type'] = PAGE_TYPE_IMAGE;
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = array('itemid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), 'screenid' => array(T_ZBX_STR, O_OPT, null, null, null), 'period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'profileIdx' => array(T_ZBX_STR, O_OPT, null, null, null), 'profileIdx2' => array(T_ZBX_STR, O_OPT, null, null, null), 'updateProfile' => array(T_ZBX_STR, O_OPT, null, null, null), 'from' => array(T_ZBX_INT, O_OPT, null, '{}>=0', null), 'width' => array(T_ZBX_INT, O_OPT, null, '{}>0', null), 'height' => array(T_ZBX_INT, O_OPT, null, '{}>0', null), 'border' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null));
check_fields($fields);
/*
 * Permissions
 */
if (!DBfetch(DBselect('SELECT i.itemid FROM items i WHERE i.itemid=' . $_REQUEST['itemid']))) {
    show_error_message(_('No items defined.'));
}
$dbItems = API::Item()->get(array('itemids' => $_REQUEST['itemid'], 'webitems' => true, 'nodeids' => get_current_nodeid(true), 'filter' => array('flags' => null)));
if (empty($dbItems)) {
    access_deny();
}
/*
 * Display
 */
$timeline = CScreenBase::calculateTime(array('profileIdx' => get_request('profileIdx', 'web.screens'), 'profileIdx2' => get_request('profileIdx2'), 'updateProfile' => get_request('updateProfile', true), 'period' => get_request('period'), 'stime' => get_request('stime')));
$graph = new CChart();
$graph->setPeriod($timeline['period']);
$graph->setSTime($timeline['stime']);
if (isset($_REQUEST['from'])) {
    $graph->setFrom($_REQUEST['from']);
}
if (isset($_REQUEST['width'])) {
    $graph->setWidth($_REQUEST['width']);
 /**
  * Get Applications data
  *
  * @param array $options
  * @param array $options['itemids']
  * @param array $options['hostids']
  * @param array $options['groupids']
  * @param array $options['triggerids']
  * @param array $options['applicationids']
  * @param boolean $options['status']
  * @param boolean $options['editable']
  * @param boolean $options['count']
  * @param string $options['pattern']
  * @param int $options['limit']
  * @param string $options['order']
  * @return array|int item data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     $sortColumns = array('applicationid', 'name');
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('apps' => 'a.applicationid'), 'from' => array('applications' => 'applications a'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'itemids' => null, 'applicationids' => null, 'templated' => null, 'editable' => null, 'inherited' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'exludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'expandData' => null, 'selectHosts' => null, 'selectItems' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     // editable + PERMISSION CHECK
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $userGroups = getUserGroupsByUserId($userid);
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE a.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['groupid'] = 'hg.groupid';
         }
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['where']['ahg'] = 'a.hostid=hg.hostid';
         $sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['hg'] = 'hg.groupid';
         }
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (!is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_EXTEND) {
             $sqlParts['select']['hostid'] = 'a.hostid';
         }
         $sqlParts['where']['hostid'] = dbConditionInt('a.hostid', $options['hostids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['hostid'] = 'a.hostid';
         }
     }
     // expandData
     if (!is_null($options['expandData'])) {
         $sqlParts['select']['host'] = 'h.host';
         $sqlParts['from']['hosts'] = 'hosts h';
         $sqlParts['where']['ah'] = 'a.hostid=h.hostid';
     }
     // itemids
     if (!is_null($options['itemids'])) {
         zbx_value2array($options['itemids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['itemid'] = 'ia.itemid';
         }
         $sqlParts['from']['items_applications'] = 'items_applications ia';
         $sqlParts['where'][] = dbConditionInt('ia.itemid', $options['itemids']);
         $sqlParts['where']['aia'] = 'a.applicationid=ia.applicationid';
     }
     // applicationids
     if (!is_null($options['applicationids'])) {
         zbx_value2array($options['applicationids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['applicationid'] = 'a.applicationid';
         }
         $sqlParts['where'][] = dbConditionInt('a.applicationid', $options['applicationids']);
     }
     // templated
     if (!is_null($options['templated'])) {
         $sqlParts['from']['hosts'] = 'hosts h';
         $sqlParts['where']['ah'] = 'a.hostid=h.hostid';
         if ($options['templated']) {
             $sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
         } else {
             $sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE;
         }
     }
     // inherited
     if (!is_null($options['inherited'])) {
         if ($options['inherited']) {
             $sqlParts['where'][] = 'a.templateid IS NOT NULL';
         } else {
             $sqlParts['where'][] = 'a.templateid IS NULL';
         }
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['apps'] = 'a.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(DISTINCT a.applicationid) as rowscount');
         // groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sqlParts['group'] as $key => $fields) {
                 $sqlParts['select'][$key] = $fields;
             }
         }
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('applications a', $options, $sqlParts);
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('applications a', $options, $sqlParts);
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 'a');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $applicationids = array();
     $sqlParts['select'] = array_unique($sqlParts['select']);
     $sqlParts['from'] = array_unique($sqlParts['from']);
     $sqlParts['where'] = array_unique($sqlParts['where']);
     $sqlParts['group'] = array_unique($sqlParts['group']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
     $sqlFrom = '';
     $sqlWhere = '';
     $sqlGroup = '';
     $sqlOrder = '';
     if (!empty($sqlParts['select'])) {
         $sqlSelect .= implode(',', $sqlParts['select']);
     }
     if (!empty($sqlParts['from'])) {
         $sqlFrom .= implode(',', $sqlParts['from']);
     }
     if (!empty($sqlParts['where'])) {
         $sqlWhere .= ' AND ' . implode(' AND ', $sqlParts['where']);
     }
     if (!empty($sqlParts['group'])) {
         $sqlWhere .= ' GROUP BY ' . implode(',', $sqlParts['group']);
     }
     if (!empty($sqlParts['order'])) {
         $sqlOrder .= ' ORDER BY ' . implode(',', $sqlParts['order']);
     }
     $sqlLimit = $sqlParts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sqlParts) . ' ' . $sqlSelect . ' FROM ' . $sqlFrom . ' WHERE ' . DBin_node('a.applicationid', $nodeids) . $sqlWhere . $sqlGroup . $sqlOrder;
     $res = DBselect($sql, $sqlLimit);
     while ($application = DBfetch($res)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $application;
             } else {
                 $result = $application['rowscount'];
             }
         } else {
             $applicationids[$application['applicationid']] = $application['applicationid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$application['applicationid']] = array('applicationid' => $application['applicationid']);
             } else {
                 if (!isset($result[$application['applicationid']])) {
                     $result[$application['applicationid']] = array();
                 }
                 if (!is_null($options['selectHosts']) && !isset($result[$application['applicationid']]['hosts'])) {
                     $result[$application['applicationid']]['hosts'] = array();
                 }
                 if (!is_null($options['selectItems']) && !isset($result[$application['applicationid']]['items'])) {
                     $result[$application['applicationid']]['items'] = array();
                 }
                 // hostids
                 if (isset($application['hostid']) && is_null($options['selectHosts'])) {
                     if (!isset($result[$application['applicationid']]['hosts'])) {
                         $result[$application['applicationid']]['hosts'] = array();
                     }
                     $result[$application['applicationid']]['hosts'][] = array('hostid' => $application['hostid']);
                 }
                 // itemids
                 if (isset($application['itemid']) && is_null($options['selectItems'])) {
                     if (!isset($result[$application['applicationid']]['items'])) {
                         $result[$application['applicationid']]['items'] = array();
                     }
                     $result[$application['applicationid']]['items'][] = array('itemid' => $application['itemid']);
                     unset($application['itemid']);
                 }
                 $result[$application['applicationid']] += $application;
             }
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     // adding objects
     // adding hosts
     if ($options['selectHosts'] !== null && (is_array($options['selectHosts']) || str_in_array($options['selectHosts'], $subselectsAllowedOutputs))) {
         $objParams = array('output' => $options['selectHosts'], 'applicationids' => $applicationids, 'nopermissions' => 1, 'templated_hosts' => true, 'preservekeys' => 1);
         $hosts = API::Host()->get($objParams);
         foreach ($hosts as $hostid => $host) {
             $iapplications = $host['applications'];
             unset($host['applications']);
             foreach ($iapplications as $application) {
                 $result[$application['applicationid']]['hosts'][] = $host;
             }
         }
     }
     // adding objects
     // adding items
     if (!is_null($options['selectItems']) && str_in_array($options['selectItems'], $subselectsAllowedOutputs)) {
         $objParams = array('output' => $options['selectItems'], 'applicationids' => $applicationids, 'nopermissions' => true, 'preservekeys' => true);
         $items = API::Item()->get($objParams);
         foreach ($items as $itemid => $item) {
             $iapplications = $item['applications'];
             unset($item['applications']);
             foreach ($iapplications as $application) {
                 $result[$application['applicationid']]['items'][] = $item;
             }
         }
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Ejemplo n.º 19
0
<?php 
$_REQUEST["show"] = get_request("show", 0);
$form = new CForm();
$form->SetMethod('get');
$cmbMode = new CComboBox("show", $_REQUEST["show"], "submit();");
$cmbMode->AddItem(0, S_OVERVIEW);
$cmbMode->AddItem(1, S_OVERVIEW_BY_PROXY);
$cmbMode->AddItem(2, S_DETAILS);
$form->AddItem($cmbMode);
show_table_header(S_QUEUE_OF_ITEMS_TO_BE_UPDATED_BIG, $form);
?>

<?php 
$now = time();
$item_types = array(ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_SIMPLE, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL);
$result = DBselect('SELECT i.itemid,i.nextcheck,i.description,i.key_,i.type,h.host,h.hostid,h.proxy_hostid ' . ' FROM items i,hosts h ' . ' WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND i.type in (' . implode(',', $item_types) . ') ' . ' AND ((h.status=' . HOST_STATUS_MONITORED . ' AND h.available != ' . HOST_AVAILABLE_FALSE . ') ' . ' OR (h.status=' . HOST_STATUS_MONITORED . ' AND h.available=' . HOST_AVAILABLE_FALSE . ' AND h.disable_until<=' . $now . ')) ' . ' AND i.hostid=h.hostid ' . ' AND i.nextcheck + 5 <' . $now . ' AND i.key_ NOT IN (' . zbx_dbstr('status') . ',' . zbx_dbstr('icmpping') . ',' . zbx_dbstr('icmppingsec') . ',' . zbx_dbstr('zabbix[log]') . ') ' . ' AND i.value_type not in (' . ITEM_VALUE_TYPE_LOG . ') ' . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' AND ' . DBin_node('h.hostid', get_current_nodeid()) . ' ORDER BY i.nextcheck,h.host,i.description,i.key_');
$table = new CTableInfo(S_THE_QUEUE_IS_EMPTY);
if ($_REQUEST["show"] == 0) {
    foreach ($item_types as $type) {
        $sec_10[$type] = 0;
        $sec_30[$type] = 0;
        $sec_60[$type] = 0;
        $sec_300[$type] = 0;
        $sec_600[$type] = 0;
        $sec_rest[$type] = 0;
    }
    while ($row = DBfetch($result)) {
        if ($now - $row["nextcheck"] <= 10) {
            $sec_10[$row["type"]]++;
        } else {
            if ($now - $row["nextcheck"] <= 30) {
 /**
  * Check graph data
  *
  * @param array $graphs
  * @param boolean $update
  *
  * @return void
  */
 protected function checkInput($graphs, $update = false)
 {
     $itemids = array();
     foreach ($graphs as $graph) {
         // no items
         if (!isset($graph['gitems']) || !is_array($graph['gitems']) || empty($graph['gitems'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Missing items for graph "%1$s".', $graph['name']));
         }
         $fields = array('itemid' => null);
         foreach ($graph['gitems'] as $gitem) {
             if (!check_db_fields($fields, $gitem)) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Missing "itemid" field for item.'));
             }
             // assigning with key preserves unique itemids
             $itemids[$gitem['itemid']] = $gitem['itemid'];
         }
     }
     $allowedItems = API::Item()->get(array('nodeids' => get_current_nodeid(true), 'itemids' => $itemids, 'webitems' => true, 'editable' => true, 'output' => array('flags'), 'selectItemDiscovery' => array('parent_itemid'), 'preservekeys' => true, 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CHILD, ZBX_FLAG_DISCOVERY_CREATED))));
     foreach ($itemids as $itemid) {
         if (!isset($allowedItems[$itemid])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
         }
     }
     parent::checkInput($graphs, $update);
     $this->checkDiscoveryRuleCount($graphs, $allowedItems);
 }
Ejemplo n.º 21
0
        case AUDIT_ACTION_ENABLE:
            $action = _('Enabled');
            break;
        case AUDIT_ACTION_DISABLE:
            $action = _('Disabled');
            break;
        default:
            $action = _('Unknown action');
    }
    $audit['action'] = $action;
    $audit['resourcetype'] = audit_resource2str($audit['resourcetype']);
    if (empty($audit['details'])) {
        $audit['details'] = DBfetchArray(DBselect('SELECT ad.table_name,ad.field_name,ad.oldvalue,ad.newvalue' . ' FROM auditlog_details ad' . ' WHERE ad.auditid=' . $audit['auditid']));
    }
    $data['actions'][$audit['auditid']] = $audit;
}
if (!empty($data['actions'])) {
    order_result($data['actions'], 'clock', ZBX_SORT_DOWN);
}
// get paging
$data['paging'] = getPagingLine($data['actions']);
// get timeline
unset($sqlWhere['from'], $sqlWhere['till']);
$sql = 'SELECT a.auditid,a.clock' . ' FROM auditlog a,users u' . ' WHERE u.userid=a.userid' . implode('', $sqlWhere) . ' AND ' . DBin_node('u.userid', get_current_nodeid(null, PERM_READ_ONLY)) . ' ORDER BY a.clock';
$firstAudit = DBfetch(DBselect($sql, $config['search_limit'] + 1));
$data['timeline'] = array('period' => $effectivePeriod, 'starttime' => date('YmdHis', !empty($firstAudit) ? $firstAudit['clock'] : null), 'usertime' => isset($_REQUEST['stime']) ? date('YmdHis', zbxDateToTime($data['stime']) + $effectivePeriod) : null);
// render view
$auditView = new CView('administration.auditlogs.list', $data);
$auditView->render();
$auditView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Ejemplo n.º 22
0
$dbGraph = API::Graph()->get(array('graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND, 'expandName' => 1));
//    _ex($dbGraph,0);
if (!$dbGraph) {
    access_deny();
} else {
    $dbGraph = reset($dbGraph);
}
$host = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true));
$host = reset($host);
/*
 * Display
 */
$timeline = CScreenBase::calculateTime(array('profileIdx' => get_request('profileIdx', 'web.screens'), 'profileIdx2' => get_request('profileIdx2'), 'updateProfile' => get_request('updateProfile', true), 'period' => get_request('period'), 'stime' => get_request('stime')));
CProfile::update('web.screens.graphid', $_REQUEST['graphid'], PROFILE_TYPE_ID);
$chartHeader = '';
if (id2nodeid($dbGraph['graphid']) != get_current_nodeid()) {
    $chartHeader = get_node_name_by_elid($dbGraph['graphid'], true, NAME_DELIMITER);
}
$chartHeader .= $host['name'] . NAME_DELIMITER . $dbGraph['name'];
$graph = new CLineGraphDraw_Zabbix($dbGraph['graphtype']);
$graph->setHeader($chartHeader);
$graph->setPeriod($timeline['period']);
$graph->setSTime($timeline['stime']);
if (isset($_REQUEST['border'])) {
    $graph->setBorder(0);
}
$width = get_request('width', 0);
if ($width <= 0) {
    $width = $dbGraph['width'];
}
$height = get_request('height', 0);
Ejemplo n.º 23
0
function update_user_group($usrgrpid, $name, $users_status, $gui_access, $api_access, $debug_mode, $users = array(), $rights = array())
{
    global $USER_DETAILS;
    $sql = 'SELECT * ' . ' FROM usrgrp ' . ' WHERE name=' . zbx_dbstr($name) . ' AND usrgrpid<>' . $usrgrpid . ' AND ' . DBin_node('usrgrpid', get_current_nodeid(false));
    if (DBfetch(DBselect($sql))) {
        error("Group '{$name}' already exists");
        return 0;
    }
    $result = DBexecute('UPDATE usrgrp SET name=' . zbx_dbstr($name) . ' WHERE usrgrpid=' . $usrgrpid);
    if (!$result) {
        return $result;
    }
    // must come before adding user to group
    $result &= change_group_status($usrgrpid, $users_status);
    $result &= change_group_gui_access($usrgrpid, $gui_access);
    $result &= change_group_api_access($usrgrpid, $api_access);
    $result &= change_group_debug_mode($usrgrpid, $debug_mode);
    if (!$result) {
        return $result;
    }
    //-------
    $grant = true;
    if ($gui_access == GROUP_GUI_ACCESS_DISABLED || $users_status == GROUP_STATUS_DISABLED) {
        $grant = !uint_in_array($USER_DETAILS['userid'], $users);
    }
    if ($grant) {
        $result = DBexecute('DELETE FROM users_groups WHERE usrgrpid=' . $usrgrpid);
        foreach ($users as $userid => $name) {
            $result = add_user_to_group($userid, $usrgrpid);
            if (!$result) {
                return $result;
            }
        }
    } else {
        error(S_USER_CANNOT_DISABLE_ITSELF);
        return false;
    }
    $result = DBexecute('DELETE FROM rights WHERE groupid=' . $usrgrpid);
    foreach ($rights as $right) {
        $id = get_dbid('rights', 'rightid');
        $result = DBexecute('INSERT INTO rights (rightid,groupid,permission,id)' . ' VALUES (' . $id . ',' . $usrgrpid . ',' . $right['permission'] . ',' . $right['id'] . ')');
        if (!$result) {
            return $result;
        }
    }
    return $result;
}
Ejemplo n.º 24
0
 /**
  * Check if user has write permissions for discovery rule.
  *
  * @param array $ids
  * @return bool
  */
 public function isWritable(array $ids)
 {
     if (empty($ids)) {
         return true;
     }
     $ids = array_unique($ids);
     $count = $this->get(array('nodeids' => get_current_nodeid(true), 'druleids' => $ids, 'output' => API_OUTPUT_SHORTEN, 'editable' => true, 'countOutput' => true));
     return count($ids) == $count;
 }
Ejemplo n.º 25
0
 /**
  * Get Host data
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @param _array $options
  * @param array $options['nodeids'] Node IDs
  * @param array $options['groupids'] HostGroup IDs
  * @param array $options['hostids'] Host IDs
  * @param boolean $options['monitored_hosts'] only monitored Hosts
  * @param boolean $options['templated_hosts'] include templates in result
  * @param boolean $options['with_items'] only with items
  * @param boolean $options['with_monitored_items'] only with monitored items
  * @param boolean $options['with_historical_items'] only with historical items
  * @param boolean $options['with_triggers'] only with triggers
  * @param boolean $options['with_monitored_triggers'] only with monitored triggers
  * @param boolean $options['with_httptests'] only with http tests
  * @param boolean $options['with_monitored_httptests'] only with monitored http tests
  * @param boolean $options['with_graphs'] only with graphs
  * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
  * @param int $options['extendoutput'] return all fields for Hosts
  * @param boolean $options['select_groups'] select HostGroups
  * @param boolean $options['select_templates'] select Templates
  * @param boolean $options['select_items'] select Items
  * @param boolean $options['select_triggers'] select Triggers
  * @param boolean $options['select_graphs'] select Graphs
  * @param boolean $options['select_applications'] select Applications
  * @param boolean $options['select_macros'] select Macros
  * @param boolean $options['select_profile'] select Profile
  * @param int $options['count'] count Hosts, returned column name is rowscount
  * @param string $options['pattern'] search hosts by pattern in Host name
  * @param string $options['extendPattern'] search hosts by pattern in Host name, ip and DNS
  * @param int $options['limit'] limit selection
  * @param string $options['sortfield'] field to sort by
  * @param string $options['sortorder'] sort order
  * @return array|boolean Host data as array or false if error
  */
 public static function get($options = array())
 {
     global $USER_DETAILS;
     $result = array();
     $nodeCheck = false;
     $user_type = $USER_DETAILS['type'];
     $userid = $USER_DETAILS['userid'];
     $sort_columns = array('hostid', 'host', 'status', 'dns', 'ip');
     // allowed columns for sorting
     $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
     // allowed output options for [ select_* ] params
     $sql_parts = array('select' => array('hosts' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
     $def_options = array('nodeids' => null, 'groupids' => null, 'hostids' => null, 'proxyids' => null, 'templateids' => null, 'itemids' => null, 'triggerids' => null, 'maintenanceids' => null, 'graphids' => null, 'dhostids' => null, 'dserviceids' => null, 'monitored_hosts' => null, 'templated_hosts' => null, 'proxy_hosts' => null, 'with_items' => null, 'with_monitored_items' => null, 'with_historical_items' => null, 'with_triggers' => null, 'with_monitored_triggers' => null, 'with_httptests' => null, 'with_monitored_httptests' => null, 'with_graphs' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'output' => API_OUTPUT_REFER, 'extendoutput' => null, 'select_groups' => null, 'selectParentTemplates' => null, 'select_items' => null, 'select_triggers' => null, 'select_graphs' => null, 'select_dhosts' => null, 'select_dservices' => null, 'select_applications' => null, 'select_macros' => null, 'select_profile' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
     $options = zbx_array_merge($def_options, $options);
     if (!is_null($options['extendoutput'])) {
         $options['output'] = API_OUTPUT_EXTEND;
         if (!is_null($options['select_groups'])) {
             $options['select_groups'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['selectParentTemplates'])) {
             $options['selectParentTemplates'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_items'])) {
             $options['select_items'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_triggers'])) {
             $options['select_triggers'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_graphs'])) {
             $options['select_graphs'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_applications'])) {
             $options['select_applications'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_macros'])) {
             $options['select_macros'] = API_OUTPUT_EXTEND;
         }
     }
     if (is_array($options['output'])) {
         unset($sql_parts['select']['hosts']);
         $sql_parts['select']['hostid'] = ' h.hostid';
         foreach ($options['output'] as $key => $field) {
             $sql_parts['select'][$field] = ' h.' . $field;
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) {
     } else {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $sql_parts['where'][] = 'EXISTS (' . ' SELECT hh.hostid ' . ' FROM hosts hh, hosts_groups hgg, rights r, users_groups ug ' . ' WHERE hh.hostid=h.hostid ' . ' AND hh.hostid=hgg.hostid ' . ' AND r.id=hgg.groupid ' . ' AND r.groupid=ug.usrgrpid ' . ' AND ug.userid=' . $userid . ' AND r.permission>=' . $permission . ' AND NOT EXISTS( ' . ' SELECT hggg.groupid ' . ' FROM hosts_groups hggg, rights rr, users_groups gg ' . ' WHERE hggg.hostid=hgg.hostid ' . ' AND rr.id=hggg.groupid ' . ' AND rr.groupid=gg.usrgrpid ' . ' AND gg.userid=' . $userid . ' AND rr.permission<' . $permission . ' )) ';
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         $sql_parts['where']['hostid'] = DBcondition('h.hostid', $options['hostids']);
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('h.hostid', $nodeids);
         }
     }
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['groupid'] = 'hg.groupid';
         }
         $sql_parts['from']['hosts_groups'] = 'hosts_groups hg';
         $sql_parts['where'][] = DBcondition('hg.groupid', $options['groupids']);
         $sql_parts['where']['hgh'] = 'hg.hostid=h.hostid';
         if (!is_null($options['groupCount'])) {
             $sql_parts['group']['groupid'] = 'hg.groupid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('hg.groupid', $nodeids);
         }
     }
     // proxyids
     if (!is_null($options['proxyids'])) {
         zbx_value2array($options['proxyids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['proxy_hostid'] = 'h.proxy_hostid';
         }
         $sql_parts['where'][] = DBcondition('h.proxy_hostid', $options['proxyids']);
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['templateid'] = 'ht.templateid';
         }
         $sql_parts['from']['hosts_templates'] = 'hosts_templates ht';
         $sql_parts['where'][] = DBcondition('ht.templateid', $options['templateids']);
         $sql_parts['where']['hht'] = 'h.hostid=ht.hostid';
         if (!is_null($options['groupCount'])) {
             $sql_parts['group']['templateid'] = 'ht.templateid';
         }
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('ht.templateid', $nodeids);
         }
     }
     // itemids
     if (!is_null($options['itemids'])) {
         zbx_value2array($options['itemids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['itemid'] = 'i.itemid';
         }
         $sql_parts['from']['items'] = 'items i';
         $sql_parts['where'][] = DBcondition('i.itemid', $options['itemids']);
         $sql_parts['where']['hi'] = 'h.hostid=i.hostid';
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('i.itemid', $nodeids);
         }
     }
     // triggerids
     if (!is_null($options['triggerids'])) {
         zbx_value2array($options['triggerids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['triggerid'] = 'f.triggerid';
         }
         $sql_parts['from']['functions'] = 'functions f';
         $sql_parts['from']['items'] = 'items i';
         $sql_parts['where'][] = DBcondition('f.triggerid', $options['triggerids']);
         $sql_parts['where']['hi'] = 'h.hostid=i.hostid';
         $sql_parts['where']['fi'] = 'f.itemid=i.itemid';
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('f.triggerid', $nodeids);
         }
     }
     // graphids
     if (!is_null($options['graphids'])) {
         zbx_value2array($options['graphids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['graphid'] = 'gi.graphid';
         }
         $sql_parts['from']['graphs_items'] = 'graphs_items gi';
         $sql_parts['from']['items'] = 'items i';
         $sql_parts['where'][] = DBcondition('gi.graphid', $options['graphids']);
         $sql_parts['where']['igi'] = 'i.itemid=gi.itemid';
         $sql_parts['where']['hi'] = 'h.hostid=i.hostid';
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('gi.graphid', $nodeids);
         }
     }
     // dhostids
     if (!is_null($options['dhostids'])) {
         zbx_value2array($options['dhostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['dhostid'] = 'ds.dhostid';
         }
         $sql_parts['from']['dservices'] = 'dservices ds';
         $sql_parts['where'][] = DBcondition('ds.dhostid', $options['dhostids']);
         $sql_parts['where']['dsh'] = 'ds.ip=h.ip';
         if (!is_null($options['groupCount'])) {
             $sql_parts['group']['dhostid'] = 'ds.dhostid';
         }
     }
     // dserviceids
     if (!is_null($options['dserviceids'])) {
         zbx_value2array($options['dserviceids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['dserviceid'] = 'ds.dserviceid';
         }
         $sql_parts['from']['dservices'] = 'dservices ds';
         $sql_parts['where'][] = DBcondition('ds.dserviceid', $options['dserviceids']);
         $sql_parts['where']['dsh'] = 'ds.ip=h.ip';
         if (!is_null($options['groupCount'])) {
             $sql_parts['group']['dserviceid'] = 'ds.dserviceid';
         }
     }
     // maintenanceids
     if (!is_null($options['maintenanceids'])) {
         zbx_value2array($options['maintenanceids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['maintenanceid'] = 'mh.maintenanceid';
         }
         $sql_parts['from']['maintenances_hosts'] = 'maintenances_hosts mh';
         $sql_parts['where'][] = DBcondition('mh.maintenanceid', $options['maintenanceids']);
         $sql_parts['where']['hmh'] = 'h.hostid=mh.hostid';
         if (!is_null($options['groupCount'])) {
             $sql_parts['group']['maintenanceid'] = 'mh.maintenanceid';
         }
     }
     // node check !!!!!
     // should last, after all ****IDS checks
     if (!$nodeCheck) {
         $nodeCheck = true;
         $sql_parts['where'][] = DBin_node('h.hostid', $nodeids);
     }
     // monitored_hosts, templated_hosts
     if (!is_null($options['monitored_hosts'])) {
         $sql_parts['where']['status'] = 'h.status=' . HOST_STATUS_MONITORED;
     } else {
         if (!is_null($options['templated_hosts'])) {
             $sql_parts['where']['status'] = 'h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ')';
         } else {
             if (!is_null($options['proxy_hosts'])) {
                 $sql_parts['where']['status'] = 'h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')';
             } else {
                 $sql_parts['where']['status'] = 'h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')';
             }
         }
     }
     // with_items, with_monitored_items, with_historical_items
     if (!is_null($options['with_items'])) {
         $sql_parts['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid )';
     } else {
         if (!is_null($options['with_monitored_items'])) {
             $sql_parts['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid AND i.status=' . ITEM_STATUS_ACTIVE . ')';
         } else {
             if (!is_null($options['with_historical_items'])) {
                 $sql_parts['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid AND (i.status=' . ITEM_STATUS_ACTIVE . ' OR i.status=' . ITEM_STATUS_NOTSUPPORTED . ') AND i.lastvalue IS NOT NULL)';
             }
         }
     }
     // with_triggers, with_monitored_triggers
     if (!is_null($options['with_triggers'])) {
         $sql_parts['where'][] = 'EXISTS( ' . ' SELECT i.itemid ' . ' FROM items i, functions f, triggers t ' . ' WHERE i.hostid=h.hostid ' . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid)';
     } else {
         if (!is_null($options['with_monitored_triggers'])) {
             $sql_parts['where'][] = 'EXISTS( ' . ' SELECT i.itemid ' . ' FROM items i, functions f, triggers t ' . ' WHERE i.hostid=h.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ')';
         }
     }
     // with_httptests, with_monitored_httptests
     if (!is_null($options['with_httptests'])) {
         $sql_parts['where'][] = 'EXISTS( ' . ' SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=h.hostid ' . ' AND ht.applicationid=a.applicationid)';
     } else {
         if (!is_null($options['with_monitored_httptests'])) {
             $sql_parts['where'][] = 'EXISTS( ' . ' SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=h.hostid ' . ' AND ht.applicationid=a.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE . ')';
         }
     }
     // with_graphs
     if (!is_null($options['with_graphs'])) {
         $sql_parts['where'][] = 'EXISTS( ' . ' SELECT DISTINCT i.itemid ' . ' FROM items i, graphs_items gi ' . ' WHERE i.hostid=h.hostid ' . ' AND i.itemid=gi.itemid)';
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sql_parts['select']['hosts'] = 'h.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sql_parts['select'] = array('count(DISTINCT h.hostid) as rowscount');
         //groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sql_parts['group'] as $key => $fields) {
                 $sql_parts['select'][$key] = $fields;
             }
         }
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('hosts h', $options, $sql_parts);
     }
     // filter
     if (is_array($options['filter'])) {
         zbx_db_filter('hosts h', $options, $sql_parts);
     }
     // order
     // restrict not allowed columns for sorting
     $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
     if (!zbx_empty($options['sortfield'])) {
         $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
         $sql_parts['order'][$options['sortfield']] = 'h.' . $options['sortfield'] . ' ' . $sortorder;
         if (!str_in_array('h.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('h.*', $sql_parts['select'])) {
             $sql_parts['select'][$options['sortfield']] = 'h.' . $options['sortfield'];
         }
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sql_parts['limit'] = $options['limit'];
     }
     //-------
     $hostids = array();
     $sql_parts['select'] = array_unique($sql_parts['select']);
     $sql_parts['from'] = array_unique($sql_parts['from']);
     $sql_parts['where'] = array_unique($sql_parts['where']);
     $sql_parts['group'] = array_unique($sql_parts['group']);
     $sql_parts['order'] = array_unique($sql_parts['order']);
     $sql_select = '';
     $sql_from = '';
     $sql_where = '';
     $sql_group = '';
     $sql_order = '';
     if (!empty($sql_parts['select'])) {
         $sql_select .= implode(',', $sql_parts['select']);
     }
     if (!empty($sql_parts['from'])) {
         $sql_from .= implode(',', $sql_parts['from']);
     }
     if (!empty($sql_parts['where'])) {
         $sql_where .= implode(' AND ', $sql_parts['where']);
     }
     if (!empty($sql_parts['group'])) {
         $sql_where .= ' GROUP BY ' . implode(',', $sql_parts['group']);
     }
     if (!empty($sql_parts['order'])) {
         $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']);
     }
     $sql_limit = $sql_parts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sql_parts) . ' ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . $sql_where . $sql_group . $sql_order;
     //SDI($sql);
     $res = DBselect($sql, $sql_limit);
     while ($host = DBfetch($res)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $host;
             } else {
                 $result = $host['rowscount'];
             }
         } else {
             $hostids[$host['hostid']] = $host['hostid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$host['hostid']] = array('hostid' => $host['hostid']);
             } else {
                 if (!isset($result[$host['hostid']])) {
                     $result[$host['hostid']] = array();
                 }
                 if (!is_null($options['select_groups']) && !isset($result[$host['hostid']]['groups'])) {
                     $result[$host['hostid']]['groups'] = array();
                 }
                 if (!is_null($options['selectParentTemplates']) && !isset($result[$host['hostid']]['parentTemplates'])) {
                     $result[$host['hostid']]['parentTemplates'] = array();
                 }
                 if (!is_null($options['select_items']) && !isset($result[$host['hostid']]['items'])) {
                     $result[$host['hostid']]['items'] = array();
                 }
                 if (!is_null($options['select_profile']) && !isset($result[$host['hostid']]['profile'])) {
                     $result[$host['hostid']]['profile'] = array();
                     $result[$host['hostid']]['profile_ext'] = array();
                 }
                 if (!is_null($options['select_triggers']) && !isset($result[$host['hostid']]['triggers'])) {
                     $result[$host['hostid']]['triggers'] = array();
                 }
                 if (!is_null($options['select_graphs']) && !isset($result[$host['hostid']]['graphs'])) {
                     $result[$host['hostid']]['graphs'] = array();
                 }
                 if (!is_null($options['select_dhosts']) && !isset($result[$host['hostid']]['dhosts'])) {
                     $result[$host['hostid']]['dhosts'] = array();
                 }
                 if (!is_null($options['select_dservices']) && !isset($result[$host['hostid']]['dservices'])) {
                     $result[$host['hostid']]['dservices'] = array();
                 }
                 if (!is_null($options['select_applications']) && !isset($result[$host['hostid']]['applications'])) {
                     $result[$host['hostid']]['applications'] = array();
                 }
                 if (!is_null($options['select_macros']) && !isset($result[$host['hostid']]['macros'])) {
                     $result[$host['hostid']]['macros'] = array();
                 }
                 //					if(!is_null($options['select_maintenances']) && !isset($result[$host['hostid']]['maintenances'])){
                 //						$result[$host['hostid']]['maintenances'] = array();
                 //					}
                 // groupids
                 if (isset($host['groupid']) && is_null($options['select_groups'])) {
                     if (!isset($result[$host['hostid']]['groups'])) {
                         $result[$host['hostid']]['groups'] = array();
                     }
                     $result[$host['hostid']]['groups'][] = array('groupid' => $host['groupid']);
                     unset($host['groupid']);
                 }
                 // templateids
                 if (isset($host['templateid'])) {
                     if (!isset($result[$host['hostid']]['templates'])) {
                         $result[$host['hostid']]['templates'] = array();
                     }
                     $result[$host['hostid']]['templates'][] = array('templateid' => $host['templateid']);
                     unset($host['templateid']);
                 }
                 // triggerids
                 if (isset($host['triggerid']) && is_null($options['select_triggers'])) {
                     if (!isset($result[$host['hostid']]['triggers'])) {
                         $result[$host['hostid']]['triggers'] = array();
                     }
                     $result[$host['hostid']]['triggers'][] = array('triggerid' => $host['triggerid']);
                     unset($host['triggerid']);
                 }
                 // itemids
                 if (isset($host['itemid']) && is_null($options['select_items'])) {
                     if (!isset($result[$host['hostid']]['items'])) {
                         $result[$host['hostid']]['items'] = array();
                     }
                     $result[$host['hostid']]['items'][] = array('itemid' => $host['itemid']);
                     unset($host['itemid']);
                 }
                 // graphids
                 if (isset($host['graphid']) && is_null($options['select_graphs'])) {
                     if (!isset($result[$host['hostid']]['graphs'])) {
                         $result[$host['hostid']]['graphs'] = array();
                     }
                     $result[$host['hostid']]['graphs'][] = array('graphid' => $host['graphid']);
                     unset($host['graphid']);
                 }
                 // dhostids
                 if (isset($host['dhostid']) && is_null($options['select_dhosts'])) {
                     if (!isset($result[$host['hostid']]['dhosts'])) {
                         $result[$host['hostid']]['dhosts'] = array();
                     }
                     $result[$host['hostid']]['dhosts'][] = array('dhostid' => $host['dhostid']);
                     unset($host['dhostid']);
                 }
                 // dserviceids
                 if (isset($host['dserviceid']) && is_null($options['select_dservices'])) {
                     if (!isset($result[$host['hostid']]['dservices'])) {
                         $result[$host['hostid']]['dservices'] = array();
                     }
                     $result[$host['hostid']]['dservices'][] = array('dserviceid' => $host['dserviceid']);
                     unset($host['dserviceid']);
                 }
                 // maintenanceids
                 if (isset($host['maintenanceid'])) {
                     if (!isset($result[$host['hostid']]['maintenanceid'])) {
                         $result[$host['hostid']]['maintenances'] = array();
                     }
                     $result[$host['hostid']]['maintenances'][] = array('maintenanceid' => $host['maintenanceid']);
                     //						unset($host['maintenanceid']);
                 }
                 //---
                 $result[$host['hostid']] += $host;
             }
         }
     }
     Copt::memoryPick();
     if (!is_null($options['countOutput'])) {
         if (is_null($options['preservekeys'])) {
             $result = zbx_cleanHashes($result);
         }
         return $result;
     }
     // Adding Objects
     // Adding Groups
     if (!is_null($options['select_groups']) && str_in_array($options['select_groups'], $subselects_allowed_outputs)) {
         $obj_params = array('nodeids' => $nodeids, 'output' => $options['select_groups'], 'hostids' => $hostids, 'preservekeys' => 1);
         $groups = CHostgroup::get($obj_params);
         foreach ($groups as $groupid => $group) {
             $ghosts = $group['hosts'];
             unset($group['hosts']);
             foreach ($ghosts as $num => $host) {
                 $result[$host['hostid']]['groups'][] = $group;
             }
         }
     }
     // Adding Profiles
     if (!is_null($options['select_profile'])) {
         $sql = 'SELECT hp.* ' . ' FROM hosts_profiles hp ' . ' WHERE ' . DBcondition('hp.hostid', $hostids);
         $db_profile = DBselect($sql);
         while ($profile = DBfetch($db_profile)) {
             $result[$profile['hostid']]['profile'] = $profile;
         }
         $sql = 'SELECT hpe.* ' . ' FROM hosts_profiles_ext hpe ' . ' WHERE ' . DBcondition('hpe.hostid', $hostids);
         $db_profile_ext = DBselect($sql);
         while ($profile_ext = DBfetch($db_profile_ext)) {
             $result[$profile_ext['hostid']]['profile_ext'] = $profile_ext;
         }
     }
     // Adding Templates
     if (!is_null($options['selectParentTemplates'])) {
         $obj_params = array('nodeids' => $nodeids, 'hostids' => $hostids, 'preservekeys' => 1);
         if (is_array($options['selectParentTemplates']) || str_in_array($options['selectParentTemplates'], $subselects_allowed_outputs)) {
             $obj_params['output'] = $options['selectParentTemplates'];
             $templates = CTemplate::get($obj_params);
             if (!is_null($options['limitSelects'])) {
                 order_result($templates, 'host');
             }
             foreach ($templates as $templateid => $template) {
                 unset($templates[$templateid]['hosts']);
                 $count = array();
                 foreach ($template['hosts'] as $hnum => $host) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$host['hostid']])) {
                             $count[$host['hostid']] = 0;
                         }
                         $count[$host['hostid']]++;
                         if ($count[$host['hostid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$host['hostid']]['parentTemplates'][] =& $templates[$templateid];
                 }
             }
         } else {
             if (API_OUTPUT_COUNT == $options['selectParentTemplates']) {
                 $obj_params['countOutput'] = 1;
                 $obj_params['groupCount'] = 1;
                 $templates = CTemplate::get($obj_params);
                 $templates = zbx_toHash($templates, 'hostid');
                 foreach ($result as $hostid => $host) {
                     if (isset($templates[$hostid])) {
                         $result[$hostid]['templates'] = $templates[$hostid]['rowscount'];
                     } else {
                         $result[$hostid]['templates'] = 0;
                     }
                 }
             }
         }
     }
     // Adding Items
     if (!is_null($options['select_items'])) {
         $obj_params = array('nodeids' => $nodeids, 'hostids' => $hostids, 'nopermissions' => 1, 'preservekeys' => 1);
         if (is_array($options['select_items']) || str_in_array($options['select_items'], $subselects_allowed_outputs)) {
             $obj_params['output'] = $options['select_items'];
             $items = CItem::get($obj_params);
             if (!is_null($options['limitSelects'])) {
                 order_result($items, 'description');
             }
             foreach ($items as $itemid => $item) {
                 unset($items[$itemid]['hosts']);
                 foreach ($item['hosts'] as $hnum => $host) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$host['hostid']])) {
                             $count[$host['hostid']] = 0;
                         }
                         $count[$host['hostid']]++;
                         if ($count[$host['hostid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$host['hostid']]['items'][] =& $items[$itemid];
                 }
             }
         } else {
             if (API_OUTPUT_COUNT == $options['select_items']) {
                 $obj_params['countOutput'] = 1;
                 $obj_params['groupCount'] = 1;
                 $items = CItem::get($obj_params);
                 $items = zbx_toHash($items, 'hostid');
                 foreach ($result as $hostid => $host) {
                     if (isset($items[$hostid])) {
                         $result[$hostid]['items'] = $items[$hostid]['rowscount'];
                     } else {
                         $result[$hostid]['items'] = 0;
                     }
                 }
             }
         }
     }
     // Adding triggers
     if (!is_null($options['select_triggers'])) {
         $obj_params = array('nodeids' => $nodeids, 'hostids' => $hostids, 'nopermissions' => 1, 'preservekeys' => 1);
         if (is_array($options['select_triggers']) || str_in_array($options['select_triggers'], $subselects_allowed_outputs)) {
             $obj_params['output'] = $options['select_triggers'];
             $triggers = CTrigger::get($obj_params);
             if (!is_null($options['limitSelects'])) {
                 order_result($triggers, 'description');
             }
             foreach ($triggers as $triggerid => $trigger) {
                 unset($triggers[$triggerid]['hosts']);
                 foreach ($trigger['hosts'] as $hnum => $host) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$host['hostid']])) {
                             $count[$host['hostid']] = 0;
                         }
                         $count[$host['hostid']]++;
                         if ($count[$host['hostid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$host['hostid']]['triggers'][] =& $triggers[$triggerid];
                 }
             }
         } else {
             if (API_OUTPUT_COUNT == $options['select_triggers']) {
                 $obj_params['countOutput'] = 1;
                 $obj_params['groupCount'] = 1;
                 $triggers = CTrigger::get($obj_params);
                 $triggers = zbx_toHash($triggers, 'hostid');
                 foreach ($result as $hostid => $host) {
                     if (isset($triggers[$hostid])) {
                         $result[$hostid]['triggers'] = $triggers[$hostid]['rowscount'];
                     } else {
                         $result[$hostid]['triggers'] = 0;
                     }
                 }
             }
         }
     }
     // Adding graphs
     if (!is_null($options['select_graphs'])) {
         $obj_params = array('nodeids' => $nodeids, 'hostids' => $hostids, 'nopermissions' => 1, 'preservekeys' => 1);
         if (is_array($options['select_graphs']) || str_in_array($options['select_graphs'], $subselects_allowed_outputs)) {
             $obj_params['output'] = $options['select_graphs'];
             $graphs = CGraph::get($obj_params);
             if (!is_null($options['limitSelects'])) {
                 order_result($graphs, 'name');
             }
             foreach ($graphs as $graphid => $graph) {
                 unset($graphs[$graphid]['hosts']);
                 foreach ($graph['hosts'] as $hnum => $host) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$host['hostid']])) {
                             $count[$host['hostid']] = 0;
                         }
                         $count[$host['hostid']]++;
                         if ($count[$host['hostid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$host['hostid']]['graphs'][] =& $graphs[$graphid];
                 }
             }
         } else {
             if (API_OUTPUT_COUNT == $options['select_graphs']) {
                 $obj_params['countOutput'] = 1;
                 $obj_params['groupCount'] = 1;
                 $graphs = CGraph::get($obj_params);
                 $graphs = zbx_toHash($graphs, 'hostid');
                 foreach ($result as $hostid => $host) {
                     if (isset($graphs[$hostid])) {
                         $result[$hostid]['graphs'] = $graphs[$hostid]['rowscount'];
                     } else {
                         $result[$hostid]['graphs'] = 0;
                     }
                 }
             }
         }
     }
     // Adding discovery hosts
     if (!is_null($options['select_dhosts'])) {
         $obj_params = array('nodeids' => $nodeids, 'hostids' => $hostids, 'nopermissions' => 1, 'preservekeys' => 1);
         if (is_array($options['select_dhosts']) || str_in_array($options['select_dhosts'], $subselects_allowed_outputs)) {
             $obj_params['output'] = $options['select_dhosts'];
             $dhosts = CDHost::get($obj_params);
             if (!is_null($options['limitSelects'])) {
                 order_result($dhosts, 'dhostid');
             }
             foreach ($dhosts as $dhostid => $dhost) {
                 unset($dhosts[$dhostid]['hosts']);
                 foreach ($dhost['hosts'] as $hnum => $host) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$host['hostid']])) {
                             $count[$host['hostid']] = 0;
                         }
                         $count[$host['hostid']]++;
                         if ($count[$host['hostid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$host['hostid']]['dhosts'][] =& $dhosts[$dhostid];
                 }
             }
         } else {
             if (API_OUTPUT_COUNT == $options['select_dhosts']) {
                 $obj_params['countOutput'] = 1;
                 $obj_params['groupCount'] = 1;
                 $dhosts = CDHost::get($obj_params);
                 $dhosts = zbx_toHash($dhosts, 'hostid');
                 foreach ($result as $hostid => $host) {
                     if (isset($dhosts[$hostid])) {
                         $result[$hostid]['dhosts'] = $dhosts[$hostid]['rowscount'];
                     } else {
                         $result[$hostid]['dhosts'] = 0;
                     }
                 }
             }
         }
     }
     // Adding applications
     if (!is_null($options['select_applications'])) {
         $obj_params = array('nodeids' => $nodeids, 'hostids' => $hostids, 'nopermissions' => 1, 'preservekeys' => 1);
         if (is_array($options['select_applications']) || str_in_array($options['select_applications'], $subselects_allowed_outputs)) {
             $obj_params['output'] = $options['select_applications'];
             $applications = CApplication::get($obj_params);
             if (!is_null($options['limitSelects'])) {
                 order_result($applications, 'name');
             }
             foreach ($applications as $applicationid => $application) {
                 unset($applications[$applicationid]['hosts']);
                 foreach ($application['hosts'] as $hnum => $host) {
                     if (!is_null($options['limitSelects'])) {
                         if (!isset($count[$host['hostid']])) {
                             $count[$host['hostid']] = 0;
                         }
                         $count[$host['hostid']]++;
                         if ($count[$host['hostid']] > $options['limitSelects']) {
                             continue;
                         }
                     }
                     $result[$host['hostid']]['applications'][] =& $applications[$applicationid];
                 }
             }
         } else {
             if (API_OUTPUT_COUNT == $options['select_applications']) {
                 $obj_params['countOutput'] = 1;
                 $obj_params['groupCount'] = 1;
                 $applications = CApplication::get($obj_params);
                 $applications = zbx_toHash($applications, 'hostid');
                 foreach ($result as $hostid => $host) {
                     if (isset($applications[$hostid])) {
                         $result[$hostid]['applications'] = $applications[$hostid]['rowscount'];
                     } else {
                         $result[$hostid]['applications'] = 0;
                     }
                 }
             }
         }
     }
     // Adding macros
     if (!is_null($options['select_macros']) && str_in_array($options['select_macros'], $subselects_allowed_outputs)) {
         $obj_params = array('nodeids' => $nodeids, 'output' => $options['select_macros'], 'hostids' => $hostids, 'preservekeys' => 1);
         $macros = CUserMacro::get($obj_params);
         foreach ($macros as $macroid => $macro) {
             $mhosts = $macro['hosts'];
             unset($macro['hosts']);
             foreach ($mhosts as $num => $host) {
                 $result[$host['hostid']]['macros'][] = $macro;
             }
         }
     }
     Copt::memoryPick();
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Ejemplo n.º 26
0
        }
    }
}
if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
/*
 * Display
 */
$data = array('fullscreen' => $_REQUEST['fullscreen'], 'period' => get_request('period'), 'stime' => get_request('stime'), 'elementid' => get_request('elementid', false), 'use_screen_name' => isset($_REQUEST['screenname']));
// if none is provided
if (empty($data['elementid']) && !$data['use_screen_name']) {
    // get element id saved in profile from the last visit
    $data['elementid'] = CProfile::get('web.screens.elementid', null);
}
$data['screens'] = API::Screen()->get(array('nodeids' => get_current_nodeid(), 'output' => array('screenid', 'name')));
// if screen name is provided it takes priority over elementid
if ($data['use_screen_name']) {
    $data['screens'] = zbx_toHash($data['screens'], 'name');
    $data['elementIdentifier'] = get_request('screenname');
} else {
    $data['screens'] = zbx_toHash($data['screens'], 'screenid');
    $data['elementIdentifier'] = $data['elementid'];
}
order_result($data['screens'], 'name');
// render view
$screenView = new CView('monitoring.screen', $data);
$screenView->render();
$screenView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Ejemplo n.º 27
0
$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();
Ejemplo n.º 28
0
function get_viewed_hosts($perm, $groupid = 0, $options = array(), $nodeid = null, $sql = array())
{
    global $USER_DETAILS;
    global $page;
    $userid = $USER_DETAILS['userid'];
    $def_sql = array('select' => array('h.hostid', 'h.host'), 'from' => array('hosts h'), 'where' => array(), 'order' => array());
    $def_options = array('deny_all' => 0, 'allow_all' => 0, 'select_first_host' => 0, 'select_first_host_if_empty' => 0, 'select_host_on_group_switch' => 0, 'do_not_select' => 0, 'do_not_select_if_empty' => 0, 'monitored_hosts' => 0, 'templated_hosts' => 0, 'real_hosts' => 0, 'not_proxy_hosts' => 0, 'with_items' => 0, 'with_monitored_items' => 0, 'with_historical_items' => 0, 'with_triggers' => 0, 'with_monitored_triggers' => 0, 'with_httptests' => 0, 'with_monitored_httptests' => 0, 'with_graphs' => 0, 'only_current_node' => 0);
    $def_options = zbx_array_merge($def_options, $options);
    $config = select_config();
    $dd_first_entry = $config['dropdown_first_entry'];
    if ($def_options['allow_all']) {
        $dd_first_entry = ZBX_DROPDOWN_FIRST_ALL;
    }
    if ($def_options['deny_all']) {
        $dd_first_entry = ZBX_DROPDOWN_FIRST_NONE;
    }
    if ($dd_first_entry == ZBX_DROPDOWN_FIRST_ALL) {
        $def_options['select_host_on_group_switch'] = 1;
    }
    $result = array('original' => -1, 'selected' => 0, 'hosts' => array(), 'hostids' => array());
    $hosts =& $result['hosts'];
    $hostids =& $result['hostids'];
    $first_entry = $dd_first_entry == ZBX_DROPDOWN_FIRST_NONE ? S_NOT_SELECTED_SMALL : S_ALL_SMALL;
    $hosts['0'] = $first_entry;
    if (!is_array($groupid) && $groupid == 0) {
        if ($dd_first_entry == ZBX_DROPDOWN_FIRST_NONE) {
            return $result;
        }
    } else {
        zbx_value2array($groupid);
        $def_sql['from'][] = 'hosts_groups hg';
        $def_sql['where'][] = DBcondition('hg.groupid', $groupid);
        $def_sql['where'][] = 'hg.hostid=h.hostid';
    }
    $_REQUEST['hostid'] = $result['original'] = get_request('hostid', -1);
    //-----
    if (is_null($nodeid)) {
        if (!$def_options['only_current_node']) {
            $nodeid = get_current_nodeid();
        } else {
            $nodeid = get_current_nodeid(false);
        }
    }
    //$nodeid = is_null($nodeid)?get_current_nodeid($opt):$nodeid;
    //$available_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm,PERM_RES_IDS_ARRAY,$nodeid,AVAILABLE_NOCACHE);
    if (USER_TYPE_SUPER_ADMIN != $USER_DETAILS['type']) {
        $def_sql['from']['hg'] = 'hosts_groups hg';
        $def_sql['from']['r'] = 'rights r';
        $def_sql['from']['ug'] = 'users_groups ug';
        $def_sql['where']['hgh'] = 'hg.hostid=h.hostid';
        $def_sql['where'][] = 'r.id=hg.groupid ';
        $def_sql['where'][] = 'r.groupid=ug.usrgrpid';
        $def_sql['where'][] = 'ug.userid=' . $userid;
        $def_sql['where'][] = 'r.permission>=' . $perm;
        $def_sql['where'][] = 'NOT EXISTS( ' . ' SELECT hgg.groupid ' . ' FROM hosts_groups hgg, rights rr, users_groups gg ' . ' WHERE hgg.hostid=hg.hostid ' . ' AND rr.id=hgg.groupid ' . ' AND rr.groupid=gg.usrgrpid ' . ' AND gg.userid=' . $userid . ' AND rr.permission<' . $perm . ')';
    }
    // nodes
    if (ZBX_DISTRIBUTED) {
        $def_sql['select'][] = 'n.name';
        $def_sql['from'][] = 'nodes n';
        $def_sql['where'][] = 'n.nodeid=' . DBid2nodeid('h.hostid');
        $def_sql['order'][] = 'n.name';
    }
    // hosts
    if ($def_options['monitored_hosts']) {
        $def_sql['where'][] = 'h.status=' . HOST_STATUS_MONITORED;
    } else {
        if ($def_options['real_hosts']) {
            $def_sql['where'][] = 'h.status IN(' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')';
        } else {
            if ($def_options['templated_hosts']) {
                $def_sql['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
            } else {
                if ($def_options['not_proxy_hosts']) {
                    $def_sql['where'][] = 'h.status<>' . HOST_STATUS_PROXY;
                }
            }
        }
    }
    // items
    if ($def_options['with_items']) {
        $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid )';
    } else {
        if ($def_options['with_monitored_items']) {
            $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid AND i.status=' . ITEM_STATUS_ACTIVE . ')';
        } else {
            if ($def_options['with_historical_items']) {
                $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid AND (i.status=' . ITEM_STATUS_ACTIVE . ' OR i.status=' . ITEM_STATUS_NOTSUPPORTED . ') AND i.lastvalue IS NOT NULL)';
            }
        }
    }
    // triggers
    if ($def_options['with_triggers']) {
        $def_sql['where'][] = 'EXISTS( SELECT i.itemid ' . ' FROM items i, functions f, triggers t' . ' WHERE i.hostid=h.hostid ' . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid)';
    } else {
        if ($def_options['with_monitored_triggers']) {
            $def_sql['where'][] = 'EXISTS( SELECT i.itemid ' . ' FROM items i, functions f, triggers t' . ' WHERE i.hostid=h.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ')';
        }
    }
    // httptests
    if ($def_options['with_httptests']) {
        $def_sql['where'][] = 'EXISTS( SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=h.hostid ' . ' AND ht.applicationid=a.applicationid)';
    } else {
        if ($def_options['with_monitored_httptests']) {
            $def_sql['where'][] = 'EXISTS( SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=h.hostid ' . ' AND ht.applicationid=a.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE . ')';
        }
    }
    // graphs
    if ($def_options['with_graphs']) {
        $def_sql['where'][] = 'EXISTS( SELECT DISTINCT i.itemid ' . ' FROM items i, graphs_items gi ' . ' WHERE i.hostid=h.hostid ' . ' AND i.itemid=gi.itemid)';
    }
    //------
    $def_sql['order'][] = 'h.host';
    foreach ($sql as $key => $value) {
        zbx_value2array($value);
        if (isset($def_sql[$key])) {
            $def_sql[$key] = zbx_array_merge($def_sql[$key], $value);
        } else {
            $def_sql[$key] = $value;
        }
    }
    $def_sql['select'] = array_unique($def_sql['select']);
    $def_sql['from'] = array_unique($def_sql['from']);
    $def_sql['where'] = array_unique($def_sql['where']);
    $def_sql['order'] = array_unique($def_sql['order']);
    $sql_select = '';
    $sql_from = '';
    $sql_where = '';
    $sql_order = '';
    if (!empty($def_sql['select'])) {
        $sql_select .= implode(',', $def_sql['select']);
    }
    if (!empty($def_sql['from'])) {
        $sql_from .= implode(',', $def_sql['from']);
    }
    if (!empty($def_sql['where'])) {
        $sql_where .= ' AND ' . implode(' AND ', $def_sql['where']);
    }
    if (!empty($def_sql['order'])) {
        $sql_order .= implode(',', $def_sql['order']);
    }
    $sql = 'SELECT DISTINCT ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . DBin_node('h.hostid', $nodeid) . $sql_where . ' ORDER BY ' . $sql_order;
    $res = DBselect($sql);
    while ($host = DBfetch($res)) {
        $hosts[$host['hostid']] = $host['host'];
        $hostids[$host['hostid']] = $host['hostid'];
        if (bccomp($_REQUEST['hostid'], $host['hostid']) == 0) {
            $result['selected'] = $host['hostid'];
        }
    }
    $profile_hostid = CProfile::get('web.' . $page['menu'] . '.hostid');
    //-----
    if ($def_options['do_not_select']) {
        $_REQUEST['hostid'] = $result['selected'] = 0;
    } else {
        if ($def_options['do_not_select_if_empty'] && $_REQUEST['hostid'] == -1) {
            $_REQUEST['hostid'] = $result['selected'] = 0;
        } else {
            if ($def_options['select_first_host'] || $def_options['select_first_host_if_empty'] && $_REQUEST['hostid'] == -1 && is_null($profile_hostid) || $def_options['select_host_on_group_switch'] && $_REQUEST['hostid'] != -1 && bccomp($_REQUEST['hostid'], $result['selected']) != 0) {
                $first_hostid = next($hostids);
                reset($hostids);
                if ($first_hostid !== FALSE) {
                    $_REQUEST['hostid'] = $result['selected'] = $first_hostid;
                } else {
                    $_REQUEST['hostid'] = $result['selected'] = 0;
                }
            } else {
                if ($config['dropdown_first_remember']) {
                    if ($_REQUEST['hostid'] == -1) {
                        $_REQUEST['hostid'] = is_null($profile_hostid) ? '0' : $profile_hostid;
                    }
                    if (isset($hostids[$_REQUEST['hostid']])) {
                        $result['selected'] = $_REQUEST['hostid'];
                    } else {
                        $_REQUEST['hostid'] = $result['selected'];
                    }
                } else {
                    $_REQUEST['hostid'] = $result['selected'];
                }
            }
        }
    }
    return $result;
}
Ejemplo n.º 29
0
check_fields($fields);
/*
 * Permissions
 */
if (get_request('groupid') && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
    access_deny();
}
if (get_request('hostid') && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
    access_deny();
}
validate_sort_and_sortorder('name', ZBX_SORT_DOWN);
$options = array('groups' => array('real_hosts' => true, 'with_httptests' => true), 'hosts' => array('with_monitored_items' => true, 'with_httptests' => true), 'hostid' => get_request('hostid', null), 'groupid' => get_request('groupid', null));
$pageFilter = new CPageFilter($options);
$_REQUEST['groupid'] = $pageFilter->groupid;
$_REQUEST['hostid'] = $pageFilter->hostid;
$displayNodes = is_array(get_current_nodeid()) && $pageFilter->groupid == 0 && $pageFilter->hostid == 0;
$r_form = new CForm('get');
$r_form->addVar('fullscreen', $_REQUEST['fullscreen']);
$r_form->addItem(array(_('Group') . SPACE, $pageFilter->getGroupsCB(true)));
$r_form->addItem(array(SPACE . _('Host') . SPACE, $pageFilter->getHostsCB(true)));
$httpmon_wdgt = new CWidget();
$httpmon_wdgt->addPageHeader(_('STATUS OF WEB MONITORING'), get_icon('fullscreen', array('fullscreen' => $_REQUEST['fullscreen'])));
$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) {
Ejemplo n.º 30
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) {