本文整理汇总了PHP中CTemplate::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP CTemplate::exists方法的具体用法?PHP CTemplate::exists怎么用?PHP CTemplate::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTemplate
的用法示例。
在下文中一共展示了CTemplate::exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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']);
}
//.........这里部分代码省略.........
示例2: 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;
//.........这里部分代码省略.........