Skip to content

Commit

Permalink
logzio integration logs added
Browse files Browse the repository at this point in the history
  • Loading branch information
kotkovkirill committed Oct 19, 2024
1 parent ef35617 commit c8cfdaf
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/services/ngalert/notifier/channels/logzio_opsgenie.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ func NewLogzioOpsgenieNotifier(config *LogzioOpsgenieConfig, ns notifications.We
APIKey: config.APIKey,
APIUrl: config.APIUrl,
tmpl: t,
log: log.New("alerting.notifier." + config.Name),
log: log.New("alerting.notifier.logzio_opsgenie"),
ns: ns,
}
}

func (on *LogzioOpsgenieNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {

id := uuid.New()
logger := on.log.New("notificationId", id.String())
logger := on.log.New("requestId", id.String(), "notificationId", on.UID)

logger.Info("Executing Opsgenie (Logzio Integration) notification", "notification", on.Name)

Expand All @@ -96,16 +96,23 @@ func (on *LogzioOpsgenieNotifier) Notify(ctx context.Context, as ...*types.Alert

bodyJSON, err := on.buildOpsgenieMessage(ctx, alerts, as)
if err != nil {
return false, fmt.Errorf("build Opsgenie message: %w", err)
error := fmt.Errorf("build Opsgenie message: %w", err)
logger.Error(error.Error())
return false, error
}

body, err := json.Marshal(bodyJSON)
if err != nil {
return false, fmt.Errorf("marshal json: %w", err)
error := fmt.Errorf("marshal json: %w", err)
logger.Error(error.Error())
return false, error
}

url := fmt.Sprintf("%s?apiKey=%s", on.APIUrl, on.APIKey)


logger.Info("Sending Opsgenie (Logzio Integration) API request", "url", on.APIUrl, "body", minify(body))

cmd := &models.SendWebhookSync{
Url: url,
Body: string(body),
Expand All @@ -116,9 +123,12 @@ func (on *LogzioOpsgenieNotifier) Notify(ctx context.Context, as ...*types.Alert
}

if err := on.ns.SendWebhookSync(ctx, cmd); err != nil {
return false, fmt.Errorf("send notification to Opsgenie (Logzio Integration): %w", err)
error := fmt.Errorf("Sending Opsgenie (Logzio Integration) API request failed: %w", err)
logger.Error(error.Error())
return false, error
}

logger.Info("Sending Opsgenie API request succeeded", "url", on.APIUrl)
return true, nil
}

Expand Down

0 comments on commit c8cfdaf

Please sign in to comment.