disableCsrfValidation(); } protected function checkInput() { return true; } protected function checkPermissions() { return CWebUser::getType() == USER_TYPE_SUPER_ADMIN; } protected function doAction() { $module_dir = dirname(__DIR__); $mediatypes = Helper::webhookMediatypes(); $mediatypeid = (string) ($_REQUEST['mediatypeid'] ?? ''); if ($mediatypeid === '' && $mediatypes) { foreach ($mediatypes as $mt) { if (stripos($mt['name'], 'wecom') !== false) { $mediatypeid = (string) $mt['mediatypeid']; break; } } if ($mediatypeid === '') { $mediatypeid = (string) $mediatypes[0]['mediatypeid']; } } $mediatype = null; $webhook_url = ''; $media = null; if ($mediatypeid !== '') { $mediatype = Helper::getMediatype($mediatypeid); if ($mediatype) { $webhook_url = Helper::webhookKey($mediatype); } $robot = Helper::robotUser('wecomrobot'); $media = Helper::currentMedia($robot, $mediatypeid); } // ---- alert strategy ---- $template_hostid = Helper::templateHostid(); $current_strategy = Helper::currentStrategy(); $preview = null; $preview_key = (string) ($_REQUEST['preview_preset'] ?? ''); if ($preview_key !== '' && isset(Helper::STRATEGY_PRESETS[$preview_key]) && $template_hostid !== null) { $preview = Helper::previewStrategy($template_hostid, Helper::STRATEGY_PRESETS[$preview_key]['targets']); } // ---- server tuning generator ---- $tuning_profile = (string) ($_REQUEST['tuning_profile'] ?? 'medium'); if (!isset(Helper::TUNING_PROFILES[$tuning_profile])) { $tuning_profile = 'medium'; } $tuning = Helper::tuningSnippet($tuning_profile); // ---- map: single marker = Zabbix server host ---- $server_host = null; $server_loc = ['location_lat' => '', 'location_lon' => '']; try { $sh = \API::Host()->get([ 'output' => ['hostid', 'name'], 'filter' => ['host' => 'Zabbix server'], 'selectInventory' => ['location_lat', 'location_lon'], 'limit' => 1 ]); if ($sh) { $server_host = $sh[0]; $server_loc = [ 'location_lat' => $sh[0]['inventory']['location_lat'] ?? '', 'location_lon' => $sh[0]['inventory']['location_lon'] ?? '' ]; } } catch (\Throwable $e) { /* ignore */ } // ---- maintenance: per-trigger alerting switch ---- $trig_search = trim((string) ($_REQUEST['trig_search'] ?? '')); $triggers = Helper::triggers($trig_search); $trigger_count = Helper::triggerCount(); // ---- template switch / migration ---- $huawei_tpls = Helper::huaweiTemplates(); $switch_src = (string) ($_REQUEST['switch_src'] ?? ''); $switch_dst = (string) ($_REQUEST['switch_dst'] ?? ''); $switch_preview = null; if ($switch_src !== '' && $switch_dst !== '' && $switch_src !== $switch_dst) { $switch_preview = Helper::switchPreview($switch_src, $switch_dst); } // ---- L2 topology configuration ---- L2Store::ensureSchema(); $l2 = L2Store::getConfig(); $l2_templates = []; try { $tpls = \API::Template()->get(['output' => ['templateid', 'name'], 'sortfield' => 'name']); foreach ($tpls as $tp) { $l2_templates[] = $tp['name']; } } catch (\Throwable $e) { /* ignore */ } $data = [ 'title' => I18n::t('page.title'), 'l2' => $l2, 'l2_templates' => $l2_templates, 'mediatypes' => $mediatypes, 'mediatypeid' => $mediatypeid, 'mediatype' => $mediatype, 'webhook_url' => $webhook_url, 'media' => $media, 'severity' => $media['severity'] ?? 48, 'active' => $media['active'] ?? 0, 'presets' => Helper::STRATEGY_PRESETS, 'classes' => Helper::CLASSES, 'current_strategy'=> $current_strategy, 'template_hostid' => $template_hostid, 'preview_key' => $preview_key, 'preview' => $preview, 'tuning_profile' => $tuning_profile, 'tuning' => $tuning, 'tuning_profiles' => Helper::TUNING_PROFILES, 'templates' => Helper::bundledTemplates($module_dir), 'server_host' => $server_host, 'server_loc' => $server_loc, 'trig_search' => $trig_search, 'triggers' => $triggers, 'trigger_count' => $trigger_count, 'huawei_tpls' => $huawei_tpls, 'switch_src' => $switch_src, 'switch_dst' => $switch_dst, 'switch_preview' => $switch_preview, 'lang' => I18n::lang() ]; $response = new CControllerResponseData($data); $response->setTitle(I18n::t('page.title')); $this->setResponse($response); } }