From 17cb9aafb420b0716c6fd3a0da1f9c1f654a3953 Mon Sep 17 00:00:00 2001 From: n0mjs710 Date: Wed, 9 Jan 2019 09:03:59 -0600 Subject: [PATCH 1/4] Added TX/RX to OpenBridge Listings --- templates/hblink_table.html | 2 +- web_tables.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/hblink_table.html b/templates/hblink_table.html index 6f947dc..dcce8e3 100755 --- a/templates/hblink_table.html +++ b/templates/hblink_table.html @@ -83,7 +83,7 @@ {{ _openbridge}} {{ _table['OPENBRIDGES'][_openbridge]['NETWORK_ID'] }}
{{ _table['OPENBRIDGES'][_openbridge]['TARGET_IP'] }}:{{ _table['OPENBRIDGES'][_openbridge]['TARGET_PORT'] }}
- {% for entry in _table['OPENBRIDGES'][_openbridge]['STREAMS'] %}({{ _table['OPENBRIDGES'][_openbridge]['STREAMS'][entry][0] }} >> {{ _table['OPENBRIDGES'][_openbridge]['STREAMS'][entry][1] }}) {% endfor %} + {% for entry in _table['OPENBRIDGES'][_openbridge]['STREAMS'] %}({{ _table['OPENBRIDGES'][_openbridge]['STREAMS'][entry][0] }} | {{ _table['OPENBRIDGES'][_openbridge]['STREAMS'][entry][1] }} >> {{ _table['OPENBRIDGES'][_openbridge]['STREAMS'][entry][2] }}) {% endfor %} {% endfor %} diff --git a/web_tables.py b/web_tables.py index 16c556b..ca9a015 100755 --- a/web_tables.py +++ b/web_tables.py @@ -380,7 +380,7 @@ def rts_update(p): if system in CTABLE['OPENBRIDGES']: if action == 'START': - CTABLE['OPENBRIDGES'][system]['STREAMS'][streamId] = (alias_call(sourceSub, subscriber_ids), destination) + CTABLE['OPENBRIDGES'][system]['STREAMS'][streamId] = (trx, alias_call(sourceSub, subscriber_ids), destination) if action == 'END': if streamId in CTABLE['OPENBRIDGES'][system]['STREAMS']: del CTABLE['OPENBRIDGES'][system]['STREAMS'][streamId] From 58423d0ab149ecd889fc96a1c0099bf59475b747 Mon Sep 17 00:00:00 2001 From: cort Date: Wed, 27 Feb 2019 09:29:34 -0600 Subject: [PATCH 2/4] Added client timeouts and general clean-up --- config_SAMPLE.py | 5 +++-- index_template.html | 3 ++- web_tables.py | 43 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/config_SAMPLE.py b/config_SAMPLE.py index 8c4779b..cd74be8 100755 --- a/config_SAMPLE.py +++ b/config_SAMPLE.py @@ -1,10 +1,11 @@ REPORT_NAME = 'system.domain.name' # Name of the monitored HBlink system CONFIG_INC = True # Include HBlink stats BRIDGES_INC = True # Include Bridge stats (confbrige.py) -HBLINK_IP = '127.0.0.1' # HBlink's IP Address -HBLINK_PORT = 4321 # HBlink's TCP reporting socket +HBLINK_IP = '127.0.0.1' # HBlink's IP Address +HBLINK_PORT = 4321 # HBlink's TCP reporting socket FREQUENCY = 10 # Frequency to push updates to web clients WEB_SERVER_PORT = 8080 # Has to be above 1024 if you're not running as root +CLIENT_TIMEOUT = 300 # Clients are timed out after this many seconds, 0 to disable # Files and stuff for loading alias files for mapping numbers to names PATH = './' # MUST END IN '/' diff --git a/index_template.html b/index_template.html index 2b9d7a5..70a4d1d 100755 --- a/index_template.html +++ b/index_template.html @@ -71,6 +71,7 @@

HBlink Monitoring Server

<<>>

+

<<>>


