Esempio 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();
 }
Esempio n. 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;
}
Esempio n. 3
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;
}
 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);
 }
 /**
  * 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);
     }
 }
 /**
  * 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;
 }
Esempio n. 7
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;
 }
Esempio n. 8
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;
 }
Esempio n. 9
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;
 }
 /**
  * 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']));
 }
Esempio n. 11
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;
}
Esempio n. 12
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));
 }
Esempio n. 13
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;
 }
Esempio n. 14
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();
 }
Esempio n. 15
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];
}
 /**
  * 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;
 }
Esempio n. 17
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;
 }
Esempio n. 18
0
function make_acktab_by_eventid($eventid)
{
    $table = new CTableInfo();
    $table->SetHeader(array(S_TIME, S_USER, S_COMMENTS));
    $acks = get_acknowledges_by_eventid($eventid);
    while ($ack = DBfetch($acks)) {
        $user = get_user_by_userid($ack['userid']);
        $table->AddRow(array(date('d-m-Y h:i:s A', $ack['clock']), $user['alias'], new CCol(zbx_nl2br($ack['message']), 'wraptext')));
    }
    return $table;
}
Esempio n. 19
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;
 }
Esempio n. 20
0
function make_acktab_by_eventid($eventid)
{
    $table = new CTableInfo();
    $table->SetHeader(array(S_TIME, S_USER, S_COMMENTS));
    $acks = get_acknowledges_by_eventid($eventid);
    while ($ack = DBfetch($acks)) {
        //$users = CUser::get(array('userids' => $ack['userid'],  'output' => API_OUTPUT_EXTEND));
        //$user = reset($users);
        $table->addRow(array(zbx_date2str(S_ACKNOWINC_BY_EVENTS_DATE_FORMAT, $ack['clock']), $ack['alias'], new CCol(zbx_nl2br($ack['message']), 'wraptext')));
    }
    return $table;
}
Esempio n. 21
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;
 }
Esempio n. 22
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;
}
Esempio n. 23
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']));
 }
Esempio n. 25
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;
 }
Esempio n. 26
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];
     }
 }
function get_next_event($currentEvent, array $eventList = array(), $showUnknown = false)
{
    $nextEvent = false;
    foreach ($eventList as $event) {
        // check only the events belonging to the same object
        // find the event with the smallest eventid but greater than the current event id
        if ($event['object'] == $currentEvent['object'] && bccomp($event['objectid'], $currentEvent['objectid']) == 0 && (bccomp($event['eventid'], $currentEvent['eventid']) === 1 && (!$nextEvent || bccomp($event['eventid'], $nextEvent['eventid']) === -1))) {
            $nextEvent = $event;
        }
    }
    if ($nextEvent) {
        return $nextEvent;
    }
    $sql = 'SELECT e.*' . ' FROM events e' . ' WHERE e.objectid=' . zbx_dbstr($currentEvent['objectid']) . ' AND e.eventid>' . zbx_dbstr($currentEvent['eventid']) . ' AND e.object=' . zbx_dbstr($currentEvent['object']) . ($showUnknown ? '' : ' AND e.value_changed=' . TRIGGER_VALUE_CHANGED_YES) . ' ORDER BY e.object,e.objectid,e.eventid';
    return DBfetch(DBselect($sql, 1));
}
Esempio n. 28
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $total = 0;
     // fetch accessible host ids
     $hosts = API::Host()->get(['output' => ['hostid'], 'preservekeys' => true]);
     $hostids = array_keys($hosts);
     if ($this->screenitem['resourceid'] != 0) {
         $cond_from = ',hosts_groups hg';
         $cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']);
     } else {
         $cond_from = '';
         $cond_where = '';
     }
     $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'];
     $avail = (new CCol($avail . '  ' . _('Available')))->addClass(ZBX_STYLE_GREEN);
     $notav = (new CCol($notav . '  ' . _('Not available')))->addClass(ZBX_STYLE_RED);
     $uncn = (new CCol($uncn . '  ' . _('Unknown')))->addClass(ZBX_STYLE_GREY);
     $total = new CCol($total . '  ' . _('Total'));
     $header = (new CDiv([new CTag('h4', true, _('Hosts info'))]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
     if ($this->screenitem['resourceid'] != 0) {
         $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
         $header->addItem((new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']]));
     }
     $table = new CTableInfo();
     if ($this->screenitem['style'] == STYLE_HORIZONTAL) {
         $table->addRow([$avail, $notav, $uncn, $total]);
     } else {
         $table->addRow($avail);
         $table->addRow($notav);
         $table->addRow($uncn);
         $table->addRow($total);
     }
     $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
 }
Esempio n. 29
0
function replace_value_by_map($value, $valuemapid)
{
    if ($valuemapid < 1) {
        return $value;
    }
    static $valuemaps = array();
    if (isset($valuemaps[$valuemapid][$value])) {
        return $valuemaps[$valuemapid][$value];
    }
    $sql = 'SELECT newvalue ' . ' FROM mappings ' . ' WHERE valuemapid=' . $valuemapid . ' AND value=' . zbx_dbstr($value);
    $result = DBselect($sql);
    if ($row = DBfetch($result)) {
        $valuemaps[$valuemapid][$value] = $row['newvalue'] . ' ' . '(' . $value . ')';
        return $valuemaps[$valuemapid][$value];
    }
    return $value;
}
Esempio n. 30
0
function update_regexp($regexpid, $regexp = array())
{
    $db_fields = array('name' => null, 'test_string' => '');
    if (!check_db_fields($db_fields, $regexp)) {
        error('Incorrect arguments pasted to function [update_regexp]');
        return false;
    }
    $sql = 'SELECT regexpid FROM regexps WHERE name=' . zbx_dbstr($regexp['name']);
    if ($db_regexp = DBfetch(DBselect($sql))) {
        if (bccomp($regexpid, $db_regexp['regexpid']) != 0) {
            info(S_REGULAR_EXPRESSION . ' [' . $regexp['name'] . '] ' . S_ALREADY_EXISTS_SMALL);
            return false;
        }
    }
    $sql = 'UPDATE regexps SET ' . ' name=' . zbx_dbstr($regexp['name']) . ',' . ' test_string=' . zbx_dbstr($regexp['test_string']) . ' WHERE regexpid=' . $regexpid;
    $result = DBexecute($sql);
    return $result;
}