-
Notifications
You must be signed in to change notification settings - Fork 21
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
6 changed files
with
195 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,72 @@ | ||
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 { | ||
v1.EntityWithoutChecksum `json:",inline" db:"-"` | ||
EnvironmentId types.Binary `json:"environment_id"` | ||
HostId types.Binary `json:"host_id"` | ||
ServiceId types.Binary `json:"service_id"` | ||
EventTime types.UnixMilli `json:"event_time"` | ||
EventType string `json:"event_type"` | ||
} | ||
|
||
type SlaHostHistoryTrailColumns struct { | ||
v1.EntityWithoutChecksum `json:",inline"` | ||
EnvironmentId `json:",inline"` | ||
} | ||
|
||
type SlaServiceHistoryTrailColumns struct { | ||
v1.EntityWithoutChecksum `json:",inline"` | ||
EnvironmentId `json:",inline"` | ||
HostId types.Binary `json:"host_id"` | ||
} | ||
|
||
type EnvironmentId struct { | ||
EnvironmentId types.Binary `json:"environment_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 | ||
} |
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