当前位置: 首页>>代码示例>>PHP>>正文


PHP API::Item方法代码示例

本文整理汇总了PHP中API::Item方法的典型用法代码示例。如果您正苦于以下问题:PHP API::Item方法的具体用法?PHP API::Item怎么用?PHP API::Item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在API的用法示例。


在下文中一共展示了API::Item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doAction

 protected function doAction()
 {
     $sortField = $this->getInput('sort', CProfile::get('web.proxies.php.sort', 'host'));
     $sortOrder = $this->getInput('sortorder', CProfile::get('web.proxies.php.sortorder', ZBX_SORT_UP));
     CProfile::update('web.proxies.php.sort', $sortField, PROFILE_TYPE_STR);
     CProfile::update('web.proxies.php.sortorder', $sortOrder, PROFILE_TYPE_STR);
     $config = select_config();
     $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder, 'config' => ['max_in_table' => $config['max_in_table']]];
     $data['proxies'] = API::Proxy()->get(['output' => ['proxyid', 'host', 'status', 'lastaccess', 'tls_connect', 'tls_accept'], 'selectHosts' => ['hostid', 'name', 'status'], 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]);
     // sorting & paging
     order_result($data['proxies'], $sortField, $sortOrder);
     $url = (new CUrl('zabbix.php'))->setArgument('action', 'proxy.list');
     $data['paging'] = getPagingLine($data['proxies'], $sortOrder, $url);
     foreach ($data['proxies'] as &$proxy) {
         order_result($proxy['hosts'], 'name');
     }
     unset($proxy);
     // get proxy IDs for a *selected* page
     $proxyIds = array_keys($data['proxies']);
     if ($proxyIds) {
         // calculate performance
         $dbPerformance = DBselect('SELECT h.proxy_hostid,SUM(1.0/i.delay) AS qps' . ' FROM hosts h,items i' . ' WHERE h.hostid=i.hostid' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.delay<>0' . ' AND i.flags<>' . ZBX_FLAG_DISCOVERY_PROTOTYPE . ' AND ' . dbConditionInt('h.proxy_hostid', $proxyIds) . ' GROUP BY h.proxy_hostid');
         while ($performance = DBfetch($dbPerformance)) {
             $data['proxies'][$performance['proxy_hostid']]['perf'] = round($performance['qps'], 2);
         }
         // get items
         $items = API::Item()->get(['proxyids' => $proxyIds, 'groupCount' => true, 'countOutput' => true, 'webitems' => true, 'monitored' => true]);
         foreach ($items as $item) {
             $data['proxies'][$item['proxy_hostid']]['item_count'] = $item['rowscount'];
         }
     }
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Configuration of proxies'));
     $this->setResponse($response);
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:35,代码来源:CControllerProxyList.php

示例2: get

 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $error = null;
     $timeOffset = null;
     $timeZone = null;
     switch ($this->screenitem['style']) {
         case TIME_TYPE_HOST:
             $items = API::Item()->get(array('itemids' => $this->screenitem['resourceid'], 'selectHosts' => array('host'), 'output' => array('itemid', 'value_type')));
             $item = reset($items);
             $host = reset($item['hosts']);
             $lastValue = Manager::History()->getLast(array($item));
             if ($lastValue) {
                 $lastValue = reset($lastValue[$item['itemid']]);
                 $item['lastvalue'] = $lastValue['value'];
                 $item['lastclock'] = $lastValue['clock'];
             } else {
                 $item['lastvalue'] = '0';
                 $item['lastclock'] = '0';
             }
             $timeType = $host['host'];
             preg_match('/([+-]{1})([\\d]{1,2}):([\\d]{1,2})/', $item['lastvalue'], $arr);
             if (!empty($arr)) {
                 $timeZone = $arr[2] * SEC_PER_HOUR + $arr[3] * SEC_PER_MIN;
                 if ($arr[1] == '-') {
                     $timeZone = 0 - $timeZone;
                 }
             }
             if ($lastvalue = strtotime($item['lastvalue'])) {
                 $diff = time() - $item['lastclock'];
                 $timeOffset = $lastvalue + $diff;
             } else {
                 $error = _('NO DATA');
             }
             break;
         case TIME_TYPE_SERVER:
             $error = null;
             $timeType = _('SERVER');
             $timeOffset = time();
             $timeZone = date('Z');
             break;
         default:
             $error = null;
             $timeType = _('LOCAL');
             $timeOffset = null;
             $timeZone = null;
             break;
     }
     if ($this->screenitem['width'] > $this->screenitem['height']) {
         $this->screenitem['width'] = $this->screenitem['height'];
     }
     $item = new CFlashClock($this->screenitem['width'], $this->screenitem['height'], $this->action);
     $item->setTimeError($error);
     $item->setTimeType($timeType);
     $item->setTimeZone($timeZone);
     $item->setTimeOffset($timeOffset);
     $flashclockOverDiv = new CDiv(null, 'flashclock');
     $flashclockOverDiv->setAttribute('style', 'width: ' . $this->screenitem['width'] . 'px; height: ' . $this->screenitem['height'] . 'px;');
     return $this->getOutput(array($item, $flashclockOverDiv));
 }
