WIP: add: base files #1
2 changed files with 9 additions and 14 deletions
13
Database.py
13
Database.py
|
|
@ -7,20 +7,17 @@ import os
|
||||||
class Database():
|
class Database():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = Config()
|
self.config = Config()
|
||||||
self.conn = self.conenct()
|
self.connect()
|
||||||
self.cur = self.conn.cursor(
|
|
||||||
cursor_factory=psycopg2.extras.RealDictCursor)
|
|
||||||
|
|
||||||
def conenct(self):
|
def connect(self):
|
||||||
return psycopg2.connect(
|
self.conn = psycopg2.connect(
|
||||||
host=self.config["DB_HOST"],
|
host=self.config["DB_HOST"],
|
||||||
database=self.config["DB_DATABASE"],
|
database=self.config["DB_DATABASE"],
|
||||||
user=self.config["DB_USER"],
|
user=self.config["DB_USER"],
|
||||||
password=self.config["DB_PASSWORD"]
|
password=self.config["DB_PASSWORD"]
|
||||||
)
|
)
|
||||||
|
self.cur = self.conn.cursor(
|
||||||
def check_connection(self):
|
cursor_factory=psycopg2.extras.RealDictCursor)
|
||||||
return self.conn.closed
|
|
||||||
|
|
||||||
def get_vm(self, id):
|
def get_vm(self, id):
|
||||||
self.cur.execute("SELECT * FROM vm WHERE id = %s;", (str(id),))
|
self.cur.execute("SELECT * FROM vm WHERE id = %s;", (str(id),))
|
||||||
|
|
|
||||||
10
Uptime.py
10
Uptime.py
|
|
@ -165,9 +165,8 @@ class Uptime():
|
||||||
self.__disconnect()
|
self.__disconnect()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if (self.db.check_connection()):
|
logger.info("Connecting to Database")
|
||||||
logger.info("Connecting to Database")
|
self.db.connect()
|
||||||
self.db.connect()
|
|
||||||
self.update_time = str(datetime.now(pytz.UTC).timestamp())
|
self.update_time = str(datetime.now(pytz.UTC).timestamp())
|
||||||
logger.info(f"Update time is {datetime.now(pytz.UTC)} \
|
logger.info(f"Update time is {datetime.now(pytz.UTC)} \
|
||||||
({self.update_time})")
|
({self.update_time})")
|
||||||
|
|
@ -197,9 +196,8 @@ class Uptime():
|
||||||
logger.info("Purge completed")
|
logger.info("Purge completed")
|
||||||
|
|
||||||
def calculate_sla(self):
|
def calculate_sla(self):
|
||||||
if (self.db.check_connection()):
|
logger.info("Connecting to Database")
|
||||||
logger.info("Connecting to Database")
|
self.db.connect()
|
||||||
self.db.connect()
|
|
||||||
hits, failures, total = 0, 0, 0
|
hits, failures, total = 0, 0, 0
|
||||||
logger.info("Calculating SLA (hits/failures)")
|
logger.info("Calculating SLA (hits/failures)")
|
||||||
for vm in self.db.get_all_vm():
|
for vm in self.db.get_all_vm():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue