예제 #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();
 }
예제 #2
0
function updateMessageSettings($messages)
{
    if (!isset($messages['enabled'])) {
        $messages['enabled'] = 0;
    }
    if (isset($messages['triggers.severities'])) {
        $messages['triggers.severities'] = serialize($messages['triggers.severities']);
    }
    $dbProfiles = DBselect('SELECT p.profileid,p.idx,p.source,p.value_str' . ' FROM profiles p' . ' WHERE p.userid=' . CWebUser::$data['userid'] . ' AND ' . dbConditionString('p.idx', array('web.messages')));
    while ($profile = DBfetch($dbProfiles)) {
        $profile['value'] = $profile['value_str'];
        $dbMessages[$profile['source']] = $profile;
    }
    $inserts = array();
    $updates = array();
    foreach ($messages as $key => $value) {
        $values = array('userid' => CWebUser::$data['userid'], 'idx' => 'web.messages', 'source' => $key, 'value_str' => $value, 'type' => PROFILE_TYPE_STR);
        if (!isset($dbMessages[$key])) {
            $inserts[] = $values;
        } elseif ($dbMessages[$key]['value'] != $value) {
            $updates[] = array('values' => $values, 'where' => array('profileid' => $dbMessages[$key]['profileid']));
        }
    }
    try {
        DB::insert('profiles', $inserts);
        DB::update('profiles', $updates);
    } catch (APIException $e) {
        error($e->getMessage());
    }
    return $messages;
}
 public function _getContent($refresh = false)
 {
     $table = new CTableInfo(_('No web scenarios found.'));
     $table->setHeader(array(_('Website'), _('Links'), _('Broken Links')));
     $data = array();
     // fetch links between HTTP tests and host groups
     $result = DbFetchArray(DBselect('SELECT website.*, sum(status LIKE "2%") as links_ok, sum(status != "" AND NOT status LIKE "2%") as links_404, sum(status = "" OR status is null) as links_unchecked FROM zabbix_spider.website LEFT JOIN zabbix_spider.page ON page.website = Website.aid group by page.website;'));
     foreach ($result as $row) {
         $deadlinks = DbFetchArray(DBselect('SELECT * FROM zabbix_spider.page  WHERE NOT status IS NULL AND status != "200" AND status != "" and website = ' . $row['aid']));
         $deadlink_output = array();
         $link_options = array("target" => "_blank");
         foreach ($deadlinks as $deadlink) {
             $link_link = new CLink($deadlink['url'] == "" ? "root" : substr($deadlink['url'], 0, 50), ($deadlink['url'] == "" || $deadlink['url'][0] == "/" ? $row['url'] : "") . $deadlink['url']);
             $link_link->setTarget("_blank");
             $map_link = new CLink("map", $this->reportUrl . "?pid={$deadlink['aid']}");
             $map_link->setTarget("_blank");
             $info_link = new CLink($deadlink["status"], "http://www.checkupdown.com/status/E{$deadlink['status']}.html");
             $info_link->setTarget("_blank");
             $deadlink_output[] = new CDiv(array($link_link, " [ ", $map_link, " | ", $info_link, " ]"));
         }
         $link_link = new CLink($row['name'], $row['url']);
         $link_link->setTarget("_blank");
         $map_link = new CLink("map", $this->reportUrl . "?wid={$row['aid']}");
         $map_link->setTarget("_blank");
         $table->addRow(array(new CDiv(array($link_link, " [ ", $map_link, " ]")), new CDiv(array(new CSpan($row['links_ok'], 'green'), " / ", new CSpan($row['links_404'], 'red'), " / ", new CSpan($row['links_unchecked'], 'gray'))), new CDiv($deadlink_output)));
     }
     return $table;
 }
예제 #4
0
function updateRegexp(array $regexp, array $expressions)
{
    try {
        $regexpId = $regexp['regexpid'];
        unset($regexp['regexpid']);
        // check existence
        if (!getRegexp($regexpId)) {
            throw new Exception(_('Regular expression does not exist.'));
        }
        // check required fields
        $dbFields = array('name' => null);
        if (!check_db_fields($dbFields, $regexp)) {
            throw new Exception(_('Incorrect arguments passed to function') . ' [updateRegexp]');
        }
        // check duplicate name
        $dbRegexp = DBfetch(DBselect('SELECT re.regexpid' . ' FROM regexps re' . ' WHERE re.name=' . zbx_dbstr($regexp['name']) . andDbNode('re.regexpid')));
        if ($dbRegexp && bccomp($regexpId, $dbRegexp['regexpid']) != 0) {
            throw new Exception(_s('Regular expression "%s" already exists.', $regexp['name']));
        }
        rewriteRegexpExpressions($regexpId, $expressions);
        DB::update('regexps', array('values' => $regexp, 'where' => array('regexpid' => $regexpId)));
    } catch (Exception $e) {
        error($e->getMessage());
        return false;
    }
    return true;
}
 /**
  * Import template screens.
  *
  * @param array $allScreens
  *
  * @return void
  */
 public function import(array $allScreens)
 {
     $screensToCreate = array();
     $screensToUpdate = array();
     foreach ($allScreens as $template => $screens) {
         // TODO: select all at once out of loop
         $dbScreens = DBselect('SELECT s.screenid,s.name FROM screens s WHERE' . ' s.templateid=' . zbx_dbstr($this->referencer->resolveTemplate($template)) . ' AND ' . dbConditionString('s.name', array_keys($screens)));
         while ($dbScreen = DBfetch($dbScreens)) {
             $screens[$dbScreen['name']]['screenid'] = $dbScreen['screenid'];
         }
         foreach ($screens as $screen) {
             $screen = $this->resolveScreenReferences($screen);
             if (isset($screen['screenid'])) {
                 $screensToUpdate[] = $screen;
             } else {
                 $screen['templateid'] = $this->referencer->resolveTemplate($template);
                 $screensToCreate[] = $screen;
             }
         }
     }
     if ($this->options['templateScreens']['createMissing'] && $screensToCreate) {
         API::TemplateScreen()->create($screensToCreate);
     }
     if ($this->options['templateScreens']['updateExisting'] && $screensToUpdate) {
         API::TemplateScreen()->update($screensToUpdate);
     }
 }
 protected function doAction()
 {
     $sortField = $this->getInput('sort', CProfile::get('web.proxies.php.sort', 'host'));
     $sortOrder = $this->getInput('sortorder', CProfile::get('web.proxies.php.sortorder', ZBX_SORT_UP));
     CProfile::update('web.proxies.php.sort', $sortField, PROFILE_TYPE_STR);
     CProfile::update('web.proxies.php.sortorder', $sortOrder, PROFILE_TYPE_STR);
     $config = select_config();
     $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder, 'config' => ['max_in_table' => $config['max_in_table']]];
     $data['proxies'] = API::Proxy()->get(['output' => ['proxyid', 'host', 'status', 'lastaccess', 'tls_connect', 'tls_accept'], 'selectHosts' => ['hostid', 'name', 'status'], 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]);
     // sorting & paging
     order_result($data['proxies'], $sortField, $sortOrder);
     $url = (new CUrl('zabbix.php'))->setArgument('action', 'proxy.list');
     $data['paging'] = getPagingLine($data['proxies'], $sortOrder, $url);
     foreach ($data['proxies'] as &$proxy) {
         order_result($proxy['hosts'], 'name');
     }
     unset($proxy);
     // get proxy IDs for a *selected* page
     $proxyIds = array_keys($data['proxies']);
     if ($proxyIds) {
         // calculate performance
         $dbPerformance = DBselect('SELECT h.proxy_hostid,SUM(1.0/i.delay) AS qps' . ' FROM hosts h,items i' . ' WHERE h.hostid=i.hostid' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.delay<>0' . ' AND i.flags<>' . ZBX_FLAG_DISCOVERY_PROTOTYPE . ' AND ' . dbConditionInt('h.proxy_hostid', $proxyIds) . ' GROUP BY h.proxy_hostid');
         while ($performance = DBfetch($dbPerformance)) {
             $data['proxies'][$performance['proxy_hostid']]['perf'] = round($performance['qps'], 2);
         }
         // get items
         $items = API::Item()->get(['proxyids' => $proxyIds, 'groupCount' => true, 'countOutput' => true, 'webitems' => true, 'monitored' => true]);
         foreach ($items as $item) {
             $data['proxies'][$item['proxy_hostid']]['item_count'] = $item['rowscount'];
         }
     }
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Configuration of proxies'));
     $this->setResponse($response);
 }
 public function _getContent($refresh = false)
 {
     global $DB;
     $table = new CTableInfo(_('No email log data found'));
     $table->setHeader(array(_('System'), _('Interval'), _('Next Expected'), _('Last Seen'), _('Total Emails'), _('Actions')));
     $data = array();
     $db = mysql_connect("192.168.211.7", "zabbix", "asmd213)A)SDM@**@@");
     $result = DbFetchArray(DBselect('
                 SELECT email_schedule.*,COUNT(email_match.schedule) as `email_count` FROM email_tracker.email_schedule LEFT JOIN email_tracker.email_match ON email_match.schedule = email_schedule.id GROUP BY email_schedule.id ORDER BY exec_order 
             '));
     foreach ($result as $row) {
         //            $link_link = new CLink($row['name'],$row['url']);
         //            $link_link->setTarget("_blank");
         //            $map_link  = new CLink("map","/spider_report.php?wid=$row[aid]");
         //            $map_link->setTarget("_blank");
         $color = $row['missed'] == 0 ? 'green' : 'red';
         $last_seen = empty($row['last_seen']) || $row['last_seen'] == '0000-00-00 00:00:00' ? 'Never' : $row['last_seen'];
         $table->addRow(array(new CDiv($row['name']), new CDiv($row['expected_interval']), new CDiv($row['next_expected']), new CDiv(new CSpan($last_seen, $color)), new CDiv($row['email_count']), new CLink('Ack', '/zabbix/email.php?action=ack&id=' . $row['id'])));
         //		if (!isset($httpTestData[$row['httptestid']])) {
         //			$data[$row['groupid']]['unknown'] = empty($data[$row['groupid']]['unknown']) ? 1 : ++$data[$row['groupid']]['unknown'];
         //		}
         //		elseif ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) {
         //			$data[$row['groupid']]['failed'] = empty($data[$row['groupid']]['failed']) ? 1 : ++$data[$row['groupid']]['failed'];
         //		}
         //		else {
         //			$data[$row['groupid']]['ok'] = empty($data[$row['groupid']]['ok']) ? 1 : ++$data[$row['groupid']]['ok'];
         //		}
     }
     return $table;
 }
예제 #8
0
 /**
  * Check the integrity of the table "config".
  *
  * @return bool
  */
 public function checkConfig()
 {
     if (!DBfetch(DBselect('SELECT NULL FROM config c'))) {
         $this->setError(_('Unable to select configuration.'));
         return false;
     }
     return true;
 }
예제 #9
0
 /**
  * Check if 'dbversion' table exists.
  *
  * @return boolean
  */
 protected function checkDbVersionTable()
 {
     if (!DBfetch(DBselect("SELECT name FROM sqlite_master WHERE type='table' AND name='dbversion';"))) {
         $this->setError(_('The frontend does not match Zabbix database.'));
         return false;
     }
     return true;
 }
예제 #10
0
 /**
  * Get GraphItems data
  *
  * @param array $options
  * @return array|boolean
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     $sqlParts = array('select' => array('gitems' => 'gi.gitemid'), 'from' => array('graphs_items' => 'graphs_items gi'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('graphids' => null, 'itemids' => null, 'type' => null, 'editable' => null, 'nopermissions' => null, 'selectGraphs' => null, 'output' => API_OUTPUT_EXTEND, 'expandData' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     $this->checkDeprecatedParam($options, 'expandData');
     // editable + PERMISSION CHECK
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
         $userGroups = getUserGroupsByUserId($userid);
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE gi.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY i.itemid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
     }
     // graphids
     if (!is_null($options['graphids'])) {
         zbx_value2array($options['graphids']);
         $sqlParts['from']['graphs'] = 'graphs g';
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where'][] = dbConditionInt('g.graphid', $options['graphids']);
     }
     // itemids
     if (!is_null($options['itemids'])) {
         zbx_value2array($options['itemids']);
         $sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
     }
     // type
     if (!is_null($options['type'])) {
         $sqlParts['where'][] = 'gi.type=' . zbx_dbstr($options['type']);
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $dbRes = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
     while ($gitem = DBfetch($dbRes)) {
         if (!is_null($options['countOutput'])) {
             $result = $gitem['rowscount'];
         } else {
             $result[$gitem['gitemid']] = $gitem;
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     if ($result) {
         $result = $this->addRelatedObjects($options, $result);
         $result = $this->unsetExtraFields($result, array('graphid'), $options['output']);
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
예제 #11
0
 /**
  * Check if 'dbversion' table exists.
  *
  * @return boolean
  */
 protected function checkDbVersionTable()
 {
     $tableExists = DBfetch(DBselect("SELECT table_name FROM user_tables WHERE table_name='DBVERSION'"));
     if (!$tableExists) {
         $this->setError(_('The frontend does not match Zabbix database.'));
         return false;
     }
     return true;
 }
예제 #12
0
function rightsForLink($idl)
{
    $glinks = DBfetchArray(DBselect('SELECT host1, host2
	FROM hosts_links WHERE hosts_links.id = ' . $idl));
    if (API::Host()->isWritable(array(1 * $glinks[0]['host1'])) and API::Host()->isWritable(array(1 * $glinks[0]['host2']))) {
        return true;
    }
    return false;
}
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $hostids = array();
     $dbHostGroups = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
     while ($dbHostGroup = DBfetch($dbHostGroups)) {
         $hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
     }
     return $this->getOutput(get_items_data_overview($hostids, $this->screenitem['style']));
 }
예제 #14
0
 /**
  * Check if 'dbversion' table exists.
  *
  * @return bool
  */
 protected function checkDbVersionTable()
 {
     $tableExists = DBfetch(DBselect("SHOW TABLES LIKE 'dbversion'"));
     if (!$tableExists) {
         $this->setError(_('The frontend does not match Zabbix database.'));
         return false;
     }
     return true;
 }
예제 #15
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $hostids = array();
     $dbHostGroups = DBselect('SELECT DISTINCT hg.hostid' . ' FROM hosts_groups hg' . ' WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
     while ($dbHostGroup = DBfetch($dbHostGroups)) {
         $hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
     }
     return $this->getOutput(getTriggersOverview($hostids, $this->screenitem['application'], $this->pageFile, $this->screenitem['style'], $this->screenid));
 }
예제 #16
0
function get_image_by_imageid($imageid)
{
    $sql = 'SELECT * FROM images WHERE imageid=' . $imageid;
    $result = DBselect($sql);
    if ($row = DBfetch($result)) {
        $row['image'] = zbx_unescape_image($row['image']);
    }
    return $row;
}
예제 #17
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 . '&quot;';
     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'] . '&quot;';
     } else {
         $header_str .= S_ALL_S . '&quot;';
     }
     $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();
 }
예제 #18
0
 /**
  * Check if 'dbversion' table exists.
  *
  * @return bool
  */
 protected function checkDbVersionTable()
 {
     global $DB;
     $tableExists = DBfetch(DBselect('SELECT 1 FROM information_schema.tables' . ' WHERE table_catalog=' . zbx_dbstr($DB['DATABASE']) . " AND table_schema='public'" . " AND table_name='dbversion'"));
     if (!$tableExists) {
         $this->setError(_('The frontend does not match Zabbix database.'));
         return false;
     }
     return true;
 }
예제 #19
0
/**
 * Get image data from db, cache is used
 * @param  $imageid
 * @return array image data from db
 */
function get_image_by_imageid($imageid)
{
    static $images = array();
    if (!isset($images[$imageid])) {
        $row = DBfetch(DBselect('SELECT i.* FROM images i WHERE i.imageid=' . zbx_dbstr($imageid)));
        $row['image'] = zbx_unescape_image($row['image']);
        $images[$imageid] = $row;
    }
    return $images[$imageid];
}
예제 #20
0
function get_userid_by_usrgrpid($usrgrpids)
{
    zbx_value2array($usrgrpids);
    $userids = array();
    $db_users = DBselect('SELECT DISTINCT u.userid' . ' FROM users u,users_groups ug' . ' WHERE u.userid=ug.userid' . ' AND ' . dbConditionInt('ug.usrgrpid', $usrgrpids) . ' AND ' . DBin_node('ug.usrgrpid', false));
    while ($user = DBFetch($db_users)) {
        $userids[$user['userid']] = $user['userid'];
    }
    return $userids;
}
예제 #21
0
 /**
  * Returns the last $limit history objects for the given items.
  *
  * @param array $items      an array of items with the 'itemid' and 'value_type' properties
  * @param int   $limit
  * @param int   $period     the maximum period to retrieve data for
  *
  * @return array    an array with items IDs as keys and arrays of history objects as values
  */
 public function getLast(array $items, $limit = 1, $period = null)
 {
     $rs = array();
     foreach ($items as $item) {
         $values = DBfetchArray(DBselect('SELECT *' . ' FROM ' . self::getTableName($item['value_type']) . ' h' . ' WHERE h.itemid=' . zbx_dbstr($item['itemid']) . ($period ? ' AND h.clock>' . (time() - $period) : '') . ' ORDER BY h.clock DESC', $limit));
         if ($values) {
             $rs[$item['itemid']] = $values;
         }
     }
     return $rs;
 }
예제 #22
0
 /**
  * Check if 'dbversion' table exists.
  *
  * @return boolean
  */
 protected function checkDbVersionTable()
 {
     global $DB;
     $tabSchema = zbx_dbstr(!empty($DB['SCHEMA']) ? $DB['SCHEMA'] : zbx_strtoupper($DB['USER']));
     $tableExists = DBfetch(DBselect('SELECT 1 FROM SYSCAT.TABLES' . " WHERE TABNAME='DBVERSION'" . " AND TABSCHEMA=" . $tabSchema));
     if (!$tableExists) {
         $this->setError(_('The frontend does not match Zabbix database.'));
         return false;
     }
     return true;
 }
예제 #23
0
function get_mediatype_by_mediatypeid($mediatypeid)
{
    $sql = "select * from media_type where mediatypeid={$mediatypeid}";
    $result = DBselect($sql);
    $row = DBfetch($result);
    if ($row) {
        return $row;
    } else {
        error("No media type with with mediatypeid=[{$mediatypeid}]");
    }
    return $item;
}
예제 #24
0
 /**
  * Check if connected database version matches with frontend version.
  *
  * @return bool
  */
 public function checkDbVersion()
 {
     if (!$this->checkDbVersionTable()) {
         return false;
     }
     $version = DBfetch(DBselect('SELECT dv.mandatory,dv.optional FROM dbversion dv'));
     if ($version['mandatory'] != ZABBIX_DB_VERSION) {
         $this->setError(_s('The frontend does not match Zabbix database. Current database version (mandatory/optional): %d/%d. Required mandatory version: %d. Contact your system administrator.', $version['mandatory'], $version['optional'], ZABBIX_DB_VERSION));
         return false;
     }
     return true;
 }
예제 #25
0
 /**
  * Returns the last $limit history objects for the given items.
  *
  * @param array $items  an array of items with the 'itemid' and 'value_type' properties
  * @param int $limit
  *
  * @return array    an array with items IDs as keys and arrays of history objects as values
  */
 public function getLast(array $items, $limit = 1)
 {
     $rs = array();
     foreach ($items as $item) {
         $table = self::getTableName($item['value_type']);
         $query = DBselect('SELECT *' . ' FROM ' . $table . ' h' . ' WHERE h.itemid=' . zbx_dbstr($item['itemid']) . ' ORDER BY h.clock DESC', $limit);
         while ($history = DBfetch($query)) {
             $rs[$history['itemid']][] = $history;
         }
     }
     return $rs;
 }
예제 #26
0
function script_make_command($scriptid, $hostid)
{
    $host_db = DBfetch(DBselect('SELECT dns,useip,ip FROM hosts WHERE hostid=' . $hostid));
    $script_db = DBfetch(DBselect('SELECT command FROM scripts WHERE scriptid=' . $scriptid));
    if ($host_db && $script_db) {
        $command = $script_db['command'];
        $command = str_replace("{HOST.DNS}", $host_db['dns'], $command);
        $command = str_replace("{IPADDRESS}", $host_db['ip'], $command);
        $command = $host_db['useip'] == 0 ? str_replace("{HOST.CONN}", $host_db['dns'], $command) : str_replace("{HOST.CONN}", $host_db['ip'], $command);
    } else {
        $command = FALSE;
    }
    return $command;
}
예제 #27
0
 public static function init()
 {
     global $USER_DETAILS;
     self::$profiles = array();
     $sql = 'SELECT * ' . ' FROM profiles ' . ' WHERE userid=' . $USER_DETAILS['userid'] . ' AND ' . DBin_node('profileid', false) . ' ORDER BY userid ASC, profileid ASC';
     $db_profiles = DBselect($sql);
     while ($profile = DBfetch($db_profiles)) {
         $value_type = self::getFieldByType($profile['type']);
         if (!isset(self::$profiles[$profile['idx']])) {
             self::$profiles[$profile['idx']] = array();
         }
         self::$profiles[$profile['idx']][$profile['idx2']] = $profile[$value_type];
     }
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $hostids = array();
     $dbHostGroups = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
     while ($dbHostGroup = DBfetch($dbHostGroups)) {
         $hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
     }
     // application filter
     $applicationIds = null;
     if ($this->screenitem['application'] !== '') {
         $applications = API::Application()->get(array('output' => array('applicationid'), 'hostids' => $hostids, 'search' => array('name' => $this->screenitem['application'])));
         $applicationIds = zbx_objectValues($applications, 'applicationid');
     }
     return $this->getOutput(getItemsDataOverview($hostids, $applicationIds, $this->screenitem['style']));
 }
예제 #29
0
 /**
  * Returns favorite values from db. Uses caching for performance.
  *
  * @param string $idx identifier of favorite value group
  *
  * @return array list of favorite values corresponding to $idx
  */
 public static function get($idx)
 {
     // return values if cached
     if (isset(self::$cache[$idx])) {
         return self::$cache[$idx];
     }
     $result = array();
     $db_profiles = DBselect('SELECT p.value_id,p.source' . ' FROM profiles p' . ' WHERE p.userid=' . CWebUser::$data['userid'] . ' AND p.idx=' . zbx_dbstr($idx) . ' ORDER BY p.profileid');
     while ($profile = DBfetch($db_profiles)) {
         $result[] = array('value' => $profile['value_id'], 'source' => $profile['source']);
     }
     // store db values in cache
     self::$cache[$idx] = $result;
     return $result;
 }
예제 #30
0
 public static function init()
 {
     self::$userDetails = CWebUser::$data;
     self::$profiles = array();
     $profilesTableSchema = DB::getSchema('profiles');
     self::$stringProfileMaxLength = $profilesTableSchema['fields']['value_str']['length'];
     $db_profiles = DBselect('SELECT p.*' . ' FROM profiles p' . ' WHERE p.userid=' . self::$userDetails['userid'] . andDbNode('p.profileid', false) . ' ORDER BY p.userid,p.profileid');
     while ($profile = DBfetch($db_profiles)) {
         $value_type = self::getFieldByType($profile['type']);
         if (!isset(self::$profiles[$profile['idx']])) {
             self::$profiles[$profile['idx']] = array();
         }
         self::$profiles[$profile['idx']][$profile['idx2']] = $profile[$value_type];
     }
 }