httpserver

package
v0.0.0-...-520c4d9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

File: server/internal/http/handleAlertContextAPI.go

Basic Handler for http server server/internal/http/handler.go

server/internal/http/router.go Router for HTTPServer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterAgents

func FilterAgents(list []*model.Agent, filter EndpointFilter) []*model.Agent

FilterAgents filters a list of agents based on the provided filter criteria. It checks for matching endpoint ID, hostname, status, host ID, tags, and last seen time. The filtered list is then sorted and limited based on the specified criteria.

func FilterContainers

func FilterContainers(list []*model.Container, filter EndpointFilter) []*model.Container

FilterContainers filters a list of containers based on the provided filter criteria. It checks for matching endpoint ID, hostname, status, host ID, tags, and last seen time. The filtered list is then sorted and limited based on the specified criteria.

func GetFlash

func GetFlash(w http.ResponseWriter, r *http.Request) string

func InjectUserContext

func InjectUserContext(ctx context.Context, user *usermodel.User) context.Context

func SetFlash

func SetFlash(w http.ResponseWriter, message string)

func SortAndLimitAgents

func SortAndLimitAgents(list []*model.Agent, sortBy, order string, limit int) []*model.Agent

SortAndLimitAgents sorts a list of agents based on the specified criteria and limits the number of results. It sorts by hostname or last seen time, and can reverse the order.

func SortAndLimitContainers

func SortAndLimitContainers(list []*model.Container, sortBy, order string, limit int) []*model.Container

SortAndLimitContainers sorts a list of containers based on the specified criteria and limits the number of results. It sorts by name or last seen time, and can reverse the order.

func SortBy

func SortBy(alerts *[]model.AlertInstance, field, order string)

Types

type APIMetricStore

type APIMetricStore struct {
	Store metricstore.MetricStore
}

func (*APIMetricStore) Close

func (a *APIMetricStore) Close() error

func (*APIMetricStore) FetchDimensionsForMetric

func (a *APIMetricStore) FetchDimensionsForMetric(metric string) ([]string, error)

func (*APIMetricStore) QueryInstant

func (a *APIMetricStore) QueryInstant(metric string, filters map[string]string) ([]model.MetricRow, error)

func (*APIMetricStore) QueryMultiInstant

func (a *APIMetricStore) QueryMultiInstant(metricNames []string, filters map[string]string) ([]model.MetricRow, error)

func (*APIMetricStore) QueryMultiRange

func (a *APIMetricStore) QueryMultiRange(metrics []string, start, end time.Time, step string, filters map[string]string) ([]model.MetricRow, error)

func (*APIMetricStore) QueryRange

func (a *APIMetricStore) QueryRange(metric string, start, end time.Time, step string, filters map[string]string) ([]model.Point, error)

func (*APIMetricStore) Write

func (a *APIMetricStore) Write(metrics []model.MetricPayload) error

type AlertContextResponse

type AlertContextResponse struct {
	Alert  model.AlertInstance `json:"alert"`
	Logs   []model.LogEntry    `json:"logs"`
	Events []model.EventEntry  `json:"events"`
}

type ContainerMetrics

type ContainerMetrics struct {
	Host   string            `json:"host"`
	Name   string            `json:"name"`
	Image  string            `json:"image"`
	Status string            `json:"status"`
	CPU    *float64          `json:"cpu,omitempty"`
	Mem    *float64          `json:"mem,omitempty"`
	RX     *float64          `json:"rx,omitempty"`
	TX     *float64          `json:"tx,omitempty"`
	Uptime *float64          `json:"uptime,omitempty"`
	Labels map[string]string `json:"labels,omitempty"`
	Ports  string            `json:"ports,omitempty"`
}

type ContainerRow

type ContainerRow struct {
	ID     string
	Name   string
	Image  string
	Status string
	CPU    string
	Mem    string
	RX     string
	TX     string
	Uptime string
}

type EndpointFilter

type EndpointFilter struct {
	EndpointID string
	Hostname   string
	Status     string
	HostID     string
	IP         string // ← Add this
	OS         string
	Arch       string

	Tags        map[string]string
	LastSeenMin time.Duration
	LastSeenMax time.Duration
	Limit       int
	Sort        string
	Order       string
}

func ParseEndpointFilters

func ParseEndpointFilters(r *http.Request) EndpointFilter

type HostRow

type HostRow struct {
	Agent   model.Agent
	Metrics map[string]string // uptime, cpu %, mem %, etc.
}

type HttpServer

type HttpServer struct {
	Router *mux.Router
	Sys    *sys.SystemContext
	Tmpl   *gosighttemplate.GoSightTemplate
	// contains filtered or unexported fields
}

