akpw / mktxp

Prometheus Exporter for Mikrotik RouterOS devices
Other
466 stars 91 forks source link

Cannot specify what address to listen on, and hardoced IPv4 #73

Closed jktjkt closed 6 months ago

jktjkt commented 1 year ago

I have IPv6-only network, and I'm running the Mikrotik exporter on the same node as my TSDB. The address that the mktxp export listens on is currently not configurable, so I cannot easily set it to localhost. Also, it only listens on an IPv4 socket. For those like me who want a quick fix, it's like this:

diff --git a/mktxp/flow/processor/base_proc.py b/mktxp/flow/processor/base_proc.py
index f42766e..8c84212 100644
--- a/mktxp/flow/processor/base_proc.py
+++ b/mktxp/flow/processor/base_proc.py
@@ -27,6 +27,8 @@ from mktxp.cli.output.wifi_out import WirelessOutput
 from mktxp.cli.output.dhcp_out import DHCPOutput
 from mktxp.cli.output.conn_stats_out import ConnectionsStatsOutput

+import socket
+

 class ExportProcessor:
     ''' Base Export Processing
@@ -38,7 +40,8 @@ class ExportProcessor:

     @staticmethod
     def run(server_class=HTTPServer, handler_class=MetricsHandler, port=None):
-        server_address = ('', port)
+        server_class.address_family = socket.AF_INET6
+        server_address = ('::1', port)
         httpd = server_class(server_address, handler_class)
         current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
         print(f'{current_time} Running HTTP metrics server on port {port}')

Since this is super-hacky and because the underlying API library also needs a patch for connecting to IPv6-only routers (https://github.com/socialwifi/RouterOS-api/pull/88), I'm just reporting an issue and not sending a patch. A proper fix is not a one-liner I'm afraid because the Python HTTP library apparently requires jumping through some hoops (https://github.com/python/cpython/commit/f289084c83190cc72db4a70c58f007ec62e75247) for this.

leahoswald commented 6 months ago

It would be really great if this was configurable. Would like to set it to localhost only but patching code in prod isn't that great. Should be an easy fix.

akpw commented 6 months ago

should be fixed in the latest, described here