本文整理汇总了PHP中API::Script方法的典型用法代码示例。如果您正苦于以下问题:PHP API::Script方法的具体用法?PHP API::Script怎么用?PHP API::Script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::Script方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doAction
protected function doAction()
{
$script = [];
$this->getInputs($script, ['scriptid', 'name', 'type', 'execute_on', 'command', 'description', 'usrgrpid', 'groupid', 'host_access']);
$script['confirmation'] = $this->getInput('confirmation', '');
if ($this->getInput('type', ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT) == ZBX_SCRIPT_TYPE_IPMI && $this->hasInput('commandipmi')) {
$script['command'] = $this->getInput('commandipmi');
}
if ($this->getInput('hgstype', 1) == 0) {
$script['groupid'] = 0;
}
DBstart();
$result = API::Script()->update($script);
if ($result) {
$scriptId = reset($result['scriptids']);
add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_SCRIPT, 'Name [' . $this->getInput('name', '') . '] id [' . $scriptId . ']');
}
$result = DBend($result);
if ($result) {
$response = new CControllerResponseRedirect('zabbix.php?action=script.list&uncheck=1');
$response->setMessageOk(_('Script updated'));
} else {
$response = new CControllerResponseRedirect('zabbix.php?action=script.edit&scriptid=' . $this->getInput('scriptid'));
$response->setFormData($this->getInputAll());
$response->setMessageError(_('Cannot update script'));
}
$this->setResponse($response);
}
示例2: doAction
protected function doAction()
{
$sortField = $this->getInput('sort', CProfile::get('web.scripts.php.sort', 'name'));
$sortOrder = $this->getInput('sortorder', CProfile::get('web.scripts.php.sortorder', ZBX_SORT_UP));
CProfile::update('web.scripts.php.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.scripts.php.sortorder', $sortOrder, PROFILE_TYPE_STR);
$config = select_config();
$data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder];
// list of scripts
$data['scripts'] = API::Script()->get(['output' => ['scriptid', 'name', 'command', 'host_access', 'usrgrpid', 'groupid', 'type', 'execute_on'], 'editable' => true, 'limit' => $config['search_limit'] + 1]);
// sorting & paging
order_result($data['scripts'], $sortField, $sortOrder);
$url = (new CUrl('zabbix.php'))->setArgument('action', 'script.list');
$data['paging'] = getPagingLine($data['scripts'], $sortOrder, $url);
// find script host group name and user group name. set to '' if all host/user groups used.
$usrgrpids = [];
$groupids = [];
foreach ($data['scripts'] as &$script) {
$script['userGroupName'] = null;
// all user groups
$script['hostGroupName'] = null;
// all host groups
if ($script['usrgrpid'] != 0) {
$usrgrpids[] = $script['usrgrpid'];
}
if ($script['groupid'] != 0) {
$groupids[] = $script['groupid'];
}
}
unset($script);
if ($usrgrpids) {
$userGroups = API::UserGroup()->get(['output' => ['name'], 'usrgrpids' => $usrgrpids, 'preservekeys' => true]);
foreach ($data['scripts'] as &$script) {
if ($script['usrgrpid'] != 0 && array_key_exists($script['usrgrpid'], $userGroups)) {
$script['userGroupName'] = $userGroups[$script['usrgrpid']]['name'];
}
unset($script['usrgrpid']);
}
unset($script);
}
if ($groupids) {
$hostGroups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupids, 'preservekeys' => true]);
foreach ($data['scripts'] as &$script) {
if ($script['groupid'] != 0 && array_key_exists($script['groupid'], $hostGroups)) {
$script['hostGroupName'] = $hostGroups[$script['groupid']]['name'];
}
unset($script['groupid']);
}
unset($script);
}
$response = new CControllerResponseData($data);
$response->setTitle(_('Configuration of scripts'));
$this->setResponse($response);
}
示例3: getActionMapBySysmap
function getActionMapBySysmap($sysmap)
{
$action_map = new CAreaMap('links' . $sysmap['sysmapid']);
$areas = populateFromMapAreas($sysmap);
$map_info = getSelementsInfo($sysmap);
processAreasCoordinates($sysmap, $areas, $map_info);
$hostids = array();
foreach ($sysmap['selements'] as $sid => &$selement) {
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
$hostids[$selement['elementid']] = $selement['elementid'];
// expanding hosts url macros again as some hosts were added from hostgroup areeas
// and automatic expanding only happens for elements that are defined for map in db
foreach ($selement['urls'] as $urlid => $url) {
$selement['urls'][$urlid]['url'] = str_replace('{HOST.ID}', $selement['elementid'], $url['url']);
}
}
if ($selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) {
unset($sysmap['selements'][$sid]);
}
}
unset($selement);
if (count($hostids)) {
$scripts_by_hosts = API::Script()->getScriptsByHosts($hostids);
}
$hosts = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'hostids' => $hostids, 'output' => array('status'), 'nopermissions' => true, 'preservekeys' => true, 'selectScreens' => API_OUTPUT_COUNT));
foreach ($sysmap['selements'] as $elem) {
$back = get_png_by_selement($map_info[$elem['selementid']]);
$area = new CArea(array($elem['x'], $elem['y'], $elem['x'] + imagesx($back), $elem['y'] + imagesy($back)), '', '', 'rect');
$area->addClass('menu-map');
// pop up menu
order_result($elem['urls'], 'name');
$menuData = array('urls' => array_values($elem['urls']), 'elementId' => $elem['elementid'], 'elementType' => $elem['elementtype'], 'scripts' => array(), 'hasScreens' => false, 'isMonitored' => false);
if ($elem['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
$host = $hosts[$elem['elementid']];
$menuData['scripts'] = $scripts_by_hosts[$elem['elementid']];
$menuData['hasScreens'] = (bool) $host['screens'];
$menuData['isMonitored'] = $hosts[$elem['elementid']]['status'] == HOST_STATUS_MONITORED;
}
$area->setAttribute('data-menu', $menuData);
$action_map->addItem($area);
}
return $action_map;
}
示例4: doAction
protected function doAction()
{
$scriptids = $this->getInput('scriptids');
DBstart();
$result = API::Script()->delete($scriptids);
if ($result) {
foreach ($scriptids as $scriptid) {
add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_SCRIPT, _('Script') . ' [' . $scriptid . ']');
}
}
$result = DBend($result);
$deleted = count($scriptids);
$response = new CControllerResponseRedirect('zabbix.php?action=script.list&uncheck=1');
if ($result) {
$response->setMessageOk(_n('Script deleted', 'Scripts deleted', $deleted));
} else {
$response->setMessageError(_n('Cannot delete script', 'Cannot delete scripts', $deleted));
}
$this->setResponse($response);
}
示例5: doAction
protected function doAction()
{
// default values
$data = ['sid' => $this->getUserSID(), 'scriptid' => 0, 'name' => '', 'type' => ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT, 'execute_on' => ZBX_SCRIPT_EXECUTE_ON_AGENT, 'command' => '', 'commandipmi' => '', 'description' => '', 'usrgrpid' => 0, 'groupid' => 0, 'host_access' => 0, 'confirmation' => '', 'enable_confirmation' => 0, 'hgstype' => 0];
// get values from the dabatase
if ($this->hasInput('scriptid')) {
$scripts = API::Script()->get(['output' => ['scriptid', 'name', 'type', 'execute_on', 'command', 'description', 'usrgrpid', 'groupid', 'host_access', 'confirmation'], 'scriptids' => $this->getInput('scriptid')]);
$script = $scripts[0];
$data['scriptid'] = $script['scriptid'];
$data['name'] = $script['name'];
$data['type'] = $script['type'];
$data['execute_on'] = $script['execute_on'];
$data['command'] = $script['type'] == ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT ? $script['command'] : '';
$data['commandipmi'] = $script['type'] == ZBX_SCRIPT_TYPE_IPMI ? $script['command'] : '';
$data['description'] = $script['description'];
$data['usrgrpid'] = $script['usrgrpid'];
$data['groupid'] = $script['groupid'];
$data['host_access'] = $script['host_access'];
$data['confirmation'] = $script['confirmation'];
$data['enable_confirmation'] = $script['confirmation'] !== '';
$data['hgstype'] = $script['groupid'] != 0 ? 1 : 0;
}
// overwrite with input variables
$this->getInputs($data, ['name', 'type', 'execute_on', 'command', 'commandipmi', 'description', 'usrgrpid', 'groupid', 'host_access', 'confirmation', 'enable_confirmation', 'hgstype']);
// get host group
if ($data['groupid'] == 0) {
$data['hostgroup'] = null;
} else {
$hostgroups = API::HostGroup()->get(['groupids' => [$data['groupid']], 'output' => ['groupid', 'name']]);
$hostgroup = $hostgroups[0];
$data['hostgroup'][] = ['id' => $hostgroup['groupid'], 'name' => $hostgroup['name']];
}
// get list of user groups
$usergroups = API::UserGroup()->get(['output' => ['usrgrpid', 'name']]);
order_result($usergroups, 'name');
$data['usergroups'] = $usergroups;
$response = new CControllerResponseData($data);
$response->setTitle(_('Configuration of scripts'));
$this->setResponse($response);
}
示例6: get_operation_descr
//.........这里部分代码省略.........
$result[] = array(implode(', ', zbx_objectValues($groups, 'name')), BR());
}
break;
case OPERATION_TYPE_HOST_ADD:
$result[] = array(bold(_('Add host')), BR());
break;
case OPERATION_TYPE_HOST_REMOVE:
$result[] = array(bold(_('Remove host')), BR());
break;
case OPERATION_TYPE_HOST_ENABLE:
$result[] = array(bold(_('Enable host')), BR());
break;
case OPERATION_TYPE_HOST_DISABLE:
$result[] = array(bold(_('Disable host')), BR());
break;
case OPERATION_TYPE_GROUP_ADD:
case OPERATION_TYPE_GROUP_REMOVE:
if (!isset($data['opgroup'])) {
$data['opgroup'] = array();
}
$groups = API::HostGroup()->get(array('groupids' => zbx_objectValues($data['opgroup'], 'groupid'), 'output' => array('groupid', 'name')));
if (!empty($groups)) {
order_result($groups, 'name');
if (OPERATION_TYPE_GROUP_ADD == $data['operationtype']) {
$result[] = bold(_('Add to host groups') . NAME_DELIMITER);
} else {
$result[] = bold(_('Remove from host groups') . NAME_DELIMITER);
}
$result[] = array(implode(', ', zbx_objectValues($groups, 'name')), BR());
}
break;
case OPERATION_TYPE_TEMPLATE_ADD:
case OPERATION_TYPE_TEMPLATE_REMOVE:
if (!isset($data['optemplate'])) {
$data['optemplate'] = array();
}
$templates = API::Template()->get(array('templateids' => zbx_objectValues($data['optemplate'], 'templateid'), 'output' => array('hostid', 'name')));
if (!empty($templates)) {
order_result($templates, 'name');
if (OPERATION_TYPE_TEMPLATE_ADD == $data['operationtype']) {
$result[] = bold(_('Link to templates') . NAME_DELIMITER);
} else {
$result[] = bold(_('Unlink from templates') . NAME_DELIMITER);
}
$result[] = array(implode(', ', zbx_objectValues($templates, 'name')), BR());
}
break;
default:
}
} else {
switch ($data['operationtype']) {
case OPERATION_TYPE_MESSAGE:
if (isset($data['opmessage']['default_msg']) && !empty($data['opmessage']['default_msg'])) {
if (isset($_REQUEST['def_shortdata']) && isset($_REQUEST['def_longdata'])) {
$result[] = array(bold(_('Subject') . NAME_DELIMITER), BR(), zbx_nl2br($_REQUEST['def_shortdata']));
$result[] = array(bold(_('Message') . NAME_DELIMITER), BR(), zbx_nl2br($_REQUEST['def_longdata']));
} elseif (isset($data['opmessage']['operationid'])) {
$sql = 'SELECT a.def_shortdata,a.def_longdata ' . ' FROM actions a,operations o ' . ' WHERE a.actionid=o.actionid ' . ' AND o.operationid=' . zbx_dbstr($data['operationid']);
if ($rows = DBfetch(DBselect($sql, 1))) {
$result[] = array(bold(_('Subject') . NAME_DELIMITER), BR(), zbx_nl2br($rows['def_shortdata']));
$result[] = array(bold(_('Message') . NAME_DELIMITER), BR(), zbx_nl2br($rows['def_longdata']));
}
}
} else {
$result[] = array(bold(_('Subject') . NAME_DELIMITER), BR(), zbx_nl2br($data['opmessage']['subject']));
$result[] = array(bold(_('Message') . NAME_DELIMITER), BR(), zbx_nl2br($data['opmessage']['message']));
}
break;
case OPERATION_TYPE_COMMAND:
switch ($data['opcommand']['type']) {
case ZBX_SCRIPT_TYPE_IPMI:
$result[] = array(bold(_('Run IPMI command') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command'])));
break;
case ZBX_SCRIPT_TYPE_SSH:
$result[] = array(bold(_('Run SSH commands') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command'])));
break;
case ZBX_SCRIPT_TYPE_TELNET:
$result[] = array(bold(_('Run TELNET commands') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command'])));
break;
case ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT:
if ($data['opcommand']['execute_on'] == ZBX_SCRIPT_EXECUTE_ON_AGENT) {
$result[] = array(bold(_('Run custom commands on Zabbix agent') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command'])));
} else {
$result[] = array(bold(_('Run custom commands on Zabbix server') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command'])));
}
break;
case ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT:
$userScripts = API::Script()->get(array('scriptids' => $data['opcommand']['scriptid'], 'output' => API_OUTPUT_EXTEND));
$userScript = reset($userScripts);
$result[] = array(bold(_('Run global script') . NAME_DELIMITER), italic($userScript['name']));
break;
default:
$result[] = array(bold(_('Run commands') . NAME_DELIMITER), BR(), italic(zbx_nl2br($data['opcommand']['command'])));
}
break;
default:
}
}
return $result;
}
示例7: delete
/**
* Delete UserGroups.
*
* @param array $usrgrpids
* @return boolean
*/
public function delete($usrgrpids)
{
$usrgrpids = zbx_toArray($usrgrpids);
$dbUsrgrps = $this->get(array('output' => array('usrgrpid', 'name'), 'usrgrpids' => $usrgrpids, 'preservekeys' => true));
if (empty($usrgrpids)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
}
if (USER_TYPE_SUPER_ADMIN != self::$userData['type']) {
// GETTEXT: API exception
self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only Super Admins can delete user groups.'));
}
// check, if this user group is used in one of the scripts. If so, it cannot be deleted
$dbScripts = API::Script()->get(array('output' => array('scriptid', 'name', 'usrgrpid'), 'usrgrpids' => $usrgrpids, 'nopermissions' => true));
if (!empty($dbScripts)) {
foreach ($dbScripts as $snum => $script) {
if ($script['usrgrpid'] == 0) {
continue;
}
self::exception(ZBX_API_ERROR_PARAMETERS, _s('User group "%1$s" is used in script "%2$s".', $dbUsrgrps[$script['usrgrpid']]['name'], $script['name']));
}
}
// check, if this user group is used in the config. If so, it cannot be deleted
$config = select_config();
if (isset($dbUsrgrps[$config['alert_usrgrpid']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('User group [%s] is used in configuration for database down messages.', $dbUsrgrps[$config['alert_usrgrpid']]['name']));
}
// delete action operation msg
$operationids = array();
$sql = 'SELECT DISTINCT om.operationid' . ' FROM opmessage_grp om' . ' WHERE ' . dbConditionInt('om.usrgrpid', $usrgrpids);
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$operationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('opmessage_grp', array('usrgrpid' => $usrgrpids));
// delete empty operations
$delOperationids = array();
$sql = 'SELECT DISTINCT o.operationid' . ' FROM operations o' . ' WHERE ' . dbConditionInt('o.operationid', $operationids) . ' AND NOT EXISTS(SELECT om.opmessage_grpid FROM opmessage_grp om WHERE om.operationid=o.operationid)';
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$delOperationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('operations', array('operationid' => $delOperationids));
DB::delete('rights', array('groupid' => $usrgrpids));
DB::delete('users_groups', array('usrgrpid' => $usrgrpids));
DB::delete('usrgrp', array('usrgrpid' => $usrgrpids));
return array('usrgrpids' => $usrgrpids);
}
示例8: getItemsDataOverview
/**
* Retrieve overview table object for items.
*
* @param array $hostIds
* @param string $application name of application to filter
* @param int $viewMode
*
* @return CTableInfo
*/
function getItemsDataOverview($hostIds, $application, $viewMode)
{
$sqlFrom = '';
$sqlWhere = '';
if ($application !== '') {
$sqlFrom = 'applications a,items_applications ia,';
$sqlWhere = ' AND i.itemid=ia.itemid AND a.applicationid=ia.applicationid AND a.name=' . zbx_dbstr($application);
}
$dbItems = DBfetchArray(DBselect('SELECT DISTINCT h.hostid,h.name AS hostname,i.itemid,i.key_,i.value_type,i.units,' . 'i.name,t.priority,i.valuemapid,t.value AS tr_value,t.triggerid' . ' FROM hosts h,' . $sqlFrom . 'items i' . ' LEFT JOIN functions f ON f.itemid=i.itemid' . ' LEFT JOIN triggers t ON t.triggerid=f.triggerid AND t.status=' . TRIGGER_STATUS_ENABLED . ' WHERE ' . dbConditionInt('h.hostid', $hostIds) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . $sqlWhere));
$dbItems = CMacrosResolverHelper::resolveItemNames($dbItems);
CArrayHelper::sort($dbItems, array(array('field' => 'name_expanded', 'order' => ZBX_SORT_UP), array('field' => 'itemid', 'order' => ZBX_SORT_UP)));
// fetch latest values
$history = Manager::History()->getLast(zbx_toHash($dbItems, 'itemid'), 1, ZBX_HISTORY_PERIOD);
// fetch data for the host JS menu
$hosts = API::Host()->get(array('output' => array('name', 'hostid', 'status'), 'monitored_hosts' => true, 'hostids' => $hostIds, 'with_monitored_items' => true, 'preservekeys' => true, 'selectScreens' => $viewMode == STYLE_LEFT ? API_OUTPUT_COUNT : null));
$items = array();
foreach ($dbItems as $dbItem) {
$name = $dbItem['name_expanded'];
$dbItem['hostname'] = get_node_name_by_elid($dbItem['hostid'], null, NAME_DELIMITER) . $dbItem['hostname'];
$hostNames[$dbItem['hostid']] = $dbItem['hostname'];
// a little tricky check for attempt to overwrite active trigger (value=1) with
// inactive or active trigger with lower priority.
if (!isset($items[$name][$dbItem['hostname']]) || ($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE && $dbItem['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE || $dbItem['tr_value'] == TRIGGER_VALUE_TRUE) && $dbItem['priority'] > $items[$name][$dbItem['hostname']]['severity'])) {
$items[$name][$dbItem['hostname']] = array('itemid' => $dbItem['itemid'], 'value_type' => $dbItem['value_type'], 'value' => isset($history[$dbItem['itemid']]) ? $history[$dbItem['itemid']][0]['value'] : null, 'units' => $dbItem['units'], 'name' => $name, 'valuemapid' => $dbItem['valuemapid'], 'severity' => $dbItem['priority'], 'tr_value' => $dbItem['tr_value'], 'triggerid' => $dbItem['triggerid']);
}
}
$table = new CTableInfo(_('No items found.'));
if (empty($hostNames)) {
return $table;
}
$table->makeVerticalRotation();
order_result($hostNames);
if ($viewMode == STYLE_TOP) {
$header = array(new CCol(_('Items'), 'center'));
foreach ($hostNames as $hostName) {
$header[] = new CCol($hostName, 'vertical_rotation');
}
$table->setHeader($header, 'vertical_header');
foreach ($items as $descr => $ithosts) {
$tableRow = array(nbsp($descr));
foreach ($hostNames as $hostName) {
$tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName);
}
$table->addRow($tableRow);
}
} else {
$scripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid'));
$header = array(new CCol(_('Hosts'), 'center'));
foreach ($items as $descr => $ithosts) {
$header[] = new CCol($descr, 'vertical_rotation');
}
$table->setHeader($header, 'vertical_header');
foreach ($hostNames as $hostId => $hostName) {
$host = $hosts[$hostId];
$name = new CSpan($host['name'], 'link_menu');
$name->setMenuPopup(getMenuPopupHost($host, $scripts[$hostId]));
$tableRow = array(new CCol($name));
foreach ($items as $ithosts) {
$tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName);
}
$table->addRow($tableRow);
}
}
return $table;
}
示例9: make_trigger_details
function make_trigger_details($trigger)
{
$table = new CTableInfo();
if (is_show_all_nodes()) {
$table->addRow(array(_('Node'), get_node_name_by_elid($trigger['triggerid'])));
}
$expression = explode_exp($trigger['expression'], true, true);
$host = API::Host()->get(array('output' => array('name', 'hostid'), 'hostids' => $trigger['hosts'][0]['hostid'], 'selectScreens' => API_OUTPUT_COUNT, 'selectInventory' => array('hostid'), 'preservekeys' => true));
$host = reset($host);
$hostScripts = API::Script()->getScriptsByHosts($host['hostid']);
// host js link
$hostSpan = new CSpan($host['name'], 'link_menu menu-host');
$scripts = $hostScripts[$host['hostid']];
$hostSpan->attr('data-menu', hostMenuData($host, $scripts));
// get visible name of the first host
$table->addRow(array(_('Host'), $hostSpan));
$table->addRow(array(_('Trigger'), CTriggerHelper::expandDescription($trigger)));
$table->addRow(array(_('Severity'), getSeverityCell($trigger['priority'])));
$table->addRow(array(_('Expression'), $expression));
$table->addRow(array(_('Event generation'), _('Normal') . (TRIGGER_MULT_EVENT_ENABLED == $trigger['type'] ? SPACE . '+' . SPACE . _('Multiple PROBLEM events') : '')));
$table->addRow(array(_('Disabled'), TRIGGER_STATUS_ENABLED == $trigger['status'] ? new CCol(_('No'), 'off') : new CCol(_('Yes'), 'on')));
return $table;
}
示例10: getActionMapBySysmap
/**
* Create map area with submenu for sysmap elements.
* In submenu gathered information about urls, scripts and submaps.
*
* @param array $sysmap
* @param array $options
* @param int $options['severity_min']
*
* @return CAreaMap
*/
function getActionMapBySysmap($sysmap, array $options = array())
{
$sysmap['selements'] = zbx_toHash($sysmap['selements'], 'selementid');
$sysmap['links'] = zbx_toHash($sysmap['links'], 'linkid');
$actionMap = new CAreaMap('links' . $sysmap['sysmapid']);
$areas = populateFromMapAreas($sysmap);
$mapInfo = getSelementsInfo($sysmap, $options);
processAreasCoordinates($sysmap, $areas, $mapInfo);
$hostIds = array();
$triggerIds = array();
foreach ($sysmap['selements'] as $id => &$selement) {
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
$hostIds[$selement['elementid']] = $selement['elementid'];
// expanding host URL macros again as some hosts were added from hostgroup areas
// and automatic expanding only happens for elements that are defined for map in db
foreach ($selement['urls'] as $urlId => $url) {
$selement['urls'][$urlId]['url'] = str_replace('{HOST.ID}', $selement['elementid'], $url['url']);
}
} elseif ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) {
$triggerIds[$selement['elementid']] = $selement['elementid'];
}
if ($selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) {
unset($sysmap['selements'][$id]);
}
}
unset($selement);
$hostScripts = API::Script()->getScriptsByHosts($hostIds);
$hosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid', 'status'), 'nopermissions' => true, 'preservekeys' => true, 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT));
$triggers = API::Trigger()->get(array('output' => array('triggerid'), 'triggerids' => $triggerIds, 'selectHosts' => array('status'), 'preservekeys' => true, 'nopermissions' => true));
foreach ($sysmap['selements'] as $elem) {
$back = get_png_by_selement($mapInfo[$elem['selementid']]);
$area = new CArea(array($elem['x'], $elem['y'], $elem['x'] + imagesx($back), $elem['y'] + imagesy($back)), '', '', 'rect');
$area->addClass('menu-map');
$hostId = null;
$scripts = null;
$gotos = null;
switch ($elem['elementtype']) {
case SYSMAP_ELEMENT_TYPE_HOST:
$host = $hosts[$elem['elementid']];
if ($hostScripts[$elem['elementid']]) {
$hostId = $elem['elementid'];
$scripts = $hostScripts[$elem['elementid']];
}
$gotos['triggerStatus'] = array('hostid' => $elem['elementid'], 'show_severity' => isset($options['severity_min']) ? $options['severity_min'] : null);
$gotos['showTriggers'] = $hosts[$elem['elementid']]['status'] == HOST_STATUS_MONITORED;
$gotos['graphs'] = array('hostid' => $host['hostid']);
$gotos['showGraphs'] = (bool) $host['graphs'];
$gotos['screens'] = array('hostid' => $host['hostid']);
$gotos['showScreens'] = (bool) $host['screens'];
$gotos['inventory'] = array('hostid' => $host['hostid']);
$gotos['latestData'] = array('hostids' => array($host['hostid']));
break;
case SYSMAP_ELEMENT_TYPE_MAP:
$gotos['submap'] = array('sysmapid' => $elem['elementid'], 'severity_min' => isset($options['severity_min']) ? $options['severity_min'] : null);
break;
case SYSMAP_ELEMENT_TYPE_TRIGGER:
$gotos['events'] = array('triggerid' => $elem['elementid'], 'stime' => date(TIMESTAMP_FORMAT, time() - SEC_PER_WEEK), 'period' => SEC_PER_WEEK);
$gotos['showEvents'] = false;
if (isset($triggers[$elem['elementid']])) {
foreach ($triggers[$elem['elementid']]['hosts'] as $host) {
if ($host['status'] == HOST_STATUS_MONITORED) {
$gotos['showEvents'] = true;
break;
}
}
}
break;
case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
$gotos['triggerStatus'] = array('groupid' => $elem['elementid'], 'hostid' => 0, 'show_severity' => isset($options['severity_min']) ? $options['severity_min'] : null);
// always show active trigger link for host group map elements
$gotos['showTriggers'] = true;
break;
}
order_result($elem['urls'], 'name');
$area->setMenuPopup(CMenuPopupHelper::getMap($hostId, $scripts, $gotos, $elem['urls']));
$actionMap->addItem($area);
}
return $actionMap;
}
示例11: dirname
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/hosts.inc.php';
require_once dirname(__FILE__) . '/include/forms.inc.php';
$page['title'] = _('Scripts');
$page['file'] = 'scripts_exec.php';
define('ZBX_PAGE_NO_MENU', 1);
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array('hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'scriptid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'execute' => array(T_ZBX_INT, O_OPT, P_ACT, IN('0,1'), null));
check_fields($fields);
if (isset($_REQUEST['execute'])) {
$scriptid = get_request('scriptid');
$hostid = get_request('hostid');
$data = array('message' => '', 'info' => DBfetch(DBselect('SELECT s.name FROM scripts s WHERE s.scriptid=' . zbx_dbstr($scriptid))));
$result = API::Script()->execute(array('hostid' => $hostid, 'scriptid' => $scriptid));
$isErrorExist = false;
if (empty($result)) {
$isErrorExist = true;
} elseif ($result['response'] == 'failed') {
error($result['value']);
$isErrorExist = true;
} else {
$data['message'] = $result['value'];
}
if ($isErrorExist) {
show_error_message(_('Cannot connect to the trapper port of zabbix server daemon, but it should be available to run the script.'));
}
// render view
$scriptView = new CView('general.script.execute', $data);
$scriptView->render();
示例12: array_keys
$triggersEventCount[$row['objectid']] = $row['cnt_event'];
}
$triggers = API::Trigger()->get(array('triggerids' => array_keys($triggersEventCount), 'output' => array('triggerid', 'description', 'expression', 'priority', 'flags', 'lastchange'), 'selectItems' => array('hostid', 'name', 'value_type', 'key_'), 'expandDescription' => true, 'expandData' => true, 'preservekeys' => true, 'nopermissions' => true));
$hosts = array();
foreach ($triggers as $tid => $trigger) {
$hosts[$trigger['hostid']] = $trigger['hostid'];
$trigger['cnt_event'] = $triggersEventCount[$tid];
$items = $trigger['items'];
$trigger['items'] = array();
foreach ($items as $item) {
$trigger['items'][$item['itemid']] = array('itemid' => $item['itemid'], 'action' => str_in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues', 'name' => itemName($item), 'value_type' => $item['value_type']);
}
$triggers[$tid] = $trigger;
}
CArrayHelper::sort($triggers, array(array('field' => 'cnt_event', 'order' => ZBX_SORT_DOWN), 'host', 'description', 'priority'));
$scripts_by_hosts = API::Script()->getScriptsByHosts($hosts);
foreach ($triggers as $trigger) {
$menus = '';
$host_nodeid = id2nodeid($trigger['hostid']);
foreach ($scripts_by_hosts[$trigger['hostid']] as $script) {
$script_nodeid = id2nodeid($script['scriptid']);
if (bccomp($host_nodeid, $script_nodeid) == 0) {
$menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $trigger['hostid'] . "&scriptid=" . $script['scriptid'] . "','Global script',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
}
}
$menus .= "['" . _('URLs') . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],";
$menus .= "['" . _('Latest data') . "',\"javascript: redirect('latest.php?hostid=" . $trigger['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}]";
$menus = "show_popup_menu(event,[['" . _('Scripts') . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus . "],180);";
$hostSpan = new CSpan($trigger['hostname'], 'link_menu');
$hostSpan->setAttribute('onclick', $menus);
$tr_conf_link = 'null';
示例13: array
$scriptView->set('hostGroup', $hostGroup);
// get list of user groups
$usergroups = API::UserGroup()->get(array('output' => array('usrgrpid', 'name')));
order_result($usergroups, 'name');
$scriptView->set('usergroups', $usergroups);
// render view
$scriptView->render();
$scriptView->show();
} else {
$sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
$sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR);
$data = array('sort' => $sortField, 'sortorder' => $sortOrder);
// list of scripts
$data['scripts'] = API::Script()->get(array('output' => array('scriptid', 'name', 'command', 'host_access', 'usrgrpid', 'groupid', 'type', 'execute_on'), 'editable' => true, 'selectGroups' => API_OUTPUT_EXTEND));
// find script host group name and user group name. set to '' if all host/user groups used.
foreach ($data['scripts'] as $key => $script) {
$scriptId = $script['scriptid'];
if ($script['usrgrpid'] > 0) {
$userGroup = API::UserGroup()->get(array('usrgrpids' => $script['usrgrpid'], 'output' => API_OUTPUT_EXTEND));
$userGroup = reset($userGroup);
$data['scripts'][$key]['userGroupName'] = $userGroup['name'];
} else {
$data['scripts'][$key]['userGroupName'] = '';
// all user groups
}
if ($script['groupid'] > 0) {
$group = array_pop($script['groups']);
$data['scripts'][$key]['hostGroupName'] = $group['name'];
} else {
示例14: validateOperations
public function validateOperations($operations)
{
$operations = zbx_toArray($operations);
foreach ($operations as $operation) {
if ((isset($operation['esc_step_from']) || isset($operation['esc_step_to'])) && !isset($operation['esc_step_from'], $operation['esc_step_to'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('esc_step_from and esc_step_to must be set together.'));
}
if (isset($operation['esc_step_from'], $operation['esc_step_to'])) {
if ($operation['esc_step_from'] < 1 || $operation['esc_step_to'] < 0) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation escalation step values.'));
}
if ($operation['esc_step_from'] > $operation['esc_step_to'] && $operation['esc_step_to'] != 0) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation escalation step values.'));
}
}
if (isset($operation['esc_period'])) {
if (isset($operation['esc_period']) && $operation['esc_period'] != 0 && $operation['esc_period'] < SEC_PER_MIN) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation step duration.'));
}
}
$hostIdsAll = $hostGroupIdsAll = $useridsAll = $userGroupidsAll = array();
switch ($operation['operationtype']) {
case OPERATION_TYPE_MESSAGE:
$userids = isset($operation['opmessage_usr']) ? zbx_objectValues($operation['opmessage_usr'], 'userid') : array();
$usergroupids = isset($operation['opmessage_grp']) ? zbx_objectValues($operation['opmessage_grp'], 'usrgrpid') : array();
if (empty($userids) && empty($usergroupids)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No recipients for action operation message.'));
}
$useridsAll = array_merge($useridsAll, $userids);
$userGroupidsAll = array_merge($userGroupidsAll, $usergroupids);
break;
case OPERATION_TYPE_COMMAND:
if (!isset($operation['opcommand']['type'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No command type specified for action operation.'));
}
if ((!isset($operation['opcommand']['command']) || zbx_empty(trim($operation['opcommand']['command']))) && $operation['opcommand']['type'] != ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No command specified for action operation.'));
}
switch ($operation['opcommand']['type']) {
case ZBX_SCRIPT_TYPE_IPMI:
break;
case ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT:
if (!isset($operation['opcommand']['execute_on'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No execution target specified for action operation command "%s".', $operation['opcommand']['command']));
}
break;
case ZBX_SCRIPT_TYPE_SSH:
if (!isset($operation['opcommand']['authtype']) || zbx_empty($operation['opcommand']['authtype'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No authentication type specified for action operation command "%s".', $operation['opcommand']['command']));
}
if (!isset($operation['opcommand']['username']) || zbx_empty($operation['opcommand']['username'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No authentication user name specified for action operation command "%s".', $operation['opcommand']['command']));
}
if ($operation['opcommand']['authtype'] == ITEM_AUTHTYPE_PUBLICKEY) {
if (!isset($operation['opcommand']['publickey']) || zbx_empty($operation['opcommand']['publickey'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No public key file specified for action operation command "%s".', $operation['opcommand']['command']));
}
if (!isset($operation['opcommand']['privatekey']) || zbx_empty($operation['opcommand']['privatekey'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No private key file specified for action operation command "%s".', $operation['opcommand']['command']));
}
}
break;
case ZBX_SCRIPT_TYPE_TELNET:
if (!isset($operation['opcommand']['username']) || zbx_empty($operation['opcommand']['username'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No authentication user name specified for action operation command "%s".', $operation['opcommand']['command']));
}
break;
case ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT:
if (!isset($operation['opcommand']['scriptid']) || zbx_empty($operation['opcommand']['scriptid'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No script specified for action operation command.'));
}
$scripts = API::Script()->get(array('output' => array('scriptid', 'name'), 'scriptids' => $operation['opcommand']['scriptid'], 'preservekeys' => true));
if (!isset($scripts[$operation['opcommand']['scriptid']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Specified script does not exist or you do not have rights on it for action operation command.'));
}
break;
default:
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect action operation command type.'));
}
if (isset($operation['opcommand']['port']) && !zbx_empty($operation['opcommand']['port'])) {
if (zbx_ctype_digit($operation['opcommand']['port'])) {
if ($operation['opcommand']['port'] > 65535 || $operation['opcommand']['port'] < 1) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action operation port "%s".', $operation['opcommand']['port']));
}
} elseif (!preg_match('/^' . ZBX_PREG_EXPRESSION_USER_MACROS . '$/', $operation['opcommand']['port'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect action operation port "%s".', $operation['opcommand']['port']));
}
}
$groupids = array();
if (isset($operation['opcommand_grp'])) {
$groupids = zbx_objectValues($operation['opcommand_grp'], 'groupid');
}
$hostids = array();
$withoutCurrent = true;
if (isset($operation['opcommand_hst'])) {
foreach ($operation['opcommand_hst'] as $hstCommand) {
if ($hstCommand['hostid'] == 0) {
$withoutCurrent = false;
} else {
$hostids[$hstCommand['hostid']] = $hstCommand['hostid'];
//.........这里部分代码省略.........
示例15: delete
/**
* Delete host groups.
*
* @param array $groupids
*
* @return boolean
*/
public function delete($groupids)
{
if (empty($groupids)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
}
$groupids = zbx_toArray($groupids);
$options = array('groupids' => $groupids, 'editable' => true, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true);
$delGroups = $this->get($options);
foreach ($groupids as $groupid) {
if (!isset($delGroups[$groupid])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.'));
}
if ($delGroups[$groupid]['internal'] == ZBX_INTERNAL_GROUP) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Group "%1$s" is internal and can not be deleted.', $delGroups[$groupid]['name']));
}
}
$dltGroupids = getDeletableHostGroups($groupids);
if (count($groupids) != count($dltGroupids)) {
foreach ($groupids as $groupid) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Group "%s" cannot be deleted, because some hosts depend on it.', $delGroups[$groupid]['name']));
}
}
$dbScripts = API::Script()->get(array('groupids' => $groupids, 'output' => array('scriptid', 'groupid'), 'nopermissions' => true));
if (!empty($dbScripts)) {
foreach ($dbScripts as $script) {
if ($script['groupid'] == 0) {
continue;
}
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Group "%s" cannot be deleted, because it is used in a global script.', $delGroups[$script['groupid']]['name']));
}
}
// delete screens items
$resources = array(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW);
DB::delete('screens_items', array('resourceid' => $groupids, 'resourcetype' => $resources));
// delete sysmap element
if (!empty($groupids)) {
DB::delete('sysmaps_elements', array('elementtype' => SYSMAP_ELEMENT_TYPE_HOST_GROUP, 'elementid' => $groupids));
}
// disable actions
// actions from conditions
$actionids = array();
$dbActions = DBselect('SELECT DISTINCT c.actionid' . ' FROM conditions c' . ' WHERE c.conditiontype=' . CONDITION_TYPE_HOST_GROUP . ' AND ' . dbConditionString('c.value', $groupids));
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
// actions from operations
$dbActions = DBselect('SELECT DISTINCT o.actionid' . ' FROM operations o,opgroup og' . ' WHERE o.operationid=og.operationid' . ' AND ' . dbConditionInt('og.groupid', $groupids));
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
if (!empty($actionids)) {
$update = array();
$update[] = array('values' => array('status' => ACTION_STATUS_DISABLED), 'where' => array('actionid' => $actionids));
DB::update('actions', $update);
}
// delete action conditions
DB::delete('conditions', array('conditiontype' => CONDITION_TYPE_HOST_GROUP, 'value' => $groupids));
// delete action operation commands
$operationids = array();
$dbOperations = DBselect('SELECT DISTINCT og.operationid' . ' FROM opgroup og' . ' WHERE ' . dbConditionInt('og.groupid', $groupids));
while ($dbOperation = DBfetch($dbOperations)) {
$operationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('opgroup', array('groupid' => $groupids));
// delete empty operations
$delOperationids = array();
$dbOperations = DBselect('SELECT DISTINCT o.operationid' . ' FROM operations o' . ' WHERE ' . dbConditionInt('o.operationid', $operationids) . ' AND NOT EXISTS (SELECT NULL FROM opgroup og WHERE o.operationid=og.operationid)');
while ($dbOperation = DBfetch($dbOperations)) {
$delOperationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('operations', array('operationid' => $delOperationids));
// host groups
DB::delete('groups', array('groupid' => $groupids));
// TODO: remove audit
foreach ($groupids as $groupid) {
add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_HOST_GROUP, $groupid, $delGroups[$groupid]['name'], 'groups', null, null);
}
return array('groupids' => $groupids);
}