mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
send alert on all key events
This commit is contained in:
parent
97626b1c89
commit
0f7d575992
3 changed files with 28 additions and 23 deletions
|
@ -29,8 +29,8 @@ from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
|
|||
from litellm.proxy._types import (
|
||||
AlertType,
|
||||
CallInfo,
|
||||
KeyCreatedEvent,
|
||||
UserAPIKeyAuth,
|
||||
VirtualKeyEvent,
|
||||
WebhookEvent,
|
||||
)
|
||||
from litellm.types.router import LiteLLM_Params
|
||||
|
@ -1797,7 +1797,7 @@ Model Info:
|
|||
|
||||
async def send_virtual_key_event_slack(
|
||||
self,
|
||||
key_event: KeyCreatedEvent,
|
||||
key_event: VirtualKeyEvent,
|
||||
event_name: str,
|
||||
):
|
||||
"""
|
||||
|
@ -1811,15 +1811,17 @@ Model Info:
|
|||
key_event_dict = key_event.model_dump()
|
||||
|
||||
# Add Created by information first
|
||||
message += "*Created by:*\n"
|
||||
message += "*Action Done by:*\n"
|
||||
for key, value in key_event_dict.items():
|
||||
if "created_by" in key:
|
||||
message += f"{key}: `{value}`\n"
|
||||
|
||||
# Add all non created by information next
|
||||
# Add args sent to function in the alert
|
||||
message += "\n*Arguments passed:*\n"
|
||||
for key, value in key_event_dict.items():
|
||||
if "created_by" not in key:
|
||||
request_kwargs = key_event.request_kwargs
|
||||
for key, value in request_kwargs.items():
|
||||
if key == "user_api_key_dict":
|
||||
continue
|
||||
message += f"{key}: `{value}`\n"
|
||||
|
||||
await self.send_alert(
|
||||
|
|
|
@ -1756,10 +1756,8 @@ class SSOUserDefinedValues(TypedDict):
|
|||
budget_duration: Optional[str]
|
||||
|
||||
|
||||
class KeyCreatedEvent(LiteLLMBase):
|
||||
class VirtualKeyEvent(LiteLLMBase):
|
||||
created_by_user_id: str
|
||||
created_by_user_role: str
|
||||
created_by_key_alias: Optional[str]
|
||||
key_alias: Optional[str]
|
||||
team_id: Optional[str]
|
||||
max_budget: Optional[float]
|
||||
request_kwargs: dict
|
||||
|
|
|
@ -13,7 +13,6 @@ from litellm.proxy._types import ( # key request types; user request types; tea
|
|||
DeleteCustomerRequest,
|
||||
DeleteTeamRequest,
|
||||
DeleteUserRequest,
|
||||
KeyCreatedEvent,
|
||||
KeyRequest,
|
||||
LiteLLM_TeamTable,
|
||||
ManagementEndpointLoggingPayload,
|
||||
|
@ -24,6 +23,7 @@ from litellm.proxy._types import ( # key request types; user request types; tea
|
|||
UpdateTeamRequest,
|
||||
UpdateUserRequest,
|
||||
UserAPIKeyAuth,
|
||||
VirtualKeyEvent,
|
||||
)
|
||||
from litellm.proxy.common_utils.http_parsing_utils import _read_request_body
|
||||
from litellm.proxy.utils import PrismaClient
|
||||
|
@ -203,24 +203,29 @@ async def send_management_endpoint_alert(
|
|||
if premium_user is not True:
|
||||
return
|
||||
|
||||
key_function_to_event_name = {
|
||||
"generate_key_fn": "Virtual Key Created",
|
||||
"update_key_fn": "Virtual Key Updated",
|
||||
"delete_key_fn": "Virtual Key Deleted",
|
||||
}
|
||||
|
||||
if (
|
||||
proxy_logging_obj is not None
|
||||
and proxy_logging_obj.slack_alerting_instance is not None
|
||||
):
|
||||
key_event = KeyCreatedEvent(
|
||||
|
||||
# Virtual Key Events
|
||||
if function_name in key_function_to_event_name:
|
||||
key_event = VirtualKeyEvent(
|
||||
created_by_user_id=user_api_key_dict.user_id or "Unknown",
|
||||
created_by_user_role=user_api_key_dict.user_role or "Unknown",
|
||||
created_by_key_alias=user_api_key_dict.key_alias,
|
||||
key_alias=request_kwargs.get("key_alias"),
|
||||
team_id=request_kwargs.get("team_id"),
|
||||
max_budget=request_kwargs.get("max_budget"),
|
||||
request_kwargs=request_kwargs,
|
||||
)
|
||||
|
||||
if function_name == "generate_key_fn":
|
||||
from litellm.proxy.proxy_server import proxy_logging_obj
|
||||
|
||||
event_name = key_function_to_event_name[function_name]
|
||||
await proxy_logging_obj.slack_alerting_instance.send_virtual_key_event_slack(
|
||||
key_event=key_event, event_name="Virtual Key Created"
|
||||
key_event=key_event, event_name=event_name
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue