reorganize
This commit is contained in:
parent
1044d76bf5
commit
4488e04b28
|
@ -1,5 +1,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from urllib3.exceptions import InsecureRequestWarning
|
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.')
|
parser.add_argument('--password', required=True, help='API password.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Retrieve a list of unacknowledged alerts
|
# Acknowledge all services that meet this filter.
|
||||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||||
payload = {
|
payload = {
|
||||||
"type": "Service",
|
"type": "Service",
|
||||||
|
@ -21,12 +22,11 @@ payload = {
|
||||||
"pretty": True
|
"pretty": True
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send the API request
|
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)
|
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:
|
if response.status_code == 200:
|
||||||
print("All pending alerts have been acknowledged.")
|
print("All pending alerts have been acknowledged.")
|
||||||
else:
|
else:
|
||||||
print("Failed to acknowledge the alerts. Status code:", response.status_code)
|
print("Failed to acknowledge the alerts. Status code:", response.status_code)
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
time.sleep(60)
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -4,9 +4,9 @@ After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=flask
|
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
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,10 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
User=flask
|
User=flask
|
||||||
Environment="ICINGA2KUMA_ICINGA2_PW=[your icinga2 API password]"
|
Environment="ICINGA2KUMA_ICINGA2_PW=[your icinga2 API password]"
|
||||||
WorkingDirectory=/opt/icinga2-checks
|
WorkingDirectory=/opt/icinga2-checks/Other
|
||||||
ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8081 -w 4 icinga2kuma:app
|
ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/gunicorn -b 0.0.0.0:8081 -w 4 icinga2kuma:app
|
||||||
|
SyslogIdentifier=icinga2kuma
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ 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/icinga2-checks/opnsense_traffic_watcher.py --daemon
|
ExecStart=/opt/venvs/icinga2/icinga2_checks/bin/python3 /opt/icinga2-checks/opnsense_traffic_watcher.py --daemon
|
||||||
|
SyslogIdentifier=onsense-watcher-daemon
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ Environment="OPN_KEY=[your OPNsense key]"
|
||||||
Environment="OPN_SECRET=[your OPNsense secret]"
|
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
|
||||||
|
SyslogIdentifier=onsense-watcher-server
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue