protected function doAction() { $sortField = $this->getInput('sort', CProfile::get('web.media_types.php.sort', 'description')); $sortOrder = $this->getInput('sortorder', CProfile::get('web.media_types.php.sortorder', ZBX_SORT_UP)); CProfile::update('web.media_type.php.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.media_types.php.sortorder', $sortOrder, PROFILE_TYPE_STR); $config = select_config(); $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder]; // get media types $data['mediatypes'] = API::Mediatype()->get(['output' => ['mediatypeid', 'description', 'type', 'smtp_server', 'smtp_helo', 'smtp_email', 'exec_path', 'gsm_modem', 'username', 'status'], 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]); if ($data['mediatypes']) { // get media types used in actions $actions = API::Action()->get(['output' => ['actionid', 'name'], 'selectOperations' => ['operationtype', 'opmessage'], 'mediatypeids' => array_keys($data['mediatypes'])]); foreach ($data['mediatypes'] as &$mediaType) { $mediaType['typeid'] = $mediaType['type']; $mediaType['type'] = media_type2str($mediaType['type']); $mediaType['listOfActions'] = []; foreach ($actions as $action) { foreach ($action['operations'] as $operation) { if ($operation['operationtype'] == OPERATION_TYPE_MESSAGE && $operation['opmessage']['mediatypeid'] == $mediaType['mediatypeid']) { $mediaType['listOfActions'][$action['actionid']] = ['actionid' => $action['actionid'], 'name' => $action['name']]; } } } order_result($mediaType['listOfActions'], 'name'); } unset($mediaType); order_result($data['mediatypes'], $sortField, $sortOrder); } $url = (new CUrl('zabbix.php'))->setArgument('action', 'mediatype.list'); $data['paging'] = getPagingLine($data['mediatypes'], $sortOrder, $url); $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of media types')); $this->setResponse($response); }
/** * Validates the input parameters for the delete() method. * * @throws APIException if the input is invalid * * @param array $scriptIds */ protected function validateDelete(array $scriptIds) { if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.')); } if (empty($scriptIds)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete scripts. Empty input parameter "scriptids".')); } $dbScripts = $this->get(array('scriptids' => $scriptIds, 'editable' => true, 'output' => array('name'), 'preservekeys' => true)); foreach ($scriptIds as $scriptId) { if (isset($dbScripts[$scriptId])) { continue; } self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Cannot delete scripts. Script with scriptid "%1$s" does not exist.', $scriptId)); } $actions = API::Action()->get(array('scriptids' => $scriptIds, 'nopermissions' => true, 'preservekeys' => true, 'output' => array('actionid', 'name'), 'selectOperations' => array('opcommand'))); foreach ($actions as $action) { foreach ($action['operations'] as $operation) { if (isset($operation['opcommand']['scriptid']) && $operation['opcommand']['scriptid'] && in_array($operation['opcommand']['scriptid'], $scriptIds)) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot delete scripts. Script "%1$s" is used in action operation "%2$s".', $dbScripts[$operation['opcommand']['scriptid']]['name'], $action['name'])); } } } }
} // render view $mediaTypeView = new CView('administration.mediatypes.edit', $data); $mediaTypeView->render(); $mediaTypeView->show(); } else { $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'description')); $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); // get media types $data['mediatypes'] = API::Mediatype()->get(array('output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'editable' => true, 'limit' => $config['search_limit'] + 1)); if ($data['mediatypes']) { // get media types used in actions $actions = API::Action()->get(array('mediatypeids' => zbx_objectValues($data['mediatypes'], 'mediatypeid'), 'output' => array('actionid', 'name'), 'selectOperations' => array('operationtype', 'opmessage'), 'preservekeys' => true)); foreach ($data['mediatypes'] as $key => $mediaType) { $data['mediatypes'][$key]['typeid'] = $data['mediatypes'][$key]['type']; $data['mediatypes'][$key]['type'] = media_type2str($data['mediatypes'][$key]['type']); $data['mediatypes'][$key]['listOfActions'] = array(); if ($actions) { foreach ($actions as $actionId => $action) { foreach ($action['operations'] as $operation) { if ($operation['operationtype'] == OPERATION_TYPE_MESSAGE && $operation['opmessage']['mediatypeid'] == $mediaType['mediatypeid']) { $data['mediatypes'][$key]['listOfActions'][$actionId] = array('actionid' => $actionId, 'name' => $action['name']); } } } order_result($data['mediatypes'][$key]['listOfActions'], 'name'); } }
$data['new_condition']['conditiontype'] = $data['allowedConditions'][0]; } // new operation if (!empty($data['new_operation'])) { if (!is_array($data['new_operation'])) { $data['new_operation'] = array('action' => 'create', 'operationtype' => 0, 'esc_period' => 0, 'esc_step_from' => 1, 'esc_step_to' => 1, 'evaltype' => 0); } } // render view $actionView = new CView('configuration.action.edit', $data); $actionView->render(); $actionView->show(); } else { $data = array('eventsource' => getRequest('eventsource', CProfile::get('web.actionconf.eventsource', EVENT_SOURCE_TRIGGERS)), 'displayNodes' => is_array(get_current_nodeid())); $sortfield = getPageSortField('name'); $data['actions'] = API::Action()->get(array('output' => API_OUTPUT_EXTEND, 'filter' => array('eventsource' => array($data['eventsource'])), 'selectConditions' => API_OUTPUT_EXTEND, 'selectOperations' => API_OUTPUT_EXTEND, 'editable' => true, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1)); // sorting && paging order_result($data['actions'], $sortfield, getPageSortOrder()); $data['paging'] = getPagingLine($data['actions'], array('actionid')); // nodes if ($data['displayNodes']) { foreach ($data['actions'] as &$action) { $action['nodename'] = get_node_name_by_elid($action['actionid'], true); } unset($action); } // render view $actionView = new CView('configuration.action.list', $data); $actionView->render(); $actionView->show(); }
/** * Delete Media types. * * @param array $mediatypeids * * @return array */ public function delete(array $mediatypeids) { if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only Super Admins can delete media types.')); } $actions = API::Action()->get(array('mediatypeids' => $mediatypeids, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true)); if (!empty($actions)) { $action = reset($actions); self::exception(ZBX_API_ERROR_PARAMETERS, _s('Media types used by action "%s".', $action['name'])); } DB::delete('media_type', array('mediatypeid' => $mediatypeids)); return array('mediatypeids' => $mediatypeids); }
$data['gsm_modem'] = get_request('gsm_modem', '/dev/ttyS0'); $data['username'] = get_request('username', $data['type'] == MEDIA_TYPE_EZ_TEXTING ? 'username' : 'user@server'); $data['password'] = get_request('password', ''); $data['status'] = get_request('status', MEDIA_TYPE_STATUS_ACTIVE); } // render view $mediaTypeView = new CView('administration.mediatypes.edit', $data); $mediaTypeView->render(); $mediaTypeView->show(); } else { // get media types $options = array('output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'editable' => true, 'limit' => $config['search_limit'] + 1); $data['mediatypes'] = API::Mediatype()->get($options); // get media types used in actions $options = array('mediatypeids' => zbx_objectValues($data['mediatypes'], 'mediatypeid'), 'output' => array('actionid', 'name'), 'preservekeys' => 1); $actions = API::Action()->get($options); foreach ($data['mediatypes'] as $number => $mediatype) { $data['mediatypes'][$number]['listOfActions'] = array(); foreach ($actions as $actionid => $action) { if (!empty($action['mediatypeids'])) { foreach ($action['mediatypeids'] as $actionMediaTypeId) { if ($mediatype['mediatypeid'] == $actionMediaTypeId) { $data['mediatypes'][$number]['listOfActions'][$actionid] = array('actionid' => $actionid, 'name' => $action['name']); } } } } $data['mediatypes'][$number]['usedInActions'] = !isset($mediatype['listOfActions']); // allow sort by mediatype name $data['mediatypes'][$number]['typeid'] = $data['mediatypes'][$number]['type']; $data['mediatypes'][$number]['type'] = media_type2str($data['mediatypes'][$number]['type']);
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $sortfield = 'clock'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Time'); switch ($this->screenitem['sort_triggers']) { case SCREEN_SORT_TRIGGERS_TIME_ASC: $sortfield = 'clock'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Time'); break; case SCREEN_SORT_TRIGGERS_TIME_DESC: $sortfield = 'clock'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Time'); break; case SCREEN_SORT_TRIGGERS_TYPE_ASC: $sortfield = 'description'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Type'); break; case SCREEN_SORT_TRIGGERS_TYPE_DESC: $sortfield = 'description'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Type'); break; case SCREEN_SORT_TRIGGERS_STATUS_ASC: $sortfield = 'status'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Status'); break; case SCREEN_SORT_TRIGGERS_STATUS_DESC: $sortfield = 'status'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Status'); break; case SCREEN_SORT_TRIGGERS_RECIPIENT_ASC: $sortfield = 'sendto'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Recipient(s)'); break; case SCREEN_SORT_TRIGGERS_RECIPIENT_DESC: $sortfield = 'sendto'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Recipient(s)'); break; } $sql = 'SELECT a.alertid,a.clock,a.sendto,a.subject,a.message,a.status,a.retries,a.error,' . 'a.userid,a.actionid,a.mediatypeid,mt.description' . ' FROM events e,alerts a' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE e.eventid=a.eventid' . ' AND alerttype=' . ALERT_TYPE_MESSAGE; if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) { $userid = CWebUser::$data['userid']; $userGroups = getUserGroupsByUserId($userid); $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ')'; } $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder; $alerts = DBfetchArray(DBselect($sql, $this->screenitem['elements'])); order_result($alerts, $sortfield, $sortorder); if ($alerts) { $dbUsers = API::User()->get(array('output' => array('userid', 'alias', 'name', 'surname'), 'userids' => zbx_objectValues($alerts, 'userid'), 'preservekeys' => true)); } // indicator of sort field $sortfieldSpan = new CSpan(array($sorttitle, SPACE)); $sortorderSpan = new CSpan(SPACE, $sortorder === ZBX_SORT_DOWN ? 'icon_sortdown default_cursor' : 'icon_sortup default_cursor'); // create alert table $actionTable = new CTableInfo(_('No action log entries found.')); $actionTable->setHeader(array($sortfield === 'clock' ? array($sortfieldSpan, $sortorderSpan) : _('Time'), _('Action'), $sortfield === 'description' ? array($sortfieldSpan, $sortorderSpan) : _('Type'), $sortfield === 'sendto' ? array($sortfieldSpan, $sortorderSpan) : _('Recipient(s)'), _('Message'), $sortfield === 'status' ? array($sortfieldSpan, $sortorderSpan) : _('Status'), _('Info'))); $actions = API::Action()->get(array('output' => array('actionid', 'name'), 'actionids' => array_unique(zbx_objectValues($alerts, 'actionid')), 'preservekeys' => true)); foreach ($alerts as $alert) { if ($alert['status'] == ALERT_STATUS_SENT) { $status = new CSpan(_('Sent'), 'green'); } elseif ($alert['status'] == ALERT_STATUS_NOT_SENT) { $status = new CSpan(array(_('In progress') . ':', BR(), _n('%1$s retry left', '%1$s retries left', ALERT_MAX_RETRIES - $alert['retries'])), 'orange'); } else { $status = new CSpan(_('Not sent'), 'red'); } $recipient = $alert['userid'] ? array(bold(getUserFullname($dbUsers[$alert['userid']])), BR(), $alert['sendto']) : $alert['sendto']; $message = array(bold(_('Subject') . ':'), br(), $alert['subject'], br(), br(), bold(_('Message') . ':'), br(), $alert['message']); if (zbx_empty($alert['error'])) { $info = ''; } else { $info = new CDiv(SPACE, 'status_icon iconerror'); $info->setHint($alert['error'], 'on'); } $actionTable->addRow(array(new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $alert['clock']), 'top'), new CCol($actions[$alert['actionid']]['name'], 'top'), new CCol($alert['mediatypeid'] == 0 ? '-' : $alert['description'], 'top'), new CCol($recipient, 'top'), new CCol($message, 'top pre'), new CCol($status, 'top'), new CCol($info, 'wraptext top'))); } return $this->getOutput($actionTable); }
foreach (eventSourceObjects() as $eventSource) { $data['alerts'] = array_merge($data['alerts'], API::Alert()->get(array('output' => API_OUTPUT_EXTEND, 'selectMediatypes' => API_OUTPUT_EXTEND, 'userids' => $userId, 'time_from' => $from, 'time_till' => $till, 'eventsource' => $eventSource['source'], 'eventobject' => $eventSource['object'], 'limit' => $config['search_limit'] + 1))); } CArrayHelper::sort($data['alerts'], array(array('field' => 'alertid', 'order' => ZBX_SORT_DOWN))); $data['alerts'] = array_slice($data['alerts'], 0, $config['search_limit'] + 1); // paging $data['paging'] = getPagingLine($data['alerts']); // get users if (!$data['alias']) { $data['users'] = API::User()->get(array('output' => array('userid', 'alias', 'name', 'surname'), 'userids' => zbx_objectValues($data['alerts'], 'userid'), 'preservekeys' => true)); } } // get first alert clock $firstAlert = null; if ($userId) { $firstAlert = DBfetch(DBselect('SELECT MIN(a.clock) AS clock' . ' FROM alerts a' . ' WHERE a.userid=' . zbx_dbstr($userId))); } elseif ($data['alias'] === '') { $firstAlert = DBfetch(DBselect('SELECT MIN(a.clock) AS clock FROM alerts a')); } $minStartTime = $firstAlert ? $firstAlert['clock'] : null; // get actions names if ($data['alerts']) { $data['actions'] = API::Action()->get(array('output' => array('actionid', 'name'), 'actionids' => array_unique(zbx_objectValues($data['alerts'], 'actionid')), 'preservekeys' => true)); } // timeline $data['timeline'] = array('period' => $effectivePeriod, 'starttime' => date(TIMESTAMP_FORMAT, $minStartTime), 'usertime' => $data['stime'] ? date(TIMESTAMP_FORMAT, zbxDateToTime($data['stime']) + $effectivePeriod) : null); // render view $auditView = new CView('administration.auditacts.list', $data); $auditView->render(); $auditView->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
$data['new_operation']['opinventory'] = ['inventory_mode' => HOST_INVENTORY_MANUAL]; } break; } } // render view $actionView = new CView('configuration.action.edit', $data); $actionView->render(); $actionView->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 = ['eventsource' => getRequest('eventsource', CProfile::get('web.actionconf.eventsource', EVENT_SOURCE_TRIGGERS)), 'sort' => $sortField, 'sortorder' => $sortOrder, 'config' => $config]; $data['actions'] = API::Action()->get(['output' => API_OUTPUT_EXTEND, 'filter' => ['eventsource' => [$data['eventsource']]], 'selectFilter' => ['formula', 'conditions', 'evaltype'], 'selectOperations' => API_OUTPUT_EXTEND, 'editable' => true, 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1]); foreach ($data['actions'] as &$action) { foreach ($action['operations'] as &$operation) { switch ($operation['operationtype']) { case OPERATION_TYPE_GROUP_ADD: case OPERATION_TYPE_GROUP_REMOVE: $operation = ['operationtype' => $operation['operationtype'], 'groupids' => zbx_objectValues($operation['opgroup'], 'groupid')]; break; case OPERATION_TYPE_TEMPLATE_ADD: case OPERATION_TYPE_TEMPLATE_REMOVE: $operation = ['operationtype' => $operation['operationtype'], 'templateids' => zbx_objectValues($operation['optemplate'], 'templateid')]; break; } } unset($operation); }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $sortfield = 'clock'; $sortorder = ZBX_SORT_DOWN; switch ($this->screenitem['sort_triggers']) { case SCREEN_SORT_TRIGGERS_TIME_ASC: $sortfield = 'clock'; $sortorder = ZBX_SORT_UP; break; case SCREEN_SORT_TRIGGERS_TIME_DESC: $sortfield = 'clock'; $sortorder = ZBX_SORT_DOWN; break; case SCREEN_SORT_TRIGGERS_TYPE_ASC: $sortfield = 'description'; $sortorder = ZBX_SORT_UP; break; case SCREEN_SORT_TRIGGERS_TYPE_DESC: $sortfield = 'description'; $sortorder = ZBX_SORT_DOWN; break; case SCREEN_SORT_TRIGGERS_STATUS_ASC: $sortfield = 'status'; $sortorder = ZBX_SORT_UP; break; case SCREEN_SORT_TRIGGERS_STATUS_DESC: $sortfield = 'status'; $sortorder = ZBX_SORT_DOWN; break; case SCREEN_SORT_TRIGGERS_RECIPIENT_ASC: $sortfield = 'sendto'; $sortorder = ZBX_SORT_UP; break; case SCREEN_SORT_TRIGGERS_RECIPIENT_DESC: $sortfield = 'sendto'; $sortorder = ZBX_SORT_DOWN; break; } $sql = 'SELECT a.alertid,a.clock,a.sendto,a.subject,a.message,a.status,a.retries,a.error,' . 'a.userid,a.actionid,a.mediatypeid,mt.description' . ' FROM events e,alerts a' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE e.eventid=a.eventid' . ' AND alerttype=' . ALERT_TYPE_MESSAGE; if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) { $userid = CWebUser::$data['userid']; $userGroups = getUserGroupsByUserId($userid); $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ')'; } $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder; $alerts = DBfetchArray(DBselect($sql, $this->screenitem['elements'])); order_result($alerts, $sortfield, $sortorder); $userids = []; foreach ($alerts as $alert) { if ($alert['userid'] != 0) { $userids[$alert['userid']] = true; } } if ($userids) { $dbUsers = API::User()->get(['output' => ['userid', 'alias', 'name', 'surname'], 'userids' => array_keys($userids), 'preservekeys' => true]); } // indicator of sort field $sort_div = (new CSpan())->addClass($sortorder === ZBX_SORT_DOWN ? ZBX_STYLE_ARROW_DOWN : ZBX_STYLE_ARROW_UP); // create alert table $table = (new CTableInfo())->setHeader([$sortfield === 'clock' ? ['Time', $sort_div] : _('Time'), _('Action'), $sortfield === 'description' ? [_('Type'), $sort_div] : _('Type'), $sortfield === 'sendto' ? [_('Recipient(s)'), $sort_div] : _('Recipient(s)'), _('Message'), $sortfield === 'status' ? [_('Status'), $sort_div] : _('Status'), _('Info')]); $actions = API::Action()->get(['output' => ['actionid', 'name'], 'actionids' => array_unique(zbx_objectValues($alerts, 'actionid')), 'preservekeys' => true]); foreach ($alerts as $alert) { if ($alert['status'] == ALERT_STATUS_SENT) { $status = (new CSpan(_('Sent')))->addClass(ZBX_STYLE_GREEN); } elseif ($alert['status'] == ALERT_STATUS_NOT_SENT) { $status = (new CSpan([_('In progress') . ':', BR(), _n('%1$s retry left', '%1$s retries left', ALERT_MAX_RETRIES - $alert['retries'])]))->addClass(ZBX_STYLE_YELLOW); } else { $status = (new CSpan(_('Not sent')))->addClass(ZBX_STYLE_RED); } $recipient = $alert['userid'] != 0 ? [bold(getUserFullname($dbUsers[$alert['userid']])), BR(), $alert['sendto']] : $alert['sendto']; $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $alert['clock']), $actions[$alert['actionid']]['name'], $alert['mediatypeid'] == 0 ? '' : $alert['description'], $recipient, [bold($alert['subject']), BR(), BR(), zbx_nl2br($alert['message'])], $status, $alert['error'] === '' ? '' : makeErrorIcon($alert['error'])]); } $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT); return $this->getOutput((new CUiWidget(uniqid(), [$table, $footer]))->setHeader(_('Action log'))); }
/** * Delete Scripts * * @param _array $scriptids * @param array $scriptids * @return boolean */ public function delete($scriptids) { $scriptids = zbx_toArray($scriptids); if (USER_TYPE_SUPER_ADMIN != self::$userData['type']) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.')); } if (empty($scriptids)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete scripts. Empty input parameter "scriptids".')); } $dbScripts = $this->get(array('scriptids' => $scriptids, 'editable' => true, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true)); foreach ($scriptids as $scriptid) { if (isset($dbScripts[$scriptid])) { continue; } self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Cannot delete scripts. Script with scriptid "%s" does not exist.', $scriptid)); } $scriptActions = API::Action()->get(array('scriptids' => $scriptids, 'nopermissions' => true, 'preservekeys' => true, 'output' => array('actionid', 'name'))); foreach ($scriptActions as $action) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot delete scripts. Script "%1$s" is used in action operation "%2$s".', $dbScripts[$action['scriptid']]['name'], $action['name'])); } DB::delete('scripts', array('scriptid' => $scriptids)); return array('scriptids' => $scriptids); }