-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathlinode.go
53 lines (48 loc) · 1.53 KB
/
linode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package linode
import (
"context"
"log"
"github.com/sirupsen/logrus"
"github.com/tailwarden/komiser/providers/linode/networking"
"github.com/tailwarden/komiser/utils"
"github.com/tailwarden/komiser/providers"
"github.com/tailwarden/komiser/providers/linode/compute"
"github.com/tailwarden/komiser/providers/linode/postgres"
"github.com/tailwarden/komiser/providers/linode/sql"
"github.com/tailwarden/komiser/providers/linode/storage"
"github.com/uptrace/bun"
)
func listOfSupportedServices() []providers.FetchDataFunction {
return []providers.FetchDataFunction{
// compute.LinodeInstancesAndInstanceDisks,
compute.LKEClusters,
storage.Volumes,
storage.Databases,
storage.Buckets,
networking.NodeBalancers,
networking.Firewalls,
sql.Instances,
postgres.Instances,
}
}
func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics) {
for _, fetchResources := range listOfSupportedServices() {
resources, err := fetchResources(ctx, client)
if err != nil {
log.Printf("[%s][Linode] %s", client.Name, err)
} else {
for _, resource := range resources {
_, err := db.NewInsert().Model(&resource).On("CONFLICT (resource_id) DO UPDATE").Set("cost = EXCLUDED.cost").Exec(context.Background())
if err != nil {
logrus.WithError(err).Errorf("db trigger failed")
}
}
if telemetry {
analytics.TrackEvent("discovered_resources", map[string]interface{}{
"provider": "Linode",
"resources": len(resources),
})
}
}
}
}