func NewServer

func NewServer(sys *sys.SystemContext) *HttpServer

NewServer creates a new HTTP server instance with the provided system context. It initializes the router and sets up the server configuration.

func (*HttpServer) BuildAuthEventMeta

func (s *HttpServer) BuildAuthEventMeta(user *usermodel.User, r *http.Request) map[string]string

func (*HttpServer) GetDimensions

func (s *HttpServer) GetDimensions(w http.ResponseWriter, r *http.Request)

GetDimensions retrieves all available dimensions.

func (*HttpServer) GetMetricData

func (s *HttpServer) GetMetricData(w http.ResponseWriter, r *http.Request)

func (*HttpServer) GetMetricDimensions

func (s *HttpServer) GetMetricDimensions(w http.ResponseWriter, r *http.Request)

GetMetricDimensions retrieves the dimensions for a specific metric.

func (*HttpServer) GetMetricLatest

func (s *HttpServer) GetMetricLatest(w http.ResponseWriter, r *http.Request)

func (*HttpServer) GetMetricNames

func (s *HttpServer) GetMetricNames(w http.ResponseWriter, r *http.Request)

GetMetricNames retrieves all metric names for a given namespace and subnamespace.

func (*HttpServer) GetNamespaces

func (s *HttpServer) GetNamespaces(w http.ResponseWriter, r *http.Request)

func (*HttpServer) GetSubNamespaces

