From 98a0a9d94c1219c4eda4f3f27c2b2364fcf83da9 Mon Sep 17 00:00:00 2001 From: yuweizzz Date: Wed, 5 Jun 2024 17:28:56 +0800 Subject: [PATCH] feat: support sqlite (#1978) * demo sqlite --- docker/initsql/sqlite.sql | 1777 ++++++++++++++++++++++++++++++ etc/config.toml | 5 +- go.mod | 4 +- go.sum | 8 +- models/builtin_metrics.go | 2 +- models/builtin_metrics_filter.go | 2 +- models/builtin_payload.go | 2 +- pkg/ormx/ormx.go | 13 +- 8 files changed, 1802 insertions(+), 11 deletions(-) create mode 100644 docker/initsql/sqlite.sql diff --git a/docker/initsql/sqlite.sql b/docker/initsql/sqlite.sql new file mode 100644 index 000000000..e8f2d492e --- /dev/null +++ b/docker/initsql/sqlite.sql @@ -0,0 +1,1777 @@ +CREATE TABLE `users` ( + `id` integer primary key autoincrement, + `username` varchar(64) not null unique, + `nickname` varchar(64) not null, + `password` varchar(128) not null default '', + `phone` varchar(16) not null default '', + `email` varchar(64) not null default '', + `portrait` varchar(255) not null default '', + `roles` varchar(255) not null, + `contacts` varchar(1024), + `maintainer` tinyint(1) not null default 0, + `belong` varchar(16) not null default '', + `last_active_time` bigint not null default 0, + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); + +insert into `users`(id, username, nickname, password, roles, create_at, create_by, update_at, update_by) values(1, 'root', '超管', 'root.2020', 'Admin', strftime('%s', 'now'), 'system', strftime('%s', 'now'), 'system'); + +CREATE TABLE `user_group` ( + `id` integer primary key autoincrement, + `name` varchar(128) not null default '', + `note` varchar(255) not null default '', + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); +CREATE INDEX `idx_user_group_create_by` ON `user_group` (`create_by` asc); +CREATE INDEX `idx_user_group_update_at` ON `user_group` (`update_at` asc); + +insert into user_group(id, name, create_at, create_by, update_at, update_by) values(1, 'demo-root-group', strftime('%s', 'now'), 'root', strftime('%s', 'now'), 'root'); + +CREATE TABLE `user_group_member` ( + `id` integer primary key autoincrement, + `group_id` bigint unsigned not null, + `user_id` bigint unsigned not null +); +CREATE INDEX `idx_user_group_member_group_id` ON `user_group_member` (`group_id` asc); +CREATE INDEX `idx_user_group_member_user_id` ON `user_group_member` (`user_id` asc); + +insert into user_group_member(group_id, user_id) values(1, 1); + +CREATE TABLE `configs` ( + `id` integer primary key autoincrement, + `ckey` varchar(191) not null, + `cval` text not null, + `note` varchar(1024) not null default '', + `external` tinyint(1) not null default 0, + `encrypted` tinyint(1) not null default 0, + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); + +CREATE TABLE `role` ( + `id` integer primary key autoincrement, + `name` varchar(191) not null unique default '', + `note` varchar(255) not null default '' +); + +insert into `role`(name, note) values('Admin', 'Administrator role'); +insert into `role`(name, note) values('Standard', 'Ordinary user role'); +insert into `role`(name, note) values('Guest', 'Readonly user role'); + + +CREATE TABLE `role_operation`( + `id` integer primary key autoincrement, + `role_name` varchar(128) not null, + `operation` varchar(191) not null +); +CREATE INDEX `idx_role_operation_role_name` ON `role_operation` (`role_name` asc); +CREATE INDEX `idx_role_operation_operation` ON `role_operation` (`operation` asc); + +-- Admin is special, who has no concrete operation but can do anything. +insert into `role_operation`(role_name, operation) values('Guest', '/metric/explorer'); +insert into `role_operation`(role_name, operation) values('Guest', '/object/explorer'); +insert into `role_operation`(role_name, operation) values('Guest', '/log/explorer'); +insert into `role_operation`(role_name, operation) values('Guest', '/trace/explorer'); +insert into `role_operation`(role_name, operation) values('Guest', '/help/version'); +insert into `role_operation`(role_name, operation) values('Guest', '/help/contact'); + +insert into `role_operation`(role_name, operation) values('Standard', '/metric/explorer'); +insert into `role_operation`(role_name, operation) values('Standard', '/object/explorer'); +insert into `role_operation`(role_name, operation) values('Standard', '/log/explorer'); +insert into `role_operation`(role_name, operation) values('Standard', '/trace/explorer'); +insert into `role_operation`(role_name, operation) values('Standard', '/help/version'); +insert into `role_operation`(role_name, operation) values('Standard', '/help/contact'); +insert into `role_operation`(role_name, operation) values('Standard', '/help/servers'); +insert into `role_operation`(role_name, operation) values('Standard', '/help/migrate'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules-built-in'); +insert into `role_operation`(role_name, operation) values('Standard', '/dashboards-built-in'); +insert into `role_operation`(role_name, operation) values('Standard', '/trace/dependencies'); + +insert into `role_operation`(role_name, operation) values('Admin', '/help/source'); +insert into `role_operation`(role_name, operation) values('Admin', '/help/sso'); +insert into `role_operation`(role_name, operation) values('Admin', '/help/notification-tpls'); +insert into `role_operation`(role_name, operation) values('Admin', '/help/notification-settings'); + +insert into `role_operation`(role_name, operation) values('Standard', '/users'); +insert into `role_operation`(role_name, operation) values('Standard', '/user-groups'); +insert into `role_operation`(role_name, operation) values('Standard', '/user-groups/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/user-groups/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/user-groups/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups'); +insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/busi-groups/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/targets'); +insert into `role_operation`(role_name, operation) values('Standard', '/targets/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/targets/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/targets/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/dashboards'); +insert into `role_operation`(role_name, operation) values('Standard', '/dashboards/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/dashboards/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/dashboards/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-rules/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-mutes'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-mutes/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-mutes/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-subscribes/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-cur-events'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-cur-events/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/alert-his-events'); +insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls'); +insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/job-tpls/del'); +insert into `role_operation`(role_name, operation) values('Standard', '/job-tasks'); +insert into `role_operation`(role_name, operation) values('Standard', '/job-tasks/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/job-tasks/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules'); +insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules/add'); +insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules/put'); +insert into `role_operation`(role_name, operation) values('Standard', '/recording-rules/del'); + +-- for alert_rule | collect_rule | mute | dashboard grouping +CREATE TABLE `busi_group` ( + `id` integer primary key autoincrement, + `name` varchar(191) not null unique, + `label_enable` tinyint(1) not null default 0, + `label_value` varchar(191) not null default '', + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); + +insert into busi_group(id, name, create_at, create_by, update_at, update_by) values(1, 'Default Busi Group', strftime('%s', 'now'), 'root', strftime('%s', 'now'), 'root'); + +CREATE TABLE `busi_group_member` ( + `id` integer primary key autoincrement, + `busi_group_id` bigint not null, + `user_group_id` bigint not null, + `perm_flag` char(2) not null +); +CREATE INDEX `idx_busi_group_member_busi_group_id` ON `busi_group_member` (`busi_group_id` asc); +CREATE INDEX `idx_busi_group_member_user_group_id` ON `busi_group_member` (`user_group_id` asc); + +insert into busi_group_member(busi_group_id, user_group_id, perm_flag) values(1, 1, 'rw'); + +-- for dashboard new version +CREATE TABLE `board` ( + `id` integer primary key autoincrement, + `group_id` bigint not null default 0, + `name` varchar(191) not null, + `ident` varchar(200) not null default '', + `tags` varchar(255) not null, + `public` tinyint(1) not null default 0, + `built_in` tinyint(1) not null default 0, + `hide` tinyint(1) not null default 0, + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '', + unique (`group_id`, `name`) +); +CREATE INDEX `idx_board_ident` ON `board` (`ident` asc); + +-- for dashboard new version +CREATE TABLE `board_payload` ( + `id` bigint unsigned not null unique, + `payload` mediumtext not null +); + +CREATE TABLE `chart_share` ( + `id` integer primary key autoincrement, + `cluster` varchar(128) not null, + `datasource_id` bigint unsigned not null default 0, + `configs` text, + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '' +); +CREATE INDEX `idx_chart_share_create_at` ON `chart_share` (`create_at` asc); + +CREATE TABLE `alert_rule` ( + `id` integer primary key autoincrement, + `group_id` bigint not null default 0, + `cate` varchar(128) not null, + `datasource_ids` varchar(255) not null default '', + `cluster` varchar(128) not null, + `name` varchar(255) not null, + `note` varchar(1024) not null default '', + `prod` varchar(255) not null default '', + `algorithm` varchar(255) not null default '', + `algo_params` varchar(255), + `delay` int not null default 0, + `severity` tinyint(1) not null, + `disabled` tinyint(1) not null, + `prom_for_duration` int not null, + `rule_config` text not null, + `prom_ql` text not null, + `prom_eval_interval` int not null, + `enable_stime` varchar(255) not null default '00:00', + `enable_etime` varchar(255) not null default '23:59', + `enable_days_of_week` varchar(255) not null default '', + `enable_in_bg` tinyint(1) not null default 0, + `notify_recovered` tinyint(1) not null, + `notify_channels` varchar(255) not null default '', + `notify_groups` varchar(255) not null default '', + `notify_repeat_step` int not null default 0, + `notify_max_number` int not null default 0, + `recover_duration` int not null default 0 , + `callbacks` varchar(4096) not null default '', + `runbook_url` varchar(4096), + `append_tags` varchar(255) not null default '', + `annotations` text not null, + `extra_config` text not null, + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); +CREATE INDEX `idx_alert_rule_group_id` ON `alert_rule` (`group_id` asc); +CREATE INDEX `idx_alert_rule_update_at` ON `alert_rule` (`update_at` asc); + +CREATE TABLE `alert_mute` ( + `id` integer primary key autoincrement, + `group_id` bigint not null default 0, + `prod` varchar(255) not null default '', + `note` varchar(1024) not null default '', + `cate` varchar(128) not null, + `cluster` varchar(128) not null, + `datasource_ids` varchar(255) not null default '', + `tags` varchar(4096) default '[]', + `cause` varchar(255) not null default '', + `btime` bigint not null default 0, + `etime` bigint not null default 0, + `disabled` tinyint(1) not null default 0, + `mute_time_type` tinyint(1) not null default 0, + `periodic_mutes` varchar(4096) not null default '', + `severities` varchar(32) not null default '', + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); +CREATE INDEX `idx_alert_mute_create_at` ON `alert_mute` (`create_at` asc); +CREATE INDEX `idx_alert_mute_group_id` ON `alert_mute` (`group_id` asc); + +CREATE TABLE `alert_subscribe` ( + `id` integer primary key autoincrement, + `name` varchar(255) not null default '', + `disabled` tinyint(1) not null default 0, + `group_id` bigint not null default 0, + `prod` varchar(255) not null default '', + `cate` varchar(128) not null, + `datasource_ids` varchar(255) not null default '', + `cluster` varchar(128) not null, + `rule_id` bigint not null default 0, + `severities` varchar(32) not null default '', + `tags` varchar(4096) not null default '', + `redefine_severity` tinyint(1) default 0, + `new_severity` tinyint(1) not null, + `redefine_channels` tinyint(1) default 0, + `new_channels` varchar(255) not null default '', + `user_group_ids` varchar(250) not null, + `busi_groups` VARCHAR(4096) NOT NULL DEFAULT '[]', + `note` VARCHAR(1024) DEFAULT '', + `rule_ids` VARCHAR(1024) DEFAULT '', + `webhooks` text not null, + `extra_config` text not null, + `redefine_webhooks` tinyint(1) default 0, + `for_duration` bigint not null default 0, + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); +CREATE INDEX `idx_alert_subscribe_update_at` ON `alert_subscribe` (`update_at` asc); +CREATE INDEX `idx_alert_subscribe_group_id` ON `alert_subscribe` (`group_id` asc); + + +CREATE TABLE `target` ( + `id` integer primary key autoincrement, + `group_id` bigint not null default 0, + `ident` varchar(191) not null unique, + `note` varchar(255) not null default '', + `tags` varchar(512) not null default '', + `host_ip` varchar(15) default '', + `agent_version` varchar(255) default '', + `engine_name` varchar(255) default '', + `update_at` bigint not null default 0 +); +CREATE INDEX `idx_target_group_id` ON `target` (`group_id` asc); + + +CREATE TABLE `metric_view` ( + `id` integer primary key autoincrement, + `name` varchar(191) not null default '', + `cate` tinyint(1) not null, + `configs` varchar(8192) not null default '', + `create_at` bigint not null default 0, + `create_by` bigint not null default 0, + `update_at` bigint not null default 0 +); +CREATE INDEX `idx_metric_view_create_by` ON `metric_view` (`create_by` asc); + +insert into metric_view(name, cate, configs) values('Host View', 0, '{"filters":[{"oper":"=","label":"__name__","value":"cpu_usage_idle"}],"dynamicLabels":[],"dimensionLabels":[{"label":"ident","value":""}]}'); + +CREATE TABLE `recording_rule` ( + `id` integer primary key autoincrement, + `group_id` bigint not null default '0', + `datasource_ids` varchar(255) not null default '', + `cluster` varchar(128) not null, + `name` varchar(255) not null, + `note` varchar(255) not null, + `disabled` tinyint(1) not null default 0, + `prom_ql` varchar(8192) not null, + `prom_eval_interval` int not null, + `append_tags` varchar(255) default '', + `query_configs` text not null, + `create_at` bigint default '0', + `create_by` varchar(64) default '', + `update_at` bigint default '0', + `update_by` varchar(64) default '' +); +CREATE INDEX `idx_recording_rule_group_id` ON `recording_rule` (`group_id` asc); +CREATE INDEX `idx_recording_rule_update_at` ON `recording_rule` (`update_at` asc); + +CREATE TABLE `alert_aggr_view` ( + `id` integer primary key autoincrement, + `name` varchar(191) not null default '', + `rule` varchar(2048) not null default '', + `cate` tinyint(1) not null, + `create_at` bigint not null default 0, + `create_by` bigint not null default 0, + `update_at` bigint not null default 0 +); +CREATE INDEX `idx_alert_aggr_view_create_by` ON `alert_aggr_view` (`create_by` asc); + +insert into alert_aggr_view(name, rule, cate) values('By BusiGroup, Severity', 'field:group_name::field:severity', 0); +insert into alert_aggr_view(name, rule, cate) values('By RuleName', 'field:rule_name', 0); + +CREATE TABLE `alert_cur_event` ( + `id` integer primary key autoincrement, + `cate` varchar(128) not null, + `datasource_id` bigint not null default 0, + `cluster` varchar(128) not null, + `group_id` bigint unsigned not null, + `group_name` varchar(255) not null default '', + `hash` varchar(64) not null, + `rule_id` bigint unsigned not null, + `rule_name` varchar(255) not null, + `rule_note` varchar(2048) not null default 'alert rule note', + `rule_prod` varchar(255) not null default '', + `rule_algo` varchar(255) not null default '', + `severity` tinyint(1) not null, + `prom_for_duration` int not null, + `prom_ql` varchar(8192) not null, + `prom_eval_interval` int not null, + `callbacks` varchar(255) not null default '', + `runbook_url` varchar(255), + `notify_recovered` tinyint(1) not null, + `notify_channels` varchar(255) not null default '', + `notify_groups` varchar(255) not null default '', + `notify_repeat_next` bigint not null default 0, + `notify_cur_number` int not null default 0, + `target_ident` varchar(191) not null default '', + `target_note` varchar(191) not null default '', + `first_trigger_time` bigint, + `trigger_time` bigint not null, + `trigger_value` varchar(255) not null, + `annotations` text not null, + `rule_config` text not null, + `tags` varchar(1024) not null default '' +); +CREATE INDEX `idx_alert_cur_event_hash` ON `alert_cur_event` (`hash` asc); +CREATE INDEX `idx_alert_cur_event_rule_id` ON `alert_cur_event` (`rule_id` asc); +CREATE INDEX `idx_alert_cur_event_trigger_time_group_id` ON `alert_cur_event` (`trigger_time`, `group_id` asc); +CREATE INDEX `idx_alert_cur_event_notify_repeat_next` ON `alert_cur_event` (`notify_repeat_next` asc); + +CREATE TABLE `alert_his_event` ( + `id` integer primary key autoincrement, + `is_recovered` tinyint(1) not null, + `cate` varchar(128) not null, + `datasource_id` bigint not null default 0, + `cluster` varchar(128) not null, + `group_id` bigint unsigned not null, + `group_name` varchar(255) not null default '', + `hash` varchar(64) not null, + `rule_id` bigint unsigned not null, + `rule_name` varchar(255) not null, + `rule_note` varchar(2048) not null default 'alert rule note', + `rule_prod` varchar(255) not null default '', + `rule_algo` varchar(255) not null default '', + `severity` tinyint(1) not null, + `prom_for_duration` int not null, + `prom_ql` varchar(8192) not null, + `prom_eval_interval` int not null, + `callbacks` varchar(255) not null default '', + `runbook_url` varchar(255), + `notify_recovered` tinyint(1) not null, + `notify_channels` varchar(255) not null default '', + `notify_groups` varchar(255) not null default '', + `notify_cur_number` int not null default 0, + `target_ident` varchar(191) not null default '', + `target_note` varchar(191) not null default '', + `first_trigger_time` bigint, + `trigger_time` bigint not null, + `trigger_value` varchar(255) not null, + `recover_time` bigint not null default 0, + `last_eval_time` bigint not null default 0, + `tags` varchar(1024) not null default '', + `annotations` text not null, + `rule_config` text not null +); +CREATE INDEX `idx_alert_his_event_last_eval_time` ON `alert_his_event` (`last_eval_time` asc); +CREATE INDEX `idx_alert_his_event_hash` ON `alert_his_event` (`hash` asc); +CREATE INDEX `idx_alert_his_event_rule_id` ON `alert_his_event` (`rule_id` asc); +CREATE INDEX `idx_alert_his_event_trigger_time_group_id` ON `alert_his_event` (`trigger_time`, `group_id` asc); + +CREATE TABLE `board_busigroup` ( + `busi_group_id` bigint(20) NOT NULL DEFAULT '0', + `board_id` bigint(20) NOT NULL DEFAULT '0', + primary key (`busi_group_id`, `board_id`) +); + +CREATE TABLE `builtin_components` ( + `id` integer primary key autoincrement, + `ident` varchar(191) not null, + `logo` varchar(191) not null, + `readme` text not null, + `created_at` bigint(20) not null default 0, + `created_by` varchar(191) not null default '', + `updated_at` bigint(20) not null default 0, + `updated_by` varchar(191) not null default '' +); +CREATE INDEX `idx_builtin_components_ident` ON `builtin_components` (`ident` asc); + +CREATE TABLE `builtin_payloads` ( + `id` integer primary key autoincrement, + `type` varchar(191) not null, + `component` varchar(191) not null, + `cate` varchar(191) not null, + `name` varchar(191) not null, + `tags` varchar(191) not null default '', + `content` longtext not null, + `created_at` bigint(20) not null default 0, + `created_by` varchar(191) not null default '', + `updated_at` bigint(20) not null default 0, + `updated_by` varchar(191) not null default '' +); +CREATE INDEX `idx_builtin_payloads_component` ON `builtin_payloads` (`component` asc); +CREATE INDEX `idx_builtin_payloads_name` ON `builtin_payloads` (`name` asc); +CREATE INDEX `idx_builtin_payloads_cate` ON `builtin_payloads` (`cate` asc); +CREATE INDEX `idx_builtin_payloads_type` ON `builtin_payloads` (`type` asc); + +CREATE TABLE `task_tpl` ( + `id` integer primary key autoincrement, + `group_id` int unsigned not null, + `title` varchar(255) not null default '', + `account` varchar(64) not null, + `batch` int unsigned not null default 0, + `tolerance` int unsigned not null default 0, + `timeout` int unsigned not null default 0, + `pause` varchar(255) not null default '', + `script` text not null, + `args` varchar(512) not null default '', + `tags` varchar(255) not null default '', + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); +CREATE INDEX `idx_task_tpl_group_id` ON `task_tpl` (`group_id` asc); + +CREATE TABLE `task_tpl_host` ( + `ii` integer primary key autoincrement, + `id` int unsigned not null, + `host` varchar(128) not null +); +CREATE INDEX `idx_task_tpl_host_id_host` ON `task_tpl_host` (`id`, `host` asc); + +CREATE TABLE `task_record` ( + `id` integer primary key autoincrement, + `event_id` bigint not null default 0, + `group_id` bigint not null, + `ibex_address` varchar(128) not null, + `ibex_auth_user` varchar(128) not null default '', + `ibex_auth_pass` varchar(128) not null default '', + `title` varchar(255) not null default '', + `account` varchar(64) not null, + `batch` int unsigned not null default 0, + `tolerance` int unsigned not null default 0, + `timeout` int unsigned not null default 0, + `pause` varchar(255) not null default '', + `script` text not null, + `args` varchar(512) not null default '', + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '' +); +CREATE INDEX `idx_task_record_create_at_group_id` ON `task_record` (`create_at`, `group_id` asc); +CREATE INDEX `idx_task_record_create_by` ON `task_record` (`create_by` asc); +CREATE INDEX `idx_task_record_event_id` ON `task_record` (`event_id` asc); + + +CREATE TABLE `alerting_engines` ( + `id` integer primary key autoincrement, + `instance` varchar(128) not null default '', + `datasource_id` bigint not null default 0, + `engine_cluster` varchar(128) not null default '', + `clock` bigint not null +); + +CREATE TABLE `datasource` +( + `id` integer primary key autoincrement, + `name` varchar(191) not null default '' unique, + `description` varchar(255) not null default '', + `category` varchar(255) not null default '', + `plugin_id` int unsigned not null default 0, + `plugin_type` varchar(255) not null default '', + `plugin_type_name` varchar(255) not null default '', + `cluster_name` varchar(255) not null default '', + `settings` text not null, + `status` varchar(255) not null default '', + `http` varchar(4096) not null default '', + `auth` varchar(8192) not null default '', + `is_default` tinyint not null default 0, + `created_at` bigint not null default 0, + `created_by` varchar(64) not null default '', + `updated_at` bigint not null default 0, + `updated_by` varchar(64) not null default '' +); + +CREATE TABLE `builtin_cate` ( + `id` integer primary key autoincrement, + `name` varchar(191) not null, + `user_id` bigint not null default 0 +); + +CREATE TABLE `notify_tpl` ( + `id` integer primary key autoincrement, + `channel` varchar(32) not null unique, + `name` varchar(255) not null, + `content` text not null, + `create_at` bigint not null default 0, + `create_by` varchar(64) not null default '', + `update_at` bigint not null default 0, + `update_by` varchar(64) not null default '' +); + +CREATE TABLE `sso_config` ( + `id` integer primary key autoincrement, + `name` varchar(191) not null unique, + `content` text not null, + `update_at` bigint not null default 0 +); + +CREATE TABLE `es_index_pattern` ( + `id` integer primary key autoincrement, + `datasource_id` bigint not null default 0, + `name` varchar(191) not null, + `time_field` varchar(128) not null default '@timestamp', + `allow_hide_system_indices` tinyint(1) not null default 0, + `fields_format` varchar(4096) not null default '', + `create_at` bigint default '0', + `create_by` varchar(64) default '', + `update_at` bigint default '0', + `update_by` varchar(64) default '', + unique (`datasource_id`, `name`) +); + +CREATE TABLE `builtin_metrics` ( + `id` integer primary key autoincrement, + `collector` varchar(191) NOT NULL, + `typ` varchar(191) NOT NULL, + `name` varchar(191) NOT NULL, + `unit` varchar(191) NOT NULL, + `lang` varchar(191) NOT NULL DEFAULT '', + `note` varchar(4096) NOT NULL, + `expression` varchar(4096) NOT NULL, + `created_at` bigint NOT NULL DEFAULT 0, + `created_by` varchar(191) NOT NULL DEFAULT '', + `updated_at` bigint NOT NULL DEFAULT 0, + `updated_by` varchar(191) NOT NULL DEFAULT '' +); +-- CREATE UNIQUE INDEX `idx_builtin_metrics_collector_typ_name` ON `builtin_metrics` (`lang`,`collector`, `typ`, `name` asc); +-- CREATE INDEX `idx_builtin_metrics_collector` ON `builtin_metrics` (`collector` asc); +-- CREATE INDEX `idx_builtin_metrics_typ` ON `builtin_metrics` (`typ` asc); +-- CREATE INDEX `idx_builtin_metrics_name` ON `builtin_metrics` (`name` asc); +-- CREATE INDEX `idx_builtin_metrics_lang` ON `builtin_metrics` (`lang` asc); + + +CREATE TABLE `metric_filter` ( + `id` integer primary key autoincrement, + `name` varchar(191) NOT NULL, + `configs` varchar(4096) NOT NULL, + `groups_perm` text, + `create_at` bigint NOT NULL DEFAULT '0', + `create_by` varchar(191) NOT NULL DEFAULT '', + `update_at` bigint NOT NULL DEFAULT '0', + `update_by` varchar(191) NOT NULL DEFAULT '' +); +CREATE INDEX `idx_metric_filter_name` ON `metric_filter` (`name` asc); + + +CREATE TABLE `task_meta` +( + `id` integer primary key autoincrement, + `title` varchar(255) not null default '', + `account` varchar(64) not null, + `batch` int unsigned not null default 0, + `tolerance` int unsigned not null default 0, + `timeout` int unsigned not null default 0, + `pause` varchar(255) not null default '', + `script` text not null, + `args` varchar(512) not null default '', + `stdin` varchar(1024) not null default '', + `creator` varchar(64) not null default '', + `created` timestamp not null default CURRENT_TIMESTAMP +); +CREATE INDEX `idx_task_meta_creator` ON `task_meta` (`creator` asc); +CREATE INDEX `idx_task_meta_created` ON `task_meta` (`created` asc); + + +/* start|cancel|kill|pause */ +CREATE TABLE `task_action` +( + `id` integer primary key autoincrement, + `action` varchar(32) not null, + `clock` bigint not null default 0 +); + +CREATE TABLE `task_scheduler` +( + `id` bigint unsigned not null, + `scheduler` varchar(128) not null default '' +); +CREATE INDEX `idx_task_scheduler_id_scheduler` ON `task_scheduler` (`id`, `scheduler` asc); + +CREATE TABLE `task_scheduler_health` +( + `scheduler` varchar(128) not null unique, + `clock` bigint not null +); +CREATE INDEX `idx_task_scheduler_health_clock` ON `task_scheduler_health` (`clock` asc); + +CREATE TABLE `task_host_doing` +( + `id` bigint unsigned not null, + `host` varchar(128) not null, + `clock` bigint not null default 0, + `action` varchar(16) not null +); +CREATE INDEX `idx_task_host_doing_id` ON `task_host_doing` (`id` asc); +CREATE INDEX `idx_task_host_doing_host` ON `task_host_doing` (`host` asc); + +CREATE TABLE task_host_0 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_1 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_2 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_3 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_4 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_5 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_6 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_7 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_8 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_9 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_10 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_11 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_12 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_13 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_14 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_15 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_16 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_17 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_18 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_19 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_20 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_21 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_22 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_23 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_24 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_25 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_26 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_27 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_28 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_29 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_30 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_31 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_32 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_33 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_34 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_35 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_36 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_37 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_38 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_39 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_40 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_41 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_42 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_43 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_44 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_45 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_46 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_47 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_48 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_49 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_50 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_51 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_52 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_53 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_54 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_55 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_56 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_57 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_58 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_59 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_60 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_61 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_62 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_63 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_64 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_65 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_66 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_67 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_68 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_69 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_70 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_71 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_72 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_73 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_74 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_75 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_76 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_77 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_78 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_79 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_80 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_81 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_82 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_83 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_84 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_85 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_86 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_87 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_88 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_89 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_90 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_91 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_92 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_93 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_94 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_95 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_96 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_97 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_98 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); + +CREATE TABLE task_host_99 +( + `ii` integer primary key autoincrement, + `id` bigint unsigned not null, + `host` varchar(128) not null, + `status` varchar(32) not null, + `stdout` text, + `stderr` text, + unique (`id`, `host`) +); diff --git a/etc/config.toml b/etc/config.toml index 7bce99bfc..0180c5f08 100644 --- a/etc/config.toml +++ b/etc/config.toml @@ -75,10 +75,11 @@ OpenRSA = false [DB] # postgres: host=%s port=%s user=%s dbname=%s password=%s sslmode=%s # postgres: DSN="host=127.0.0.1 port=5432 user=root dbname=n9e_v6 password=1234 sslmode=disable" -DSN="root:1234@tcp(127.0.0.1:3306)/n9e_v6?charset=utf8mb4&parseTime=True&loc=Local&allowNativePasswords=true" +# sqlite: DSN="/path/to/filename.db" +DSN = "root:1234@tcp(127.0.0.1:3306)/n9e_v6?charset=utf8mb4&parseTime=True&loc=Local&allowNativePasswords=true" # enable debug mode or not Debug = false -# mysql postgres +# mysql postgres sqlite DBType = "mysql" # unit: s MaxLifetime = 7200 diff --git a/go.mod b/go.mod index 6dae184e6..9bd974d53 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,8 @@ require ( gopkg.in/yaml.v2 v2.4.0 gorm.io/driver/mysql v1.4.4 gorm.io/driver/postgres v1.4.5 - gorm.io/gorm v1.24.2 + gorm.io/driver/sqlite v1.5.5 + gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde ) require ( @@ -77,6 +78,7 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/mattn/go-sqlite3 v1.14.17 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/go.sum b/go.sum index 32e870de3..68a98e6c7 100644 --- a/go.sum +++ b/go.sum @@ -209,6 +209,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= +github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -464,9 +466,11 @@ gorm.io/driver/mysql v1.4.4 h1:MX0K9Qvy0Na4o7qSC/YI7XxqUw5KDw01umqgID+svdQ= gorm.io/driver/mysql v1.4.4/go.mod h1:BCg8cKI+R0j/rZRQxeKis/forqRwRSYOR8OM3Wo6hOM= gorm.io/driver/postgres v1.4.5 h1:mTeXTTtHAgnS9PgmhN2YeUbazYpLhUI1doLnw42XUZc= gorm.io/driver/postgres v1.4.5/go.mod h1:GKNQYSJ14qvWkvPwXljMGehpKrhlDNsqYRr5HnYGncg= +gorm.io/driver/sqlite v1.5.5 h1:7MDMtUZhV065SilG62E0MquljeArQZNfJnjd9i9gx3E= +gorm.io/driver/sqlite v1.5.5/go.mod h1:6NgQ7sQWAIFsPrJJl1lSNSu2TABh0ZZ/zm5fosATavE= gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= gorm.io/gorm v1.24.1-0.20221019064659-5dd2bb482755/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= -gorm.io/gorm v1.24.2 h1:9wR6CFD+G8nOusLdvkZelOEhpJVwwHzpQOUM+REd6U0= -gorm.io/gorm v1.24.2/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde h1:9DShaph9qhkIYw7QF91I/ynrr4cOO2PZra2PFD7Mfeg= +gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/models/builtin_metrics.go b/models/builtin_metrics.go index b6dd02d44..ac1c3a7e6 100644 --- a/models/builtin_metrics.go +++ b/models/builtin_metrics.go @@ -15,7 +15,7 @@ type BuiltinMetric struct { UUID int64 `json:"uuid" gorm:"type:bigint;not null;default:0;comment:'uuid'"` Collector string `json:"collector" gorm:"type:varchar(191);not null;index:idx_collector,sort:asc;comment:'type of collector'"` // Type of collector (e.g., 'categraf', 'telegraf') Typ string `json:"typ" gorm:"type:varchar(191);not null;index:idx_typ,sort:asc;comment:'type of metric'"` // Type of metric (e.g., 'host', 'mysql', 'redis') - Name string `json:"name" gorm:"type:varchar(191);not null;index:idx_name,sort:asc;comment:'name of metric'"` + Name string `json:"name" gorm:"type:varchar(191);not null;index:idx_builtinmetric_name,sort:asc;comment:'name of metric'"` Unit string `json:"unit" gorm:"type:varchar(191);not null;comment:'unit of metric'"` Note string `json:"note" gorm:"type:varchar(4096);not null;comment:'description of metric'"` Lang string `json:"lang" gorm:"type:varchar(191);not null;default:'zh';index:idx_lang,sort:asc;comment:'language'"` diff --git a/models/builtin_metrics_filter.go b/models/builtin_metrics_filter.go index bebe0f4c5..9706798e5 100644 --- a/models/builtin_metrics_filter.go +++ b/models/builtin_metrics_filter.go @@ -10,7 +10,7 @@ import ( type MetricFilter struct { ID int64 `json:"id" gorm:"primaryKey;type:bigint;autoIncrement;comment:'unique identifier'"` - Name string `json:"name" gorm:"type:varchar(191);not null;index:idx_name,sort:asc;comment:'name of metric filter'"` + Name string `json:"name" gorm:"type:varchar(191);not null;index:idx_metricfilter_name,sort:asc;comment:'name of metric filter'"` Configs string `json:"configs" gorm:"type:varchar(4096);not null;comment:'configuration of metric filter'"` GroupsPerm []GroupPerm `json:"groups_perm" gorm:"type:text;serializer:json;"` CreateAt int64 `json:"create_at" gorm:"type:bigint;not null;default:0;comment:'create time'"` diff --git a/models/builtin_payload.go b/models/builtin_payload.go index 89456e55f..b07073888 100644 --- a/models/builtin_payload.go +++ b/models/builtin_payload.go @@ -13,7 +13,7 @@ type BuiltinPayload struct { Type string `json:"type" gorm:"type:varchar(191);not null;index:idx_type,sort:asc;comment:'type of payload'"` // Alert Dashboard Collet Component string `json:"component" gorm:"type:varchar(191);not null;index:idx_component,sort:asc;comment:'component of payload'"` // Host MySQL Redis Cate string `json:"cate" gorm:"type:varchar(191);not null;comment:'category of payload'"` // categraf_v1 telegraf_v1 - Name string `json:"name" gorm:"type:varchar(191);not null;index:idx_name,sort:asc;comment:'name of payload'"` // + Name string `json:"name" gorm:"type:varchar(191);not null;index:idx_buildinpayload_name,sort:asc;comment:'name of payload'"` // Tags string `json:"tags" gorm:"type:varchar(191);not null;default:'';comment:'tags of payload'"` // {"host":" Content string `json:"content" gorm:"type:longtext;not null;comment:'content of payload'"` UUID int64 `json:"uuid" gorm:"type:bigint;not null;index:idx_uuid;comment:'uuid of payload'"` diff --git a/pkg/ormx/ormx.go b/pkg/ormx/ormx.go index 75a3a1982..aec1090d0 100644 --- a/pkg/ormx/ormx.go +++ b/pkg/ormx/ormx.go @@ -9,6 +9,7 @@ import ( tklog "github.com/toolkits/pkg/logger" "gorm.io/driver/mysql" "gorm.io/driver/postgres" + "gorm.io/driver/sqlite" "gorm.io/gorm" "gorm.io/gorm/logger" "gorm.io/gorm/schema" @@ -72,12 +73,16 @@ func (l *TKitLogger) Printf(s string, i ...interface{}) { // New Create gorm.DB instance func New(c DBConfig) (*gorm.DB, error) { var dialector gorm.Dialector + sqliteUsed := false switch strings.ToLower(c.DBType) { case "mysql": dialector = mysql.Open(c.DSN) case "postgres": dialector = postgres.Open(c.DSN) + case "sqlite": + dialector = sqlite.Open(c.DSN) + sqliteUsed = true default: return nil, fmt.Errorf("dialector(%s) not supported", c.DBType) } @@ -104,9 +109,11 @@ func New(c DBConfig) (*gorm.DB, error) { return nil, err } - sqlDB.SetMaxIdleConns(c.MaxIdleConns) - sqlDB.SetMaxOpenConns(c.MaxOpenConns) - sqlDB.SetConnMaxLifetime(time.Duration(c.MaxLifetime) * time.Second) + if !sqliteUsed { + sqlDB.SetMaxIdleConns(c.MaxIdleConns) + sqlDB.SetMaxOpenConns(c.MaxOpenConns) + sqlDB.SetConnMaxLifetime(time.Duration(c.MaxLifetime) * time.Second) + } return db, nil }