2025-02-18 13:06:31 +05:30
|
|
|
package alertmanager
|
|
|
|
|
|
|
|
|
|
import (
|
2025-03-05 10:01:02 +05:30
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
2025-02-20 14:14:09 +05:30
|
|
|
"net/url"
|
2025-02-18 13:06:31 +05:30
|
|
|
"time"
|
|
|
|
|
|
2025-02-20 14:14:09 +05:30
|
|
|
"go.signoz.io/signoz/pkg/alertmanager/alertmanagerserver"
|
2025-02-18 13:06:31 +05:30
|
|
|
"go.signoz.io/signoz/pkg/factory"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
|
// Provider is the provider for the alertmanager service.
|
|
|
|
|
Provider string `mapstructure:"provider"`
|
|
|
|
|
|
|
|
|
|
// Internal is the internal alertmanager configuration.
|
2025-02-20 14:14:09 +05:30
|
|
|
Signoz Signoz `mapstructure:"signoz"`
|
|
|
|
|
|
|
|
|
|
// Legacy is the legacy alertmanager configuration.
|
|
|
|
|
Legacy Legacy `mapstructure:"legacy"`
|
2025-02-18 13:06:31 +05:30
|
|
|
}
|
|
|
|
|
|
2025-02-20 14:14:09 +05:30
|
|
|
type Signoz struct {
|
2025-02-18 13:06:31 +05:30
|
|
|
// PollInterval is the interval at which the alertmanager is synced.
|
|
|
|
|
PollInterval time.Duration `mapstructure:"poll_interval"`
|
2025-03-05 10:01:02 +05:30
|
|
|
|
|
|
|
|
// Config is the config for the alertmanager server.
|
|
|
|
|
alertmanagerserver.Config `mapstructure:",squash"`
|
2025-02-18 13:06:31 +05:30
|
|
|
}
|
|
|
|
|
|
2025-02-20 14:14:09 +05:30
|
|
|
type Legacy struct {
|
2025-03-05 10:01:02 +05:30
|
|
|
// ApiURL is the URL of the legacy signoz alertmanager.
|
|
|
|
|
ApiURL string `mapstructure:"api_url"`
|
2025-02-20 14:14:09 +05:30
|
|
|
}
|
|
|
|
|
|
2025-02-18 13:06:31 +05:30
|
|
|
func NewConfigFactory() factory.ConfigFactory {
|
|
|
|
|
return factory.NewConfigFactory(factory.MustNewName("alertmanager"), newConfig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newConfig() factory.Config {
|
|
|
|
|
return Config{
|
2025-03-05 10:01:02 +05:30
|
|
|
Provider: "legacy",
|
|
|
|
|
Legacy: Legacy{
|
|
|
|
|
ApiURL: "http://alertmanager:9093/api",
|
|
|
|
|
},
|
2025-02-20 14:14:09 +05:30
|
|
|
Signoz: Signoz{
|
2025-02-18 13:06:31 +05:30
|
|
|
PollInterval: 15 * time.Second,
|
2025-03-05 10:01:02 +05:30
|
|
|
Config: alertmanagerserver.NewConfig(),
|
2025-02-18 13:06:31 +05:30
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c Config) Validate() error {
|
2025-03-05 10:01:02 +05:30
|
|
|
if c.Provider == "legacy" {
|
|
|
|
|
if c.Legacy.ApiURL == "" {
|
|
|
|
|
return errors.New("api_url is required")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := url.Parse(c.Legacy.ApiURL)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("api_url %q is invalid: %w", c.Legacy.ApiURL, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 13:06:31 +05:30
|
|
|
return nil
|
|
|
|
|
}
|