2022-12-14 14:35:07 +00:00
|
|
|
package fetcher
|
|
|
|
|
|
|
|
import (
|
2024-01-17 16:49:34 +00:00
|
|
|
"github.com/hetznercloud/hcloud-go/v2/hcloud"
|
2022-12-14 14:35:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ Fetcher = &floatingIP{}
|
|
|
|
|
|
|
|
// NewPrimaryIP creates a new fetcher that will collect pricing information on primary IPs.
|
2023-01-25 19:24:33 +00:00
|
|
|
func NewPrimaryIP(pricing *PriceProvider, additionalLabels ...string) Fetcher {
|
|
|
|
return &primaryIP{newBase(pricing, "primaryip", []string{"datacenter", "type"}, additionalLabels...)}
|
2022-12-14 14:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type primaryIP struct {
|
|
|
|
*baseFetcher
|
|
|
|
}
|
|
|
|
|
|
|
|
func (primaryIP primaryIP) Run(client *hcloud.Client) error {
|
2024-01-17 19:19:21 +00:00
|
|
|
primaryIPs, err := client.PrimaryIP.All(ctx)
|
2022-12-14 14:35:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range primaryIPs {
|
|
|
|
datacenter := p.Datacenter
|
|
|
|
|
2022-12-29 13:45:14 +00:00
|
|
|
hourlyPrice, monthlyPrice, err := primaryIP.pricing.PrimaryIP(p.Type, datacenter.Location.Name)
|
2022-12-14 14:35:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-01-25 19:24:33 +00:00
|
|
|
labels := append([]string{
|
|
|
|
p.Name,
|
|
|
|
datacenter.Name,
|
|
|
|
string(p.Type),
|
|
|
|
},
|
|
|
|
parseAdditionalLabels(primaryIP.additionalLabels, p.Labels)...,
|
|
|
|
)
|
|
|
|
|
|
|
|
primaryIP.hourly.WithLabelValues(labels...).Set(hourlyPrice)
|
|
|
|
primaryIP.monthly.WithLabelValues(labels...).Set(monthlyPrice)
|
2022-12-14 14:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|