OPNsense Log JSON Parser to LOKI
774
LogSense2Loki is a sophisticated Python-based solution designed for modern logging infrastructures. It captures syslog messages, intelligently parses them into JSON format, and efficiently forwards them to Grafana Loki. With optional GeoIP lookup capabilities, LogSense2Loki enhances your logs with geolocation data, providing invaluable insights for monitoring and analysis. Additionally, it exposes Prometheus metrics to ensure you can effortlessly track the performance of your logging setup.
just kidding,
it's probably not very performant, but it does what it's supposed to as long as OPNsense itself doesn't log json, it's definitely the best way.
With JSON it is very easy to search and analyze the logs, and especially to visualize them with Loki in Grafana.
It is quite simple so that you can easily add additional parsers, metrics endpoint gives information about how many percent could be parsed, for me it is 99.99%
LogSense2Loki provides the following Prometheus metrics endpoint at http://localhost:8100/metrics:
logsense2loki_successful_logs_total: Monitors the total number of successfully parsed and sent logs.logsense2loki_failed_logs_total: Tracks the total number of logs that failed to parse or send.System -> Settings -> Logging -> Remote -> "+"

Configure LogSense2Loki using the following environment variables:
SYSLOG_HOST: The syslog server host (default: 0.0.0.0)SYSLOG_PORT: The syslog server port (default: 1540)LOKI_URL: The Grafana Loki URL (default: https://logs.domain.com/api/prom/push)GEOIP_DB_PATH: Path to the MaxMind GeoIP database (default: /geo/db/GeoLite2-City.mmdb)ENABLE_GEOIP: Enable (True) or disable (False) GeoIP lookups (default: False)config.py)SYSLOG_HOST = '0.0.0.0'
SYSLOG_PORT = 1540
LOKI_URL = 'https://logs.domain.com/api/prom/push'
GEOIP_DB_PATH = "/geo/db/GeoLite2-City.mmdb"
ENABLE_GEOIP = False
Here is a sample docker-compose.yml to get you started:
version: "2"
services:
LogSense2Loki:
image: badsmoke/logsense2loki
ports:
- 1540:1540
- 8100:8100
restart: always
volumes:
- ./geodb/:/geodb/
environment:
- SYSLOG_HOST=0.0.0.0
- SYSLOG_PORT=1540
- LOKI_URL=https://logs.domain.com/api/prom/push
- GEOIP_DB_PATH=/geo/db/GeoLite2-City.mmdb
- ENABLE_GEOIP=False
To run LogSense2Loki with the above configuration, use:
docker-compose up -d
Build the Docker image with the following command:
docker build -t logsense2loki .
To visualize the GeoIP data in Grafana Geomap, follow these steps:
Configure Data Source: Ensure your Loki data source is configured in Grafana.
Create a New Dashboard: Add a new panel using the Geomap plugin.
Data Query: Use a query that extracts the relevant GeoIP information. Example query:
{service="geoip"} |= "latitude" |= "longitude"


Styling and Visualization: Customize the appearance of your Geomap panel to suit your needs.
LogSense2Loki brings structure, insight, and performance to your logging infrastructure. With its powerful parsing, forwarding, GeoIP, and metric capabilities, it's an indispensable tool for any modern monitoring ecosystem.
This project is licensed under the MIT License.
Content type
Image
Digest
sha256:966edd70d…
Size
52.7 MB
Last updated
about 2 years ago
docker pull badsmoke/logsense2loki