Add authentication to the ntfy hook

This commit is contained in:
Tom Hubrecht 2023-02-24 16:54:58 +01:00
parent 418ebc8843
commit a79c0b8441
1 changed files with 10 additions and 1 deletions

View File

@ -56,10 +56,19 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_
'X-Tags': state_config.get('tags'),
}
username = hook_config.get('username')
password = hook_config.get('password')
auth = (
requests.auth.HTTPBasicAuth(username, password)
if (username and password) is not None
else None
)
if not dry_run:
logging.getLogger('urllib3').setLevel(logging.ERROR)
try:
response = requests.post(f'{base_url}/{topic}', headers=headers)
response = requests.post(f'{base_url}/{topic}', headers=headers, auth=auth)
if not response.ok:
response.raise_for_status()
except requests.exceptions.RequestException as error: