Refactor get_monitored_events to dict to incl supported variables

Update panel_handler to account for type change to get_monitored_events
This commit is contained in:
Zedifus 2024-04-21 17:53:27 +01:00
parent ae4f806bac
commit 915245bbff
2 changed files with 29 additions and 21 deletions

View File

@ -731,7 +731,9 @@ class PanelHandler(BaseHandler):
server_id, model=True server_id, model=True
) )
) )
page_data["triggers"] = WebhookFactory.get_monitored_events() page_data["triggers"] = list(
WebhookFactory.get_monitored_events().keys()
)
def get_banned_players_html(): def get_banned_players_html():
banned_players = self.controller.servers.get_banned_players(server_id) banned_players = self.controller.servers.get_banned_players(server_id)
@ -1041,7 +1043,7 @@ class PanelHandler(BaseHandler):
page_data["webhook"]["enabled"] = True page_data["webhook"]["enabled"] = True
page_data["providers"] = WebhookFactory.get_supported_providers() page_data["providers"] = WebhookFactory.get_supported_providers()
page_data["triggers"] = WebhookFactory.get_monitored_events() page_data["triggers"] = list(WebhookFactory.get_monitored_events().keys())
if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]: if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]:
if not superuser: if not superuser:
@ -1092,7 +1094,7 @@ class PanelHandler(BaseHandler):
).split(",") ).split(",")
page_data["providers"] = WebhookFactory.get_supported_providers() page_data["providers"] = WebhookFactory.get_supported_providers()
page_data["triggers"] = WebhookFactory.get_monitored_events() page_data["triggers"] = list(WebhookFactory.get_monitored_events().keys())
if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]: if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]:
if not superuser: if not superuser:

View File

@ -68,17 +68,23 @@ class WebhookFactory:
Retrieves the list of supported events for monitoring. Retrieves the list of supported events for monitoring.
This method provides a list of common server events that the webhook system can This method provides a list of common server events that the webhook system can
monitor and notify about. monitor and notify about. Along with the available `event_data` vars for use
on the frontend.
Returns: Returns:
List[str]: A list of supported monitored actions. dict: A dictionary where each key is an event name and the value is a
dictionary containing a list of `variables` for that event.
These variables are intended for use in the frontend to show whats
available.
""" """
return [ return {
"start_server", "start_server": {"variables": ["server_name", "user", "timestamp"]},
"stop_server", "stop_server": {"variables": ["server_name", "user", "timestamp"]},
"crash_detected", "crash_detected": {"variables": ["server_name", "user", "timestamp"]},
"backup_server", "backup_server": {"variables": ["server_name", "user", "timestamp"]},
"jar_update", "jar_update": {"variables": ["server_name", "user", "timestamp"]},
"send_command", "send_command": {
"kill", "variables": ["server_name", "user", "command", "timestamp"]
] },
"kill": {"variables": ["server_name", "user", "timestamp"]},
}