Conversation
**Added:**
- Introduced `create_detection_rule` method to GrafanaTools for creating alert
rules via the provisioning API, including label validation, severity handling,
and automatic folder management
- Added `_ensure_alert_folder` helper to automatically manage the alert rule
folder in Grafana
- Implemented `_is_mitre_technique_description` utility to skip MITRE technique
descriptions during evidence value validation
**Changed:**
- Updated evidence validation logic to skip validation for MITRE technique
description values and log the action for transparency
- Improved documentation and step-by-step instructions in
`system_instructions.md.jinja`:
- Emphasized mandatory label discovery before querying logs
- Updated LogQL performance advice and provided concrete selector examples
- Clarified and reordered investigation workflow steps for better clarity
- Provided explicit examples for Windows event log queries with correct label usage
- Added section detailing when and how to create alert rules using the new
`create_detection_rule` tool
- Changed default label selector in `QueryTemplateTools` from a broad
`{job=~".+"}` to `{job="eventlog"}` for better performance and safer queries
**Removed:**
- Removed outdated examples and advice using broad label selectors from
documentation in favor of specific, performant patterns
**Changed:** - Removed redundant or obvious comments that restated code actions across multiple modules, including alert correlation, evidence validation, query templates, and factory files, to enhance readability and reduce noise - Improved clarity by keeping only non-obvious comments or those with explanatory value
…ry usage
**Added:**
- Added '{hostname=~".+"}' to list of broad selector patterns to detect more
problematic queries
- Updated logic to auto-rewrite broad LogQL selectors to '{job="eventlog"}'
instead of just warning, reducing risk of timeouts
- Modified query handling to update kwargs with the optimized query if
rewriting occurs, ensuring downstream code uses the corrected query
**Changed:**
- Changed _optimize_logql_query docstring to clarify that it now rewrites
queries for safety rather than just warning
- Adjusted logging messages to reflect that queries are auto-rewritten instead
of only warning the user
- Improved pattern matching to allow multiple broad selectors in a single
query to be rewritten, rather than stopping after the first
- Ensured duplicate query checking and later logic operates on the optimized
query when a rewrite occurs
CAP-835 Optimize Blue Agent Loki Querying and Evidence Validation
Description: Objective: Reduce query timeouts and duplication while improving evidence validation accuracy and query efficiency in the Blue Agent's Loki integration. Scope of Work:
Dependencies:
Acceptance Criteria:
Additional Notes:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Key Changes:
create_detection_ruletool for automated Grafana alert rule creationAdded:
create_detection_ruleasync method toGrafanaToolsfor creating alert rules basedon investigation findings, with validation for label selectors, severity, and folder
management
_ensure_alert_folderinternal helper to automatically provision the requiredGrafana folder for new alert rules
_is_mitre_technique_descriptionto skip validation for MITRE technique IDs (they'reclassifications, not raw log data)
{deployment=~".+"}, etc.) to{job="eventlog"}to prevent query timeouts
guidance on when and how to use
create_detection_rule, with examplesChanged:
system_instructions.md.jinjato require label discovery(using
list_loki_label_namesandlist_loki_label_values) before running queries,and to use only specific labels like
{job="eventlog"}to avoid timeoutsexamples for contains (
|=) vs regex (|~) usage, combining queries, and avoidinganti-patterns
QueryTemplateToolsto{job="eventlog"}insteadof broad patterns, and clarified override instructions
before execution
Removed:
in query templates and agent instructions
evidence recording or label discovery