#wip: SQL Building. Docker container done.

This commit is contained in:
KyMAN 2026-03-03 21:53:09 +01:00
parent 36e6187c04
commit a363133891
5 changed files with 454 additions and 49 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@ __pycache__
*.[Ss]ecrets.*
*.[Ss]ecret.*
/Python/pyodbc.py
/SQLServer/data
/SQLServer/temporary
/SQLServer/scripts

5
SQLServer/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
from mcr.microsoft.com/mssql/server:2022-latest
expose 1433/tcp
user root
env ACCEPT_EULA=Y
env MSSQL_SA_PASSWORD=Abc123..

View File

@ -9,6 +9,9 @@ create procedure dbo.tables_drop as begin
set nocount on
-- Level Plains.
if object_id(N'dbo.MachineInterfacesPlain', N'U') is not null drop table dbo.MachineInterfacesPlain
if object_id(N'dbo.MachineDisksPlain', N'U') is not null drop table dbo.MachineDisksPlain
if object_id(N'dbo.MachinePlain', N'U') is not null drop table dbo.MachinePlain
-- Level 2.
if object_id(N'dbo.MachineInterfacesData', N'U') is not null drop table dbo.MachineInterfacesData
@ -52,7 +55,7 @@ create procedure dbo.tables_create as begin
date_out datetime,
constraint machines_pk primary key clustered (id),
constraint machines_uk_key unique ([key]),
constraint machines_ck_key check ([key] like '[a-zA-Z0-9][a-zA-Z0-9_]{0,31}') with (fillfactor = 90)
constraint machines_ck_key check ([key] like '[a-zA-Z0-9][a-zA-Z0-9_]{0,31}')
)
if object_id(N'dbo.Domains', N'U') is null create table dbo.Domains(
@ -63,7 +66,7 @@ create procedure dbo.tables_create as begin
date_out datetime,
constraint domains_pk primary key clustered (id),
constraint domains_uk_domain unique nonclustered (domain asc) with (fillfactor = 90),
constraint domains_ck_domain check ([domain] like '[a-zA-Z0-9_-.]{1,64}') with (fillfactor = 90)
constraint domains_ck_domain check ([domain] like '[a-zA-Z0-9_-.]{1,64}')
)
@ -75,7 +78,7 @@ create procedure dbo.tables_create as begin
date_out datetime,
constraint hostnames_pk primary key clustered (id),
constraint hostnames_uk_name unique nonclustered ([name] asc) with (fillfactor = 90),
constraint hostnames_ck_name check ([name] like '[a-zA-Z0-9_-]{1,32}') with (fillfactor = 90)
constraint hostnames_ck_name check ([name] like '[a-zA-Z0-9_-]{1,32}')
)
if object_id(N'dbo.Disks', N'U') is null create table dbo.Disks(
@ -87,17 +90,17 @@ create procedure dbo.tables_create as begin
date_in datetime not null constraint disks_df_date_in default getdate(),
date_out datetime,
constraint disks_pk primary key clustered (id),
constraint disks_uk_name unique nonclustered ([name] asc, mountpoint asc) with (fillfactor = 90),
-- constraint disks_uk_name unique nonclustered ([name] asc, mountpoint asc) with (fillfactor = 90),
constraint disks_ck_name check (
[name] like '[a-zA-Z0-9_-]{1,32}' or
mountpoint like '[A-Z]:'
) with (fillfactor = 90),
constraint disks_ck_size check (size >= 0 and size < power(2, 53)) with (fillfactor = 90),
),
constraint disks_ck_size check (size >= 0 and size < power(2, 53)),
constraint disks_ck_mountpoint check (
mountpoint like '/%' or
mountpoint like '[a-zA-Z]:\%' or
mountpoint like '\\%'
) with (fillfactor = 90)
)
)
if object_id(N'dbo.Interfaces', N'U') is null create table dbo.Interfaces(
@ -107,19 +110,20 @@ create procedure dbo.tables_create as begin
date_in datetime not null constraint interfaces_df_date_in default getdate(),
date_out datetime,
constraint interfaces_pk primary key clustered (id),
constraint interfaces_uk_machine_name unique nonclustered (machine asc, [name] asc) with (fillfactor = 90),
constraint interfaces_ck_name check ([name] like '[a-zA-Z0-9_-]{1,32}') with (fillfactor = 90)
-- constraint interfaces_uk_machine_name unique nonclustered ([name] asc) with (fillfactor = 90),
constraint interfaces_ck_name check ([name] like '[a-zA-Z0-9_-]{1,32}')
)
if object_id(N'dbo.CandlesTimes', N'U') is null create table dbo.CandlesTimes(
id integer not null identity(1, 1),
[from] datetime not null,
[to] datetime not null,
iterations integer not null,
date_in datetime not null constraint candles_times_df_date_in default getdate(),
date_out datetime,
constraint candles_times_pk primary key clustered (id),
constraint candles_times_uk_from_to unique nonclustered ([from] asc, [to] asc) with (fillfactor = 90),
constraint candles_times_ck_from_to check ([from] < [to]) with (fillfactor = 90)
constraint candles_times_ck_from_to check ([from] < [to])
)
if object_id(N'dbo.BigData', N'U') is null create table dbo.BigData(
@ -138,7 +142,7 @@ create procedure dbo.tables_create as begin
date_in datetime not null constraint messages_df_date_in default getdate(),
date_out datetime,
constraint messages_pk primary key clustered (id),
constraint messages_ck_key check ([key] like '[a-zA-Z_][a-zA-Z0-9_]{0,127}') with (fillfactor = 90)
constraint messages_ck_key check ([key] like '[a-zA-Z_][a-zA-Z0-9_]{0,127}')
)
if object_id(N'dbo.Databases', N'U') is null create table dbo.Databases(
@ -148,7 +152,7 @@ create procedure dbo.tables_create as begin
date_out datetime,
constraint databases_pk primary key clustered (id),
constraint databases_uk_name unique nonclustered ([name] asc) with (fillfactor = 90),
constraint databases_ck_name check ([name] like '[a-zA-Z_][a-zA-Z0-9_]{0,63}') with (fillfactor = 90)
constraint databases_ck_name check ([name] like '[a-zA-Z_][a-zA-Z0-9_]{0,63}')
)
-- Level 1.
@ -173,23 +177,23 @@ create procedure dbo.tables_create as begin
constraint machine_cpu_ck_cpu_in check (
[in] between 0 and 100 and
[in] between minimum and maximum
) with (fillfactor = 90),
),
constraint machine_cpu_ck_cpu_out check (
[out] between 0 and 100 and
[out] between minimum and maximum
) with (fillfactor = 90),
),
constraint machine_cpu_ck_cpu_minimum check (
minimum between 0 and 100 and
minimum <= maximum
) with (fillfactor = 90),
),
constraint machine_cpu_ck_cpu_maximum check (
maximum between 0 and 100 and
maximum >= minimum
) with (fillfactor = 90),
),
constraint machine_cpu_ck_cpu_average check (
average between 0 and 100 and
average between minimum and maximum
) with (fillfactor = 90)
)
)
if object_id(N'dbo.MachineRAM', N'U') is null create table dbo.MachineRAM(
@ -213,31 +217,31 @@ create procedure dbo.tables_create as begin
on delete no action,
constraint machine_ram_ck_memory_total check (
total between 0 and power(2, 53) - 1
) with (fillfactor = 90),
),
constraint machine_ram_ck_memory_in check (
[in] between 0 and power(2, 53) - 1 and
[in] between minimum and maximum and
[in] <= total
) with (fillfactor = 90),
),
constraint machine_ram_ck_memory_out check (
[out] between 0 and power(2, 53) - 1 and
[out] between minimum and maximum and
[out] <= total
) with (fillfactor = 90),
),
constraint machine_ram_ck_memory_minimum check (
minimum between 0 and power(2, 53) - 1 and
minimum <= total and
minimum <= maximum
) with (fillfactor = 90),
),
constraint machine_ram_ck_memory_maximum check (
maximum between 0 and power(2, 53) - 1 and
maximum between total and minimum
) with (fillfactor = 90),
),
constraint machine_ram_ck_memory_average check (
average between 0 and power(2, 53) - 1 and
average between minimum and maximum and
average <= total
) with (fillfactor = 90)
)
)
if object_id(N'dbo.MachineDisks', N'U') is null create table dbo.MachineDisks(
@ -285,7 +289,7 @@ create procedure dbo.tables_create as begin
on update no action
on delete no action,
constraint procedures_uk_name unique nonclustered ([database] asc, [name] asc) with (fillfactor = 90),
constraint procedures_ck_name check ([name] like '[a-zA-Z_][a-zA-Z0-9_]{0,63}') with (fillfactor = 90)
constraint procedures_ck_name check ([name] like '[a-zA-Z_][a-zA-Z0-9_]{0,63}')
)
-- Level 2.
@ -304,18 +308,18 @@ create procedure dbo.tables_create as begin
on update no action
on delete no action,
constraint machine_disks_space_ck_free check (
free between 0 and power(2, 53) - 1 and
free <= isnull((
select top 1 disks.[size]
from dbo.Disks disks
join dbo.MachineDisks machine_disks on machine_disks.[disk] = disks.id
where
disks.date_out is null and
machine_disks.date_out is null and
machine_disks.belongs = 1 and
machine_disks.id = machine_disk
), 0)
) with (fillfactor = 90)
free between 0 and power(2, 53) - 1 -- and
-- free <= isnull((
-- select top 1 disks.[size]
-- from dbo.Disks disks
-- join dbo.MachineDisks machine_disks on machine_disks.[disk] = disks.id
-- where
-- disks.date_out is null and
-- machine_disks.date_out is null and
-- machine_disks.belongs = 1 and
-- machine_disks.id = machine_disk
-- ), 0)
)
)
if object_id(N'dbo.MachineInterfacesTraffic', N'U') is null create table dbo.MachineInterfacesTraffic(
@ -336,13 +340,13 @@ create procedure dbo.tables_create as begin
on delete no action,
constraint machine_interfaces_traffic_ck_bytes check (
bytes between 0 and power(2, 53) - 1
) with (fillfactor = 90),
),
constraint machine_interfaces_traffic_ck_packages check (
packages between 0 and power(2, 31) - 1
) with (fillfactor = 90),
),
constraint machine_interfaces_traffic_ck_errors check (
errors between 0 and power(2, 31) - 1
) with (fillfactor = 90)
)
)
if object_id(N'dbo.MachineInterfacesData', N'U') is null create table dbo.MachineInterfacesData(
@ -360,14 +364,14 @@ create procedure dbo.tables_create as begin
constraint machine_interfaces_data_ck_is_ipv6 check (
(is_ipv6 = 0 and [address] like '[0-9]%.%.%.%') or
(is_ipv6 = 1 and [address] like '%:%')
) with (fillfactor = 90),
),
constraint machine_interfaces_data_ck_address check (
([address] like '[0-9]%.%.%.%' and mask between 0 and 32) or
([address] like '%:%' and mask between 0 and 128)
) with (fillfactor = 90),
),
constraint machine_interfaces_data_ck_mask check (
(mask between 0 and (case when is_ipv6 = 1 then 128 else 32 end))
) with (fillfactor = 90)
)
)
if object_id(N'dbo.Exceptions', N'U') is null create table dbo.Exceptions(
@ -395,28 +399,165 @@ create procedure dbo.tables_create as begin
on delete no action
)
-- Level Plains.
-- Level Plains 1.
if object_id(N'dbo.MachinePlain', N'U') is null create table dbo.MachinePlain(
id integer not null identity(1, 1),
[key] varchar(32) not null,
machine integer not null,
candle_time integer not null,
machine_ram integer not null,
machine_cpu integer not null,
ram_total bigint not null,
ram_in bigint not null,
ram_out bigint not null,
ram_minimum bigint not null,
ram_maximum bigint not null,
ram_average bigint not null,
cpu_in float not null,
cpu_out float not null,
cpu_minimum float not null,
cpu_maximum float not null,
cpu_average float not null,
date_in datetime not null constraint machine_plain_df_date_in default getdate(),
date_out datetime,
constraint machine_plain_pk primary key clustered (id),
constraint machine_plain_fk_machine foreign key (machine) references dbo.Machines(id)
on update no action
on delete no action,
constraint machine_plain_fk_candle_time foreign key (candle_time) references dbo.CandlesTimes(id)
on update no action
on delete no action,
constraint machine_plain_fk_machine_ram foreign key (machine_ram) references dbo.MachineRAM(id)
on update no action
on delete no action,
constraint machine_plain_fk_machine_cpu foreign key (machine_cpu) references dbo.MachineCPU(id)
on update no action
on delete no action,
constraint machine_plain_uk_key unique ([key]),
constraint machine_plain_ck_key check ([key] like '[a-zA-Z0-9][a-zA-Z0-9_]{0,31}'),
constraint machine_plain_ck_memory_total check (
ram_total between 0 and power(2, 53) - 1
),
constraint machine_plain_ck_memory_in check (
ram_in between 0 and power(2, 53) - 1 and
ram_in between ram_minimum and ram_maximum and
ram_in <= ram_total
),
constraint machine_plain_ck_memory_out check (
ram_out between 0 and power(2, 53) - 1 and
ram_out between ram_minimum and ram_maximum and
ram_out <= ram_total
),
constraint machine_plain_ck_memory_minimum check (
ram_minimum between 0 and power(2, 53) - 1 and
ram_minimum <= ram_total and
ram_minimum <= ram_maximum
),
constraint machine_plain_ck_memory_maximum check (
ram_maximum between 0 and power(2, 53) - 1 and
ram_maximum between ram_total and ram_minimum
),
constraint machine_plain_ck_memory_average check (
ram_average between 0 and power(2, 53) - 1 and
ram_average between ram_minimum and ram_maximum and
ram_average <= ram_total
),
constraint machine_plain_ck_cpu_in check (
cpu_in between 0 and 100 and
cpu_in between cpu_minimum and cpu_maximum
),
constraint machine_plain_ck_cpu_out check (
cpu_out between 0 and 100 and
cpu_out between cpu_minimum and cpu_maximum
),
constraint machine_plain_ck_cpu_minimum check (
cpu_minimum between 0 and 100 and
cpu_minimum <= cpu_maximum
),
constraint machine_plain_ck_cpu_maximum check (
cpu_maximum between 0 and 100 and
cpu_maximum >= cpu_minimum
),
constraint machine_plain_ck_cpu_average check (
cpu_average between 0 and 100 and
cpu_average between cpu_minimum and cpu_maximum
)
)
-- Level Plains 1.
if object_id(N'dbo.MachineInterfacesPlain', N'U') is null create table dbo.MachineInterfacesPlain(
id integer not null identity(1, 1),
plain integer not null,
machine integer not null,
interface integer not null,
machine_interface integer not null,
candle_time integer not null,
[name] varchar(32) not null,
bytes bigint not null,
packages integer not null,
errors integer not null,
is_ipv6 bit not null constraint machine_interfaces_data_df_is_ipv6 default 0,
is_ipv6 bit not null constraint machine_interfaces_plain_df_is_ipv6 default 0,
[address] varchar(45) not null,
mask tinyint not null,
belongs bit not null constraint machine_interfaces_plain_df_belongs default 1,
date_in datetime not null constraint machine_interfaces_plain_df_date_in default getdate(),
date_out datetime,
constraint machine_interfaces_plain_pk primary key clustered (id),
constraint machine_interfaces_plain_fk_plain foreign key (plain) references dbo.MachinePlain(id)
on update no action
on delete no action,
constraint machine_interfaces_plain_fk_machine foreign key (machine) references dbo.Machines(id)
on update no action
on delete no action,
constraint machine_interfaces_plain_fk_interface foreign key (interface) references dbo.Interfaces(id)
on update no action
on delete no action,
constraint machine_interfaces_plain_uk_machine_interface unique nonclustered (machine asc, [interface] asc) with (fillfactor = 90),
constraint machine_interfaces_plain_ck_interface check ([interface] like '[a-zA-Z0-9_-]{1,32}') with (fillfactor = 90)
-- constraint machine_interfaces_plain_uk_machine_name unique nonclustered ([name] asc) with (fillfactor = 90),
constraint machine_interfaces_plain_ck_name check ([name] like '[a-zA-Z0-9_-]{1,32}'),
constraint machine_interfaces_plain_ck_interface check ([interface] like '[a-zA-Z0-9_-]{1,32}')
)
if object_id(N'dbo.MachineDisksPlain', N'U') is null create table dbo.MachineDisksPlain(
id integer not null identity(1, 1),
plain integer not null,
machine integer not null,
[disk] integer not null,
machine_disk integer not null,
candle_time integer not null,
[name] varchar(32) not null,
[size] bigint not null,
mountpoint varchar(128) not null,
free bigint not null,
belongs bit not null constraint machine_disks_plain_df_belongs default 1,
date_in datetime not null constraint machine_disks_plain_df_date_in default getdate(),
date_out datetime,
constraint machine_disks_plain_pk primary key clustered (id),
constraint machine_disks_plain_fk_plain foreign key (plain) references dbo.MachinePlain(id)
on update no action
on delete no action,
constraint machine_disks_plain_fk_machine foreign key (machine) references dbo.Machines(id)
on update no action
on delete no action,
constraint machine_disks_plain_fk_disk foreign key ([disk]) references dbo.Disks(id)
on update no action
on delete no action,
constraint machine_disks_plain_uk_machine_disk unique nonclustered (machine asc, [disk] asc) with (fillfactor = 90),
-- constraint machine_disks_plain_uk_name unique nonclustered ([name] asc, mountpoint asc) with (fillfactor = 90),
constraint machine_disks_plain_ck_name check (
[name] like '[a-zA-Z0-9_-]{1,32}' or
mountpoint like '[A-Z]:'
),
constraint machine_disks_plain_ck_size check (size >= 0 and size < power(2, 53)),
constraint machine_disks_plain_ck_mountpoint check (
mountpoint like '/%' or
mountpoint like '[a-zA-Z]:\%' or
mountpoint like '\\%'
),
constraint machine_disks_plain_ck_free check (
free between 0 and power(2, 53) - 1 and
free <= [size]
)
)
end
@ -451,8 +592,8 @@ go
if object_id(N'dbo.hash_big_data', N'FN') is not null drop function dbo.hash_big_data
go
create function dbo.hash_big_data (@value varchar(max)) returns binary(64) as begin
return select top 1 convert(binary(64), hashbytes('SHA2_256', convert(nvarchar(max), @value)))
create function dbo.hash_big_data (@value varchar(max)) returns binary(64) begin
return (select top 1 convert(binary(64), hashbytes('SHA2_256', convert(nvarchar(max), @value))))
end
go
@ -607,3 +748,234 @@ where
parameters.date_out is null and
exception.date_out is null
go
if object_id(N'dbo.get_basic_data_ids', N'P') is not null drop procedure dbo.get_basic_data_ids
go
create procedure dbo.get_basic_data_ids
@key varchar(32),
@candle_start datetime,
@candle_end datetime,
@candle_interations integer,
@machine_id integer output,
@candle_time_id integer output
as begin
set nocount on
set @machine_id = (
select top 1 id from dbo.Machines where
date_out is null and
[key] = @key
)
if @machine_id is null begin
insert into dbo.BasicData([key]) values (@key)
set @machine_id = scope_identity()
end
set @machine_id = @machine_id
set @candle_time_id = (
select top 1 id from dbo.CandlesTimes where
date_out is null and
[from] = @candle_start and
[to] = @candle_end and
iterations = @candle_interations
)
if @candle_time_id is null begin
insert into dbo.CandlesTimes([from], [to], iterations) values (@candle_start, @candle_end, @candle_interations)
set @candle_time_id = scope_identity()
end
set @candle_time_id = @candle_time_id
end
go
if object_id(N'dbo.set_machine_data', N'P') is not null drop procedure dbo.set_machine_data
go
create procedure dbo.set_machine_data
@key varchar(32),
@candle_start datetime,
@candle_end datetime,
@candle_interations integer,
@ram_total bigint,
@ram_in bigint,
@ram_out bigint,
@ram_minimum bigint,
@ram_maximum bigint,
@ram_average bigint,
@cpu_in float,
@cpu_out float,
@cpu_minimum float,
@cpu_maximum float,
@cpu_average float
as begin
declare @machine_id integer
declare @candle_time_id integer
declare @machine_ram_id integer
declare @machine_cpu_id integer
set nocount on
execute dbo.get_basic_data_ids
@key,
@candle_start,
@candle_end,
@candle_interations,
@machine_id output,
@candle_time_id output
insert into dbo.MachineRAM(machine, candle_time, total, [in], [out], minimum, maximum, average) values
(@machine_id, @candle_time_id, @ram_total, @ram_in, @ram_out, @ram_minimum, @ram_maximum, @ram_average)
set @machine_ram_id = scope_identity()
insert into dbo.MachineCPU(machine, candle_time, [in], [out], minimum, maximum, average) values
(@machine_id, @candle_time_id, @cpu_in, @cpu_out, @cpu_minimum, @cpu_maximum, @cpu_average)
set @machine_cpu_id = scope_identity()
if (select top 1 id from dbo.MachinePlain where
date_out is null and
machine = @machine_id and
candle_time = @candle_time_id
) is null
insert into dbo.MachinePlain([key], machine, candle_time, machine_ram, machine_cpu, ram_total, ram_in, ram_out, ram_minimum, ram_maximum, ram_average, cpu_in, cpu_out, cpu_minimum, cpu_maximum, cpu_average) values
(@key, @machine_id, @candle_time_id, @machine_ram_id, @machine_cpu_id, @ram_total, @ram_in, @ram_out, @ram_minimum, @ram_maximum, @ram_average, @cpu_in, @cpu_out, @cpu_minimum, @cpu_maximum, @cpu_average)
else
update dbo.MachinePlain set
machine_ram = @machine_ram_id,
machine_cpu = @machine_cpu_id,
ram_total = @ram_total,
ram_in = @ram_in,
ram_out = @ram_out,
ram_minimum = @ram_minimum,
ram_maximum = @ram_maximum,
ram_average = @ram_average,
cpu_in = @cpu_in,
cpu_out = @cpu_out,
cpu_minimum = @cpu_minimum,
cpu_maximum = @cpu_maximum,
cpu_average = @cpu_average
where
date_out is null and
[key] = @key and
candle_time = @candle_time_id
end
go
if object_id(N'dbo.set_machine_interface_data', N'P') is not null drop procedure dbo.set_machine_interface_data
go
create procedure dbo.set_machine_interface_data
@key varchar(32),
@candle_start datetime,
@candle_end datetime,
@candle_interations integer,
@name varchar(32),
@bytes bigint,
@packages integer,
@errors integer,
@is_ipv6 bit,
@address varchar(45),
@mask tinyint
as begin
declare @machine_id integer
declare @candle_time_id integer
declare @interface_id integer = (select top 1 id from dbo.Interfaces where
date_out is null and
[name] = @name
)
declare @machine_interface_id integer
declare @machine_interface_data_id integer
declare @machine_interface_traffic_id integer
set nocount on
execute dbo.get_basic_data_ids
@key,
@candle_start,
@candle_end,
@candle_interations,
@machine_id output,
@candle_time_id output
if @interface_id is null begin
insert into dbo.Interfaces([name]) values (@name)
set @interface_id = scope_identity()
end
set @machine_interface_id = (
select top 1 id from dbo.MachineInterfaces where
date_out is null and
machine = @machine_id and
[interface] = @interface_id and
[name] = @name
)
if @machine_interface_id is null begin
insert into dbo.MachineInterfaces(machine, [interface], [name]) values (@machine_id, @interface_id, @name)
set @machine_interface_id = scope_identity()
end
set @machine_interface_data_id = (
select top 1 id from dbo.MachineInterfacesData where
date_out is null and
machine_interface = @machine_interface_id and
is_ipv6 = @is_ipv6 and
[address] = @address and
mask = @mask
)
if @machine_interface_data_id is null begin
insert into dbo.MachineInterfacesData(machine_interface, is_ipv6, [address], mask) values
(@machine_interface_id, @is_ipv6, @address, @mask)
set @machine_interface_data_id = scope_identity()
end else begin
set @machine_interface_data_id = (
select top 1 id from dbo.MachineInterfacesData where
date_out is null and
machine_interface = @machine_interface_id
)
if @machine_interface_data_id is null begin
insert into dbo.MachineInterfacesData(machine_interface, is_ipv6, [address], mask) values
(@machine_interface_id, @is_ipv6, @address, @mask)
set @machine_interface_data_id = scope_identity()
end else
update dbo.MachineInterfacesData set
is_ipv6 = @is_ipv6,
[address] = @address,
mask = @mask
where
date_out is null and
machine_interface = @machine_interface_id and
candle_time = @candle_time_id
end
insert into dbo.MachineInterfacesTraffic(machine_interface, candle_time, bytes, packages, errors) values
(@machine_interface_id, @candle_time_id, @bytes, @packages, @errors)
set @machine_interface_traffic_id = scope_identity()
if (select top 1 id from dbo.MachineInterfacesPlain where
date_out is null and
machine = @machine_id and
[interface] = @interface_id and
candle_time = @candle_time_id
) is null
insert into dbo.MachineInterfacesPlain(plain, machine, [interface], machine_interface, candle_time, [name], bytes, packages, errors, is_ipv6, [address], mask) values
(null, @machine_id, @interface_id, @machine_interface_id, @candle_time_id, @name, @bytes, @packages, @errors, @is_ipv6, @address, @mask)
else
update dbo.MachineInterfacesPlain set
machine_interface = @machine_interface_id,
bytes = @bytes,
packages = @packages,
errors = @errors,
is_ipv6 = @is_ipv6,
[address] = @address,
mask = @mask
where
date_out is null and
machine = @machine_id and
[interface] = @interface_id and
candle_time = @candle_time_id
end
go

4
SQLServer/docker.rebuild.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
directory=`dirname $(readlink -f "$0")`
[ "$(docker images -q nucelar-monitor:sql-server 2>/dev/null)" ] && docker image remove nucelar-monitor:sql-server --force
docker build -f $directory/Dockerfile -t nucelar-monitor:sql-server $directory --no-cache

21
docker-compose.yml Normal file
View File

@ -0,0 +1,21 @@
services:
nucelar-monitor-sql-server:
image: nucelar-monitor:sql-server
container_name: nucelar-monitor-sql-server
volumes:
- ./SQLServer/data:/var/opt/mssql
- ./SQLServer/temporary:/temporary
- ./SQLServer/scripts:/scripts
ports:
- 21433:1433/tcp
networks:
nucelar-monitor-network:
ipv4_address: 172.20.201.222
networks:
nucelar-monitor-network:
driver: bridge
ipam:
config:
- subnet: 172.20.201.0/24