@@ -82,7 +83,7 @@
- Copyright (c) 2016, 2017, 2018
The Founding Members of the K0USY Group. All rights reserved. + Copyright (c) 2016, 2017, 2018, 2019
The Regents of the K0USY Group. All rights reserved. diff --git a/web_tables.py b/web_tables.py index ca9a015..d8961a5 100755 --- a/web_tables.py +++ b/web_tables.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # ############################################################################### -# Copyright (C) 2016 Cortney T. Buffington, N0MJS +# Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS # # 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 @@ -50,9 +50,8 @@ from jinja2 import Environment, PackageLoader, select_autoescape # Utilities from K0USY Group sister project from dmr_utils.utils import int_id, get_alias, try_download, mk_full_id_dict, hex_str_4 -# Configuration variables and IPSC constants +# Configuration variables and constants from config import * -#from ipsc_const import * # Opcodes for reporting protocol to HBlink OPCODE = { @@ -341,6 +340,21 @@ def build_stats(): dashboard_server.broadcast(table) build_time = now + +def timeout_clients(): + now = time() + try: + for client in dashboard_server.clients: + if dashboard_server.clients[client] + CLIENT_TIMEOUT < now: + logger.info('TIMEOUT: disconnecting client %s', dashboard_server.clients[client]) + try: + dashboard.sendClose(client) + except Exception as e: + logger.error('Exception caught parsing client timeout %s', e) + except: + logger.info('CLIENT TIMEOUT: List does not exist, skipping. If this message persists, contact the developer') + + def rts_update(p): callType = p[0] action = p[1] @@ -539,22 +553,21 @@ class dashboard(WebSocketServerProtocol): def onClose(self, wasClean, code, reason): logging.info('WebSocket connection closed: %s', reason) - class dashboardFactory(WebSocketServerFactory): def __init__(self, url): WebSocketServerFactory.__init__(self, url) - self.clients = [] + self.clients = {} def register(self, client): if client not in self.clients: logging.info('registered client %s', client.peer) - self.clients.append(client) + self.clients[client] = time() def unregister(self, client): if client in self.clients: logging.info('unregistered client %s', client.peer) - self.clients.remove(client) + del self.clients[client] def broadcast(self, msg): logging.debug('broadcasting message to: %s', self.clients) @@ -581,15 +594,19 @@ if __name__ == '__main__': logging.basicConfig( level=logging.INFO, filename = (LOG_PATH + LOG_NAME), - filemode='a' + filemode='a', + format='%(asctime)s %(levelname)s %(message)s', + datefmt='%Y-%m-%d %H:%M:%S' ) console = logging.StreamHandler() console.setLevel(logging.INFO) + formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + console.setFormatter(formatter) logging.getLogger('').addHandler(console) logger = logging.getLogger(__name__) logging.info('web_tables.py starting up') - logger.info('\n\nCopyright (c) 2017, 2018\n\tThe Founding Members of the K0USY Group. All rights reserved.\n') + logger.info('\n\nCopyright (c) 2016, 2017, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n') # Download alias files result = try_download(PATH, 'peer_ids.csv', PEER_URL, (FILE_RELOAD * 86400)) @@ -633,11 +650,19 @@ if __name__ == '__main__': # Create Static Website index file index_html = get_template(PATH + 'index_template.html') index_html = index_html.replace('<<>>', REPORT_NAME) + if CLIENT_TIMEOUT > 0: + index_html = index_html.replace('<<>>', 'Continuous connections not allowed. Connections time out in {} seconds'.format(CLIENT_TIMEOUT)) + else: + index_html = index_html.replace('<<>>', '') # Start update loop update_stats = task.LoopingCall(build_stats) update_stats.start(FREQUENCY) + # Start a timout loop + timeout = task.LoopingCall(timeout_clients) + timeout.start(10) + # Connect to HBlink reactor.connectTCP(HBLINK_IP, HBLINK_PORT, reportClientFactory()) From 936d226a3da245d4a6961c94dbda6fadcf69ad71 Mon Sep 17 00:00:00 2001 From: cort Date: Fri, 1 Mar 2019 10:48:31 -0600 Subject: [PATCH 3/4] Fixed hardcoded alias files to use config file instead --- web_tables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_tables.py b/web_tables.py index d8961a5..4338f80 100755 --- a/web_tables.py +++ b/web_tables.py @@ -609,10 +609,10 @@ if __name__ == '__main__': logger.info('\n\nCopyright (c) 2016, 2017, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n') # Download alias files - result = try_download(PATH, 'peer_ids.csv', PEER_URL, (FILE_RELOAD * 86400)) + result = try_download(PATH, PEER_FILE, PEER_URL, (FILE_RELOAD * 86400)) logging.info(result) - result = try_download(PATH, 'subscriber_ids.csv', SUBSCRIBER_URL, (FILE_RELOAD * 86400)) + result = try_download(PATH, SUBSCRIBER_FILE, SUBSCRIBER_URL, (FILE_RELOAD * 86400)) logging.info(result) # Make Alias Dictionaries From 01194e1af4443a2625c9ada15216d0dfd141b810 Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Fri, 1 Mar 2019 11:43:24 -0600 Subject: [PATCH 4/4] Create talkgroup_ids.json --- talkgroup_ids.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 talkgroup_ids.json diff --git a/talkgroup_ids.json b/talkgroup_ids.json new file mode 100644 index 0000000..c461d84 --- /dev/null +++ b/talkgroup_ids.json @@ -0,0 +1,16 @@ +{ + "results": [ + { + "id": "3120", + "callsign": "Kansas Statewide" + }, + { + "id": "31201", + "callsign": "BYRG" + }, + { + "id": "310", + "callsign": "Kerchunk 310" + } + ] +} \ No newline at end of file