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
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()
# Retrieve a list of unacknowledged alerts
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
}
# 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)