icmp ping #1

Open
fil wants to merge 6 commits from dev into main
3 changed files with 11 additions and 24 deletions
Showing only changes of commit 5e479bba43 - Show all commits

View file

@ -6,23 +6,12 @@ with open("config.yaml") as f:
cfg = yaml.load(f, Loader=yaml.FullLoader)
class Config:
config_data: dict
__instance = None
def __getitem__(self, name):
if name in self.config_data:
return self.config_data[name]
return None
def __new__(cls):
if cls.__instance is None:
cls.__instance = super().__new__(cls)
cls.__instance.__init()
return cls.__instance
def __init(self):
def __init__(self):
load_dotenv()
self.config_data = cfg
for key in cfg.keys():
if key in os.environ:
self.config_data[key] = os.environ[key]
setattr(self, key, self.config_data[key])
CONFIG = Config()

View file

@ -1,18 +1,17 @@
from config import Config
from config import CONFIG
import psycopg2.extras
import psycopg2
class Database():
def __init__(self):
self.config = Config()
self.connect()
def connect(self):
self.conn = psycopg2.connect(
host=self.config["db_host"],
database=self.config["db_database"],
user=self.config["db_user"],
password=self.config["db_password"]
host=CONFIG.db_host,
database=CONFIG.db_database,
user=CONFIG.db_user,
password=CONFIG.db_password
)
self.cur = self.conn.cursor(
cursor_factory=psycopg2.extras.RealDictCursor)

View file

@ -1,12 +1,11 @@
from database import Database
from pythonping import ping
from tcppinglib import tcpping
from config import Config
from config import CONFIG
class PingPong:
def __init__(self):
self.db = Database()
self.config = Config()
def icmp_ping(self, service):
r = {}
@ -29,7 +28,7 @@ class PingPong:
def start(self):
latency = {
"location": self.config["location"]
"location": CONFIG.location
}
for el in self.db.get_all_services():
state = self.db.create_state(el['id'])[0]