fix some stuff
This commit is contained in:
parent
63c7c505f2
commit
0f0e65e272
|
@ -11,7 +11,6 @@ import checker.nagios as nagios
|
||||||
from checker import print_icinga2_check_status
|
from checker import print_icinga2_check_status
|
||||||
from checker.http import fetch_with_retry
|
from checker.http import fetch_with_retry
|
||||||
from checker.linuxfabric.base import get_state
|
from checker.linuxfabric.base import get_state
|
||||||
from checker.markdown import list_to_markdown_table
|
|
||||||
from checker.units import filesize
|
from checker.units import filesize
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,10 +82,6 @@ def main():
|
||||||
ok = []
|
ok = []
|
||||||
perf_data = {}
|
perf_data = {}
|
||||||
|
|
||||||
output_table = [
|
|
||||||
('Max Rate In', 'Max Rate Out', 'Cumulative In', 'Cumulative Out', 'Connections', 'Status')
|
|
||||||
]
|
|
||||||
|
|
||||||
def check(name, state, value, do_filesize=True):
|
def check(name, state, value, do_filesize=True):
|
||||||
# TODO: improve this its kinda messy
|
# TODO: improve this its kinda messy
|
||||||
def do_value(v):
|
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 = check(f'connections', conn_state, check_result['connections'], do_filesize=False)
|
||||||
conn_exit_code = 0
|
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_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'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_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'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}
|
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])
|
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)
|
print_icinga2_check_status(text_result, exit_code, perf_data)
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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
|
||||||
|
@ -23,8 +22,7 @@ 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:
|
if not OPNSENSE_URL or not OPNSENSE_KEY or not OPNSENSE_URL:
|
||||||
print('Missing environment variables')
|
raise Exception('Missing environment variables')
|
||||||
sys.exit(1)
|
|
||||||
OPNSENSE_URL = OPNSENSE_URL.strip('/')
|
OPNSENSE_URL = OPNSENSE_URL.strip('/')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=flask
|
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_KEY=[your OPNsense key]"
|
||||||
Environment="OPN_SECRET=[your OPNsense secret]"
|
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
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|
|
@ -4,6 +4,9 @@ After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=flask
|
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
|
WorkingDirectory=/opt/icinga2-checks
|
||||||
ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/gunicorn -b 0.0.0.0:8082 -w 4 opnsense_traffic_watcher:app
|
ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/gunicorn -b 0.0.0.0:8082 -w 4 opnsense_traffic_watcher:app
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
Loading…
Reference in New Issue