1
0
Fork 0

Added DMRIDs-loopup in logtailer.py

For those using DMRHost by BrandMeister or those having no ID-lookup enabled in MMDVMHost.
main
Kim - DG9VH 4 years ago
parent 38b391794e
commit 937be46503

@ -27,6 +27,7 @@ Actually known:
### Reommendations ### Reommendations
* take care to set Loglevel for FileLevel = 2 in your MMDVM.ini * take care to set Loglevel for FileLevel = 2 in your MMDVM.ini
* also set debug = 0 on each section to avoid irritating output on the Dashboard * also set debug = 0 on each section to avoid irritating output on the Dashboard
* Python3.7 at least must be instaled
### Installation steps ### Installation steps
* clone this repository to your home-directory with `git clone --recurse-submodules -j8 https://github.com/dg9vh/MMDVMHost-Websocketboard` to clone the repository with it's submodules * clone this repository to your home-directory with `git clone --recurse-submodules -j8 https://github.com/dg9vh/MMDVMHost-Websocketboard` to clone the repository with it's submodules
@ -46,6 +47,12 @@ Actually known:
Finally you should be able to get the new Dashboard calling the hostname of your hotspot and port 8000 (default) in your broser Finally you should be able to get the new Dashboard calling the hostname of your hotspot and port 8000 (default) in your broser
### If using DMRHost by BrandMeister-Team
If you are using the DMRHost as replacement for MMDVMHost you should enable DMR-ID-Lookup within logtailer.ini by setting the corresponding option = 1
Also take care to configure the filepath to the correct location of your DMRIds.dat.
For updating the DMRIds.dat you can use the script you find in scripts-folder.
## Credits ## Credits
*logtailer.py* is based on the work of http://shzhangji.com/blog/2017/07/15/log-tailer-with-websocket-and-python/ *logtailer.py* is based on the work of http://shzhangji.com/blog/2017/07/15/log-tailer-with-websocket-and-python/

@ -6,6 +6,8 @@ Port=5678
Logdir=/mnt/ramdisk/ Logdir=/mnt/ramdisk/
Prefix=MMDVM Prefix=MMDVM
Num_Lines=10000 Num_Lines=10000
DMR_ID_Lookup=0
DMR_ID_LookupFile=/etc/MMDVM/DMRIds.dat
[DAPNETGateway] [DAPNETGateway]
Logdir=/mnt/ramdisk/ Logdir=/mnt/ramdisk/

@ -18,7 +18,7 @@ current_dir = os.getcwd()
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(current_dir + '/logtailer.ini') config.read(current_dir + '/logtailer.ini')
dmrids = {}
# init # init
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
@ -27,6 +27,7 @@ conv = Ansi2HTMLConverter(inline=True)
@asyncio.coroutine @asyncio.coroutine
def view_log(websocket, path): def view_log(websocket, path):
global config global config
global dmrids
logging.info('Connected, remote={}, path={}'.format(websocket.remote_address, path)) logging.info('Connected, remote={}, path={}'.format(websocket.remote_address, path))
try: try:
@ -62,13 +63,23 @@ def view_log(websocket, path):
content = conv.convert(content, full=False) content = conv.convert(content, full=False)
lines = content.split("\n") lines = content.split("\n")
for line in lines: for line in lines:
if line.find("from ") > 0 and line.find("to ") > 0:
source = line[line.index("from ") + 5:line.index("to ")].strip()
if source in dmrids:
line = line.replace(source, dmrids[source])
yield from websocket.send(line) yield from websocket.send(line)
while True: while True:
content = f.read() content = f.read()
if content: if content:
content = conv.convert(content, full=False) content = conv.convert(content, full=False)
yield from websocket.send(content) lines = content.split("\n")
for line in lines:
if line.find("from ") > 0 and line.find("to ") > 0:
source = line[line.index("from ") + 5:line.index("to ")].strip()
if source in dmrids:
line = line.replace(source, dmrids[source])
yield from websocket.send(line)
else: else:
yield from asyncio.sleep(0.2) yield from asyncio.sleep(0.2)
@ -107,6 +118,19 @@ def websocketserver():
def main(): def main():
dmr_id_lookup = config['MMDVMHost']['DMR_ID_Lookup']
dmr_id_lookupfile = config['MMDVMHost']['DMR_ID_LookupFile']
if dmr_id_lookup == "1":
if not os.path.isfile(dmr_id_lookupfile):
raise ValueError('File not found', format(dmr_id_lookupfile))
f = open(dmr_id_lookupfile, 'r')
lines = f.readlines()
for line in lines:
tokens = line.split("\t")
dmrids[tokens[0]] = tokens[1]
logging.info("Starting Websocketserver")
websocketserver() websocketserver()

@ -0,0 +1,109 @@
#! /bin/bash
###############################################################################
#
# DMRIDUpdate.sh
#
# Copyright (C) 2016 by Tony Corbett G0WFV
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###############################################################################
#
# On a Linux based system, such as a Raspberry Pi, this script will perform all
# the steps required to maintain the DMRIds.dat (or similar) file for you.
#
# It is designed to run from crontab and will download the latest IDs from the
# master DMR-MARC ID database and optionally keep a backup of previously
# created files for you.
#
# It will also prune the number of backup files according to a value specified
# by you in the configuration below.
#
# When done, it will restart MMDVMHost to make the ID changes take effect.
#
# To install in root's crontab use the command ...
#
# sudo crontab -e
#
# ... and add the following line to the bottom of the file ...
#
# 0 0 * * * /path/to/script/DMRIDUpdate.sh 1>/dev/null 2>&1
#
# ... where /path/to/script/ should be replaced by the path to this script.
#
###############################################################################
#
# CONFIGURATION
#
# Full path to DMR ID file, without final slash
DMRIDPATH=/etc/MMDVM
DMRIDFILE=${DMRIDPATH}/DMRIds.dat
# DMR IDs now served by RadioID.net
DATABASEURL='https://ham-digital.org/status/users.csv'
#
# How many DMR ID files do you want backed up (0 = do not keep backups)
DMRFILEBACKUP=1
#
# Command line to restart MMDVMHost
RESTARTCOMMAND="systemctl status MMDVMHost.service"
# RESTARTCOMMAND="killall MMDVMHost ; /path/to/MMDVMHost/executable/MMDVMHost /path/to/MMDVM/ini/file/MMDVM.ini"
###############################################################################
#
# Do not edit below here
#
###############################################################################
# Check we are root
if [ "$(id -u)" != "0" ]
then
echo "This script must be run as root" 1>&2
exit 1
fi
# Create backup of old file
if [ ${DMRFILEBACKUP} -ne 0 ]
then
cp ${DMRIDFILE} ${DMRIDFILE}.$(date +%d%m%y)
fi
# Prune backups
BACKUPCOUNT=$(ls ${DMRIDFILE}.* | wc -l)
BACKUPSTODELETE=$(expr ${BACKUPCOUNT} - ${DMRFILEBACKUP})
if [ ${BACKUPCOUNT} -gt ${DMRFILEBACKUP} ]
then
for f in $(ls -tr ${DMRIDFILE}.* | head -${BACKUPSTODELETE})
do
rm $f
done
fi
# Generate new file
curl ${DATABASEURL} 2>/dev/null | sed -e 's/\t//g' | awk -F"," '/,/{gsub(/ /, "", $2); printf "%s\t%s\t%s\n", $1, $2, $3}' | sed -e 's/\(.\) .*/\1/g' > ${DMRIDPATH}/DMRIds.tmp
NUMOFLINES=$(wc -l ${DMRIDPATH}/DMRIds.tmp | awk '{print $1}')
if [ $NUMOFLINES -gt 1 ]
then
mv ${DMRIDPATH}/DMRIds.tmp ${DMRIDFILE}
else
echo " ERROR during file update "
rm ${DMRIDPATH}/DMRIds.tmp
fi
# Restart MMDVMHost
eval ${RESTARTCOMMAND}
Loading…
Cancel
Save