2025-02-18 13:06:31 +05:30
package alertmanager
import (
2025-02-20 14:14:09 +05:30
"net/url"
2025-09-10 13:58:13 +05:30
"strings"
2025-02-18 13:06:31 +05:30
"time"
2025-03-20 21:01:41 +05:30
"github.com/SigNoz/signoz/pkg/alertmanager/alertmanagerserver"
2025-09-10 13:58:13 +05:30
"github.com/SigNoz/signoz/pkg/errors"
2025-03-20 21:01:41 +05:30
"github.com/SigNoz/signoz/pkg/factory"
2025-02-18 13:06:31 +05:30
)
type Config struct {
// Provider is the provider for the alertmanager service.
Provider string ` mapstructure:"provider" `
// Internal is the internal alertmanager configuration.
2025-03-10 01:30:42 +05:30
Signoz Signoz ` mapstructure:"signoz" yaml:"signoz" `
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.
2025-03-10 01:30:42 +05:30
alertmanagerserver . Config ` mapstructure:",squash" yaml:",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.
2025-03-10 01:30:42 +05:30
ApiURL * url . URL ` 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-09-10 13:58:13 +05:30
Provider : "signoz" ,
2025-02-20 14:14:09 +05:30
Signoz : Signoz {
2025-03-10 01:30:42 +05:30
PollInterval : 1 * time . Minute ,
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-09-10 13:58:13 +05:30
if c . Provider != "signoz" {
return errors . Newf ( errors . TypeInvalidInput , errors . CodeInvalidInput , "provider must be one of [%s], got %s" , strings . Join ( [ ] string { "signoz" } , ", " ) , c . Provider )
}
2025-02-18 13:06:31 +05:30
return nil
}