-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b486a7
commit 5006e04
Showing
7 changed files
with
160 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"sync" | ||
"time" | ||
|
||
"github.com/carverauto/serviceradar/pkg/checker/snmp" | ||
"github.com/carverauto/serviceradar/pkg/db" | ||
"github.com/carverauto/serviceradar/pkg/metrics" | ||
"github.com/carverauto/serviceradar/pkg/models" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
type ServiceStatus struct { | ||
Name string `json:"name"` | ||
Available bool `json:"available"` | ||
Message string `json:"message"` | ||
Type string `json:"type"` // e.g., "process", "port", "blockchain", etc. | ||
Details json.RawMessage `json:"details"` // Flexible field for service-specific data | ||
} | ||
|
||
type NodeStatus struct { | ||
NodeID string `json:"node_id"` | ||
IsHealthy bool `json:"is_healthy"` | ||
LastUpdate time.Time `json:"last_update"` | ||
Services []ServiceStatus `json:"services"` | ||
UpTime string `json:"uptime"` | ||
FirstSeen time.Time `json:"first_seen"` | ||
Metrics []models.MetricPoint `json:"metrics,omitempty"` | ||
} | ||
|
||
type SystemStatus struct { | ||
TotalNodes int `json:"total_nodes"` | ||
HealthyNodes int `json:"healthy_nodes"` | ||
LastUpdate time.Time `json:"last_update"` | ||
} | ||
|
||
type NodeHistory struct { | ||
NodeID string | ||
Timestamp time.Time | ||
IsHealthy bool | ||
Services []ServiceStatus | ||
} | ||
|
||
type NodeHistoryPoint struct { | ||
Timestamp time.Time `json:"timestamp"` | ||
IsHealthy bool `json:"is_healthy"` | ||
} | ||
|
||
type APIServer struct { | ||
mu sync.RWMutex | ||
nodes map[string]*NodeStatus | ||
router *mux.Router | ||
nodeHistoryHandler func(nodeID string) ([]NodeHistoryPoint, error) | ||
metricsManager metrics.MetricCollector | ||
snmpManager snmp.SNMPManager | ||
db db.Service | ||
knownPollers []string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package config | ||
|
||
// Validator interface for configurations that need validation. | ||
type Validator interface { | ||
Validate() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/carverauto/serviceradar/pkg/models" | ||
) | ||
|
||
type Duration time.Duration | ||
|
||
func (d *Duration) UnmarshalJSON(b []byte) error { | ||
var v interface{} | ||
if err := json.Unmarshal(b, &v); err != nil { | ||
return err | ||
} | ||
|
||
switch value := v.(type) { | ||
case float64: | ||
// parse numeric as nanoseconds | ||
*d = Duration(time.Duration(value)) | ||
return nil | ||
case string: | ||
dur, err := time.ParseDuration(value) | ||
if err != nil { | ||
return fmt.Errorf("invalid duration: %w", err) | ||
} | ||
|
||
*d = Duration(dur) | ||
|
||
return nil | ||
default: | ||
return errInvalidDuration | ||
} | ||
} | ||
|
||
// AgentConfig represents the configuration for an agent instance. | ||
type AgentConfig struct { | ||
CheckersDir string `json:"checkers_dir"` // e.g., /etc/serviceradar/checkers | ||
ListenAddr string `json:"listen_addr"` // e.g., :50051 | ||
ServiceName string `json:"service_name"` // e.g., "agent" | ||
Security *models.SecurityConfig `json:"security"` | ||
} | ||
|
||
// Check represents a generic service check configuration. | ||
type Check struct { | ||
ServiceType string `json:"service_type"` // e.g., "grpc", "process", "port" | ||
ServiceName string `json:"service_name"` | ||
Details string `json:"details,omitempty"` // Service-specific details | ||
Port int32 `json:"port,omitempty"` // For port checkers | ||
Config json.RawMessage `json:"config,omitempty"` // Checker-specific configuration | ||
} | ||
|
||
// AgentDefinition represents a remote agent and its checks. | ||
type AgentDefinition struct { | ||
Address string `json:"address"` // gRPC address of the agent | ||
Checks []Check `json:"checks"` // List of checks to run on this agent | ||
} | ||
|
||
// PollerConfig represents the configuration for a poller instance. | ||
type PollerConfig struct { | ||
Agents map[string]AgentDefinition `json:"agents"` // Map of agent ID to agent definition | ||
CloudAddress string `json:"cloud_address"` // Address of cloud service | ||
PollInterval Duration `json:"poll_interval"` // How often to poll agents | ||
PollerID string `json:"poller_id"` // Unique identifier for this poller | ||
} | ||
|
||
// WebhookConfig represents a webhook notification configuration. | ||
type WebhookConfig struct { | ||
Enabled bool `json:"enabled"` | ||
URL string `json:"url"` | ||
Cooldown Duration `json:"cooldown"` | ||
Template string `json:"template"` | ||
Headers []Header `json:"headers,omitempty"` // Optional custom headers | ||
} | ||
|
||
// Header represents a custom HTTP header. | ||
type Header struct { | ||
Key string `json:"key"` | ||
Value string `json:"value"` | ||
} | ||
|
||
// CloudConfig represents the configuration for the cloud service. | ||
type CloudConfig struct { | ||
ListenAddr string `json:"listen_addr"` | ||
GrpcAddr string `json:"grpc_addr,omitempty"` | ||
DBPath string `json:"db_path"` | ||
AlertThreshold Duration `json:"alert_threshold"` | ||
KnownPollers []string `json:"known_pollers"` | ||
Webhooks []WebhookConfig `json:"webhooks,omitempty"` | ||
} |
Oops, something went wrong.