diff --git a/internal/incident/incident.go b/internal/incident/incident.go index a232eb971..1de773629 100644 --- a/internal/incident/incident.go +++ b/internal/incident/incident.go @@ -146,12 +146,6 @@ func (i *Incident) ProcessEvent(ctx context.Context, ev *event.Event) error { i.logger = i.logger.With(zap.String("incident", i.String())) } - if err = i.AddEvent(ctx, tx, ev); err != nil { - i.logger.Errorw("Can't insert incident event to the database", zap.Error(err)) - - return errors.New("can't insert incident event to the database") - } - switch ev.Type { case event.TypeState: if !isNew { @@ -233,10 +227,6 @@ func (i *Incident) RetriggerEscalations(ev *event.Event) { return err } - if err = i.AddEvent(ctx, tx, ev); err != nil { - return fmt.Errorf("can't insert incident event to the database: %w", err) - } - if err = i.triggerEscalations(ctx, tx, ev, escalations); err != nil { return err } diff --git a/internal/incident/incidents.go b/internal/incident/incidents.go index 5bcc36c59..e4e7efb45 100644 --- a/internal/incident/incidents.go +++ b/internal/incident/incidents.go @@ -2,7 +2,6 @@ package incident import ( "context" - "fmt" "github.com/icinga/icinga-notifications/internal/config" "github.com/icinga/icinga-notifications/internal/event" "github.com/icinga/icinga-notifications/internal/object" @@ -194,49 +193,3 @@ func GetCurrentIncidents() map[int64]*Incident { } return m } - -// ProcessEvent from an event.Event. -// -// This function first gets this Event's object.Object and its incident.Incident. Then, after performing some safety -// checks, it calls the Incident.ProcessEvent method. -// -// The returned error might be wrapped around event.ErrSuperfluousStateChange. -func ProcessEvent( - ctx context.Context, - db *icingadb.DB, - logs *logging.Logging, - runtimeConfig *config.RuntimeConfig, - ev *event.Event, -) error { - obj, err := object.FromEvent(ctx, db, ev) - if err != nil { - return fmt.Errorf("cannot sync event object: %w", err) - } - - createIncident := ev.Severity != event.SeverityNone && ev.Severity != event.SeverityOK - currentIncident, err := GetCurrent( - ctx, - db, - obj, - logs.GetChildLogger("incident"), - runtimeConfig, - createIncident) - if err != nil { - return fmt.Errorf("cannot get current incident for %q: %w", obj.DisplayName(), err) - } - - if currentIncident == nil { - switch { - // ignore non-state event without incident - case ev.Severity == event.SeverityNone: - return fmt.Errorf("%q does not have an active incident, ignoring %q event from source %d", - obj.DisplayName(), ev.Type, ev.SourceId) - case ev.Severity != event.SeverityOK: - panic(fmt.Sprintf("cannot process event %v with a non-OK state %v without a known incident", ev, ev.Severity)) - default: - return fmt.Errorf("%w: ok state event from source %d", event.ErrSuperfluousStateChange, ev.SourceId) - } - } - - return currentIncident.ProcessEvent(ctx, ev) -} diff --git a/internal/incident/sync.go b/internal/incident/sync.go index 76b1f1b2a..1cec8772b 100644 --- a/internal/incident/sync.go +++ b/internal/incident/sync.go @@ -55,15 +55,6 @@ func (i *Incident) AddEscalationTriggered(ctx context.Context, tx *sqlx.Tx, stat return err } -// AddEvent Inserts incident history record to the database and returns an error on db failure. -func (i *Incident) AddEvent(ctx context.Context, tx *sqlx.Tx, ev *event.Event) error { - ie := &EventRow{IncidentID: i.Id, EventID: ev.ID} - stmt, _ := i.db.BuildInsertStmt(ie) - _, err := tx.NamedExecContext(ctx, stmt, ie) - - return err -} - // AddRecipient adds recipient from the given *rule.Escalation to this incident. // Syncs also all the recipients with the database and returns an error on db failure. func (i *Incident) AddRecipient(ctx context.Context, tx *sqlx.Tx, escalation *rule.Escalation, eventId int64) error { diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index ad4ede4d1..a544e8d2d 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -254,13 +254,6 @@ CREATE TABLE incident ( CONSTRAINT pk_incident PRIMARY KEY (id) ); -CREATE TABLE incident_event ( - incident_id bigint NOT NULL REFERENCES incident(id), - event_id bigint NOT NULL REFERENCES event(id), - - CONSTRAINT pk_incident_event PRIMARY KEY (incident_id, event_id) -); - CREATE TYPE incident_contact_role AS ENUM ('recipient', 'subscriber', 'manager'); CREATE TABLE incident_contact ( diff --git a/schema/pgsql/upgrades/some-unique-file-name.sql b/schema/pgsql/upgrades/some-unique-file-name.sql new file mode 100644 index 000000000..79c19f8f3 --- /dev/null +++ b/schema/pgsql/upgrades/some-unique-file-name.sql @@ -0,0 +1 @@ +DROP TABLE incident_event;