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


PHP CTemplate::get方法代码示例

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


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

示例1: massUpdate

 /**
  * Mass update hosts
  *
  * @param _array $hosts multidimensional array with Hosts data
  * @param array $hosts['hosts'] Array of Host objects to update
  * @param string $hosts['fields']['host'] Host name.
  * @param array $hosts['fields']['groupids'] HostGroup IDs add Host to.
  * @param int $hosts['fields']['port'] Port. OPTIONAL
  * @param int $hosts['fields']['status'] Host Status. OPTIONAL
  * @param int $hosts['fields']['useip'] Use IP. OPTIONAL
  * @param string $hosts['fields']['dns'] DNS. OPTIONAL
  * @param string $hosts['fields']['ip'] IP. OPTIONAL
  * @param int $hosts['fields']['proxy_hostid'] Proxy Host ID. OPTIONAL
  * @param int $hosts['fields']['useipmi'] Use IPMI. OPTIONAL
  * @param string $hosts['fields']['ipmi_ip'] IPMAI IP. OPTIONAL
  * @param int $hosts['fields']['ipmi_port'] IPMI port. OPTIONAL
  * @param int $hosts['fields']['ipmi_authtype'] IPMI authentication type. OPTIONAL
  * @param int $hosts['fields']['ipmi_privilege'] IPMI privilege. OPTIONAL
  * @param string $hosts['fields']['ipmi_username'] IPMI username. OPTIONAL
  * @param string $hosts['fields']['ipmi_password'] IPMI password. OPTIONAL
  * @return boolean
  */
 public static function massUpdate($data)
 {
     $hosts = zbx_toArray($data['hosts']);
     $hostids = zbx_objectValues($hosts, 'hostid');
     try {
         self::BeginTransaction(__METHOD__);
         $options = array('hostids' => $hostids, 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
         $upd_hosts = self::get($options);
         foreach ($hosts as $hnum => $host) {
             if (!isset($upd_hosts[$host['hostid']])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
             }
         }
         // CHECK IF HOSTS HAVE AT LEAST 1 GROUP {{{
         if (isset($data['groups']) && empty($data['groups'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'No groups for hosts');
         }
         // }}} CHECK IF HOSTS HAVE AT LEAST 1 GROUP
         // UPDATE HOSTS PROPERTIES {{{
         if (isset($data['host'])) {
             if (count($hosts) > 1) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot mass update host name');
             }
             $cur_host = reset($hosts);
             $options = array('filter' => array('host' => $cur_host['host']), 'output' => API_OUTPUT_SHORTEN, 'editable' => 1, 'nopermissions' => 1);
             $host_exists = self::get($options);
             $host_exist = reset($host_exists);
             if ($host_exist && $host_exist['hostid'] != $cur_host['hostid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, S_HOST . ' [ ' . $data['host'] . ' ] ' . S_ALREADY_EXISTS_SMALL);
             }
             //can't add host with the same name as existing template
             if (CTemplate::exists(array('host' => $cur_host['host']))) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, S_TEMPLATE . ' [ ' . $cur_host['host'] . ' ] ' . S_ALREADY_EXISTS_SMALL);
             }
         }
         if (isset($data['host']) && !preg_match('/^' . ZBX_PREG_HOST_FORMAT . '$/i', $data['host'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect characters used for Hostname [ ' . $data['host'] . ' ]');
         }
         if (isset($data['dns']) && !empty($data['dns']) && !preg_match('/^' . ZBX_PREG_DNS_FORMAT . '$/i', $data['dns'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect characters used for DNS [ ' . $data['dns'] . ' ]');
         }
         $sql_set = array();
         if (isset($data['proxy_hostid'])) {
             $sql_set[] = 'proxy_hostid=' . $data['proxy_hostid'];
         }
         if (isset($data['host'])) {
             $sql_set[] = 'host=' . zbx_dbstr($data['host']);
         }
         if (isset($data['port'])) {
             $sql_set[] = 'port=' . $data['port'];
         }
         if (isset($data['status'])) {
             $sql_set[] = 'status=' . $data['status'];
         }
         if (isset($data['useip'])) {
             $sql_set[] = 'useip=' . $data['useip'];
         }
         if (isset($data['dns'])) {
             $sql_set[] = 'dns=' . zbx_dbstr($data['dns']);
         }
         if (isset($data['ip'])) {
             $sql_set[] = 'ip=' . zbx_dbstr($data['ip']);
         }
         if (isset($data['useipmi'])) {
             $sql_set[] = 'useipmi=' . $data['useipmi'];
         }
         if (isset($data['ipmi_port'])) {
             $sql_set[] = 'ipmi_port=' . $data['ipmi_port'];
         }
         if (isset($data['ipmi_authtype'])) {
             $sql_set[] = 'ipmi_authtype=' . $data['ipmi_authtype'];
         }
         if (isset($data['ipmi_privilege'])) {
             $sql_set[] = 'ipmi_privilege=' . $data['ipmi_privilege'];
         }
         if (isset($data['ipmi_username'])) {
             $sql_set[] = 'ipmi_username=' . zbx_dbstr($data['ipmi_username']);
         }
//.........这里部分代码省略.........
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,代码来源:class.chost.php

示例2: array

$wdgt_hgroups->setClass('header');
$wdgt_hgroups->addHeader(S_HOST_GROUPS, SPACE);
$right_tab->addRow($wdgt_hgroups);
//----------------
// FIND Templates
if ($admin) {
    $params = array('nodeids' => get_current_nodeid(true), 'search' => array('host' => $search), 'output' => API_OUTPUT_EXTEND, 'select_groups' => API_OUTPUT_REFER, 'sortfield' => 'host', 'select_items' => API_OUTPUT_COUNT, 'select_triggers' => API_OUTPUT_COUNT, 'select_graphs' => API_OUTPUT_COUNT, 'select_applications' => API_OUTPUT_COUNT, 'limit' => $rows_per_page);
    $db_templates = CTemplate::get($params);
    order_result($db_templates, 'host');
    $templates = selectByPattern($db_templates, 'host', $search, $rows_per_page);
    $templateids = zbx_objectValues($templates, 'templateid');
    $params = array('nodeids' => get_current_nodeid(true), 'templateids' => $templateids, 'editable' => 1);
    $rw_templates = CTemplate::get($params);
    $rw_templates = zbx_toHash($rw_templates, 'templateid');
    $params = array('nodeids' => get_current_nodeid(true), 'search' => array('host' => $search), 'countOutput' => 1, 'editable' => 1);
    $overalCount = CTemplate::get($params);
    $viewCount = count($templates);
    $header = array(ZBX_DISTRIBUTED ? new CCol(S_NODE) : null, new CCol(S_TEMPLATES), new CCol(S_APPLICATIONS), new CCol(S_ITEMS), new CCol(S_TRIGGERS), new CCol(S_GRAPHS));
    $table = new CTableInfo();
    $table->setHeader($header);
    foreach ($templates as $tnum => $template) {
        $templateid = $template['hostid'];
        $group = reset($template['groups']);
        $link = 'groupid=' . $group['groupid'] . '&hostid=' . $templateid . '&switch_node=' . id2nodeid($templateid);
        $caption = make_decoration($template['host'], $search);
        if (isset($rw_templates[$templateid])) {
            $template_link = new CLink($caption, 'templates.php?form=update&' . '&templateid=' . $templateid . '&switch_node=' . id2nodeid($templateid));
            $applications_link = array(new CLink(S_APPLICATIONS, 'applications.php?' . $link), ' (' . $template['applications'] . ')');
            $items_link = array(new CLink(S_ITEMS, 'items.php?' . $link), ' (' . $template['items'] . ')');
            $triggers_link = array(new CLink(S_TRIGGERS, 'triggers.php?' . $link), ' (' . $template['triggers'] . ')');
            $graphs_link = array(new CLink(S_GRAPHS, 'graphs.php?' . $link), ' (' . $template['graphs'] . ')');
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:31,代码来源:search.php

示例3: array

$right_tab->addRow($wdgt_hgroups);
//----------------
// FIND Templates
if ($admin) {
    $params = array('nodeid' => get_current_nodeid(), 'extendoutput' => 1, 'pattern' => $search, 'limit' => $rows_per_page, 'order' => 'host', 'editable' => 1);
    $db_templates = CTemplate::get($params);
    $templates = selectByPattern($db_templates, 'host', $search, $rows_per_page);
    $templateids = array_keys($templates);
    $hostsgroups = array();
    $sql = 'SELECT * FROM hosts_groups hg WHERE ' . DBcondition('hg.hostid', $templateids);
    $res = DBselect($sql);
    while ($templategroup = DBfetch($res)) {
        $hostsgroups[$templategroup['hostid']] = $templategroup['groupid'];
    }
    $params = array('nodeids' => get_current_nodeid(), 'pattern' => $search, 'count' => 1, 'editable' => 1);
    $hosts_count = CTemplate::get($params);
    $overalCount = $hosts_count['rowscount'];
    $viewCount = count($templates);
    $header = array(is_show_all_nodes() ? new CCol(S_NODE) : null, new CCol(S_TEMPLATES), new CCol(S_ITEMS), new CCol(S_TRIGGERS), new CCol(S_GRAPHS));
    $table = new CTableInfo();
    $table->setHeader($header);
    foreach ($templates as $num => $template) {
        $templateid = $template['hostid'];
        $groupid = isset($hostsgroups[$templateid]) ? $hostsgroups[$templateid] : 0;
        $link = 'groupid=' . $groupid . '&hostid=' . $templateid;
        $caption = make_decoration($template['host'], $search);
        $table->addRow(array(get_node_name_by_elid($templateid), new CLink($caption, 'hosts.php?config=3&hostid=' . $templateid), new CLink(S_GO, 'items.php?' . $link), new CLink(S_GO, 'triggers.php?' . $link), new CLink(S_GO, 'graphs.php?' . $link)));
    }
    $table->setFooter(new CCol(S_DISPLAYING . SPACE . $viewCount . SPACE . S_OF_SMALL . SPACE . $overalCount . SPACE . S_FOUND_SMALL));
    $wdgt_templates = new CWidget('search_templates', $table);
    $wdgt_templates->addHeader(S_TEMPLATES, SPACE);
开发者ID:phedders,项目名称:zabbix,代码行数:31,代码来源:search.php

示例4: template

 private static function template($action, $params)
 {
     CTemplate::$error = array();
     switch ($action) {
         case 'add':
             $result = CTemplate::add($params);
             break;
         case 'get':
             $result = CTemplate::get($params);
             break;
         case 'getById':
             $result = CTemplate::getById($params);
             break;
         case 'getId':
             $result = CTemplate::getId($params);
             break;
         case 'update':
             $result = CTemplate::update($params);
             break;
         case 'linkHosts':
             $result = CTemplate::linkHosts($params);
             break;
         case 'unlinkHosts':
             $result = CTemplate::unlinkHosts($params);
             break;
         case 'linkTemplates':
             $result = CTemplate::linkTemplates($params);
             break;
         case 'unlinkTemplates':
             $result = CTemplate::unlinkTemplates($params);
             break;
         case 'delete':
             $result = CTemplate::delete($params);
             break;
         default:
             self::$result = array('error' => ZBX_API_ERROR_NO_METHOD, 'data' => 'Method: "' . $action . '" doesn\'t exist.');
             return;
             //exit function
     }
     if ($result !== false) {
         self::$result = array('result' => $result);
     } else {
         self::$result = CTemplate::$error;
     }
 }
开发者ID:phedders,项目名称:zabbix,代码行数:45,代码来源:class.czbxrpc.php

示例5: get

 /**
  * Get graph data
  *
  * <code>
  * $options = array(
  *	array 'graphids'				=> array(graphid1, graphid2, ...),
  *	array 'itemids'					=> array(itemid1, itemid2, ...),
  *	array 'hostids'					=> array(hostid1, hostid2, ...),
  *	int 'type'					=> 'graph type, chart/pie'
  *	boolean 'templated_graphs'			=> 'only templated graphs',
  *	int 'count'					=> 'count',
  *	string 'pattern'				=> 'search hosts by pattern in graph names',
  *	integer 'limit'					=> 'limit selection',
  *	string 'order'					=> 'depricated parameter (for now)'
  * );
  * </code>
  *
  * @static
  * @param array $options
  * @return array|boolean host data as array or false if error
  */
 public static function get($options = array())
 {
     global $USER_DETAILS;
     $result = array();
     $user_type = $USER_DETAILS['type'];
     $userid = $USER_DETAILS['userid'];
     $result = array();
     $sort_columns = array('graphid');
     // allowed columns for sorting
     $sql_parts = array('select' => array('graphs' => 'g.graphid'), 'from' => array('graphs g'), 'where' => array(), 'order' => array(), 'limit' => null);
     $def_options = array('nodeids' => 0, 'groupids' => 0, 'hostids' => 0, 'graphids' => 0, 'itemids' => 0, 'type' => 0, 'templated_graphs' => 0, 'editable' => 0, 'nopermission' => 0, 'select_hosts' => 0, 'select_templates' => 0, 'select_items' => 0, 'extendoutput' => 0, 'count' => 0, 'pattern' => '', 'limit' => 0, 'order' => '');
     $options = array_merge($def_options, $options);
     // editable + PERMISSION CHECK
     if (defined('ZBX_API_REQUEST')) {
         $options['nopermissions'] = false;
     }
     if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) {
     } else {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $sql_parts['from']['gi'] = 'graphs_items gi';
         $sql_parts['from']['i'] = 'items i';
         $sql_parts['from']['hg'] = 'hosts_groups hg';
         $sql_parts['from']['r'] = 'rights r';
         $sql_parts['from']['ug'] = 'users_groups ug';
         $sql_parts['where']['gig'] = 'gi.graphid=g.graphid';
         $sql_parts['where']['igi'] = 'i.itemid=gi.itemid';
         $sql_parts['where']['hgi'] = 'hg.hostid=i.hostid';
         $sql_parts['where'][] = 'r.id=hg.groupid ';
         $sql_parts['where'][] = 'r.groupid=ug.usrgrpid';
         $sql_parts['where'][] = 'ug.userid=' . $userid;
         $sql_parts['where'][] = 'r.permission>=' . $permission;
         $sql_parts['where'][] = 'NOT EXISTS( ' . ' SELECT gii.graphid ' . ' FROM graphs_items gii, items ii ' . ' WHERE gii.graphid=g.graphid ' . ' AND gii.itemid=ii.itemid ' . ' AND EXISTS( ' . ' SELECT hgg.groupid ' . ' FROM hosts_groups hgg, rights rr, users_groups ugg ' . ' WHERE ii.hostid=hgg.hostid ' . ' AND rr.id=hgg.groupid ' . ' AND rr.groupid=ugg.usrgrpid ' . ' AND ugg.userid=' . $userid . ' AND rr.permission<' . $permission . '))';
     }
     // nodeids
     $nodeids = $options['nodeids'] ? $options['nodeids'] : get_current_nodeid(false);
     // groupids
     if ($options['groupids'] != 0) {
         zbx_value2array($options['groupids']);
         if ($options['extendoutput'] != 0) {
             $sql_parts['select']['groupid'] = 'hg.groupid';
         }
         $sql_parts['from']['gi'] = 'graphs_items gi';
         $sql_parts['from']['i'] = 'items i';
         $sql_parts['from']['hg'] = 'hosts_groups hg';
         $sql_parts['where'][] = DBcondition('hg.groupid', $options['groupids']);
         $sql_parts['where'][] = 'hg.hostid=i.hostid';
         $sql_parts['where']['gig'] = 'gi.graphid=g.graphid';
         $sql_parts['where']['igi'] = 'i.itemid=gi.itemid';
         $sql_parts['where']['hgi'] = 'hg.hostid=i.hostid';
     }
     // hostids
     if ($options['hostids'] != 0) {
         zbx_value2array($options['hostids']);
         if ($options['extendoutput'] != 0) {
             $sql_parts['select']['hostid'] = 'i.hostid';
         }
         $sql_parts['from']['gi'] = 'graphs_items gi';
         $sql_parts['from']['i'] = 'items i';
         $sql_parts['where'][] = DBcondition('i.hostid', $options['hostids']);
         $sql_parts['where']['gig'] = 'gi.graphid=g.graphid';
         $sql_parts['where']['igi'] = 'i.itemid=gi.itemid';
     }
     // graphids
     if ($options['graphids'] != 0) {
         $sql_parts['where'][] = DBcondition('g.graphid', $options['graphids']);
     }
     // itemids
     if ($options['itemids'] != 0) {
         zbx_value2array($options['itemids']);
         if ($options['extendoutput'] != 0) {
             $sql_parts['select']['itemid'] = 'gi.itemid';
         }
         $sql_parts['from']['gi'] = 'graphs_items gi';
         $sql_parts['where']['gig'] = 'gi.graphid=g.graphid';
         $sql_parts['where'][] = DBcondition('gi.itemid', $options['itemids']);
     }
     // type
     if ($options['type'] != 0) {
         $sql_parts['where'][] = 'g.type=' . $options['type'];
//.........这里部分代码省略.........
开发者ID:phedders,项目名称:zabbix,代码行数:101,代码来源:class.cgraph.php

示例6: get

 /**
  * Get items data
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @param array $options
  * @param array $options['itemids']
  * @param array $options['hostids']
  * @param array $options['groupids']
  * @param array $options['triggerids']
  * @param array $options['applicationids']
  * @param boolean $options['status']
  * @param boolean $options['templated_items']
  * @param boolean $options['editable']
  * @param boolean $options['count']
  * @param string $options['pattern']
  * @param int $options['limit']
  * @param string $options['order']
  * @return array|int item data as array or false if error
  */
 public static function get($options = array())
 {
     global $USER_DETAILS;
     $result = array();
     $user_type = $USER_DETAILS['type'];
     $userid = $USER_DETAILS['userid'];
     $sort_columns = array('itemid', 'description', 'key_', 'delay', 'history', 'trends', 'type', 'status');
     // allowed columns for sorting
     $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     // allowed output options for [ select_* ] params
     $sql_parts = array('select' => array('items' => 'i.itemid'), 'from' => array('items' => 'items i'), 'where' => array('webtype' => 'i.type<>9'), 'group' => array(), 'order' => array(), 'limit' => null);
     $def_options = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'proxyids' => null, 'itemids' => null, 'graphids' => null, 'triggerids' => null, 'applicationids' => null, 'webitems' => null, 'inherited' => null, 'templated' => null, 'monitored' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'group' => null, 'host' => null, 'application' => null, 'belongs' => null, 'with_triggers' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'output' => API_OUTPUT_REFER, 'extendoutput' => null, 'select_hosts' => null, 'select_triggers' => null, 'select_graphs' => null, 'select_applications' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($def_options, $options);
     if (!is_null($options['extendoutput'])) {
         $options['output'] = API_OUTPUT_EXTEND;
         if (!is_null($options['select_hosts'])) {
             $options['select_hosts'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_triggers'])) {
             $options['select_triggers'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_graphs'])) {
             $options['select_graphs'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_applications'])) {
             $options['select_applications'] = API_OUTPUT_EXTEND;
         }
     }
     // editable + PERMISSION CHECK
     if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) {
     } else {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $sql_parts['from']['hosts_groups'] = 'hosts_groups hg';
         $sql_parts['from']['rights'] = 'rights r';
         $sql_parts['from']['users_groups'] = 'users_groups ug';
         $sql_parts['where'][] = 'hg.hostid=i.hostid';
         $sql_parts['where'][] = 'r.id=hg.groupid ';
         $sql_parts['where'][] = 'r.groupid=ug.usrgrpid';
         $sql_parts['where'][] = 'ug.userid=' . $userid;
         $sql_parts['where'][] = 'r.permission>=' . $permission;
         $sql_parts['where'][] = 'NOT EXISTS( ' . ' SELECT hgg.groupid ' . ' FROM hosts_groups hgg, rights rr, users_groups gg ' . ' WHERE hgg.hostid=hg.hostid ' . ' AND rr.id=hgg.groupid ' . ' AND rr.groupid=gg.usrgrpid ' . ' AND gg.userid=' . $userid . ' AND rr.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) {
             $sql_parts['select']['groupid'] = 'hg.groupid';
         }
         $sql_parts['from']['hosts_groups'] = 'hosts_groups hg';
         $sql_parts['where'][] = DBcondition('hg.groupid', $options['groupids']);
         $sql_parts['where'][] = 'hg.hostid=i.hostid';
         if (!is_null($options['groupCount'])) {
             $sql_parts['group']['hg'] = 'hg.groupid';
         }
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (!is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_EXTEND) {
             $sql_parts['select']['hostid'] = 'i.hostid';
         }
         $sql_parts['where']['hostid'] = DBcondition('i.hostid', $options['hostids']);
         if (!is_null($options['groupCount'])) {
             $sql_parts['group']['i'] = 'i.hostid';
//.........这里部分代码省略.........
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,代码来源:class.citem.php

示例7: massUpdate

 /**
  * Update HostGroups with new Hosts (rewrite)
  *
  * @param array $data
  * @param array $data['groups']
  * @param array $data['hosts']
  * @param array $data['templates']
  * @return boolean
  */
 public static function massUpdate($data)
 {
     $groups = zbx_toArray($data['groups']);
     $hosts = isset($data['hosts']) ? zbx_toArray($data['hosts']) : null;
     $templates = isset($data['templates']) ? zbx_toArray($data['templates']) : null;
     $groupids = zbx_objectValues($groups, 'groupid');
     $hostids = zbx_objectValues($hosts, 'hostid');
     $templateids = zbx_objectValues($templates, 'templateid');
     try {
         self::BeginTransaction(__METHOD__);
         $hosts_to_unlink = $hosts_to_link = array();
         $options = array('groupids' => $groupids, 'preservekeys' => 1);
         if (!is_null($hosts)) {
             $groups_hosts = CHost::get($options);
             $hosts_to_unlink = array_diff(array_keys($groups_hosts), $hostids);
             $hosts_to_link = array_diff($hostids, array_keys($groups_hosts));
         }
         $templates_to_unlink = $templates_to_link = array();
         if (!is_null($templates)) {
             $groups_templates = CTemplate::get($options);
             $templates_to_unlink = array_diff(array_keys($groups_templates), $templateids);
             $templates_to_link = array_diff($templateids, array_keys($groups_templates));
         }
         $objectids_to_link = array_merge($hosts_to_link, $templates_to_link);
         $objectids_to_unlink = array_merge($hosts_to_unlink, $templates_to_unlink);
         // PERMISSION {{{
         $options = array('groupids' => $groupids, 'editable' => 1, 'preservekeys' => 1);
         $allowed_groups = self::get($options);
         foreach ($groups as $num => $group) {
             if (!isset($allowed_groups[$group['groupid']])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
             }
         }
         if (!is_null($hosts)) {
             $hosts_to_check = array_merge($hosts_to_link, $hosts_to_unlink);
             $options = array('hostids' => $hosts_to_check, 'editable' => 1, 'preservekeys' => 1);
             $allowed_hosts = CHost::get($options);
             foreach ($hosts_to_check as $num => $hostid) {
                 if (!isset($allowed_hosts[$hostid])) {
                     self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
                 }
             }
         }
         if (!is_null($templates)) {
             $templates_to_check = array_merge($templates_to_link, $templates_to_unlink);
             $options = array('templateids' => $templates_to_check, 'editable' => 1, 'preservekeys' => 1);
             $allowed_templates = CTemplate::get($options);
             foreach ($templates_to_check as $num => $templateid) {
                 if (!isset($allowed_templates[$templateid])) {
                     self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
                 }
             }
         }
         // }}} PERMISSION
         $unlinkable = getUnlinkableHosts($groupids, $objectids_to_unlink);
         if (count($objectids_to_unlink) != count($unlinkable)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'One of the Objects is left without Hostgroup');
         }
         $sql = 'DELETE FROM hosts_groups WHERE ' . DBcondition('groupid', $groupids) . ' AND ' . DBcondition('hostid', $objectids_to_unlink);
         if (!DBexecute($sql)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
         }
         foreach ($groupids as $gnum => $groupid) {
             foreach ($objectids_to_link as $objectid) {
                 $hostgroupid = get_dbid('hosts_groups', 'hostgroupid');
                 $result = DBexecute("INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ({$hostgroupid}, {$objectid}, {$groupid})");
                 if (!$result) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
                 }
             }
         }
         self::EndTransaction(true, __METHOD__);
         return array('groupids' => $groupids);
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:90,代码来源:class.chostgroup.php

示例8: getMacros

 public static function getMacros($macros, $options)
 {
     zbx_value2array($macros);
     $macros = array_unique($macros);
     $result = array();
     $obj_options = array('itemids' => isset($options['itemid']) ? $options['itemid'] : null, 'triggerids' => isset($options['triggerid']) ? $options['triggerid'] : null, 'nopermissions' => 1, 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN, 'templated_hosts' => true);
     $hosts = CHost::get($obj_options);
     $hostids = array_keys($hosts);
     do {
         $obj_options = array('hostids' => $hostids, 'macros' => $macros, 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1, 'preservekeys' => 1);
         $host_macros = self::get($obj_options);
         order_result($host_macros, 'hostid');
         foreach ($macros as $mnum => $macro) {
             foreach ($host_macros as $hmnum => $hmacro) {
                 if ($macro == $hmacro['macro']) {
                     $result[$macro] = $hmacro['value'];
                     unset($host_macros[$hmnum], $macros[$mnum]);
                     break;
                 }
             }
         }
         if (!empty($macros)) {
             $obj_options = array('hostids' => $hostids, 'nopermissions' => 1, 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN);
             $hosts = CTemplate::get($obj_options);
             $hostids = array_keys($hosts);
         }
     } while (!empty($macros) && !empty($hostids));
     if (!empty($macros)) {
         $obj_options = array('output' => API_OUTPUT_EXTEND, 'globalmacro' => 1, 'nopermissions' => 1, 'macros' => $macros);
         $gmacros = self::get($obj_options);
         foreach ($macros as $macro) {
             foreach ($gmacros as $mid => $gmacro) {
                 if ($macro == $gmacro['macro']) {
                     $result[$macro] = $gmacro['value'];
                     unset($gmacros[$mid]);
                     break;
                 }
             }
         }
     }
     return $result;
 }
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:42,代码来源:class.cusermacro.php

示例9: validate_operation

function validate_operation($operation)
{
    if (isset($operation['esc_period']) && ($operation['esc_period'] > 0 && $operation['esc_period'] < 60)) {
        error(S_INCORRECT_ESCALATION_PERIOD);
        return false;
    }
    switch ($operation['operationtype']) {
        case OPERATION_TYPE_MESSAGE:
            switch ($operation['object']) {
                case OPERATION_OBJECT_USER:
                    $users = CUser::get(array('userids' => $operation['objectid'], 'output' => API_OUTPUT_EXTEND));
                    if (empty($users)) {
                        error(S_INCORRECT_USER);
                        return false;
                    }
                    break;
                case OPERATION_OBJECT_GROUP:
                    $usrgrps = CUserGroup::get(array('usrgrpids' => $operation['objectid'], 'output' => API_OUTPUT_EXTEND));
                    if (empty($usrgrps)) {
                        error(S_INCORRECT_GROUP);
                        return false;
                    }
                    break;
                default:
                    error(S_INCORRECT_OBJECT_TYPE);
                    return false;
            }
            break;
        case OPERATION_TYPE_COMMAND:
            return validate_commands($operation['longdata']);
        case OPERATION_TYPE_HOST_ADD:
        case OPERATION_TYPE_HOST_REMOVE:
        case OPERATION_TYPE_HOST_ENABLE:
        case OPERATION_TYPE_HOST_DISABLE:
            break;
        case OPERATION_TYPE_GROUP_ADD:
        case OPERATION_TYPE_GROUP_REMOVE:
            $groups = CHostGroup::get(array('groupids' => $operation['objectid'], 'output' => API_OUTPUT_SHORTEN, 'editable' => 1));
            if (empty($groups)) {
                error(S_INCORRECT_GROUP);
                return false;
            }
            break;
        case OPERATION_TYPE_TEMPLATE_ADD:
        case OPERATION_TYPE_TEMPLATE_REMOVE:
            $tpls = CTemplate::get(array('templateids' => $operation['objectid'], 'output' => API_OUTPUT_SHORTEN, 'editable' => 1));
            if (empty($tpls)) {
                error(S_INCORRECT_HOST);
                return false;
            }
            break;
        default:
            error(S_INCORRECT_OPERATION_TYPE);
            return false;
    }
    return true;
}
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:57,代码来源:actions.inc.php

示例10: get

    /**
     * Get Host data
     *
     * {@source}
     * @access public
     * @static
     * @since 1.8
     * @version 1
     *
     * @param _array $options
     * @param array $options['nodeids'] Node IDs
     * @param array $options['groupids'] HostGroup IDs
     * @param array $options['hostids'] Host IDs
     * @param boolean $options['monitored_hosts'] only monitored Hosts
     * @param boolean $options['templated_hosts'] include templates in result
     * @param boolean $options['with_items'] only with items
     * @param boolean $options['with_monitored_items'] only with monitored items
     * @param boolean $options['with_historical_items'] only with historical items
     * @param boolean $options['with_triggers'] only with triggers
     * @param boolean $options['with_monitored_triggers'] only with monitores triggers
     * @param boolean $options['with_httptests'] only with http tests
     * @param boolean $options['with_monitored_httptests'] only with monitores http tests
     * @param boolean $options['with_graphs'] only with graphs
     * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
     * @param int $options['extendoutput'] return all fields for Hosts
     * @param int $options['count'] count Hosts, returned column name is rowscount
     * @param string $options['pattern'] search hosts by pattern in host names
     * @param int $options['limit'] limit selection
     * @param string $options['order'] depricated parametr (for now)
     * @return array|boolean Host data as array or false if error
     */
    public static function get($options = array())
    {
        global $USER_DETAILS;
        $result = array();
        $user_type = $USER_DETAILS['type'];
        $userid = $USER_DETAILS['userid'];
        $sort_columns = array('hostid', 'host');
        // allowed columns for sorting
        $sql_parts = array('select' => array('hosts' => 'h.hostid'), 'from' => array('hosts h'), 'where' => array(), 'order' => array(), 'limit' => null);
        $def_options = array('nodeids' => 0, 'groupids' => 0, 'hostids' => 0, 'templateids' => 0, 'triggerids' => 0, 'graphids' => 0, 'monitored_hosts' => 0, 'templated_hosts' => 0, 'with_items' => 0, 'with_monitored_items' => 0, 'with_historical_items' => 0, 'with_triggers' => 0, 'with_monitored_triggers' => 0, 'with_httptests' => 0, 'with_monitored_httptests' => 0, 'with_graphs' => 0, 'editable' => 0, 'nopermissions' => 0, 'extendoutput' => 0, 'select_templates' => 0, 'select_items' => 0, 'select_triggers' => 0, 'select_graphs' => 0, 'count' => 0, 'pattern' => '', 'extend_pattern' => 0, 'order' => '', 'limit' => 0);
        $options = array_merge($def_options, $options);
        // editable + PERMISSION CHECK
        if (defined('ZBX_API_REQUEST')) {
            $options['nopermissions'] = false;
        }
        if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) {
        } else {
            $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
            $sql_parts['from']['hg'] = 'hosts_groups hg';
            $sql_parts['from']['r'] = 'rights r';
            $sql_parts['from']['ug'] = 'users_groups ug';
            $sql_parts['where']['hgh'] = 'hg.hostid=h.hostid';
            $sql_parts['where'][] = 'r.id=hg.groupid ';
            $sql_parts['where'][] = 'r.groupid=ug.usrgrpid';
            $sql_parts['where'][] = 'ug.userid=' . $userid;
            $sql_parts['where'][] = 'r.permission>=' . $permission;
            $sql_parts['where'][] = 'NOT EXISTS( ' . ' SELECT hgg.groupid ' . ' FROM hosts_groups hgg, rights rr, users_groups gg ' . ' WHERE hgg.hostid=hg.hostid ' . ' AND rr.id=hgg.groupid ' . ' AND rr.groupid=gg.usrgrpid ' . ' AND gg.userid=' . $userid . ' AND rr.permission<' . $permission . ')';
        }
        // nodeids
        $nodeids = $options['nodeids'] ? $options['nodeids'] : get_current_nodeid(false);
        // groupids
        if ($options['groupids'] != 0) {
            zbx_value2array($options['groupids']);
            if ($options['extendoutput'] != 0) {
                $sql_parts['select']['groupid'] = 'hg.groupid';
            }
            $sql_parts['from']['hg'] = 'hosts_groups hg';
            $sql_parts['where'][] = DBcondition('hg.groupid', $options['groupids']);
            $sql_parts['where']['hgh'] = 'hg.hostid=h.hostid';
        }
        // hostids
        if ($options['hostids'] != 0) {
            zbx_value2array($options['hostids']);
            $sql_parts['where'][] = DBcondition('h.hostid', $options['hostids']);
        }
        // templateids
        if ($options['templateids'] != 0) {
            zbx_value2array($options['templateids']);
            if ($options['extendoutput'] != 0) {
                $sql_parts['select']['templateid'] = 'ht.templateid';
            }
            $sql_parts['from']['ht'] = 'hosts_templates ht';
            $sql_parts['where'][] = DBcondition('ht.templateid', $options['templateids']);
            $sql_parts['where']['hht'] = 'h.hostid=ht.hostid';
        }
        // triggerids
        if ($options['triggerids'] != 0) {
            zbx_value2array($options['triggerids']);
            if ($options['extendoutput'] != 0) {
                $sql_parts['select']['triggerid'] = 'f.triggerid';
            }
            $sql_parts['from']['f'] = 'functions f';
            $sql_parts['from']['i'] = 'items i';
            $sql_parts['where'][] = DBcondition('f.triggerid', $options['triggerids']);
            $sql_parts['where']['hi'] = 'h.hostid=i.hostid';
            $sql_parts['where']['fi'] = 'f.itemid=i.itemid';
        }
        // graphids
        if ($options['graphids'] != 0) {
//.........这里部分代码省略.........
开发者ID:phedders,项目名称:zabbix,代码行数:101,代码来源:class.chost.php

示例11: foreach

     foreach ($templates as $tnum => $row) {
         $name = new CSpan($row['host'], 'link');
         $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
         $name->setAttribute('onclick', $action . " close_window(); return false;");
         $table->addRow($name);
     }
     $table->show();
 } else {
     if ($srctbl == 'hosts_and_templates') {
         $table = new CTableInfo(S_NO_TEMPLATES_DEFINED);
         $table->setHeader(array(S_NAME));
         $options = array('nodeids' => $nodeid, 'groupids' => $groupid, 'output' => API_OUTPUT_EXTEND, 'sortfield' => 'host');
         if (!is_null($writeonly)) {
             $options['editable'] = 1;
         }
         $templates = CTemplate::get($options);
         foreach ($templates as $tnum => $template) {
             $templates[$tnum]['hostid'] = $template['templateid'];
         }
         $hosts = CHost::get($options);
         $objects = array_merge($templates, $hosts);
         foreach ($objects as $row) {
             $name = new CSpan($row['host'], 'link');
             $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
             $name->setAttribute('onclick', $action . " close_window(); return false;");
             $table->addRow($name);
         }
         $table->show();
     } else {
         if ($srctbl == 'usrgrp') {
             $table = new CTableInfo(S_NO_GROUPS_DEFINED);
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:31,代码来源:popup.php

示例12: syncTemplates

 /**
  * Inherit template graphs from template to host
  *
  * params: templateids, hostids
  *
  * @param array $data
  * @return boolean
  */
 public static function syncTemplates($data)
 {
     try {
         self::BeginTransaction(__METHOD__);
         $data['templateids'] = zbx_toArray($data['templateids']);
         $data['hostids'] = zbx_toArray($data['hostids']);
         $options = array('hostids' => $data['hostids'], 'editable' => 1, 'preservekeys' => 1, 'templated_hosts' => 1, 'output' => API_OUTPUT_SHORTEN);
         $allowedHosts = CHost::get($options);
         foreach ($data['hostids'] as $hostid) {
             if (!isset($allowedHosts[$hostid])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
             }
         }
         $options = array('templateids' => $data['templateids'], 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN);
         $allowedTemplates = CTemplate::get($options);
         foreach ($data['templateids'] as $templateid) {
             if (!isset($allowedTemplates[$templateid])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
             }
         }
         $sql = 'SELECT hostid, templateid' . ' FROM hosts_templates' . ' WHERE ' . DBcondition('hostid', $data['hostids']) . ' AND ' . DBcondition('templateid', $data['templateids']);
         $db_links = DBSelect($sql);
         $linkage = array();
         while ($link = DBfetch($db_links)) {
             if (!isset($linkage[$link['templateid']])) {
                 $linkage[$link['templateid']] = array();
             }
             $linkage[$link['templateid']][$link['hostid']] = 1;
         }
         $options = array('hostids' => $data['templateids'], 'preservekeys' => 1, 'output' => API_OUTPUT_EXTEND, 'select_graph_items' => API_OUTPUT_EXTEND);
         $graphs = self::get($options);
         foreach ($graphs as $graph) {
             foreach ($data['hostids'] as $hostid) {
                 if (isset($linkage[$graph['hosts'][0]['hostid']][$hostid])) {
                     self::inherit($graph, $hostid);
                 }
             }
         }
         self::EndTransaction(true, __METHOD__);
         return true;
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:56,代码来源:class.cgraph.php

示例13: available_hosts

}
if (get_request('hostid', 0) > 0) {
    $hostids = available_hosts($_REQUEST['hostid'], 1);
    if (empty($hostids)) {
        access_deny();
    }
}
/*** <--- ACTIONS ---> ***/
if (isset($_REQUEST['clone']) && isset($_REQUEST['groupid'])) {
    unset($_REQUEST['groupid']);
    $_REQUEST['form'] = 'clone';
} else {
    if (isset($_REQUEST['save'])) {
        $objects = get_request('hosts', array());
        $hosts = CHost::get(array('hostids' => $objects, 'output' => API_OUTPUT_SHORTEN));
        $templates = CTemplate::get(array('templateids' => $objects, 'output' => API_OUTPUT_SHORTEN));
        if (isset($_REQUEST['groupid'])) {
            DBstart();
            $old_group = CHostGroup::get(array('groupids' => $_REQUEST['groupid'], 'output' => API_OUTPUT_EXTEND));
            $old_group = reset($old_group);
            $result = CHostGroup::update(array('groupid' => $_REQUEST['groupid'], 'name' => $_REQUEST['gname']));
            if ($result) {
                $options = array('groupids' => $result['groupids'], 'output' => API_OUTPUT_EXTEND);
                $groups = CHostGroup::get($options);
                $data = array('hosts' => $hosts, 'templates' => $templates, 'groups' => $groups);
                $result = CHostGroup::massUpdate($data);
            }
            $result = DBend($result);
            if ($result) {
                $group = reset($groups);
                add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_HOST_GROUP, $group['groupid'], $group['name'], 'groups', array('name' => $old_group['name']), array('name' => $group['name']));
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:31,代码来源:hostgroups.php

示例14: massUpdate

 /**
  * Mass update hosts
  *
  * @param _array $hosts multidimensional array with Hosts data
  * @param array $hosts['hosts'] Array of Host objects to update
  * @param string $hosts['fields']['host'] Host name.
  * @param array $hosts['fields']['groupids'] HostGroup IDs add Host to.
  * @param int $hosts['fields']['port'] Port. OPTIONAL
  * @param int $hosts['fields']['status'] Host Status. OPTIONAL
  * @param int $hosts['fields']['useip'] Use IP. OPTIONAL
  * @param string $hosts['fields']['dns'] DNS. OPTIONAL
  * @param string $hosts['fields']['ip'] IP. OPTIONAL
  * @param int $hosts['fields']['proxy_hostid'] Proxy Host ID. OPTIONAL
  * @param int $hosts['fields']['useipmi'] Use IPMI. OPTIONAL
  * @param string $hosts['fields']['ipmi_ip'] IPMAI IP. OPTIONAL
  * @param int $hosts['fields']['ipmi_port'] IPMI port. OPTIONAL
  * @param int $hosts['fields']['ipmi_authtype'] IPMI authentication type. OPTIONAL
  * @param int $hosts['fields']['ipmi_privilege'] IPMI privilege. OPTIONAL
  * @param string $hosts['fields']['ipmi_username'] IPMI username. OPTIONAL
  * @param string $hosts['fields']['ipmi_password'] IPMI password. OPTIONAL
  * @return boolean
  */
 public static function massUpdate($data)
 {
     $transaction = false;
     $templates = zbx_toArray($data['templates']);
     $templateids = zbx_objectValues($templates, 'templateid');
     try {
         $options = array('templateids' => $templateids, 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
         $upd_templates = self::get($options);
         foreach ($templates as $tnum => $template) {
             if (!isset($upd_templates[$template['templateid']])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
             }
         }
         // CHECK IF TEMPLATES HAVE AT LEAST 1 GROUP {{{
         if (isset($data['groups']) && empty($data['groups'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'No groups for template');
         }
         $data['groups'] = zbx_toArray($data['groups']);
         // }}} CHECK IF TEMPLATES HAVE AT LEAST 1 GROUP
         $transaction = self::BeginTransaction(__METHOD__);
         // UPDATE TEMPLATES PROPERTIES {{{
         if (isset($data['host'])) {
             if (count($templates) > 1) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot mass update template name');
             }
             $cur_template = reset($templates);
             $options = array('filter' => array('host' => $cur_template['host']), 'output' => API_OUTPUT_SHORTEN, 'editable' => 1, 'nopermissions' => 1);
             $template_exists = self::get($options);
             $template_exist = reset($template_exists);
             if ($template_exist && $template_exist['templateid'] != $cur_template['templateid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, S_TEMPLATE . ' [ ' . $data['host'] . ' ] ' . S_ALREADY_EXISTS_SMALL);
             }
             //can't set the same name as existing host
             if (CHost::exists(array('host' => $cur_template['host']))) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, S_HOST . ' [ ' . $template['host'] . ' ] ' . S_ALREADY_EXISTS_SMALL);
             }
         }
         if (isset($data['host']) && !preg_match('/^' . ZBX_PREG_HOST_FORMAT . '$/i', $data['host'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect characters used for Hostname [ ' . $data['host'] . ' ]');
         }
         $sql_set = array();
         if (isset($data['host'])) {
             $sql_set[] = 'host=' . zbx_dbstr($data['host']);
         }
         if (!empty($sql_set)) {
             $sql = 'UPDATE hosts SET ' . implode(', ', $sql_set) . ' WHERE ' . DBcondition('hostid', $templateids);
             $result = DBexecute($sql);
         }
         // }}} UPDATE TEMPLATES PROPERTIES
         // UPDATE HOSTGROUPS LINKAGE {{{
         if (isset($data['groups']) && !is_null($data['groups'])) {
             $template_groups = CHostGroup::get(array('hostids' => $templateids));
             $template_groupids = zbx_objectValues($template_groups, 'groupid');
             $new_groupids = zbx_objectValues($data['groups'], 'groupid');
             $groups_to_add = array_diff($new_groupids, $template_groupids);
             if (!empty($groups_to_add)) {
                 $result = self::massAdd(array('templates' => $templates, 'groups' => zbx_toObject($groups_to_add, 'groupid')));
                 if (!$result) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t add group');
                 }
             }
             $groupids_to_del = array_diff($template_groupids, $new_groupids);
             if (!empty($groupids_to_del)) {
                 $result = self::massRemove(array('templateids' => $templateids, 'groupids' => $groupids_to_del));
                 if (!$result) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t remove group');
                 }
             }
         }
         // }}} UPDATE HOSTGROUPS LINKAGE
         $data['templates_clear'] = isset($data['templates_clear']) ? zbx_toArray($data['templates_clear']) : array();
         $cleared_templateids = array();
         foreach ($templateids as $templateid) {
             foreach ($data['templates_clear'] as $tpl) {
                 $result = unlink_template($templateid, $tpl['templateid'], false);
                 if (!$result) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot unlink template [ ' . $tpl['templateid'] . ' ]');
                 }
//.........这里部分代码省略.........
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,代码来源:class.ctemplate.php

示例15: parseMain

 public static function parseMain($rules)
 {
     $triggers_for_dependencies = array();
     try {
         if (isset($rules['host']['exist']) || isset($rules['host']['missed'])) {
             $xpath = new DOMXPath(self::$xml);
             $hosts = $xpath->query('hosts/host');
             foreach ($hosts as $hnum => $host) {
                 $host_db = self::mapXML2arr($host, XML_TAG_HOST);
                 if (!isset($host_db['status'])) {
                     $host_db['status'] = HOST_STATUS_TEMPLATE;
                 }
                 $current_host = $host_db['status'] == HOST_STATUS_TEMPLATE ? CTemplate::exists($host_db) : CHost::exists($host_db);
                 if (!$current_host && !isset($rules['host']['missed'])) {
                     info('Host [' . $host_db['host'] . '] skipped - user rule');
                     continue;
                     // break if update nonexist
                 }
                 if ($current_host && !isset($rules['host']['exist'])) {
                     info('Host [' . $host_db['host'] . '] skipped - user rule');
                     continue;
                     // break if not update exist
                 }
                 if (isset($host_db['proxy_hostid'])) {
                     $proxy_exists = CProxy::get(array('proxyids' => $host_db['proxy_hostid']));
                     if (empty($proxy_exists)) {
                         $host_db['proxy_hostid'] = 0;
                     }
                 }
                 if ($current_host) {
                     $options = array('filter' => array('host' => $host_db['host']), 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                     if ($host_db['status'] == HOST_STATUS_TEMPLATE) {
                         $current_host = CTemplate::get($options);
                     } else {
                         $current_host = CHost::get($options);
                     }
                     if (empty($current_host)) {
                         throw new APIException(1, 'No permission for host [' . $host_db['host'] . ']');
                     } else {
                         $current_host = reset($current_host);
                     }
                 }
                 // HOST GROUPS {{{
                 $groups = $xpath->query('groups/group', $host);
                 $host_db['groups'] = array();
                 $groups_to_parse = array();
                 foreach ($groups as $gnum => $group) {
                     $groups_to_parse[] = array('name' => $group->nodeValue);
                 }
                 if (empty($groups_to_parse)) {
                     $groups_to_parse[] = array('name' => ZBX_DEFAULT_IMPORT_HOST_GROUP);
                 }
                 foreach ($groups_to_parse as $group) {
                     $current_group = CHostGroup::exists($group);
                     if ($current_group) {
                         $options = array('filter' => $group, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                         $current_group = CHostGroup::get($options);
                         if (empty($current_group)) {
                             throw new APIException(1, 'No permissions for group ' . $group['name']);
                         }
                         $host_db['groups'][] = reset($current_group);
                     } else {
                         $result = CHostGroup::create($group);
                         if (!$result) {
                             throw new APIException(1, CHostGroup::resetErrors());
                         }
                         $options = array('groupids' => $result['groupids'], 'output' => API_OUTPUT_EXTEND);
                         $new_group = CHostgroup::get($options);
                         $host_db['groups'][] = reset($new_group);
                     }
                 }
                 // }}} HOST GROUPS
                 // MACROS
                 $macros = $xpath->query('macros/macro', $host);
                 $host_db['macros'] = array();
                 if ($macros->length > 0) {
                     foreach ($macros as $macro) {
                         $host_db['macros'][] = self::mapXML2arr($macro, XML_TAG_MACRO);
                     }
                 }
                 // }}} MACROS
                 // TEMPLATES {{{
                 if (isset($rules['template']['exist'])) {
                     $templates = $xpath->query('templates/template', $host);
                     $host_db['templates'] = array();
                     foreach ($templates as $tnum => $template) {
                         $options = array('filter' => array('host' => $template->nodeValue), 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                         $current_template = CTemplate::get($options);
                         if (empty($current_template)) {
                             throw new APIException(1, 'No permission for Template [' . $template->nodeValue . ']');
                         }
                         $current_template = reset($current_template);
                         if (!$current_template && !isset($rules['template']['missed'])) {
                             info('Template [' . $template->nodeValue . '] skipped - user rule');
                             continue;
                             // break if update nonexist
                         }
                         if ($current_template && !isset($rules['template']['exist'])) {
                             info('Template [' . $template->nodeValue . '] skipped - user rule');
                             continue;
//.........这里部分代码省略.........
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,代码来源:export.inc.php


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