Add authentication to the ntfy hook
This commit is contained in:
parent
418ebc8843
commit
d80e716822
2 changed files with 20 additions and 1 deletions
|
@ -1029,6 +1029,16 @@ properties:
|
||||||
description: |
|
description: |
|
||||||
The address of your self-hosted ntfy.sh instance.
|
The address of your self-hosted ntfy.sh instance.
|
||||||
example: https://ntfy.your-domain.com
|
example: https://ntfy.your-domain.com
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
The username used for authentication.
|
||||||
|
example: testuser
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
The password used for authentication.
|
||||||
|
example: fakepassword
|
||||||
start:
|
start:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -56,10 +56,19 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_
|
||||||
'X-Tags': state_config.get('tags'),
|
'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:
|
if not dry_run:
|
||||||
logging.getLogger('urllib3').setLevel(logging.ERROR)
|
logging.getLogger('urllib3').setLevel(logging.ERROR)
|
||||||
try:
|
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:
|
if not response.ok:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except requests.exceptions.RequestException as error:
|
except requests.exceptions.RequestException as error:
|
||||||
|
|
Loading…
Reference in a new issue