A comprehensive Python agent for querying Azure Monitor Log Analytics using both direct KQL and natural language (NL) questions. Features multiple interfaces including CLI, web UI, REST API, and MCP server integration for AI assistants.
- Multiple Interfaces: CLI, Beautiful Web UI, REST API, and MCP Server
- Natural Language Queries: Ask questions in plain English, get KQL results
- Enhanced Table Display: Beautiful HTML tables with professional styling (NEW!)
- Smart Retry Logic: Automatic retries improve translation success rates
- Smart Timespan Detection: Automatically handles queries with time filters
- Example-Driven Translation: Uses curated KQL examples for accurate translations
- Azure OpenAI Integration: Powered by Azure OpenAI with o4-mini model support
- Real-time Results: Interactive web interface with live query execution
- Workspace Management: Easy setup and connection testing
- Defensive Error Handling: Robust error handling and result parsing
- Python 3.8+
- Azure CLI (for authentication)
- Azure Log Analytics Workspace
- Azure OpenAI resource (for NL-to-KQL translation)
- Clone this repository and enter the directory:
git clone <your-repo-url> cd NoaAzMonAgent
- Install dependencies:
pip install -r requirements.txt - Set environment variables for Azure OpenAI (see code comments for required variables).
The easiest way to get started with a beautiful, interactive web interface:
# Install dependencies
pip install -r requirements.txt
# Launch web interface
python launch_web.pyThen open your browser to http://localhost:5000 and enjoy the modern web UI!
Web Interface Features:
- π¨ Beautiful, responsive design
- π¬ Natural language question input
- π Interactive workspace setup
- π‘ Quick suggestion pills
- π Built-in example queries
- β‘ Real-time results display
- π§ͺ Connection testing
For terminal-based interactions:
python server_manager.py agentpython server_manager.py http
# Available at http://localhost:8080python server_manager.py mcp- Start the web interface:
python launch_web.py - Enter your Log Analytics Workspace ID
- Click "Connect" to setup the workspace
- Ask questions like:
- "Show me failed requests from the last hour"
- "What are the top 5 slowest API calls?"
- "Get heartbeat data from the last 30 minutes"
Run a KQL query directly:
python main.py query --workspace-id <WORKSPACE_ID> --query "Heartbeat | take 5"Ask a question in natural language:
python main.py query --workspace-id <WORKSPACE_ID> --ask "Show me the total ingestion volume in MB in the last 24 hours"# Execute a KQL query
curl -X POST http://localhost:8080/query \
-H "Content-Type: application/json" \
-d '{"workspace_id": "your-workspace-id", "query": "Heartbeat | take 5"}'- Python 3.8+
- Azure CLI (for authentication)
- Azure Log Analytics Workspace
- Azure OpenAI resource (for natural language translation)
-
Clone and setup:
git clone <your-repo-url> cd NoaAzMonAgent pip install -r requirements.txt
-
Azure authentication:
az login
-
Configure Azure OpenAI:
# Copy template and edit with your details copy .env.template .env # Edit .env with your Azure OpenAI endpoint and API key
-
Test setup:
python setup_azure_openai.py
- Web Interface (
web_app.py): Modern Flask-based web UI - CLI Agent (
nl_agent.py): Command-line natural language interface - Translation Engine (
enhanced_translation.py): NL-to-KQL conversion - REST API (
my-first-mcp-server/main_new.py): HTTP API server - MCP Server (
my-first-mcp-server/mcp_server.py): AI assistant integration
- Intelligent Timespan Detection: Automatically detects time filters in queries
- Example-Driven Translation: Uses curated KQL examples for accurate translations
- Defensive Error Handling: Robust error recovery and user feedback
- Multiple Authentication: Azure CLI, managed identity, service principal support
The system includes curated examples for:
- App Requests (
app_requests_kql_examples.md): HTTP request analysis - App Exceptions (
app_exceptions_kql_examples.md): Error and exception tracking - App Traces (
app_traces_kql_examples.md): Application trace analysis - App Dependencies (
app_dependencies_kql_examples.md): External service monitoring - Performance (
app_performance_kql_examples.md): Performance metrics - Usage Analytics (
usage_kql_examples.md): Usage patterns and statistics
# Server management
python server_manager.py web # Start web interface
python server_manager.py agent # Start CLI agent
python server_manager.py http # Start REST API server
python server_manager.py mcp # Start MCP server
python server_manager.py test # Test functionality
# Direct launchers
python launch_web.py # Launch web interface
python nl_agent.py # Start CLI agent directly- Import errors: Run
pip install -r requirements.txt - Authentication failures: Check
az loginstatus - Translation errors: Verify Azure OpenAI configuration in
.env - Connection issues: Test with built-in connection testing tools
python test_translation.py- Test NL-to-KQL translationpython test_mcp_server.py- Test MCP server functionalitypython setup_azure_openai.py- Verify Azure OpenAI setup
- Environment Variables: Never commit
.envfiles with secrets - Azure RBAC: Use Azure role-based access control for workspace access
- API Key Management: Rotate Azure OpenAI keys regularly
- Network Security: Use private endpoints for production deployments
- Web Interface Guide: Comprehensive web UI documentation
- KQL Examples: Browse curated query examples
- Setup Guides: Step-by-step configuration instructions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
MIT License - see LICENSE file for details
- π Beautiful Web Interface: Modern, responsive web UI
- π§ Smart Timespan Detection: Automatic time filter handling
- π§ Enhanced Translation: Improved NL-to-KQL accuracy
- π€ MCP Server Integration: AI assistant compatibility
- π± Mobile-Responsive: Works on all devices
- Query history and favorites
- Advanced result visualization
- Team collaboration features
- Export capabilities (CSV, JSON)
- Custom dashboard creation
Happy querying! π
Tip: Start with the web interface for the best experience, then explore the CLI and API options for automation and integration needs.
The web interface now features beautiful HTML table rendering instead of plain text results:
- π¨ Professional Styling: Gradient headers, hover effects, responsive design
- π Multi-Table Support: Handle complex queries returning multiple result sets
- π Query Context: Shows the generated KQL query alongside results
- π Smart Formatting: Automatic type detection for numbers, booleans, and nulls
- π± Mobile Responsive: Tables adapt to different screen sizes
βοΈ Scrollable Results: Large datasets with vertical scrolling- π Table Statistics: Shows row/column counts and data insights
Before (Plain Text):
Table 1 (3 rows):
Name | Success | Duration
-----|---------|----------
API1 | True | 245
API2 | False | 5000
After (HTML Table):
- Beautiful gradient headers
- Professional row styling
- Interactive hover effects
- Responsive mobile design
- Color-coded data types
π See: TABLE_DISPLAY_GUIDE.md for complete documentation