From 4488e04b28ea735e5bbf11161b4f5a8282ad5588 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sun, 25 Feb 2024 20:52:48 -0700 Subject: [PATCH] reorganize --- Other/auto-acknowledge-apt.py | 20 +++++----- Other/auto-acknowledge-apt.sh | 47 ++++++++++++++++++++++++ fail-overdue.py => Other/fail-overdue.py | 0 icinga2kuma.py => Other/icinga2kuma.py | 0 services/auto-acknowledge-apt.service | 11 ++++++ services/failoverdue.service | 4 +- services/icinga2kuma.service | 6 +-- services/opnsense-watcher-daemon.service | 2 +- services/opnsense-watcher.service | 2 +- 9 files changed, 75 insertions(+), 17 deletions(-) create mode 100755 Other/auto-acknowledge-apt.sh rename fail-overdue.py => Other/fail-overdue.py (100%) rename icinga2kuma.py => Other/icinga2kuma.py (100%) create mode 100644 services/auto-acknowledge-apt.service diff --git a/Other/auto-acknowledge-apt.py b/Other/auto-acknowledge-apt.py index 9c8d84a..593c9c0 100755 --- a/Other/auto-acknowledge-apt.py +++ b/Other/auto-acknowledge-apt.py @@ -1,5 +1,6 @@ import argparse import json +import time import requests from urllib3.exceptions import InsecureRequestWarning @@ -10,7 +11,7 @@ parser.add_argument('--user', required=True, help='API username.') parser.add_argument('--password', required=True, help='API password.') args = parser.parse_args() -# Retrieve a list of unacknowledged alerts +# Acknowledge all services that meet this filter. requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) payload = { "type": "Service", @@ -21,12 +22,11 @@ payload = { "pretty": True } -# Send the API request -response = requests.post(f'{args.api}/v1/actions/acknowledge-problem', headers={"Accept": "application/json"}, auth=(args.user, args.password), data=json.dumps(payload), verify=False) - -# Check the response status code -if response.status_code == 200: - print("All pending alerts have been acknowledged.") -else: - print("Failed to acknowledge the alerts. Status code:", response.status_code) - print(response.text) +while True: + response = requests.post(f'{args.api}/v1/actions/acknowledge-problem', headers={"Accept": "application/json"}, auth=(args.user, args.password), data=json.dumps(payload), verify=False) + if response.status_code == 200: + print("All pending alerts have been acknowledged.") + else: + print("Failed to acknowledge the alerts. Status code:", response.status_code) + print(response.text) + time.sleep(60) diff --git a/Other/auto-acknowledge-apt.sh b/Other/auto-acknowledge-apt.sh new file mode 100755 index 0000000..a389dba --- /dev/null +++ b/Other/auto-acknowledge-apt.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Check OPNsense network traffic for a host. +usage() { + echo "Usage: $0 --api --user --password " + exit 1 +} + +while [ "$1" != "" ]; do + case $1 in + --api ) shift + api=$1 + ;; + --user ) shift + user=$1 + ;; + --password ) shift + password=$1 + ;; + * ) usage + esac + shift +done + +if [ -z "$api" ] || [ -z "$user" ] || [ -z "$password" ]; then + usage +fi + +# Acknowledge all services that meet this filter. +payload='{ + "type": "Service", + "filter": "service.name == \"apt\" && service.acknowledgement == 0", + "author": "Auto-Acknowledgement Script", + "comment": "This alert has been automatically acknowledged.", + "notify": true, + "pretty": true +}' + +while true; do + response=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Accept: application/json" -u "$user:$password" -d "$payload" -k "$api/v1/actions/acknowledge-problem") + if [ "$response" == "200" ]; then + echo "All pending alerts have been acknowledged." + else + echo "Failed to acknowledge the alerts. Status code: $response" + fi + sleep 60 +done diff --git a/fail-overdue.py b/Other/fail-overdue.py similarity index 100% rename from fail-overdue.py rename to Other/fail-overdue.py diff --git a/icinga2kuma.py b/Other/icinga2kuma.py similarity index 100% rename from icinga2kuma.py rename to Other/icinga2kuma.py diff --git a/services/auto-acknowledge-apt.service b/services/auto-acknowledge-apt.service new file mode 100644 index 0000000..5ddb1a1 --- /dev/null +++ b/services/auto-acknowledge-apt.service @@ -0,0 +1,11 @@ +[Unit] +Description=Auto Acknowledge all Icinga2 apt alerts + +[Service] +User=flask +ExecStart=/opt/icinga2-checks/Other/auto-acknowledge-apt.sh --api https://localhost:5665 --user icingaweb2 --password queeyahnahz3Zie1 +SyslogIdentifier=auto-acknowledge-apt +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/services/failoverdue.service b/services/failoverdue.service index 597e25f..89c027b 100644 --- a/services/failoverdue.service +++ b/services/failoverdue.service @@ -4,9 +4,9 @@ After=network.target [Service] User=flask -ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/python3 /opt/icinga2-checks/fail-overdue.py --password XXXXX --insecure +ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/python3 /opt/icinga2-checks/Other/fail-overdue.py --password XXXXX --insecure +SyslogIdentifier=failoverdue Restart=always [Install] WantedBy=multi-user.target - diff --git a/services/icinga2kuma.service b/services/icinga2kuma.service index e9acc82..685d5d0 100644 --- a/services/icinga2kuma.service +++ b/services/icinga2kuma.service @@ -5,10 +5,10 @@ After=network.target [Service] User=flask Environment="ICINGA2KUMA_ICINGA2_PW=[your icinga2 API password]" -WorkingDirectory=/opt/icinga2-checks -ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8081 -w 4 icinga2kuma:app +WorkingDirectory=/opt/icinga2-checks/Other +ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/gunicorn -b 0.0.0.0:8081 -w 4 icinga2kuma:app +SyslogIdentifier=icinga2kuma Restart=always [Install] WantedBy=multi-user.target - diff --git a/services/opnsense-watcher-daemon.service b/services/opnsense-watcher-daemon.service index 937c5f7..abd5f17 100644 --- a/services/opnsense-watcher-daemon.service +++ b/services/opnsense-watcher-daemon.service @@ -8,8 +8,8 @@ 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/icinga2-checks/opnsense_traffic_watcher.py --daemon +SyslogIdentifier=onsense-watcher-daemon Restart=always [Install] WantedBy=multi-user.target - diff --git a/services/opnsense-watcher.service b/services/opnsense-watcher.service index be94814..d7a3cc5 100644 --- a/services/opnsense-watcher.service +++ b/services/opnsense-watcher.service @@ -9,8 +9,8 @@ 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 +SyslogIdentifier=onsense-watcher-server Restart=always [Install] WantedBy=multi-user.target -