Documentation
¶
Index ¶
- Constants
- Variables
- type AccountService
- func (s *AccountService) GetAuthConfig() *AuthConfig
- func (s *AccountService) GetGitHubAuthURL() (*GitHubAuthURL, error)
- func (s *AccountService) GetOIDCAuthURL(ctx context.Context) (*OIDCAuthURL, error)
- func (s *AccountService) Login(ctx context.Context, username, password string) (*LoginResponse, error)
- func (s *AccountService) LoginWithGitHub(ctx context.Context, code, state string) (*LoginResponse, error)
- func (s *AccountService) LoginWithOIDC(ctx context.Context, code, state string) (*LoginResponse, error)
- func (s *AccountService) Logout(ctx context.Context, userID string) error
- func (s *AccountService) ValidateToken(tokenString string) (*JWTClaims, error)
- type AgentService
- func (s *AgentService) BatchUpdateTags(ctx context.Context, agentIDs []string, tags []string, operation string) error
- func (s *AgentService) BatchUpdateVisibility(ctx context.Context, agentIDs []string, visibility string) error
- func (s *AgentService) DeleteAgent(ctx context.Context, agentID string) error
- func (s *AgentService) GetAgent(ctx context.Context, agentID string) (*models.Agent, error)
- func (s *AgentService) GetAgentByAuth(ctx context.Context, id string, isAuthenticated bool) (*models.Agent, error)
- func (s *AgentService) GetAllTags(ctx context.Context) ([]string, error)
- func (s *AgentService) GetAuditResult(ctx context.Context, agentID string) (*protocol.VPSAuditResult, error)
- func (s *AgentService) GetStatistics(ctx context.Context) (map[string]interface{}, error)
- func (s *AgentService) HandleCommandResponse(ctx context.Context, agentID string, resp *protocol.CommandResponse) error
- func (s *AgentService) InitStatus(ctx context.Context) error
- func (s *AgentService) IsAgentByIP(ctx context.Context, ip string) (bool, error)
- func (s *AgentService) IsAgentEnabled(ctx context.Context, agentID string) (bool, error)
- func (s *AgentService) ListAgents(ctx context.Context) ([]models.Agent, error)
- func (s *AgentService) ListAuditResults(ctx context.Context, agentID string) ([]map[string]interface{}, error)
- func (s *AgentService) ListByAuth(ctx context.Context, isAuthenticated bool) ([]models.Agent, error)
- func (s *AgentService) ListOnlineAgents(ctx context.Context) ([]models.Agent, error)
- func (s *AgentService) RegisterAgent(ctx context.Context, ip string, info *protocol.AgentInfo, apiKey string) (*models.Agent, error)
- func (s *AgentService) SaveAuditResult(ctx context.Context, agentID string, result *protocol.VPSAuditResult) error
- func (s *AgentService) UpdateAgentEnabled(ctx context.Context, agentID string, enabled bool) error
- func (s *AgentService) UpdateAgentOrder(ctx context.Context, agentIDs []string) error
- func (s *AgentService) UpdateAgentStatus(ctx context.Context, agentID string, status int) error
- func (s *AgentService) UpdatePublicIP(ctx context.Context, agentID string, ipv4 string, ipv6 string) error
- type AlertRuleRequest
- type AlertRuleService
- func (s *AlertRuleService) CreateRule(ctx context.Context, req *AlertRuleRequest) (*models.AlertRule, error)
- func (s *AlertRuleService) DeleteRule(ctx context.Context, id string) error
- func (s *AlertRuleService) ResolveForAgent(ctx context.Context, agentID string) (*EffectiveAlertConfig, error)
- func (s *AlertRuleService) ResolveForAgents(ctx context.Context, agentIDs []string) (map[string]*EffectiveAlertConfig, error)
- func (s *AlertRuleService) SeedDefaultRule(ctx context.Context) error
- func (s *AlertRuleService) UpdateRule(ctx context.Context, id string, req *AlertRuleRequest) (*models.AlertRule, error)
- func (s *AlertRuleService) UpdateRuleEnabled(ctx context.Context, id string, enabled bool) error
- type AlertService
- func (s *AlertService) CheckAgentExpireAlerts(ctx context.Context) error
- func (s *AlertService) CheckMetrics(ctx context.Context, agentID string, cpu, memory, disk, networkSpeed float64) error
- func (s *AlertService) CheckMonitorAlerts(ctx context.Context) error
- func (s *AlertService) Clear(ctx context.Context) error
- func (s *AlertService) Shutdown()
- type AlertTypeMetadata
- type ApiKeyService
- func (s *ApiKeyService) DeleteApiKey(ctx context.Context, id string) error
- func (s *ApiKeyService) DisableApiKey(ctx context.Context, id string) error
- func (s *ApiKeyService) EnableApiKey(ctx context.Context, id string) error
- func (s *ApiKeyService) FillLegacyApiKeyType(ctx context.Context) error
- func (s *ApiKeyService) GenerateApiKey(ctx context.Context, name, userID, keyType string) (*models.ApiKey, error)
- func (s *ApiKeyService) GetApiKey(ctx context.Context, id string) (*models.ApiKey, error)
- func (s *ApiKeyService) ListApiKeys(ctx context.Context, page, pageSize int) ([]models.ApiKey, int64, error)
- func (s *ApiKeyService) ListUserApiKeys(ctx context.Context, userID string, page, pageSize int) ([]models.ApiKey, int64, error)
- func (s *ApiKeyService) UpdateApiKeyName(ctx context.Context, id, name string) error
- func (s *ApiKeyService) ValidateApiKey(ctx context.Context, key string, keyType string) (*models.ApiKey, error)
- type AppearanceConfig
- type AuthConfig
- type DDNSService
- func (s *DDNSService) CreateConfig(ctx context.Context, config *models.DDNSConfig) error
- func (s *DDNSService) DeleteConfig(ctx context.Context, id string) error
- func (s *DDNSService) GetConfig(ctx context.Context, id string) (*models.DDNSConfig, error)
- func (s *DDNSService) GetConfigByAgentID(ctx context.Context, agentID string) (*models.DDNSConfig, error)
- func (s *DDNSService) GetDDNSConfig(config *models.DDNSConfig) (*protocol.DDNSConfigData, error)
- func (s *DDNSService) HandleIPReport(ctx context.Context, agentID string, ipData *protocol.DDNSIPReportData) error
- func (s *DDNSService) ListConfigsByAgentID(ctx context.Context, agentID string) ([]models.DDNSConfig, error)
- func (s *DDNSService) ListRecords(ctx context.Context, configID string, limit int) ([]models.DDNSRecord, error)
- func (s *DDNSService) ListRecordsByAgentID(ctx context.Context, agentID string, limit int) ([]models.DDNSRecord, error)
- func (s *DDNSService) Run(ctx context.Context)
- func (s *DDNSService) TriggerUpdate(ctx context.Context, configID string) error
- func (s *DDNSService) UpdateConfig(ctx context.Context, config *models.DDNSConfig) error
- func (s *DDNSService) UpdateEnabled(ctx context.Context, id string, enabled bool) error
- type EffectiveAlertConfig
- type GeoIPService
- type GitHubAccessTokenResponse
- type GitHubAuthURL
- type GitHubOAuthService
- type GitHubUserInfo
- type JWTClaims
- type LoginResponse
- type MetricService
- func (s *MetricService) CleanAgentFromMonitorCache(agentID string)
- func (s *MetricService) CleanAgentMetrics(ctx context.Context, agentID string) error
- func (s *MetricService) CleanMonitorCache(ctx context.Context, monitorID string) error
- func (s *MetricService) CleanOrphanedAgentMetrics(ctx context.Context) error
- func (s *MetricService) DeleteAgentLatestMetricsCache(agentID string)
- func (s *MetricService) DeleteAgentMetrics(ctx context.Context, agentID string) error
- func (s *MetricService) DeleteMonitorMetrics(ctx context.Context, monitorID string) error
- func (s *MetricService) GetAvailableNetworkInterfaces(ctx context.Context, agentID string) ([]string, error)
- func (s *MetricService) GetCachedMonitorSparklines(ctx context.Context, monitorIDs []string, window, ttl time.Duration) (int64, map[string][]metric.MonitorSparklinePoint, error)
- func (s *MetricService) GetLatestMetrics(agentID string) (*metric.LatestMetrics, bool)
- func (s *MetricService) GetLiveMetrics(ctx context.Context, agentID string) (*metric.LiveMetricsResponse, error)
- func (s *MetricService) GetMetrics(ctx context.Context, agentID, metricType string, start, end int64, ...) (*metric.GetMetricsResponse, error)
- func (s *MetricService) GetMonitorAgentStats(ctx context.Context, monitorID string) []protocol.MonitorData
- func (s *MetricService) GetMonitorHistory(ctx context.Context, monitorID string, start, end int64, aggregation string) (*metric.GetMetricsResponse, error)
- func (s *MetricService) GetMonitorSparklines(ctx context.Context, monitorIDs []string, start, end int64) (map[string][]metric.MonitorSparklinePoint, error)
- func (s *MetricService) GetMonitorStats(ctx context.Context, monitorID string) *metric.MonitorStatsResult
- func (s *MetricService) HandleMetricData(ctx context.Context, agentID string, metricType string, data json.RawMessage, ...) error
- func (s *MetricService) PrepareMetricData(ctx context.Context, agentID string, metricType string, data json.RawMessage, ...) (result []vmclient.Metric, resultErr error)
- func (s *MetricService) WriteMetrics(ctx context.Context, metrics []vmclient.Metric) error
- type MonitorScheduler
- type MonitorService
- func (s *MonitorService) CreateMonitor(ctx context.Context, req *MonitorTaskRequest) (*models.MonitorTask, error)
- func (s *MonitorService) DeleteMonitor(ctx context.Context, id string) error
- func (s *MonitorService) GetAllLatestMonitorMetrics(ctx context.Context) ([]protocol.MonitorData, error)
- func (s *MonitorService) GetLatestMonitorMetricsByType(ctx context.Context, monitorType string) ([]protocol.MonitorData, error)
- func (s *MonitorService) GetMonitorByAuth(ctx context.Context, id string, isAuthenticated bool) (*models.MonitorTask, error)
- func (s *MonitorService) GetMonitorSparklinesByAuth(ctx context.Context, isAuthenticated bool) (*metric.PublicMonitorSparklinesResponse, error)
- func (s *MonitorService) GetMonitorStatsByID(ctx context.Context, monitorID string) (*metric.PublicMonitorOverview, error)
- func (s *MonitorService) ListByAuth(ctx context.Context, isAuthenticated bool) ([]metric.PublicMonitorOverview, error)
- func (s *MonitorService) SendMonitorTaskToAgents(ctx context.Context, monitor models.MonitorTask) error
- func (s *MonitorService) SetScheduler(scheduler MonitorScheduler)
- func (s *MonitorService) UpdateMonitor(ctx context.Context, id string, req *MonitorTaskRequest) (*models.MonitorTask, error)
- type MonitorTaskRequest
- type NotificationQueue
- type NotificationService
- type NotificationTask
- type Notifier
- func (n *Notifier) SendDingTalkByConfig(ctx context.Context, config map[string]interface{}, message string) error
- func (n *Notifier) SendEmailByConfig(ctx context.Context, config map[string]interface{}, message string) error
- func (n *Notifier) SendFeishuByConfig(ctx context.Context, config map[string]interface{}, message string) error
- func (n *Notifier) SendNotificationByConfig(ctx context.Context, channelConfig *models.NotificationChannelConfig, ...) error
- func (n *Notifier) SendNotificationByConfigs(ctx context.Context, channelConfigs []models.NotificationChannelConfig, ...) error
- func (n *Notifier) SendTelegramByConfig(ctx context.Context, config map[string]interface{}, message string) error
- func (n *Notifier) SendTestNotification(ctx context.Context, channelType string, config map[string]interface{}, ...) error
- func (n *Notifier) SendWeComAppByConfig(ctx context.Context, config map[string]interface{}, message string) error
- func (n *Notifier) SendWeComByConfig(ctx context.Context, config map[string]interface{}, message string) error
- func (n *Notifier) SendWebhookByConfig(ctx context.Context, config map[string]interface{}, message string) error
- type OIDCAuthURL
- type OIDCService
- type PropertyService
- func (s *PropertyService) DeleteDNSProvider(ctx context.Context, providerType string) error
- func (s *PropertyService) Get(ctx context.Context, id string) (*models.Property, error)
- func (s *PropertyService) GetAgentInstallConfig(ctx context.Context) (*models.AgentInstallConfig, error)
- func (s *PropertyService) GetAlertConfig(ctx context.Context) (*models.AlertConfig, error)
- func (s *PropertyService) GetAppearanceConfig(ctx context.Context) (*AppearanceConfig, error)
- func (s *PropertyService) GetDNSProviderByType(ctx context.Context, providerType string) (*models.DNSProviderConfig, error)
- func (s *PropertyService) GetDNSProviderConfigs(ctx context.Context) ([]models.DNSProviderConfig, error)
- func (s *PropertyService) GetNotificationChannelConfigs(ctx context.Context) ([]models.NotificationChannelConfig, error)
- func (s *PropertyService) GetPublicIPConfig(ctx context.Context) (*models.PublicIPConfig, error)
- func (s *PropertyService) GetSystemConfig(ctx context.Context) (*models.SystemConfig, error)
- func (s *PropertyService) GetSystemVersion(ctx context.Context) (string, error)
- func (s *PropertyService) GetValue(ctx context.Context, id string, target interface{}) error
- func (s *PropertyService) InitializeDefaultConfigs(ctx context.Context) error
- func (s *PropertyService) Set(ctx context.Context, id string, name string, value interface{}) error
- func (s *PropertyService) SetAgentInstallConfig(ctx context.Context, config models.AgentInstallConfig) error
- func (s *PropertyService) SetAlertConfig(ctx context.Context, config models.AlertConfig) error
- func (s *PropertyService) SetAppearanceConfig(ctx context.Context, config AppearanceConfig) error
- func (s *PropertyService) SetDNSProviderConfigs(ctx context.Context, providers []models.DNSProviderConfig) error
- func (s *PropertyService) SetSystemVersion(ctx context.Context, systemVersion string) error
- func (s *PropertyService) UpsertDNSProvider(ctx context.Context, newProvider models.DNSProviderConfig) error
- type PublicIPService
- type SSHLoginService
- func (s *SSHLoginService) DeleteEventsByAgentID(ctx context.Context, agentID string) error
- func (s *SSHLoginService) GetConfig(ctx context.Context, agentID string) (*models.SSHLoginConfigData, error)
- func (s *SSHLoginService) HandleConfigResult(ctx context.Context, agentID string, result protocol.SSHLoginConfigResult) error
- func (s *SSHLoginService) HandleEvent(ctx context.Context, agentID string, eventData protocol.SSHLoginEvent) error
- func (s *SSHLoginService) UpdateConfig(ctx context.Context, agentID string, req *models.SSHLoginConfigData) error
- type TamperService
- func (s *TamperService) BuildInitialConfig(ctx context.Context, agentID string) (added, removed []string, err error)
- func (s *TamperService) CreateEvent(ctx context.Context, agentID string, eventData *protocol.TamperEventData) error
- func (s *TamperService) DeleteEventsByAgentID(ctx context.Context, id string) error
- func (s *TamperService) GetConfigByAgentID(ctx context.Context, agentID string) (*models.TamperProtectConfigData, error)
- func (s *TamperService) HandleConfigResult(ctx context.Context, agentID string, resp protocol.TamperProtectResponse) error
- func (s *TamperService) UpdateConfig(ctx context.Context, agentID string, req *models.TamperProtectConfigData) error
- func (s *TamperService) UpdateConfigByAgentID(ctx context.Context, agentID string, config *models.TamperProtectConfigData) error
- type ThemeInfo
- type ThemeInstallResult
- type ThemeManifest
- type ThemeService
- func (s *ThemeService) Activate(ctx context.Context, id string) error
- func (s *ThemeService) Active(ctx context.Context) (*ThemeInfo, error)
- func (s *ThemeService) ActiveDistDir(ctx context.Context) (string, string, error)
- func (s *ThemeService) ActiveThemeID(ctx context.Context) string
- func (s *ThemeService) Delete(ctx context.Context, id string) error
- func (s *ThemeService) Get(ctx context.Context, id string) (*ThemeInfo, error)
- func (s *ThemeService) Install(ctx context.Context, reader io.Reader) (*ThemeInstallResult, error)
- func (s *ThemeService) List(ctx context.Context) ([]ThemeInfo, error)
- func (s *ThemeService) PreviewPath(ctx context.Context, id string) (string, string, error)
- func (s *ThemeService) RenderIndex(ctx context.Context, runtime any, systemConfig *models.SystemConfig) ([]byte, error)
- type TrafficAlerts
- type TrafficService
- func (s *TrafficService) CheckAndResetTraffic(ctx context.Context) error
- func (s *TrafficService) GetTrafficStats(ctx context.Context, agentID string) (*TrafficStats, error)
- func (s *TrafficService) ResetAgentTraffic(ctx context.Context, agentID string) error
- func (s *TrafficService) UpdateAgentTraffic(ctx context.Context, agentID string, currentRecvTotal, currentSentTotal uint64) error
- func (s *TrafficService) UpdateTrafficConfig(ctx context.Context, agentID string, enabled bool, trafficType string, ...) error
- type TrafficStats
- type UserInfo
- type UserService
- type WeComResult
Constants ¶
const ( NotificationTypeTraffic = "traffic" NotificationTypeSSHLogin = "ssh_login" NotificationTypeTamperEvt = "tamper" NotificationTypeAgentExpire = "agent_expire" )
const ( // PropertyIDSystemVersion 系统版本的固定 ID PropertyIDSystemVersion = "version" // PropertyIDNotificationChannels 通知渠道配置的固定 ID PropertyIDNotificationChannels = "notification_channels" // PropertyIDSystemConfig 系统配置的固定 ID PropertyIDSystemConfig = "system_config" // PropertyIDPublicIPConfig 公网 IP 采集配置的固定 ID PropertyIDPublicIPConfig = "public_ip_config" // PropertyIDAlertConfig 告警配置的固定 ID PropertyIDAlertConfig = "alert_config" // PropertyIDDNSProviders DNS 服务商配置的固定 ID PropertyIDDNSProviders = "dns_providers" // PropertyIDAgentInstallConfig 探针安装配置的固定 ID PropertyIDAgentInstallConfig = "agent_install_config" // PropertyIDAppearanceConfig 当前公开主题和默认明暗模式。 PropertyIDAppearanceConfig = "appearance_config" )
const ( DefaultThemeID = "default" ThemeSchemaVersion = 1 ThemeAPIVersion = "v1" )
const DefaultAlertRuleName = "默认规则"
DefaultAlertRuleName 默认规则名称(首次启动/升级时从全局告警配置生成的规则)
Variables ¶
var ( ErrThemeNotFound = errors.New("主题不存在") ErrThemeExists = errors.New("主题已存在") ErrThemeActive = errors.New("当前主题不能删除") ErrDefaultTheme = errors.New("默认主题不能修改或删除") )
var ErrInvalidAgentOrder = errors.New("无效的探针排序")
ErrInvalidAgentOrder 表示提交的排序列表无法完整、唯一地对应当前探针列表。
Functions ¶
This section is empty.
Types ¶
type AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
func NewAccountService ¶
func NewAccountService(logger *zap.Logger, userService *UserService, oidcService *OIDCService, githubService *GitHubOAuthService, appConfig *config.AppConfig) *AccountService
func (*AccountService) GetAuthConfig ¶
func (s *AccountService) GetAuthConfig() *AuthConfig
GetAuthConfig 获取认证配置
func (*AccountService) GetGitHubAuthURL ¶
func (s *AccountService) GetGitHubAuthURL() (*GitHubAuthURL, error)
GetGitHubAuthURL 获取 GitHub 认证 URL
func (*AccountService) GetOIDCAuthURL ¶
func (s *AccountService) GetOIDCAuthURL(ctx context.Context) (*OIDCAuthURL, error)
GetOIDCAuthURL 获取 OIDC 认证 URL
func (*AccountService) Login ¶
func (s *AccountService) Login(ctx context.Context, username, password string) (*LoginResponse, error)
Login 用户登录(Basic Auth)
func (*AccountService) LoginWithGitHub ¶
func (s *AccountService) LoginWithGitHub(ctx context.Context, code, state string) (*LoginResponse, error)
LoginWithGitHub GitHub 登录
func (*AccountService) LoginWithOIDC ¶
func (s *AccountService) LoginWithOIDC(ctx context.Context, code, state string) (*LoginResponse, error)
LoginWithOIDC OIDC 登录
func (*AccountService) Logout ¶
func (s *AccountService) Logout(ctx context.Context, userID string) error
Logout 用户登出
func (*AccountService) ValidateToken ¶
func (s *AccountService) ValidateToken(tokenString string) (*JWTClaims, error)
ValidateToken 验证 JWT token
type AgentService ¶
type AgentService struct {
*orz.Service
AgentRepo *repo.AgentRepo
MonitorRepo *repo.MonitorRepo
TamperEventRepo *repo.TamperEventRepo
SSHLoginEventRepo *repo.SSHLoginEventRepo
// contains filtered or unexported fields
}
func NewAgentService ¶
func NewAgentService(logger *zap.Logger, db *gorm.DB, apiKeyService *ApiKeyService, metricService *MetricService, geoipService *GeoIPService) *AgentService
func (*AgentService) BatchUpdateTags ¶
func (s *AgentService) BatchUpdateTags(ctx context.Context, agentIDs []string, tags []string, operation string) error
BatchUpdateTags 批量更新探针标签 operation: "add" 添加标签, "remove" 移除标签, "replace" 替换标签
func (*AgentService) BatchUpdateVisibility ¶
func (s *AgentService) BatchUpdateVisibility(ctx context.Context, agentIDs []string, visibility string) error
BatchUpdateVisibility 批量更新探针可见性
func (*AgentService) DeleteAgent ¶
func (s *AgentService) DeleteAgent(ctx context.Context, agentID string) error
DeleteAgent 删除探针及其所有相关数据
func (*AgentService) GetAgentByAuth ¶
func (s *AgentService) GetAgentByAuth(ctx context.Context, id string, isAuthenticated bool) (*models.Agent, error)
GetAgentByAuth 根据认证状态获取探针(已登录返回全部,未登录返回公开可见) 支持完整UUID和短ID(前缀匹配)
func (*AgentService) GetAllTags ¶
func (s *AgentService) GetAllTags(ctx context.Context) ([]string, error)
GetAllTags 获取所有探针的标签
func (*AgentService) GetAuditResult ¶
func (s *AgentService) GetAuditResult(ctx context.Context, agentID string) (*protocol.VPSAuditResult, error)
GetAuditResult 获取最新的审计结果(原始数据)
func (*AgentService) GetStatistics ¶
func (s *AgentService) GetStatistics(ctx context.Context) (map[string]interface{}, error)
GetStatistics 获取探针统计数据
func (*AgentService) HandleCommandResponse ¶
func (s *AgentService) HandleCommandResponse(ctx context.Context, agentID string, resp *protocol.CommandResponse) error
HandleCommandResponse 处理指令响应
func (*AgentService) InitStatus ¶
func (s *AgentService) InitStatus(ctx context.Context) error
func (*AgentService) IsAgentByIP ¶
IsAgentByIP 检查指定公网IP是否为探针
func (*AgentService) IsAgentEnabled ¶ added in v0.2.2
IsAgentEnabled 查询探针是否允许接收并处理数据(带短 TTL 缓存, 禁用操作会立即失效缓存)。
func (*AgentService) ListAgents ¶
ListAgents 列出所有探针
func (*AgentService) ListAuditResults ¶
func (s *AgentService) ListAuditResults(ctx context.Context, agentID string) ([]map[string]interface{}, error)
ListAuditResults 获取审计结果列表
func (*AgentService) ListByAuth ¶
func (s *AgentService) ListByAuth(ctx context.Context, isAuthenticated bool) ([]models.Agent, error)
ListByAuth 根据认证状态列出探针(已登录返回全部,未登录返回公开可见)
func (*AgentService) ListOnlineAgents ¶
ListOnlineAgents 列出所有在线探针
func (*AgentService) RegisterAgent ¶
func (s *AgentService) RegisterAgent(ctx context.Context, ip string, info *protocol.AgentInfo, apiKey string) (*models.Agent, error)
RegisterAgent 注册探针
func (*AgentService) SaveAuditResult ¶
func (s *AgentService) SaveAuditResult(ctx context.Context, agentID string, result *protocol.VPSAuditResult) error
SaveAuditResult 保存审计结果
func (*AgentService) UpdateAgentEnabled ¶ added in v0.2.2
UpdateAgentEnabled 更新探针启用状态。禁用时立即标记离线,后续状态更新由仓储层原子拦截。
func (*AgentService) UpdateAgentOrder ¶ added in v0.2.2
func (s *AgentService) UpdateAgentOrder(ctx context.Context, agentIDs []string) error
UpdateAgentOrder 按从前到后的 ID 顺序重新分配探针权重。 请求必须包含当前全部探针,避免筛选状态下排序时意外覆盖未展示探针的相对顺序。
func (*AgentService) UpdateAgentStatus ¶
UpdateAgentStatus 更新探针状态
func (*AgentService) UpdatePublicIP ¶
func (s *AgentService) UpdatePublicIP(ctx context.Context, agentID string, ipv4 string, ipv6 string) error
UpdatePublicIP 更新探针的公网 IP 信息
type AlertRuleRequest ¶
type AlertRuleRequest struct {
Name string `json:"name"`
Priority int `json:"priority"`
Enabled bool `json:"enabled"`
TargetType string `json:"targetType"`
AgentIds []string `json:"agentIds"`
Tags []string `json:"tags"`
Rules models.AlertRules `json:"rules"`
Channels []string `json:"channels"`
MaskIP bool `json:"maskIP"`
Notifications models.AlertNotifications `json:"notifications"`
MaintenanceEnabled bool `json:"maintenanceEnabled"`
MaintenanceStartTime string `json:"maintenanceStartTime"`
MaintenanceEndTime string `json:"maintenanceEndTime"`
}
type AlertRuleService ¶
type AlertRuleService struct {
*repo.AlertRuleRepo
*orz.Service
// contains filtered or unexported fields
}
func NewAlertRuleService ¶
func NewAlertRuleService(logger *zap.Logger, db *gorm.DB, propertyService *PropertyService) *AlertRuleService
func (*AlertRuleService) CreateRule ¶
func (s *AlertRuleService) CreateRule(ctx context.Context, req *AlertRuleRequest) (*models.AlertRule, error)
func (*AlertRuleService) DeleteRule ¶
func (s *AlertRuleService) DeleteRule(ctx context.Context, id string) error
func (*AlertRuleService) ResolveForAgent ¶
func (s *AlertRuleService) ResolveForAgent(ctx context.Context, agentID string) (*EffectiveAlertConfig, error)
ResolveForAgent 解析主机实际生效的告警配置: 启用的规则按优先级升序取第一条命中的规则;未命中任何规则时返回 nil(该主机不产生告警)。
func (*AlertRuleService) ResolveForAgents ¶
func (s *AlertRuleService) ResolveForAgents(ctx context.Context, agentIDs []string) (map[string]*EffectiveAlertConfig, error)
ResolveForAgents 批量解析主机实际生效的告警配置(返回的 map 中不含未命中任何规则的主机)
func (*AlertRuleService) SeedDefaultRule ¶
func (s *AlertRuleService) SeedDefaultRule(ctx context.Context) error
SeedDefaultRule 不存在任何告警规则时,从全局告警配置生成一条默认规则(覆盖全部主机)
func (*AlertRuleService) UpdateRule ¶
func (s *AlertRuleService) UpdateRule(ctx context.Context, id string, req *AlertRuleRequest) (*models.AlertRule, error)
func (*AlertRuleService) UpdateRuleEnabled ¶
UpdateRuleEnabled 更新规则启用状态(停用时其下主机不再命中该规则,清理告警状态)
type AlertService ¶
type AlertService struct {
Service *orz.Service
AlertRecordRepo *repo.AlertRecordRepo
AlertStateRepo *repo.AlertStateRepo
// contains filtered or unexported fields
}
AlertService 告警服务
func NewAlertService ¶
func NewAlertService(logger *zap.Logger, db *gorm.DB, propertyService *PropertyService, alertRuleService *AlertRuleService, monitorService *MonitorService, notifier *Notifier) *AlertService
func (*AlertService) CheckAgentExpireAlerts ¶
func (s *AlertService) CheckAgentExpireAlerts(ctx context.Context) error
CheckAgentExpireAlerts 检查机器到期提醒(按各主机命中的告警规则检查,未命中规则的主机不提醒)
func (*AlertService) CheckMetrics ¶
func (s *AlertService) CheckMetrics(ctx context.Context, agentID string, cpu, memory, disk, networkSpeed float64) error
CheckMetrics 检查指标并触发告警
func (*AlertService) CheckMonitorAlerts ¶
func (s *AlertService) CheckMonitorAlerts(ctx context.Context) error
CheckMonitorAlerts 检查监控相关告警(证书、服务下线、探针离线,按各主机生效的规则检查)
type AlertTypeMetadata ¶
type AlertTypeMetadata struct {
Name string // 中文名称
ThresholdUnit string // 阈值单位
ValueUnit string // 当前值单位
ShowThreshold bool // 是否显示阈值
ShowActual bool // 是否显示当前值
}
AlertTypeMetadata 告警类型元数据
type ApiKeyService ¶
type ApiKeyService struct {
ApiKeyRepo *repo.ApiKeyRepo
// contains filtered or unexported fields
}
func NewApiKeyService ¶
func NewApiKeyService(logger *zap.Logger, db *gorm.DB) *ApiKeyService
func (*ApiKeyService) DeleteApiKey ¶
func (s *ApiKeyService) DeleteApiKey(ctx context.Context, id string) error
DeleteApiKey 删除API密钥
func (*ApiKeyService) DisableApiKey ¶
func (s *ApiKeyService) DisableApiKey(ctx context.Context, id string) error
DisableApiKey 禁用API密钥
func (*ApiKeyService) EnableApiKey ¶
func (s *ApiKeyService) EnableApiKey(ctx context.Context, id string) error
EnableApiKey 启用API密钥
func (*ApiKeyService) FillLegacyApiKeyType ¶
func (s *ApiKeyService) FillLegacyApiKeyType(ctx context.Context) error
FillLegacyApiKeyType 将旧版本未标记类型的密钥回填为通信密钥。
func (*ApiKeyService) GenerateApiKey ¶
func (s *ApiKeyService) GenerateApiKey(ctx context.Context, name, userID, keyType string) (*models.ApiKey, error)
GenerateApiKey 生成API密钥
func (*ApiKeyService) ListApiKeys ¶
func (s *ApiKeyService) ListApiKeys(ctx context.Context, page, pageSize int) ([]models.ApiKey, int64, error)
ListApiKeys 列出所有API密钥
func (*ApiKeyService) ListUserApiKeys ¶
func (s *ApiKeyService) ListUserApiKeys(ctx context.Context, userID string, page, pageSize int) ([]models.ApiKey, int64, error)
ListUserApiKeys 列出用户的API密钥
func (*ApiKeyService) UpdateApiKeyName ¶
func (s *ApiKeyService) UpdateApiKeyName(ctx context.Context, id, name string) error
UpdateApiKeyName 更新API密钥名称
func (*ApiKeyService) ValidateApiKey ¶
func (s *ApiKeyService) ValidateApiKey(ctx context.Context, key string, keyType string) (*models.ApiKey, error)
ValidateApiKey 验证API密钥
type AppearanceConfig ¶
type AppearanceConfig struct {
ActiveTheme string `json:"activeTheme"`
DefaultColorMode string `json:"defaultColorMode"`
}
AppearanceConfig 记录当前启用主题和默认明暗模式,存放在 appearance_config Property。
type AuthConfig ¶
type AuthConfig struct {
OIDCEnabled bool `json:"oidcEnabled"`
GitHubEnabled bool `json:"githubEnabled"`
PasswordEnabled bool `json:"passwordEnabled"`
}
AuthConfig 认证配置
type DDNSService ¶
type DDNSService struct {
ConfigRepo *repo.DDNSConfigRepo // 导出用于 handler 的 PageBuilder
// contains filtered or unexported fields
}
func NewDDNSService ¶
func NewDDNSService( logger *zap.Logger, db *gorm.DB, propertyService *PropertyService, wsManager *websocket.Manager, ) *DDNSService
func (*DDNSService) CreateConfig ¶
func (s *DDNSService) CreateConfig(ctx context.Context, config *models.DDNSConfig) error
CreateConfig 创建 DDNS 配置
func (*DDNSService) DeleteConfig ¶
func (s *DDNSService) DeleteConfig(ctx context.Context, id string) error
DeleteConfig 删除 DDNS 配置
func (*DDNSService) GetConfig ¶
func (s *DDNSService) GetConfig(ctx context.Context, id string) (*models.DDNSConfig, error)
GetConfig 获取 DDNS 配置
func (*DDNSService) GetConfigByAgentID ¶
func (s *DDNSService) GetConfigByAgentID(ctx context.Context, agentID string) (*models.DDNSConfig, error)
GetConfigByAgentID 获取探针的 DDNS 配置
func (*DDNSService) GetDDNSConfig ¶
func (s *DDNSService) GetDDNSConfig(config *models.DDNSConfig) (*protocol.DDNSConfigData, error)
GetDDNSConfig 将数据库配置转换为协议配置(下发给客户端)
func (*DDNSService) HandleIPReport ¶
func (s *DDNSService) HandleIPReport(ctx context.Context, agentID string, ipData *protocol.DDNSIPReportData) error
HandleIPReport 处理客户端上报的 IP 地址
func (*DDNSService) ListConfigsByAgentID ¶
func (s *DDNSService) ListConfigsByAgentID(ctx context.Context, agentID string) ([]models.DDNSConfig, error)
ListConfigsByAgentID 列出探针的所有 DDNS 配置
func (*DDNSService) ListRecords ¶
func (s *DDNSService) ListRecords(ctx context.Context, configID string, limit int) ([]models.DDNSRecord, error)
ListRecords 列出 DDNS 更新记录
func (*DDNSService) ListRecordsByAgentID ¶
func (s *DDNSService) ListRecordsByAgentID(ctx context.Context, agentID string, limit int) ([]models.DDNSRecord, error)
ListRecordsByAgentID 列出探针的 DDNS 更新记录
func (*DDNSService) TriggerUpdate ¶
func (s *DDNSService) TriggerUpdate(ctx context.Context, configID string) error
TriggerUpdate 手动触发 DDNS 更新 向探针发送配置消息,触发探针立即获取并上报 IP 地址
func (*DDNSService) UpdateConfig ¶
func (s *DDNSService) UpdateConfig(ctx context.Context, config *models.DDNSConfig) error
UpdateConfig 更新 DDNS 配置
func (*DDNSService) UpdateEnabled ¶
type EffectiveAlertConfig ¶
type EffectiveAlertConfig struct {
ConfigID string // 告警规则 ID
Name string // 规则名称
MaskIP bool // 通知中是否打码 IP
Notifications models.AlertNotifications // 事件通知开关(流量/SSH登录/防篡改/机器到期)
Rules models.AlertRules // 告警规则
Channels []string // 通知渠道类型列表(空 = 所有启用渠道)
MaintenanceEnabled bool // 是否启用每日计划维护
MaintenanceStartTime string // 每日计划维护开始时间(HH:mm)
MaintenanceEndTime string // 每日计划维护结束时间(HH:mm)
}
EffectiveAlertConfig 主机实际生效的告警配置(按优先级命中的第一条启用的告警规则)
func (*EffectiveAlertConfig) ConditionStartAfterMaintenance ¶
func (c *EffectiveAlertConfig) ConditionStartAfterMaintenance(now time.Time, startTime int64) int64
ConditionStartAfterMaintenance 将异常累计起点截断到最近一次维护结束时间, 避免维护结束后把维护期间计入持续时间。未启用维护或起点更晚时保持原值。
func (*EffectiveAlertConfig) IsInMaintenance ¶
func (c *EffectiveAlertConfig) IsInMaintenance(now time.Time) bool
IsInMaintenance 判断指定时间是否处于每日计划维护时段。时间按服务端本地时区解释, 范围采用左闭右开;开始时间晚于结束时间时表示跨天。
type GeoIPService ¶
type GeoIPService struct {
// contains filtered or unexported fields
}
func NewGeoIPService ¶
func (*GeoIPService) LookupIP ¶
func (s *GeoIPService) LookupIP(ip string) string
LookupIP 查询 IP 归属地
type GitHubAccessTokenResponse ¶
type GitHubAccessTokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
}
GitHubAccessTokenResponse GitHub Access Token 响应
type GitHubAuthURL ¶
GitHubAuthURL GitHub 认证 URL 响应
type GitHubOAuthService ¶
type GitHubOAuthService struct {
// contains filtered or unexported fields
}
GitHubOAuthService GitHub OAuth 认证服务
func NewGitHubOAuthService ¶
func NewGitHubOAuthService(logger *zap.Logger, appConfig *config.AppConfig) *GitHubOAuthService
NewGitHubOAuthService 创建 GitHub OAuth 服务
func (*GitHubOAuthService) ExchangeCode ¶
func (s *GitHubOAuthService) ExchangeCode(ctx context.Context, code, state string) (string, string, error)
ExchangeCode 交换授权码获取 access token 和用户信息
func (*GitHubOAuthService) GenerateAuthURL ¶
func (s *GitHubOAuthService) GenerateAuthURL() (string, string, error)
GenerateAuthURL 生成 GitHub 认证 URL
func (*GitHubOAuthService) IsEnabled ¶
func (s *GitHubOAuthService) IsEnabled() bool
IsEnabled 检查 GitHub OAuth 是否启用
type GitHubUserInfo ¶
type GitHubUserInfo struct {
Login string `json:"login"` // GitHub 用户名
Name string `json:"name"` // 显示名称
Email string `json:"email"` // 邮箱
AvatarURL string `json:"avatar_url"` // 头像
}
GitHubUserInfo GitHub 用户信息
type JWTClaims ¶
type JWTClaims struct {
UserID string `json:"userId"`
Username string `json:"username"`
jwt.RegisteredClaims
}
JWTClaims JWT 声明
type LoginResponse ¶
type LoginResponse struct {
Token string `json:"token"`
ExpiresAt int64 `json:"expiresAt"`
User *UserInfo `json:"user"`
}
LoginResponse 登录响应
type MetricService ¶
type MetricService struct {
// contains filtered or unexported fields
}
MetricService 指标服务
func NewMetricService ¶
func NewMetricService(logger *zap.Logger, db *gorm.DB, propertyService *PropertyService, trafficService *TrafficService, vmClient *vmclient.VMClient) *MetricService
NewMetricService 创建指标服务
func (*MetricService) CleanAgentFromMonitorCache ¶
func (s *MetricService) CleanAgentFromMonitorCache(agentID string)
CleanAgentFromMonitorCache 从所有监控缓存中移除指定探针的数据
func (*MetricService) CleanAgentMetrics ¶
func (s *MetricService) CleanAgentMetrics(ctx context.Context, agentID string) error
CleanAgentMetrics 清理指定探针的所有指标数据
func (*MetricService) CleanMonitorCache ¶
func (s *MetricService) CleanMonitorCache(ctx context.Context, monitorID string) error
CleanMonitorCache 清理监控任务缓存中不再关联的探针数据
func (*MetricService) CleanOrphanedAgentMetrics ¶
func (s *MetricService) CleanOrphanedAgentMetrics(ctx context.Context) error
CleanOrphanedAgentMetrics 批量清理已删除探针的指标数据
func (*MetricService) DeleteAgentLatestMetricsCache ¶
func (s *MetricService) DeleteAgentLatestMetricsCache(agentID string)
DeleteAgentLatestMetricsCache 删除探针在内存中的最新指标缓存
func (*MetricService) DeleteAgentMetrics ¶
func (s *MetricService) DeleteAgentMetrics(ctx context.Context, agentID string) error
DeleteAgentMetrics 删除探针在 VictoriaMetrics 中的历史指标
func (*MetricService) DeleteMonitorMetrics ¶
func (s *MetricService) DeleteMonitorMetrics(ctx context.Context, monitorID string) error
DeleteMonitorMetrics 删除服务监控在 VictoriaMetrics 中的历史指标
func (*MetricService) GetAvailableNetworkInterfaces ¶
func (s *MetricService) GetAvailableNetworkInterfaces(ctx context.Context, agentID string) ([]string, error)
GetAvailableNetworkInterfaces 获取探针的可用网卡列表(从 VictoriaMetrics 查询)
func (*MetricService) GetCachedMonitorSparklines ¶
func (s *MetricService) GetCachedMonitorSparklines(ctx context.Context, monitorIDs []string, window, ttl time.Duration) (int64, map[string][]metric.MonitorSparklinePoint, error)
GetCachedMonitorSparklines 返回带短期缓存的批量走势图,并合并同一查询的并发请求。
func (*MetricService) GetLatestMetrics ¶
func (s *MetricService) GetLatestMetrics(agentID string) (*metric.LatestMetrics, bool)
GetLatestMetrics 获取最新指标的快照 返回值是缓存项的浅拷贝(无互斥量),调用方可以安全 marshal 或在副本上 sanitize 字段, 不会与上报路径产生 data race。
func (*MetricService) GetLiveMetrics ¶ added in v0.2.8
func (s *MetricService) GetLiveMetrics(ctx context.Context, agentID string) (*metric.LiveMetricsResponse, error)
func (*MetricService) GetMetrics ¶
func (s *MetricService) GetMetrics(ctx context.Context, agentID, metricType string, start, end int64, interfaceName string, aggregation string) (*metric.GetMetricsResponse, error)
GetMetrics 获取聚合指标数据(从 VictoriaMetrics 查询) 返回统一的 GetMetricsResponse 格式
func (*MetricService) GetMonitorAgentStats ¶
func (s *MetricService) GetMonitorAgentStats(ctx context.Context, monitorID string) []protocol.MonitorData
GetMonitorAgentStats 获取监控任务各探针的统计数据(只从缓存读取)
func (*MetricService) GetMonitorHistory ¶
func (s *MetricService) GetMonitorHistory(ctx context.Context, monitorID string, start, end int64, aggregation string) (*metric.GetMetricsResponse, error)
GetMonitorHistory 获取监控任务的历史趋势数据
func (*MetricService) GetMonitorSparklines ¶
func (s *MetricService) GetMonitorSparklines(ctx context.Context, monitorIDs []string, start, end int64) (map[string][]metric.MonitorSparklinePoint, error)
GetMonitorSparklines 使用一次 VictoriaMetrics 查询返回多个监控项的列表走势图。
func (*MetricService) GetMonitorStats ¶
func (s *MetricService) GetMonitorStats(ctx context.Context, monitorID string) *metric.MonitorStatsResult
GetMonitorStats 获取监控任务的聚合统计数据(只从缓存读取)
func (*MetricService) HandleMetricData ¶
func (s *MetricService) HandleMetricData(ctx context.Context, agentID string, metricType string, data json.RawMessage, timestamp int64) error
HandleMetricData 处理指标数据
并发:每次调用都会刷新 latestCache 的 TTL(defer Set),且对 latestMetrics 字段的写入 走 Update 在写锁内 commit;读者侧 GetLatestMetrics 通过 Snapshot 取读锁拷贝,避免与 json.Marshal 之间的 data race。
时间戳:sample.Timestamp(agent 端 wall clock)只用于写入 VictoriaMetrics 的样本时间, LatestMetrics.Timestamp 改用服务端 time.Now()(单调推进),避免 agent NTP 倒拨导致 前端 useLiveBuffer 的去重逻辑永久冻结。
func (*MetricService) PrepareMetricData ¶ added in v0.2.8
func (s *MetricService) PrepareMetricData(ctx context.Context, agentID string, metricType string, data json.RawMessage, timestamp int64) (result []vmclient.Metric, resultErr error)
PrepareMetricData 更新实时缓存并转换指标,不单独发起 HTTP 写入。
func (*MetricService) WriteMetrics ¶ added in v0.2.8
WriteMetrics 等待合并导入完成后返回,避免可靠消息在数据写入前被 ACK。
type MonitorScheduler ¶
type MonitorScheduler interface {
AddTask(monitorID string, interval int) error
UpdateTask(monitorID string, interval int) error
RemoveTask(monitorID string)
}
MonitorScheduler 调度器接口(避免循环依赖)
type MonitorService ¶
type MonitorService struct {
*repo.MonitorRepo
*orz.Service
// contains filtered or unexported fields
}
func NewMonitorService ¶
func NewMonitorService(logger *zap.Logger, db *gorm.DB, metricService *MetricService, wsManager *ws.Manager) *MonitorService
func (*MonitorService) CreateMonitor ¶
func (s *MonitorService) CreateMonitor(ctx context.Context, req *MonitorTaskRequest) (*models.MonitorTask, error)
func (*MonitorService) DeleteMonitor ¶
func (s *MonitorService) DeleteMonitor(ctx context.Context, id string) error
func (*MonitorService) GetAllLatestMonitorMetrics ¶
func (s *MonitorService) GetAllLatestMonitorMetrics(ctx context.Context) ([]protocol.MonitorData, error)
GetAllLatestMonitorMetrics 获取所有最新监控指标(用于告警检查)
func (*MonitorService) GetLatestMonitorMetricsByType ¶
func (s *MonitorService) GetLatestMonitorMetricsByType(ctx context.Context, monitorType string) ([]protocol.MonitorData, error)
GetLatestMonitorMetricsByType 获取指定类型的最新监控指标(用于告警检查)
func (*MonitorService) GetMonitorByAuth ¶
func (s *MonitorService) GetMonitorByAuth(ctx context.Context, id string, isAuthenticated bool) (*models.MonitorTask, error)
GetMonitorByAuth 根据认证状态获取监控任务(已登录返回全部,未登录返回公开可见)
func (*MonitorService) GetMonitorSparklinesByAuth ¶
func (s *MonitorService) GetMonitorSparklinesByAuth(ctx context.Context, isAuthenticated bool) (*metric.PublicMonitorSparklinesResponse, error)
GetMonitorSparklinesByAuth 返回当前访问者可见监控项的批量走势图。
func (*MonitorService) GetMonitorStatsByID ¶
func (s *MonitorService) GetMonitorStatsByID(ctx context.Context, monitorID string) (*metric.PublicMonitorOverview, error)
GetMonitorStatsByID 获取监控任务的统计数据(聚合后的单个监控详情)
func (*MonitorService) ListByAuth ¶
func (s *MonitorService) ListByAuth(ctx context.Context, isAuthenticated bool) ([]metric.PublicMonitorOverview, error)
ListByAuth 返回公开展示所需的监控配置和汇总统计
func (*MonitorService) SendMonitorTaskToAgents ¶
func (s *MonitorService) SendMonitorTaskToAgents(ctx context.Context, monitor models.MonitorTask) error
SendMonitorTaskToAgents 向指定探针发送单个监控任务(公开方法)
func (*MonitorService) SetScheduler ¶
func (s *MonitorService) SetScheduler(scheduler MonitorScheduler)
SetScheduler 设置调度器(由外部注入,避免循环依赖)
func (*MonitorService) UpdateMonitor ¶
func (s *MonitorService) UpdateMonitor(ctx context.Context, id string, req *MonitorTaskRequest) (*models.MonitorTask, error)
type MonitorTaskRequest ¶
type MonitorTaskRequest struct {
Name string `json:"name"`
Type string `json:"type"`
Target string `json:"target"`
Description string `json:"description"`
Enabled bool `json:"enabled,omitempty"`
ShowTargetPublic bool `json:"showTargetPublic,omitempty"` // 在公开页面是否显示目标地址
Visibility string `json:"visibility,omitempty"` // 可见性: public-匿名可见, private-登录可见
Interval int `json:"interval"` // 检测频率(秒)
HTTPConfig protocol.HTTPMonitorConfig `json:"httpConfig,omitempty"`
TCPConfig protocol.TCPMonitorConfig `json:"tcpConfig,omitempty"`
ICMPConfig protocol.ICMPMonitorConfig `json:"icmpConfig,omitempty"`
AgentIds []string `json:"agentIds,omitempty"`
Tags []string `json:"tags,omitempty"` // 标签列表,拥有这些标签的探针都会执行此监控
}
type NotificationQueue ¶
type NotificationQueue struct {
// contains filtered or unexported fields
}
func NewNotificationQueue ¶
func NewNotificationQueue(db *gorm.DB, alertService *AlertService, alertRecordRepo *repo.AlertRecordRepo, logger *zap.Logger) *NotificationQueue
func (*NotificationQueue) Enqueue ¶
func (q *NotificationQueue) Enqueue(recordID int64, agent *models.Agent) error
func (*NotificationQueue) GetActiveWorkers ¶
func (q *NotificationQueue) GetActiveWorkers() int
func (*NotificationQueue) GetQueueLength ¶
func (q *NotificationQueue) GetQueueLength() int
func (*NotificationQueue) Shutdown ¶
func (q *NotificationQueue) Shutdown()
func (*NotificationQueue) Start ¶
func (q *NotificationQueue) Start()
type NotificationService ¶
type NotificationService struct {
// contains filtered or unexported fields
}
NotificationService 统一通知发送入口(事件类通知,按各主机命中的告警规则驱动)
func NewNotificationService ¶
func NewNotificationService(logger *zap.Logger, db *gorm.DB, propertyService *PropertyService, alertRuleService *AlertRuleService, notifier *Notifier) *NotificationService
func (*NotificationService) ResolveMaskIP ¶
func (s *NotificationService) ResolveMaskIP(ctx context.Context, agentID string) bool
ResolveMaskIP 解析主机命中规则的 IP 打码配置(未命中规则时不打码)
func (*NotificationService) SendAlertNotification ¶
func (s *NotificationService) SendAlertNotification(ctx context.Context, notificationType string, record *models.AlertRecord, agent *models.Agent) error
SendAlertNotification 根据主机命中的告警规则发送事件通知
type NotificationTask ¶
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier 告警通知服务
func NewNotifier ¶
func (*Notifier) SendDingTalkByConfig ¶
func (n *Notifier) SendDingTalkByConfig(ctx context.Context, config map[string]interface{}, message string) error
SendDingTalkByConfig 导出方法供外部调用
func (*Notifier) SendEmailByConfig ¶
func (n *Notifier) SendEmailByConfig(ctx context.Context, config map[string]interface{}, message string) error
SendEmailByConfig 导出方法供外部调用
func (*Notifier) SendFeishuByConfig ¶
func (n *Notifier) SendFeishuByConfig(ctx context.Context, config map[string]interface{}, message string) error
SendFeishuByConfig 导出方法供外部调用
func (*Notifier) SendNotificationByConfig ¶
func (n *Notifier) SendNotificationByConfig(ctx context.Context, channelConfig *models.NotificationChannelConfig, record *models.AlertRecord, agent *models.Agent, maskIP bool) error
SendNotificationByConfig 根据新的配置结构发送通知
func (*Notifier) SendNotificationByConfigs ¶
func (n *Notifier) SendNotificationByConfigs(ctx context.Context, channelConfigs []models.NotificationChannelConfig, record *models.AlertRecord, agent *models.Agent, maskIP bool) error
SendNotificationByConfigs 根据新的配置结构向多个渠道发送通知
func (*Notifier) SendTelegramByConfig ¶
func (n *Notifier) SendTelegramByConfig(ctx context.Context, config map[string]interface{}, message string) error
SendTelegramByConfig 导出方法供外部调用
func (*Notifier) SendTestNotification ¶
func (n *Notifier) SendTestNotification(ctx context.Context, channelType string, config map[string]interface{}, message string) error
SendTestNotification 发送测试通知(动态匹配通知渠道类型)
func (*Notifier) SendWeComAppByConfig ¶
func (n *Notifier) SendWeComAppByConfig(ctx context.Context, config map[string]interface{}, message string) error
SendWeComAppByConfig 导出方法供外部调用
type OIDCAuthURL ¶
OIDCAuthURL OIDC 认证 URL 响应
type OIDCService ¶
type OIDCService struct {
// contains filtered or unexported fields
}
OIDCService OIDC 认证服务
func NewOIDCService ¶
func NewOIDCService(logger *zap.Logger, appConfig *config.AppConfig) *OIDCService
NewOIDCService 创建 OIDC 服务
func (*OIDCService) ExchangeCode ¶
ExchangeCode 交换授权码获取 token 和用户信息
func (*OIDCService) GenerateAuthURL ¶
GenerateAuthURL 生成认证 URL
type PropertyService ¶
type PropertyService struct {
// contains filtered or unexported fields
}
func NewPropertyService ¶
func NewPropertyService(logger *zap.Logger, db *gorm.DB) *PropertyService
func (*PropertyService) DeleteDNSProvider ¶
func (s *PropertyService) DeleteDNSProvider(ctx context.Context, providerType string) error
DeleteDNSProvider 删除指定类型的 DNS 服务商配置
func (*PropertyService) GetAgentInstallConfig ¶
func (s *PropertyService) GetAgentInstallConfig(ctx context.Context) (*models.AgentInstallConfig, error)
GetAgentInstallConfig 获取探针安装配置
func (*PropertyService) GetAlertConfig ¶
func (s *PropertyService) GetAlertConfig(ctx context.Context) (*models.AlertConfig, error)
GetAlertConfig 获取告警配置
func (*PropertyService) GetAppearanceConfig ¶
func (s *PropertyService) GetAppearanceConfig(ctx context.Context) (*AppearanceConfig, error)
func (*PropertyService) GetDNSProviderByType ¶
func (s *PropertyService) GetDNSProviderByType(ctx context.Context, providerType string) (*models.DNSProviderConfig, error)
GetDNSProviderByType 根据 Provider 类型获取单个配置
func (*PropertyService) GetDNSProviderConfigs ¶
func (s *PropertyService) GetDNSProviderConfigs(ctx context.Context) ([]models.DNSProviderConfig, error)
GetDNSProviderConfigs 获取 DNS 服务商配置列表
func (*PropertyService) GetNotificationChannelConfigs ¶
func (s *PropertyService) GetNotificationChannelConfigs(ctx context.Context) ([]models.NotificationChannelConfig, error)
func (*PropertyService) GetPublicIPConfig ¶
func (s *PropertyService) GetPublicIPConfig(ctx context.Context) (*models.PublicIPConfig, error)
GetPublicIPConfig 获取公网 IP 采集配置
func (*PropertyService) GetSystemConfig ¶
func (s *PropertyService) GetSystemConfig(ctx context.Context) (*models.SystemConfig, error)
func (*PropertyService) GetSystemVersion ¶
func (s *PropertyService) GetSystemVersion(ctx context.Context) (string, error)
func (*PropertyService) GetValue ¶
func (s *PropertyService) GetValue(ctx context.Context, id string, target interface{}) error
GetValue 获取属性值并反序列化
func (*PropertyService) InitializeDefaultConfigs ¶
func (s *PropertyService) InitializeDefaultConfigs(ctx context.Context) error
InitializeDefaultConfigs 初始化默认配置(如果数据库中不存在)
func (*PropertyService) SetAgentInstallConfig ¶
func (s *PropertyService) SetAgentInstallConfig(ctx context.Context, config models.AgentInstallConfig) error
SetAgentInstallConfig 设置探针安装配置
func (*PropertyService) SetAlertConfig ¶
func (s *PropertyService) SetAlertConfig(ctx context.Context, config models.AlertConfig) error
SetAlertConfig 设置告警配置
func (*PropertyService) SetAppearanceConfig ¶
func (s *PropertyService) SetAppearanceConfig(ctx context.Context, config AppearanceConfig) error
func (*PropertyService) SetDNSProviderConfigs ¶
func (s *PropertyService) SetDNSProviderConfigs(ctx context.Context, providers []models.DNSProviderConfig) error
SetDNSProviderConfigs 设置 DNS 服务商配置列表
func (*PropertyService) SetSystemVersion ¶
func (s *PropertyService) SetSystemVersion(ctx context.Context, systemVersion string) error
func (*PropertyService) UpsertDNSProvider ¶
func (s *PropertyService) UpsertDNSProvider(ctx context.Context, newProvider models.DNSProviderConfig) error
UpsertDNSProvider 创建或更新单个 DNS 服务商配置(每种类型只允许一个)
type PublicIPService ¶
type PublicIPService struct {
// contains filtered or unexported fields
}
func NewPublicIPService ¶
func NewPublicIPService(logger *zap.Logger, db *gorm.DB, propertyService *PropertyService, wsManager *websocket.Manager) *PublicIPService
type SSHLoginService ¶
type SSHLoginService struct {
SSHLoginEventRepo *repo.SSHLoginEventRepo
// contains filtered or unexported fields
}
SSHLoginService SSH登录服务
func NewSSHLoginService ¶
func NewSSHLoginService(logger *zap.Logger, db *gorm.DB, wsManager *websocket.Manager, geoIPSvc *GeoIPService, notificationSvc *NotificationService) *SSHLoginService
NewSSHLoginService 创建服务
func (*SSHLoginService) DeleteEventsByAgentID ¶
func (s *SSHLoginService) DeleteEventsByAgentID(ctx context.Context, agentID string) error
DeleteEventsByAgentID 删除探针的所有事件
func (*SSHLoginService) GetConfig ¶
func (s *SSHLoginService) GetConfig(ctx context.Context, agentID string) (*models.SSHLoginConfigData, error)
GetConfig 获取探针的配置
func (*SSHLoginService) HandleConfigResult ¶
func (s *SSHLoginService) HandleConfigResult(ctx context.Context, agentID string, result protocol.SSHLoginConfigResult) error
HandleConfigResult 处理 Agent 上报的配置应用结果
func (*SSHLoginService) HandleEvent ¶
func (s *SSHLoginService) HandleEvent(ctx context.Context, agentID string, eventData protocol.SSHLoginEvent) error
HandleEvent 处理 Agent 上报的事件
func (*SSHLoginService) UpdateConfig ¶
func (s *SSHLoginService) UpdateConfig(ctx context.Context, agentID string, req *models.SSHLoginConfigData) error
UpdateConfig 更新配置并下发到 Agent 返回: config - 配置对象, error - 错误信息
type TamperService ¶
type TamperService struct {
TamperEventRepo *repo.TamperEventRepo
// contains filtered or unexported fields
}
func NewTamperService ¶
func NewTamperService(logger *zap.Logger, db *gorm.DB, wsManager *websocket.Manager, notificationSvc *NotificationService) *TamperService
func (*TamperService) BuildInitialConfig ¶
func (s *TamperService) BuildInitialConfig(ctx context.Context, agentID string) (added, removed []string, err error)
BuildInitialConfig 构建探针初始化时的配置(用于探针连接时) 根据 enabled 状态决定发送的内容: - enabled=true: 发送所有配置的路径作为新增 - enabled=false: 发送空配置
func (*TamperService) CreateEvent ¶
func (s *TamperService) CreateEvent(ctx context.Context, agentID string, eventData *protocol.TamperEventData) error
CreateEvent 创建防篡改事件
func (*TamperService) DeleteEventsByAgentID ¶
func (s *TamperService) DeleteEventsByAgentID(ctx context.Context, id string) error
func (*TamperService) GetConfigByAgentID ¶
func (s *TamperService) GetConfigByAgentID(ctx context.Context, agentID string) (*models.TamperProtectConfigData, error)
GetConfigByAgentID 获取探针的防篡改配置
func (*TamperService) HandleConfigResult ¶
func (s *TamperService) HandleConfigResult(ctx context.Context, agentID string, resp protocol.TamperProtectResponse) error
func (*TamperService) UpdateConfig ¶
func (s *TamperService) UpdateConfig(ctx context.Context, agentID string, req *models.TamperProtectConfigData) error
UpdateConfig 更新探针的防篡改配置
func (*TamperService) UpdateConfigByAgentID ¶
func (s *TamperService) UpdateConfigByAgentID(ctx context.Context, agentID string, config *models.TamperProtectConfigData) error
type ThemeInstallResult ¶
type ThemeManifest ¶
type ThemeManifest struct {
SchemaVersion int `json:"schemaVersion"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
Author string `json:"author"`
Homepage string `json:"homepage"`
License string `json:"license"`
Preview string `json:"preview"`
Entry string `json:"entry"`
APIVersion string `json:"apiVersion"`
Capabilities []string `json:"capabilities"`
}
ThemeManifest 是 pika-theme.json 的结构,只含展示用的关键信息。
type ThemeService ¶
type ThemeService struct {
// contains filtered or unexported fields
}
ThemeService 通过扫描本地主题目录提供主题的列表、安装、启用、删除和入口 HTML 渲染。 主题数据全部存放在文件系统,不经过数据库。
func NewThemeService ¶
func NewThemeService(logger *zap.Logger, propertyService *PropertyService, cfg *config.AppConfig) (*ThemeService, error)
func (*ThemeService) Activate ¶
func (s *ThemeService) Activate(ctx context.Context, id string) error
func (*ThemeService) Active ¶
func (s *ThemeService) Active(ctx context.Context) (*ThemeInfo, error)
func (*ThemeService) ActiveDistDir ¶
func (*ThemeService) ActiveThemeID ¶
func (s *ThemeService) ActiveThemeID(ctx context.Context) string
func (*ThemeService) Install ¶
func (s *ThemeService) Install(ctx context.Context, reader io.Reader) (*ThemeInstallResult, error)
func (*ThemeService) PreviewPath ¶
func (*ThemeService) RenderIndex ¶
func (s *ThemeService) RenderIndex(ctx context.Context, runtime any, systemConfig *models.SystemConfig) ([]byte, error)
type TrafficAlerts ¶
type TrafficAlerts struct {
Sent80 bool `json:"sent80"`
Sent90 bool `json:"sent90"`
Sent100 bool `json:"sent100"`
}
TrafficAlerts 流量告警状态
type TrafficService ¶
type TrafficService struct {
// contains filtered or unexported fields
}
func NewTrafficService ¶
func NewTrafficService(logger *zap.Logger, db *gorm.DB, notificationService *NotificationService) *TrafficService
func (*TrafficService) CheckAndResetTraffic ¶
func (s *TrafficService) CheckAndResetTraffic(ctx context.Context) error
CheckAndResetTraffic 检查并重置所有到期的探针流量(定时任务调用)
func (*TrafficService) GetTrafficStats ¶
func (s *TrafficService) GetTrafficStats(ctx context.Context, agentID string) (*TrafficStats, error)
GetTrafficStats 获取流量统计信息
func (*TrafficService) ResetAgentTraffic ¶
func (s *TrafficService) ResetAgentTraffic(ctx context.Context, agentID string) error
ResetAgentTraffic 重置探针流量
func (*TrafficService) UpdateAgentTraffic ¶
func (s *TrafficService) UpdateAgentTraffic(ctx context.Context, agentID string, currentRecvTotal, currentSentTotal uint64) error
UpdateAgentTraffic 更新探针流量统计(每次上报网络指标时调用)
type TrafficStats ¶
type TrafficStats struct {
Enabled bool `json:"enabled"`
Type string `json:"type"` // 统计类型: recv/send/both
Limit uint64 `json:"limit"`
Used uint64 `json:"used"`
UsedPercent float64 `json:"usedPercent"`
Remaining uint64 `json:"remaining"`
ResetDay int `json:"resetDay"`
PeriodStart int64 `json:"periodStart"`
PeriodEnd int64 `json:"periodEnd"`
DaysUntilReset int `json:"daysUntilReset"`
Alerts TrafficAlerts `json:"alerts"`
}
TrafficStats 流量统计信息
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService User 认证服务
func NewUserService ¶
func NewUserService(logger *zap.Logger, appConfig *config.AppConfig) *UserService
NewUserService 创建 User 服务
func (*UserService) GetUsername ¶
GetUsername 获取用户名(如果认证成功)
func (*UserService) ValidateCredentials ¶
func (s *UserService) ValidateCredentials(ctx context.Context, username, password string) error
ValidateCredentials 验证用户名和密码
Source Files
¶
- account_service.go
- agent_service.go
- alert_rule_service.go
- alert_service.go
- api_key_service.go
- ddns_service.go
- geoip_service.go
- github_oauth_service.go
- live_metrics.go
- metric_converter.go
- metric_service.go
- monitor_service.go
- monitor_target.go
- notification_queue.go
- notification_service.go
- notifier.go
- oidc_service.go
- property_service.go
- public_ip_service.go
- ssh_login_service.go
- tamper_service.go
- theme.go
- theme_util.go
- traffic_service.go
- user_service.go