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; }
/** * 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; }
$generalComboBox = new CComboBox('configDropDown', 'adm.valuemapping.php', 'redirect(this.options[this.selectedIndex].value);'); $generalComboBox->addItems(array('adm.gui.php' => _('GUI'), 'adm.housekeeper.php' => _('Housekeeping'), 'adm.images.php' => _('Images'), 'adm.iconmapping.php' => _('Icon mapping'), 'adm.regexps.php' => _('Regular expressions'), 'adm.macros.php' => _('Macros'), 'adm.valuemapping.php' => _('Value mapping'), 'adm.workingtime.php' => _('Working time'), 'adm.triggerseverities.php' => _('Trigger severities'), 'adm.triggerdisplayoptions.php' => _('Trigger displaying options'), 'adm.other.php' => _('Other'))); $valueMapForm = new CForm(); $valueMapForm->cleanItems(); $valueMapForm->addItem($generalComboBox); if (!isset($_REQUEST['form'])) { $valueMapForm->addItem(new CSubmit('form', _('Create value map'))); } $valueMapWidget = new CWidget(); $valueMapWidget->addPageHeader(_('CONFIGURATION OF VALUE MAPPING'), $valueMapForm); if (isset($_REQUEST['form'])) { $data = array('form' => get_request('form', 1), 'form_refresh' => get_request('form_refresh', 0), 'valuemapid' => get_request('valuemapid'), 'mappings' => array(), 'mapname' => '', 'confirmMessage' => null, 'add_value' => get_request('add_value'), 'add_newvalue' => get_request('add_newvalue')); if (isset($data['valuemapid'])) { $data['mapname'] = $dbValueMap['name']; if (empty($data['form_refresh'])) { $data['mappings'] = DBfetchArray(DBselect('SELECT m.mappingid,m.value,m.newvalue FROM mappings m WHERE m.valuemapid=' . zbx_dbstr($data['valuemapid']))); } else { $data['mapname'] = get_request('mapname', ''); $data['mappings'] = get_request('mappings', array()); } $valueMapCount = DBfetch(DBselect('SELECT COUNT(i.itemid) AS cnt FROM items i WHERE i.valuemapid=' . zbx_dbstr($data['valuemapid']))); $data['confirmMessage'] = $valueMapCount['cnt'] ? _n('Delete selected value mapping? It is used for %d item!', 'Delete selected value mapping? It is used for %d items!', $valueMapCount['cnt']) : _('Delete selected value mapping?'); } if (empty($data['valuemapid']) && !empty($data['form_refresh'])) { $data['mapname'] = get_request('mapname', ''); $data['mappings'] = get_request('mappings', array()); } order_result($data['mappings'], 'value'); $valueMapForm = new CView('administration.general.valuemapping.edit', $data); } else { $data = array('valuemaps' => array(), 'displayNodes' => is_array(get_current_nodeid()));
/** * Resolve positional macros and functional item macros, for example, {{HOST.HOST1}:key.func(param)}. * ! if same graph will be passed more than once only name for first entry will be resolved. * * @static * * @param array $data list or hashmap of graphs * @param int $data[n]['graphid'] id of graph * @param string $data[n]['name'] name of graph * * @return array inputted data with resolved names */ public static function resolveGraphNameByIds(array $data) { self::init(); $graphIds = array(); $graphMap = array(); foreach ($data as $graph) { // skip graphs without macros if (strpos($graph['name'], '{') !== false) { $graphMap[$graph['graphid']] = array('graphid' => $graph['graphid'], 'name' => $graph['name'], 'items' => array()); $graphIds[$graph['graphid']] = $graph['graphid']; } } $items = DBfetchArray(DBselect('SELECT i.hostid,gi.graphid,h.host' . ' FROM graphs_items gi,items i,hosts h' . ' WHERE gi.itemid=i.itemid' . ' AND i.hostid=h.hostid' . ' AND ' . dbConditionInt('gi.graphid', $graphIds) . ' ORDER BY gi.sortorder')); foreach ($items as $item) { $graphMap[$item['graphid']]['items'][] = array('hostid' => $item['hostid'], 'host' => $item['host']); } $graphMap = self::$macrosResolver->resolve(array('config' => 'graphName', 'data' => $graphMap)); $resolvedGraph = reset($graphMap); foreach ($data as &$graph) { if ($graph['graphid'] === $resolvedGraph['graphid']) { $graph['name'] = $resolvedGraph['name']; $resolvedGraph = next($graphMap); } } unset($graph); return $data; }
$messageFailed = _('Cannot change authentication method to HTTP'); DBstart(); $result = update_config($config); if ($result) { // reset all sessions if ($isAuthenticationTypeChanged) { $result &= DBexecute('UPDATE sessions SET status=' . ZBX_SESSION_PASSIVE . ' WHERE sessionid<>' . zbx_dbstr(CWebUser::$data['sessionid'])); } $isAuthenticationTypeChanged = false; add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ZABBIX_CONFIG, $messageSuccess); } $result = DBend($result); show_messages($result, $messageSuccess, $messageFailed); } } show_messages(); /* * Display */ $data = array('form_refresh' => getRequest('form_refresh'), 'config' => $config, 'is_authentication_type_changed' => $isAuthenticationTypeChanged, 'user' => getRequest('user', CWebUser::$data['alias']), 'user_password' => getRequest('user_password', ''), 'user_list' => null, 'change_bind_password' => getRequest('change_bind_password')); // get tab title $data['title'] = authentication2str($config['authentication_type']); // get user list if (getUserGuiAccess(CWebUser::$data['userid']) == GROUP_GUI_ACCESS_INTERNAL) { $data['user_list'] = DBfetchArray(DBselect('SELECT u.alias,u.userid FROM users u ORDER BY u.alias')); } // render view $authenticationView = new CView('administration.authentication.edit', $data); $authenticationView->render(); $authenticationView->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
$usrgrps = API::UserGroup()->get(array('usrgrpids' => $usrgrpids, 'output' => array('name'))); order_result($usrgrps, 'name'); $users = API::User()->get(array('userids' => $userids, 'output' => array('alias', 'name', 'surname'))); order_result($users, 'alias'); foreach ($users as &$user) { $user['fullname'] = getUserFullname($user); } unset($user); $jsInsert = 'addPopupValues(' . zbx_jsvalue(array('object' => 'usrgrpid', 'values' => $usrgrps)) . ');'; $jsInsert .= 'addPopupValues(' . zbx_jsvalue(array('object' => 'userid', 'values' => $users)) . ');'; zbx_add_post_js($jsInsert); $newOperationsTable->addRow(array(_('Send to User groups'), new CDiv($usrgrpList, 'objectgroup inlineblock border_dotted ui-corner-all'))); $newOperationsTable->addRow(array(_('Send to Users'), new CDiv($userList, 'objectgroup inlineblock border_dotted ui-corner-all'))); $mediaTypeComboBox = new CComboBox('new_operation[opmessage][mediatypeid]', $this->data['new_operation']['opmessage']['mediatypeid']); $mediaTypeComboBox->addItem(0, '- ' . _('All') . ' -'); $dbMediaTypes = DBfetchArray(DBselect('SELECT mt.mediatypeid,mt.description' . ' FROM media_type mt' . whereDbNode('mt.mediatypeid'))); order_result($dbMediaTypes, 'description'); foreach ($dbMediaTypes as $dbMediaType) { $mediaTypeComboBox->addItem($dbMediaType['mediatypeid'], $dbMediaType['description']); } $newOperationsTable->addRow(array(_('Send only to'), $mediaTypeComboBox)); $newOperationsTable->addRow(array(_('Default message'), new CCheckBox('new_operation[opmessage][default_msg]', $this->data['new_operation']['opmessage']['default_msg'], 'javascript: submit();', 1)), 'indent_top'); if (!$this->data['new_operation']['opmessage']['default_msg']) { $newOperationsTable->addRow(array(_('Subject'), new CTextBox('new_operation[opmessage][subject]', $this->data['new_operation']['opmessage']['subject'], ZBX_TEXTBOX_STANDARD_SIZE))); $newOperationsTable->addRow(array(_('Message'), new CTextArea('new_operation[opmessage][message]', $this->data['new_operation']['opmessage']['message']))); } else { $newOperationsTable->addItem(new CVar('new_operation[opmessage][subject]', $this->data['new_operation']['opmessage']['subject'])); $newOperationsTable->addItem(new CVar('new_operation[opmessage][message]', $this->data['new_operation']['opmessage']['message'])); } break; case OPERATION_TYPE_COMMAND:
/** * Get data for item edit page. * * @param array $item item, item prototype or LLD rule to take the data from * @param bool $options['is_discovery_rule'] * * @return array */ function getItemFormData(array $item = array(), array $options = array()) { $data = array('form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'is_discovery_rule' => !empty($options['is_discovery_rule']), 'parent_discoveryid' => getRequest('parent_discoveryid', !empty($options['is_discovery_rule']) ? getRequest('itemid') : null), 'itemid' => getRequest('itemid'), 'limited' => false, 'interfaceid' => getRequest('interfaceid', 0), 'name' => getRequest('name', ''), 'description' => getRequest('description', ''), 'key' => getRequest('key', ''), 'hostname' => getRequest('hostname'), 'delay' => getRequest('delay', ZBX_ITEM_DELAY_DEFAULT), 'history' => getRequest('history', 90), 'status' => getRequest('status', isset($_REQUEST['form_refresh']) ? 1 : 0), 'type' => getRequest('type', 0), 'snmp_community' => getRequest('snmp_community', 'public'), 'snmp_oid' => getRequest('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'), 'port' => getRequest('port', ''), 'value_type' => getRequest('value_type', ITEM_VALUE_TYPE_UINT64), 'data_type' => getRequest('data_type', ITEM_DATA_TYPE_DECIMAL), 'trapper_hosts' => getRequest('trapper_hosts', ''), 'units' => getRequest('units', ''), 'valuemapid' => getRequest('valuemapid', 0), 'params' => getRequest('params', ''), 'multiplier' => getRequest('multiplier', 0), 'delta' => getRequest('delta', 0), 'trends' => getRequest('trends', DAY_IN_YEAR), 'new_application' => getRequest('new_application', ''), 'applications' => getRequest('applications', array()), 'delay_flex' => getRequest('delay_flex', array()), 'new_delay_flex' => getRequest('new_delay_flex', array('delay' => 50, 'period' => ZBX_DEFAULT_INTERVAL)), 'snmpv3_contextname' => getRequest('snmpv3_contextname', ''), 'snmpv3_securityname' => getRequest('snmpv3_securityname', ''), 'snmpv3_securitylevel' => getRequest('snmpv3_securitylevel', 0), 'snmpv3_authprotocol' => getRequest('snmpv3_authprotocol', ITEM_AUTHPROTOCOL_MD5), 'snmpv3_authpassphrase' => getRequest('snmpv3_authpassphrase', ''), 'snmpv3_privprotocol' => getRequest('snmpv3_privprotocol', ITEM_PRIVPROTOCOL_DES), 'snmpv3_privpassphrase' => getRequest('snmpv3_privpassphrase', ''), 'ipmi_sensor' => getRequest('ipmi_sensor', ''), 'authtype' => getRequest('authtype', 0), 'username' => getRequest('username', ''), 'password' => getRequest('password', ''), 'publickey' => getRequest('publickey', ''), 'privatekey' => getRequest('privatekey', ''), 'formula' => getRequest('formula', 1), 'logtimefmt' => getRequest('logtimefmt', ''), 'add_groupid' => getRequest('add_groupid', getRequest('groupid', 0)), 'valuemaps' => null, 'possibleHostInventories' => null, 'alreadyPopulated' => null, 'initial_item_type' => null, 'templates' => array()); // hostid if (!empty($data['parent_discoveryid'])) { $discoveryRule = API::DiscoveryRule()->get(array('itemids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true)); $discoveryRule = reset($discoveryRule); $data['hostid'] = $discoveryRule['hostid']; } else { $data['hostid'] = getRequest('hostid', 0); } // types, http items only for internal processes $data['types'] = item_type2str(); unset($data['types'][ITEM_TYPE_HTTPTEST]); if (!empty($options['is_discovery_rule'])) { unset($data['types'][ITEM_TYPE_AGGREGATE], $data['types'][ITEM_TYPE_CALCULATED], $data['types'][ITEM_TYPE_SNMPTRAP]); } // item if ($item) { $data['item'] = $item; $data['hostid'] = !empty($data['hostid']) ? $data['hostid'] : $data['item']['hostid']; $data['limited'] = $data['item']['templateid'] != 0; // get templates $itemid = $item['itemid']; do { $params = array('itemids' => $itemid, 'output' => array('itemid', 'templateid'), 'selectHosts' => array('name')); if ($data['is_discovery_rule']) { $item = API::DiscoveryRule()->get($params); } else { $params['selectDiscoveryRule'] = array('itemid'); $params['filter'] = array('flags' => null); $item = API::Item()->get($params); } $item = reset($item); if (!empty($item)) { $host = reset($item['hosts']); if (!empty($item['hosts'])) { $host['name'] = CHtml::encode($host['name']); if (bccomp($data['itemid'], $itemid) == 0) { } elseif ($data['is_discovery_rule']) { $data['templates'][] = new CLink($host['name'], 'host_discovery.php?form=update&itemid=' . $item['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } elseif ($item['discoveryRule']) { $data['templates'][] = new CLink($host['name'], 'disc_prototypes.php?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $item['discoveryRule']['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } else { $data['templates'][] = new CLink($host['name'], 'items.php?form=update&itemid=' . $item['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } } $itemid = $item['templateid']; } else { break; } } while ($itemid != 0); $data['templates'] = array_reverse($data['templates']); array_shift($data['templates']); } // caption if (!empty($data['is_discovery_rule'])) { $data['caption'] = _('Discovery rule'); } else { $data['caption'] = !empty($data['parent_discoveryid']) ? _('Item prototype') : _('Item'); } // hostname if (empty($data['is_discovery_rule']) && empty($data['hostname'])) { if (!empty($data['hostid'])) { $hostInfo = API::Host()->get(array('hostids' => $data['hostid'], 'output' => array('name'), 'templated_hosts' => true)); $hostInfo = reset($hostInfo); $data['hostname'] = $hostInfo['name']; } else { $data['hostname'] = _('not selected'); } } // fill data from item if (!hasRequest('form_refresh') && ($item || $data['limited'])) { $data['name'] = $data['item']['name']; $data['description'] = $data['item']['description']; $data['key'] = $data['item']['key_']; $data['interfaceid'] = $data['item']['interfaceid']; $data['type'] = $data['item']['type']; $data['snmp_community'] = $data['item']['snmp_community']; $data['snmp_oid'] = $data['item']['snmp_oid']; $data['port'] = $data['item']['port']; $data['value_type'] = $data['item']['value_type']; $data['data_type'] = $data['item']['data_type']; $data['trapper_hosts'] = $data['item']['trapper_hosts']; $data['units'] = $data['item']['units']; $data['valuemapid'] = $data['item']['valuemapid']; $data['multiplier'] = $data['item']['multiplier']; $data['hostid'] = $data['item']['hostid']; $data['params'] = $data['item']['params']; $data['snmpv3_contextname'] = $data['item']['snmpv3_contextname']; $data['snmpv3_securityname'] = $data['item']['snmpv3_securityname']; $data['snmpv3_securitylevel'] = $data['item']['snmpv3_securitylevel']; $data['snmpv3_authprotocol'] = $data['item']['snmpv3_authprotocol']; $data['snmpv3_authpassphrase'] = $data['item']['snmpv3_authpassphrase']; $data['snmpv3_privprotocol'] = $data['item']['snmpv3_privprotocol']; $data['snmpv3_privpassphrase'] = $data['item']['snmpv3_privpassphrase']; $data['ipmi_sensor'] = $data['item']['ipmi_sensor']; $data['authtype'] = $data['item']['authtype']; $data['username'] = $data['item']['username']; $data['password'] = $data['item']['password']; $data['publickey'] = $data['item']['publickey']; $data['privatekey'] = $data['item']['privatekey']; $data['logtimefmt'] = $data['item']['logtimefmt']; $data['new_application'] = getRequest('new_application', ''); if (!$data['is_discovery_rule']) { $data['formula'] = $data['item']['formula']; } if (!$data['limited'] || !isset($_REQUEST['form_refresh'])) { $data['delay'] = $data['item']['delay']; if (($data['type'] == ITEM_TYPE_TRAPPER || $data['type'] == ITEM_TYPE_SNMPTRAP) && $data['delay'] == 0) { $data['delay'] = ZBX_ITEM_DELAY_DEFAULT; } $data['history'] = $data['item']['history']; $data['status'] = $data['item']['status']; $data['delta'] = $data['item']['delta']; $data['trends'] = $data['item']['trends']; $db_delay_flex = $data['item']['delay_flex']; if (isset($db_delay_flex)) { $arr_of_dellays = explode(';', $db_delay_flex); foreach ($arr_of_dellays as $one_db_delay) { $arr_of_delay = explode('/', $one_db_delay); if (!isset($arr_of_delay[0]) || !isset($arr_of_delay[1])) { continue; } array_push($data['delay_flex'], array('delay' => $arr_of_delay[0], 'period' => $arr_of_delay[1])); } } $data['applications'] = array_unique(zbx_array_merge($data['applications'], get_applications_by_itemid($data['itemid']))); } } // applications if (count($data['applications']) == 0) { array_push($data['applications'], 0); } $data['db_applications'] = DBfetchArray(DBselect('SELECT DISTINCT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . zbx_dbstr($data['hostid']))); order_result($data['db_applications'], 'name'); // interfaces $data['interfaces'] = API::HostInterface()->get(array('hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND)); // valuemapid if ($data['limited']) { if (!empty($data['valuemapid'])) { if ($map_data = DBfetch(DBselect('SELECT v.name FROM valuemaps v WHERE v.valuemapid=' . zbx_dbstr($data['valuemapid'])))) { $data['valuemaps'] = $map_data['name']; } } } else { $data['valuemaps'] = DBfetchArray(DBselect('SELECT v.* FROM valuemaps v')); order_result($data['valuemaps'], 'name'); } // possible host inventories if (empty($data['parent_discoveryid'])) { $data['possibleHostInventories'] = getHostInventories(); // get already populated fields by other items $data['alreadyPopulated'] = API::item()->get(array('output' => array('inventory_link'), 'filter' => array('hostid' => $data['hostid']), 'nopermissions' => true)); $data['alreadyPopulated'] = zbx_toHash($data['alreadyPopulated'], 'inventory_link'); } // template $data['is_template'] = isTemplate($data['hostid']); // unset snmpv3 fields if ($data['type'] != ITEM_TYPE_SNMPV3) { $data['snmpv3_contextname'] = ''; $data['snmpv3_securityname'] = ''; $data['snmpv3_securitylevel'] = ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV; $data['snmpv3_authprotocol'] = ITEM_AUTHPROTOCOL_MD5; $data['snmpv3_authpassphrase'] = ''; $data['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES; $data['snmpv3_privpassphrase'] = ''; } // unset ssh auth fields if ($data['type'] != ITEM_TYPE_SSH) { $data['authtype'] = ITEM_AUTHTYPE_PASSWORD; $data['publickey'] = ''; $data['privatekey'] = ''; } return $data; }
} } } show_messages(); /* * Display */ $data = array('form_refresh' => get_request('form_refresh'), 'config' => $config, 'is_authentication_type_changed' => $isAuthenticationTypeChanged, 'user' => get_request('user', $USER_DETAILS['alias']), 'user_password' => get_request('user_password', ''), 'user_list' => null, 'change_bind_password' => get_request('change_bind_password')); // get tab title switch ($config['authentication_type']) { case ZBX_AUTH_INTERNAL: $data['title'] = _('Zabbix internal authentication'); break; case ZBX_AUTH_LDAP: $data['title'] = _('LDAP authentication'); break; case ZBX_AUTH_HTTP: $data['title'] = _('HTTP authentication'); break; default: $data['title'] = ''; } // get user list if (get_user_auth($USER_DETAILS['userid']) == GROUP_GUI_ACCESS_INTERNAL) { $data['user_list'] = DBfetchArray(DBselect('SELECT u.alias,u.userid' . ' FROM users u' . ' WHERE ' . DBin_node('u.userid') . ' ORDER BY alias')); } // render view $authenticationView = new CView('administration.authentication.edit', $data); $authenticationView->render(); $authenticationView->show(); require_once 'include/page_footer.php';
} $result = DBend($result); show_messages($result, _('Configuration updated'), _('Cannot update configuration')); } /* * Display */ $form = new CForm(); $form->cleanItems(); $cmbConf = new CComboBox('configDropDown', 'adm.other.php', 'redirect(this.options[this.selectedIndex].value);'); $cmbConf->addItems(array('adm.gui.php' => _('GUI'), 'adm.housekeeper.php' => _('Housekeeping'), 'adm.images.php' => _('Images'), 'adm.iconmapping.php' => _('Icon mapping'), 'adm.regexps.php' => _('Regular expressions'), 'adm.macros.php' => _('Macros'), 'adm.valuemapping.php' => _('Value mapping'), 'adm.workingtime.php' => _('Working time'), 'adm.triggerseverities.php' => _('Trigger severities'), 'adm.triggerdisplayoptions.php' => _('Trigger displaying options'), 'adm.other.php' => _('Other'))); $form->addItem($cmbConf); $cnf_wdgt = new CWidget(); $cnf_wdgt->addPageHeader(_('OTHER CONFIGURATION PARAMETERS'), $form); $data = array(); if (hasRequest('form_refresh')) { $data['config']['discovery_groupid'] = getRequest('discovery_groupid'); $data['config']['alert_usrgrpid'] = getRequest('alert_usrgrpid'); $data['config']['refresh_unsupported'] = getRequest('refresh_unsupported'); $data['config']['snmptrap_logging'] = getRequest('snmptrap_logging'); } else { $data['config'] = select_config(false); } $data['discovery_groups'] = API::HostGroup()->get(array('output' => array('usrgrpid', 'name'), 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL), 'editable' => true)); order_result($data['discovery_groups'], 'name'); $data['alert_usrgrps'] = DBfetchArray(DBselect('SELECT u.usrgrpid,u.name FROM usrgrp u')); order_result($data['alert_usrgrps'], 'name'); $otherForm = new CView('administration.general.other.edit', $data); $cnf_wdgt->addItem($otherForm->render()); $cnf_wdgt->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
} $data['selected_usrgrp'] = get_request('selusrgrp', 0); // sort group rights order_result($data['group_rights'], 'name'); // get users if ($data['selected_usrgrp'] > 0) { $sqlFrom = ',users_groups g'; $sqlWhere = ' WHERE ' . dbConditionInt('u.userid', $data['group_users']) . ' OR (u.userid=g.userid AND g.usrgrpid=' . zbx_dbstr($data['selected_usrgrp']) . andDbNode('u.userid') . ')'; } else { $sqlFrom = ''; $sqlWhere = whereDbNode('u.userid'); } $data['users'] = DBfetchArray(DBselect('SELECT DISTINCT u.userid,u.alias,u.name,u.surname' . ' FROM users u' . $sqlFrom . $sqlWhere)); order_result($data['users'], 'alias'); // get user groups $data['usergroups'] = DBfetchArray(DBselect('SELECT ug.usrgrpid,ug.name' . ' FROM usrgrp ug' . whereDbNode('usrgrpid'))); order_result($data['usergroups'], 'name'); // render view $userGroupsView = new CView('administration.usergroups.edit', $data); $userGroupsView->render(); $userGroupsView->show(); } else { $data = array('displayNodes' => is_array(get_current_nodeid())); $sortfield = getPageSortField('name'); $data['usergroups'] = API::UserGroup()->get(array('output' => API_OUTPUT_EXTEND, 'selectUsers' => API_OUTPUT_EXTEND, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1)); // sorting & paging order_result($data['usergroups'], $sortfield, getPageSortOrder()); $data['paging'] = getPagingLine($data['usergroups'], array('usrgrpid')); // nodes if ($data['displayNodes']) { foreach ($data['usergroups'] as &$userGroup) {
$items = API::Item()->get(array('itemids' => zbx_objectValues($data['hosts']['items'], 'itemid'), 'output' => array('itemid', 'type'))); $usedInterfacesTypes = array(); foreach ($items as $item) { $usedInterfacesTypes[$item['type']] = itemTypeInterface($item['type']); } $initialItemType = min(array_keys($usedInterfacesTypes)); $data['type'] = getRequest('type') !== null ? $data['type'] : $initialItemType; $data['initial_item_type'] = $initialItemType; $data['multiple_interface_types'] = count(array_unique($usedInterfacesTypes)) > 1; } } // item types $data['itemTypes'] = item_type2str(); unset($data['itemTypes'][ITEM_TYPE_HTTPTEST]); // valuemap $data['valuemaps'] = DBfetchArray(DBselect('SELECT v.valuemapid,v.name FROM valuemaps v')); order_result($data['valuemaps'], 'name'); // render view $itemView = new CView('configuration.item.massupdate', $data); $itemView->render(); $itemView->show(); } elseif (hasRequest('action') && getRequest('action') == 'item.masscopyto' && hasRequest('group_itemid')) { // render view $data = getCopyElementsFormData('group_itemid', _('CONFIGURATION OF ITEMS')); $data['action'] = 'item.masscopyto'; $graphView = new CView('configuration.copy.elements', $data); $graphView->render(); $graphView->show(); } else { $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name')); $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
info(_n('There is "%1$d" group with Internal GUI access.', 'There are "%1$d" groups with Internal GUI access.', $result['cnt_usrgrp'])); } if (update_config($config)) { // reset all sessions if ($isAuthenticationTypeChanged) { DBexecute('UPDATE sessions SET status=' . ZBX_SESSION_PASSIVE . ' WHERE sessionid<>' . zbx_dbstr(CWebUser::$data['sessionid'])); } $isAuthenticationTypeChanged = false; add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ZABBIX_CONFIG, _('Authentication method changed to HTTP')); show_message(_('Authentication method changed to HTTP')); } else { show_error_message(_('Cannot change authentication method to HTTP')); } } } show_messages(); /* * Display */ $data = array('form_refresh' => get_request('form_refresh'), 'config' => $config, 'is_authentication_type_changed' => $isAuthenticationTypeChanged, 'user' => get_request('user', CWebUser::$data['alias']), 'user_password' => get_request('user_password', ''), 'user_list' => null, 'change_bind_password' => get_request('change_bind_password')); // get tab title $data['title'] = authentication2str($config['authentication_type']); // get user list if (getUserGuiAccess(CWebUser::$data['userid']) == GROUP_GUI_ACCESS_INTERNAL) { $data['user_list'] = DBfetchArray(DBselect('SELECT u.alias,u.userid' . ' FROM users u' . whereDbNode('u.userid') . ' ORDER BY u.alias')); } // render view $authenticationView = new CView('administration.authentication.edit', $data); $authenticationView->render(); $authenticationView->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
/** * Unlinks the templates from the given hosts. If $tragetids is set to null, the templates will be unlinked from * all hosts. * * @param array $templateids * @param null|array $targetids the IDs of the hosts to unlink the templates from * @param bool $clear delete all of the inherited objects from the hosts */ protected function unlink($templateids, $targetids = null, $clear = false) { $flags = $clear ? array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_RULE) : array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_RULE, ZBX_FLAG_DISCOVERY_PROTOTYPE); // check that all triggers on templates that we unlink, don't have items from another templates $sql = 'SELECT DISTINCT t.description' . ' FROM triggers t,functions f,items i' . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND ' . dbConditionInt('i.hostid', $templateids) . ' AND EXISTS (' . 'SELECT ff.triggerid' . ' FROM functions ff,items ii' . ' WHERE ff.itemid=ii.itemid' . ' AND ff.triggerid=t.triggerid' . ' AND ' . dbConditionInt('ii.hostid', $templateids, true) . ')' . ' AND t.flags=' . ZBX_FLAG_DISCOVERY_NORMAL; if ($dbTrigger = DBfetch(DBSelect($sql, 1))) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot unlink trigger "%s", it has items from template that is left linked to host.', $dbTrigger['description'])); } $sqlFrom = ' triggers t,hosts h'; $sqlWhere = ' EXISTS (' . 'SELECT ff.triggerid' . ' FROM functions ff,items ii' . ' WHERE ff.triggerid=t.templateid' . ' AND ii.itemid=ff.itemid' . ' AND ' . dbConditionInt('ii.hostid', $templateids) . ')' . ' AND ' . dbConditionInt('t.flags', $flags); if (!is_null($targetids)) { $sqlFrom = ' triggers t,functions f,items i,hosts h'; $sqlWhere .= ' AND ' . dbConditionInt('i.hostid', $targetids) . ' AND f.itemid=i.itemid' . ' AND t.triggerid=f.triggerid' . ' AND h.hostid=i.hostid'; } $sql = 'SELECT DISTINCT t.triggerid,t.description,t.flags,t.expression,h.name as host' . ' FROM ' . $sqlFrom . ' WHERE ' . $sqlWhere; $dbTriggers = DBSelect($sql); $triggers = array(ZBX_FLAG_DISCOVERY_NORMAL => array(), ZBX_FLAG_DISCOVERY_PROTOTYPE => array()); $triggerids = array(); while ($trigger = DBfetch($dbTriggers)) { $triggers[$trigger['flags']][$trigger['triggerid']] = array('description' => $trigger['description'], 'expression' => explode_exp($trigger['expression']), 'triggerid' => $trigger['triggerid'], 'host' => $trigger['host']); if (!in_array($trigger['triggerid'], $triggerids)) { array_push($triggerids, $trigger['triggerid']); } } if (!empty($triggers[ZBX_FLAG_DISCOVERY_NORMAL])) { if ($clear) { $result = API::Trigger()->delete(array_keys($triggers[ZBX_FLAG_DISCOVERY_NORMAL]), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear triggers')); } } else { DB::update('triggers', array('values' => array('templateid' => 0), 'where' => array('triggerid' => array_keys($triggers[ZBX_FLAG_DISCOVERY_NORMAL])))); foreach ($triggers[ZBX_FLAG_DISCOVERY_NORMAL] as $trigger) { info(_s('Unlinked: Trigger "%1$s" on "%2$s".', $trigger['description'], $trigger['host'])); } } } if (!empty($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE])) { if ($clear) { $result = API::TriggerPrototype()->delete(array_keys($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE]), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear triggers')); } } else { DB::update('triggers', array('values' => array('templateid' => 0), 'where' => array('triggerid' => array_keys($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE])))); foreach ($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE] as $trigger) { info(_s('Unlinked: Trigger prototype "%1$s" on "%2$s".', $trigger['description'], $trigger['host'])); } } } /* ITEMS, DISCOVERY RULES {{{ */ $sqlFrom = ' items i1,items i2,hosts h'; $sqlWhere = ' i2.itemid=i1.templateid' . ' AND ' . dbConditionInt('i2.hostid', $templateids) . ' AND ' . dbConditionInt('i1.flags', $flags) . ' AND h.hostid=i1.hostid'; if (!is_null($targetids)) { $sqlWhere .= ' AND ' . dbConditionInt('i1.hostid', $targetids); } $sql = 'SELECT DISTINCT i1.itemid,i1.flags,i1.name,i1.hostid,h.name as host' . ' FROM ' . $sqlFrom . ' WHERE ' . $sqlWhere; $dbItems = DBSelect($sql); $items = array(ZBX_FLAG_DISCOVERY_NORMAL => array(), ZBX_FLAG_DISCOVERY_RULE => array(), ZBX_FLAG_DISCOVERY_PROTOTYPE => array()); while ($item = DBfetch($dbItems)) { $items[$item['flags']][$item['itemid']] = array('name' => $item['name'], 'host' => $item['host']); } if (!empty($items[ZBX_FLAG_DISCOVERY_RULE])) { if ($clear) { $result = API::DiscoveryRule()->delete(array_keys($items[ZBX_FLAG_DISCOVERY_RULE]), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear discovery rules')); } } else { DB::update('items', array('values' => array('templateid' => 0), 'where' => array('itemid' => array_keys($items[ZBX_FLAG_DISCOVERY_RULE])))); foreach ($items[ZBX_FLAG_DISCOVERY_RULE] as $discoveryRule) { info(_s('Unlinked: Discovery rule "%1$s" on "%2$s".', $discoveryRule['name'], $discoveryRule['host'])); } } } if (!empty($items[ZBX_FLAG_DISCOVERY_NORMAL])) { if ($clear) { $result = API::Item()->delete(array_keys($items[ZBX_FLAG_DISCOVERY_NORMAL]), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear items')); } } else { DB::update('items', array('values' => array('templateid' => 0), 'where' => array('itemid' => array_keys($items[ZBX_FLAG_DISCOVERY_NORMAL])))); foreach ($items[ZBX_FLAG_DISCOVERY_NORMAL] as $item) { info(_s('Unlinked: Item "%1$s" on "%2$s".', $item['name'], $item['host'])); } } } if (!empty($items[ZBX_FLAG_DISCOVERY_PROTOTYPE])) { if ($clear) { $result = API::Itemprototype()->delete(array_keys($items[ZBX_FLAG_DISCOVERY_PROTOTYPE]), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear item prototypes')); } } else { DB::update('items', array('values' => array('templateid' => 0), 'where' => array('itemid' => array_keys($items[ZBX_FLAG_DISCOVERY_PROTOTYPE])))); foreach ($items[ZBX_FLAG_DISCOVERY_PROTOTYPE] as $item) { info(_s('Unlinked: Item prototype "%1$s" on "%2$s".', $item['name'], $item['host'])); } } } /* }}} ITEMS, DISCOVERY RULES */ // host prototypes // we need only to unlink host prototypes. in case of unlink and clear they will be deleted together with LLD rules. if (!$clear && isset($items[ZBX_FLAG_DISCOVERY_RULE])) { $discoveryRuleIds = array_keys($items[ZBX_FLAG_DISCOVERY_RULE]); $hostPrototypes = DBfetchArrayAssoc(DBSelect('SELECT DISTINCT h.hostid,h.host,h3.host AS parent_host' . ' FROM hosts h' . ' INNER JOIN host_discovery hd ON h.hostid=hd.hostid' . ' INNER JOIN hosts h2 ON h.templateid=h2.hostid' . ' INNER JOIN host_discovery hd2 ON h.hostid=hd.hostid' . ' INNER JOIN items i ON hd.parent_itemid=i.itemid' . ' INNER JOIN hosts h3 ON i.hostid=h3.hostid' . ' WHERE ' . dbConditionInt('hd.parent_itemid', $discoveryRuleIds)), 'hostid'); if ($hostPrototypes) { DB::update('hosts', array('values' => array('templateid' => 0), 'where' => array('hostid' => array_keys($hostPrototypes)))); DB::update('group_prototype', array('values' => array('templateid' => 0), 'where' => array('hostid' => array_keys($hostPrototypes)))); foreach ($hostPrototypes as $hostPrototype) { info(_s('Unlinked: Host prototype "%1$s" on "%2$s".', $hostPrototype['host'], $hostPrototype['parent_host'])); } } } /* GRAPHS {{{ */ $sqlFrom = ' graphs g,hosts h'; $sqlWhere = ' EXISTS (' . 'SELECT ggi.graphid' . ' FROM graphs_items ggi,items ii' . ' WHERE ggi.graphid=g.templateid' . ' AND ii.itemid=ggi.itemid' . ' AND ' . dbConditionInt('ii.hostid', $templateids) . ')' . ' AND ' . dbConditionInt('g.flags', $flags); if (!is_null($targetids)) { $sqlFrom = ' graphs g,graphs_items gi,items i,hosts h'; $sqlWhere .= ' AND ' . dbConditionInt('i.hostid', $targetids) . ' AND gi.itemid=i.itemid' . ' AND g.graphid=gi.graphid' . ' AND h.hostid=i.hostid'; } $sql = 'SELECT DISTINCT g.graphid,g.name,g.flags,h.name as host' . ' FROM ' . $sqlFrom . ' WHERE ' . $sqlWhere; $dbGraphs = DBSelect($sql); $graphs = array(ZBX_FLAG_DISCOVERY_NORMAL => array(), ZBX_FLAG_DISCOVERY_PROTOTYPE => array()); while ($graph = DBfetch($dbGraphs)) { $graphs[$graph['flags']][$graph['graphid']] = array('name' => $graph['name'], 'graphid' => $graph['graphid'], 'host' => $graph['host']); } if (!empty($graphs[ZBX_FLAG_DISCOVERY_PROTOTYPE])) { if ($clear) { $result = API::GraphPrototype()->delete(array_keys($graphs[ZBX_FLAG_DISCOVERY_PROTOTYPE]), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear graph prototypes')); } } else { DB::update('graphs', array('values' => array('templateid' => 0), 'where' => array('graphid' => array_keys($graphs[ZBX_FLAG_DISCOVERY_PROTOTYPE])))); foreach ($graphs[ZBX_FLAG_DISCOVERY_PROTOTYPE] as $graph) { info(_s('Unlinked: Graph prototype "%1$s" on "%2$s".', $graph['name'], $graph['host'])); } } } if (!empty($graphs[ZBX_FLAG_DISCOVERY_NORMAL])) { if ($clear) { $result = API::Graph()->delete(array_keys($graphs[ZBX_FLAG_DISCOVERY_NORMAL]), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear graphs.')); } } else { DB::update('graphs', array('values' => array('templateid' => 0), 'where' => array('graphid' => array_keys($graphs[ZBX_FLAG_DISCOVERY_NORMAL])))); foreach ($graphs[ZBX_FLAG_DISCOVERY_NORMAL] as $graph) { info(_s('Unlinked: Graph "%1$s" on "%2$s".', $graph['name'], $graph['host'])); } } } /* }}} GRAPHS */ // http tests $sqlWhere = ''; if (!is_null($targetids)) { $sqlWhere = ' AND ' . dbConditionInt('ht1.hostid', $targetids); } $sql = 'SELECT DISTINCT ht1.httptestid,ht1.name,h.name as host' . ' FROM httptest ht1' . ' INNER JOIN httptest ht2 ON ht2.httptestid=ht1.templateid' . ' INNER JOIN hosts h ON h.hostid=ht1.hostid' . ' WHERE ' . dbConditionInt('ht2.hostid', $templateids) . $sqlWhere; $dbHttpTests = DBSelect($sql); $httpTests = array(); while ($httpTest = DBfetch($dbHttpTests)) { $httpTests[$httpTest['httptestid']] = array('name' => $httpTest['name'], 'host' => $httpTest['host']); } if (!empty($httpTests)) { if ($clear) { $result = API::HttpTest()->delete(array_keys($httpTests), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear Web scenarios.')); } } else { DB::update('httptest', array('values' => array('templateid' => 0), 'where' => array('httptestid' => array_keys($httpTests)))); foreach ($httpTests as $httpTest) { info(_s('Unlinked: Web scenario "%1$s" on "%2$s".', $httpTest['name'], $httpTest['host'])); } } } /* APPLICATIONS {{{ */ $sql = 'SELECT at.application_templateid,at.applicationid,h.name,h.host,h.hostid' . ' FROM applications a1,application_template at,applications a2,hosts h' . ' WHERE a1.applicationid=at.applicationid' . ' AND at.templateid=a2.applicationid' . ' AND ' . dbConditionInt('a2.hostid', $templateids) . ' AND a1.hostid=h.hostid'; if ($targetids) { $sql .= ' AND ' . dbConditionInt('a1.hostid', $targetids); } $query = DBselect($sql); $applicationTemplates = array(); while ($applicationTemplate = DBfetch($query)) { $applicationTemplates[] = array('applicationid' => $applicationTemplate['applicationid'], 'application_templateid' => $applicationTemplate['application_templateid'], 'name' => $applicationTemplate['name'], 'hostid' => $applicationTemplate['hostid'], 'host' => $applicationTemplate['host']); } if ($applicationTemplates) { // unlink applications from templates DB::delete('application_template', array('application_templateid' => zbx_objectValues($applicationTemplates, 'application_templateid'))); if ($clear) { // delete inherited applications that are no longer linked to any templates $applications = DBfetchArray(DBselect('SELECT a.applicationid' . ' FROM applications a' . ' LEFT JOIN application_template at ON a.applicationid=at.applicationid ' . ' WHERE ' . dbConditionInt('a.applicationid', zbx_objectValues($applicationTemplates, 'applicationid')) . ' AND at.applicationid IS NULL')); $result = API::Application()->delete(zbx_objectValues($applications, 'applicationid'), true); if (!$result) { self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear applications.')); } } else { foreach ($applicationTemplates as $application) { info(_s('Unlinked: Application "%1$s" on "%2$s".', $application['name'], $application['host'])); } } } /* }}} APPLICATIONS */ parent::unlink($templateids, $targetids); }
$data['initial_item_type'] = $initialItemType; $data['multiple_interface_types'] = count(array_unique($usedInterfacesTypes)) > 1; } // application if (count($data['applications']) == 0) { array_push($data['applications'], 0); } if (!empty($data['hostid'])) { $data['db_applications'] = DBfetchArray(DBselect('SELECT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . zbx_dbstr($data['hostid']))); order_result($data['db_applications'], 'name'); } // item types $data['itemTypes'] = item_type2str(); unset($data['itemTypes'][ITEM_TYPE_HTTPTEST]); // valuemap $data['valuemaps'] = DBfetchArray(DBselect('SELECT v.valuemapid,v.name' . ' FROM valuemaps v' . whereDbNode('v.valuemapid'))); order_result($data['valuemaps'], 'name'); // render view $itemView = new CView('configuration.item.massupdate', $data); $itemView->render(); $itemView->show(); } elseif ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['group_itemid'])) { $data = array('group_itemid' => get_request('group_itemid', array()), 'hostid' => get_request('hostid', 0), 'copy_type' => get_request('copy_type', 0), 'copy_groupid' => get_request('copy_groupid', 0), 'copy_targetid' => get_request('copy_targetid', array())); if (!is_array($data['group_itemid']) || is_array($data['group_itemid']) && count($data['group_itemid']) < 1) { error(_('Incorrect list of items.')); } else { // group $data['groups'] = API::HostGroup()->get(array('output' => API_OUTPUT_EXTEND)); order_result($data['groups'], 'name'); // hosts if ($data['copy_type'] == 0) {
/** * Deletes the given group prototype and all discovered groups. * Deletes also group prototype children. * * @param array $groupPrototypeIds */ protected function deleteGroupPrototypes(array $groupPrototypeIds) { // delete child group prototypes $groupPrototypeChildren = DBfetchArray(DBselect('SELECT gp.group_prototypeid FROM group_prototype gp WHERE ' . dbConditionInt('templateid', $groupPrototypeIds))); if ($groupPrototypeChildren) { $this->deleteGroupPrototypes(zbx_objectValues($groupPrototypeChildren, 'group_prototypeid')); } // delete discovered groups $hostGroups = DBfetchArray(DBselect('SELECT groupid FROM group_discovery WHERE ' . dbConditionInt('parent_group_prototypeid', $groupPrototypeIds))); if ($hostGroups) { API::HostGroup()->delete(zbx_objectValues($hostGroups, 'groupid'), true); } // delete group prototypes DB::delete('group_prototype', ['group_prototypeid' => $groupPrototypeIds]); }
$data['type'] = get_request('type') !== null ? $data['type'] : $initialItemType; $data['initial_item_type'] = $initialItemType; $data['multiple_interface_types'] = count(array_unique($usedInterfacesTypes)) > 1; } // application if (count($data['applications']) == 0) { array_push($data['applications'], 0); } if (!empty($data['hostid'])) { $data['db_applications'] = DBfetchArray(DBselect('SELECT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . $data['hostid'] . ' ORDER BY a.name')); } // item types $data['itemTypes'] = item_type2str(); unset($data['itemTypes'][ITEM_TYPE_HTTPTEST]); // valuemap $data['valuemaps'] = DBfetchArray(DBselect('SELECT v.valuemapid,v.name FROM valuemaps v WHERE ' . DBin_node('v.valuemapid'))); order_result($data['valuemaps'], 'name'); // render view $itemView = new CView('configuration.item.massupdate', $data); $itemView->render(); $itemView->show(); } elseif ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['group_itemid'])) { $data = array('group_itemid' => get_request('group_itemid', array()), 'hostid' => get_request('hostid', 0), 'copy_type' => get_request('copy_type', 0), 'copy_groupid' => get_request('copy_groupid', 0), 'copy_targetid' => get_request('copy_targetid', array())); if (!is_array($data['group_itemid']) || is_array($data['group_itemid']) && count($data['group_itemid']) < 1) { error(_('Incorrect list of items.')); } else { // group $data['groups'] = API::HostGroup()->get(array('output' => API_OUTPUT_EXTEND)); order_result($data['groups'], 'name'); // hosts if ($data['copy_type'] == 0) {
/** * Check that none of the triggers have dependencies on their children. Checks only one level of inheritance, but * since it is called on each inheritance step, also works for multiple inheritance levels. * * @throws APIException if at least one trigger is dependent on its child * * @param array $triggers */ protected function checkDependencyParents(array $triggers) { // fetch all templated dependency trigger parents $depTriggerIds = []; foreach ($triggers as $trigger) { foreach ($trigger['dependencies'] as $depTriggerId) { $depTriggerIds[$depTriggerId] = $depTriggerId; } } $parentDepTriggers = DBfetchArray(DBSelect('SELECT templateid,triggerid' . ' FROM triggers' . ' WHERE templateid>0' . ' AND ' . dbConditionInt('triggerid', $depTriggerIds))); if ($parentDepTriggers) { $parentDepTriggers = zbx_toHash($parentDepTriggers, 'triggerid'); foreach ($triggers as $trigger) { foreach ($trigger['dependencies'] as $depTriggerId) { // check if the current trigger is the parent of the dependency trigger if (isset($parentDepTriggers[$depTriggerId]) && $parentDepTriggers[$depTriggerId]['templateid'] == $trigger['triggerid']) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Trigger cannot be dependent on a trigger that is inherited from it.')); } } } } }
$db_slides = DBselect('SELECT s.* FROM slides s WHERE s.slideshowid=' . zbx_dbstr($data['slideshowid']) . ' ORDER BY s.step'); while ($slide = DBfetch($db_slides)) { $data['slides'][$slide['step']] = array('slideid' => $slide['slideid'], 'screenid' => $slide['screenid'], 'delay' => $slide['delay']); } } // get slides without delay $data['slides_without_delay'] = $data['slides']; for ($i = 0, $size = count($data['slides_without_delay']); $i < $size; $i++) { unset($data['slides_without_delay'][$i]['delay']); } // render view $slideshowView = new CView('configuration.slideconf.edit', $data); $slideshowView->render(); $slideshowView->show(); } else { $data['slides'] = DBfetchArray(DBselect('SELECT s.slideshowid,s.name,s.delay,COUNT(sl.slideshowid) AS cnt' . ' FROM slideshows s' . ' LEFT JOIN slides sl ON sl.slideshowid=s.slideshowid' . whereDbNode('s.slideshowid') . ' GROUP BY s.slideshowid,s.name,s.delay')); order_result($data['slides'], getPageSortField('name'), getPageSortOrder()); $data['paging'] = getPagingLine($data['slides'], array('slideshowid')); // nodes if ($data['displayNodes'] = is_array(get_current_nodeid())) { foreach ($data['slides'] as &$slide) { $slide['nodename'] = get_node_name_by_elid($slide['slideshowid'], true); } unset($slide); } // render view $slideshowView = new CView('configuration.slideconf.list', $data); $slideshowView->render(); $slideshowView->show(); } require_once dirname(__FILE__) . '/include/page_footer.php';
/** * Returns the records that match the given criteria. * * @static * * @param string $tableName * @param array $criteria An associative array of field-value pairs, where value can be either a single value * or an array (IN) * * @return array */ public static function find($tableName, array $criteria = array()) { // build the WHERE part $sqlWhere = array(); foreach ($criteria as $field => $value) { // check if the table has this field if (!self::hasField($tableName, $field)) { self::exception(self::DBEXECUTE_ERROR, _s('Table "%1$s" doesn\'t have a field named "%2$s".', $tableName, $field)); } $sqlWhere[] = dbConditionString($field, zbx_toArray($value)); } // build query $sql = 'SELECT * FROM ' . $tableName; if ($sqlWhere) { $sql .= ' WHERE ' . implode(' AND ', $sqlWhere); } return DBfetchArray(DBSelect($sql)); }
/** * Retrieve overview table object for items. * * @param array $hostIds * @param string $application name of application to filter * @param int $viewMode * * @return CTableInfo */ function getItemsDataOverview($hostIds, $application, $viewMode) { $sqlFrom = ''; $sqlWhere = ''; if ($application !== '') { $sqlFrom = 'applications a,items_applications ia,'; $sqlWhere = ' AND i.itemid=ia.itemid AND a.applicationid=ia.applicationid AND a.name=' . zbx_dbstr($application); } $dbItems = DBfetchArray(DBselect('SELECT DISTINCT h.hostid,h.name AS hostname,i.itemid,i.key_,i.value_type,i.units,' . 'i.name,t.priority,i.valuemapid,t.value AS tr_value,t.triggerid' . ' FROM hosts h,' . $sqlFrom . 'items i' . ' LEFT JOIN functions f ON f.itemid=i.itemid' . ' LEFT JOIN triggers t ON t.triggerid=f.triggerid AND t.status=' . TRIGGER_STATUS_ENABLED . ' WHERE ' . dbConditionInt('h.hostid', $hostIds) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . $sqlWhere)); $dbItems = CMacrosResolverHelper::resolveItemNames($dbItems); CArrayHelper::sort($dbItems, array(array('field' => 'name_expanded', 'order' => ZBX_SORT_UP), array('field' => 'itemid', 'order' => ZBX_SORT_UP))); // fetch latest values $history = Manager::History()->getLast(zbx_toHash($dbItems, 'itemid'), 1, ZBX_HISTORY_PERIOD); // fetch data for the host JS menu $hosts = API::Host()->get(array('output' => array('name', 'hostid', 'status'), 'monitored_hosts' => true, 'hostids' => $hostIds, 'with_monitored_items' => true, 'preservekeys' => true, 'selectScreens' => $viewMode == STYLE_LEFT ? API_OUTPUT_COUNT : null)); $items = array(); foreach ($dbItems as $dbItem) { $name = $dbItem['name_expanded']; $dbItem['hostname'] = get_node_name_by_elid($dbItem['hostid'], null, NAME_DELIMITER) . $dbItem['hostname']; $hostNames[$dbItem['hostid']] = $dbItem['hostname']; // a little tricky check for attempt to overwrite active trigger (value=1) with // inactive or active trigger with lower priority. if (!isset($items[$name][$dbItem['hostname']]) || ($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE && $dbItem['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE || $dbItem['tr_value'] == TRIGGER_VALUE_TRUE) && $dbItem['priority'] > $items[$name][$dbItem['hostname']]['severity'])) { $items[$name][$dbItem['hostname']] = array('itemid' => $dbItem['itemid'], 'value_type' => $dbItem['value_type'], 'value' => isset($history[$dbItem['itemid']]) ? $history[$dbItem['itemid']][0]['value'] : null, 'units' => $dbItem['units'], 'name' => $name, 'valuemapid' => $dbItem['valuemapid'], 'severity' => $dbItem['priority'], 'tr_value' => $dbItem['tr_value'], 'triggerid' => $dbItem['triggerid']); } } $table = new CTableInfo(_('No items found.')); if (empty($hostNames)) { return $table; } $table->makeVerticalRotation(); order_result($hostNames); if ($viewMode == STYLE_TOP) { $header = array(new CCol(_('Items'), 'center')); foreach ($hostNames as $hostName) { $header[] = new CCol($hostName, 'vertical_rotation'); } $table->setHeader($header, 'vertical_header'); foreach ($items as $descr => $ithosts) { $tableRow = array(nbsp($descr)); foreach ($hostNames as $hostName) { $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName); } $table->addRow($tableRow); } } else { $scripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid')); $header = array(new CCol(_('Hosts'), 'center')); foreach ($items as $descr => $ithosts) { $header[] = new CCol($descr, 'vertical_rotation'); } $table->setHeader($header, 'vertical_header'); foreach ($hostNames as $hostId => $hostName) { $host = $hosts[$hostId]; $name = new CSpan($host['name'], 'link_menu'); $name->setMenuPopup(getMenuPopupHost($host, $scripts[$hostId])); $tableRow = array(new CCol($name)); foreach ($items as $ithosts) { $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName); } $table->addRow($tableRow); } } return $table; }
function update_slideshow($slideshowid, $name, $delay, $slides) { // validate slides if (empty($slides)) { error(_('Slide show must contain slides.')); return false; } // validate screens $screenids = zbx_objectValues($slides, 'screenid'); $screens = API::Screen()->get(array('screenids' => $screenids, 'output' => array('screenid'))); $screens = ZBX_toHash($screens, 'screenid'); foreach ($screenids as $screenid) { if (!isset($screens[$screenid])) { error(_('Incorrect screen provided for slide show.')); return false; } } // validate slide name $db_slideshow = DBfetch(DBselect('SELECT s.slideshowid' . ' FROM slideshows s' . ' WHERE s.name=' . zbx_dbstr($name) . ' AND s.slideshowid<>' . zbx_dbstr($slideshowid) . ' ' . andDbNode('s.slideshowid'))); if (!empty($db_slideshow)) { error(_s('Slide show "%s" already exists.', $name)); return false; } $db_slideshow = DBfetchArray(DBselect('SELECT * FROM slideshows WHERE slideshowid=' . zbx_dbstr($slideshowid))); $db_slideshow = $db_slideshow[0]; $changed = false; $slideshow = array('name' => $name, 'delay' => $delay); foreach ($slideshow as $key => $val) { if ($db_slideshow[$key] != $val) { $changed = true; break; } } if ($changed) { if (!($result = DBexecute('UPDATE slideshows SET name=' . zbx_dbstr($name) . ',delay=' . zbx_dbstr($delay) . ' WHERE slideshowid=' . zbx_dbstr($slideshowid)))) { return false; } } // get slides $db_slides = DBfetchArrayAssoc(DBselect('SELECT s.* FROM slides s WHERE s.slideshowid=' . zbx_dbstr($slideshowid)), 'slideid'); $slidesToDel = zbx_objectValues($db_slides, 'slideid'); $slidesToDel = zbx_toHash($slidesToDel); $step = 0; foreach ($slides as $slide) { $slide['delay'] = $slide['delay'] ? $slide['delay'] : 0; if (isset($db_slides[$slide['slideid']])) { // update slide if ($db_slides[$slide['slideid']]['delay'] != $slide['delay'] || $db_slides[$slide['slideid']]['step'] != $step) { $result = DBexecute('UPDATE slides SET step=' . zbx_dbstr($step) . ', delay=' . zbx_dbstr($slide['delay']) . ' WHERE slideid=' . zbx_dbstr($slide['slideid'])); } else { $result = true; } unset($slidesToDel[$slide['slideid']]); } else { $slideid = get_dbid('slides', 'slideid'); $result = DBexecute('INSERT INTO slides (slideid,slideshowid,screenid,step,delay)' . ' VALUES (' . zbx_dbstr($slideid) . ',' . zbx_dbstr($slideshowid) . ',' . zbx_dbstr($slide['screenid']) . ',' . zbx_dbstr($step) . ',' . zbx_dbstr($slide['delay']) . ')'); } $step++; if (!$result) { return false; } } // delete unnecessary slides if (!empty($slidesToDel)) { DBexecute('DELETE FROM slides WHERE slideid IN(' . implode(',', $slidesToDel) . ')'); } return true; }
$usrgrps = API::UserGroup()->get(array('usrgrpids' => $usrgrpids, 'output' => array('name'))); order_result($usrgrps, 'name'); $users = API::User()->get(array('userids' => $userids, 'output' => array('alias', 'name', 'surname'))); order_result($users, 'alias'); foreach ($users as &$user) { $user['fullname'] = getUserFullname($user); } unset($user); $jsInsert = 'addPopupValues(' . zbx_jsvalue(array('object' => 'usrgrpid', 'values' => $usrgrps)) . ');'; $jsInsert .= 'addPopupValues(' . zbx_jsvalue(array('object' => 'userid', 'values' => $users)) . ');'; zbx_add_post_js($jsInsert); $newOperationsTable->addRow(array(_('Send to User groups'), new CDiv($usrgrpList, 'objectgroup inlineblock border_dotted ui-corner-all'))); $newOperationsTable->addRow(array(_('Send to Users'), new CDiv($userList, 'objectgroup inlineblock border_dotted ui-corner-all'))); $mediaTypeComboBox = new CComboBox('new_operation[opmessage][mediatypeid]', $this->data['new_operation']['opmessage']['mediatypeid']); $mediaTypeComboBox->addItem(0, '- ' . _('All') . ' -'); $dbMediaTypes = DBfetchArray(DBselect('SELECT mt.mediatypeid,mt.description FROM media_type mt')); order_result($dbMediaTypes, 'description'); foreach ($dbMediaTypes as $dbMediaType) { $mediaTypeComboBox->addItem($dbMediaType['mediatypeid'], $dbMediaType['description']); } $newOperationsTable->addRow(array(_('Send only to'), $mediaTypeComboBox)); $newOperationsTable->addRow(array(_('Default message'), new CCheckBox('new_operation[opmessage][default_msg]', $this->data['new_operation']['opmessage']['default_msg'], 'javascript: submit();', 1)), 'indent_top'); if (!$this->data['new_operation']['opmessage']['default_msg']) { $newOperationsTable->addRow(array(_('Subject'), new CTextBox('new_operation[opmessage][subject]', $this->data['new_operation']['opmessage']['subject'], ZBX_TEXTBOX_STANDARD_SIZE))); $newOperationsTable->addRow(array(_('Message'), new CTextArea('new_operation[opmessage][message]', $this->data['new_operation']['opmessage']['message']))); } else { $newOperationsTable->addItem(new CVar('new_operation[opmessage][subject]', $this->data['new_operation']['opmessage']['subject'])); $newOperationsTable->addItem(new CVar('new_operation[opmessage][message]', $this->data['new_operation']['opmessage']['message'])); } break; case OPERATION_TYPE_COMMAND:
if (isset($_REQUEST['form']) && !empty($data['hostid'])) { $data['groupid'] = get_request('groupid', 0); $data['httptestid'] = get_request('httptestid', null); $data['form'] = get_request('form'); $data['form_refresh'] = get_request('form_refresh', 0); if (isset($_REQUEST['httptestid']) && !isset($_REQUEST['form_refresh']) || isset($limited)) { $data['name'] = $dbHttpTest['name']; $data['application'] = $dbHttpTest['application']; $data['delay'] = $dbHttpTest['delay']; $data['status'] = $dbHttpTest['status']; $data['agent'] = $dbHttpTest['agent']; $data['macros'] = $dbHttpTest['macros']; $data['authentication'] = $dbHttpTest['authentication']; $data['http_user'] = $dbHttpTest['http_user']; $data['http_password'] = $dbHttpTest['http_password']; $data['steps'] = DBfetchArray(DBselect('SELECT h.* FROM httpstep h WHERE h.httptestid=' . $_REQUEST['httptestid'] . ' ORDER BY h.no')); } else { $data['name'] = get_request('name', ''); $data['application'] = get_request('application', ''); $data['delay'] = get_request('delay', 60); $data['status'] = get_request('status', HTTPTEST_STATUS_ACTIVE); $data['agent'] = get_request('agent', ''); $data['macros'] = get_request('macros', array()); $data['authentication'] = get_request('authentication', HTTPTEST_AUTH_NONE); $data['http_user'] = get_request('http_user', ''); $data['http_password'] = get_request('http_password', ''); $data['steps'] = get_request('steps', array()); } // render view $httpView = new CView('configuration.httpconf.edit', $data); $httpView->render();
} DBend($result); } /* * Display */ $form = new CForm(); $form->cleanItems(); $cmbConf = new CComboBox('configDropDown', 'adm.other.php', 'redirect(this.options[this.selectedIndex].value);'); $cmbConf->addItems(array('adm.gui.php' => _('GUI'), 'adm.housekeeper.php' => _('Housekeeping'), 'adm.images.php' => _('Images'), 'adm.iconmapping.php' => _('Icon mapping'), 'adm.regexps.php' => _('Regular expressions'), 'adm.macros.php' => _('Macros'), 'adm.valuemapping.php' => _('Value mapping'), 'adm.workingtime.php' => _('Working time'), 'adm.triggerseverities.php' => _('Trigger severities'), 'adm.triggerdisplayoptions.php' => _('Trigger displaying options'), 'adm.other.php' => _('Other'))); $form->addItem($cmbConf); $cnf_wdgt = new CWidget(); $cnf_wdgt->addPageHeader(_('OTHER CONFIGURATION PARAMETERS'), $form); $data = array(); $data['form_refresh'] = get_request('form_refresh', 0); if ($data['form_refresh']) { $data['config']['discovery_groupid'] = get_request('discovery_groupid'); $data['config']['alert_usrgrpid'] = get_request('alert_usrgrpid'); $data['config']['refresh_unsupported'] = get_request('refresh_unsupported'); $data['config']['snmptrap_logging'] = get_request('snmptrap_logging'); } else { $data['config'] = select_config(false); } $data['discovery_groups'] = API::HostGroup()->get(array('output' => array('usrgrpid', 'name'), 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL), 'editable' => true)); order_result($data['discovery_groups'], 'name'); $data['alert_usrgrps'] = DBfetchArray(DBselect('SELECT u.usrgrpid,u.name' . ' FROM usrgrp u' . whereDbNode('u.usrgrpid'))); order_result($data['alert_usrgrps'], 'name'); $otherForm = new CView('administration.general.other.edit', $data); $cnf_wdgt->addItem($otherForm->render()); $cnf_wdgt->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
/* * Display */ if (isset($_REQUEST['form'])) { $data = ['form_refresh' => getRequest('form_refresh'), 'regexpid' => getRequest('regexpid')]; if (isset($_REQUEST['regexpid']) && !isset($_REQUEST['form_refresh'])) { $regExp = DBfetch(DBSelect('SELECT re.name,re.test_string' . ' FROM regexps re' . ' WHERE re.regexpid=' . zbx_dbstr($_REQUEST['regexpid']))); $data['name'] = $regExp['name']; $data['test_string'] = $regExp['test_string']; $data['expressions'] = DBfetchArray(DBselect('SELECT e.expressionid,e.expression,e.expression_type,e.exp_delimiter,e.case_sensitive' . ' FROM expressions e' . ' WHERE e.regexpid=' . zbx_dbstr($_REQUEST['regexpid']) . ' ORDER BY e.expression_type')); } else { $data['name'] = getRequest('name', ''); $data['test_string'] = getRequest('test_string', ''); $data['expressions'] = getRequest('expressions', [['expression' => '', 'expression_type' => EXPRESSION_TYPE_INCLUDED, 'exp_delimiter' => ',', 'case_sensitive' => 0]]); } $view = new CView('administration.general.regularexpressions.edit', $data); } else { $data = ['regexps' => [], 'regexpids' => []]; $dbRegExp = DBselect('SELECT re.* FROM regexps re'); while ($regExp = DBfetch($dbRegExp)) { $regExp['expressions'] = []; $data['regexps'][$regExp['regexpid']] = $regExp; $data['regexpids'][$regExp['regexpid']] = $regExp['regexpid']; } order_result($data['regexps'], 'name'); $data['db_exps'] = DBfetchArray(DBselect('SELECT e.*' . ' FROM expressions e' . ' WHERE ' . dbConditionInt('e.regexpid', $data['regexpids']) . ' ORDER BY e.expression_type')); $view = new CView('administration.general.regularexpressions.list', $data); } $view->render(); $view->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
/** * Prepares and returns an array of child items, inherited from items $itemsToInherit on the given hosts. * * @param array $itemsToInherit * @param array|null $hostIds * * @return array an array of unsaved child items */ protected function prepareInheritedItems(array $itemsToInherit, array $hostIds = null) { // fetch all child hosts $chdHosts = API::Host()->get(['output' => ['hostid', 'host', 'status'], 'selectParentTemplates' => ['templateid'], 'selectInterfaces' => API_OUTPUT_EXTEND, 'templateids' => zbx_objectValues($itemsToInherit, 'hostid'), 'hostids' => $hostIds, 'preservekeys' => true, 'nopermissions' => true, 'templated_hosts' => true]); if (empty($chdHosts)) { return []; } $newItems = []; foreach ($chdHosts as $hostId => $host) { $templateids = zbx_toHash($host['parentTemplates'], 'templateid'); // skip items not from parent templates of current host $parentItems = []; foreach ($itemsToInherit as $inum => $parentItem) { if (isset($templateids[$parentItem['hostid']])) { $parentItems[$inum] = $parentItem; } } // check existing items to decide insert or update $exItems = API::Item()->get(['output' => ['itemid', 'type', 'key_', 'flags', 'templateid'], 'hostids' => $hostId, 'preservekeys' => true, 'nopermissions' => true, 'filter' => ['flags' => null]]); $exItemsKeys = zbx_toHash($exItems, 'key_'); $exItemsTpl = zbx_toHash($exItems, 'templateid'); $itemids_with_application_prototypes = []; foreach ($parentItems as $parentItem) { if (isset($parentItem['applicationPrototypes']) && is_array($parentItem['applicationPrototypes']) && !array_key_exists('ruleid', $parentItem)) { $itemids_with_application_prototypes[$parentItem['itemid']] = true; } } if ($itemids_with_application_prototypes) { $discovery_rules = DBfetchArray(DBselect('SELECT id.itemid,id.parent_itemid' . ' FROM item_discovery id' . ' WHERE ' . dbConditionInt('id.itemid', array_keys($itemids_with_application_prototypes)))); $discovery_rules = zbx_toHash($discovery_rules, 'itemid'); } foreach ($parentItems as $parentItem) { $exItem = null; // check if an item of a different type with the same key exists if (isset($exItemsKeys[$parentItem['key_']])) { $exItem = $exItemsKeys[$parentItem['key_']]; if ($exItem['flags'] != $parentItem['flags']) { $this->errorInheritFlags($exItem['flags'], $exItem['key_'], $host['host']); } } // update by templateid if (isset($exItemsTpl[$parentItem['itemid']])) { $exItem = $exItemsTpl[$parentItem['itemid']]; if (isset($exItemsKeys[$parentItem['key_']]) && !idcmp($exItemsKeys[$parentItem['key_']]['templateid'], $parentItem['itemid'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _params($this->getErrorMsg(self::ERROR_EXISTS), [$parentItem['key_'], $host['host']])); } } // update by key if (isset($exItemsKeys[$parentItem['key_']])) { $exItem = $exItemsKeys[$parentItem['key_']]; if ($exItem['templateid'] > 0 && !idcmp($exItem['templateid'], $parentItem['itemid'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _params($this->getErrorMsg(self::ERROR_EXISTS_TEMPLATE), [$parentItem['key_'], $host['host']])); } } if ($host['status'] == HOST_STATUS_TEMPLATE || !isset($parentItem['type'])) { unset($parentItem['interfaceid']); } elseif (isset($parentItem['type']) && isset($exItem) && $parentItem['type'] != $exItem['type'] || !isset($exItem)) { $interface = self::findInterfaceForItem($parentItem, $host['interfaces']); if (!empty($interface)) { $parentItem['interfaceid'] = $interface['interfaceid']; } elseif ($interface !== false) { self::exception(ZBX_API_ERROR_PARAMETERS, _params($this->getErrorMsg(self::ERROR_NO_INTERFACE), [$host['host'], $parentItem['key_']])); } } else { unset($parentItem['interfaceid']); } // copying item $newItem = $parentItem; $newItem['hostid'] = $host['hostid']; $newItem['templateid'] = $parentItem['itemid']; // setting item application if (isset($parentItem['applications'])) { $newItem['applications'] = get_same_applications_for_host($parentItem['applications'], $host['hostid']); } if ($parentItem['flags'] == ZBX_FLAG_DISCOVERY_PROTOTYPE && array_key_exists('applicationPrototypes', $parentItem)) { // Get discovery rule ID for current item prototype, if it is not yet set. if (array_key_exists('ruleid', $parentItem)) { $discovery_ruleid = $parentItem['ruleid']; } else { $discovery_ruleid = $discovery_rules[$parentItem['itemid']]['parent_itemid']; } $newItem['applicationPrototypes'] = []; $db_application_prototypes = DBfetchArray(DBselect('SELECT ap.application_prototypeid,ap.name' . ' FROM application_prototype ap' . ' WHERE ap.itemid=' . zbx_dbstr($discovery_ruleid) . ' AND ' . dbConditionString('ap.name', zbx_objectValues($parentItem['applicationPrototypes'], 'name')))); $db_application_prototypes = zbx_toHash($db_application_prototypes, 'name'); foreach ($parentItem['applicationPrototypes'] as $application_prototype) { $db_application_prototype = $db_application_prototypes[$application_prototype['name']]; $newItem['applicationPrototypes'][] = ['name' => $application_prototype['name'], 'templateid' => $db_application_prototype['application_prototypeid']]; } } if ($exItem) { $newItem['itemid'] = $exItem['itemid']; } else { unset($newItem['itemid']); } $newItems[] = $newItem; } } return $newItems; }
/** * Fetch data from DB. * If post SQL filtering is necessary, several queries will be executed. SQL limit is calculated so that minimum * amount of queries would be executed and minimum amount of unnecessary data retrieved. * * @param string $query SQL query * @param array $options API call parameters * * @return array */ protected function customFetch($query, array $options) { if ($this->requiresPostSqlFiltering($options)) { $offset = 0; // we think that taking twice as necessary elements in first query is fair guess, this cast to int as well $limit = $options['limit'] ? 2 * $options['limit'] : null; // we use $minLimit for setting minimum limit twice as big for each consecutive query to not run in lots // of queries for some cases $minLimit = $limit; $allElements = []; do { // fetch group of elements $elements = DBfetchArray(DBselect($query, $limit, $offset)); // we have potentially more elements $hasMore = $limit && count($elements) === $limit; $elements = $this->applyPostSqlFiltering($elements, $options); // truncate element set after post SQL filtering, if enough elements or more retrieved via SQL query if ($options['limit'] && count($allElements) + count($elements) >= $options['limit']) { $allElements += array_slice($elements, 0, $options['limit'] - count($allElements), true); break; } $allElements += $elements; // calculate $limit and $offset for next query if ($limit) { $offset += $limit; $minLimit *= 2; // take care of division by zero $elemCount = count($elements) ? count($elements) : 1; // we take $limit as $minLimit or reasonable estimate to get all necessary data in two queries // with high probability $limit = max($minLimit, round($limit / $elemCount * ($options['limit'] - count($allElements)) * 2)); } } while ($hasMore); return $allElements; } else { return DBfetchArray(DBselect($query, $options['limit'])); } }
/** * Update web scenario steps. * * @param $httpTest * @param $websteps */ protected function updateStepsReal($httpTest, $websteps) { $webstepsNames = zbx_objectValues($websteps, 'name'); if (!preg_grep('/' . ZBX_PREG_PARAMS . '/i', $webstepsNames)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Scenario step name should contain only printable characters.')); } // get all used keys $webstepids = zbx_objectValues($websteps, 'webstepid'); $dbKeys = DBfetchArray(DBselect('SELECT i.key_' . ' FROM items i,httpstepitem hi' . ' WHERE ' . dbConditionInt('hi.httpstepid', $webstepids) . ' AND hi.itemid=i.itemid')); $dbKeys = zbx_toHash($dbKeys, 'key_'); foreach ($websteps as $webstep) { if ($webstep['no'] <= 0) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Scenario step number cannot be less than 1.')); } DB::update('httpstep', array('values' => $webstep, 'where' => array('httpstepid' => $webstep['webstepid']))); // update item keys $itemids = array(); $stepitemsUpdate = $updateFields = array(); $dbStepItems = DBselect('SELECT i.itemid,hi.type' . ' FROM items i,httpstepitem hi' . ' WHERE hi.httpstepid=' . zbx_dbstr($webstep['webstepid']) . ' AND hi.itemid=i.itemid'); while ($stepitem = DBfetch($dbStepItems)) { $itemids[] = $stepitem['itemid']; if (isset($httpTest['name']) || $webstep['name']) { switch ($stepitem['type']) { case HTTPSTEP_ITEM_TYPE_IN: $updateFields['key_'] = 'web.test.in[' . $httpTest['name'] . ',' . $webstep['name'] . ',bps]'; break; case HTTPSTEP_ITEM_TYPE_TIME: $updateFields['key_'] = 'web.test.time[' . $httpTest['name'] . ',' . $webstep['name'] . ',resp]'; break; case HTTPSTEP_ITEM_TYPE_RSPCODE: $updateFields['key_'] = 'web.test.rspcode[' . $httpTest['name'] . ',' . $webstep['name'] . ']'; break; } } if (isset($dbKeys[$updateFields['key_']])) { unset($updateFields['key_']); } if (isset($httpTest['status'])) { $updateFields['status'] = HTTPTEST_STATUS_ACTIVE == $httpTest['status'] ? ITEM_STATUS_ACTIVE : ITEM_STATUS_DISABLED; } if (isset($httpTest['delay'])) { $updateFields['delay'] = $httpTest['delay']; } if (!empty($updateFields)) { $stepitemsUpdate[] = array('values' => $updateFields, 'where' => array('itemid' => $stepitem['itemid'])); } } DB::update('items', $stepitemsUpdate); // update application if (isset($httpTest['applicationid'])) { DB::update('items_applications', array('values' => array('applicationid' => $httpTest['applicationid']), 'where' => array('itemid' => $itemids))); } } }
case AUDIT_ACTION_LOGOUT: $action = _('Logout'); break; 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=' . zbx_dbstr($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'], ZBX_SORT_DOWN, new CUrl('auditlogs.php')); // get timeline unset($sqlWhere['from'], $sqlWhere['till']); $sql = 'SELECT MIN(a.clock) AS clock' . ' FROM auditlog a,users u' . ' WHERE a.userid=u.userid' . implode('', $sqlWhere); $firstAudit = DBfetch(DBselect($sql, $config['search_limit'] + 1)); $data['timeline'] = ['period' => $effectivePeriod, 'starttime' => date(TIMESTAMP_FORMAT, $firstAudit ? $firstAudit['clock'] : null), 'usertime' => isset($_REQUEST['stime']) ? date(TIMESTAMP_FORMAT, zbxDateToTime($data['stime']) + $effectivePeriod) : null]; // render view $auditView = new CView('administration.auditlogs.list', $data);
* Display */ $hostsWidget = new CWidget(); $pageFilter = new CPageFilter(array('groups' => array('real_hosts' => true, 'editable' => true), 'groupid' => get_request('groupid', null))); $_REQUEST['groupid'] = $pageFilter->groupid; $_REQUEST['hostid'] = get_request('hostid', 0); if ($_REQUEST['go'] == 'massupdate' && isset($_REQUEST['hosts'])) { $hostsWidget->addPageHeader(_('CONFIGURATION OF HOSTS')); $data = array('hosts' => get_request('hosts', array()), 'visible' => get_request('visible', array()), 'mass_replace_tpls' => get_request('mass_replace_tpls'), 'mass_clear_tpls' => get_request('mass_clear_tpls'), 'groups' => get_request('groups', array()), 'newgroup' => get_request('newgroup', ''), 'status' => get_request('status', HOST_STATUS_MONITORED), 'proxy_hostid' => get_request('proxy_hostid', ''), 'ipmi_authtype' => get_request('ipmi_authtype', -1), 'ipmi_privilege' => get_request('ipmi_privilege', 2), 'ipmi_username' => get_request('ipmi_username', ''), 'ipmi_password' => get_request('ipmi_password', ''), 'inventory_mode' => get_request('inventory_mode', HOST_INVENTORY_DISABLED), 'host_inventory' => get_request('host_inventory', array()), 'templates' => get_request('templates', array())); // sort templates natsort($data['templates']); // get groups $data['all_groups'] = API::HostGroup()->get(array('output' => API_OUTPUT_EXTEND, 'editable' => true)); order_result($data['all_groups'], 'name'); // get proxies $data['proxies'] = DBfetchArray(DBselect('SELECT h.hostid,h.host' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . andDbNode('h.hostid'))); order_result($data['proxies'], 'host'); // get inventories if ($data['inventory_mode'] != HOST_INVENTORY_DISABLED) { $data['inventories'] = getHostInventories(); $data['inventories'] = zbx_toHash($data['inventories'], 'db_field'); } // get templates data $data['linkedTemplates'] = null; if (!empty($data['templates'])) { $getLinkedTemplates = API::Template()->get(array('templateids' => $data['templates'], 'output' => array('templateid', 'name'))); foreach ($getLinkedTemplates as $getLinkedTemplate) { $data['linkedTemplates'][] = array('id' => $getLinkedTemplate['templateid'], 'name' => $getLinkedTemplate['name']); } } $hostForm = new CView('configuration.host.massupdate', $data);