1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-11-21 15:51:52 -05:00

Compare commits

..

No commits in common. "e57a2e2ffcc4903e191447c5f7c9baaf5f76c34f" and "450bacfe990d27ea4849c0b53d9bbd6111c3e44f" have entirely different histories.

10 changed files with 82 additions and 115 deletions

View File

@ -11,7 +11,6 @@ import sys
import click
import requests
from rich.console import Console
import aprsd
from aprsd import cli_helper, utils
@ -22,7 +21,6 @@ from aprsd.aprsd import cli
# setup the global logger
# logging.basicConfig(level=logging.DEBUG) # level=10
LOG = logging.getLogger("APRSD")
console = Console()
@cli.command()
@ -44,40 +42,36 @@ console = Console()
@cli_helper.process_standard_options_no_config
def healthcheck(ctx, health_url, timeout):
"""Check the health of the running aprsd server."""
console.log(f"APRSD HealthCheck version: {aprsd.__version__}")
with console.status(f"APRSD HealthCheck version: {aprsd.__version__}") as status:
try:
url = health_url
response = requests.get(url, timeout=timeout)
response.raise_for_status()
except Exception as ex:
console.log(f"Failed to fetch healthcheck url '{url}' : '{ex}'")
LOG.debug(f"APRSD HealthCheck version: {aprsd.__version__}")
try:
url = health_url
response = requests.get(url, timeout=timeout)
response.raise_for_status()
except Exception as ex:
LOG.error(f"Failed to fetch healthcheck url '{url}' : '{ex}'")
sys.exit(-1)
else:
stats = json.loads(response.text)
LOG.debug(stats)
email_thread_last_update = stats["stats"]["email"]["thread_last_update"]
delta = utils.parse_delta_str(email_thread_last_update)
d = datetime.timedelta(**delta)
max_timeout = {"hours": 0.0, "minutes": 5, "seconds": 0}
max_delta = datetime.timedelta(**max_timeout)
if d > max_delta:
LOG.error(f"Email thread is very old! {d}")
sys.exit(-1)
else:
import time
time.sleep(2)
status.update("PISS")
time.sleep(2)
stats = json.loads(response.text)
email_thread_last_update = stats["stats"]["email"]["thread_last_update"]
aprsis_last_update = stats["stats"]["aprs-is"]["last_update"]
delta = utils.parse_delta_str(aprsis_last_update)
d = datetime.timedelta(**delta)
max_timeout = {"hours": 0.0, "minutes": 5, "seconds": 0}
max_delta = datetime.timedelta(**max_timeout)
if d > max_delta:
LOG.error(f"APRS-IS last update is very old! {d}")
sys.exit(-1)
if email_thread_last_update != "never":
delta = utils.parse_delta_str(email_thread_last_update)
d = datetime.timedelta(**delta)
max_timeout = {"hours": 0.0, "minutes": 5, "seconds": 0}
max_delta = datetime.timedelta(**max_timeout)
if d > max_delta:
console.log(f"Email thread is very old! {d}")
sys.exit(-1)
aprsis_last_update = stats["stats"]["aprs-is"]["last_update"]
delta = utils.parse_delta_str(aprsis_last_update)
d = datetime.timedelta(**delta)
max_timeout = {"hours": 0.0, "minutes": 5, "seconds": 0}
max_delta = datetime.timedelta(**max_timeout)
if d > max_delta:
LOG.error(f"APRS-IS last update is very old! {d}")
sys.exit(-1)
sys.exit(0)
sys.exit(0)

View File

@ -227,8 +227,6 @@ def list_plugins(ctx):
# now find any from pypi?
installed_plugins = get_installed_plugins()
with console.status("Fetching pypi.org plugins"):
show_pypi_plugins(installed_plugins, console)
show_pypi_plugins(installed_plugins, console)
with console.status("Looking for installed aprsd plugins"):
show_installed_plugins(installed_plugins, console)
show_installed_plugins(installed_plugins, console)

View File

