finish up opn watcher

This commit is contained in:
Cyberes 2023-11-19 16:38:20 -07:00
parent 81cefbd5df
commit 63c7c505f2
4 changed files with 37 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import argparse import argparse
import json import json
import os import os
import sys
import threading import threading
import time import time
from typing import List from typing import List
@ -15,14 +16,17 @@ from checker.units import filesize
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
# pip install redis flask flask-caching
MAX_POINTS_PER_IP = 1900 MAX_POINTS_PER_IP = 1900
OPNSENSE_URL = os.environ.get('OPN_URL') OPNSENSE_URL = os.environ.get('OPN_URL')
OPNSENSE_KEY = os.environ.get('OPN_KEY') OPNSENSE_KEY = os.environ.get('OPN_KEY')
OPNSENSE_SECRET = os.environ.get('OPN_SECRET') OPNSENSE_SECRET = os.environ.get('OPN_SECRET')
if not OPNSENSE_URL or not OPNSENSE_KEY or not OPNSENSE_URL:
print('Missing environment variables')
sys.exit(1)
OPNSENSE_URL = OPNSENSE_URL.strip('/')
class TrafficEntry: class TrafficEntry:
def __init__(self, interface: str, address: str, rate_bits_in: int, rate_bits_out: int, rate_bits: int, cumulative_bytes_in: int, cumulative_bytes_out: int, cumulative_bytes: int, connections: dict, timestamp: float): def __init__(self, interface: str, address: str, rate_bits_in: int, rate_bits_out: int, rate_bits: int, cumulative_bytes_in: int, cumulative_bytes_out: int, cumulative_bytes: int, connections: dict, timestamp: float):

View File

@ -19,3 +19,6 @@ dnspython~=2.3.0
cf-speedtest cf-speedtest
pytz~=2023.3 pytz~=2023.3
proxmoxer==2.0.1 proxmoxer==2.0.1
gunicorn
redis
flask-caching

View File

@ -0,0 +1,15 @@
[Unit]
Description=OPNsense watcher daemon
After=network.target
[Service]
User=flask
Environment="OPN_URL=https://10.0.0.1
Environment="OPN_KEY=[your OPNsense key]"
Environment="OPN_SECRET=[your OPNsense secret]"
ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/python3 /opt/venvs/icinga2/icinga2_checks/opnsense_traffic_watcher.py --daemon
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,13 @@
[Unit]
Description=OPNsense watcher server
After=network.target
[Service]
User=flask
WorkingDirectory=/opt/icinga2-checks
ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/gunicorn -b 0.0.0.0:8082 -w 4 opnsense_traffic_watcher:app
Restart=always
[Install]
WantedBy=multi-user.target