Added MySQL support and first code for testing the connection. (0.24.1)
This commit is contained in:
parent
52b0c6b509
commit
3042225ff9
6 changed files with 58 additions and 9 deletions
|
|
@ -19,7 +19,7 @@ from linspector.environment import Environment
|
||||||
from linspector.linspector import Linspector
|
from linspector.linspector import Linspector
|
||||||
from linspector.monitors import Monitors
|
from linspector.monitors import Monitors
|
||||||
|
|
||||||
__version__ = '0.24.0'
|
__version__ = '0.24.1'
|
||||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -105,7 +105,7 @@ def linspector():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if configuration.get_option('linspector', 'databases'):
|
if configuration.get_option('linspector', 'databases'):
|
||||||
log.info('Loading databases: ' + configuration.get_option('linspector', 'databases'))
|
log.info('loading databases: ' + configuration.get_option('linspector', 'databases'))
|
||||||
database_list = configuration.get_option('linspector', 'databases')
|
database_list = configuration.get_option('linspector', 'databases')
|
||||||
database_list = database_list.split(',')
|
database_list = database_list.split(',')
|
||||||
for database_name in database_list:
|
for database_name in database_list:
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ logfile_level = DEBUG
|
||||||
; size of logfiles (default: 1MB)
|
; size of logfiles (default: 1MB)
|
||||||
logfile_size = 10MB
|
logfile_size = 10MB
|
||||||
|
|
||||||
databases = mariadb
|
databases = mysql
|
||||||
|
|
||||||
notifications =
|
notifications =
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ See LICENSE (MIT license).
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, configuration, environment, log, **kwargs):
|
def __init__(self, configuration, environment, log):
|
||||||
self._args = {}
|
|
||||||
self._configuration = configuration
|
self._configuration = configuration
|
||||||
self._environment = environment
|
self._environment = environment
|
||||||
self._log = log
|
self._log = log
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,16 @@ from linspector.database import Database
|
||||||
|
|
||||||
|
|
||||||
def create(configuration, environment, log):
|
def create(configuration, environment, log):
|
||||||
return MariaDBDatabase(configuration, environment, log)
|
return DummyDBDatabase(configuration, environment, log)
|
||||||
|
|
||||||
|
|
||||||
class MariaDBDatabase(Database):
|
class DummyDBDatabase(Database):
|
||||||
|
"""
|
||||||
|
This is a dummy database
|
||||||
|
"""
|
||||||
|
|
||||||
def execute(self):
|
def connect(self):
|
||||||
self._log.debug("Hello from MariaDB Database...")
|
pass
|
||||||
|
|
||||||
|
def insert(self):
|
||||||
|
pass
|
||||||
41
linspector/databases/mysql.py
Normal file
41
linspector/databases/mysql.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
"""
|
||||||
|
This file is part of Linspector (https://linspector.org/)
|
||||||
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
|
See LICENSE (MIT license).
|
||||||
|
"""
|
||||||
|
#from mysql.connector import connect, Error
|
||||||
|
import pymysql.cursors
|
||||||
|
|
||||||
|
from linspector.database import Database
|
||||||
|
|
||||||
|
|
||||||
|
def create(configuration, environment, log):
|
||||||
|
return MySQLDatabase(configuration, environment, log)
|
||||||
|
|
||||||
|
|
||||||
|
class MySQLDatabase(Database):
|
||||||
|
|
||||||
|
def __init__(self, configuration, environment, log):
|
||||||
|
super().__init__(configuration, environment, log)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._connection = pymysql.connect(host='127.0.0.1',
|
||||||
|
user='linspector',
|
||||||
|
password='password',
|
||||||
|
database='linspector',
|
||||||
|
cursorclass=pymysql.cursors.DictCursor)
|
||||||
|
log.debug(self._connection)
|
||||||
|
except Exception as err:
|
||||||
|
log.warning('database connection failed: {0}'.format(err))
|
||||||
|
|
||||||
|
try:
|
||||||
|
with self._connection.cursor() as cursor:
|
||||||
|
sql = 'SELECT CURDATE()'
|
||||||
|
cursor.execute(sql)
|
||||||
|
result = cursor.fetchone()
|
||||||
|
log.info(result)
|
||||||
|
except Exception as err:
|
||||||
|
log.warning('database query failed: {0}'.format(err))
|
||||||
|
|
||||||
|
def insert(self):
|
||||||
|
pass
|
||||||
|
|
@ -4,13 +4,16 @@ asyncssh==2.13.2
|
||||||
fastapi==0.101.1
|
fastapi==0.101.1
|
||||||
fritzconnection==1.13.1
|
fritzconnection==1.13.1
|
||||||
loguru==0.7.0
|
loguru==0.7.0
|
||||||
|
mysql-connector-python==8.1.0
|
||||||
paramiko==3.3.1
|
paramiko==3.3.1
|
||||||
pydantic==2.2.1
|
pydantic==2.2.1
|
||||||
|
pymysql==1.1.0
|
||||||
pysnmp==4.4.12
|
pysnmp==4.4.12
|
||||||
python-gammu==3.2.4
|
python-gammu==3.2.4
|
||||||
pytz==2023.3
|
pytz==2023.3
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
rich==13.5.2
|
rich==13.5.2
|
||||||
|
SQLAlchemy==2.0.20
|
||||||
syslog2==0.5.0
|
syslog2==0.5.0
|
||||||
textual==0.33.0
|
textual==0.33.0
|
||||||
typer==0.9.0
|
typer==0.9.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue