Framework in place but lots more to do for this issue.
This commit is contained in:
parent
80ccfb8828
commit
4e959749fc
2 changed files with 65 additions and 2 deletions
13
main.py
13
main.py
|
@ -37,6 +37,11 @@ from bs4 import BeautifulSoup
|
||||||
from log import logsManager
|
from log import logsManager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
if config.loggingMode == 'rabbitmq':
|
||||||
|
|
||||||
|
import rabbitmq
|
||||||
|
rabbitmq = rabbitmq.rabbitMQClient('sampleca.crt','sample.crt','sample.key','','5671','monutil')
|
||||||
|
|
||||||
stop_event = threading.Event()
|
stop_event = threading.Event()
|
||||||
nonPOSIXCPULoads = []
|
nonPOSIXCPULoads = []
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
@ -173,14 +178,18 @@ def monitorUrls(stop_event):
|
||||||
|
|
||||||
def logHostLog(hostname, logTime, cpu, memory):
|
def logHostLog(hostname, logTime, cpu, memory):
|
||||||
|
|
||||||
if not config.loggingMode == 'none':
|
if not config.loggingMode == 'none' and not config.loggingMode == 'rabbitmq':
|
||||||
|
|
||||||
manager = logsManager(config.sqlServer, config.sqlDatabase, config.sqlUsername, config.sqlPassword)
|
manager = logsManager(config.sqlServer, config.sqlDatabase, config.sqlUsername, config.sqlPassword)
|
||||||
manager.insertHostLog(hostname, socket.gethostbyname(socket.gethostname()), logTime, cpu, memory)
|
manager.insertHostLog(hostname, socket.gethostbyname(socket.gethostname()), logTime, cpu, memory)
|
||||||
|
|
||||||
|
if config.loggingMode == 'rabbitmq':
|
||||||
|
|
||||||
|
rabbitmq.publish(hostname + '|' + str(logTime) + '|' + 'cpumem' + '|' + str(cpu) + '|' + str(memory))
|
||||||
|
|
||||||
def logURLLog(hostname, logTime, url, responseTime):
|
def logURLLog(hostname, logTime, url, responseTime):
|
||||||
|
|
||||||
if not config.loggingMode == 'none':
|
if not config.loggingMode == 'none' and not config.loggingMode == 'rabbitmq':
|
||||||
|
|
||||||
manager = logsManager(config.sqlServer, config.sqlDatabase, config.sqlUsername, config.sqlPassword)
|
manager = logsManager(config.sqlServer, config.sqlDatabase, config.sqlUsername, config.sqlPassword)
|
||||||
manager.insertURLLog(hostname, socket.gethostbyname(socket.gethostname()), logTime, url, responseTime)
|
manager.insertURLLog(hostname, socket.gethostbyname(socket.gethostname()), logTime, url, responseTime)
|
||||||
|
|
54
rabbitmq.py
Normal file
54
rabbitmq.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
# Copyright (c) 2024 Thomas Williams - https://git.server.wales/thomas
|
||||||
|
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
# The above copyright notice and this permission notice shall be included in all
|
||||||
|
# copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
# SOFTWARE.
|
||||||
|
|
||||||
|
import pika
|
||||||
|
import ssl
|
||||||
|
|
||||||
|
class rabbitMQClient:
|
||||||
|
|
||||||
|
def __init__(self, ca, cacert, cakey, rabbitmqHost, rabbitmqPort, routingKey):
|
||||||
|
|
||||||
|
self.ca = ca
|
||||||
|
self.cacert = cacert
|
||||||
|
self.cakey = cakey
|
||||||
|
self.rabbitmqHost = rabbitmqHost
|
||||||
|
self.rabbitmqPort = rabbitmqPort
|
||||||
|
self.routingKey = routingKey
|
||||||
|
|
||||||
|
def publish(self, message):
|
||||||
|
|
||||||
|
context = ssl.create_default_context(
|
||||||
|
cafile=self.ca)
|
||||||
|
context.verify_mode = ssl.CERT_REQUIRED
|
||||||
|
context.load_cert_chain(self.cacert, self.cakey)
|
||||||
|
|
||||||
|
sslOptions = pika.SSLOptions(context, self.rabbitmqHost)
|
||||||
|
|
||||||
|
connParams = pika.ConnectionParameters(host=self.rabbitmqHost,port=self.rabbitmqPort, ssl_options=sslOptions, credentials=pika.credentials.ExternalCredentials())
|
||||||
|
|
||||||
|
with pika.BlockingConnection(connParams) as conn:
|
||||||
|
|
||||||
|
ch = conn.channel()
|
||||||
|
|
||||||
|
ch.basic_publish(exchange='', routing_key=self.routingKey, body=message, properties=pika.BasicProperties(delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE))
|
Loading…
Reference in a new issue