fix(monitoring): support existing monitor updates and vault nodes
- setup_uptime_kuma: Use api.edit_monitor to update existing monitors with new configuration instead of skipping them. - setup_uptime_kuma: Add port and accepted_statuscodes to DNS monitors to prevent NodeJS null reading errors in Kuma. - http.py: Parse VAULT_HOSTS environment variable for Vault cluster nodes instead of hardcoding 'vault'.
This commit is contained in:
parent
2a482ce4df
commit
b49ca276f0
@ -145,12 +145,22 @@ def setup_uptime_kuma(dry_run=False, only=None):
|
||||
logger.info(f"Processing push monitor: {m_name}")
|
||||
if not dry_run:
|
||||
if m_name in existing_monitors:
|
||||
logger.info(f"Monitor {m_name} already exists.")
|
||||
logger.info(f"Monitor {m_name} already exists. Updating...")
|
||||
m_id = existing_monitors[m_name]['id']
|
||||
tokens[m_name] = existing_monitors[m_name]['pushToken']
|
||||
|
||||
if parent_group_id and existing_monitors[m_name].get('parent') != parent_group_id:
|
||||
api.edit_monitor(m_id, parent=parent_group_id)
|
||||
kwargs = {
|
||||
"interval": m_interval
|
||||
}
|
||||
if parent_group_id:
|
||||
kwargs["parent"] = parent_group_id
|
||||
if notif_ids:
|
||||
kwargs["notificationIDList"] = notif_ids
|
||||
|
||||
try:
|
||||
api.edit_monitor(m_id, **kwargs)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to edit push monitor {m_name}: {e}")
|
||||
else:
|
||||
logger.info(f"Creating push monitor: {m_name}")
|
||||
kwargs = {
|
||||
@ -194,7 +204,23 @@ def setup_uptime_kuma(dry_run=False, only=None):
|
||||
logger.info(f"Processing HTTP monitor: {m_name} -> {url}")
|
||||
if not dry_run:
|
||||
if m_name in existing_monitors:
|
||||
logger.info(f"Monitor {m_name} already exists.")
|
||||
logger.info(f"Monitor {m_name} already exists. Updating...")
|
||||
m_id = existing_monitors[m_name]['id']
|
||||
kwargs = {
|
||||
"type": MonitorType.HTTP,
|
||||
"name": m_name,
|
||||
"url": url,
|
||||
"interval": interval,
|
||||
"accepted_statuscodes": accepted_statuscodes,
|
||||
}
|
||||
if parent_group_id is not None:
|
||||
kwargs["parent"] = parent_group_id
|
||||
if notif_ids:
|
||||
kwargs["notificationIDList"] = notif_ids
|
||||
try:
|
||||
api.edit_monitor(m_id, **kwargs)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to edit HTTP monitor {m_name}: {e}")
|
||||
else:
|
||||
try:
|
||||
kwargs = {
|
||||
@ -227,13 +253,33 @@ def setup_uptime_kuma(dry_run=False, only=None):
|
||||
logger.info(f"Processing DNS monitor: {m_name} -> {hostname}")
|
||||
if not dry_run:
|
||||
if m_name in existing_monitors:
|
||||
logger.info(f"Monitor {m_name} already exists.")
|
||||
logger.info(f"Monitor {m_name} already exists. Updating...")
|
||||
m_id = existing_monitors[m_name]['id']
|
||||
kwargs = {
|
||||
"type": MonitorType.DNS,
|
||||
"name": m_name,
|
||||
"hostname": hostname,
|
||||
"port": 53,
|
||||
"accepted_statuscodes": ["200-299"],
|
||||
"dns_resolve_type": dns_resolve_type,
|
||||
"interval": interval,
|
||||
}
|
||||
if parent_group_id is not None:
|
||||
kwargs["parent"] = parent_group_id
|
||||
if notif_ids:
|
||||
kwargs["notificationIDList"] = notif_ids
|
||||
try:
|
||||
api.edit_monitor(m_id, **kwargs)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to edit DNS monitor {m_name}: {e}")
|
||||
else:
|
||||
try:
|
||||
kwargs = {
|
||||
"type": MonitorType.DNS,
|
||||
"name": m_name,
|
||||
"hostname": hostname,
|
||||
"port": 53,
|
||||
"accepted_statuscodes": ["200-299"],
|
||||
"dns_resolve_type": dns_resolve_type,
|
||||
"interval": interval,
|
||||
}
|
||||
@ -263,7 +309,23 @@ def setup_uptime_kuma(dry_run=False, only=None):
|
||||
logger.info(f"Processing Ping monitor: {m_name} -> {ip}")
|
||||
if not dry_run:
|
||||
if m_name in existing_monitors:
|
||||
logger.info(f"Monitor {m_name} already exists.")
|
||||
logger.info(f"Monitor {m_name} already exists. Updating...")
|
||||
m_id = existing_monitors[m_name]['id']
|
||||
kwargs = {
|
||||
"type": MonitorType.PING,
|
||||
"name": m_name,
|
||||
"hostname": ip,
|
||||
"interval": ping_interval,
|
||||
"maxretries": ping_retries,
|
||||
}
|
||||
if parent_group_id is not None:
|
||||
kwargs["parent"] = parent_group_id
|
||||
if notif_ids:
|
||||
kwargs["notificationIDList"] = notif_ids
|
||||
try:
|
||||
api.edit_monitor(m_id, **kwargs)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to edit Ping monitor {m_name}: {e}")
|
||||
else:
|
||||
try:
|
||||
kwargs = {
|
||||
@ -293,7 +355,23 @@ def setup_uptime_kuma(dry_run=False, only=None):
|
||||
logger.info(f"Processing Ping monitor: {m_name} -> {ip}")
|
||||
if not dry_run:
|
||||
if m_name in existing_monitors:
|
||||
logger.info(f"Monitor {m_name} already exists.")
|
||||
logger.info(f"Monitor {m_name} already exists. Updating...")
|
||||
m_id = existing_monitors[m_name]['id']
|
||||
kwargs = {
|
||||
"type": MonitorType.PING,
|
||||
"name": m_name,
|
||||
"hostname": ip,
|
||||
"interval": ping_interval,
|
||||
"maxretries": ping_retries,
|
||||
}
|
||||
if parent_group_id is not None:
|
||||
kwargs["parent"] = parent_group_id
|
||||
if notif_ids:
|
||||
kwargs["notificationIDList"] = notif_ids
|
||||
try:
|
||||
api.edit_monitor(m_id, **kwargs)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to edit Ping monitor {m_name}: {e}")
|
||||
else:
|
||||
try:
|
||||
kwargs = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user