c.execute("SELECT kpi_id FROM kpi WHERE device_id is ? AND kpi_sample_type is ? AND endpoint_id is ? AND service_id is ?",(device_id,kpi_sample_type,endpoint_id,service_id))
c.execute("SELECT kpi_id FROM kpi WHERE device_id is ? AND kpi_sample_type is ? AND endpoint_id is ? AND service_id is ? AND slice_id is ? AND connection_id is ?",(device_id,kpi_sample_type,endpoint_id,service_id,slice_id,connection_id))
data=c.fetchone()
data=c.fetchone()
ifdataisNone:
ifdataisNone:
c.execute("INSERT INTO kpi (kpi_description,kpi_sample_type,device_id,endpoint_id,service_id) VALUES (?,?,?,?,?)",(kpi_description,kpi_sample_type,device_id,endpoint_id,service_id))
c.execute("INSERT INTO kpi (kpi_description,kpi_sample_type,device_id,endpoint_id,service_id,slice_id,connection_id) VALUES (?,?,?,?,?,?,?)",(kpi_description,kpi_sample_type,device_id,endpoint_id,service_id,slice_id,connection_id))
self.client.commit()
self.client.commit()
kpi_id=c.lastrowid
kpi_id=c.lastrowid
LOGGER.debug(f"KPI {kpi_id} succesfully inserted in the ManagementDB")
LOGGER.debug(f"KPI {kpi_id} succesfully inserted in the ManagementDB")
@@ -246,3 +249,40 @@ class ManagementDB():
returndata
returndata
exceptsqlite3.Errorase:
exceptsqlite3.Errorase:
LOGGER.debug(f"Alarms cannot be retrieved from the ManagementDB: {e}")
LOGGER.debug(f"Alarms cannot be retrieved from the ManagementDB: {e}")
defcheck_monitoring_flag(self,kpi_id):
try:
c=self.client.cursor()
c.execute("SELECT monitor_flag FROM kpi WHERE kpi_id is ?",(kpi_id,))
data=c.fetchone()
ifdataisNone:
LOGGER.debug(f"KPI {kpi_id} does not exists")
returnNone
else:
ifdata[0]==1:
returnTrue
elifdata[0]==0:
returnFalse
else:
LOGGER.debug(f"KPI {kpi_id} is wrong")
returnNone
exceptsqlite3.Errorase:
LOGGER.debug(f"KPI {kpi_id} cannot be checked from the ManagementDB: {e}")
defset_monitoring_flag(self,kpi_id,flag):
try:
c=self.client.cursor()
data=c.execute("SELECT * FROM kpi WHERE kpi_id is ?",(kpi_id,)).fetchone()
ifdataisNone:
LOGGER.debug(f"KPI {kpi_id} does not exists")
returnNone
else:
ifflag:
value=1
else:
value=0
c.execute("UPDATE kpi SET monitor_flag = ? WHERE kpi_id is ?",(value,kpi_id))
returnTrue
exceptsqlite3.Errorase:
LOGGER.debug(f"KPI {kpi_id} cannot be checked from the ManagementDB: {e}")