本文整理汇总了PHP中API::Graph方法的典型用法代码示例。如果您正苦于以下问题:PHP API::Graph方法的具体用法?PHP API::Graph怎么用?PHP API::Graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::Graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCreatedGraphIds
/**
* Retrieves graphs created for graph prototype given as resource for this screen item
* and returns array of the graph IDs.
*
* @return array
*/
protected function getCreatedGraphIds()
{
if (!$this->createdGraphIds) {
$graphPrototype = $this->getGraphPrototype();
if ($graphPrototype) {
// Get all created (discovered) graphs for host of graph prototype.
$allCreatedGraphs = API::Graph()->get(['output' => ['graphid', 'name'], 'hostids' => [$graphPrototype['discoveryRule']['hostid']], 'selectGraphDiscovery' => ['graphid', 'parent_graphid'], 'expandName' => true, 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_CREATED]]);
// Collect those graph IDs where parent graph is graph prototype selected for
// this screen item as resource.
foreach ($allCreatedGraphs as $graph) {
if ($graph['graphDiscovery']['parent_graphid'] == $graphPrototype['graphid']) {
$this->createdGraphIds[$graph['graphid']] = $graph['name'];
}
}
natsort($this->createdGraphIds);
$this->createdGraphIds = array_keys($this->createdGraphIds);
}
}
return $this->createdGraphIds;
}
示例2: getFavouriteGraphs
/**
* Prepare data for favourite graphs menu popup.
*
* @return array
*/
public static function getFavouriteGraphs()
{
$graphs = [];
$simple_graphs = [];
$favourites = CFavorite::get('web.favorite.graphids');
if ($favourites) {
$graphids = [];
$itemids = [];
$db_graphs = [];
$db_items = [];
foreach ($favourites as $favourite) {
if ($favourite['source'] === 'itemid') {
$itemids[$favourite['value']] = true;
} else {
$graphids[$favourite['value']] = true;
}
}
if ($graphids) {
$db_graphs = API::Graph()->get(['output' => ['graphid', 'name'], 'selectHosts' => ['hostid', 'name'], 'expandName' => true, 'graphids' => array_keys($graphids), 'preservekeys' => true]);
}
if ($itemids) {
$db_items = API::Item()->get(['output' => ['itemid', 'hostid', 'name', 'key_'], 'selectHosts' => ['hostid', 'name'], 'itemids' => array_keys($itemids), 'webitems' => true, 'preservekeys' => true]);
$db_items = CMacrosResolverHelper::resolveItemNames($db_items);
}
foreach ($favourites as $favourite) {
$sourceid = $favourite['value'];
if ($favourite['source'] === 'itemid') {
if (array_key_exists($sourceid, $db_items)) {
$db_item = $db_items[$sourceid];
$simple_graphs[] = ['id' => $sourceid, 'label' => $db_item['hosts'][0]['name'] . NAME_DELIMITER . $db_item['name_expanded']];
}
} else {
if (array_key_exists($sourceid, $db_graphs)) {
$db_graph = $db_graphs[$sourceid];
$graphs[] = ['id' => $sourceid, 'label' => $db_graph['hosts'][0]['name'] . NAME_DELIMITER . $db_graph['name']];
}
}
}
}
return ['type' => 'favouriteGraphs', 'graphs' => $graphs, 'simpleGraphs' => $simple_graphs];
}
示例3: getFavouriteGraphs
/**
* Prepare data for favourite graphs menu popup.
*
* @return array
*/
public static function getFavouriteGraphs()
{
$graphs = $simpeGraphs = array();
$favourites = CFavorite::get('web.favorite.graphids');
if ($favourites) {
$graphIds = $itemIds = $dbGraphs = $dbItems = array();
foreach ($favourites as $favourite) {
if ($favourite['source'] === 'itemid') {
$itemIds[$favourite['value']] = $favourite['value'];
} else {
$graphIds[$favourite['value']] = $favourite['value'];
}
}
if ($graphIds) {
$dbGraphs = API::Graph()->get(array('output' => array('graphid', 'name'), 'selectHosts' => array('hostid', 'host'), 'expandName' => true, 'graphids' => $graphIds, 'preservekeys' => true));
}
if ($itemIds) {
$dbItems = API::Item()->get(array('output' => array('itemid', 'hostid', 'name', 'key_'), 'selectHosts' => array('hostid', 'host'), 'itemids' => $itemIds, 'webitems' => true, 'preservekeys' => true));
$dbItems = CMacrosResolverHelper::resolveItemNames($dbItems);
}
foreach ($favourites as $favourite) {
$sourceId = $favourite['value'];
if ($favourite['source'] === 'itemid') {
if (isset($dbItems[$sourceId])) {
$dbItem = $dbItems[$sourceId];
$dbHost = reset($dbItem['hosts']);
$simpeGraphs[] = array('id' => $sourceId, 'label' => $dbHost['host'] . NAME_DELIMITER . $dbItem['name_expanded']);
}
} else {
if (isset($dbGraphs[$sourceId])) {
$dbGraph = $dbGraphs[$sourceId];
$dbHost = reset($dbGraph['hosts']);
$graphs[] = array('id' => $sourceId, 'label' => $dbHost['host'] . NAME_DELIMITER . $dbGraph['name']);
}
}
}
}
return array('type' => 'favouriteGraphs', 'graphs' => $graphs, 'simpleGraphs' => $simpeGraphs);
}
示例4: array
// clone triggers
$triggers = API::Trigger()->get(array('output' => array('triggerid'), 'hostids' => $srcHostId, 'inherited' => false));
if ($triggers) {
if (!copyTriggersToHosts(zbx_objectValues($triggers, 'triggerid'), $hostId, $srcHostId)) {
throw new Exception();
}
}
// clone discovery rules
$discoveryRules = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $srcHostId, 'inherited' => false));
if ($discoveryRules) {
$copyDiscoveryRules = API::DiscoveryRule()->copy(array('discoveryids' => zbx_objectValues($discoveryRules, 'itemid'), 'hostids' => array($hostId)));
if (!$copyDiscoveryRules) {
throw new Exception();
}
}
$graphs = API::Graph()->get(array('hostids' => $srcHostId, 'selectItems' => array('type'), 'output' => API_OUTPUT_EXTEND, 'inherited' => false, 'selectHosts' => array('hostid'), 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL)));
foreach ($graphs as $graph) {
if (count($graph['hosts']) > 1) {
continue;
}
if (httpItemExists($graph['items'])) {
continue;
}
if (!copyGraphToHost($graph['graphid'], $hostId)) {
throw new Exception();
}
}
}
$result = DBend(true);
show_messages($result, $msgOk, $msgFail);
clearCookies($result);
示例5: copyGraphPrototypes
/**
* Copies all of the graphs from the source discovery to the target discovery rule.
*
* @throws APIException if graph saving fails
*
* @param array $srcDiscovery The source discovery rule to copy from
* @param array $dstDiscovery The target discovery rule to copy to
*
* @return array
*/
protected function copyGraphPrototypes(array $srcDiscovery, array $dstDiscovery)
{
// fetch source graphs
$srcGraphs = API::GraphPrototype()->get(array('discoveryids' => $srcDiscovery['itemid'], 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'selectHosts' => API_OUTPUT_REFER, 'preservekeys' => true));
if (!$srcGraphs) {
return array();
}
$srcItemIds = array();
foreach ($srcGraphs as $key => $graph) {
// skip graphs with items from multiple hosts
if (count($graph['hosts']) > 1) {
unset($srcGraphs[$key]);
continue;
}
// skip graphs with http items
if (httpItemExists($graph['gitems'])) {
unset($srcGraphs[$key]);
continue;
}
// save all used item ids to map them to the new items
foreach ($graph['gitems'] as $item) {
$srcItemIds[$item['itemid']] = $item['itemid'];
}
if ($graph['ymin_itemid']) {
$srcItemIds[$graph['ymin_itemid']] = $graph['ymin_itemid'];
}
if ($graph['ymax_itemid']) {
$srcItemIds[$graph['ymax_itemid']] = $graph['ymax_itemid'];
}
}
// fetch source items
$items = API::Item()->get(array('itemids' => $srcItemIds, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'filter' => array('flags' => null)));
$srcItems = array();
$itemKeys = array();
foreach ($items as $item) {
$srcItems[$item['itemid']] = $item;
$itemKeys[$item['key_']] = $item['key_'];
}
// fetch newly cloned items
$newItems = API::Item()->get(array('hostids' => $dstDiscovery['hostid'], 'filter' => array('key_' => $itemKeys, 'flags' => null), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
$items = array_merge($dstDiscovery['items'], $newItems);
$dstItems = array();
foreach ($items as $item) {
$dstItems[$item['key_']] = $item;
}
$dstGraphs = $srcGraphs;
foreach ($dstGraphs as &$graph) {
unset($graph['graphid']);
unset($graph['templateid']);
foreach ($graph['gitems'] as &$gitem) {
// replace the old item with the new one with the same key
$item = $srcItems[$gitem['itemid']];
$gitem['itemid'] = $dstItems[$item['key_']]['itemid'];
unset($gitem['gitemid'], $gitem['graphid']);
}
// replace the old axis items with the new one with the same key
if ($graph['ymin_itemid']) {
$yMinSrcItem = $srcItems[$graph['ymin_itemid']];
$graph['ymin_itemid'] = $dstItems[$yMinSrcItem['key_']]['itemid'];
}
if ($graph['ymax_itemid']) {
$yMaxSrcItem = $srcItems[$graph['ymax_itemid']];
$graph['ymax_itemid'] = $dstItems[$yMaxSrcItem['key_']]['itemid'];
}
}
// save graphs
$rs = API::Graph()->create($dstGraphs);
if (!$rs) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot clone graph prototypes.'));
}
return $rs;
}
示例6: make_graph_submenu
function make_graph_submenu()
{
$graphids = array();
$itemids = array();
$favGraphs = array();
$fav_graphs = CFavorite::get('web.favorite.graphids');
if (!$fav_graphs) {
return $favGraphs;
}
foreach ($fav_graphs as $favorite) {
if ('itemid' == $favorite['source']) {
$itemids[$favorite['value']] = $favorite['value'];
} else {
$graphids[$favorite['value']] = $favorite['value'];
}
}
if ($graphids) {
$options = array('graphids' => $graphids, 'selectHosts' => array('hostid', 'host'), 'output' => array('graphid', 'name'), 'expandName' => true);
$graphs = API::Graph()->get($options);
$graphs = zbx_toHash($graphs, 'graphid');
}
if ($itemids) {
$options = array('itemids' => $itemids, 'selectHosts' => array('hostid', 'host'), 'output' => array('itemid', 'name', 'key_'), 'webitems' => 1);
$items = API::Item()->get($options);
$items = zbx_toHash($items, 'itemid');
}
foreach ($fav_graphs as $favorite) {
$source = $favorite['source'];
$sourceid = $favorite['value'];
if ('itemid' == $source) {
if (!isset($items[$sourceid])) {
continue;
}
$item_added = true;
$item = $items[$sourceid];
$host = reset($item['hosts']);
$item['name'] = itemName($item);
$favGraphs[] = array('name' => $host['host'] . NAME_DELIMITER . $item['name'], 'favobj' => 'itemid', 'favid' => $sourceid, 'favaction' => 'remove');
} else {
if (!isset($graphs[$sourceid])) {
continue;
}
$graph_added = true;
$graph = $graphs[$sourceid];
$ghost = reset($graph['hosts']);
$favGraphs[] = array('name' => $ghost['host'] . NAME_DELIMITER . $graph['name'], 'favobj' => 'graphid', 'favid' => $sourceid, 'favaction' => 'remove');
}
}
if (isset($graph_added)) {
$favGraphs[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Graphs'), 'favobj' => 'graphid', 'favid' => 0, 'favaction' => 'remove');
}
if (isset($item_added)) {
$favGraphs[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Simple graphs'), 'favobj' => 'itemid', 'favid' => 0, 'favaction' => 'remove');
}
return $favGraphs;
}
示例7: Exception
throw new Exception();
}
// copy web scenarios
if (!copyHttpTests($cloneTemplateId, $templateId)) {
throw new Exception();
}
// copy triggers
$dbTriggers = API::Trigger()->get(array('output' => array('triggerid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
if ($dbTriggers) {
$result &= copyTriggersToHosts(zbx_objectValues($dbTriggers, 'triggerid'), $templateId, $cloneTemplateId);
if (!$result) {
throw new Exception();
}
}
// copy graphs
$dbGraphs = API::Graph()->get(array('output' => array('graphid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
foreach ($dbGraphs as $dbGraph) {
copyGraphToHost($dbGraph['graphid'], $templateId);
}
// copy discovery rules
$dbDiscoveryRules = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
if ($dbDiscoveryRules) {
$result &= API::DiscoveryRule()->copy(array('discoveryids' => zbx_objectValues($dbDiscoveryRules, 'itemid'), 'hostids' => array($templateId)));
if (!$result) {
throw new Exception();
}
}
// copy template screens
$dbTemplateScreens = API::TemplateScreen()->get(array('output' => array('screenid'), 'templateids' => $cloneTemplateId, 'preservekeys' => true, 'inherited' => false));
if ($dbTemplateScreens) {
$result &= API::TemplateScreen()->copy(array('screenIds' => zbx_objectValues($dbTemplateScreens, 'screenid'), 'templateIds' => $templateId));
示例8: copy_graph_to_host
/**
* Copy specified graph to specified host.
*
* @param $graphid
* @param $hostid
* @return array|bool
*/
function copy_graph_to_host($graphid, $hostid)
{
$graphs = API::Graph()->get(array('graphids' => $graphid, 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND));
$graph = reset($graphs);
$new_gitems = get_same_graphitems_for_host($graph['gitems'], $hostid);
if (!$new_gitems) {
$host = get_host_by_hostid($hostid);
info(_s('Skipped copying of graph "%1$s" to host "%2$s".', $graph['name'], $host['host']));
return false;
}
// retrieve actual ymax_itemid and ymin_itemid
if ($graph['ymax_itemid']) {
if ($itemid = get_same_item_for_host($graph['ymax_itemid'], $hostid)) {
$graph['ymax_itemid'] = $itemid;
}
}
if ($graph['ymin_itemid']) {
if ($itemid = get_same_item_for_host($graph['ymin_itemid'], $hostid)) {
$graph['ymin_itemid'] = $itemid;
}
}
$graph['gitems'] = $new_gitems;
unset($graph['templateid']);
$result = API::Graph()->create($graph);
return $result;
}
示例9: delete
/**
* Delete GraphPrototype.
*
* @param array $graphids
* @param bool $nopermissions
*
* @return array
*/
public function delete(array $graphids, $nopermissions = false)
{
if (empty($graphids)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
}
$delGraphs = $this->get(array('graphids' => $graphids, 'editable' => true, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
if (!$nopermissions) {
foreach ($graphids as $graphid) {
if (!isset($delGraphs[$graphid])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.'));
}
if ($delGraphs[$graphid]['templateid'] != 0) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('Cannot delete templated graphs.'));
}
}
}
$parentGraphids = $graphids;
do {
$dbGraphs = DBselect('SELECT g.graphid FROM graphs g WHERE ' . dbConditionInt('g.templateid', $parentGraphids));
$parentGraphids = array();
while ($dbGraph = DBfetch($dbGraphs)) {
$parentGraphids[] = $dbGraph['graphid'];
$graphids[] = $dbGraph['graphid'];
}
} while (!empty($parentGraphids));
$graphids = array_unique($graphids);
$createdGraphs = array();
$dbGraphs = DBselect('SELECT gd.graphid FROM graph_discovery gd WHERE ' . dbConditionInt('gd.parent_graphid', $graphids));
while ($graph = DBfetch($dbGraphs)) {
$createdGraphs[$graph['graphid']] = $graph['graphid'];
}
if (!empty($createdGraphs)) {
$result = API::Graph()->delete($createdGraphs, true);
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete graphs created by low level discovery.'));
}
}
DB::delete('screens_items', array('resourceid' => $graphids, 'resourcetype' => SCREEN_RESOURCE_LLD_GRAPH));
DB::delete('graphs', array('graphid' => $graphids));
foreach ($delGraphs as $graph) {
info(_s('Graph prototype "%s" deleted.', $graph['name']));
}
return array('graphids' => $graphids);
}
示例10: dirname
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/graphs.inc.php';
$page['file'] = 'chart6.php';
$page['type'] = PAGE_TYPE_IMAGE;
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array('graphid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), 'period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'profileIdx' => array(T_ZBX_STR, O_OPT, null, null, null), 'profileIdx2' => array(T_ZBX_STR, O_OPT, null, null, null), 'updateProfile' => array(T_ZBX_STR, O_OPT, null, null, null), 'border' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'width' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(20, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, P_NZERO, '{}>0', null), 'graph3d' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'legend' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null));
if (!check_fields($fields)) {
exit;
}
/*
* Permissions
*/
$dbGraph = API::Graph()->get(array('output' => API_OUTPUT_EXTEND, 'selectGraphItems' => array('itemid', 'calc_fnc', 'color', 'type'), 'selectHosts' => array('name'), 'graphids' => $_REQUEST['graphid']));
if (!$dbGraph) {
access_deny();
} else {
$dbGraph = reset($dbGraph);
}
/*
* Display
*/
$timeline = CScreenBase::calculateTime(array('profileIdx' => getRequest('profileIdx', 'web.screens'), 'profileIdx2' => getRequest('profileIdx2'), 'updateProfile' => getRequest('updateProfile', true), 'period' => getRequest('period'), 'stime' => getRequest('stime')));
$graph = new CPieGraphDraw($dbGraph['graphtype']);
$graph->setPeriod($timeline['period']);
$graph->setSTime($timeline['stime']);
if (isset($_REQUEST['border'])) {
$graph->setBorder(0);
}
示例11: checkUseInGraphAxis
/**
* Checks if any of the given items are used as min/max Y values in a graph.
*
* if there are graphs, that have an y*_itemid column set, but the
* y*_type column is not set to GRAPH_YAXIS_TYPE_ITEM_VALUE, the y*_itemid
* column will be set to NULL.
*
* If the $checkMax parameter is set to true, the items will be checked against
* max Y values, otherwise, they will be checked against min Y values.
*
* @throws APIException if any of the given items are used as min/max Y values in a graph.
*
* @param array $itemids An array of items IDs
* @param type $checkMax
*/
protected function checkUseInGraphAxis(array $itemids, $checkMax = false)
{
if ($checkMax) {
$filter = array('ymax_itemid' => $itemids);
$itemIdColumn = 'ymax_itemid';
$typeColumn = 'ymax_type';
} else {
$filter = array('ymin_itemid' => $itemids);
$itemIdColumn = 'ymin_itemid';
$typeColumn = 'ymin_type';
}
// make it work for both graphs and graph prototypes
$filter['flags'] = array(ZBX_FLAG_DISCOVERY_PROTOTYPE, ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED);
// check if the items are used in Y axis min/max values in any graphs
$graphs = API::Graph()->get(array('output' => array($itemIdColumn, $typeColumn, 'graphtype'), 'filter' => $filter));
$updateGraphs = array();
foreach ($graphs as &$graph) {
// check if Y type is actually set to GRAPH_YAXIS_TYPE_ITEM_VALUE
if ($graph[$typeColumn] == GRAPH_YAXIS_TYPE_ITEM_VALUE) {
if ($checkMax) {
self::exception(ZBX_API_ERROR_PARAMETERS, 'Could not delete these items because some of them are used as MAX values for graphs.');
} else {
self::exception(ZBX_API_ERROR_PARAMETERS, 'Could not delete these items because some of them are used as MIN values for graphs.');
}
} else {
$graph[$itemIdColumn] = null;
$updateGraphs[] = $graph;
}
}
// if there are graphs, that have an y*_itemid column set, but the
// y*_type column is not set to GRAPH_YAXIS_TYPE_ITEM_VALUE, set y*_itemid to NULL.
// Otherwise we won't be able to delete them.
if ($updateGraphs) {
API::Graph()->update($updateGraphs);
}
}
示例12: selectGraphs
/**
* Select graph IDs for previously added graph names.
*/
protected function selectGraphs()
{
if ($this->graphs) {
$this->graphsRefs = array();
$graphNames = array();
foreach ($this->graphs as $graphs) {
foreach ($graphs as $graph) {
$graphNames[$graph] = $graph;
}
}
$dbGraphs = API::Graph()->get(array('output' => array('graphid', 'name'), 'selectHosts' => array('hostid'), 'filter' => array('name' => $graphNames, 'flags' => null), 'editable' => true));
foreach ($dbGraphs as $dbGraph) {
foreach ($dbGraph['hosts'] as $host) {
$this->graphsRefs[$host['hostid']][$dbGraph['name']] = $dbGraph['graphid'];
}
}
}
}
示例13: get
/**
* Get Template data
*
* @param array $options
* @return array|boolean Template data as array or false if error
*/
public function get($options = array())
{
$result = array();
$nodeCheck = false;
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
// allowed columns for sorting
$sortColumns = array('hostid', 'host', 'name');
// allowed output options for [ select_* ] params
$subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
$sqlParts = array('select' => array('templates' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), 'where' => array('h.status=' . HOST_STATUS_TEMPLATE), 'group' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'parentTemplateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'triggerids' => null, 'with_items' => null, 'with_triggers' => null, 'with_graphs' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => '', 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectGroups' => null, 'selectHosts' => null, 'selectTemplates' => null, 'selectParentTemplates' => null, 'selectItems' => null, 'selectDiscoveries' => null, 'selectTriggers' => null, 'selectGraphs' => null, 'selectApplications' => null, 'selectMacros' => null, 'selectScreens' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
$options = zbx_array_merge($defOptions, $options);
if (is_array($options['output'])) {
unset($sqlParts['select']['templates']);
$dbTable = DB::getSchema('hosts');
$sqlParts['select']['hostid'] = 'h.hostid';
foreach ($options['output'] as $field) {
if ($field == 'templateid') {
continue;
}
if (isset($dbTable['fields'][$field])) {
$sqlParts['select'][$field] = 'h.' . $field;
}
}
$options['output'] = API_OUTPUT_CUSTOM;
}
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE h.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
}
// nodeids
$nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
// groupids
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['groupid'] = 'hg.groupid';
}
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
$sqlParts['where']['hgh'] = 'hg.hostid=h.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['hg'] = 'hg.groupid';
}
if (!$nodeCheck) {
$nodeCheck = true;
$sqlParts['where'][] = DBin_node('hg.groupid', $nodeids);
}
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
$sqlParts['where']['templateid'] = dbConditionInt('h.hostid', $options['templateids']);
if (!$nodeCheck) {
$nodeCheck = true;
$sqlParts['where'][] = DBin_node('h.hostid', $nodeids);
}
}
// parentTemplateids
if (!is_null($options['parentTemplateids'])) {
zbx_value2array($options['parentTemplateids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['parentTemplateid'] = 'ht.templateid as parentTemplateid';
}
$sqlParts['from']['hosts_templates'] = 'hosts_templates ht';
$sqlParts['where'][] = dbConditionInt('ht.templateid', $options['parentTemplateids']);
$sqlParts['where']['hht'] = 'h.hostid=ht.hostid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['templateid'] = 'ht.templateid';
}
if (!$nodeCheck) {
$nodeCheck = true;
$sqlParts['where'][] = DBin_node('ht.templateid', $nodeids);
}
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['linked_hostid'] = 'ht.hostid as linked_hostid';
}
$sqlParts['from']['hosts_templates'] = 'hosts_templates ht';
$sqlParts['where'][] = dbConditionInt('ht.hostid', $options['hostids']);
$sqlParts['where']['hht'] = 'h.hostid=ht.templateid';
if (!is_null($options['groupCount'])) {
$sqlParts['group']['ht'] = 'ht.hostid';
}
if (!$nodeCheck) {
$nodeCheck = true;
$sqlParts['where'][] = DBin_node('ht.hostid', $nodeids);
}
//.........这里部分代码省略.........
示例14: CComboBox
}
// append resource types to form list
$resourceTypeComboBox = new CComboBox('resourcetype', $resourceType, 'submit()');
$screenResources = screen_resources();
if ($this->data['screen']['templateid']) {
unset($screenResources[SCREEN_RESOURCE_DATA_OVERVIEW], $screenResources[SCREEN_RESOURCE_ACTIONS], $screenResources[SCREEN_RESOURCE_EVENTS], $screenResources[SCREEN_RESOURCE_HOSTS_INFO], $screenResources[SCREEN_RESOURCE_MAP], $screenResources[SCREEN_RESOURCE_SCREEN], $screenResources[SCREEN_RESOURCE_SERVER_INFO], $screenResources[SCREEN_RESOURCE_HOSTGROUP_TRIGGERS], $screenResources[SCREEN_RESOURCE_HOST_TRIGGERS], $screenResources[SCREEN_RESOURCE_SYSTEM_STATUS], $screenResources[SCREEN_RESOURCE_TRIGGERS_INFO], $screenResources[SCREEN_RESOURCE_TRIGGERS_OVERVIEW]);
}
$resourceTypeComboBox->addItems($screenResources);
$screenFormList->addRow(_('Resource'), $resourceTypeComboBox);
/*
* Screen item: Graph
*/
if ($resourceType == SCREEN_RESOURCE_GRAPH) {
$caption = '';
$id = 0;
$graphs = API::Graph()->get(array('graphids' => $resourceId, 'selectHosts' => array('hostid', 'name', 'status'), 'output' => API_OUTPUT_EXTEND));
if (!empty($graphs)) {
$id = $resourceId;
$graph = reset($graphs);
order_result($graph['hosts'], 'name');
$graph['host'] = reset($graph['hosts']);
$caption = $graph['host']['name'] . NAME_DELIMITER . $graph['name'];
$nodeName = get_node_name_by_elid($graph['host']['hostid']);
if (!zbx_empty($nodeName)) {
$caption = '(' . $nodeName . ') ' . $caption;
}
}
if ($this->data['screen']['templateid']) {
$selectButton = new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=graphs&srcfld1=graphid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&templated_hosts=1&only_hostid=' . $this->data['screen']['templateid'] . '&writeonly=1", 800, 450);', 'formlist');
} else {
$selectButton = new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=graphs&srcfld1=graphid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&real_hosts=1&with_graphs=1&writeonly=1", 800, 450);', 'formlist');
示例15: get
//.........这里部分代码省略.........
}
}
}
// hashing
$options['hostids'] = zbx_toHash($options['hostids']);
// adding screenitems
if (!is_null($options['selectScreenItems']) && str_in_array($options['selectScreenItems'], $subselectsAllowedOutputs)) {
$screensItems = array();
$dbSitems = DBselect('SELECT si.* FROM screens_items si WHERE ' . dbConditionInt('si.screenid', $screenids));
while ($sitem = DBfetch($dbSitems)) {
// sorting
$screensItems[$sitem['screenitemid']] = $sitem;
switch ($sitem['resourcetype']) {
case SCREEN_RESOURCE_GRAPH:
$graphids[$sitem['resourceid']] = $sitem['resourceid'];
break;
case SCREEN_RESOURCE_SIMPLE_GRAPH:
case SCREEN_RESOURCE_PLAIN_TEXT:
$itemids[$sitem['resourceid']] = $sitem['resourceid'];
break;
}
}
foreach ($screensItems as $sitem) {
if (!isset($result[$sitem['screenid']]['screenitems'])) {
$result[$sitem['screenid']]['screenitems'] = array();
}
$result[$sitem['screenid']]['screenitems'][] = $sitem;
}
}
// creating linkage of template -> real objects
if (!is_null($options['selectScreenItems']) && !is_null($options['hostids'])) {
// prepare graphs
if (!empty($graphids)) {
$tplGraphs = API::Graph()->get(array('output' => array('graphid', 'name'), 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true));
$dbGraphs = API::Graph()->get(array('output' => array('graphid', 'name'), 'hostids' => $options['hostids'], 'filter' => array('name' => zbx_objectValues($tplGraphs, 'name')), 'nopermissions' => true, 'preservekeys' => true));
$realGraphs = array();
foreach ($dbGraphs as $graph) {
$host = reset($graph['hosts']);
unset($graph['hosts']);
if (!isset($realGraphs[$host['hostid']])) {
$realGraphs[$host['hostid']] = array();
}
$realGraphs[$host['hostid']][$graph['name']] = $graph;
}
}
// prepare items
if (!empty($itemids)) {
$tplItems = API::Item()->get(array('output' => array('itemid', 'key_'), 'itemids' => $itemids, 'nopermissions' => true, 'preservekeys' => true));
$dbItems = API::Item()->get(array('output' => array('itemid', 'key_'), 'hostids' => $options['hostids'], 'filter' => array('key_' => zbx_objectValues($tplItems, 'key_')), 'nopermissions' => true, 'preservekeys' => true));
$realItems = array();
foreach ($dbItems as $item) {
unset($item['hosts']);
if (!isset($realItems[$item['hostid']])) {
$realItems[$item['hostid']] = array();
}
$realItems[$item['hostid']][$item['key_']] = $item;
}
}
}
if (is_null($options['countOutput']) || !is_null($options['countOutput']) && !is_null($options['groupCount'])) {
// creating copies of templated screens (inheritance)
// screenNum is needed due to we can't refer to screenid/hostid/templateid as they will repeat
$screenNum = 0;
$vrtResult = array();
foreach ($result as $screen) {
if (is_null($options['hostids']) || isset($options['hostids'][$screen['templateid']])) {