More cleanup...

This commit is contained in:
Cort Buffington 2017-05-15 15:29:16 -05:00
parent 04ce07dc24
commit 05c0e71773
6 changed files with 35 additions and 467 deletions

View File

@ -58,7 +58,7 @@ import sys
from dmr_utils.utils import hex_str_3, hex_str_4, int_id
from dmrlink import IPSC, systems, config_reports, reportFactory, REPORT_OPCODES # hmac_new, sha1, report
from ipsc.ipsc_const import BURST_DATA_TYPE
from DMRlink.ipsc_const import BURST_DATA_TYPE
__author__ = 'Cortney T. Buffington, N0MJS'
@ -418,13 +418,13 @@ class confReportFactory(reportFactory):
if __name__ == '__main__':
#import argparse
#import os
#import signal
#from dmr_utils.utils import try_download, mk_id_dict
import argparse
import os
import signal
from dmr_utils.utils import try_download, mk_id_dict
import dmrlink_log
import dmrlink_config
from DMRlink.dmrlink_config import build_config
from DMRlink.dmrlink_log import config_logging
# Change the current directory to the location of the application
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
@ -440,30 +440,31 @@ if __name__ == '__main__':
cli_args.CFG_FILE = os.path.dirname(os.path.abspath(__file__))+'/dmrlink.cfg'
# Call the external routine to build the configuration dictionary
CONFIG = dmrlink_config.build_config(cli_args.CFG_FILE)
CONFIG = build_config(cli_args.CFG_FILE)
# Call the external routing to start the system logger
if cli_args.LOG_LEVEL:
CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL
if cli_args.LOG_HANDLERS:
CONFIG['LOGGER']['LOG_HANDLERS'] = cli_args.LOG_HANDLERS
logger = dmrlink_log.config_logging(CONFIG['LOGGER'])
logger = config_logging(CONFIG['LOGGER'])
config_reports(CONFIG)
logger.info('DMRlink \'confbridge.py\' (c) 2016 N0MJS & the K0USY Group - SYSTEM STARTING...')
# Shut ourselves down gracefully with the IPSC peers.
def sig_handler(_signal, _frame):
logger.info('*** DMRLINK IS TERMINATING WITH SIGNAL %s ***', str(_signal))
for system in systems:
this_ipsc = systems[system]
logger.info('De-Registering from IPSC %s', system)
de_reg_req_pkt = this_ipsc.hashed_packet(this_ipsc._local['AUTH_KEY'], this_ipsc.DE_REG_REQ_PKT)
this_ipsc.send_to_ipsc(de_reg_req_pkt)
reactor.stop()
# Set signal handers so that we can gracefully exit if need be
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]:
signal.signal(sig, sig_handler)

View File