开发者ID:davidmr001,项目名称:zatree-2.2,代码行数:64,代码来源:CScreenClock.php

示例3: is_script_success

function is_script_success($hostid, $script_itemkey)
{
    $items = API::Item()->get(array("hostids" => $hostid, "filter" => array("type" => ITEM_TYPE_EXTERNAL, "status" => HOST_STATUS_MONITORED), "search" => array("key_" => $script_itemkey), "output" => "extend"));
    if (!empty($items)) {
        $result = true;
        foreach ($items as $item) {
            $result = $result && empty($item["error"]) && $item["lastvalue"] == 0;
        }
    } else {
        $result = false;
    }
    return $result;
}
开发者ID:sogaoh,项目名称:hyclops,代码行数:13,代码来源:additional_func.inc.php

示例4: 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];
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:46,代码来源:CMenuPopupHelper.php

示例5: 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);
 }
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:44,代码来源:CMenuPopupHelper.php

示例6: getCreatedItemIds

 /**
  * Retrieves items created for item prototype given as resource for this screen item
  * and returns array of the item IDs, ordered by item name.
  *
  * @return array
  */
 protected function getCreatedItemIds()
 {
     if (!$this->createdItemIds) {
         $itemPrototype = $this->getItemPrototype();
         if ($itemPrototype) {
             // get all created (discovered) items for current host
             $allCreatedItems = API::Item()->get(array('output' => array('itemid', 'name', 'key_', 'hostid'), 'hostids' => array($itemPrototype['discoveryRule']['hostid']), 'selectItemDiscovery' => array('itemid', 'parent_itemid'), 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_CREATED)));
             // collect those items where parent item is item prototype selected for this screen item as resource
             $createdItems = array();
             foreach ($allCreatedItems as $item) {
                 if ($item['itemDiscovery']['parent_itemid'] == $itemPrototype['itemid']) {
                     $createdItems[] = $item;
                 }
             }
             $createdItems = CMacrosResolverHelper::resolveItemNames($createdItems);
             foreach ($createdItems as $item) {
                 $this->createdItemIds[$item['itemid']] = $item['name_expanded'];
             }
             natsort($this->createdItemIds);
             $this->createdItemIds = array_keys($this->createdItemIds);
         }
     }
     return $this->createdItemIds;
 }
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:30,代码来源:CScreenLldSimpleGraph.php

示例7: 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;
}
开发者ID:SandipSingh14,项目名称:Zabbix_,代码行数:56,代码来源:blocks.inc.php

示例8: array

$fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'httptestid' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'http_item_type' => array(T_ZBX_INT, O_OPT, null, null, null), 'name' => array(T_ZBX_STR, O_OPT, null, null, null), 'width' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null), 'ymin_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymax_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymin_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'ymax_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'legend' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showworkperiod' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showtriggers' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'graphtype' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'yaxismin' => array(T_ZBX_DBL, O_OPT, null, null, null), 'yaxismax' => array(T_ZBX_DBL, O_OPT, null, null, null), 'percent_left' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'percent_right' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'items' => array(T_ZBX_STR, O_OPT, null, null, null));
$isDataValid = check_fields($fields);
if ($httptestid = get_request('httptestid', false)) {
    $color = array('current' => 0, 0 => array('next' => '1'), 1 => array('color' => 'Red', 'next' => '2'), 2 => array('color' => 'Dark Green', 'next' => '3'), 3 => array('color' => 'Blue', 'next' => '4'), 4 => array('color' => 'Dark Yellow', 'next' => '5'), 5 => array('color' => 'Cyan', 'next' => '6'), 6 => array('color' => 'Gray', 'next' => '7'), 7 => array('color' => 'Dark Red', 'next' => '8'), 8 => array('color' => 'Green', 'next' => '9'), 9 => array('color' => 'Dark Blue', 'next' => '10'), 10 => array('color' => 'Yellow', 'next' => '11'), 11 => array('color' => 'Black', 'next' => '1'));
    $items = array();
    $dbItems = DBselect('SELECT i.itemid' . ' FROM httpstepitem hi,items i,httpstep hs' . ' WHERE i.itemid=hi.itemid' . ' AND hs.httptestid=' . $httptestid . ' AND hs.httpstepid=hi.httpstepid' . ' AND hi.type=' . get_request('http_item_type', HTTPSTEP_ITEM_TYPE_TIME) . ' ORDER BY hs.no DESC');
    while ($item = DBfetch($dbItems)) {
        $itemColor = $color[$color['current'] = $color[$color['current']]['next']]['color'];
        $items[] = array('itemid' => $item['itemid'], 'color' => $itemColor);
    }
    $httptest = get_httptest_by_httptestid($httptestid);
    $name = $httptest['name'];
} else {
    $items = get_request('items', array());
    asort_by_key($items, 'sortorder');
    $dbItems = API::Item()->get(array('webitems' => true, 'itemids' => zbx_objectValues($items, 'itemid'), 'nodeids' => get_current_nodeid(true), 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => true, 'filter' => array('flags' => null)));
    $dbItems = zbx_toHash($dbItems, 'itemid');
    foreach ($items as $item) {
        if (!isset($dbItems[$item['itemid']])) {
            access_deny();
        }
    }
    $name = get_request('name', '');
}
/*
 * Display
 */
if ($isDataValid) {
    $graph = new CChart(get_request('graphtype', GRAPH_TYPE_NORMAL));
    $graph->setHeader($name);
    navigation_bar_calc();
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:31,代码来源:chart3.php

示例9: dirname

** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
$page['file'] = 'chart.php';
$page['type'] = PAGE_TYPE_IMAGE;
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = array('itemid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), 'screenid' => array(T_ZBX_STR, O_OPT, null, null, null), 'period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'profileIdx' => array(T_ZBX_STR, O_OPT, null, null, null), 'profileIdx2' => array(T_ZBX_STR, O_OPT, null, null, null), 'updateProfile' => array(T_ZBX_STR, O_OPT, null, null, null), 'from' => array(T_ZBX_INT, O_OPT, null, '{}>=0', null), 'width' => array(T_ZBX_INT, O_OPT, null, '{}>0', null), 'height' => array(T_ZBX_INT, O_OPT, null, '{}>0', null), 'border' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null));
check_fields($fields);
/*
 * Permissions
 */
if (!DBfetch(DBselect('SELECT i.itemid FROM items i WHERE i.itemid=' . $_REQUEST['itemid']))) {
    show_error_message(_('No items defined.'));
}
$dbItems = API::Item()->get(array('itemids' => $_REQUEST['itemid'], 'webitems' => true, 'nodeids' => get_current_nodeid(true), 'filter' => array('flags' => null)));
if (empty($dbItems)) {
    access_deny();
}
/*
 * Display
 */
