(可疑的)多对多关系的模式设计
我正在创建一个用于跟踪网络上机器配置的应用程序。 “配置”广泛地定义了系统上安装的产品/服务/操作系统/应用程序。其中任何一项的改变都会导致配置的改变。 该信息是使用扫描仪获得的。数据已经被解析。我需要找到一种有效存储数据的方法。
基本思想是
- 每个 IP 将具有一个配置标识符以及时间戳信息和将数据标识为当前或历史的标志
- 每个配置依次由多种类型的条目组成。因此,对于每个配置标识符,我们最多有三种类型的条目(1-操作系统,2-服务,3-应用程序),
- 每种类型的条目可以有多个条目。例如,类型 1(即操作系统)可以具有 a) Microsoft Windows XP b) Microsoft Windows 7 等类型的多个条目。
我一直致力于定义一组合适的表,以帮助我实现以下目标
- 了解操作系统每个 IP 的 /Service.Application 信息
- 识别 IP 配置中的更改/无更改/恢复
我获得的数据是 IP 以及条目集及其类型标识符。例如
IP - x.y.z.w :
Entries - Microsoft Windows XP :1(Type-OS),
Apache HTTP 2.3 :2(Type-Service),
Mozilla Firefox :3(Type - Application)
,早些时候,当我不关心配置而只需要存储条目时,我采用了以下方案
Table ip_map : id int, ip char #Table that keeps track of IPs
Table ip_ref: id int , ip_id references ip_map(id), t_stamp timestamp, archived bool, type smallint #Table that keeps IPs and type
Table current_network: id int, ip_ref_id references ip_ref(id), port int, vendor, product,version #Table that stores actual entries
,即 - 我使用 IP 和类型信息识别条目。
如果我需要实现配置,该方案应该有点像
ip_map:
+--+-------+
|id|ip |
+--+-------+
|1 |x.y.z.w|
+--+-------+
ip_config:
+--+------+----------+--------+----------+
|id|ip_id |t_stamp |archived|config_num|
+--+------+----------+--------+----------+
|1 |1 |1212231313| 1 | 1 |
|2 |1 |1212299999| 0 | 2 |
+--+------+----------+--------+----------+
我被困在这之后的步骤中。理想情况下,config_num 是指向配置表主键的外键。但由于配置是由不同类型组成的,这似乎是不可能的。这就是我的想法。
config:
+--+---+----+
|id|num|type|
+--+---+----+
|1 | 1 | 1 |
|2 | 1 | 2 |
|3 | 2 | 1 |
|4 | 2 | 2 |
+--+---+----+
entry:
+--+---------+----+-------------+-------------+-------------+
|id|config_id|port|vendor | product | version |
+--+---------+----+-------------+-------------+-------------+
|1 | 1 | 0 | Microsoft | Windows | XP |
|2 | 1 | 0 | Microsoft | Windows | 7 Home |
|3 | 2 | 80 | Apache | HTTP Server | 2.3.19 |
|4 | 3 | 0 | Linux | Linux | 2.6 |
|5 | 3 | 0 | Linux | Linux | 2.4 |
|6 | 4 | 22 | OpenSSH | SSHD | 4.3p1 |
+--+---------+----+-------------+-------------+-------------+
但它破坏了一致性(由于 ip_config 和配置表之间缺少外键)。 IP 可能会被删除,但配置将继续保留。 如何更改设计以满足我的要求?
注意:理想情况下,类型信息(针对每个 IP 或配置)应单独维护,因为这是程序的单独部分所期望的。
I am creating an application for tracking the configurations of machines on a network. "Configuration" broadly defines the products/service/OS/applications installed on the system. A change in any one of them brings about a change in the configuration.
The information is obtained using scanners. The data is already parsed. I need to figure out a way to efficiently store the data.
The basic idea is
- Each IP will have a configuration identifier along with timestamp information and flags that identify the data as current or historical
- Each configuration in turns consists of entries of multiple types. So for each configuration identifier, we have at most three types of entries (1-OS,2-Service, 3- Applications)
- Each type of entry can have multiple entries. For example Type 1 (i.e. - OS) can have multiple entries of the type a) Microsoft Windows XP b) Microsoft Windows 7 etc.
I am stuck at defining a set of suitable tables that helps me in fulfilling following objectives
- Get to know the OS/Service.Application information for each IP
- Recognize changes/no changes/reverting in configuration of an IP
The data I get is the IP and the set of entries and their type identifier. E.g.
IP - x.y.z.w :
Entries - Microsoft Windows XP :1(Type-OS),
Apache HTTP 2.3 :2(Type-Service),
Mozilla Firefox :3(Type - Application)
Earlier when I was not bothered about the configuration and just had to store the entries I had the following scheme
Table ip_map : id int, ip char #Table that keeps track of IPs
Table ip_ref: id int , ip_id references ip_map(id), t_stamp timestamp, archived bool, type smallint #Table that keeps IPs and type
Table current_network: id int, ip_ref_id references ip_ref(id), port int, vendor, product,version #Table that stores actual entries
i.e. - I identified entries using IP and type information.
If I need to implement configuration, the scheme should be somewhat like
ip_map:
+--+-------+
|id|ip |
+--+-------+
|1 |x.y.z.w|
+--+-------+
ip_config:
+--+------+----------+--------+----------+
|id|ip_id |t_stamp |archived|config_num|
+--+------+----------+--------+----------+
|1 |1 |1212231313| 1 | 1 |
|2 |1 |1212299999| 0 | 2 |
+--+------+----------+--------+----------+
I am stuck in the step after this. Ideally config_num is a foreign key that points to primary key of config table. But as configuration is made up of different types, it is does not seem possible. This is what I have in my mind.
config:
+--+---+----+
|id|num|type|
+--+---+----+
|1 | 1 | 1 |
|2 | 1 | 2 |
|3 | 2 | 1 |
|4 | 2 | 2 |
+--+---+----+
entry:
+--+---------+----+-------------+-------------+-------------+
|id|config_id|port|vendor | product | version |
+--+---------+----+-------------+-------------+-------------+
|1 | 1 | 0 | Microsoft | Windows | XP |
|2 | 1 | 0 | Microsoft | Windows | 7 Home |
|3 | 2 | 80 | Apache | HTTP Server | 2.3.19 |
|4 | 3 | 0 | Linux | Linux | 2.6 |
|5 | 3 | 0 | Linux | Linux | 2.4 |
|6 | 4 | 22 | OpenSSH | SSHD | 4.3p1 |
+--+---------+----+-------------+-------------+-------------+
But it breaks consistency (due to missing foreign key between ip_config and config table). IPs may be deleted but there configurations will continue to linger.
How can the design be altered to accomodate my requirements?
Note: The type information (for each IP or configuration) should ideally be maintained separately because that is how a separate part of program expects it to be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能说我理解这里的一切,所以这个例子可能会给你一些想法。
从
ConfigurationType
开始,可以是1- OS; 2- 服务...
Configuration
表保存所有可能的(允许的)配置。对于每个ConfigurationTypeID
,ConfigurationTypeNo
都是一个整数 (1,2,3 ...) - 所以有 OS (1,2,3 ..);服务(1,2,3 ...)等。SystemConfiguration
捕获每个系统的配置设置历史记录。随着TimeChanged
成为 PK 的一部分,可以重复相同的配置。IP_Allocation
跟踪 IP 分配的历史记录。I can not say that I understand everything here, so this example may give you some ideas.
Start with
ConfigurationType
, this can be1- OS; 2- Service ...
The
Configuration
table holds all possible (permitted) configurations. TheConfigurationTypeNo
is an integer (1,2,3 ...) for eachConfigurationTypeID
-- so there is OS (1,2,3 ..); service (1,2,3 ...) etc.SystemConfiguration
captures history of configuration-setups for each system. WithTimeChanged
being a part of the PK, it is possible to have same configuration repeated.IP_Allocation
tracks history of IP assignments.