Skip to main content
Glama
piekstra

New Relic MCP Server

by piekstra

test_log_parsing_rule

Validate log parsing rules against sample logs to ensure accurate data extraction in New Relic monitoring. Automatically generates patterns when needed.

Instructions

Test a log parsing rule against sample logs. If no grok_pattern is provided, it will generate one automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
log_samplesYes
grok_patternNo
account_idNo

Implementation Reference

  • MCP tool handler decorated with @mcp.tool(). Handles input validation for client and account_id, delegates to core helper in log_parsing.py, serializes result to JSON.
    @mcp.tool() async def test_log_parsing_rule( log_samples: List[str], grok_pattern: Optional[str] = None, account_id: Optional[str] = None, ) -> str: """ Test a log parsing rule against sample logs. If no grok_pattern is provided, it will generate one automatically. """ 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.test_log_parsing_rule( client, acct_id, log_samples, grok_pattern ) return json.dumps(result, indent=2) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
  • Core helper function implementing the log parsing rule testing logic: generates or converts GROK pattern to NRQL, executes test query on New Relic logs, returns patterns and test results.
    async def test_log_parsing_rule( client, account_id: str, log_samples: List[str], grok_pattern: Optional[str] = None ) -> Dict[str, Any]: """ Test a log parsing rule against sample logs If no grok_pattern is provided, it will generate one automatically """ generator = GrokPatternGenerator() if not grok_pattern: # Generate pattern from samples grok_pattern, nrql_pattern = generator.generate_grok_pattern(log_samples) else: # Generate NRQL pattern from existing GROK nrql_pattern = grok_pattern # Simple conversion - replace GROK patterns with % nrql_pattern = re.sub(r"%\{[^}]+\}", "%", nrql_pattern) # Test the pattern by querying logs test_query = f""" SELECT count(*) as matching_logs FROM Log WHERE message LIKE '{nrql_pattern}' SINCE 1 hour ago """ result = await client.query_nrql(account_id, test_query) return { "grok_pattern": grok_pattern, "nrql_pattern": nrql_pattern, "test_results": result, "sample_count": len(log_samples), }
  • Registration of the tool using @mcp.tool() decorator.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/piekstra/newrelic-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server