mirror of
https://github.com/tcivie/meshtastic-metrics-exporter.git
synced 2025-01-12 06:17:33 -08:00
Added support for filtering specific types of messages from being reported
This commit is contained in:
parent
ed5b1ee0ef
commit
d3f60cc5ff
6
.env
6
.env
|
@ -29,9 +29,11 @@ MQTT_CALLBACK_API_VERSION=VERSION2
|
|||
MESH_HIDE_SOURCE_DATA=false
|
||||
## Hide destination data in the exporter (default: false)
|
||||
MESH_HIDE_DESTINATION_DATA=false
|
||||
## Filtered ports in the exporter (default: 1, can be a comma-separated list of ports)
|
||||
FILTERED_PORTS=0
|
||||
## Hide message content in the TEXT_MESSAGE_APP packets (default: true) (Currently we only log message length, if we hide then all messages would have the same length)
|
||||
HIDE_MESSAGE=false
|
||||
## MQTT server Key for decoding
|
||||
MQTT_SERVER_KEY=1PG7OiApB1nwvP+rz05pAQ==
|
||||
|
||||
# Message types to filter (default: none) (comma separated) (eg. TEXT_MESSAGE_APP,POSITION_APP)
|
||||
# Full list can be found here: https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.PortNum
|
||||
EXPORTER_MESSAGE_TYPES_TO_FILTER=TEXT_MESSAGE_APP,POSITION_APP
|
||||
|
|
|
@ -165,9 +165,6 @@ class MessageProcessor:
|
|||
short_name='Hidden',
|
||||
long_name='Hidden')
|
||||
|
||||
if port_num in map(int, os.getenv('FILTERED_PORTS', '1').split(',')): # Filter out ports
|
||||
return None # Ignore this packet
|
||||
|
||||
self.process_simple_packet_details(destination_client_details, mesh_packet, port_num, source_client_details)
|
||||
|
||||
processor = ProcessorRegistry.get_processor(port_num)(self.registry, self.db_pool)
|
||||
|
|
|
@ -54,6 +54,11 @@ class ProcessorRegistry:
|
|||
@classmethod
|
||||
def register_processor(cls, port_num):
|
||||
def inner_wrapper(wrapped_class):
|
||||
if PortNum.DESCRIPTOR.values_by_number[port_num].name in os.getenv('EXPORTER_MESSAGE_TYPES_TO_FILTER',
|
||||
'').split(','):
|
||||
logger.info(f"Processor for port_num {port_num} is filtered out")
|
||||
return wrapped_class
|
||||
|
||||
cls._registry[port_num] = wrapped_class
|
||||
return wrapped_class
|
||||
|
||||
|
@ -71,7 +76,6 @@ class ProcessorRegistry:
|
|||
@ProcessorRegistry.register_processor(PortNum.UNKNOWN_APP)
|
||||
class UnknownAppProcessor(Processor):
|
||||
def process(self, payload: bytes, client_details: ClientDetails):
|
||||
logger.debug("Received UNKNOWN_APP packet")
|
||||
return None
|
||||
|
||||
|
||||
|
|
5
main.py
5
main.py
|
@ -17,8 +17,6 @@ except ImportError:
|
|||
from prometheus_client import CollectorRegistry, start_http_server
|
||||
from psycopg_pool import ConnectionPool
|
||||
|
||||
from exporter.processor_base import MessageProcessor
|
||||
|
||||
connection_pool = None
|
||||
|
||||
|
||||
|
@ -88,6 +86,9 @@ def handle_message(client, userdata, message):
|
|||
if __name__ == "__main__":
|
||||
load_dotenv()
|
||||
|
||||
# We have to load_dotenv before we can import MessageProcessor to allow filtering of message types
|
||||
from exporter.processor_base import MessageProcessor
|
||||
|
||||
# Setup a connection pool
|
||||
connection_pool = ConnectionPool(
|
||||
os.getenv('DATABASE_URL'),
|
||||
|
|
Loading…
Reference in a new issue