monitorconfig
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from config.database import get_connection, release_connection
|
||||
from modules.monitor_config.repository import insert_default_monitor_config_db
|
||||
|
||||
def _row_to_dict(row):
|
||||
"""
|
||||
@@ -136,6 +137,7 @@ def insert_device(data):
|
||||
"""
|
||||
Tạo mới một thiết bị và cấu hình mặc định (MonitorConfig & AlertConfig)
|
||||
trong cùng một database transaction.
|
||||
Trả về: tuple (device_dict, monitor_config_dict)
|
||||
"""
|
||||
conn = get_connection()
|
||||
cur = None
|
||||
@@ -163,19 +165,8 @@ def insert_device(data):
|
||||
device_row = cur.fetchone()
|
||||
device_id = device_row[0]
|
||||
|
||||
# 2. Thêm cấu hình giám sát mặc định (MonitorConfig) cho thiết bị vừa tạo
|
||||
# enable_ping mặc định bật True để thực hiện Ping giám sát
|
||||
cur.execute("""
|
||||
INSERT INTO monitor_config (device_id, enable_ping, ping_count, ping_timeout, ping_interval, enable_snmp)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)
|
||||
""", (
|
||||
device_id,
|
||||
True, # enable_ping
|
||||
3, # ping_count
|
||||
5, # ping_timeout (giây)
|
||||
60, # ping_interval (giây)
|
||||
False # enable_snmp
|
||||
))
|
||||
# 2. Thêm cấu hình giám sát mặc định (MonitorConfig) bằng repository chuyên biệt
|
||||
monitor_config = insert_default_monitor_config_db(device_id, cursor=cur)
|
||||
|
||||
# 3. Thêm cấu hình cảnh báo mặc định (AlertConfig) cho thiết bị vừa tạo
|
||||
cur.execute("""
|
||||
@@ -205,7 +196,7 @@ def insert_device(data):
|
||||
# Commit toàn bộ transaction
|
||||
conn.commit()
|
||||
|
||||
return _row_to_dict(full_row)
|
||||
return _row_to_dict(full_row), monitor_config
|
||||
|
||||
except Exception:
|
||||
conn.rollback()
|
||||
|
||||
Reference in New Issue
Block a user