switched from sqlite to mysql. support for sqlite will coma back at some time. removed local installed submodule libraries. need to be installed on the system using pip or package manager

This commit is contained in:
Johannes Findeisen 2020-09-10 21:39:26 +02:00
commit 80a54d0254
7 changed files with 58 additions and 28 deletions

6
.gitmodules vendored
View file

@ -1,6 +0,0 @@
[submodule "fritzconnection"]
path = fritzconnection
url = https://github.com/kbr/fritzconnection.git
[submodule "peewee"]
path = peewee
url = https://github.com/coleifer/peewee.git

View file

@ -10,20 +10,16 @@ TODO: Write feature list
## Requirements
- Git (only for installing from Git repository)
- Python >= 3.8
- fritzconnection >= 1.3.4
- https://pypi.org/project/fritzconnection/
- peewee >= 3.13.3
- https://pypi.org/project/peewee/
- Git (Just to install the way I do. You can also install downloading a .zip file and install libraries by yourself... not what I like, so I actually will not take care of this.)
3rd party libraries are included as Git submodule. See installation instructions below. Actually I use the current repository code. This will change but for development this is the easiest solution. I will switch to stable releases some day.
- pymysql >= 0.10.1
Just install the 3rdf party dependencies using `pip install $PACKAGE`
## Installation
git clone https://git.unixpeople.org/hanez/uplink.git
cd uplink
git submodule update --init --recursive
cp config.example.json config.json
### Configuration
@ -42,9 +38,14 @@ Edit config.json to your needs.
#### Example
{
"interval": 60,
"database": "./uplink.sqlite3",
"cron_mode": false,
"interval": 60,
"database_type": "mysql",
"database": "uplink",
"database_host": "127.0.0.1",
"database_user": "USER",
"database_password": "PASSWORD",
"cron": false,
"daemon": false,
"uplinks": [
{ "provider": "Cable Provider", "ip": "192.168.0.1", "password": "1234" },
{ "provider": "DSL Provider", "ip": "192.168.1.1", "password": "1234" }

@ -1 +0,0 @@
Subproject commit f2ed0baaaf57e4f0134c81ba4a7b0fcd8e8e9e53

1
peewee

@ -1 +0,0 @@
Subproject commit ce9375cb4b3fa64560e400932d86e2632c4a0586

34
uplink
View file

@ -27,12 +27,12 @@ import logging
import logging.handlers
import os
import os.path as path
import sqlite3
import pymysql
#import sqlite3
import sys
import time
from fritzconnection.fritzconnection.lib.fritzstatus import FritzStatus
from peewee import peewee
from fritzconnection.lib.fritzstatus import FritzStatus
__version__ = "0.1"
@ -103,8 +103,15 @@ def parse_args():
def get_data(config):
conn = sqlite3.connect(config["database"])
c = conn.cursor()
#conn = sqlite3.connect(config["database"])
#c = conn.cursor()
con = pymysql.connect(config["database_host"],
config["database_user"],
config["database_password"],
config["database"])
for i in range(len(config["uplinks"])):
timestamp = calendar.timegm(time.gmtime())
local_time = time.localtime(timestamp)
@ -119,8 +126,11 @@ def get_data(config):
'VALUES (\"' + str(timestamp) + '\",\"' + str(d) + '\",\"' + str(t) + '\",\"' + \
str(config["uplinks"][i]["ip"]) + '\",\"' + "0" + '\",\"' + "0" + '\",\"ERROR: ' + str(err) + '\")'
logging.debug(sql)
c.execute(sql)
conn.commit()
#c.execute(sql)
#conn.commit()
with con.cursor() as cur:
cur.execute(sql)
con.commit()
break
if fc.is_connected:
@ -141,9 +151,13 @@ def get_data(config):
str(fc.str_max_linked_bit_rate[1]) + '\",\"' + str(fc.modelname) + '\",\"' + \
str(fc.fc.system_version) + '\",\"' + status + '\")'
logging.debug(sql)
c.execute(sql)
conn.commit()
conn.close()
#c.execute(sql)
#conn.commit()
with con.cursor() as cur:
cur.execute(sql)
con.commit()
#conn.close()
con.close()
def run(config):

23
uplink.mysql.sql Normal file
View file

@ -0,0 +1,23 @@
CREATE TABLE `log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` int(11) NOT NULL,
`date` date DEFAULT NULL,
`time` time DEFAULT NULL,
`uptime` int(11) DEFAULT NULL,
`internal_ip` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL,
`external_ip` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`external_ipv6` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`is_linked` tinyint(1) DEFAULT NULL,
`is_connected` tinyint(1) DEFAULT NULL,
`str_transmission_rate_up` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`str_transmission_rate_down` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`str_max_bit_rate_up` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`str_max_bit_rate_down` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`str_max_linked_bit_rate_up` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`str_max_linked_bit_rate_down` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`modelname` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`system_version` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`message` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;