Initial commit for projmon branch
This commit is contained in:
64
projmon/projmon.py
Normal file
64
projmon/projmon.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
import json
|
||||
import requests
|
||||
import xmltodict
|
||||
|
||||
from pyutils.utils import *
|
||||
from influxdb_client_3 import InfluxDBClient3, Point
|
||||
|
||||
# Get environment variables
|
||||
env = dict(os.environ)
|
||||
LOGGER: logging.Logger
|
||||
|
||||
##################
|
||||
###### MAIN ######
|
||||
##################
|
||||
def main() -> int:
|
||||
INTERVAL = int(env['INTERVAL'])
|
||||
try:
|
||||
# Init InfluxDB-v3 Client
|
||||
write_client = InfluxDBClient3(host=env['INFLUXDB_URL'],
|
||||
token=env['INFLUXDB_TOKEN'],
|
||||
database=env['INFLUXDB_DATABASE'])
|
||||
except Exception as e:
|
||||
LOGGER.error(e)
|
||||
return 1
|
||||
finally:
|
||||
LOGGER.info(f"InfluxDB Connected: [{env['INFLUXDB_URL']}/{env['INFLUXDB_DATABASE']}]")
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Logger Constants
|
||||
LOG_FORMAT = '%(asctime)s| %(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s'
|
||||
|
||||
# Enabling Logger
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
LOGGER.setLevel(logging.DEBUG)
|
||||
LOGGER.propagate = False
|
||||
formatter = logging.Formatter(LOG_FORMAT, None)
|
||||
levels = logging.getLevelNamesMapping()
|
||||
|
||||
# File logging
|
||||
log_name = os.path.abspath(env['LOG_FILE'])
|
||||
fh = logging.FileHandler(log_name)
|
||||
fh.setLevel(levels[env['LOG_FILE_LVL']])
|
||||
fh.setFormatter(formatter)
|
||||
LOGGER.addHandler(fh)
|
||||
|
||||
# Console logging
|
||||
cl = logging.StreamHandler(sys.stdout)
|
||||
cl.setLevel(levels[env['LOG_CLI_LVL']])
|
||||
cl.setFormatter(formatter)
|
||||
LOGGER.addHandler(cl)
|
||||
|
||||
LOGGER.warning(f"Routermon started on: {time.asctime()}")
|
||||
LOGGER.info(f"Routermon BUILD: {env.get("VER", "Test")}")
|
||||
|
||||
while main():
|
||||
LOGGER.error("Main thread exited unexpectedly")
|
||||
time.sleep(15)
|
||||
sys.exit(0)
|
||||
Reference in New Issue
Block a user