mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 02:52:53 +00:00
feat: Add multi-service health check method to CLI API client
- Add ServiceHealth struct with name, status, endpoint, and message fields - Add CheckAllServices method to check health of all platform services - Add service definitions for api-server, charging-engine, carrier-connector, packet-gateway, and web-dashboard - Add HTTP health check with unreachable/healthy/unhealthy status determination - Add fmt package import for status code formatting
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package api
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Alert represents a monitoring alert
|
||||
type Alert struct {
|
||||
@@ -60,3 +63,51 @@ func (c *Client) GetHealth() ([]HealthStatus, error) {
|
||||
}
|
||||
return resp.Data, nil
|
||||
}
|
||||
|
||||
// ServiceHealth represents the health status of a single service
|
||||
type ServiceHealth struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// CheckAllServices checks the health of all platform services
|
||||
func (c *Client) CheckAllServices() ([]ServiceHealth, error) {
|
||||
services := []struct {
|
||||
name string
|
||||
endpoint string
|
||||
}{
|
||||
{"api-server", "/health"},
|
||||
{"charging-engine", "/health"},
|
||||
{"carrier-connector", "/api/v1/health"},
|
||||
{"packet-gateway", "/health"},
|
||||
{"web-dashboard", "/health"},
|
||||
}
|
||||
|
||||
healthResults := make([]ServiceHealth, 0, len(services))
|
||||
for _, svc := range services {
|
||||
health := ServiceHealth{
|
||||
Name: svc.name,
|
||||
Endpoint: svc.endpoint,
|
||||
}
|
||||
|
||||
resp, err := c.httpClient.Get(c.baseURL + svc.endpoint)
|
||||
if err != nil {
|
||||
health.Status = "unreachable"
|
||||
health.Message = err.Error()
|
||||
} else {
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == 200 {
|
||||
health.Status = "healthy"
|
||||
} else {
|
||||
health.Status = "unhealthy"
|
||||
health.Message = fmt.Sprintf("HTTP %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
healthResults = append(healthResults, health)
|
||||
}
|
||||
|
||||
return healthResults, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user