mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
Return host 'status' with host endpoints (#307)
This commit is contained in:
parent
01f20372f2
commit
f9fa3e289f
@ -20,6 +20,7 @@ type HostStore interface {
|
||||
type HostService interface {
|
||||
ListHosts(ctx context.Context) ([]*Host, error)
|
||||
GetHost(ctx context.Context, id uint) (*Host, error)
|
||||
HostStatus(ctx context.Context, host Host) string
|
||||
DeleteHost(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,11 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type hostResponse struct {
|
||||
kolide.Host
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Get Host
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -15,8 +20,8 @@ type getHostRequest struct {
|
||||
}
|
||||
|
||||
type getHostResponse struct {
|
||||
Host *kolide.Host `json:"host"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Host *hostResponse `json:"host"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getHostResponse) error() error { return r.Err }
|
||||
@ -28,7 +33,7 @@ func makeGetHostEndpoint(svc kolide.Service) endpoint.Endpoint {
|
||||
if err != nil {
|
||||
return getHostResponse{Err: err}, nil
|
||||
}
|
||||
return getHostResponse{host, nil}, nil
|
||||
return getHostResponse{&hostResponse{*host, svc.HostStatus(ctx, *host)}, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,8 +42,8 @@ func makeGetHostEndpoint(svc kolide.Service) endpoint.Endpoint {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type listHostsResponse struct {
|
||||
Hosts []kolide.Host `json:"hosts"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Hosts []hostResponse `json:"hosts"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r listHostsResponse) error() error { return r.Err }
|
||||
@ -50,9 +55,9 @@ func makeListHostsEndpoint(svc kolide.Service) endpoint.Endpoint {
|
||||
return listHostsResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
resp := listHostsResponse{Hosts: []kolide.Host{}}
|
||||
resp := listHostsResponse{Hosts: []hostResponse{}}
|
||||
for _, host := range hosts {
|
||||
resp.Hosts = append(resp.Hosts, *host)
|
||||
resp.Hosts = append(resp.Hosts, hostResponse{*host, svc.HostStatus(ctx, *host)})
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kolide/kolide-ose/server/kolide"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -13,6 +15,14 @@ func (svc service) GetHost(ctx context.Context, id uint) (*kolide.Host, error) {
|
||||
return svc.ds.Host(id)
|
||||
}
|
||||
|
||||
func (svc service) HostStatus(ctx context.Context, host kolide.Host) string {
|
||||
if host.UpdatedAt.Add(30 * time.Minute).Before(svc.clock.Now()) {
|
||||
return "offline"
|
||||
} else {
|
||||
return "online"
|
||||
}
|
||||
}
|
||||
|
||||
func (svc service) DeleteHost(ctx context.Context, id uint) error {
|
||||
host, err := svc.ds.Host(id)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user