server

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cmd = cobra.Command{
		Use:   "server",
		Short: "Run main server",
		RunE: func(cmd *cobra.Command, args []string) error {

			if configFile != nil && *configFile != "" {
				v.SetConfigFile(*configFile)
			} else {
				v.AddConfigPath(".")
				v.AddConfigPath("/etc/proteus")
				v.SetConfigName("config")
				v.SetConfigType("yaml")
			}

			if err := v.ReadInConfig(); err != nil {

				if _, ok := errors.AsType[viper.ConfigFileNotFoundError](err); !ok || (*configFile != "") {
					return fmt.Errorf("failed to read configuration: %w", err)
				}
			}

			var cfg Configuration
			if err := v.Unmarshal(&cfg); err != nil {
				return fmt.Errorf("failed to unmarshal configuration: %w", err)
			}

			ctx := cmd.Context()
			l := cfg.Log.Logger(os.Stderr)
			deps, err := buildDependencies(ctx, cfg, l)
			if err != nil {
				return err
			}
			l.Info("server starting", slog.String("version", cmd.Root().Version))
			defer l.Info("server stopped")
			if err = runServerWithDependencies(ctx, deps, prometheus.DefaultRegisterer, cfg, l); errors.Is(err, context.Canceled) {
				err = nil
			}
			return err
		},
	}
)

Functions

This section is empty.

Types

type BatteryConfiguration

type BatteryConfiguration struct {
	Type     string        `yaml:"type" default:"sigenergy" help:"Battery type"`
	Interval time.Duration `yaml:"interval" default:"30s" help:"Battery poll interval"`
	Enabled  bool          `yaml:"enabled" default:"false" help:"Enable battery collector"`
}

type ClimateConfiguration

type ClimateConfiguration struct {
	Type       string                         `yaml:"type" default:"tado" help:"Climate type"`
	Controller ClimateControllerConfiguration `yaml:"controller"`
	Interval   time.Duration                  `yaml:"interval" default:"5m" help:"Climate poll interval"`
	Enabled    bool                           `yaml:"false" default:"true" help:"Enable Climate collector"`
}

type ClimateControllerConfiguration

type ClimateControllerConfiguration struct {
	Slack   SlackConfiguration `yaml:"slack"`
	Rules   string             `yaml:"rules" help:"Path to rules file"`
	Enabled bool               `yaml:"enabled" default:"false" help:"Enable climate controller"`
}

type Components

type Components struct {
	HomeWizard HomeWizardConfiguration `yaml:"homewizard" help:"HomeWizard configuration"`
	SigEnergy  SigEnergyConfiguration  `yaml:"sigenergy" help:"SigEnergy configuration"`
	SolarEdge  SolarEdgeConfiguration  `yaml:"solaredge" help:"SolarEdge configuration"`
	Tado       TadoConfiguration       `yaml:"tado" help:"Tadoº configuration"`
}

type Configuration

type Configuration struct {
	Components Components                            `yaml:"components"`
	Log        configuration.LogConfiguration        `yaml:"log"`
	Prom       configuration.PrometheusConfiguration `yaml:"prom"`
	Health     configuration.HealthConfiguration     `yaml:"health"`
	Watchdog   WatchdogConfiguration                 `yaml:"watchdog"`
	Grid       GridConfiguration                     `yaml:"grid"`
	Battery    BatteryConfiguration                  `yaml:"battery"`
	Climate    ClimateConfiguration                  `yaml:"climate"`
	Solar      SolarConfiguration                    `yaml:"solar"`
}

func (Configuration) BatteryScraper

func (c Configuration) BatteryScraper() (collector.Scraper[battery.Metrics], error)

func (Configuration) ClimateScraper

func (c Configuration) ClimateScraper(ctx context.Context, httpClient *http.Client, logger *slog.Logger) (collector.Scraper[climate.Metrics], any, error)

func (Configuration) GridScraper

func (c Configuration) GridScraper(httpClient *http.Client, logger *slog.Logger) (collector.Scraper[grid.Metrics], error)

func (Configuration) SolarScraper

func (c Configuration) SolarScraper(httpClient *http.Client) (collector.Scraper[solar.Metrics], error)

type GridConfiguration

type GridConfiguration struct {
	Type     string        `yaml:"type" default:"homewizard" help:"Grid type"`
	Interval time.Duration `yaml:"interval" default:"30s" help:"Grid poll interval"`
	Enabled  bool          `yaml:"enabled" default:"false" help:"Enable grid collector"`
}

type HomeWizardConfiguration

type HomeWizardConfiguration struct {
	Addr string `yaml:"addr" help:"HomeWizard address"`
}

type SigEnergyConfiguration

type SigEnergyConfiguration struct {
	Addr string `yaml:"addr" help:"SigEnergy address"`
}

type SlackConfiguration

type SlackConfiguration struct {
	Token    string `yaml:"token" help:"Slack token"`
	AppToken string `yaml:"apptoken" help:"Slack app token"`
}

type SolarConfiguration

type SolarConfiguration struct {
	Type     string                  `yaml:"type" default:"solaredge" help:"Solar type"`
	Store    SolarStoreConfiguration `yaml:"store"`
	Interval time.Duration           `yaml:"interval" default:"5m" help:"Solar poll interval"`
	Enabled  bool                    `yaml:"enabled" default:"false" help:"Enable solar collector"`
}

type SolarEdgeConfiguration

type SolarEdgeConfiguration struct {
	Key string `yaml:"key" help:"SolarEdge API key"`
}

type SolarStoreConfiguration

type SolarStoreConfiguration struct {
	DB       string        `yaml:"db" help:"Solar store database URL"`
	Interval time.Duration `yaml:"interval" default:"15m" help:"Solar store write interval"`
	Enabled  bool          `yaml:"enabled" default:"false" help:"Enable solar store"`
}

type TadoConfiguration

type TadoConfiguration struct {
	Storage    string `yaml:"storage" default:"/data" help:"Tado token storage directory"`
	Passphrase string `yaml:"passphrase" help:"Tado token passphrase"`
}

type WatchdogConfiguration

type WatchdogConfiguration struct {
	AlertManagerAddress string `yaml:"alertmanager" help:"Alertmanager address"`
	Enabled             bool   `yaml:"enabled" default:"false" help:"Enable watchdog"`
}

Jump to

Keyboard shortcuts

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