| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php declare(strict_types = 0);
- /*
- ** L2 Topology - GET controller.
- ** Renders either the live snapshot or any stored snapshot chosen by ?ts=<epoch>.
- */
- namespace Modules\WecomCenter\Actions;
- use CController;
- use CControllerResponseData;
- use CWebUser;
- use Modules\WecomCenter\Lib\L2Store;
- class L2TopologyView extends CController {
- protected function init() {
- $this->disableCsrfValidation();
- }
- protected function checkInput() {
- return true;
- }
- protected function checkPermissions() {
- return CWebUser::getType() >= USER_TYPE_ZABBIX_USER;
- }
- protected function doAction() {
- L2Store::ensureSchema();
- $cfg = L2Store::getConfig();
- $ts_raw = $_REQUEST['ts'] ?? '';
- $ts = ($ts_raw === '' || $ts_raw === null) ? null : (int) $ts_raw;
- $snap = L2Store::snapshotAt($ts);
- $json = $snap['json'] ?? null;
- $used_ts = $snap['ts'];
- // The selector must cover the full retention window, not only the
- // latest 500 rows. At 5 minutes / 7 days this is ~2,016 points.
- $history_days = max(1, min(30, (int) ($cfg['history_days'] ?? 7)));
- $history_interval = max(5, (int) ($cfg['history_interval_min'] ?? 5));
- $history_limit = (int) ceil($history_days * 1440 / $history_interval) + 30;
- $history_limit = max(500, min(10000, $history_limit));
- $this->setResponse(new CControllerResponseData([
- 'title' => _('L2 Topology'),
- 'snap_json' => ($json !== null && $json !== '') ? $json : 'null',
- 'cfg_json' => json_encode($cfg, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
- 'history' => L2Store::listHistory($history_limit),
- 'used_ts' => $used_ts,
- 'requested_ts' => $ts,
- 'is_live' => ($ts === null),
- 'cfg_refresh'=> (int) $cfg['refresh_seconds']
- ]));
- }
- }
|