Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

6.1 KB
Raw Blame
package alerts

import (
	"errors"

	alertconfig "github.com/rcourtman/pulse-go-rewrite/internal/alerts/config"
)

// Type aliases re-exported from alerts/config for backward compatibility.
// These guarantee compile-time type identity: alerts.AlertLevel = alertconfig.AlertLevel.
type AlertLevel = alertconfig.AlertLevel
type ActivationState = alertconfig.ActivationState
type HysteresisThreshold = alertconfig.HysteresisThreshold
type ThresholdConfig = alertconfig.ThresholdConfig
type QuietHours = alertconfig.QuietHours
type QuietHoursSuppression = alertconfig.QuietHoursSuppression
type EscalationLevel = alertconfig.EscalationLevel
type EscalationConfig = alertconfig.EscalationConfig
type GroupingConfig = alertconfig.GroupingConfig
type ScheduleConfig = alertconfig.ScheduleConfig
type FilterCondition = alertconfig.FilterCondition
type FilterStack = alertconfig.FilterStack
type CustomAlertRule = alertconfig.CustomAlertRule
type DockerThresholdConfig = alertconfig.DockerThresholdConfig
type PMGThresholdConfig = alertconfig.PMGThresholdConfig
type SnapshotAlertConfig = alertconfig.SnapshotAlertConfig
type BackupAlertConfig = alertconfig.BackupAlertConfig
type GuestLookup = alertconfig.GuestLookup
type AlertConfig = alertconfig.AlertConfig
type AlertIntentSignal = alertconfig.AlertIntentSignal
type BackupOfflineIntentPolicy = alertconfig.BackupOfflineIntentPolicy
type AlertIntentRule = alertconfig.AlertIntentRule
type AlertIntentPolicyDocument = alertconfig.AlertIntentPolicyDocument

const (
	AlertLevelInfo                        = alertconfig.AlertLevelInfo
	AlertLevelWarning                     = alertconfig.AlertLevelWarning
	AlertLevelCritical                    = alertconfig.AlertLevelCritical
	ActivationPending                     = alertconfig.ActivationPending
	ActivationActive                      = alertconfig.ActivationActive
	ActivationSnoozed                     = alertconfig.ActivationSnoozed
	CurrentAlertIntentPolicySchemaVersion = alertconfig.CurrentAlertIntentPolicySchemaVersion
	AlertIntentSignalDefault              = alertconfig.AlertIntentSignalDefault
	AlertIntentSignalOffline              = alertconfig.AlertIntentSignalOffline
	AlertIntentSignalAvailability         = alertconfig.AlertIntentSignalAvailability
	DefaultEscalationRepeatMinutes        = alertconfig.DefaultEscalationRepeatMinutes
	MinEscalationDelayMinutes             = alertconfig.MinEscalationDelayMinutes
	MaxEscalationDelayMinutes             = alertconfig.MaxEscalationDelayMinutes
	MinEscalationRepeatMinutes            = alertconfig.MinEscalationRepeatMinutes
	MaxEscalationRepeatMinutes            = alertconfig.MaxEscalationRepeatMinutes
	DefaultCPUEvaluationWindowSeconds     = alertconfig.DefaultCPUEvaluationWindowSeconds
	MaxMetricEvaluationWindowSeconds      = alertconfig.MaxMetricEvaluationWindowSeconds
)

func NewAlertIntentPolicyDocument() AlertIntentPolicyDocument {
	return alertconfig.NewAlertIntentPolicyDocument()
}

func MetricAlertIntentSignal(metric string) string {
	return alertconfig.MetricAlertIntentSignal(metric)
}

func NormalizeAlertIntentPolicyDocument(document AlertIntentPolicyDocument) AlertIntentPolicyDocument {
	return alertconfig.NormalizeAlertIntentPolicyDocument(document)
}

func ValidateAlertIntentPolicyDocument(document AlertIntentPolicyDocument) error {
	return alertconfig.ValidateAlertIntentPolicyDocument(document)
}

func ValidAlertIntentSignal(signal string) bool {
	return alertconfig.ValidAlertIntentSignal(signal)
}

var ErrAlertNotFound = errors.New("alert not found")

func NormalizeAlertConfigAliases(config *AlertConfig) {
	alertconfig.NormalizeAlertConfigAliases(config)
}

func NormalizeMetricTimeThresholds(input map[string]map[string]int) map[string]map[string]int {
	return alertconfig.NormalizeMetricTimeThresholds(input)
}

func NormalizeMetricEvaluationWindows(input map[string]map[string]int) map[string]map[string]int {
	return alertconfig.NormalizeMetricEvaluationWindows(input)
}

func NormalizeHysteresisThreshold(threshold *HysteresisThreshold, defaultTrigger, defaultClear float64, metricName string) *HysteresisThreshold {
	return alertconfig.NormalizeHysteresisThreshold(threshold, defaultTrigger, defaultClear, metricName)
}

func NormalizeDockerIgnoredPrefixes(prefixes []string) []string {
	return alertconfig.NormalizeDockerIgnoredPrefixes(prefixes)
}

func NormalizeEscalationDestinationIDs(destinationIDs []string) []string {
	return alertconfig.NormalizeEscalationDestinationIDs(destinationIDs)
}

func CanonicalResourceTypeKeys(resourceType string) []string {
	return alertconfig.CanonicalResourceTypeKeys(resourceType)
}

func NormalizePoweredOffSeverity(level AlertLevel) AlertLevel {
	return alertconfig.NormalizePoweredOffSeverity(level)
}

func NormalizeAlertLevel(level AlertLevel) AlertLevel {
	return alertconfig.NormalizeAlertLevel(level)
}

func normalizePoweredOffSeverity(level AlertLevel) AlertLevel {
	return alertconfig.NormalizePoweredOffSeverity(level)
}

func ensureValidHysteresis(threshold *HysteresisThreshold, metricName string) {
	alertconfig.EnsureValidHysteresis(threshold, metricName)
}

// NormalizeDockerDefaults fills unset Docker container thresholds with their
// factory values and stores an Off count threshold as 0.
func NormalizeDockerDefaults(config *AlertConfig) { alertconfig.NormalizeDockerDefaults(config) }

// NormalizePMGDefaults fills unset PMG thresholds with their factory values
// and stores an Off threshold as 0.
func NormalizePMGDefaults(config *AlertConfig) { alertconfig.NormalizePMGDefaults(config) }

func normalizeSnapshotDefaults(config *AlertConfig) { alertconfig.NormalizeSnapshotDefaults(config) }
func normalizeBackupDefaults(config *AlertConfig)   { alertconfig.NormalizeBackupDefaults(config) }

// NormalizeRecoveryOverrides converts per-guest backup/snapshot overrides that
// are exact threshold copies of the current global defaults into sparse
// enabled-only overrides so they track future global edits (#1126).
func NormalizeRecoveryOverrides(config *AlertConfig) {
	alertconfig.NormalizeRecoveryOverrides(config)
}

func validateQuietHoursTimezone(config *AlertConfig) { alertconfig.ValidateQuietHoursTimezone(config) }