icmp ping #1

Open
fil wants to merge 6 commits from dev into main
4 changed files with 15 additions and 16 deletions
Showing only changes of commit 4f4a0ed627 - Show all commits

View file

@ -1,14 +1,9 @@
import os import os
import yaml
from dotenv import load_dotenv from dotenv import load_dotenv
defConfig = { with open("config.yaml") as f:
"DB_HOST": "", cfg = yaml.load(f, Loader=yaml.FullLoader)
"DB_DATABASE": "",
"DB_USER": "",
"DB_PASSWORD": "",
"LOCATION":""
}
class Config: class Config:
config_data: dict config_data: dict
@ -27,7 +22,7 @@ class Config:
def __init(self): def __init(self):
load_dotenv() load_dotenv()
self.config_data = defConfig self.config_data = cfg
for key in defConfig.keys(): for key in cfg.keys():
if key in os.environ: if key in os.environ:
self.config_data[key] = os.environ[key] self.config_data[key] = os.environ[key]

5
config.yaml Normal file
View file

@ -0,0 +1,5 @@
db_host: ""
db_database: ""
db_user: ""
db_password: ""
location: ""

View file

@ -2,7 +2,6 @@ from config import Config
import psycopg2.extras import psycopg2.extras
import psycopg2 import psycopg2
class Database(): class Database():
def __init__(self): def __init__(self):
self.config = Config() self.config = Config()
@ -10,10 +9,10 @@ class Database():
def connect(self): def connect(self):
self.conn = 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( self.cur = self.conn.cursor(
cursor_factory=psycopg2.extras.RealDictCursor) cursor_factory=psycopg2.extras.RealDictCursor)

View file

@ -29,7 +29,7 @@ class PingPong:
def start(self): def start(self):
latency = { latency = {
"location": self.config["LOCATION"] "location": self.config["location"]
} }
for el in self.db.get_all_services(): for el in self.db.get_all_services():
state = self.db.create_state(el['id'])[0] state = self.db.create_state(el['id'])[0]