2018-12-11 12:37:30 +01:00
|
|
|
create table public.mappings(
|
|
|
|
id serial primary key,
|
|
|
|
name text not null,
|
|
|
|
description text not null
|
|
|
|
);
|
|
|
|
|
|
|
|
create table public.mapping_level(
|
|
|
|
mapping_id integer not null,
|
|
|
|
source int not null,
|
|
|
|
target int not null,
|
|
|
|
title text not null,
|
|
|
|
color text not null,
|
|
|
|
unique(mapping_id, source)
|
|
|
|
);
|
|
|
|
|
2018-12-10 10:48:21 +01:00
|
|
|
CREATE TABLE public.notifier (
|
|
|
|
id serial NOT NULL primary key,
|
2018-12-11 20:21:14 +01:00
|
|
|
name text NOT NULL,
|
2018-12-12 13:25:40 +01:00
|
|
|
settings jsonb not null default '{}'::jsonb
|
2018-12-10 10:48:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE public.groups (
|
|
|
|
id serial NOT NULL,
|
|
|
|
name text NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE public.nodes (
|
|
|
|
id bigserial NOT NULL primary key,
|
2018-12-11 12:37:30 +01:00
|
|
|
mapping_id int references mappings(id),
|
2018-12-10 10:48:21 +01:00
|
|
|
name text NOT NULL,
|
|
|
|
updated timestamp with time zone DEFAULT now() NOT NULL,
|
|
|
|
created timestamp with time zone DEFAULT now() NOT NULL,
|
2018-12-12 13:25:40 +01:00
|
|
|
message text NOT NULL
|
2018-12-10 10:48:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE public.nodes_groups (
|
|
|
|
node_id bigint NOT NULL,
|
|
|
|
group_id integer NOT NULL,
|
|
|
|
unique(node_id, group_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE public.commands (
|
|
|
|
id serial NOT NULL primary key,
|
|
|
|
name text NOT NULL unique,
|
|
|
|
command text NOT NULL,
|
|
|
|
updated timestamp with time zone DEFAULT now() NOT NULL,
|
|
|
|
created timestamp with time zone DEFAULT now() NOT NULL,
|
2018-12-12 13:25:40 +01:00
|
|
|
message text NOT NULL
|
2018-12-10 10:48:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE public.checks (
|
|
|
|
id bigserial NOT NULL primary key,
|
|
|
|
node_id integer not null references nodes(id) on delete cascade,
|
|
|
|
command_id integer not null references commands(id) on delete restrict,
|
2018-12-11 12:37:30 +01:00
|
|
|
mapping_id int references mappings(id),
|
2018-12-10 10:48:21 +01:00
|
|
|
intval interval DEFAULT '00:05:00'::interval NOT NULL,
|
|
|
|
options jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
|
|
updated timestamp with time zone DEFAULT now() NOT NULL,
|
|
|
|
last_refresh timestamp with time zone,
|
|
|
|
enabled boolean DEFAULT true NOT NULL,
|
|
|
|
message text NOT NULL,
|
|
|
|
unique(node_id, command_id, options)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE public.active_checks (
|
2018-12-12 13:33:30 +01:00
|
|
|
check_id bigint NOT NULL unique references checks(id) on delete cascade,
|
2018-12-11 12:37:30 +01:00
|
|
|
mapping_id int not null references mappings(id),
|
2018-12-10 10:48:21 +01:00
|
|
|
cmdline text[] NOT NULL,
|
|
|
|
next_time timestamp with time zone DEFAULT now() NOT NULL,
|
|
|
|
states integer[] DEFAULT ARRAY[0] NOT NULL,
|
|
|
|
intval interval NOT NULL,
|
|
|
|
enabled boolean NOT NULL,
|
|
|
|
notice text,
|
|
|
|
msg text NOT NULL,
|
|
|
|
acknowledged boolean DEFAULT false NOT NULL
|
|
|
|
);
|
|
|
|
|
2018-12-11 20:21:14 +01:00
|
|
|
create table checks_notify(
|
|
|
|
check_id bigint not null references checks(id),
|
|
|
|
notifier_id bigint not null references notifier(id),
|
|
|
|
enabled bool not null default true,
|
|
|
|
unique(check_id, notifier_id)
|
|
|
|
);
|
|
|
|
|
2018-12-10 10:48:21 +01:00
|
|
|
CREATE TABLE public.notifications (
|
|
|
|
id bigserial NOT NULL primary key,
|
|
|
|
check_id bigint NOT NULL references checks(id) on delete cascade,
|
2018-12-11 20:21:14 +01:00
|
|
|
mapping_id integer not null references mappings(id),
|
|
|
|
notifier_id integer not null references notifier(id),
|
2018-12-10 10:48:21 +01:00
|
|
|
states integer[] NOT NULL,
|
|
|
|
output text,
|
|
|
|
inserted timestamp with time zone DEFAULT now() NOT NULL,
|
2018-12-12 13:25:40 +01:00
|
|
|
sent timestamp with time zone
|
2018-12-10 10:48:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE INDEX ON public.active_checks USING btree (next_time) WHERE enabled;
|
|
|
|
|
|
|
|
CREATE INDEX ON public.checks USING btree (command_id);
|
|
|
|
|
|
|
|
CREATE INDEX ON public.checks USING btree (node_id);
|
|
|
|
|
|
|
|
CREATE INDEX ON public.checks USING btree (updated, last_refresh NULLS FIRST);
|
|
|
|
|
|
|
|
CREATE INDEX ON public.notifications USING btree (check_id, inserted DESC);
|
|
|
|
|
|
|
|
CREATE INDEX ON public.notifications USING btree (inserted) WHERE (sent IS NULL);
|