-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package icingadb | ||
|
||
import ( | ||
"context" | ||
"github.com/icinga/icingadb/pkg/contracts" | ||
v1 "github.com/icinga/icingadb/pkg/icingadb/v1" | ||
"github.com/icinga/icingadb/pkg/types" | ||
"golang.org/x/sync/errgroup" | ||
"time" | ||
) | ||
|
||
type SlaHistoryTrail struct { | ||
Id types.Int `json:"id" db:"-"` | ||
v1.EnvironmentMeta `json:",inline"` | ||
HostId types.Binary `json:"host_id"` | ||
ServiceId types.Binary `json:"service_id"` | ||
EventType string `json:"event_type"` | ||
EventTime types.UnixMilli `json:"event_time"` | ||
} | ||
|
||
// Fingerprint implements the contracts.Fingerprinter interface. | ||
func (sht SlaHistoryTrail) Fingerprint() contracts.Fingerprinter { | ||
return sht | ||
} | ||
|
||
// ID implements part of the contracts.IDer interface. | ||
func (sht SlaHistoryTrail) ID() contracts.ID { | ||
return sht.Id | ||
} | ||
|
||
// SetID implements part of the contracts.IDer interface. | ||
func (sht *SlaHistoryTrail) SetID(id contracts.ID) { | ||
sht.Id = id.(types.Int) | ||
} | ||
|
||
type SlaHostHistoryTrailColumns struct { | ||
v1.EntityWithoutChecksum `json:",inline"` | ||
v1.EnvironmentMeta `json:",inline"` | ||
} | ||
|
||
type SlaServiceHistoryTrailColumns struct { | ||
v1.EntityWithoutChecksum `json:",inline"` | ||
v1.EnvironmentMeta `json:",inline"` | ||
HostId types.Binary `json:"host_id"` | ||
} | ||
|
||
func CheckableToSlaTrailEntities(ctx context.Context, g *errgroup.Group, checkables <-chan contracts.Entity, eventType string) <-chan contracts.Entity { | ||
entities := make(chan contracts.Entity, 1) | ||
|
||
g.Go(func() error { | ||
defer close(entities) | ||
|
||
for { | ||
select { | ||
case checkable, ok := <-checkables: | ||
if !ok { | ||
return nil | ||
} | ||
|
||
entity := &SlaHistoryTrail{ | ||
EventTime: types.UnixMilli(time.Now()), | ||
EventType: eventType, | ||
} | ||
|
||
switch ptr := checkable.(type) { | ||
case *v1.Host: | ||
entity.HostId = ptr.Id | ||
entity.EnvironmentId = ptr.EnvironmentId | ||
case *v1.Service: | ||
entity.HostId = ptr.HostId | ||
entity.ServiceId = ptr.Id | ||
entity.EnvironmentId = ptr.EnvironmentId | ||
} | ||
|
||
entities <- entity | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
} | ||
} | ||
}) | ||
|
||
return entities | ||
} | ||
|
||
var ( | ||
_ contracts.Entity = (*SlaHistoryTrail)(nil) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters