reorganize

This commit is contained in:
Cyberes 2024-02-25 20:52:48 -07:00
parent 1044d76bf5
commit 4488e04b28
9 changed files with 75 additions and 17 deletions

View File

@ -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)

47
Other/auto-acknowledge-apt.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
# Check OPNsense network traffic for a host.
usage() {
echo "Usage: $0 --api <api_url> --user <username> --password <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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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