model.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from sqlalchemy import Column, String, Integer, Boolean, Text, DateTime, Float
  2. from sqlalchemy.ext.declarative import declarative_base
  3. Base = declarative_base()
  4. class Event(Base):
  5. __tablename__ = 'events'
  6. id = Column(Integer, primary_key=True, autoincrement=True) # 主键
  7. name = Column(String, nullable=False)
  8. time = Column(Integer, nullable=False)
  9. level = Column(String, nullable=True)
  10. res_name = Column(String, nullable=True)
  11. view_type = Column(String, nullable=True)
  12. event_state = Column(String, nullable=True)
  13. event_type = Column(String, nullable=True)
  14. res_temp_id = Column(String, nullable=True)
  15. event_id = Column(String, unique=True, nullable=False)
  16. res_type = Column(String, nullable=True)
  17. ip = Column(String, nullable=True)
  18. policy_id = Column(String, nullable=True)
  19. metric_id = Column(String, nullable=True)
  20. metric_name = Column(String, nullable=True)
  21. res_id = Column(String, nullable=True)
  22. collect_type = Column(String, nullable=True)
  23. is_app = Column(String, nullable=True)
  24. create_time = Column(String, nullable=True)
  25. sub_res_id = Column(String, nullable=True)
  26. recovered = Column(String, nullable=True)
  27. show_accept = Column(Boolean, nullable=False, default=False)
  28. show_maintain = Column(Boolean, nullable=False, default=False)
  29. recovered_event_id = Column(String, nullable=True)
  30. def __repr__(self):
  31. return f"<Event(name='{self.name}', event_id='{self.event_id}')>"
  32. class LogEvent(Base):
  33. __tablename__ = 'log_events'
  34. id = Column(String, primary_key=True, nullable=False)
  35. log_type = Column(String, nullable=True)
  36. alarm_level = Column(String, nullable=True)
  37. receiver = Column(String, nullable=True)
  38. resource_name = Column(String, nullable=True)
  39. send_type = Column(String, nullable=True)
  40. send_time = Column(String, nullable=True)
  41. alarm_content = Column(Text, nullable=True)
  42. send_result = Column(String, nullable=True)
  43. alarms_id = Column(String, nullable=True)
  44. log_host = Column(String, nullable=True)
  45. name = Column(String, nullable=True)
  46. company_id = Column(String, nullable=True)
  47. tag1 = Column(String, nullable=True)
  48. tag2 = Column(String, nullable=True)
  49. tag3 = Column(String, nullable=True)
  50. tag4 = Column(String, nullable=True)
  51. class Resource(Base):
  52. __tablename__ = 'resources'
  53. res_id = Column(String, primary_key=True, nullable=False) # 主键字段
  54. state = Column(String, nullable=True) # 状态
  55. name = Column(String, nullable=True) # 名称
  56. location = Column(String, nullable=True) # 位置
  57. type = Column(String, nullable=True) # 类型
  58. desc = Column(String, nullable=True) # 描述
  59. policy_name = Column(String, nullable=True) # 策略名称
  60. usability = Column(String, nullable=True) # 可用性
  61. sysoid = Column(String, nullable=True) # 系统 OID
  62. vender_name = Column(String, nullable=True) # 厂商名称
  63. name_display = Column(String, nullable=True) # 显示名称
  64. contact = Column(String, nullable=True) # 联系方式
  65. model_number = Column(String, nullable=True) # 型号
  66. ip = Column(String, nullable=True) # IP 地址
  67. tree_node_id = Column(String, nullable=True) # 树节点 ID
  68. res_type_id = Column(String, nullable=True) # 资源类型 ID
  69. series = Column(String, nullable=True) # 系列
  70. mac = Column(String, nullable=True) # MAC 地址
  71. location_name = Column(String, nullable=True) # 位置名称
  72. contact_name = Column(String, nullable=True) # 联系人名称
  73. mem_rate = Column(String, nullable=True) # 内存使用率
  74. cpu_rate = Column(String, nullable=True) # CPU 使用率
  75. busy = Column(String, nullable=True) # 繁忙状态
  76. sys_info = Column(String, nullable=True) # 系统信息
  77. vender_id = Column(String, nullable=True) # 厂商 ID
  78. class Location(Base):
  79. __tablename__ = 'locations'
  80. id = Column(String, primary_key=True, nullable=False) # 主键,网段 ID
  81. name = Column(String, nullable=True) # 名称
  82. parent_id = Column(String, nullable=True) # 父节点 ID
  83. full_path_name = Column(String, nullable=True) # 完整路径名称
  84. class Segment(Base):
  85. __tablename__ = 'segments'
  86. id = Column(String, primary_key=True, nullable=False) # 主键,子网 ID
  87. name = Column(String, nullable=True) # 名称
  88. ip_subnet = Column(String, nullable=True) # 子网地址
  89. vlan_id = Column(Integer, nullable=True) # VLAN ID
  90. vlan_name = Column(String, nullable=True) # VLAN 名称
  91. location_id = Column(String, nullable=True) # 网段 ID,关联Location.id
  92. location_full_path = Column(String, nullable=True) # 网段完整路径
  93. location_name = Column(String, nullable=True) # 网段名称
  94. class Room(Base):
  95. __tablename__ = 'rooms'
  96. id = Column(String, primary_key=True, nullable=False) # 主键,机房 ID
  97. display_name = Column(String, nullable=True) # 机房显示名称
  98. level = Column(String, nullable=True) # 机房等级
  99. rack_count = Column(Integer, nullable=True) # 机柜数量
  100. res_count = Column(Integer, nullable=True) # 资源数量
  101. capacity = Column(Integer, nullable=True) # 总容量
  102. used_capacity = Column(Integer, nullable=True) # 已用容量
  103. used_capacity_rate = Column(Float, nullable=True) # 容量使用率
  104. area = Column(Integer, nullable=True) # 面积
  105. class Element(Base):
  106. __tablename__ = 'elements'
  107. id = Column(String, primary_key=True, autoincrement=True) # 自动生成主键
  108. value = Column(String, nullable=True) # 元素值
  109. time = Column(DateTime, nullable=True) # 时间
  110. room_id = Column(String, nullable=False) # 机房 ID,外键关联
  111. is_cross = Column(String, nullable=True) # 是否跨域
  112. element_name = Column(String, nullable=True) # 元素名称
  113. metric_id = Column(String, nullable=True) # 指标 ID
  114. metric_name = Column(String, nullable=True) # 指标名称
  115. unit = Column(String, nullable=True) # 单位
  116. metric_definition_id = Column(String, nullable=True) # 指标定义 ID
  117. element_definition_name = Column(String, nullable=True) # 元素定义名称
  118. element_display_name = Column(String, nullable=True) # 元素显示名称
  119. metric_definition_name = Column(String, nullable=True) # 指标定义名称
  120. data_type = Column(String, nullable=True) # 数据类型
  121. element_definition_id = Column(String, nullable=True) # 元素定义 ID