update_log_parsing_rule
Modify an existing log parsing rule in New Relic to change its configuration, such as Grok patterns, NRQL queries, or enablement status.
Instructions
Update an existing log parsing rule
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rule_id | Yes | ||
| description | No | ||
| grok | No | ||
| nrql | No | ||
| enabled | No | ||
| lucene | No | ||
| account_id | No |
Implementation Reference
- newrelic_mcp/server.py:690-715 (handler)MCP tool handler decorated with @mcp.tool(), which handles input parameters, client validation, and delegates to the log_parsing helper function.@mcp.tool() async def update_log_parsing_rule( rule_id: str, description: Optional[str] = None, grok: Optional[str] = None, nrql: Optional[str] = None, enabled: Optional[bool] = None, lucene: Optional[str] = None, account_id: Optional[str] = None, ) -> str: """Update an existing log parsing rule""" if not client: return json.dumps({"error": "New Relic client not initialized"}) acct_id = account_id or client.account_id if not acct_id: return json.dumps({"error": "Account ID required but not provided"}) try: result = await log_parsing.update_log_parsing_rule( client, acct_id, rule_id, description, grok, nrql, enabled, lucene ) return json.dumps(result, indent=2) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
- newrelic_mcp/server.py:690-715 (registration)The @mcp.tool() decorator registers this function as an MCP tool named 'update_log_parsing_rule'.@mcp.tool() async def update_log_parsing_rule( rule_id: str, description: Optional[str] = None, grok: Optional[str] = None, nrql: Optional[str] = None, enabled: Optional[bool] = None, lucene: Optional[str] = None, account_id: Optional[str] = None, ) -> str: """Update an existing log parsing rule""" if not client: return json.dumps({"error": "New Relic client not initialized"}) acct_id = account_id or client.account_id if not acct_id: return json.dumps({"error": "Account ID required but not provided"}) try: result = await log_parsing.update_log_parsing_rule( client, acct_id, rule_id, description, grok, nrql, enabled, lucene ) return json.dumps(result, indent=2) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
- newrelic_mcp/log_parsing.py:457-517 (helper)Helper function that constructs and executes the GraphQL mutation to update a log parsing rule in New Relic via NerdGraph API.async def update_log_parsing_rule( client, account_id: str, rule_id: str, description: Optional[str] = None, grok: Optional[str] = None, nrql: Optional[str] = None, enabled: Optional[bool] = None, lucene: Optional[str] = None, ) -> Dict[str, Any]: """Update an existing log parsing rule""" # Build the update fields rule_fields = [] if description is not None: rule_fields.append(f'description: "{description}"') if enabled is not None: rule_fields.append(f"enabled: {str(enabled).lower()}") if grok is not None: # grok_escaped = grok.replace("\\", "\\\\") rule_fields.append(f'grok: "{grok}"') if lucene is not None: rule_fields.append(f'lucene: "{lucene}"') if nrql is not None: rule_fields.append(f'nrql: "{nrql}"') rule_object = "{ " + ", ".join(rule_fields) + " }" mutation = f""" mutation {{ logConfigurationsUpdateParsingRule( accountId: {int(account_id)}, id: "{rule_id}", rule: {rule_object} ) {{ rule {{ id description enabled grok lucene nrql updatedAt }} errors {{ message type }} }} }} """ result = await client.nerdgraph_query(mutation) if result and "data" in result: update_result = result["data"].get("logConfigurationsUpdateParsingRule", {}) if update_result.get("errors"): raise Exception(f"Failed to update rule: {update_result['errors']}") return update_result.get("rule", {}) raise Exception("Failed to update parsing rule")