Skip to content

Commit

Permalink
Add platform switcher and request conf sections
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCoderCarl committed Apr 26, 2024
1 parent b59c856 commit a0e9b41
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ services:
SETTINGS_FILE_FOR_DYNACONF: "/opt/settings.toml"
VERBOSE: "True"
ALERTING: "True"
PLATFORM: "True"
ENVIRONMENT: "Dev"
# CHANEL: "TODO"
networks:
5 changes: 4 additions & 1 deletion settings.toml
Original file line number Diff line number Diff line change
@@ -19,4 +19,7 @@ HOSTS = [

[TELEGRAM]
API_TOKEN = "12334567890qwertyuiop"
CHAT_ID = "1234567"
CHAT_ID = "1234567"

[REQUEST]
TIMEOUT = 5
20 changes: 14 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from platform import processor, uname # TODO add platform env var
from platform import processor, uname
from time import sleep

import requests
@@ -31,6 +31,13 @@
except KeyError as key_err:
logging.warning(f"Key Error - {key_err}")

try:
PLATFORM = bool(os.getenv("PLATFORM"))
if PLATFORM:
logger.info(f"Platform info activated !")
except KeyError as key_err:
logging.warning(f"Key Error - {key_err}")

try:
ENVIRONMENT = os.getenv("ENVIRONMENT")
if ENVIRONMENT:
@@ -97,7 +104,7 @@ def http_requests(hosts: list):
for host in hosts:
try:
logging.info(f"Going to request {host}")
response = requests.get(f"http://{host}", timeout=5)
response = requests.get(f"http://{host}", timeout=dynaconfig.settings["REQUEST"]["TIMEOUT"])
if VERBOSE:
logging.info(response.text) # TODO parse json
logging.info(response.headers)
@@ -131,9 +138,10 @@ def http_requests(hosts: list):
icmp_requests(icmp_hosts)
http_requests(http_hosts)
sleep(1)
if PLATFORM:
logger.info(f"Processor: {processor()}")
sleep(1)
logger.info(f"Uname: {uname()}")
sleep(1)
except ValueError as val_err:
logging.warning(f"Config was not loaded - Value Error - {val_err}")
# logger.info(f"Processor: {processor()}")
# sleep(1)
# logger.info(f"Uname: {uname()}")
# sleep(1)

0 comments on commit a0e9b41

Please sign in to comment.