icinga2-checks/Other/auto-acknowledge-apt.py

33 lines
1.2 KiB
Python
Raw Normal View History

2023-04-21 23:54:20 -06:00
import argparse
import json
2024-02-25 20:52:48 -07:00
import time
2023-04-21 23:54:20 -06:00
import requests
from urllib3.exceptions import InsecureRequestWarning
parser = argparse.ArgumentParser(description='Check OPNsense network traffic for a host.')
parser.add_argument('--api', required=True, help='Full URL to your Icinga2 API.')
parser.add_argument('--user', required=True, help='API username.')
parser.add_argument('--password', required=True, help='API password.')
args = parser.parse_args()
2024-02-25 20:52:48 -07:00
# Acknowledge all services that meet this filter.
2023-04-21 23:54:20 -06:00
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
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
}
2024-02-25 20:52:48 -07:00
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)