diff --git a/src/robusta/core/playbooks/internal/ai_integration.py b/src/robusta/core/playbooks/internal/ai_integration.py index 4c580b266..0d4550cb3 100644 --- a/src/robusta/core/playbooks/internal/ai_integration.py +++ b/src/robusta/core/playbooks/internal/ai_integration.py @@ -29,6 +29,7 @@ ) from robusta.core.schedule.model import FixedDelayRepeat from robusta.integrations.kubernetes.autogenerated.events import KubernetesAnyChangeEvent +from robusta.integrations.prometheus.models import PrometheusKubernetesAlert from robusta.integrations.prometheus.utils import HolmesDiscovery from robusta.utils.error_codes import ActionException, ErrorCodes @@ -40,6 +41,32 @@ def build_investigation_title(params: AIInvestigateParams) -> str: return params.context.get("issue_type", "unknown health issue") +@action +def auto_ask_holmes(event: ExecutionBaseEvent): + subject: FindingSubject = event.get_subject() + resource = ResourceInfo( + name=subject.name, + namespace=subject.namespace, + kind=str(subject.subject_type.value), + node=subject.node, + container=subject.container, + ) + issue_type = event.alert_name if isinstance(event, PrometheusKubernetesAlert) else type(event).__name__ + logging.warning(issue_type) + source = event.get_source() + + context = { + "issue_type": issue_type, + "source": str(source.value), + "labels": subject.labels, + } + + action_params = AIInvestigateParams( + resource=resource, investigation_type="issue", ask="Why is this alert firing?", context=context + ) + ask_holmes(event, params=action_params) + + @action def ask_holmes(event: ExecutionBaseEvent, params: AIInvestigateParams): holmes_url = HolmesDiscovery.find_holmes_url(params.holmes_url) @@ -167,7 +194,9 @@ def build_conversation_title(params: HolmesConversationParams) -> str: def add_labels_to_ask(params: HolmesConversationParams) -> str: - label_string = f"the alert has the following labels: {params.context.get('labels')}" if params.context.get("labels") else "" + label_string = ( + f"the alert has the following labels: {params.context.get('labels')}" if params.context.get("labels") else "" + ) ask = f"{params.ask}, {label_string}" if label_string else params.ask logging.debug(f"holmes ask query: {ask}") return ask