Repository navigation
fix(mcp-query): recent_alerts applies the severity floor before the LIMIT - #98
Merged
Merged
Conversation
…IMIT recent_alerts took the newest LIMIT alert-class rows and only then dropped the ones below min_severity in Python. Every PAN-OS system log is alert-class (it carries panw.panos.severity) and most are informational, so on a busy fabric they fill the LIMIT and the tool returns zero rows with truncated=true while medium and high alerts sit in the window. The floor is now a ClickHouse expression in the WHERE, mirroring normalize_severity, which still labels each row. Junos screen (RT_SCREEN) rows were also all named "N/A": the signature came from rule_name, which is that literal for screens. The screen name is in event_action, which is now selected and used when there is no rule name. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
recent_alertscould return zero rows withtruncated: truewhile medium and high alerts sat in the window, and it named every Junos screen alertN/A.LIMITalert-class rows and dropped those belowmin_severityafterwards, in Python. Every PAN-OS system log is alert-class (it carriespanw.panos.severity) and most are informational, so on a busy fabric they fill theLIMITand nothing survives the filter.rule_name, which is the literalN/Afor RT_SCREEN rows. The screen name is inevent_action, which was never selected.Changes
alerts.py:SEVERITY_NUM_SQL, a ClickHouse expression mirroringnormalize_severity, is added to theWHEREas>= %(floor)s.normalize_severitystill labels each row and the Python floor stays as a second check.alerts.py: selectevent_action; signature falls backunifi.ips.signature→rule_name(unless empty orN/A) →event_action→event_kind.test_alerts.py: the floor is in theWHEREand in the params; an unknownmin_severityfloors at high; a screen row is named by its event action.Touches an MCP tool that reads
ssdf.events. No schema change and nothing changes for stored data. Visible behaviour changes: calls that returned nothing now return rows, and rows with no rule name (Junos screens, PAN-OS system logs) get their event action as the signature instead ofN/Aor the event kind.Verification
The built SQL was also run read-only against a live event store: the default call (
min_severity=high, 24h, limit 500) returned rows where the old query returned none, and aGROUP BYon the SQL expression matched the per-severity counts from the Python mapping.pip-auditdid not run (it cannot install the editableservices/commonrequirement); this change touches no dependency.Checklist
ruff check servicesandruff format --check servicespassssdf.events: called out aboveAnything you're unsure about
mediumin Python for PAN-OS, and falls through to the next rule in SQL. Both end atmediumunless the row also carriessyslog.severity.truncatedis stillfetched rows >= limit, which is now a count of matching rows, so it means what its name says.🤖 Generated with Claude Code