-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
196 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import retriever | ||
|
||
__version__ = '0.0.28' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import configparser | ||
import threading | ||
from influxdb_client import InfluxDBClient | ||
import logging | ||
import logging_loki | ||
from requests.packages import urllib3 | ||
import schedule | ||
import time | ||
from docsismodem.modems.netgear_cm2000 import NetgearCM2000 | ||
from docsismodem.modems.technicolor_xb7 import TechnicolorXB7 | ||
from docsismodem.modems.motorola_mb8600 import MotorolaMB8600 | ||
from docsismodem.modems.touchstone_tg3492_upc_ch import TouchstoneTG3492UPCCH | ||
|
||
from flask import Flask | ||
from flask_healthz import healthz | ||
|
||
from docsismodem.probe import Probe | ||
from docsismodem.collectionJob import collectionJob | ||
|
||
def main(): | ||
consoleLogger.info("Connecting to InfluxDB") | ||
|
||
handler = logging_loki.LokiHandler( | ||
url=lokiUrl + "/loki/api/v1/push", | ||
tags={'application': "cablemodem-status-logs"}, | ||
auth=(lokiUsername, lokiPassword), | ||
version="1", | ||
) | ||
|
||
filter = CustomTimestampFilter() | ||
|
||
logger = logging.getLogger("modem") | ||
logger.addHandler(handler) | ||
logger.addFilter(filter) | ||
|
||
influxUrl = ("https" if influxUseTLS else "http") + "://" + influxHost + ":" + influxPort | ||
|
||
dbClient = InfluxDBClient(url=influxUrl, org=influxOrg, token=influxToken, ssl=influxUseTLS) | ||
|
||
modems = { | ||
"MotorolaMB8600": MotorolaMB8600(config, dbClient, consoleLogger), | ||
"NetgearCM2000": NetgearCM2000(config, dbClient, consoleLogger), | ||
"TechnicolorXB7": TechnicolorXB7(config, dbClient, consoleLogger), | ||
"TouchstoneTG3492UPCCH": TouchstoneTG3492UPCCH(config, dbClient, consoleLogger) | ||
} | ||
|
||
jobRunner = collectionJob(modems[config['General']['ModemType']], config['Modem'].getboolean('CollectLogs'), consoleLogger) | ||
|
||
# Because the modem uses a self-signed certificate and this is expected, disabling the warning to reduce noise. | ||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
|
||
def runDaemon(): | ||
jobRunner.collectionJob() | ||
consoleLogger.info("Running as daemon") | ||
schedule.every(runEveryMinutes).minutes.do(jobRunner.collectionJob) | ||
|
||
while 1: | ||
schedule.run_pending() | ||
time.sleep(1) | ||
|
||
if runAsDaemon: | ||
runnerThread = threading.Thread(target=runDaemon, daemon=True) | ||
runnerThread.start() | ||
create_flask_app(jobRunner) | ||
else: | ||
consoleLogger.info("One-time execution") | ||
jobRunner.collectionJob() | ||
|
||
|
||
|
||
def create_flask_app(runner): | ||
|
||
if enableHealthProbe is True: | ||
app = Flask(__name__) | ||
app.register_blueprint(healthz, url_prefix="/healthz") | ||
|
||
probe = Probe(runner, runEveryMinutes) | ||
|
||
app.config.update( | ||
HEALTHZ = { | ||
"live": probe.liveness, | ||
"ready": lambda: None, | ||
} | ||
) | ||
|
||
app.run(host='0.0.0.0', port=80, debug=False, use_reloader=False) | ||
|
||
class CustomTimestampFilter(logging.Filter): | ||
def filter(self, record): | ||
if hasattr(record, 'timestamp'): | ||
record.created = record.timestamp | ||
return True | ||
|
||
# Init logger | ||
logging.basicConfig(level=logging.INFO) | ||
consoleLogger = logging.getLogger("app") | ||
|
||
# Read configuration | ||
consoleLogger.info("Reading configuration") | ||
|
||
config = configparser.ConfigParser() | ||
config.read('data/configuration.ini') | ||
|
||
influxOrg = config['Database']['Org'] | ||
influxHost = config['Database']['Host'] | ||
influxPort = config['Database']['Port'] | ||
influxToken = config['Database']['Token'] | ||
influxUseTLS = bool(config['Database']['UseTls']) | ||
|
||
lokiUrl = config['Loki']['Url'] | ||
lokiUsername = config['Loki']['Username'] | ||
lokiPassword = config['Loki']['Password'] | ||
|
||
runAsDaemon = config['General'].getboolean('Daemon') | ||
enableHealthProbe = config['General'].getboolean('EnableK8sProbe') | ||
runEveryMinutes = int(config['General']['RunEveryMinutes']) | ||
|
||
lastUpdated = 0 | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.