WIP: add: base files #1

Draft
fil wants to merge 3 commits from developing into main
3 changed files with 16 additions and 3 deletions
Showing only changes of commit 703c57333e - Show all commits

View file

@ -7,14 +7,20 @@ import os
class Database():
def __init__(self):
self.config = Config()
self.conn = psycopg2.connect(
self.conn = self.conenct()
self.cur = self.conn.cursor(
cursor_factory=psycopg2.extras.RealDictCursor)
def conenct(self):
return psycopg2.connect(
host=self.config["DB_HOST"],
database=self.config["DB_DATABASE"],
user=self.config["DB_USER"],
password=self.config["DB_PASSWORD"]
)
self.cur = self.conn.cursor(
cursor_factory=psycopg2.extras.RealDictCursor)
def check_connection(self):
return self.conn.closed
def get_vm(self, id):
self.cur.execute("SELECT * FROM vm WHERE id = %s;", (str(id),))

View file

@ -165,6 +165,9 @@ class Uptime():
self.__disconnect()
def start(self):
if (self.db.check_connection()):
logger.info("Connecting to Database")
self.db.connect()
self.update_time = str(datetime.now(pytz.UTC).timestamp())
logger.info(f"Update time is {datetime.now(pytz.UTC)} \
({self.update_time})")
@ -194,6 +197,9 @@ class Uptime():
logger.info("Purge completed")
def calculate_sla(self):
if (self.db.check_connection()):
logger.info("Connecting to Database")
self.db.connect()
hits, failures, total = 0, 0, 0
logger.info("Calculating SLA (hits/failures)")
for vm in self.db.get_all_vm():

View file

@ -3,6 +3,7 @@ from apscheduler.triggers.cron import CronTrigger
from config import Config
from Uptime import Uptime
if __name__ == "__main__":
uptime = Uptime()
scheduelr = BlockingScheduler()