finish up opn watcher
This commit is contained in:
parent
81cefbd5df
commit
63c7c505f2
|
@ -1,6 +1,7 @@
|
|||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from typing import List
|
||||
|
@ -15,14 +16,17 @@ from checker.units import filesize
|
|||
|
||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||
|
||||
# pip install redis flask flask-caching
|
||||
|
||||
MAX_POINTS_PER_IP = 1900
|
||||
|
||||
OPNSENSE_URL = os.environ.get('OPN_URL')
|
||||
OPNSENSE_KEY = os.environ.get('OPN_KEY')
|
||||
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:
|
||||
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):
|
||||
|
|
|
@ -19,3 +19,6 @@ dnspython~=2.3.0
|
|||
cf-speedtest
|
||||
pytz~=2023.3
|
||||
proxmoxer==2.0.1
|
||||
gunicorn
|
||||
redis
|
||||
flask-caching
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue