diff --git a/config.py.sample b/config.py.sample new file mode 100644 index 0000000..312f5a7 --- /dev/null +++ b/config.py.sample @@ -0,0 +1,27 @@ +#!/usr/bin/python3 + +# See README before changing any of these options. + +hostMonitoringPeriod = 1 +urlMonitoringPeriod = 120 +urls = ["https://one.one.one.one"] +urlTimeout = 10 +maxWorkers = 4 +forceNonPOSIXCPU = True +loggingMode = '' +sqlServer = '' +sqlDatabase = '' +sqlUsername = '' +sqlPassword = '' +rabbitmqHost = '' +rabbitmqPort = 5671 +rabbitmqca = '' +rabbitmqcacert = '' +rabbitmqcakey = '' +rabbitmqRoutingKey = '' +logRetentionDays = 90 +maximumSQLAttempts = 3 +hostMonitorStartTime = "00:00:00" +hostMonitorEndTime = "23:59:59" +urlMonitorStartTime = "00:00:00" +urlMonitorEndTime = "23:59:59" diff --git a/main.py b/main.py index aaeceb0..15ce8f6 100755 --- a/main.py +++ b/main.py @@ -40,7 +40,7 @@ from datetime import datetime if config.loggingMode == 'rabbitmq': import rabbitmq - rabbitmq = rabbitmq.rabbitMQClient('sampleca.crt','sample.crt','sample.key','','5671','monutil') + rabbitmq = rabbitmq.rabbitMQClient(config.rabbitmqca,config.rabbitmqcacert,config.rabbitmqcakey,config.rabbitmqHost,config.rabbitmqPort,config.rabbitmqRoutingKey) stop_event = threading.Event() nonPOSIXCPULoads = [] @@ -93,7 +93,6 @@ def getNonPOSIXCPUAverage(): return avgLoad - def monitorHost(stop_event): nonPOSIXCPUStarted = False @@ -194,6 +193,10 @@ def logURLLog(hostname, logTime, url, responseTime): manager = logsManager(config.sqlServer, config.sqlDatabase, config.sqlUsername, config.sqlPassword) manager.insertURLLog(hostname, socket.gethostbyname(socket.gethostname()), logTime, url, responseTime) + if config.loggingMode == 'rabbitmq': + + rabbitmq.publish(hostname + '|' + str(logTime) + '|' + 'url' + '|' + url + '|' + str(responseTime)) + def main(): signal.signal(signal.SIGTERM, signal_handler) diff --git a/rabbitmq.py b/rabbitmq.py index a74cc2d..f8fe63a 100644 --- a/rabbitmq.py +++ b/rabbitmq.py @@ -24,6 +24,7 @@ import pika import ssl +import base64 class rabbitMQClient: @@ -38,6 +39,8 @@ class rabbitMQClient: def publish(self, message): + message = base64.b64encode(message.encode('utf-8')) + context = ssl.create_default_context( cafile=self.ca) context.verify_mode = ssl.CERT_REQUIRED