Skip to content

Commit

Permalink
Use IGL database
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 authored and lippserd committed Nov 4, 2024
1 parent 6f41bd0 commit 511a805
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/icinga-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,19 @@ func main() {
}, periodic.Immediate()).Stop()

var nclient *notifications.Client
if err := notifications.SyncSourceConfig(ctx, db, &cfg.Notifications); err != nil {
if err := notifications.SyncSourceConfig(ctx, db2, &cfg.Notifications); err != nil {
klog.Fatal(err)
}

if cfg.Notifications.Url == "" {
err = notifications.RetrieveConfig(ctx, db, &cfg.Notifications)
err = notifications.RetrieveConfig(ctx, db2, &cfg.Notifications)
if err != nil {
klog.Error(errors.Wrap(err, "cannot retrieve Icinga Notifications config"))
}
}

if cfg.Notifications.Url != "" {
nclient = notifications.NewClient(db, cfg.Notifications)
nclient = notifications.NewClient(db2, cfg.Notifications)
}

if cfg.Prometheus.Url != "" {
Expand Down
6 changes: 3 additions & 3 deletions pkg/notifications/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"context"
"encoding/json"
"github.com/icinga/icinga-go-library/database"
"github.com/icinga/icinga-kubernetes/internal"
"github.com/icinga/icinga-kubernetes/pkg/database"
"github.com/pkg/errors"
"io"
"k8s.io/klog/v2"
Expand All @@ -20,12 +20,12 @@ type Notifiable interface {
}

type Client struct {
db *database.Database
db *database.DB
client http.Client
Config
}

func NewClient(db *database.Database, c Config) *Client {
func NewClient(db *database.DB, c Config) *Client {
return &Client{db: db, client: http.Client{}, Config: c}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package notifications
import (
"context"
"fmt"
"github.com/icinga/icinga-kubernetes/pkg/database"
"github.com/icinga/icinga-go-library/database"
schemav1 "github.com/icinga/icinga-kubernetes/pkg/schema/v1"
"github.com/pkg/errors"
)

// SyncSourceConfig synchronises the Icinga Notifications credentials from the YAML config to the database.
func SyncSourceConfig(ctx context.Context, db *database.Database, config *Config) error {
func SyncSourceConfig(ctx context.Context, db *database.DB, config *Config) error {
var configPairs []*schemav1.Config

if config.Url != "" {
Expand All @@ -23,7 +23,7 @@ func SyncSourceConfig(ctx context.Context, db *database.Database, config *Config

stmt := fmt.Sprintf(
`DELETE FROM %s WHERE %s IN (?)`,
db.QuoteIdentifier(database.TableName(&schemav1.Config{})),
database.TableName(&schemav1.Config{}),
"`key`",
)

Expand All @@ -45,7 +45,7 @@ func SyncSourceConfig(ctx context.Context, db *database.Database, config *Config
}

// RetrieveConfig retrieves the Icinga Notifications config from the database. The username is "source-<sourceID>".
func RetrieveConfig(ctx context.Context, db *database.Database, config *Config) error {
func RetrieveConfig(ctx context.Context, db *database.DB, config *Config) error {
var dbConfig []*schemav1.Config
if err := db.SelectContext(ctx, &dbConfig, db.BuildSelectStmt(&schemav1.Config{}, &schemav1.Config{})); err != nil {
return errors.Wrap(err, "cannot fetch Icinga Notifications config from DB")
Expand Down

0 comments on commit 511a805

Please sign in to comment.