本文整理汇总了PHP中zbx_toObject函数的典型用法代码示例。如果您正苦于以下问题:PHP zbx_toObject函数的具体用法?PHP zbx_toObject怎么用?PHP zbx_toObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zbx_toObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: elseif
} elseif (isset($_REQUEST['delete_and_clear']) && isset($_REQUEST['templateid'])) {
DBstart();
$result = API::Template()->delete(array(getRequest('templateid')));
$result = DBend($result);
if ($result) {
unset($_REQUEST['form'], $_REQUEST['templateid']);
uncheckTableRows();
}
unset($_REQUEST['delete']);
show_messages($result, _('Template deleted'), _('Cannot delete template'));
} elseif (hasRequest('action') && str_in_array(getRequest('action'), array('template.massdelete', 'template.massdeleteclear')) && hasRequest('templates')) {
$templates = getRequest('templates');
DBstart();
$result = true;
if (getRequest('action') == 'action.massdelete') {
$result = API::Template()->massUpdate(array('templates' => zbx_toObject($templates, 'templateid'), 'hosts' => array()));
}
if ($result) {
$result = API::Template()->delete($templates);
}
$result = DBend($result);
if ($result) {
uncheckTableRows();
}
show_messages($result, _('Template deleted'), _('Cannot delete template'));
}
/*
* Display
*/
$templateWidget = new CWidget();
$pageFilter = new CPageFilter(array('config' => array('individual' => 1), 'groups' => array('templated_hosts' => true, 'editable' => true), 'groupid' => getRequest('groupid')));
示例2: reset
$bulk = !isset($_REQUEST['eventid']);
if (!$bulk) {
$events = API::Event()->get(array('eventids' => $_REQUEST['eventid'], 'output' => API_OUTPUT_EXTEND, 'selectRelatedObject' => API_OUTPUT_EXTEND));
if ($events) {
$event = reset($events);
$eventTriggerName = CMacrosResolverHelper::resolveTriggerName($event['relatedObject']);
$eventAcknowledged = $event['acknowledged'];
}
$_REQUEST['events'] = $_REQUEST['eventid'];
}
if (isset($_REQUEST['save']) || isset($_REQUEST['saveandreturn'])) {
if ($bulk) {
$_REQUEST['message'] .= $_REQUEST['message'] == '' ? '' : "\n\r" . _('----[BULK ACKNOWLEDGE]----');
}
if (isset($_REQUEST['events'])) {
$_REQUEST['events'] = zbx_toObject($_REQUEST['events'], 'eventid');
} elseif (isset($_REQUEST['triggers'])) {
$_REQUEST['events'] = API::Event()->get(array('source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'objectids' => $_REQUEST['triggers'], 'output' => array('eventid'), 'acknowledged' => EVENT_NOT_ACKNOWLEDGED));
}
$acknowledgeEvent = API::Event()->acknowledge(array('eventids' => zbx_objectValues($_REQUEST['events'], 'eventid'), 'message' => $_REQUEST['message']));
show_messages($acknowledgeEvent, _('Event acknowledged'), _('Cannot acknowledge event'));
if ($acknowledgeEvent) {
$eventAcknowledged = true;
add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER, _('Acknowledge added') . ' [' . ($bulk ? ' BULK ACKNOWLEDGE ' : $eventTriggerName) . ']' . ' [' . $_REQUEST['message'] . ']');
}
if (isset($_REQUEST['saveandreturn'])) {
ob_end_clean();
if (in_array($_REQUEST['backurl'], array('tr_events.php', 'events.php'))) {
redirect($_REQUEST['backurl'] . '?eventid=' . $_REQUEST['eventid'] . '&triggerid=' . $_REQUEST['triggerid']);
} elseif ($_REQUEST['backurl'] == 'screenedit.php') {
redirect($_REQUEST['backurl'] . '?screenid=' . $_REQUEST['screenid']);
示例3: getRequest
}
// new group
$groups = getRequest('groups', []);
$newGroup = getRequest('newgroup');
if (!zbx_empty($newGroup)) {
$newGroup = API::HostGroup()->create(['name' => $newGroup]);
if (!$newGroup) {
throw new Exception();
}
$groups[] = reset($newGroup['groupids']);
}
$groups = zbx_toObject($groups, 'groupid');
// host data
$host = ['host' => getRequest('host'), 'name' => getRequest('visiblename'), 'status' => getRequest('status', HOST_STATUS_NOT_MONITORED), 'description' => getRequest('description'), 'proxy_hostid' => getRequest('proxy_hostid', 0), 'ipmi_authtype' => getRequest('ipmi_authtype'), 'ipmi_privilege' => getRequest('ipmi_privilege'), 'ipmi_username' => getRequest('ipmi_username'), 'ipmi_password' => getRequest('ipmi_password'), 'tls_connect' => getRequest('tls_connect', HOST_ENCRYPTION_NONE), 'tls_accept' => getRequest('tls_accept', HOST_ENCRYPTION_NONE), 'tls_issuer' => getRequest('tls_issuer'), 'tls_subject' => getRequest('tls_subject'), 'tls_psk_identity' => getRequest('tls_psk_identity'), 'tls_psk' => getRequest('tls_psk'), 'groups' => $groups, 'templates' => $templates, 'interfaces' => $interfaces, 'macros' => $macros, 'inventory_mode' => getRequest('inventory_mode'), 'inventory' => getRequest('inventory_mode') == HOST_INVENTORY_DISABLED ? [] : getRequest('host_inventory', [])];
if (!$create) {
$host['templates_clear'] = zbx_toObject(getRequest('clear_templates', []), 'templateid');
}
}
if ($create) {
$hostIds = API::Host()->create($host);
if ($hostIds) {
$hostId = reset($hostIds['hostids']);
} else {
throw new Exception();
}
add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_HOST, $hostId, $host['host'], null, null, null);
} else {
$host['hostid'] = $hostId;
if (!API::Host()->update($host)) {
throw new Exception();
}
示例4: massUpdate
//.........这里部分代码省略.........
$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']);
}
if (isset($data['ipmi_password'])) {
$sql_set[] = 'ipmi_password=' . zbx_dbstr($data['ipmi_password']);
}
if (isset($data['ipmi_ip'])) {
$sql_set[] = 'ipmi_ip=' . zbx_dbstr($data['ipmi_ip']);
}
if (!empty($sql_set)) {
$sql = 'UPDATE hosts SET ' . implode(', ', $sql_set) . ' WHERE ' . DBcondition('hostid', $hostids);
$result = DBexecute($sql);
if (isset($data['status'])) {
update_host_status($hostids, $data['status']);
}
}
// }}} UPDATE HOSTS PROPERTIES
// UPDATE HOSTGROUPS LINKAGE {{{
if (isset($data['groups']) && !is_null($data['groups'])) {
$data['groups'] = zbx_toArray($data['groups']);
$host_groups = CHostGroup::get(array('hostids' => $hostids));
$host_groupids = zbx_objectValues($host_groups, 'groupid');
$new_groupids = zbx_objectValues($data['groups'], 'groupid');
$groups_to_add = array_diff($new_groupids, $host_groupids);
if (!empty($groups_to_add)) {
$result = self::massAdd(array('hosts' => $hosts, 'groups' => zbx_toObject($groups_to_add, 'groupid')));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t add group');
}
}
$groupids_to_del = array_diff($host_groupids, $new_groupids);
if (!empty($groupids_to_del)) {
$result = self::massRemove(array('hostids' => $hostids, '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 ($hostids as $hostid) {
foreach ($data['templates_clear'] as $tpl) {
$result = unlink_template($hostid, $tpl['templateid'], false);
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot unlink template [ ' . $tpl['templateid'] . ' ]');
}
$cleared_templateids[] = $tpl['templateid'];
}
}
// UPDATE TEMPLATE LINKAGE {{{
if (isset($data['templates']) && !is_null($data['templates'])) {
$opt = array('hostids' => $hostids, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => true);
$host_templates = CTemplate::get($opt);
$host_templateids = array_keys($host_templates);
$new_templateids = zbx_objectValues($data['templates'], 'templateid');
$templates_to_del = array_diff($host_templateids, $new_templateids);
$templates_to_del = array_diff($templates_to_del, $cleared_templateids);
示例5: updateHostStatus
$oldStatus = $dbHost['status'];
if ($oldStatus == $status) {
continue;
}
$go_result &= updateHostStatus($dbHost['hostid'], $status);
if (!$go_result) {
continue;
}
}
}
$go_result = DBend($go_result && !empty($hosts));
show_messages($go_result, _('Host status updated'), null);
} elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['hosts'])) {
$hosts = get_request('hosts', array());
DBstart();
$go_result = API::Proxy()->delete(zbx_toObject($hosts, 'proxyid'));
$go_result = DBend($go_result);
show_messages($go_result, _('Proxy deleted'), _('Cannot delete proxy'));
}
if ($_REQUEST['go'] != 'none' && !empty($go_result)) {
$url = new CUrl();
$path = $url->getPath();
insert_js('cookie.eraseArray("' . $path . '")');
}
/*
* Display
*/
if (isset($_REQUEST['form'])) {
$data = array('form' => get_request('form', 1), 'form_refresh' => get_request('form_refresh', 0) + 1, 'proxyid' => get_request('proxyid', 0), 'name' => get_request('host', ''), 'status' => get_request('status', HOST_STATUS_PROXY_ACTIVE), 'hosts' => get_request('hosts', array()), 'interfaces' => get_request('interfaces', array()), 'interface' => get_request('interface', array()), 'proxy' => array());
// proxy
if (!empty($data['proxyid'])) {
示例6: foreach
}
foreach ($macros as $key => $macro) {
// transform macros to uppercase {$aaa} => {$AAA}
$macros[$key]['macro'] = zbx_strtoupper($macro['macro']);
}
// create new group
if (!zbx_empty($_REQUEST['newgroup'])) {
if (!($newGroup = API::HostGroup()->create(array('name' => $_REQUEST['newgroup'])))) {
throw new Exception();
}
$groups[] = reset($newGroup['groupids']);
}
$groups = zbx_toObject($groups, 'groupid');
$host = array('host' => $_REQUEST['host'], 'name' => $_REQUEST['visiblename'], 'status' => $_REQUEST['status'], 'proxy_hostid' => get_request('proxy_hostid', 0), 'ipmi_authtype' => get_request('ipmi_authtype'), 'ipmi_privilege' => get_request('ipmi_privilege'), 'ipmi_username' => get_request('ipmi_username'), 'ipmi_password' => get_request('ipmi_password'), 'groups' => $groups, 'templates' => $templates, 'interfaces' => $interfaces, 'macros' => $macros, 'inventory' => get_request('inventory_mode') != HOST_INVENTORY_DISABLED ? get_request('host_inventory', array()) : null, 'inventory_mode' => get_request('inventory_mode'));
if (!$createNew) {
$host['templates_clear'] = zbx_toObject(get_request('clear_templates', array()), 'templateid');
}
}
##############################################################################################
# update racktables object
require_once 'racktablesapi.php';
$groupids = get_request('groups', array());
$groupNames = array();
foreach ($groupids as $groupid) {
$group = API::HostGroup()->get(array('groupids' => $groupid, 'output' => API_OUTPUT_EXTEND));
array_push($groupNames, $group[0]['name']);
}
if (!zbx_empty($_REQUEST['newgroup'])) {
# new group
$response = addRack($_REQUEST['newgroup']);
if (isset($response['error'])) {
示例7: massUpdate
//.........这里部分代码省略.........
}
/*
* update interfaces
*/
if (isset($updateInterfaces)) {
foreach ($hostids as $hostid) {
API::HostInterface()->replaceHostInterfaces(['hostid' => $hostid, 'interfaces' => $updateInterfaces]);
}
}
// link new templates
if (isset($updateTemplates)) {
$result = $this->massAdd(['hosts' => $hosts, 'templates' => $updateTemplates]);
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot link template'));
}
}
// macros
if (isset($updateMacros)) {
DB::delete('hostmacro', ['hostid' => $hostids]);
$this->massAdd(['hosts' => $hosts, 'macros' => $updateMacros]);
}
/*
* Inventory
*/
if (isset($updateInventory)) {
// disabling inventory
if ($updateInventory['inventory_mode'] == HOST_INVENTORY_DISABLED) {
$sql = 'DELETE FROM host_inventory WHERE ' . dbConditionInt('hostid', $hostids);
if (!DBexecute($sql)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete inventory.'));
}
} else {
$existingInventoriesDb = DBfetchArrayAssoc(DBselect('SELECT hostid,inventory_mode' . ' FROM host_inventory' . ' WHERE ' . dbConditionInt('hostid', $hostids)), 'hostid');
// check existing host inventory data
$automaticHostIds = [];
if ($updateInventory['inventory_mode'] === null) {
foreach ($hostids as $hostid) {
// if inventory is disabled for one of the updated hosts, throw an exception
if (!isset($existingInventoriesDb[$hostid])) {
$host = get_host_by_hostid($hostid);
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Inventory disabled for host "%1$s".', $host['host']));
} elseif ($existingInventoriesDb[$hostid]['inventory_mode'] == HOST_INVENTORY_AUTOMATIC) {
$automaticHostIds[] = $hostid;
}
}
}
$inventoriesToSave = [];
foreach ($hostids as $hostid) {
$hostInventory = $updateInventory;
$hostInventory['hostid'] = $hostid;
// if no 'inventory_mode' has been passed, set inventory 'inventory_mode' from DB
if ($updateInventory['inventory_mode'] === null) {
$hostInventory['inventory_mode'] = $existingInventoriesDb[$hostid]['inventory_mode'];
}
$inventoriesToSave[$hostid] = $hostInventory;
}
// when updating automatic inventory, ignore fields that have items linked to them
if ($updateInventory['inventory_mode'] == HOST_INVENTORY_AUTOMATIC || $updateInventory['inventory_mode'] === null && $automaticHostIds) {
$itemsToInventories = API::item()->get(['output' => ['inventory_link', 'hostid'], 'hostids' => $automaticHostIds ? $automaticHostIds : $hostids, 'nopermissions' => true]);
$inventoryFields = getHostInventories();
foreach ($itemsToInventories as $hinv) {
// 0 means 'no link'
if ($hinv['inventory_link'] != 0) {
$inventoryName = $inventoryFields[$hinv['inventory_link']]['db_field'];
unset($inventoriesToSave[$hinv['hostid']][$inventoryName]);
}
}
}
// save inventory data
foreach ($inventoriesToSave as $inventory) {
$hostid = $inventory['hostid'];
if (isset($existingInventoriesDb[$hostid])) {
DB::update('host_inventory', ['values' => $inventory, 'where' => ['hostid' => $hostid]]);
} else {
DB::insert('host_inventory', [$inventory], false);
}
}
}
}
/*
* Update host and host group linkage. This procedure should be done the last because user can unlink
* him self from a group with write permissions leaving only read premissions. Thus other procedures, like
* host-template linkage, inventory update, macros update, must be done before this.
*/
if (isset($updateGroups)) {
$updateGroups = zbx_toArray($updateGroups);
$hostGroups = API::HostGroup()->get(['output' => ['groupid'], 'hostids' => $hostids]);
$hostGroupIds = zbx_objectValues($hostGroups, 'groupid');
$newGroupIds = zbx_objectValues($updateGroups, 'groupid');
$groupsToAdd = array_diff($newGroupIds, $hostGroupIds);
if ($groupsToAdd) {
$this->massAdd(['hosts' => $hosts, 'groups' => zbx_toObject($groupsToAdd, 'groupid')]);
}
$groupIdsToDelete = array_diff($hostGroupIds, $newGroupIds);
if ($groupIdsToDelete) {
$this->massRemove(['hostids' => $hostids, 'groupids' => $groupIdsToDelete]);
}
}
return ['hostids' => $inputHostIds];
}
示例8: DBend
$result = DBend($result);
show_messages($result, _('Host deleted'), _('Cannot delete host'));
if ($result) {
unset($_REQUEST['form'], $_REQUEST['hostid']);
}
unset($_REQUEST['delete']);
} elseif (isset($_REQUEST['chstatus']) && isset($_REQUEST['hostid'])) {
DBstart();
$result = updateHostStatus($_REQUEST['hostid'], $_REQUEST['chstatus']);
$result = DBend($result);
show_messages($result, _('Host status updated'), _('Cannot update host status'));
unset($_REQUEST['chstatus'], $_REQUEST['hostid']);
} elseif ($_REQUEST['go'] == 'delete') {
$hostids = get_request('hosts', array());
DBstart();
$go_result = API::Host()->delete(zbx_toObject($hostids, 'hostid'));
$go_result = DBend($go_result);
show_messages($go_result, _('Host deleted'), _('Cannot delete host'));
} elseif (str_in_array($_REQUEST['go'], array('activate', 'disable'))) {
$status = $_REQUEST['go'] == 'activate' ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED;
$hosts = get_request('hosts', array());
$act_hosts = available_hosts($hosts, 1);
DBstart();
$go_result = updateHostStatus($act_hosts, $status);
$go_result = DBend($go_result);
show_messages($go_result, _('Host status updated'), _('Cannot update host status'));
}
if ($_REQUEST['go'] != 'none' && isset($go_result) && $go_result) {
$url = new CUrl();
$path = $url->getPath();
insert_js('cookie.eraseArray("' . $path . '")');
示例9: elseif
if (!uint_in_array($triggerId, getRequest('dependencies'))) {
$_REQUEST['dependencies'][] = $triggerId;
}
}
} elseif (hasRequest('action') && getRequest('action') === 'triggerprototype.massupdate' && hasRequest('massupdate') && hasRequest('g_triggerid')) {
$result = true;
$visible = getRequest('visible', []);
if ($visible) {
$triggersToUpdate = [];
foreach (getRequest('g_triggerid') as $triggerId) {
$trigger = ['triggerid' => $triggerId];
if (isset($visible['priority'])) {
$trigger['priority'] = getRequest('priority');
}
if (isset($visible['dependencies'])) {
$trigger['dependencies'] = zbx_toObject(getRequest('dependencies', []), 'triggerid');
}
$triggersToUpdate[] = $trigger;
}
$result = (bool) API::TriggerPrototype()->update($triggersToUpdate);
}
if ($result) {
unset($_REQUEST['form'], $_REQUEST['g_triggerid']);
uncheckTableRows(getRequest('parent_discoveryid'));
}
show_messages($result, _('Trigger prototypes updated'), _('Cannot update trigger prototypes'));
} elseif (getRequest('action') && str_in_array(getRequest('action'), ['triggerprototype.massenable', 'triggerprototype.massdisable']) && hasRequest('g_triggerid')) {
$enable = getRequest('action') == 'triggerprototype.massenable';
$status = $enable ? TRIGGER_STATUS_ENABLED : TRIGGER_STATUS_DISABLED;
$update = [];
// get requested triggers with permission check
示例10: massUpdate
//.........这里部分代码省略.........
$templateIds = zbx_objectValues($templates, 'templateid');
$fieldsToUpdate = array();
if (isset($data['host'])) {
$fieldsToUpdate[] = 'host=' . zbx_dbstr($data['host']);
}
if (isset($data['name'])) {
// if visible name is empty replace it with host name
if (zbx_empty(trim($data['name'])) && isset($data['host'])) {
$fieldsToUpdate[] = 'name=' . zbx_dbstr($data['host']);
} elseif (zbx_empty(trim($data['name'])) && !isset($data['host'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot have empty visible template name.'));
} else {
$fieldsToUpdate[] = 'name=' . zbx_dbstr($data['name']);
}
}
if (isset($data['description'])) {
$fieldsToUpdate[] = 'description=' . zbx_dbstr($data['description']);
}
if ($fieldsToUpdate) {
DBexecute('UPDATE hosts SET ' . implode(', ', $fieldsToUpdate) . ' WHERE ' . dbConditionInt('hostid', $templateIds));
}
$data['templates_clear'] = isset($data['templates_clear']) ? zbx_toArray($data['templates_clear']) : array();
$templateIdsClear = zbx_objectValues($data['templates_clear'], 'templateid');
if ($data['templates_clear']) {
$this->massRemove(array('templateids' => $templateIds, 'templateids_clear' => $templateIdsClear));
}
// update template linkage
// firstly need to unlink all things, to correctly check circulars
if (isset($data['hosts']) && $data['hosts'] !== null) {
/*
* Get all currently linked hosts and templates (skip discovered hosts) to these templates
* that user has read permissions.
*/
$templateHosts = API::Host()->get(array('output' => array('hostid'), 'templateids' => $templateIds, 'templated_hosts' => true, 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL)));
$templateHostIds = zbx_objectValues($templateHosts, 'hostid');
$newHostIds = zbx_objectValues($data['hosts'], 'hostid');
$hostsToDelete = array_diff($templateHostIds, $newHostIds);
$hostIdsToDelete = array_diff($hostsToDelete, $templateIdsClear);
$hostIdsToAdd = array_diff($newHostIds, $templateHostIds);
if ($hostIdsToDelete) {
$result = $this->massRemove(array('hostids' => $hostIdsToDelete, 'templateids' => $templateIds));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot unlink template.'));
}
}
}
if (isset($data['templates_link']) && $data['templates_link'] !== null) {
$templateTemplates = API::Template()->get(array('output' => array('templateid'), 'hostids' => $templateIds));
$templateTemplateIds = zbx_objectValues($templateTemplates, 'templateid');
$newTemplateIds = zbx_objectValues($data['templates_link'], 'templateid');
$templatesToDelete = array_diff($templateTemplateIds, $newTemplateIds);
$templateIdsToDelete = array_diff($templatesToDelete, $templateIdsClear);
if ($templateIdsToDelete) {
$result = $this->massRemove(array('templateids' => $templateIds, 'templateids_link' => $templateIdsToDelete));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot unlink template.'));
}
}
}
if (isset($data['hosts']) && $data['hosts'] !== null && $hostIdsToAdd) {
$result = $this->massAdd(array('templates' => $templates, 'hosts' => $hostIdsToAdd));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot link template.'));
}
}
if (isset($data['templates_link']) && $data['templates_link'] !== null) {
$templatesToAdd = array_diff($newTemplateIds, $templateTemplateIds);
if ($templatesToAdd) {
$result = $this->massAdd(array('templates' => $templates, 'templates_link' => $templatesToAdd));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot link template.'));
}
}
}
// macros
if (isset($data['macros'])) {
DB::delete('hostmacro', array('hostid' => $templateIds));
$this->massAdd(array('hosts' => $templates, 'macros' => $data['macros']));
}
/*
* Update template and host group linkage. This procedure should be done the last because user can unlink
* him self from a group with write permissions leaving only read premissions. Thus other procedures, like
* host-template linking, macros update, must be done before this.
*/
if (isset($data['groups']) && $data['groups'] !== null && is_array($data['groups'])) {
$updateGroups = zbx_toArray($data['groups']);
$templateGroups = API::HostGroup()->get(array('output' => array('groupid'), 'templateids' => $templateIds));
$templateGroupIds = zbx_objectValues($templateGroups, 'groupid');
$newGroupIds = zbx_objectValues($updateGroups, 'groupid');
$groupsToAdd = array_diff($newGroupIds, $templateGroupIds);
if ($groupsToAdd) {
$this->massAdd(array('templates' => $templates, 'groups' => zbx_toObject($groupsToAdd, 'groupid')));
}
$groupIdsToDelete = array_diff($templateGroupIds, $newGroupIds);
if ($groupIdsToDelete) {
$this->massRemove(array('templateids' => $templateIds, 'groupids' => $groupIdsToDelete));
}
}
return array('templateids' => $templateIds);
}
示例11: elseif
} elseif (isset($_REQUEST['delete_and_clear']) && isset($_REQUEST['templateid'])) {
DBstart();
$result = API::Template()->delete([getRequest('templateid')]);
$result = DBend($result);
if ($result) {
unset($_REQUEST['form'], $_REQUEST['templateid']);
uncheckTableRows();
}
unset($_REQUEST['delete']);
show_messages($result, _('Template deleted'), _('Cannot delete template'));
} elseif (hasRequest('action') && str_in_array(getRequest('action'), ['template.massdelete', 'template.massdeleteclear']) && hasRequest('templates')) {
$templates = getRequest('templates');
DBstart();
$result = true;
if (getRequest('action') === 'template.massdelete') {
$result = API::Template()->massUpdate(['templates' => zbx_toObject($templates, 'templateid'), 'hosts' => []]);
}
if ($result) {
$result = API::Template()->delete($templates);
}
$result = DBend($result);
if ($result) {
uncheckTableRows();
}
show_messages($result, _('Template deleted'), _('Cannot delete template'));
}
/*
* Display
*/
$templateWidget = (new CWidget())->setTitle(_('Templates'));
$pageFilter = new CPageFilter(['config' => ['individual' => 1], 'groups' => ['templated_hosts' => true, 'editable' => true], 'groupid' => getRequest('groupid')]);
示例12: massUpdate
//.........这里部分代码省略.........
$result = DBexecute($sql);
}
// }}} UPDATE TEMPLATES PROPERTIES
$data['templates_clear'] = isset($data['templates_clear']) ? zbx_toArray($data['templates_clear']) : array();
$templateidsClear = zbx_objectValues($data['templates_clear'], 'templateid');
if (!empty($data['templates_clear'])) {
$result = $this->massRemove(array('templateids' => $templateids, 'templateids_clear' => $templateidsClear));
}
// UPDATE TEMPLATE LINKAGE {{{
// firstly need to unlink all things, to correctly check circulars
if (isset($data['hosts']) && !is_null($data['hosts'])) {
/*
* Get all currently linked hosts and templates (skip discovered hosts) to these templates
* that user has read permissions.
*/
$templateHosts = API::Host()->get(array('output' => array('hostid'), 'templateids' => $templateids, 'templated_hosts' => 1, 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL)));
$templateHostids = zbx_objectValues($templateHosts, 'hostid');
$newHostids = zbx_objectValues($data['hosts'], 'hostid');
$hostsToDel = array_diff($templateHostids, $newHostids);
$hostidsToDel = array_diff($hostsToDel, $templateidsClear);
$hostIdsToAdd = array_diff($newHostids, $templateHostids);
// gather both host and template IDs and validate write permissions
$hostIds = array_merge($hostIdsToAdd, $hostidsToDel);
if ($hostIds) {
/*
* Get all currently linked hosts and templates (skip discovered hosts) to these templates
* that user has write permissions.
*/
$templatesHostsAllowed = API::Host()->get(array('output' => array('hostid'), 'templated_hosts' => true, 'editable' => true, 'preservekeys' => true, 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL)));
foreach ($hostIds as $hostId) {
if (!isset($templatesHostsAllowed[$hostId])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
}
}
}
if ($hostidsToDel) {
$result = $this->massRemove(array('hostids' => $hostidsToDel, 'templateids' => $templateids));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _("Can't unlink template"));
}
}
}
if (isset($data['templates_link']) && !is_null($data['templates_link'])) {
$templateTemplates = API::Template()->get(array('hostids' => $templateids));
$templateTemplateids = zbx_objectValues($templateTemplates, 'templateid');
$newTemplateids = zbx_objectValues($data['templates_link'], 'templateid');
$templatesToDel = array_diff($templateTemplateids, $newTemplateids);
$templateidsToDel = array_diff($templatesToDel, $templateidsClear);
if (!empty($templateidsToDel)) {
$result = $this->massRemove(array('templateids' => $templateids, 'templateids_link' => $templateidsToDel));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _("Can't unlink template"));
}
}
}
if (isset($data['hosts']) && !is_null($data['hosts'])) {
$hostsToAdd = array_diff($newHostids, $templateHostids);
if (!empty($hostsToAdd)) {
$result = $this->massAdd(array('templates' => $templates, 'hosts' => $hostsToAdd));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _("Can't link template"));
}
}
}
if (isset($data['templates_link']) && !is_null($data['templates_link'])) {
$templatesToAdd = array_diff($newTemplateids, $templateTemplateids);
if (!empty($templatesToAdd)) {
$result = $this->massAdd(array('templates' => $templates, 'templates_link' => $templatesToAdd));
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, _("Can't link template"));
}
}
}
// }}} UPDATE TEMPLATE LINKAGE
// macros
if (isset($data['macros'])) {
DB::delete('hostmacro', array('hostid' => $templateids));
$this->massAdd(array('hosts' => $templates, 'macros' => $data['macros']));
}
/*
* Update template and host group linkage. This procedure should be done the last because user can unlink
* him self from a group with write permissions leaving only read premissions. Thus other procedures, like
* host-template linking, macros update, must be done before this.
*/
if (isset($data['groups']) && is_array($data['groups'])) {
$updateGroups = zbx_toArray($data['groups']);
$templateGroups = API::HostGroup()->get(array('output' => array('groupid'), 'templateids' => $templateids));
$templateGroupids = zbx_objectValues($templateGroups, 'groupid');
$newGroupids = zbx_objectValues($updateGroups, 'groupid');
$groupsToAdd = array_diff($newGroupids, $templateGroupids);
if ($groupsToAdd) {
$this->massAdd(array('templates' => $templates, 'groups' => zbx_toObject($groupsToAdd, 'groupid')));
}
$groupidsToDel = array_diff($templateGroupids, $newGroupids);
if ($groupidsToDel) {
$this->massRemove(array('templateids' => $templateids, 'groupids' => $groupidsToDel));
}
}
return array('templateids' => $templateids);
}
示例13: unset
unset($_REQUEST['form']);
unset($_REQUEST['hostid']);
}
unset($_REQUEST['delete']);
} else {
if (isset($_REQUEST['chstatus']) && isset($_REQUEST['hostid'])) {
DBstart();
$result = update_host_status($_REQUEST['hostid'], $_REQUEST['chstatus']);
$result = DBend($result);
show_messages($result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST_STATUS);
unset($_REQUEST['chstatus']);
unset($_REQUEST['hostid']);
} else {
if ($_REQUEST['go'] == 'delete') {
$hostids = get_request('hosts', array());
$hosts = zbx_toObject($hostids, 'hostid');
$go_result = CHost::delete($hosts);
show_messages($go_result, S_HOST_DELETED, S_CANNOT_DELETE_HOST);
} else {
if (str_in_array($_REQUEST['go'], array('activate', 'disable'))) {
$status = $_REQUEST['go'] == 'activate' ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED;
$hosts = get_request('hosts', array());
$act_hosts = available_hosts($hosts, 1);
DBstart();
$go_result = update_host_status($act_hosts, $status);
$go_result = DBend($go_result);
show_messages($go_result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST);
}
}
}
}
示例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'] . ' ]');
}
//.........这里部分代码省略.........
示例15: array
}
if ($isValid) {
$user = array();
$user['alias'] = getRequest('alias');
$user['name'] = getRequest('name');
$user['surname'] = getRequest('surname');
$user['passwd'] = getRequest('password1');
$user['url'] = getRequest('url');
$user['autologin'] = getRequest('autologin', 0);
$user['autologout'] = hasRequest('autologout_visible') ? getRequest('autologout') : 0;
$user['theme'] = getRequest('theme');
$user['refresh'] = getRequest('refresh');
$user['rows_per_page'] = getRequest('rows_per_page');
$user['type'] = getRequest('user_type');
$user['user_medias'] = getRequest('user_medias', array());
$user['usrgrps'] = zbx_toObject($usrgrps, 'usrgrpid');
if (hasRequest('lang')) {
$user['lang'] = getRequest('lang');
}
DBstart();
if (hasRequest('userid')) {
$user['userid'] = getRequest('userid');
$result = API::User()->update(array($user));
if ($result) {
$result = API::User()->updateMedia(array('users' => $user, 'medias' => $user['user_medias']));
}
$messageSuccess = _('User updated');
$messageFailed = _('Cannot update user');
$auditAction = AUDIT_ACTION_UPDATE;
} else {
$result = API::User()->create($user);