update_log_parsing_rule
Modify existing log parsing rules to extract and structure log data for better analysis and monitoring in New Relic.
Instructions
Update an existing log parsing rule
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rule_id | Yes | ||
| description | No | ||
| grok | No | ||
| nrql | No | ||
| enabled | No | ||
| lucene | No | ||
| account_id | No |
Input Schema (JSON Schema)
{
"properties": {
"account_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Account Id"
},
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Description"
},
"enabled": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Enabled"
},
"grok": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Grok"
},
"lucene": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Lucene"
},
"nrql": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Nrql"
},
"rule_id": {
"title": "Rule Id",
"type": "string"
}
},
"required": [
"rule_id"
],
"type": "object"
}
Implementation Reference
- newrelic_mcp/server.py:690-715 (registration)Registers the 'update_log_parsing_rule' MCP tool with @mcp.tool() decorator. This wrapper handles client initialization, account ID resolution, and delegates to the core implementation in log_parsing module.@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-518 (handler)Core handler function that constructs and executes a NerdGraph GraphQL mutation to update a log parsing rule in New Relic. Handles dynamic field updates and error checking.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")