test_connection
Verify Grafana API connectivity and configuration to ensure proper integration with the MCP server.
Instructions
Test connection to Grafana API to verify configuration and connectivity. Requires API key or open Grafana instance.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The implementation of the `test_connection` method within the `GrafanaApiProcessor` class, which verifies connectivity to the Grafana API by querying the `/api/datasources` endpoint.
def test_connection(self): """ Test connection to Grafana API to verify configuration and connectivity. Uses the /api/datasources endpoint to verify API access. Returns: bool: True if connection successful Raises: Exception: If connection fails with details about the failure """ try: url = f"{self.__host}/api/datasources" logger.info(f"Testing Grafana connection to: {url}") response = requests.get(url, headers=self.headers, verify=self.__ssl_verify, timeout=20) if response and response.status_code == 200: logger.info("Successfully connected to Grafana API") return True else: status_code = response.status_code if response else None raise Exception(f"Failed to connect with Grafana. Status Code: {status_code}. Response Text: {response.text}") except Exception as e: logger.error(f"Exception occurred while fetching grafana data sources with error: {e}") raise e