$timeline = CScreenBase::calculateTime(array('profileIdx' => get_request('profileIdx', 'web.screens'), 'profileIdx2' => get_request('profileIdx2'), 'updateProfile' => get_request('updateProfile', true), 'period' => get_request('period'), 'stime' => get_request('stime')));
$graph = new CChart();
$graph->setPeriod($timeline['period']);
$graph->setSTime($timeline['stime']);
if (isset($_REQUEST['from'])) {
    $graph->setFrom($_REQUEST['from']);
}
if (isset($_REQUEST['width'])) {
    $graph->setWidth($_REQUEST['width']);
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:31,代码来源:chart.php

示例10: validateInventoryLinks

 /**
  * Check, if items that are about to be inserted or updated violate the rule:
  * only one item can be linked to a inventory filed.
  * If everything is ok, function return true or throws Exception otherwise
  *
  * @static
  *
  * @param array $items
  * @param bool $update whether this is update operation
  *
  * @return bool
  */
 public static function validateInventoryLinks(array $items, $update = false)
 {
     // inventory link field is not being updated, or being updated to 0, no need to validate anything then
     foreach ($items as $i => $item) {
         if (!isset($item['inventory_link']) || $item['inventory_link'] == 0) {
             unset($items[$i]);
         }
     }
     if (zbx_empty($items)) {
         return true;
     }
     $possibleHostInventories = getHostInventories();
     if ($update) {
         // for successful validation we need three fields for each item: inventory_link, hostid and key_
         // problem is, that when we are updating an item, we might not have them, because they are not changed
         // so, we need to find out what is missing and use API to get the lacking info
         $itemsWithNoHostId = array();
         $itemsWithNoInventoryLink = array();
         $itemsWithNoKeys = array();
         foreach ($items as $item) {
             if (!isset($item['inventory_link'])) {
                 $itemsWithNoInventoryLink[$item['itemid']] = $item['itemid'];
             }
             if (!isset($item['hostid'])) {
                 $itemsWithNoHostId[$item['itemid']] = $item['itemid'];
             }
             if (!isset($item['key_'])) {
                 $itemsWithNoKeys[$item['itemid']] = $item['itemid'];
             }
         }
         $itemsToFind = array_merge($itemsWithNoHostId, $itemsWithNoInventoryLink, $itemsWithNoKeys);
         // are there any items with lacking info?
         if (!zbx_empty($itemsToFind)) {
             $missingInfo = API::Item()->get(array('output' => array('hostid', 'inventory_link', 'key_'), 'filter' => array('itemid' => $itemsToFind), 'nopermissions' => true));
             $missingInfo = zbx_toHash($missingInfo, 'itemid');
             // appending host ids, inventory_links and keys where they are needed
             foreach ($items as $i => $item) {
                 if (isset($missingInfo[$item['itemid']])) {
                     if (!isset($items[$i]['hostid'])) {
                         $items[$i]['hostid'] = $missingInfo[$item['itemid']]['hostid'];
                     }
                     if (!isset($items[$i]['inventory_link'])) {
                         $items[$i]['inventory_link'] = $missingInfo[$item['itemid']]['inventory_link'];
                     }
                     if (!isset($items[$i]['key_'])) {
                         $items[$i]['key_'] = $missingInfo[$item['itemid']]['key_'];
                     }
                 }
             }
         }
     }
     $hostids = zbx_objectValues($items, 'hostid');
     // getting all inventory links on every affected host
     $itemsOnHostsInfo = API::Item()->get(array('output' => array('key_', 'inventory_link', 'hostid'), 'filter' => array('hostid' => $hostids), 'nopermissions' => true));
     // now, changing array to: 'hostid' => array('key_'=>'inventory_link')
     $linksOnHostsCurr = array();
     foreach ($itemsOnHostsInfo as $info) {
         // 0 means no link - we are not interested in those ones
         if ($info['inventory_link'] != 0) {
             if (!isset($linksOnHostsCurr[$info['hostid']])) {
                 $linksOnHostsCurr[$info['hostid']] = array($info['key_'] => $info['inventory_link']);
             } else {
                 $linksOnHostsCurr[$info['hostid']][$info['key_']] = $info['inventory_link'];
             }
         }
     }
     $linksOnHostsFuture = array();
     foreach ($items as $item) {
         // checking if inventory_link value is a valid number
         if ($update || $item['value_type'] != ITEM_VALUE_TYPE_LOG) {
             // does inventory field with provided number exists?
             if (!isset($possibleHostInventories[$item['inventory_link']])) {
                 $maxVar = max(array_keys($possibleHostInventories));
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Item "%1$s" cannot populate a missing host inventory field number "%2$d". Choices are: from 0 (do not populate) to %3$d.', $item['name'], $item['inventory_link'], $maxVar));
             }
         }
         if (!isset($linksOnHostsFuture[$item['hostid']])) {
             $linksOnHostsFuture[$item['hostid']] = array($item['key_'] => $item['inventory_link']);
         } else {
             $linksOnHostsFuture[$item['hostid']][$item['key_']] = $item['inventory_link'];
         }
     }
     foreach ($linksOnHostsFuture as $hostId => $linkFuture) {
         if (isset($linksOnHostsCurr[$hostId])) {
             $futureSituation = array_merge($linksOnHostsCurr[$hostId], $linksOnHostsFuture[$hostId]);
         } else {
             $futureSituation = $linksOnHostsFuture[$hostId];
         }
//.........这里部分代码省略.........
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:101,代码来源:CItem.php

示例11: massAdd

 /**
  * Add Items to applications
  *
  * @param array $data
  * @param array $data['applications']
  * @param array $data['items']
  * @return boolean
  */
 public function massAdd($data)
 {
     if (empty($data['applications'])) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
     }
     $applications = zbx_toArray($data['applications']);
     $items = zbx_toArray($data['items']);
     $applicationids = zbx_objectValues($applications, 'applicationid');
     $itemids = zbx_objectValues($items, 'itemid');
     // validate permissions
     $appOptions = array('applicationids' => $applicationids, 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
     $allowedApplications = $this->get($appOptions);
     foreach ($applications as $application) {
         if (!isset($allowedApplications[$application['applicationid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
     }
     $allowedItems = API::Item()->get(array('itemids' => $itemids, 'editable' => true, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CHILD, ZBX_FLAG_DISCOVERY_CREATED))));
     foreach ($items as $num => $item) {
         if (!isset($allowedItems[$item['itemid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
     }
     $linkedDb = DBselect('SELECT ia.itemid,ia.applicationid' . ' FROM items_applications ia' . ' WHERE ' . dbConditionInt('ia.itemid', $itemids) . ' AND ' . dbConditionInt('ia.applicationid', $applicationids));
     while ($pair = DBfetch($linkedDb)) {
         $linked[$pair['applicationid']] = array($pair['itemid'] => $pair['itemid']);
     }
     $appsInsert = array();
     foreach ($applicationids as $applicationid) {
         foreach ($itemids as $inum => $itemid) {
             if (isset($linked[$applicationid]) && isset($linked[$applicationid][$itemid])) {
                 continue;
             }
             $appsInsert[] = array('itemid' => $itemid, 'applicationid' => $applicationid);
         }
     }
     DB::insert('items_applications', $appsInsert);
     foreach ($itemids as $inum => $itemid) {
         $dbChilds = DBselect('SELECT i.itemid,i.hostid FROM items i WHERE i.templateid=' . zbx_dbstr($itemid));
         while ($child = DBfetch($dbChilds)) {
             $dbApps = DBselect('SELECT a1.applicationid' . ' FROM applications a1,applications a2' . ' WHERE a1.name=a2.name' . ' AND a1.hostid=' . $child['hostid'] . ' AND ' . dbConditionInt('a2.applicationid', $applicationids));
             $childApplications = array();
             while ($app = DBfetch($dbApps)) {
                 $childApplications[] = $app;
             }
             $result = $this->massAdd(array('items' => $child, 'applications' => $childApplications));
             if (!$result) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot add items.');
             }
         }
     }
     return array('applicationids' => $applicationids);
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:61,代码来源:CApplication.php

示例12: order_result

    $proxies = API::proxy()->get(['output' => ['hostid', 'host'], 'preservekeys' => true]);
    order_result($proxies, 'host');
    $proxies[0] = ['host' => _('Server')];
    $table->setHeader([_('Proxy'), _('5 seconds'), _('10 seconds'), _('30 seconds'), _('1 minute'), _('5 minutes'), _('More than 10 minutes')]);
    $queueData = zbx_toHash($queueData, 'proxyid');
    foreach ($proxies as $proxyId => $proxy) {
        if (isset($queueData[$proxyId])) {
            $proxyData = $queueData[$proxyId];
        } else {
            $proxyData = ['delay5' => 0, 'delay10' => 0, 'delay30' => 0, 'delay60' => 0, 'delay300' => 0, 'delay600' => 0];
        }
        $table->addRow([$proxy['host'], getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $severityConfig, $proxyData['delay5'], !$proxyData['delay5']), getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $severityConfig, $proxyData['delay10'], !$proxyData['delay10']), getSeverityCell(TRIGGER_SEVERITY_WARNING, $severityConfig, $proxyData['delay30'], !$proxyData['delay30']), getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $severityConfig, $proxyData['delay60'], !$proxyData['delay60']), getSeverityCell(TRIGGER_SEVERITY_HIGH, $severityConfig, $proxyData['delay300'], !$proxyData['delay300']), getSeverityCell(TRIGGER_SEVERITY_DISASTER, $severityConfig, $proxyData['delay600'], !$proxyData['delay600'])]);
    }
} elseif ($config == QUEUE_DETAILS) {
    $queueData = zbx_toHash($queueData, 'itemid');
    $items = API::Item()->get(['output' => ['itemid', 'hostid', 'name', 'key_'], 'selectHosts' => ['name'], 'itemids' => array_keys($queueData), 'webitems' => true, 'preservekeys' => true]);
    $items = CMacrosResolverHelper::resolveItemNames($items);
    // get hosts for queue items
    $hostIds = zbx_objectValues($items, 'hostid');
    $hostIds = array_keys(array_flip($hostIds));
    $hosts = API::Host()->get(['output' => ['hostid', 'proxy_hostid'], 'hostids' => $hostIds, 'preservekeys' => true]);
    // get proxies for those hosts
    $proxyHostIds = [];
    foreach ($hosts as $host) {
        if ($host['proxy_hostid']) {
            $proxyHostIds[$host['proxy_hostid']] = $host['proxy_hostid'];
        }
    }
    if ($proxyHostIds) {
        $proxies = API::Proxy()->get(['proxyids' => $proxyHostIds, 'output' => ['proxyid', 'host'], 'preservekeys' => true]);
    }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:queue.php

示例13: array

if ($_REQUEST['form'] == 'full_clone') {
    // host applications
    $hostApps = API::Application()->get(array('hostids' => $_REQUEST['hostid'], 'inherited' => false, 'output' => array('name'), 'preservekeys' => true));
    if (!empty($hostApps)) {
        $applicationsList = array();
        foreach ($hostApps as $hostAppId => $hostApp) {
            $applicationsList[$hostAppId] = $hostApp['name'];
        }
        order_result($applicationsList);
        $listBox = new CListBox('applications', null, 8);
        $listBox->setAttribute('disabled', 'disabled');
        $listBox->addItems($applicationsList);
        $hostList->addRow(_('Applications'), $listBox);
    }
    // host items
    $hostItems = API::Item()->get(array('hostids' => $_REQUEST['hostid'], 'inherited' => false, 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL), 'output' => array('itemid', 'key_', 'name')));
    if (!empty($hostItems)) {
        $itemsList = array();
        foreach ($hostItems as $hostItem) {
            $itemsList[$hostItem['itemid']] = itemName($hostItem);
        }
        order_result($itemsList);
        $listBox = new CListBox('items', null, 8);
        $listBox->setAttribute('disabled', 'disabled');
        $listBox->addItems($itemsList);
        $hostList->addRow(_('Items'), $listBox);
    }
    // host triggers
    $hostTriggers = API::Trigger()->get(array('inherited' => false, 'hostids' => $_REQUEST['hostid'], 'output' => array('triggerid', 'description'), 'selectItems' => array('type'), 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL))));
    if (!empty($hostTriggers)) {
        $triggersList = array();
开发者ID:SandipSingh14,项目名称:Zabbix_,代码行数:31,代码来源:configuration.host.edit.php

示例14: deleteMissingItems

 /**
  * Deletes items from DB that are missing in XML.
  *
  * @return null
  */
 protected function deleteMissingItems()
 {
     if (!$this->options['items']['deleteMissing']) {
         return;
     }
     $processedHostIds = $this->importedObjectContainer->getHostIds();
     $processedTemplateIds = $this->importedObjectContainer->getTemplateIds();
     $processedHostIds = array_merge($processedHostIds, $processedTemplateIds);
     // no hosts or templates have been processed
     if (!$processedHostIds) {
         return;
     }
     $itemIdsXML = array();
     $allItems = $this->getFormattedItems();
     if ($allItems) {
         foreach ($allItems as $host => $items) {
             $hostId = $this->referencer->resolveHostOrTemplate($host);
             foreach ($items as $item) {
                 $itemId = $this->referencer->resolveItem($hostId, $item['key_']);
                 if ($itemId) {
                     $itemIdsXML[$itemId] = $itemId;
                 }
             }
         }
     }
     $dbItemIds = API::Item()->get(array('output' => array('itemid'), 'hostids' => $processedHostIds, 'preservekeys' => true, 'nopermissions' => true, 'inherited' => false, 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL)));
     $itemsToDelete = array_diff_key($dbItemIds, $itemIdsXML);
     if ($itemsToDelete) {
         API::Item()->delete(array_keys($itemsToDelete));
     }
     $this->referencer->refreshItems();
 }
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:37,代码来源:CConfigurationImport.php

示例15: 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;
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:82,代码来源:CDiscoveryRule.php


注:本文中的API::Item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。