@ -10,7 +10,6 @@ import time
import aprslib
import click
from rich.console import Console
# local imports here
import aprsd
@ -23,7 +22,6 @@ from aprsd.aprsd import cli
# setup the global logger
# logging.basicConfig(level=logging.DEBUG) # level=10
LOG = logging.getLogger("APRSD")
console = Console()
def signal_handler(sig, frame):
@ -115,7 +113,7 @@ def listen(
resp = packet.get("response", None)
if resp == "ack":
ack_num = packet.get("msgNo")
console.log(f"We saw an ACK {ack_num} Ignoring")
LOG.info(f"We saw an ACK {ack_num} Ignoring")
messaging.log_packet(packet)
else:
message = packet.get("message_text", None)
@ -127,7 +125,6 @@ def listen(
message,
fromcall=fromcall,
ack=msg_number,
console=console,
)
# Initialize the client factory and create
@ -151,8 +148,7 @@ def listen(
# This will register a packet consumer with aprslib
# When new packets come in the consumer will process
# the packet
with console.status("Listening for packets"):
aprs_client.consumer(rx_packet, raw=False)
aprs_client.consumer(rx_packet, raw=False)
except aprslib.exceptions.ConnectionDrop:
LOG.error("Connection dropped, reconnecting")
time.sleep(5)

View File

@ -1,7 +1,9 @@
import datetime
import json
import logging
from logging import NullHandler
from logging.handlers import RotatingFileHandler
import sys
import threading
import time
@ -9,7 +11,6 @@ import aprslib
from aprslib.exceptions import LoginError
import flask
from flask import request
from flask.logging import default_handler
import flask_classful
from flask_httpauth import HTTPBasicAuth
from flask_socketio import Namespace, SocketIO
@ -20,7 +21,6 @@ from aprsd import client
from aprsd import config as aprsd_config
from aprsd import log, messaging, packets, plugin, stats, threads, utils
from aprsd.clients import aprsis
from aprsd.logging import logging as aprsd_logging
LOG = logging.getLogger("APRSD")
@ -552,15 +552,6 @@ class LoggingNamespace(Namespace):
def setup_logging(config, flask_app, loglevel, quiet):
flask_log = logging.getLogger("werkzeug")
flask_app.logger.removeHandler(default_handler)
flask_log.removeHandler(default_handler)
log_level = aprsd_config.LOG_LEVELS[loglevel]
flask_log.setLevel(log_level)
date_format = config["aprsd"].get(
"dateformat",
aprsd_config.DEFAULT_DATE_FORMAT,
)
if not config["aprsd"]["web"].get("logging_enabled", False):
# disable web logging
@ -568,30 +559,28 @@ def setup_logging(config, flask_app, loglevel, quiet):
flask_app.logger.disabled = True
return
if config["aprsd"].get("rich_logging", False) and not quiet:
log_format = "%(message)s"
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
rh = aprsd_logging.APRSDRichHandler(
show_thread=True, thread_width=15,
rich_tracebacks=True, omit_repeated_times=False,
)
rh.setFormatter(log_formatter)
flask_log.addHandler(rh)
log_level = aprsd_config.LOG_LEVELS[loglevel]
LOG.setLevel(log_level)
log_format = config["aprsd"].get("logformat", aprsd_config.DEFAULT_LOG_FORMAT)
date_format = config["aprsd"].get("dateformat", aprsd_config.DEFAULT_DATE_FORMAT)
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
log_file = config["aprsd"].get("logfile", None)
if log_file:
log_format = config["aprsd"].get(
"logformat",
aprsd_config.DEFAULT_LOG_FORMAT,
)
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
fh = RotatingFileHandler(
log_file, maxBytes=(10248576 * 5),
backupCount=4,
)
fh.setFormatter(log_formatter)
flask_log.addHandler(fh)
fh = RotatingFileHandler(log_file, maxBytes=(10248576 * 5), backupCount=4)
else:
fh = NullHandler()
fh.setFormatter(log_formatter)
for handler in flask_app.logger.handlers:
handler.setFormatter(log_formatter)
print(handler)
flask_log.addHandler(fh)
if not quiet:
sh = logging.StreamHandler(sys.stdout)
sh.setFormatter(log_formatter)
flask_log.addHandler(sh)
def init_flask(config, loglevel, quiet):

View File

@ -18,31 +18,35 @@ logging_queue = queue.Queue()
def setup_logging(config, loglevel, quiet):
log_level = aprsd_config.LOG_LEVELS[loglevel]
LOG.setLevel(log_level)
if config["aprsd"].get("rich_logging", False):
log_format = "%(message)s"
else:
log_format = config["aprsd"].get("logformat", aprsd_config.DEFAULT_LOG_FORMAT)
date_format = config["aprsd"].get("dateformat", aprsd_config.DEFAULT_DATE_FORMAT)
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
log_file = config["aprsd"].get("logfile", None)
rich_logging = False
if config["aprsd"].get("rich_logging", False) and not quiet:
log_format = "%(message)s"
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
if config["aprsd"].get("rich_logging", False):
rh = aprsd_logging.APRSDRichHandler(
show_thread=True, thread_width=20,
show_thread=True, thread_width=15,
rich_tracebacks=True, omit_repeated_times=False,
)
rh.setFormatter(log_formatter)
LOG.addHandler(rh)
rich_logging = True
log_file = config["aprsd"].get("logfile", None)
if log_file:
log_format = config["aprsd"].get("logformat", aprsd_config.DEFAULT_LOG_FORMAT)
log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
fh = RotatingFileHandler(log_file, maxBytes=(10248576 * 5), backupCount=4)
fh.setFormatter(log_formatter)
LOG.addHandler(fh)
else:
fh = NullHandler()
fh.setFormatter(log_formatter)
LOG.addHandler(fh)
imap_logger = None
if config.get("aprsd.email.enabled", default=False) and config.get("aprsd.email.imap.debug", default=False):
imap_logger = logging.getLogger("imapclient.imaplib")
imap_logger.setLevel(log_level)
imap_logger.addHandler(fh)

View File

@ -190,7 +190,6 @@ class Message(metaclass=abc.ABCMeta):
fromcall,
tocall,
msg_id=None,
allow_delay=True,
):
self.fromcall = fromcall
self.tocall = tocall
@ -200,10 +199,6 @@ class Message(metaclass=abc.ABCMeta):
msg_id = c.value
self.id = msg_id
# do we try and save this message for later if we don't get
# an ack? Some messages we don't want to do this ever.
self.allow_delay = allow_delay
@abc.abstractmethod
def send(self):
"""Child class must declare."""
@ -219,8 +214,8 @@ class RawMessage(Message):
message = None
def __init__(self, message, allow_delay=True):
super().__init__(fromcall=None, tocall=None, msg_id=None, allow_delay=allow_delay)
def __init__(self, message):
super().__init__(None, None, msg_id=None)
self.message = message
def dict(self):
@ -274,11 +269,11 @@ class TextMessage(Message):
msg_id=None,
allow_delay=True,
):
super().__init__(
fromcall=fromcall, tocall=tocall,
msg_id=msg_id, allow_delay=allow_delay,
)
super().__init__(fromcall, tocall, msg_id)
self.message = message
# do we try and save this message for later if we don't get
# an ack? Some messages we don't want to do this ever.
self.allow_delay = allow_delay
def dict(self):
now = datetime.datetime.now()
@ -374,8 +369,6 @@ class SendMessageThread(threads.APRSDThread):
# we reached the send limit, don't send again
# TODO(hemna) - Need to put this in a delayed queue?
LOG.info("Message Send Complete. Max attempts reached.")
if not msg.allow_delay:
tracker.remove(msg.id)
return False
# Message is still outstanding and needs to be acked.
@ -534,7 +527,6 @@ def log_packet(packet):
def log_message(
header, raw, message, tocall=None, fromcall=None, msg_num=None,
retry_number=None, ack=None, packet_type=None, uuid=None,
console=None,
):
"""
@ -573,7 +565,4 @@ def log_message(
log_list.append(f" UUID : {uuid}")
log_list.append(f"{header} _______________ Complete")
if console:
console.log("\n".join(log_list))
else:
LOG.info("\n".join(log_list))
LOG.info("\n".join(log_list))

View File

@ -86,7 +86,7 @@ class WatchList(objectstore.ObjectStoreMixin):
if config:
self.config = config
ring_size = config["aprsd"]["watch_list"].get("packet_keep_count", 10)
ring_size = config["aprsd"]["watch_list"]["packet_keep_count"]
for callsign in config["aprsd"]["watch_list"].get("callsigns", []):
call = callsign.replace("*", "")

View File

@ -177,6 +177,7 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
)
if result:
self.tx_inc()
wl.update_seen(packet)
else:
LOG.warning(f"{self.__class__} plugin is not enabled")

View File

@ -1,6 +1,6 @@
import logging
from aprsd import messaging, packets, plugin, trace
from aprsd import messaging, packets, plugin
LOG = logging.getLogger("APRSD")
@ -17,7 +17,6 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
short_description = "Notify me when a CALLSIGN is recently seen on APRS-IS"
@trace.trace
def process(self, packet):
LOG.info("NotifySeenPlugin")
@ -47,11 +46,10 @@ class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
)
return msg
else:
LOG.debug("fromcall and notify_callsign are the same, not notifying")
return messaging.NULL_MESSAGE
else:
LOG.debug(
"Not old enough to notify on callsign '{}' : {} < {}".format(
"Not old enough to notify callsign '{}' : {} < {}".format(
fromcall,
age,
wl.max_delta(),

View File

@ -202,7 +202,7 @@ class APRSDProcessPacketThread(APRSDThread):
self.packet = packet
self.config = config
name = self.packet["raw"][:10]
super().__init__(f"RXPKT-{name}")
super().__init__(f"RX_PACKET-{name}")
def process_ack_packet(self, packet):
ack_num = packet.get("msgNo")
@ -261,8 +261,6 @@ class APRSDProcessPacketThread(APRSDThread):
pm = plugin.PluginManager()
try:
results = pm.run(packet)
wl = packets.WatchList()
wl.update_seen(packet)
replied = False
for reply in results:
if isinstance(reply, list):