func (s *HttpServer) GetSubNamespaces(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleAPIQuery

func (s *HttpServer) HandleAPIQuery(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleActiveAlertsAPI

func (s *HttpServer) HandleActiveAlertsAPI(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleActivityPage

func (s *HttpServer) HandleActivityPage(w http.ResponseWriter, r *http.Request)

HandleActivityPage handles requests to the activity page.

func (*HttpServer) HandleAddAlertRulePage

func (s *HttpServer) HandleAddAlertRulePage(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleAgentsAPI

func (s *HttpServer) HandleAgentsAPI(w http.ResponseWriter, r *http.Request)

// HandleAgentsAPI returns a JSON list of active agents

func (s *HttpServer) HandleAgentsAPI(w http.ResponseWriter, r *http.Request) {
	agents := s.Sys.Agents.GetAgents()

	sort.SliceStable(agents, func(i, j int) bool {
		return agents[i].Hostname < agents[j].Hostname
	})

	w.Header().Set("Content-Type", "application/json")
	_ = json.NewEncoder(w).Encode(agents)
}

func (*HttpServer) HandleAgentsPage

func (s *HttpServer) HandleAgentsPage(w http.ResponseWriter, r *http.Request, templateDir, env string)

RenderAgentsPage serves the agents.html template

func (*HttpServer) HandleAlertContext

func (s *HttpServer) HandleAlertContext(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleAlertRulesAPI

func (s *HttpServer) HandleAlertRulesAPI(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleAlertsAPI

func (s *HttpServer) HandleAlertsAPI(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleAlertsActivePage

func (s *HttpServer) HandleAlertsActivePage(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleAlertsHistoryPage

func (s *HttpServer) HandleAlertsHistoryPage(w http.ResponseWriter, r *http.Request)

HandleAlertsHistoryPage handles the page for viewing alert history at /alerts/history

func (*HttpServer) HandleAlertsPage

func (s *HttpServer) HandleAlertsPage(w http.ResponseWriter, r *http.Request)

HandleAlertsHistoryPage handles the page for viewing configured alerts at /alerts

func (*HttpServer) HandleAlertsSummaryAPI

func (s *HttpServer) HandleAlertsSummaryAPI(w http.ResponseWriter, r *http.Request)

HandleAlertsSummaryAPI handles requests to the /api/alerts/summary endpoint It returns a summary of alerts grouped by rule_id, showing the latest state and last change time.

func (*HttpServer) HandleCacheAudit

func (s *HttpServer) HandleCacheAudit(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleCallback

func (s *HttpServer) HandleCallback(w http.ResponseWriter, r *http.Request)

handleCallback handles the callback route for various auth providers.

func (*HttpServer) HandleCommandsAPI

func (s *HttpServer) HandleCommandsAPI(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleContainers

func (s *HttpServer) HandleContainers(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleCreateAlertRuleAPI

func (s *HttpServer) HandleCreateAlertRuleAPI(w http.ResponseWriter, r *http.Request)

HandleCreateAlert handles POST /api/v1/alerts

func (*HttpServer) HandleDeleteTag

func (s *HttpServer) HandleDeleteTag(w http.ResponseWriter, r *http.Request)

HandleDeleteTag deletes a specific tag key

func (*HttpServer) HandleEndpointDetail

func (s *HttpServer) HandleEndpointDetail(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleEndpointPage

func (s *HttpServer) HandleEndpointPage(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleEndpointsAPI

func (s *HttpServer) HandleEndpointsAPI(w http.ResponseWriter, r *http.Request)

HandleEndpointsAPI returns a JSON list of active endpoints It supports querying or listing all endpoints as well as /api/v1/endpoints/{endpoint_type} (hosts / containers)

func (*HttpServer) HandleEndpointsByTypeAPI

func (s *HttpServer) HandleEndpointsByTypeAPI(w http.ResponseWriter, r *http.Request)

HandleEndpointsByTypeAPI handles the /api/v1/endpoints/{endpointType} endpoint. It returns a JSON list of active endpoints filtered by the specified type (hosts or containers). It supports querying or listing all endpoints of the specified type. The endpoint type is specified in the URL path.

func (*HttpServer) HandleEventsAPI

func (s *HttpServer) HandleEventsAPI(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleExportQuery

func (s *HttpServer) HandleExportQuery(w http.ResponseWriter, r *http.Request)

ExportQueryHandler handles flexible label-based queries without requiring a metric name. Supports optional time range via start= and end= query params.

func (*HttpServer) HandleGetTags

func (s *HttpServer) HandleGetTags(w http.ResponseWriter, r *http.Request)

HandleGetTags returns all tags for an endpoint

func (*HttpServer) HandleGlobalSearchAPI

func (s *HttpServer) HandleGlobalSearchAPI(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleIndexPage

func (s *HttpServer) HandleIndexPage(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleLabelValues

func (s *HttpServer) HandleLabelValues(w http.ResponseWriter, r *http.Request)

HandleLabelValues returns all values for a given label key from

func (*HttpServer) HandleLogAPI

func (s *HttpServer) HandleLogAPI(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleLogin

func (s *HttpServer) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin renders the login page. It lists all available auth providers and handles flash messages.

func (*HttpServer) HandleLoginStart

func (s *HttpServer) HandleLoginStart(w http.ResponseWriter, r *http.Request)

startLogin handles the login/start route for various auth providers.

func (*HttpServer) HandleLogout

func (s *HttpServer) HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout handles the logout process.

func (*HttpServer) HandleLogsPage

func (s *HttpServer) HandleLogsPage(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleMFA

func (s *HttpServer) HandleMFA(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleMFAPage

func (s *HttpServer) HandleMFAPage(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleMetricExplorerPage

func (s *HttpServer) HandleMetricExplorerPage(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandlePatchTags

func (s *HttpServer) HandlePatchTags(w http.ResponseWriter, r *http.Request)

HandlePatchTags updates or adds individual tags

func (*HttpServer) HandleRecentLogs

func (s *HttpServer) HandleRecentLogs(w http.ResponseWriter, r *http.Request)

func (*HttpServer) HandleSetTags

func (s *HttpServer) HandleSetTags(w http.ResponseWriter, r *http.Request)

HandleSetTags replaces all tags for an endpoint

func (*HttpServer) HandleTagKeys

func (s *HttpServer) HandleTagKeys(w http.ResponseWriter, r *http.Request)

HandleTagKeys returns all known tag keys

func (*HttpServer) HandleTagValues

func (s *HttpServer) HandleTagValues(w http.ResponseWriter, r *http.Request)

HandleTagValues returns all values for a given key

func (*HttpServer) Shutdown

func (s *HttpServer) Shutdown() error

func (*HttpServer) Start

func (s *HttpServer) Start() error

type LogResponse

type LogResponse struct {
	Logs       []model.LogEntry `json:"logs"`
	NextCursor string           `json:"next_cursor,omitempty"`
	HasMore    bool             `json:"has_more"`
	Count      int              `json:"count"`
}

HandleLogAPI handles the HTTP request for the log API. It retrieves the logs from the log store, applies any filters specified in the query parameters, and returns the logs as a JSON response. The function uses the LogQueryParams struct to parse the query parameters and filter the logs. It handles errors and returns appropriate HTTP status codes and messages. The logs are filtered based on the specified levels, unit, source, contains string, and start and end times. The function limits the number of logs returned to the specified limit in the query parameters, with a maximum of 1000 logs. If the limit is not specified, it defaults to 100 logs. The function also handles errors and returns appropriate HTTP status codes and messages.

type SearchResult

type SearchResult struct {
	Hosts      []map[string]string `json:"hosts"`
	Containers []map[string]string `json:"containers"`
	Rules      []map[string]string `json:"rules"`
	Tags       []map[string]string `json:"tags"`
	Logs       []map[string]string `json:"logs"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL