fix some stuff

This commit is contained in:
Cyberes 2023-11-19 17:19:26 -07:00
parent 63c7c505f2
commit 0f0e65e272
4 changed files with 6 additions and 27 deletions

View File

@ -11,7 +11,6 @@ import checker.nagios as nagios
from checker import print_icinga2_check_status
from checker.http import fetch_with_retry
from checker.linuxfabric.base import get_state
from checker.markdown import list_to_markdown_table
from checker.units import filesize
@ -83,10 +82,6 @@ def main():
ok = []
perf_data = {}
output_table = [
('Max Rate In', 'Max Rate Out', 'Cumulative In', 'Cumulative Out', 'Connections', 'Status')
]
def check(name, state, value, do_filesize=True):
# TODO: improve this its kinda messy
def do_value(v):
@ -117,30 +112,13 @@ def main():
conn_exit_code = check(f'connections', conn_state, check_result['connections'], do_filesize=False)
conn_exit_code = 0
interface_status_code = max(in_exit_code, out_exit_code, conn_exit_code)
if interface_status_code == nagios.STATE_OK:
interface_status = '[OK]'
elif interface_status_code == nagios.STATE_WARN:
interface_status = '[WARNING]'
elif interface_status_code == nagios.STATE_CRIT:
interface_status = '[CRITICAL]'
else:
interface_status = '[UNKNOWN]'
perf_data[f'max_rate_in'] = {'value': int(check_result["rate_in"]), 'warn': warn_b_value, 'crit': crit_b_value, 'min': 0, 'unit': 'B'}
perf_data[f'max_rate_out'] = {'value': int(check_result["rate_out"]), 'warn': warn_b_value, 'crit': crit_b_value, 'min': 0, 'unit': 'B'}
perf_data[f'cumulative_in'] = {'value': int(check_result["cumulative_in"]), 'warn': warn_b_value, 'crit': crit_b_value, 'min': 0, 'unit': 'B'}
perf_data[f'cumulative_out'] = {'value': int(check_result["cumulative_out"]), 'warn': warn_b_value, 'crit': crit_b_value, 'min': 0, 'unit': 'B'}
perf_data[f'connections'] = {'value': int(check_result["connections"]), 'warn': conn_warn, 'crit': conn_crit, 'min': 0}
output_table.append((filesize(check_result['rate_in']), filesize(check_result['rate_out']),
filesize(check_result['cumulative_in']), filesize(check_result['cumulative_out']), check_result['connections'],
interface_status))
text_result = ', '.join(f'{name}: {rate}' for name, rate in [*critical, *warn, *ok])
if len(check_result) > 1:
text_result = text_result + '\n' + list_to_markdown_table(output_table, align='left', seperator='!', borders=False)
print_icinga2_check_status(text_result, exit_code, perf_data)
sys.exit(exit_code)

View File

@ -1,7 +1,6 @@
import argparse
import json
import os
import sys
import threading
import time
from typing import List
@ -23,8 +22,7 @@ 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)
raise Exception('Missing environment variables')
OPNSENSE_URL = OPNSENSE_URL.strip('/')

View File

@ -4,10 +4,10 @@ After=network.target
[Service]
User=flask
Environment="OPN_URL=https://10.0.0.1
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
ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/python3 /opt/icinga2-checks/opnsense_traffic_watcher.py --daemon
Restart=always
[Install]

View File

@ -4,6 +4,9 @@ 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]"
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