Skip to content

Commit

Permalink
Merge pull request sensu#699 from sensu/feature/proxy-entity-subscrip…
Browse files Browse the repository at this point in the history
…tions

Proxy entities silencing
  • Loading branch information
palourde authored Dec 8, 2017
2 parents 91006ea + a47f297 commit eae68e0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 5 additions & 4 deletions backend/agentd/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ func getProxyEntity(event *types.Event, s store.Store) error {
// Check if an entity was found for this source. If not, we need to create it
if entity == nil {
entity = &types.Entity{
ID: event.Check.Config.Source,
Class: types.EntityProxyClass,
Environment: event.Entity.Environment,
Organization: event.Entity.Organization,
ID: event.Check.Config.Source,
Class: types.EntityProxyClass,
Environment: event.Entity.Environment,
Organization: event.Entity.Organization,
Subscriptions: addEntitySubscription(event.Check.Config.Source, []string{}),
}

if err := s.UpdateEntity(ctx, entity); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions cli/commands/entity/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package entity
import (
"io"
"strings"
"time"

"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/cli/commands/flags"
Expand Down Expand Up @@ -79,8 +78,7 @@ func printToTable(results interface{}, writer io.Writer) {
Title: "Last Seen",
CellTransformer: func(data interface{}) string {
entity, _ := data.(types.Entity)
time := time.Unix(entity.LastSeen, 0)
return time.String()
return helpers.HumanTimestamp(entity.LastSeen)
},
},
})
Expand Down
3 changes: 1 addition & 2 deletions cli/commands/entity/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package entity
import (
"io"
"strings"
"time"

"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/cli/commands/helpers"
Expand Down Expand Up @@ -73,7 +72,7 @@ func printEntityToList(r *types.Entity, writer io.Writer) {
},
{
Label: "Last Seen",
Value: time.Unix(r.LastSeen, 0).String(),
Value: helpers.HumanTimestamp(r.LastSeen),
},
{
Label: "Hostname",
Expand Down
13 changes: 13 additions & 0 deletions cli/commands/helpers/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package helpers

import "time"

// HumanTimestamp takes a timestamp and returns a readable date. If the
// timestamp equals 0, "N/A" will be returned instead of the epoch date
func HumanTimestamp(timestamp int64) string {
if timestamp == 0 {
return "N/A"
}

return time.Unix(timestamp, 0).String()
}

0 comments on commit eae68e0

Please sign in to comment.