@ -43,13 +43,12 @@ from twisted.internet.protocol import DatagramProtocol, Factory, Protocol
from twisted.protocols.basic import NetstringReceiver
from twisted.internet import reactor, task
# Imports from our static file directory
from dmrlink.ipsc_const import *
from dmrlink.ipsc_mask import *
from dmrlink.reporting_const import *
from dmrlink.dmrlink_config import build_config
from dmrlink.dmrlink_log import config_logging
# Imports files in the dmrlink subdirectory (these things shouldn't change often)
from DMRlink.ipsc_const import *
from DMRlink.ipsc_mask import *
from DMRlink.reporting_const import *
# Imports from DMR Utilities package
from dmr_utils.utils import hex_str_2, hex_str_3, hex_str_4, int_id
@ -65,18 +64,6 @@ __email__ = 'n0mjs@me.com'
systems = {}
# Shut ourselves down gracefully with the IPSC peers.
#
def sig_handler(_signal, _frame):
logger.info('*** DMRLINK IS TERMINATING WITH SIGNAL %s ***', str(_signal))
for system in systems:
this_ipsc = systems[system]
logger.info('De-Registering from IPSC %s', system)
de_reg_req_pkt = this_ipsc.hashed_packet(this_ipsc._local['AUTH_KEY'], this_ipsc.DE_REG_REQ_PKT)
this_ipsc.send_to_ipsc(de_reg_req_pkt)
reactor.stop()
# Timed loop used for reporting IPSC status
#
# REPORT BASED ON THE TYPE SELECTED IN THE MAIN CONFIG FILE
@ -1008,6 +995,9 @@ if __name__ == '__main__':
import os
import signal
from DMRlink.dmrlink_config import build_config
from DMRlink.dmrlink_log import config_logging
# Change the current directory to the location of the application
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
@ -1025,7 +1015,6 @@ if __name__ == '__main__':
# Call the external routine to build the configuration dictionary
CONFIG = build_config(cli_args.CFG_FILE)
# Call the external routing to start the system logger
if cli_args.LOG_LEVEL:
CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL
@ -1035,6 +1024,20 @@ if __name__ == '__main__':
logger.info('DMRlink \'dmrlink.py\' (c) 2013 - 2015 N0MJS & the K0USY Group - SYSTEM STARTING...')
# Set signal handers so that we can gracefully exit if need be
def sig_handler(_signal, _frame):
logger.info('*** DMRLINK IS TERMINATING WITH SIGNAL %s ***', str(_signal))
for system in systems:
this_ipsc = systems[system]
logger.info('De-Registering from IPSC %s', system)
de_reg_req_pkt = this_ipsc.hashed_packet(this_ipsc._local['AUTH_KEY'], this_ipsc.DE_REG_REQ_PKT)
this_ipsc.send_to_ipsc(de_reg_req_pkt)
reactor.stop()
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]:
signal.signal(sig, sig_handler)
# INITIALIZE THE REPORTING LOOP
config_reports(CONFIG)
@ -1061,8 +1064,6 @@ if __name__ == '__main__':
systems[system] = IPSC(system, CONFIG, logger, report_server)
reactor.listenUDP(CONFIG['SYSTEMS'][system]['LOCAL']['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['LOCAL']['IP'])
# Set signal handers so that we can gracefully exit if need be
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]:
signal.signal(sig, sig_handler)
reactor.run()

View File

@ -1,35 +0,0 @@
#! /bin/sh
###################################################
# #
# Download Subscriber and Peer ID's from DMR-MARC #
# #
###################################################
# To provide more readable output from DMRlink with current subscriber and repeater IDs, we download the CSV files from DMR-MARC
# If you are going to use this in a cron task, don't run it more then once a day.
# It might be good to find alternale a source as a backup.
# <http://www.dmr-marc.net/cgi-bin/trbo-database/datadump.cgi>
# wget -O users.csv -q "http://www.dmr-marc.net/cgi-bin/trbo-database/datadump.cgi?table=users&format=csv&header=0"
# Options are:
# table { users | repeaters }
# format { table | csv | csvq | json }
# header { 0 | 1 } (only applies to table and csv formats)
# id { nnnnnn } (query an individual record)
# Get the user IDs.
wget -O subscriber_ids.csv -q "http://www.dmr-marc.net/cgi-bin/trbo-database/datadump.cgi?table=users&format=csv&header=0"
# Get the peer IDs
wget -O peer_ids.csv -q "http://www.dmr-marc.net/cgi-bin/trbo-database/datadump.cgi?table=repeaters&format=csv&header=0"
# Tell ambe_audio to re-read the files
echo -n "reread_subscribers" | nc 127.0.0.1 31002

View File

@ -1,150 +0,0 @@
#!/usr/bin/env python
#
###############################################################################
# Copyright (C) 2017 Cortney T. Buffington, N0MJS <n0mjs@me.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of tde GNU General Public License as published by
# the Free Software Foundation; eitder version 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
from __future__ import print_function
from cPickle import load
from pprint import pprint
from time import time, strftime, localtime
from twisted.internet import reactor
from twisted.internet import task
from binascii import b2a_hex as h
from dmr_utils.utils import int_id, get_alias
from os.path import getmtime
__autdor__ = 'Cortney T. Buffington, N0MJS'
__copyright__ = 'Copyright (c) 2017 Cortney T. Buffington, N0MJS'
__license__ = 'GNU GPLv3'
__maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
# This is the only user-configuration necessary
# Tell the program where the pickle file is
# Tell the program where to write the html table file
# Tell the program how often to print a report -- should match dmrlink report period
stat_file = '../confbridge_stats.pickle'
html_table_file = '../confbridge_stats.html'
frequency = 10
def read_dict():
try:
with open(stat_file, 'rb') as file:
BRIDGES = load(file)
return BRIDGES
except IOError as detail:
print('I/O Error: {}'.format(detail))
except EOFError:
print('EOFError')
def write_file(_string):
try:
with open(html_table_file, 'w') as file:
file.write(_string)
file.close()
except IOError as detail:
print('I/O Error: {}'.format(detail))
except EOFError:
print('EOFError')
def build_table():
_now = time()
_last_update = strftime('%Y-%m-%d %H:%M:%S', localtime(getmtime(stat_file)))
_cnow = strftime('%Y-%m-%d %H:%M:%S', localtime(_now))
BRIDGES = read_dict()
if BRIDGES != 'None':
stuff = 'Table Generated: {}<br>'.format(_cnow)
stuff += 'Last Stat Data Recieved: {}<br>'.format(_last_update)
#style="font: 10pt arial, sans-serif;"
for bridge in BRIDGES:
stuff += '<style>table, td, th {border: .5px solid black; padding: 2px; border-collapse: collapse}</style>'
stuff += '<table style="width:90%; font: 10pt arial, sans-serif">'
stuff += '<colgroup>\
<col style="width: 20%" />\
<col style="width: 5%" />\
<col style="width: 5%" />\
<col style="width: 10%" />\
<col style="width: 10%" />\
<col style="width: 10%" />\
<col style="width: 10%" />\
<col style="width: 10%" />\
<col style="width: 10%" />\
</colgroup>'
stuff += '<caption>{}</caption>'.format(bridge)
stuff += '<tr><th>System</th>\
<th>Slot</th>\
<th>TGID</th>\
<th>Status</th>\
<th>Timeout</th>\
<th>Timeout Action</th>\
<th>ON Triggers</th>\
<th>OFF Triggers</th></tr>'
for system in BRIDGES[bridge]:
on = ''
off = ''
active = '<td bgcolor="#FFFF00">Unknown</td>'
if system['TO_TYPE'] == 'ON' or system['TO_TYPE'] == 'OFF':
if system['TIMER'] - _now > 0:
exp_time = int(system['TIMER'] - _now)
else:
exp_time = 'Expired'
if system['TO_TYPE'] == 'ON':
to_action = 'Turn OFF'
else:
to_action = 'Turn ON'
else:
exp_time = 'N/A'
to_action = 'None'
if system['ACTIVE'] == True:
active = '<td bgcolor="#00FF00">Connected</td>'
elif system['ACTIVE'] == False:
active = '<td bgcolor="#FF0000">Disconnected</td>'
for trigger in system['ON']:
on += str(int_id(trigger)) + ' '
for trigger in system['OFF']:
off += str(int_id(trigger)) + ' '
stuff += '<tr> <td>{}</td> <td>{}</td> <td>{}</td> {} <td>{}</td> <td>{}</td> <td>{}</td> <td>{}</td> </tr>'.format(\
system['SYSTEM'],\
system['TS'],\
int_id(system['TGID']),\
active,\
exp_time,\
to_action,\
on,\
off)
stuff += '</table><br>'
write_file(stuff)
if __name__ == '__main__':
output_stats = task.LoopingCall(build_table)
output_stats.start(frequency)
reactor.run()

View File

@ -1,139 +0,0 @@
#!/usr/bin/env python
#
###############################################################################
# Copyright (C) 2017 Cortney T. Buffington, N0MJS <n0mjs@me.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of tde GNU General Public License as published by
# the Free Software Foundation; eitder version 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
from __future__ import print_function
from cPickle import load
from pprint import pprint
from time import time, strftime, localtime
from twisted.internet import reactor
from twisted.internet import task
from binascii import b2a_hex as h
from dmr_utils.utils import int_id, get_alias
__autdor__ = 'Cortney T. Buffington, N0MJS'
__copyright__ = 'Copyright (c) 2017 Cortney T. Buffington, N0MJS'
__license__ = 'GNU GPLv3'
__maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
# This is the only user-configuration necessary
# Tell the program where the pickle file is
# Tell the program where to write the html table file
# Tell the program how often to print a report -- should match dmrlink report period
stat_file = '../dmrlink_stats.pickle'
html_table_file = '../stats.html'
frequency = 30
def read_dict():
try:
with open(stat_file, 'rb') as file:
NETWORK = load(file)
return NETWORK
except IOError as detail:
print('I/O Error: {}'.format(detail))
except EOFError:
print('EOFError')
def write_file(_string):
try:
with open(html_table_file, 'w') as file:
file.write(_string)
file.close()
except IOError as detail:
print('I/O Error: {}'.format(detail))
except EOFError:
print('EOFError')
def build_table():
NETWORK = read_dict()
if NETWORK != 'None':
_cnow = strftime('%Y-%m-%d %H:%M:%S', localtime(time()))
stuff = 'Last Update: {}'.format(_cnow)
stuff += '<style>table, td, th {border: .5px solid black; padding: 2px; border-collapse: collapse}</style>'
for ipsc in NETWORK:
stat = NETWORK[ipsc]['MASTER']['STATUS']
master = NETWORK[ipsc]['LOCAL']['MASTER_PEER']
stuff += '<table style="width:90%; font: 10pt arial, sans-serif">'
stuff += '<colgroup>\
<col style="width: 10%" />\
<col style="width: 20%" />\
<col style="width: 20%" />\
<col style="width: 10%" />\
<col style="width: 15%" />\
<col style="width: 15%" />\
<col style="width: 10%" />\
</colgroup>'
stuff += '<caption>{} '.format(ipsc)
if master:
stuff += '(master)'
else:
stuff += '(peer)'
stuff +='</caption>'
stuff += '<tr><th rowspan="2">Type</th>\
<th rowspan="2">Radio ID</th>\
<th rowspan="2">IP Address</th>\
<th rowspan="2">Connected</th>\
<th colspan="3">Keep Alives</th></tr>\
<tr><th>Sent</th><th>Received</th><th>Missed</th></tr>'
if not master:
stuff += '<tr><td>Master</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>'.format(\
str(int_id(NETWORK[ipsc]['MASTER']['RADIO_ID'])).rjust(8,'0'),\
NETWORK[ipsc]['MASTER']['IP'],\
stat['CONNECTED'],\
stat['KEEP_ALIVES_SENT'],\
stat['KEEP_ALIVES_RECEIVED'],\
stat['KEEP_ALIVES_MISSED'],)
if master:
for peer in NETWORK[ipsc]['PEERS']:
stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
stuff += '<tr><td>Peer</td><td>{}</td><td>{}</td><td>{}</td><td>n/a</td><td>{}</td><td>n/a</td></tr>'.format(\
str(int_id(peer)).rjust(8,'0'),\
NETWORK[ipsc]['PEERS'][peer]['IP'],\
stat['CONNECTED'],\
stat['KEEP_ALIVES_RECEIVED'])
else:
for peer in NETWORK[ipsc]['PEERS']:
stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
if peer != NETWORK[ipsc]['LOCAL']['RADIO_ID']:
stuff += '<tr><td>Peer</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>'.format(\
str(int_id(peer)).rjust(8,'0'),\
NETWORK[ipsc]['PEERS'][peer]['IP'],\
stat['CONNECTED'],\
stat['KEEP_ALIVES_SENT'],\
stat['KEEP_ALIVES_RECEIVED'],\
stat['KEEP_ALIVES_MISSED'])
stuff += '</table><br>'
write_file(stuff)
if __name__ == '__main__':
output_stats = task.LoopingCall(build_table)
output_stats.start(frequency)
reactor.run()

View File

@ -1,110 +0,0 @@
#!/usr/bin/env python
#
###############################################################################
# Copyright (C) 2016 Cortney T. Buffington, N0MJS <n0mjs@me.com>
#
# 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
from __future__ import print_function
from cPickle import load
from pprint import pprint
from time import ctime
from twisted.internet import reactor
from twisted.internet import task
from binascii import b2a_hex as h
__author__ = 'Cortney T. Buffington, N0MJS'
__copyright__ = 'Copyright (c) 2015 Cortney T. Buffington, N0MJS and the K0USY Group'
__credits__ = 'Adam Fast, KC0YLK, Dave Kierzkowski, KD8EYF'
__license__ = 'GNU GPLv3'
__maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
# This is the only user-configuration necessary
# Tell the program where the pickle file is
# Tell the program how often to print a report
stat_file = '../dmrlink_stats.pickle'
frequency = 30
def int_id(_hex_string):
return int(h(_hex_string), 16)
def read_dict():
try:
with open(stat_file, 'rb') as file:
NETWORK = load(file)
return NETWORK
except IOError as detail:
print('I/O Error: {}'.format(detail))
except EOFError:
print('EOFError')
def print_stats():
NETWORK = read_dict()
if NETWORK != "None":
print('NETWORK STATISTICS REPORT:', ctime())
for ipsc in NETWORK:
stat = NETWORK[ipsc]['MASTER']['STATUS']
master = NETWORK[ipsc]['LOCAL']['MASTER_PEER']
print(ipsc)
if master:
print(' MASTER Information:')
print(' RADIO ID: {} (self)'.format(str(int_id(NETWORK[ipsc]['LOCAL']['RADIO_ID'])).rjust(8,'0')))
else:
print(' MASTER Information:')
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: SENT {} RECEIVED {} MISSED {} ({})'.format(\
str(int_id(NETWORK[ipsc]['MASTER']['RADIO_ID'])).rjust(8,'0'),\
stat['CONNECTED'],stat['KEEP_ALIVES_SENT'],\
stat['KEEP_ALIVES_RECEIVED'],\
stat['KEEP_ALIVES_MISSED'],\
NETWORK[ipsc]['MASTER']['IP']))
print(' PEER Information:')
if master:
for peer in NETWORK[ipsc]['PEERS']:
stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: RECEIVED {} ({})'.format(\
str(int_id(peer)).rjust(8,'0'),\
stat['CONNECTED'],\
stat['KEEP_ALIVES_RECEIVED'],\
NETWORK[ipsc]['PEERS'][peer]['IP']))
else:
for peer in NETWORK[ipsc]['PEERS']:
stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
if peer == NETWORK[ipsc]['LOCAL']['RADIO_ID']:
print(' RADIO ID: {} (self)'.format(str(int_id(peer)).rjust(8,'0')))
else:
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: SENT {} RECEIVED {} MISSED {} ({})'.format(\
str(int_id(peer)).rjust(8,'0'),\
stat['CONNECTED'],\
stat['KEEP_ALIVES_SENT'],\
stat['KEEP_ALIVES_RECEIVED'],\
stat['KEEP_ALIVES_MISSED'],\
NETWORK[ipsc]['PEERS'][peer]['IP']))
print()
print()
if __name__ == '__main__':
output_stats = task.LoopingCall(print_stats)
output_stats.start(frequency)
reactor.run()