Make naming of host columns consistent (#1183)
Adding consistency between API and DB helps to make it easier for users and developers working with the API to correctly order things. Closes #317
This commit is contained in:
@@ -47,7 +47,7 @@ func (c *goqueryClient) CheckHost(query string) (gqhosts.Host, error) {
|
||||
var host *fleet.Host
|
||||
for _, h := range res.Hosts {
|
||||
// We allow hosts to be looked up by hostname in addition to UUID
|
||||
if query == h.UUID || query == h.HostName || query == h.ComputerName {
|
||||
if query == h.UUID || query == h.Hostname || query == h.ComputerName {
|
||||
host = h
|
||||
break
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (c *goqueryClient) CheckHost(query string) (gqhosts.Host, error) {
|
||||
return gqhosts.Host{}, fmt.Errorf("host %s not found", query)
|
||||
}
|
||||
|
||||
c.hostnameByUUID[host.UUID] = host.HostName
|
||||
c.hostnameByUUID[host.UUID] = host.Hostname
|
||||
|
||||
return gqhosts.Host{
|
||||
UUID: host.UUID,
|
||||
|
||||
@@ -28,7 +28,7 @@ func newJsonWriter() *jsonWriter {
|
||||
|
||||
func (w *jsonWriter) WriteResult(res fleet.DistributedQueryResult) error {
|
||||
out := resultOutput{
|
||||
HostIdentifier: res.Host.HostName,
|
||||
HostIdentifier: res.Host.Hostname,
|
||||
Rows: res.Rows,
|
||||
Error: res.Error,
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func (w *prettyWriter) WriteResult(res fleet.DistributedQueryResult) error {
|
||||
// Extract columns from the results in the appropriate order
|
||||
for _, res := range w.results {
|
||||
for _, row := range res.Rows {
|
||||
cols := []string{res.Host.HostName}
|
||||
cols := []string{res.Host.Hostname}
|
||||
for _, col := range columns {
|
||||
cols = append(cols, row[col])
|
||||
}
|
||||
|
||||
@@ -483,7 +483,7 @@ If `additional_info_filters` is not specified, no `additional` information will
|
||||
|
||||
#### Example
|
||||
|
||||
`GET /api/v1/fleet/hosts?page=0&per_page=100&order_key=host_name&query=2ce`
|
||||
`GET /api/v1/fleet/hosts?page=0&per_page=100&order_key=hostname&query=2ce`
|
||||
|
||||
##### Request query parameters
|
||||
|
||||
@@ -491,7 +491,7 @@ If `additional_info_filters` is not specified, no `additional` information will
|
||||
{
|
||||
"page": 0,
|
||||
"per_page": 100,
|
||||
"order_key": "host_name",
|
||||
"order_key": "hostname",
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+170
-170
@@ -44,25 +44,25 @@ var enrollTests = []struct {
|
||||
|
||||
func testSaveHosts(t *testing.T, ds fleet.Datastore) {
|
||||
host, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
HostName: "foo.local",
|
||||
PrimaryIP: "192.168.1.1",
|
||||
PrimaryMac: "30-65-EC-6F-C4-58",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
Hostname: "foo.local",
|
||||
PrimaryIP: "192.168.1.1",
|
||||
PrimaryMac: "30-65-EC-6F-C4-58",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, host)
|
||||
|
||||
host.HostName = "bar.local"
|
||||
host.Hostname = "bar.local"
|
||||
err = ds.SaveHost(host)
|
||||
require.Nil(t, err)
|
||||
|
||||
host, err = ds.Host(host.ID)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "bar.local", host.HostName)
|
||||
assert.Equal(t, "bar.local", host.Hostname)
|
||||
assert.Equal(t, "192.168.1.1", host.PrimaryIP)
|
||||
assert.Equal(t, "30-65-EC-6F-C4-58", host.PrimaryMac)
|
||||
|
||||
@@ -95,14 +95,14 @@ func testSaveHosts(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
func testSaveHostPackStats(t *testing.T, ds fleet.Datastore) {
|
||||
host, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
HostName: "foo.local",
|
||||
PrimaryIP: "192.168.1.1",
|
||||
PrimaryMac: "30-65-EC-6F-C4-58",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
Hostname: "foo.local",
|
||||
PrimaryIP: "192.168.1.1",
|
||||
PrimaryMac: "30-65-EC-6F-C4-58",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, host)
|
||||
@@ -214,12 +214,12 @@ func testSaveHostPackStats(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
func testDeleteHost(t *testing.T, ds fleet.Datastore) {
|
||||
host, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
HostName: "foo.local",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
Hostname: "foo.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, host)
|
||||
@@ -235,13 +235,13 @@ func testListHosts(t *testing.T, ds fleet.Datastore) {
|
||||
hosts := []*fleet.Host{}
|
||||
for i := 0; i < 10; i++ {
|
||||
host, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
HostName: fmt.Sprintf("foo.local%d", i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
Hostname: fmt.Sprintf("foo.local%d", i),
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
@@ -279,13 +279,13 @@ func testListHosts(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
func testListHostsFilterAdditional(t *testing.T, ds fleet.Datastore) {
|
||||
h, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "foobar",
|
||||
NodeKey: "nodekey",
|
||||
UUID: "uuid",
|
||||
HostName: "foobar.local",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "foobar",
|
||||
NodeKey: "nodekey",
|
||||
UUID: "uuid",
|
||||
Hostname: "foobar.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -317,13 +317,13 @@ func testListHostsFilterAdditional(t *testing.T, ds fleet.Datastore) {
|
||||
func testListHostsStatus(t *testing.T, ds fleet.Datastore) {
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now().Add(-time.Duration(i) * time.Minute),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
HostName: fmt.Sprintf("foo.local%d", i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now().Add(-time.Duration(i) * time.Minute),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
Hostname: fmt.Sprintf("foo.local%d", i),
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
@@ -354,14 +354,14 @@ func testListHostsQuery(t *testing.T, ds fleet.Datastore) {
|
||||
hosts := []*fleet.Host{}
|
||||
for i := 0; i < 10; i++ {
|
||||
host, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("uuid_00%d", i),
|
||||
HostName: fmt.Sprintf("hostname%%00%d", i),
|
||||
HardwareSerial: fmt.Sprintf("serial00%d", i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("uuid_00%d", i),
|
||||
Hostname: fmt.Sprintf("hostname%%00%d", i),
|
||||
HardwareSerial: fmt.Sprintf("serial00%d", i),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
host.PrimaryIP = fmt.Sprintf("192.168.1.%d", i)
|
||||
@@ -470,35 +470,35 @@ func testAuthenticateHostCaseSensitive(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
func testSearchHosts(t *testing.T, ds fleet.Datastore) {
|
||||
_, err := ds.NewHost(&fleet.Host{
|
||||
OsqueryHostID: "1234",
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
HostName: "foo.local",
|
||||
OsqueryHostID: "1234",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
Hostname: "foo.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
h2, err := ds.NewHost(&fleet.Host{
|
||||
OsqueryHostID: "5679",
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "2",
|
||||
UUID: "2",
|
||||
HostName: "bar.local",
|
||||
OsqueryHostID: "5679",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "2",
|
||||
UUID: "2",
|
||||
Hostname: "bar.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
h3, err := ds.NewHost(&fleet.Host{
|
||||
OsqueryHostID: "99999",
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "3",
|
||||
UUID: "abc-def-ghi",
|
||||
HostName: "foo-bar.local",
|
||||
OsqueryHostID: "99999",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
NodeKey: "3",
|
||||
UUID: "abc-def-ghi",
|
||||
Hostname: "foo-bar.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -517,12 +517,12 @@ func testSearchHosts(t *testing.T, ds fleet.Datastore) {
|
||||
host, err := ds.SearchHosts(filter, "foo", h3.ID)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, host, 1)
|
||||
assert.Equal(t, "foo.local", host[0].HostName)
|
||||
assert.Equal(t, "foo.local", host[0].Hostname)
|
||||
|
||||
host, err = ds.SearchHosts(filter, "foo", h3.ID, h2.ID)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, host, 1)
|
||||
assert.Equal(t, "foo.local", host[0].HostName)
|
||||
assert.Equal(t, "foo.local", host[0].Hostname)
|
||||
|
||||
host, err = ds.SearchHosts(filter, "abc")
|
||||
require.Nil(t, err)
|
||||
@@ -562,13 +562,13 @@ func testSearchHostsLimit(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
for i := 0; i < 15; i++ {
|
||||
_, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: fmt.Sprintf("host%d", i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
HostName: fmt.Sprintf("foo.%d.local", i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: fmt.Sprintf("host%d", i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
Hostname: fmt.Sprintf("foo.%d.local", i),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
}
|
||||
@@ -591,12 +591,12 @@ func testGenerateHostStatusStatistics(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
// Online
|
||||
h, err := ds.NewHost(&fleet.Host{
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdateTime: mockClock.Now().Add(-30 * time.Second),
|
||||
LabelUpdateTime: mockClock.Now().Add(-30 * time.Second),
|
||||
SeenTime: mockClock.Now().Add(-30 * time.Second),
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdatedAt: mockClock.Now().Add(-30 * time.Second),
|
||||
LabelUpdatedAt: mockClock.Now().Add(-30 * time.Second),
|
||||
SeenTime: mockClock.Now().Add(-30 * time.Second),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
h.DistributedInterval = 15
|
||||
@@ -605,12 +605,12 @@ func testGenerateHostStatusStatistics(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
// Online
|
||||
h, err = ds.NewHost(&fleet.Host{
|
||||
ID: 2,
|
||||
OsqueryHostID: "2",
|
||||
NodeKey: "2",
|
||||
DetailUpdateTime: mockClock.Now().Add(-1 * time.Minute),
|
||||
LabelUpdateTime: mockClock.Now().Add(-1 * time.Minute),
|
||||
SeenTime: mockClock.Now().Add(-1 * time.Minute),
|
||||
ID: 2,
|
||||
OsqueryHostID: "2",
|
||||
NodeKey: "2",
|
||||
DetailUpdatedAt: mockClock.Now().Add(-1 * time.Minute),
|
||||
LabelUpdatedAt: mockClock.Now().Add(-1 * time.Minute),
|
||||
SeenTime: mockClock.Now().Add(-1 * time.Minute),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
h.DistributedInterval = 60
|
||||
@@ -619,12 +619,12 @@ func testGenerateHostStatusStatistics(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
// Offline
|
||||
h, err = ds.NewHost(&fleet.Host{
|
||||
ID: 3,
|
||||
OsqueryHostID: "3",
|
||||
NodeKey: "3",
|
||||
DetailUpdateTime: mockClock.Now().Add(-1 * time.Hour),
|
||||
LabelUpdateTime: mockClock.Now().Add(-1 * time.Hour),
|
||||
SeenTime: mockClock.Now().Add(-1 * time.Hour),
|
||||
ID: 3,
|
||||
OsqueryHostID: "3",
|
||||
NodeKey: "3",
|
||||
DetailUpdatedAt: mockClock.Now().Add(-1 * time.Hour),
|
||||
LabelUpdatedAt: mockClock.Now().Add(-1 * time.Hour),
|
||||
SeenTime: mockClock.Now().Add(-1 * time.Hour),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
h.DistributedInterval = 300
|
||||
@@ -633,12 +633,12 @@ func testGenerateHostStatusStatistics(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
// MIA
|
||||
h, err = ds.NewHost(&fleet.Host{
|
||||
ID: 4,
|
||||
OsqueryHostID: "4",
|
||||
NodeKey: "4",
|
||||
DetailUpdateTime: mockClock.Now().Add(-35 * (24 * time.Hour)),
|
||||
LabelUpdateTime: mockClock.Now().Add(-35 * (24 * time.Hour)),
|
||||
SeenTime: mockClock.Now().Add(-35 * (24 * time.Hour)),
|
||||
ID: 4,
|
||||
OsqueryHostID: "4",
|
||||
NodeKey: "4",
|
||||
DetailUpdatedAt: mockClock.Now().Add(-35 * (24 * time.Hour)),
|
||||
LabelUpdatedAt: mockClock.Now().Add(-35 * (24 * time.Hour)),
|
||||
SeenTime: mockClock.Now().Add(-35 * (24 * time.Hour)),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -664,13 +664,13 @@ func testMarkHostSeen(t *testing.T, ds fleet.Datastore) {
|
||||
aDayAgo := mockClock.Now().Add(-24 * time.Hour).UTC()
|
||||
|
||||
h1, err := ds.NewHost(&fleet.Host{
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
UUID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdateTime: aDayAgo,
|
||||
LabelUpdateTime: aDayAgo,
|
||||
SeenTime: aDayAgo,
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
UUID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdatedAt: aDayAgo,
|
||||
LabelUpdatedAt: aDayAgo,
|
||||
SeenTime: aDayAgo,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -700,24 +700,24 @@ func testMarkHostsSeen(t *testing.T, ds fleet.Datastore) {
|
||||
aDayAgo := mockClock.Now().Add(-24 * time.Hour).UTC()
|
||||
|
||||
h1, err := ds.NewHost(&fleet.Host{
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
UUID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdateTime: aDayAgo,
|
||||
LabelUpdateTime: aDayAgo,
|
||||
SeenTime: aDayAgo,
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
UUID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdatedAt: aDayAgo,
|
||||
LabelUpdatedAt: aDayAgo,
|
||||
SeenTime: aDayAgo,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
h2, err := ds.NewHost(&fleet.Host{
|
||||
ID: 2,
|
||||
OsqueryHostID: "2",
|
||||
UUID: "2",
|
||||
NodeKey: "2",
|
||||
DetailUpdateTime: aDayAgo,
|
||||
LabelUpdateTime: aDayAgo,
|
||||
SeenTime: aDayAgo,
|
||||
ID: 2,
|
||||
OsqueryHostID: "2",
|
||||
UUID: "2",
|
||||
NodeKey: "2",
|
||||
DetailUpdatedAt: aDayAgo,
|
||||
LabelUpdatedAt: aDayAgo,
|
||||
SeenTime: aDayAgo,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -757,26 +757,26 @@ func testCleanupIncomingHosts(t *testing.T, ds fleet.Datastore) {
|
||||
mockClock := clock.NewMockClock()
|
||||
|
||||
h1, err := ds.NewHost(&fleet.Host{
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
UUID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdateTime: mockClock.Now(),
|
||||
LabelUpdateTime: mockClock.Now(),
|
||||
SeenTime: mockClock.Now(),
|
||||
ID: 1,
|
||||
OsqueryHostID: "1",
|
||||
UUID: "1",
|
||||
NodeKey: "1",
|
||||
DetailUpdatedAt: mockClock.Now(),
|
||||
LabelUpdatedAt: mockClock.Now(),
|
||||
SeenTime: mockClock.Now(),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
h2, err := ds.NewHost(&fleet.Host{
|
||||
ID: 2,
|
||||
OsqueryHostID: "2",
|
||||
UUID: "2",
|
||||
NodeKey: "2",
|
||||
HostName: "foobar",
|
||||
OsqueryVersion: "3.2.3",
|
||||
DetailUpdateTime: mockClock.Now(),
|
||||
LabelUpdateTime: mockClock.Now(),
|
||||
SeenTime: mockClock.Now(),
|
||||
ID: 2,
|
||||
OsqueryHostID: "2",
|
||||
UUID: "2",
|
||||
NodeKey: "2",
|
||||
Hostname: "foobar",
|
||||
OsqueryVersion: "3.2.3",
|
||||
DetailUpdatedAt: mockClock.Now(),
|
||||
LabelUpdatedAt: mockClock.Now(),
|
||||
SeenTime: mockClock.Now(),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -802,13 +802,13 @@ func testCleanupIncomingHosts(t *testing.T, ds fleet.Datastore) {
|
||||
func testHostIDsByName(t *testing.T, ds fleet.Datastore) {
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: fmt.Sprintf("host%d", i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
HostName: fmt.Sprintf("foo.%d.local", i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: fmt.Sprintf("host%d", i),
|
||||
NodeKey: fmt.Sprintf("%d", i),
|
||||
UUID: fmt.Sprintf("%d", i),
|
||||
Hostname: fmt.Sprintf("foo.%d.local", i),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
}
|
||||
@@ -822,19 +822,19 @@ func testHostIDsByName(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
func testHostAdditional(t *testing.T, ds fleet.Datastore) {
|
||||
_, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "foobar",
|
||||
NodeKey: "nodekey",
|
||||
UUID: "uuid",
|
||||
HostName: "foobar.local",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "foobar",
|
||||
NodeKey: "nodekey",
|
||||
UUID: "uuid",
|
||||
Hostname: "foobar.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
h, err := ds.AuthenticateHost("nodekey")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "foobar.local", h.HostName)
|
||||
assert.Equal(t, "foobar.local", h.Hostname)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
// Additional not yet set
|
||||
@@ -850,7 +850,7 @@ func testHostAdditional(t *testing.T, ds fleet.Datastore) {
|
||||
// Additional should not be loaded for authenticatehost
|
||||
h, err = ds.AuthenticateHost("nodekey")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "foobar.local", h.HostName)
|
||||
assert.Equal(t, "foobar.local", h.Hostname)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
h, err = ds.Host(h.ID)
|
||||
@@ -860,13 +860,13 @@ func testHostAdditional(t *testing.T, ds fleet.Datastore) {
|
||||
// Update besides additional. Additional should be unchanged.
|
||||
h, err = ds.AuthenticateHost("nodekey")
|
||||
require.Nil(t, err)
|
||||
h.HostName = "baz.local"
|
||||
h.Hostname = "baz.local"
|
||||
err = ds.SaveHost(h)
|
||||
require.Nil(t, err)
|
||||
|
||||
h, err = ds.AuthenticateHost("nodekey")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "baz.local", h.HostName)
|
||||
assert.Equal(t, "baz.local", h.Hostname)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
h, err = ds.Host(h.ID)
|
||||
@@ -883,7 +883,7 @@ func testHostAdditional(t *testing.T, ds fleet.Datastore) {
|
||||
|
||||
h, err = ds.AuthenticateHost("nodekey")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "baz.local", h.HostName)
|
||||
assert.Equal(t, "baz.local", h.Hostname)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
h, err = ds.Host(h.ID)
|
||||
@@ -894,13 +894,13 @@ func testHostAdditional(t *testing.T, ds fleet.Datastore) {
|
||||
func testHostByIdentifier(t *testing.T, ds fleet.Datastore) {
|
||||
for i := 1; i <= 10; i++ {
|
||||
_, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: fmt.Sprintf("osquery_host_id_%d", i),
|
||||
NodeKey: fmt.Sprintf("node_key_%d", i),
|
||||
UUID: fmt.Sprintf("uuid_%d", i),
|
||||
HostName: fmt.Sprintf("hostname_%d", i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: fmt.Sprintf("osquery_host_id_%d", i),
|
||||
NodeKey: fmt.Sprintf("node_key_%d", i),
|
||||
UUID: fmt.Sprintf("uuid_%d", i),
|
||||
Hostname: fmt.Sprintf("hostname_%d", i),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func testLabels(t *testing.T, db fleet.Datastore) {
|
||||
|
||||
host, err = db.Host(host.ID)
|
||||
require.NoError(t, err)
|
||||
host.LabelUpdateTime = baseTime
|
||||
host.LabelUpdatedAt = baseTime
|
||||
|
||||
// Now no queries should be returned
|
||||
queries, err = db.LabelQueriesForHost(host, baseTime.Add(-1*time.Minute))
|
||||
@@ -239,35 +239,35 @@ func testSearchLabelsLimit(t *testing.T, db fleet.Datastore) {
|
||||
|
||||
func testListHostsInLabel(t *testing.T, db fleet.Datastore) {
|
||||
h1, err := db.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "1",
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
HostName: "foo.local",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "1",
|
||||
NodeKey: "1",
|
||||
UUID: "1",
|
||||
Hostname: "foo.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
h2, err := db.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "2",
|
||||
NodeKey: "2",
|
||||
UUID: "2",
|
||||
HostName: "bar.local",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "2",
|
||||
NodeKey: "2",
|
||||
UUID: "2",
|
||||
Hostname: "bar.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
h3, err := db.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "3",
|
||||
NodeKey: "3",
|
||||
UUID: "3",
|
||||
HostName: "baz.local",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: "3",
|
||||
NodeKey: "3",
|
||||
UUID: "3",
|
||||
Hostname: "baz.local",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -317,13 +317,13 @@ func testListUniqueHostsInLabels(t *testing.T, db fleet.Datastore) {
|
||||
hosts := []*fleet.Host{}
|
||||
for i := 0; i < 4; i++ {
|
||||
h, err := db.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: strconv.Itoa(i),
|
||||
UUID: strconv.Itoa(i),
|
||||
HostName: fmt.Sprintf("host_%d", i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: strconv.Itoa(i),
|
||||
UUID: strconv.Itoa(i),
|
||||
Hostname: fmt.Sprintf("host_%d", i),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, h)
|
||||
@@ -392,13 +392,13 @@ func testChangeLabelDetails(t *testing.T, db fleet.Datastore) {
|
||||
func setupLabelSpecsTest(t *testing.T, ds fleet.Datastore) []*fleet.LabelSpec {
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err := ds.NewHost(&fleet.Host{
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: strconv.Itoa(i),
|
||||
UUID: strconv.Itoa(i),
|
||||
HostName: strconv.Itoa(i),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(i),
|
||||
NodeKey: strconv.Itoa(i),
|
||||
UUID: strconv.Itoa(i),
|
||||
Hostname: strconv.Itoa(i),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ func testCountHostsInTargets(t *testing.T, ds fleet.Datastore) {
|
||||
hostCount += 1
|
||||
h, err := ds.NewHost(&fleet.Host{
|
||||
OsqueryHostID: strconv.Itoa(hostCount),
|
||||
DetailUpdateTime: mockClock.Now(),
|
||||
LabelUpdateTime: mockClock.Now(),
|
||||
DetailUpdatedAt: mockClock.Now(),
|
||||
LabelUpdatedAt: mockClock.Now(),
|
||||
SeenTime: mockClock.Now(),
|
||||
NodeKey: strconv.Itoa(hostCount),
|
||||
DistributedInterval: distributedInterval,
|
||||
@@ -235,11 +235,11 @@ func testHostIDsInTargets(t *testing.T, ds fleet.Datastore) {
|
||||
initHost := func() *fleet.Host {
|
||||
hostCount += 1
|
||||
h, err := ds.NewHost(&fleet.Host{
|
||||
OsqueryHostID: strconv.Itoa(hostCount),
|
||||
NodeKey: strconv.Itoa(hostCount),
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
OsqueryHostID: strconv.Itoa(hostCount),
|
||||
NodeKey: strconv.Itoa(hostCount),
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
return h
|
||||
|
||||
@@ -28,16 +28,16 @@ func testUnicode(t *testing.T, ds fleet.Datastore) {
|
||||
assert.Equal(t, "測試", label.Name)
|
||||
|
||||
host, err := ds.NewHost(&fleet.Host{
|
||||
HostName: "🍌",
|
||||
DetailUpdateTime: time.Now(),
|
||||
LabelUpdateTime: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
Hostname: "🍌",
|
||||
DetailUpdatedAt: time.Now(),
|
||||
LabelUpdatedAt: time.Now(),
|
||||
SeenTime: time.Now(),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
host, err = ds.Host(host.ID)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "🍌", host.HostName)
|
||||
assert.Equal(t, "🍌", host.Hostname)
|
||||
|
||||
user, err := ds.NewUser(&fleet.User{Username: "🍱", Password: []byte{}})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -79,19 +79,19 @@ func (d *Datastore) ListHosts(filter fleet.TeamFilter, opt fleet.HostListOptions
|
||||
// Apply ordering
|
||||
if opt.OrderKey != "" {
|
||||
var fields = map[string]string{
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_update_time": "DetailUpdateTime",
|
||||
"hostname": "HostName",
|
||||
"uuid": "UUID",
|
||||
"platform": "Platform",
|
||||
"osquery_version": "OsqueryVersion",
|
||||
"os_version": "OSVersion",
|
||||
"uptime": "Uptime",
|
||||
"memory": "PhysicalMemory",
|
||||
"mac": "PrimaryMAC",
|
||||
"ip": "PrimaryIP",
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_updated_at": "DetailUpdatedAt",
|
||||
"hostname": "Hostname",
|
||||
"uuid": "UUID",
|
||||
"platform": "Platform",
|
||||
"osquery_version": "OsqueryVersion",
|
||||
"os_version": "OSVersion",
|
||||
"uptime": "Uptime",
|
||||
"memory": "Memory",
|
||||
"mac": "PrimaryMAC",
|
||||
"ip": "PrimaryIP",
|
||||
}
|
||||
if err := sortResults(hosts, opt.ListOptions, fields); err != nil {
|
||||
return nil, err
|
||||
@@ -164,9 +164,9 @@ func (d *Datastore) EnrollHost(osQueryHostID, nodeKey string, teamID *uint, cool
|
||||
}
|
||||
|
||||
host := fleet.Host{
|
||||
OsqueryHostID: osQueryHostID,
|
||||
NodeKey: nodeKey,
|
||||
DetailUpdateTime: time.Unix(0, 0).Add(24 * time.Hour),
|
||||
OsqueryHostID: osQueryHostID,
|
||||
NodeKey: nodeKey,
|
||||
DetailUpdatedAt: time.Unix(0, 0).Add(24 * time.Hour),
|
||||
}
|
||||
|
||||
host.CreatedAt = time.Now().UTC()
|
||||
@@ -230,7 +230,7 @@ func (d *Datastore) SearchHosts(filter fleet.TeamFilter, query string, omit ...u
|
||||
break
|
||||
}
|
||||
|
||||
if (strings.Contains(h.HostName, query) || strings.Contains(h.UUID, query)) && !omitLookup[h.ID] {
|
||||
if (strings.Contains(h.Hostname, query) || strings.Contains(h.UUID, query)) && !omitLookup[h.ID] {
|
||||
results = append(results, h)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -360,15 +360,15 @@ func (d *Datastore) createDevHosts() error {
|
||||
UpdatedAt: time.Now().Add(-20 * time.Minute),
|
||||
},
|
||||
},
|
||||
NodeKey: "totally-legit",
|
||||
HostName: "jmeller-mbp.local",
|
||||
UUID: "1234-5678-9101",
|
||||
Platform: "darwin",
|
||||
OsqueryVersion: "2.0.0",
|
||||
OSVersion: "Mac OS X 10.11.6",
|
||||
Uptime: 60 * time.Minute,
|
||||
PhysicalMemory: 4145483776,
|
||||
DetailUpdateTime: time.Now().Add(-20 * time.Minute),
|
||||
NodeKey: "totally-legit",
|
||||
Hostname: "jmeller-mbp.local",
|
||||
UUID: "1234-5678-9101",
|
||||
Platform: "darwin",
|
||||
OsqueryVersion: "2.0.0",
|
||||
OSVersion: "Mac OS X 10.11.6",
|
||||
Uptime: 60 * time.Minute,
|
||||
Memory: 4145483776,
|
||||
DetailUpdatedAt: time.Now().Add(-20 * time.Minute),
|
||||
},
|
||||
{
|
||||
UpdateCreateTimestamps: fleet.UpdateCreateTimestamps{
|
||||
@@ -380,15 +380,15 @@ func (d *Datastore) createDevHosts() error {
|
||||
},
|
||||
},
|
||||
|
||||
NodeKey: "definitely-legit",
|
||||
HostName: "marpaia.local",
|
||||
UUID: "1234-5678-9102",
|
||||
Platform: "windows",
|
||||
OsqueryVersion: "2.0.0",
|
||||
OSVersion: "Windows 10.0.0",
|
||||
Uptime: 60 * time.Minute,
|
||||
PhysicalMemory: 17179869184,
|
||||
DetailUpdateTime: time.Now().Add(-10 * time.Second),
|
||||
NodeKey: "definitely-legit",
|
||||
Hostname: "marpaia.local",
|
||||
UUID: "1234-5678-9102",
|
||||
Platform: "windows",
|
||||
OsqueryVersion: "2.0.0",
|
||||
OSVersion: "Windows 10.0.0",
|
||||
Uptime: 60 * time.Minute,
|
||||
Memory: 17179869184,
|
||||
DetailUpdatedAt: time.Now().Add(-10 * time.Second),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -49,14 +49,14 @@ func (d *Datastore) ListInvites(opt fleet.ListOptions) ([]*fleet.Invite, error)
|
||||
// Apply ordering
|
||||
if opt.OrderKey != "" {
|
||||
var fields = map[string]string{
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_update_time": "DetailUpdateTime",
|
||||
"email": "Email",
|
||||
"admin": "Admin",
|
||||
"name": "Name",
|
||||
"position": "Position",
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_updated_at": "DetailUpdatedAt",
|
||||
"email": "Email",
|
||||
"admin": "Admin",
|
||||
"name": "Name",
|
||||
"position": "Position",
|
||||
}
|
||||
if err := sortResults(invites, opt, fields); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -225,19 +225,19 @@ func (d *Datastore) ListHostsInPack(pid uint, opt fleet.ListOptions) ([]uint, er
|
||||
// Apply ordering
|
||||
if opt.OrderKey != "" {
|
||||
var fields = map[string]string{
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_update_time": "DetailUpdateTime",
|
||||
"hostname": "HostName",
|
||||
"uuid": "UUID",
|
||||
"platform": "Platform",
|
||||
"osquery_version": "OsqueryVersion",
|
||||
"os_version": "OSVersion",
|
||||
"uptime": "Uptime",
|
||||
"memory": "PhysicalMemory",
|
||||
"mac": "PrimaryMAC",
|
||||
"ip": "PrimaryIP",
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_updated_at": "DetailUpdatedAt",
|
||||
"hostname": "Hostname",
|
||||
"uuid": "UUID",
|
||||
"platform": "Platform",
|
||||
"osquery_version": "OsqueryVersion",
|
||||
"os_version": "OSVersion",
|
||||
"uptime": "Uptime",
|
||||
"memory": "Memory",
|
||||
"mac": "PrimaryMAC",
|
||||
"ip": "PrimaryIP",
|
||||
}
|
||||
if err := sortResults(hosts, opt, fields); err != nil {
|
||||
return nil, err
|
||||
@@ -273,19 +273,19 @@ func (d *Datastore) ListExplicitHostsInPack(pid uint, opt fleet.ListOptions) ([]
|
||||
// Apply ordering
|
||||
if opt.OrderKey != "" {
|
||||
var fields = map[string]string{
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_update_time": "DetailUpdateTime",
|
||||
"hostname": "HostName",
|
||||
"uuid": "UUID",
|
||||
"platform": "Platform",
|
||||
"osquery_version": "OsqueryVersion",
|
||||
"os_version": "OSVersion",
|
||||
"uptime": "Uptime",
|
||||
"memory": "PhysicalMemory",
|
||||
"mac": "PrimaryMAC",
|
||||
"ip": "PrimaryIP",
|
||||
"id": "ID",
|
||||
"created_at": "CreatedAt",
|
||||
"updated_at": "UpdatedAt",
|
||||
"detail_updated_at": "DetailUpdatedAt",
|
||||
"hostname": "Hostname",
|
||||
"uuid": "UUID",
|
||||
"platform": "Platform",
|
||||
"osquery_version": "OsqueryVersion",
|
||||
"os_version": "OSVersion",
|
||||
"uptime": "Uptime",
|
||||
"memory": "Memory",
|
||||
"mac": "PrimaryMAC",
|
||||
"ip": "PrimaryIP",
|
||||
}
|
||||
if err := sortResults(hosts, opt, fields); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -12,22 +12,22 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var hostSearchColumns = []string{"host_name", "uuid", "hardware_serial", "primary_ip"}
|
||||
var hostSearchColumns = []string{"hostname", "uuid", "hardware_serial", "primary_ip"}
|
||||
|
||||
func (d *Datastore) NewHost(host *fleet.Host) (*fleet.Host, error) {
|
||||
sqlStatement := `
|
||||
INSERT INTO hosts (
|
||||
osquery_host_id,
|
||||
detail_update_time,
|
||||
label_update_time,
|
||||
detail_updated_at,
|
||||
label_updated_at,
|
||||
node_key,
|
||||
host_name,
|
||||
hostname,
|
||||
uuid,
|
||||
platform,
|
||||
osquery_version,
|
||||
os_version,
|
||||
uptime,
|
||||
physical_memory,
|
||||
memory,
|
||||
seen_time,
|
||||
team_id
|
||||
)
|
||||
@@ -36,16 +36,16 @@ func (d *Datastore) NewHost(host *fleet.Host) (*fleet.Host, error) {
|
||||
result, err := d.db.Exec(
|
||||
sqlStatement,
|
||||
host.OsqueryHostID,
|
||||
host.DetailUpdateTime,
|
||||
host.LabelUpdateTime,
|
||||
host.DetailUpdatedAt,
|
||||
host.LabelUpdatedAt,
|
||||
host.NodeKey,
|
||||
host.HostName,
|
||||
host.Hostname,
|
||||
host.UUID,
|
||||
host.Platform,
|
||||
host.OsqueryVersion,
|
||||
host.OSVersion,
|
||||
host.Uptime,
|
||||
host.PhysicalMemory,
|
||||
host.Memory,
|
||||
host.SeenTime,
|
||||
host.TeamID,
|
||||
)
|
||||
@@ -57,20 +57,19 @@ func (d *Datastore) NewHost(host *fleet.Host) (*fleet.Host, error) {
|
||||
return host, nil
|
||||
}
|
||||
|
||||
// TODO needs test
|
||||
func (d *Datastore) SaveHost(host *fleet.Host) error {
|
||||
sqlStatement := `
|
||||
UPDATE hosts SET
|
||||
detail_update_time = ?,
|
||||
label_update_time = ?,
|
||||
detail_updated_at = ?,
|
||||
label_updated_at = ?,
|
||||
node_key = ?,
|
||||
host_name = ?,
|
||||
hostname = ?,
|
||||
uuid = ?,
|
||||
platform = ?,
|
||||
osquery_version = ?,
|
||||
os_version = ?,
|
||||
uptime = ?,
|
||||
physical_memory = ?,
|
||||
memory = ?,
|
||||
cpu_type = ?,
|
||||
cpu_subtype = ?,
|
||||
cpu_brand = ?,
|
||||
@@ -95,16 +94,16 @@ func (d *Datastore) SaveHost(host *fleet.Host) error {
|
||||
WHERE id = ?
|
||||
`
|
||||
_, err := d.db.Exec(sqlStatement,
|
||||
host.DetailUpdateTime,
|
||||
host.LabelUpdateTime,
|
||||
host.DetailUpdatedAt,
|
||||
host.LabelUpdatedAt,
|
||||
host.NodeKey,
|
||||
host.HostName,
|
||||
host.Hostname,
|
||||
host.UUID,
|
||||
host.Platform,
|
||||
host.OsqueryVersion,
|
||||
host.OSVersion,
|
||||
host.Uptime,
|
||||
host.PhysicalMemory,
|
||||
host.Memory,
|
||||
host.CPUType,
|
||||
host.CPUSubtype,
|
||||
host.CPUBrand,
|
||||
@@ -288,9 +287,9 @@ func (d *Datastore) ListHosts(filter fleet.TeamFilter, opt fleet.HostListOptions
|
||||
h.osquery_host_id,
|
||||
h.created_at,
|
||||
h.updated_at,
|
||||
h.detail_update_time,
|
||||
h.detail_updated_at,
|
||||
h.node_key,
|
||||
h.host_name,
|
||||
h.hostname,
|
||||
h.uuid,
|
||||
h.platform,
|
||||
h.osquery_version,
|
||||
@@ -299,7 +298,7 @@ func (d *Datastore) ListHosts(filter fleet.TeamFilter, opt fleet.HostListOptions
|
||||
h.platform_like,
|
||||
h.code_name,
|
||||
h.uptime,
|
||||
h.physical_memory,
|
||||
h.memory,
|
||||
h.cpu_type,
|
||||
h.cpu_subtype,
|
||||
h.cpu_brand,
|
||||
@@ -317,7 +316,7 @@ func (d *Datastore) ListHosts(filter fleet.TeamFilter, opt fleet.HostListOptions
|
||||
h.config_tls_refresh,
|
||||
h.primary_ip,
|
||||
h.primary_mac,
|
||||
h.label_update_time,
|
||||
h.label_updated_at,
|
||||
h.team_id,
|
||||
h.refetch_requested,
|
||||
t.name AS team_name
|
||||
@@ -379,7 +378,7 @@ func (d *Datastore) ListHosts(filter fleet.TeamFilter, opt fleet.HostListOptions
|
||||
func (d *Datastore) CleanupIncomingHosts(now time.Time) error {
|
||||
sqlStatement := `
|
||||
DELETE FROM hosts
|
||||
WHERE host_name = '' AND osquery_version = ''
|
||||
WHERE hostname = '' AND osquery_version = ''
|
||||
AND created_at < (? - INTERVAL 5 MINUTE)
|
||||
`
|
||||
if _, err := d.db.Exec(sqlStatement, now); err != nil {
|
||||
@@ -435,7 +434,7 @@ func (d *Datastore) EnrollHost(osqueryHostID, nodeKey string, teamID *uint, cool
|
||||
zeroTime := time.Unix(0, 0).Add(24 * time.Hour)
|
||||
|
||||
var id int64
|
||||
err := tx.Get(&host, `SELECT id, last_enroll_time FROM hosts WHERE osquery_host_id = ?`, osqueryHostID)
|
||||
err := tx.Get(&host, `SELECT id, last_enrolled_at FROM hosts WHERE osquery_host_id = ?`, osqueryHostID)
|
||||
switch {
|
||||
case err != nil && !errors.Is(err, sql.ErrNoRows):
|
||||
return errors.Wrap(err, "check existing")
|
||||
@@ -444,8 +443,8 @@ func (d *Datastore) EnrollHost(osqueryHostID, nodeKey string, teamID *uint, cool
|
||||
// Create new host record
|
||||
sqlInsert := `
|
||||
INSERT INTO hosts (
|
||||
detail_update_time,
|
||||
label_update_time,
|
||||
detail_updated_at,
|
||||
label_updated_at,
|
||||
osquery_host_id,
|
||||
seen_time,
|
||||
node_key,
|
||||
@@ -464,7 +463,7 @@ func (d *Datastore) EnrollHost(osqueryHostID, nodeKey string, teamID *uint, cool
|
||||
// Prevent hosts from enrolling too often with the same identifier.
|
||||
// Prior to adding this we saw many hosts (probably VMs) with the
|
||||
// same identifier competing for enrollment and causing perf issues.
|
||||
if cooldown > 0 && time.Since(host.LastEnrollTime) < cooldown {
|
||||
if cooldown > 0 && time.Since(host.LastEnrolledAt) < cooldown {
|
||||
return backoff.Permanent(fmt.Errorf("host identified by %s enrolling too often", osqueryHostID))
|
||||
}
|
||||
id = int64(host.ID)
|
||||
@@ -473,7 +472,7 @@ func (d *Datastore) EnrollHost(osqueryHostID, nodeKey string, teamID *uint, cool
|
||||
UPDATE hosts
|
||||
SET node_key = ?,
|
||||
team_id = ?,
|
||||
last_enroll_time = NOW()
|
||||
last_enrolled_at = NOW()
|
||||
WHERE osquery_host_id = ?
|
||||
`
|
||||
_, err := tx.Exec(sqlUpdate, nodeKey, teamID, osqueryHostID)
|
||||
@@ -513,10 +512,10 @@ func (d *Datastore) AuthenticateHost(nodeKey string) (*fleet.Host, error) {
|
||||
osquery_host_id,
|
||||
created_at,
|
||||
updated_at,
|
||||
detail_update_time,
|
||||
label_update_time,
|
||||
detail_updated_at,
|
||||
label_updated_at,
|
||||
node_key,
|
||||
host_name,
|
||||
hostname,
|
||||
uuid,
|
||||
platform,
|
||||
osquery_version,
|
||||
@@ -525,7 +524,7 @@ func (d *Datastore) AuthenticateHost(nodeKey string) (*fleet.Host, error) {
|
||||
platform_like,
|
||||
code_name,
|
||||
uptime,
|
||||
physical_memory,
|
||||
memory,
|
||||
cpu_type,
|
||||
cpu_subtype,
|
||||
cpu_brand,
|
||||
@@ -616,7 +615,7 @@ func (d *Datastore) searchHostsWithOmits(filter fleet.TeamFilter, query string,
|
||||
FROM hosts
|
||||
WHERE
|
||||
(
|
||||
MATCH (host_name, uuid) AGAINST (? IN BOOLEAN MODE)
|
||||
MATCH (hostname, uuid) AGAINST (? IN BOOLEAN MODE)
|
||||
OR MATCH (primary_ip, primary_mac) AGAINST (? IN BOOLEAN MODE)
|
||||
)
|
||||
AND id NOT IN (?) AND %s
|
||||
@@ -691,7 +690,7 @@ func (d *Datastore) SearchHosts(filter fleet.TeamFilter, query string, omit ...u
|
||||
FROM hosts
|
||||
WHERE
|
||||
(
|
||||
MATCH (host_name, uuid) AGAINST (? IN BOOLEAN MODE)
|
||||
MATCH (hostname, uuid) AGAINST (? IN BOOLEAN MODE)
|
||||
OR MATCH (primary_ip, primary_mac) AGAINST (? IN BOOLEAN MODE)
|
||||
) AND %s
|
||||
LIMIT 10
|
||||
@@ -714,7 +713,7 @@ func (d *Datastore) HostIDsByName(filter fleet.TeamFilter, hostnames []string) (
|
||||
|
||||
sqlStatement := fmt.Sprintf(`
|
||||
SELECT id FROM hosts
|
||||
WHERE host_name IN (?) AND %s
|
||||
WHERE hostname IN (?) AND %s
|
||||
`, d.whereFilterHostsByTeams(filter, "hosts"),
|
||||
)
|
||||
|
||||
@@ -735,7 +734,7 @@ func (d *Datastore) HostIDsByName(filter fleet.TeamFilter, hostnames []string) (
|
||||
func (d *Datastore) HostByIdentifier(identifier string) (*fleet.Host, error) {
|
||||
sql := `
|
||||
SELECT * FROM hosts
|
||||
WHERE ? IN (host_name, osquery_host_id, node_key, uuid)
|
||||
WHERE ? IN (hostname, osquery_host_id, node_key, uuid)
|
||||
LIMIT 1
|
||||
`
|
||||
host := &fleet.Host{}
|
||||
|
||||
@@ -76,7 +76,7 @@ DELETE FROM label_membership WHERE label_id = ?
|
||||
// Use ignore because duplicate hostnames could appear in
|
||||
// different batches and would result in duplicate key errors.
|
||||
sql = `
|
||||
INSERT IGNORE INTO label_membership (label_id, host_id) (SELECT ?, id FROM hosts where host_name IN (?))
|
||||
INSERT IGNORE INTO label_membership (label_id, host_id) (SELECT ?, id FROM hosts where hostname IN (?))
|
||||
`
|
||||
sql, args, err := sqlx.In(sql, labelID, hostnames)
|
||||
if err != nil {
|
||||
@@ -161,7 +161,7 @@ WHERE name = ?
|
||||
|
||||
func (d *Datastore) getLabelHostnames(label *fleet.LabelSpec) error {
|
||||
sql := `
|
||||
SELECT host_name
|
||||
SELECT hostname
|
||||
FROM hosts
|
||||
WHERE id IN
|
||||
(
|
||||
@@ -268,7 +268,7 @@ func (d *Datastore) ListLabels(filter fleet.TeamFilter, opt fleet.ListOptions) (
|
||||
func (d *Datastore) LabelQueriesForHost(host *fleet.Host, cutoff time.Time) (map[string]string, error) {
|
||||
var rows *sql.Rows
|
||||
var err error
|
||||
if host.LabelUpdateTime.Before(cutoff) {
|
||||
if host.LabelUpdatedAt.Before(cutoff) {
|
||||
// Retrieve all labels (with matching platform) for this host
|
||||
sql := `
|
||||
SELECT id, query
|
||||
@@ -291,7 +291,7 @@ func (d *Datastore) LabelQueriesForHost(host *fleet.Host, cutoff time.Time) (map
|
||||
rows, err = d.db.Query(
|
||||
sql,
|
||||
host.Platform,
|
||||
host.LabelUpdateTime,
|
||||
host.LabelUpdatedAt,
|
||||
host.Platform,
|
||||
fleet.LabelMembershipTypeDynamic,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20210623133615, Down_20210623133615)
|
||||
}
|
||||
|
||||
func Up_20210623133615(tx *sql.Tx) error {
|
||||
sql := `
|
||||
ALTER TABLE hosts
|
||||
CHANGE COLUMN host_name hostname varchar(255) NOT NULL DEFAULT '',
|
||||
CHANGE COLUMN physical_memory memory bigint(20) NOT NULL DEFAULT '0',
|
||||
CHANGE COLUMN detail_update_time detail_updated_at timestamp NULL DEFAULT NULL,
|
||||
CHANGE COLUMN label_update_time label_updated_at timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',
|
||||
CHANGE COLUMN last_enroll_time last_enrolled_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
`
|
||||
if _, err := tx.Exec(sql); err != nil {
|
||||
return errors.Wrap(err, "rename columns")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20210623133615(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
||||
@@ -121,14 +121,14 @@ type Host struct {
|
||||
// used to retrieve host information. It is sent from osquery and may currently be
|
||||
// a GUID or a Host Name, but in either case, it MUST be unique
|
||||
OsqueryHostID string `json:"-" db:"osquery_host_id"`
|
||||
DetailUpdateTime time.Time `json:"detail_updated_at" db:"detail_update_time"` // Time that the host details were last updated
|
||||
LabelUpdateTime time.Time `json:"label_updated_at" db:"label_update_time"` // Time that the host details were last updated
|
||||
LastEnrollTime time.Time `json:"last_enrolled_at" db:"last_enroll_time"` // Time that the host last enrolled
|
||||
SeenTime time.Time `json:"seen_time" db:"seen_time"` // Time that the host was last "seen"
|
||||
DetailUpdatedAt time.Time `json:"detail_updated_at" db:"detail_updated_at"` // Time that the host details were last updated
|
||||
LabelUpdatedAt time.Time `json:"label_updated_at" db:"label_updated_at"` // Time that the host labels were last updated
|
||||
LastEnrolledAt time.Time `json:"last_enrolled_at" db:"last_enrolled_at"` // Time that the host last enrolled
|
||||
SeenTime time.Time `json:"seen_time" db:"seen_time"` // Time that the host was last "seen"
|
||||
RefetchRequested bool `json:"refetch_requested" db:"refetch_requested"`
|
||||
NodeKey string `json:"-" db:"node_key"`
|
||||
HostName string `json:"hostname" db:"host_name"` // there is a fulltext index on this field
|
||||
UUID string `json:"uuid" db:"uuid"` // there is a fulltext index on this field
|
||||
Hostname string `json:"hostname" db:"hostname"` // there is a fulltext index on this field
|
||||
UUID string `json:"uuid" db:"uuid"` // there is a fulltext index on this field
|
||||
Platform string `json:"platform"`
|
||||
OsqueryVersion string `json:"osquery_version" db:"osquery_version"`
|
||||
OSVersion string `json:"os_version" db:"os_version"`
|
||||
@@ -136,7 +136,7 @@ type Host struct {
|
||||
PlatformLike string `json:"platform_like" db:"platform_like"`
|
||||
CodeName string `json:"code_name" db:"code_name"`
|
||||
Uptime time.Duration `json:"uptime"`
|
||||
PhysicalMemory int64 `json:"memory" sql:"type:bigint" db:"physical_memory"`
|
||||
Memory int64 `json:"memory" sql:"type:bigint" db:"memory"`
|
||||
// system_info fields
|
||||
CPUType string `json:"cpu_type" db:"cpu_type"`
|
||||
CPUSubtype string `json:"cpu_subtype" db:"cpu_subtype"`
|
||||
|
||||
@@ -95,7 +95,7 @@ func testQueryResultsStoreErrors(t *testing.T, store fleet.QueryResultStore) {
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
},
|
||||
},
|
||||
DetailUpdateTime: time.Now().UTC(),
|
||||
DetailUpdatedAt: time.Now().UTC(),
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -132,8 +132,8 @@ func testQueryResultsStore(t *testing.T, store fleet.QueryResultStore) {
|
||||
},
|
||||
},
|
||||
|
||||
DetailUpdateTime: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
DetailUpdatedAt: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
},
|
||||
},
|
||||
fleet.DistributedQueryResult{
|
||||
@@ -150,8 +150,8 @@ func testQueryResultsStore(t *testing.T, store fleet.QueryResultStore) {
|
||||
},
|
||||
},
|
||||
|
||||
DetailUpdateTime: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
DetailUpdatedAt: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
},
|
||||
},
|
||||
fleet.DistributedQueryResult{
|
||||
@@ -168,8 +168,8 @@ func testQueryResultsStore(t *testing.T, store fleet.QueryResultStore) {
|
||||
},
|
||||
},
|
||||
|
||||
DetailUpdateTime: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
DetailUpdatedAt: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func testQueryResultsStore(t *testing.T, store fleet.QueryResultStore) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
expected2 := []fleet.DistributedQueryResult{
|
||||
fleet.DistributedQueryResult{
|
||||
{
|
||||
DistributedQueryCampaignID: 2,
|
||||
Rows: []map[string]string{{"tim": "tom"}},
|
||||
Host: fleet.Host{
|
||||
@@ -195,11 +195,11 @@ func testQueryResultsStore(t *testing.T, store fleet.QueryResultStore) {
|
||||
},
|
||||
},
|
||||
|
||||
DetailUpdateTime: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
DetailUpdatedAt: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
},
|
||||
},
|
||||
fleet.DistributedQueryResult{
|
||||
{
|
||||
DistributedQueryCampaignID: 2,
|
||||
Rows: []map[string]string{{"slim": "slam"}},
|
||||
Host: fleet.Host{
|
||||
@@ -213,8 +213,8 @@ func testQueryResultsStore(t *testing.T, store fleet.QueryResultStore) {
|
||||
},
|
||||
},
|
||||
|
||||
DetailUpdateTime: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
DetailUpdatedAt: time.Now().UTC(),
|
||||
SeenTime: time.Now().UTC(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
type HostResponse struct {
|
||||
*fleet.Host
|
||||
Status fleet.HostStatus `json:"status"`
|
||||
DisplayText string `json:"display_text"`
|
||||
DisplayText string `json:"display_text"`
|
||||
Labels []fleet.Label `json:"labels,omitempty"`
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func hostResponseForHost(ctx context.Context, svc fleet.Service, host *fleet.Hos
|
||||
return &HostResponse{
|
||||
Host: host,
|
||||
Status: host.Status(time.Now()),
|
||||
DisplayText: host.HostName,
|
||||
DisplayText: host.Hostname,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ func hostResponseForHost(ctx context.Context, svc fleet.Service, host *fleet.Hos
|
||||
type HostDetailResponse struct {
|
||||
fleet.HostDetail
|
||||
Status fleet.HostStatus `json:"status"`
|
||||
DisplayText string `json:"display_text"`
|
||||
DisplayText string `json:"display_text"`
|
||||
}
|
||||
|
||||
func hostDetailResponseForHost(ctx context.Context, svc fleet.Service, host *fleet.HostDetail) (*HostDetailResponse, error) {
|
||||
return &HostDetailResponse{
|
||||
HostDetail: *host,
|
||||
Status: host.Status(time.Now()),
|
||||
DisplayText: host.HostName,
|
||||
DisplayText: host.Hostname,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -223,9 +223,9 @@ func makeAddHostsToTeamEndpoint(svc fleet.Service) endpoint.Endpoint {
|
||||
type addHostsToTeamByFilterRequest struct {
|
||||
TeamID *uint `json:"team_id"`
|
||||
Filters struct {
|
||||
MatchQuery string `json:"query"`
|
||||
MatchQuery string `json:"query"`
|
||||
Status fleet.HostStatus `json:"status"`
|
||||
LabelID *uint `json:"label_id"`
|
||||
LabelID *uint `json:"label_id"`
|
||||
} `json:"filters"`
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ func TestAuthenticatedHost(t *testing.T) {
|
||||
ds := new(mock.Store)
|
||||
svc := newTestService(ds, nil, nil)
|
||||
|
||||
expectedHost := fleet.Host{HostName: "foo!"}
|
||||
expectedHost := fleet.Host{Hostname: "foo!"}
|
||||
goodNodeKey := "foo bar baz bing bang boom"
|
||||
|
||||
ds.AuthenticateHostFunc = func(secret string) (*fleet.Host, error) {
|
||||
|
||||
@@ -77,7 +77,7 @@ func makeSearchTargetsEndpoint(svc fleet.Service) endpoint.Endpoint {
|
||||
Host: host,
|
||||
Status: host.Status(time.Now()),
|
||||
},
|
||||
host.HostName,
|
||||
host.Hostname,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ func (svc Service) StreamCampaignResults(ctx context.Context, conn *websocket.Co
|
||||
if row == nil {
|
||||
continue
|
||||
}
|
||||
row["host_hostname"] = res.Host.HostName
|
||||
row["host_hostname"] = res.Host.Hostname
|
||||
filteredRows = append(filteredRows, row)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ func (svc *Service) CarveBegin(ctx context.Context, payload fleet.CarveBeginPayl
|
||||
|
||||
now := time.Now().UTC()
|
||||
carve := &fleet.CarveMetadata{
|
||||
Name: fmt.Sprintf("%s-%s-%s", host.HostName, now.Format(time.RFC3339), payload.RequestId),
|
||||
Name: fmt.Sprintf("%s-%s-%s", host.Hostname, now.Format(time.RFC3339), payload.RequestId),
|
||||
HostId: host.ID,
|
||||
BlockCount: payload.BlockCount,
|
||||
BlockSize: payload.BlockSize,
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestListHosts(t *testing.T) {
|
||||
assert.Len(t, hosts, 0)
|
||||
|
||||
_, err = ds.NewHost(&fleet.Host{
|
||||
HostName: "foo",
|
||||
Hostname: "foo",
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestDeleteHost(t *testing.T) {
|
||||
svc := newTestService(ds, nil, nil)
|
||||
|
||||
host, err := ds.NewHost(&fleet.Host{
|
||||
HostName: "foo",
|
||||
Hostname: "foo",
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.NotZero(t, host.ID)
|
||||
|
||||
@@ -551,11 +551,11 @@ var detailQueries = map[string]detailQuery{
|
||||
}
|
||||
|
||||
var err error
|
||||
host.PhysicalMemory, err = strconv.ParseInt(emptyToZero(rows[0]["physical_memory"]), 10, 64)
|
||||
host.Memory, err = strconv.ParseInt(emptyToZero(rows[0]["physical_memory"]), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
host.HostName = rows[0]["hostname"]
|
||||
host.Hostname = rows[0]["hostname"]
|
||||
host.UUID = rows[0]["uuid"]
|
||||
host.CPUType = rows[0]["cpu_type"]
|
||||
host.CPUSubtype = rows[0]["cpu_subtype"]
|
||||
@@ -777,7 +777,7 @@ FROM python_packages;
|
||||
if providedName == "" {
|
||||
level.Debug(logger).Log(
|
||||
"msg", "host reported scheduled query with empty name",
|
||||
"host", host.HostName,
|
||||
"host", host.Hostname,
|
||||
)
|
||||
continue
|
||||
}
|
||||
@@ -785,7 +785,7 @@ FROM python_packages;
|
||||
if delimiter == "" {
|
||||
level.Debug(logger).Log(
|
||||
"msg", "host reported scheduled query with empty delimiter",
|
||||
"host", host.HostName,
|
||||
"host", host.Hostname,
|
||||
)
|
||||
continue
|
||||
}
|
||||
@@ -798,7 +798,7 @@ FROM python_packages;
|
||||
if len(parts) != 2 {
|
||||
level.Debug(logger).Log(
|
||||
"msg", "could not split pack and query names",
|
||||
"host", host.HostName,
|
||||
"host", host.Hostname,
|
||||
"name", providedName,
|
||||
"delimiter", delimiter,
|
||||
)
|
||||
@@ -849,7 +849,7 @@ func ingestSoftware(logger log.Logger, host *fleet.Host, rows []map[string]strin
|
||||
if name == "" {
|
||||
level.Debug(logger).Log(
|
||||
"msg", "host reported software with empty name",
|
||||
"host", host.HostName,
|
||||
"host", host.Hostname,
|
||||
"version", version,
|
||||
"source", source,
|
||||
)
|
||||
@@ -858,7 +858,7 @@ func ingestSoftware(logger log.Logger, host *fleet.Host, rows []map[string]strin
|
||||
if source == "" {
|
||||
level.Debug(logger).Log(
|
||||
"msg", "host reported software with empty name",
|
||||
"host", host.HostName,
|
||||
"host", host.Hostname,
|
||||
"version", version,
|
||||
"name", name,
|
||||
)
|
||||
@@ -877,7 +877,7 @@ func ingestSoftware(logger log.Logger, host *fleet.Host, rows []map[string]strin
|
||||
// osqueryd to fill in the host details
|
||||
func (svc *Service) hostDetailQueries(host fleet.Host) (map[string]string, error) {
|
||||
queries := make(map[string]string)
|
||||
if host.DetailUpdateTime.After(svc.clock.Now().Add(-svc.config.Osquery.DetailUpdateInterval)) && !host.RefetchRequested {
|
||||
if host.DetailUpdatedAt.After(svc.clock.Now().Add(-svc.config.Osquery.DetailUpdateInterval)) && !host.RefetchRequested {
|
||||
// No need to update already fresh details
|
||||
return queries, nil
|
||||
}
|
||||
@@ -952,7 +952,7 @@ func (svc *Service) GetDistributedQueries(ctx context.Context) (map[string]strin
|
||||
}
|
||||
|
||||
accelerate := uint(0)
|
||||
if host.HostName == "" || host.Platform == "" {
|
||||
if host.Hostname == "" || host.Platform == "" {
|
||||
// Assume this host is just enrolling, and accelerate checkins
|
||||
// (to allow for platform restricted labels to run quickly
|
||||
// after platform is retrieved from details)
|
||||
@@ -1119,7 +1119,7 @@ func (svc *Service) SubmitDistributedQueryResults(ctx context.Context, results f
|
||||
}
|
||||
|
||||
if len(labelResults) > 0 {
|
||||
host.LabelUpdateTime = svc.clock.Now()
|
||||
host.LabelUpdatedAt = svc.clock.Now()
|
||||
err = svc.ds.RecordLabelQueryExecutions(&host, labelResults, svc.clock.Now())
|
||||
if err != nil {
|
||||
return osqueryError{message: "failed to save labels: " + err.Error()}
|
||||
@@ -1127,7 +1127,7 @@ func (svc *Service) SubmitDistributedQueryResults(ctx context.Context, results f
|
||||
}
|
||||
|
||||
if detailUpdated {
|
||||
host.DetailUpdateTime = svc.clock.Now()
|
||||
host.DetailUpdatedAt = svc.clock.Now()
|
||||
additionalJSON, err := json.Marshal(additionalResults)
|
||||
if err != nil {
|
||||
return osqueryError{message: "failed to marshal additional: " + err.Error()}
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestEnrollAgentDetails(t *testing.T) {
|
||||
assert.Equal(t, "Mac OS X 10.14.5", gotHost.OSVersion)
|
||||
assert.Equal(t, "darwin", gotHost.Platform)
|
||||
assert.Equal(t, "2.12.0", gotHost.OsqueryVersion)
|
||||
assert.Equal(t, "zwass.local", gotHost.HostName)
|
||||
assert.Equal(t, "zwass.local", gotHost.Hostname)
|
||||
assert.Equal(t, "froobling_uuid", gotHost.UUID)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func TestAuthenticateHost(t *testing.T) {
|
||||
svc := newTestService(ds, nil, nil)
|
||||
|
||||
var gotKey string
|
||||
host := fleet.Host{ID: 1, HostName: "foobar"}
|
||||
host := fleet.Host{ID: 1, Hostname: "foobar"}
|
||||
ds.AuthenticateHostFunc = func(key string) (*fleet.Host, error) {
|
||||
gotKey = key
|
||||
return &host, nil
|
||||
@@ -134,13 +134,13 @@ func TestAuthenticateHost(t *testing.T) {
|
||||
assert.Equal(t, "test", gotKey)
|
||||
assert.False(t, ds.MarkHostsSeenFuncInvoked)
|
||||
|
||||
host = fleet.Host{ID: 7, HostName: "foobar"}
|
||||
host = fleet.Host{ID: 7, Hostname: "foobar"}
|
||||
_, err = svc.AuthenticateHost(context.Background(), "floobar")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "floobar", gotKey)
|
||||
assert.False(t, ds.MarkHostsSeenFuncInvoked)
|
||||
// Host checks in twice
|
||||
host = fleet.Host{ID: 7, HostName: "foobar"}
|
||||
host = fleet.Host{ID: 7, Hostname: "foobar"}
|
||||
_, err = svc.AuthenticateHost(context.Background(), "floobar")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "floobar", gotKey)
|
||||
@@ -257,11 +257,11 @@ func TestHostDetailQueries(t *testing.T) {
|
||||
},
|
||||
},
|
||||
|
||||
Platform: "rhel",
|
||||
DetailUpdateTime: mockClock.Now(),
|
||||
NodeKey: "test_key",
|
||||
HostName: "test_hostname",
|
||||
UUID: "test_uuid",
|
||||
Platform: "rhel",
|
||||
DetailUpdatedAt: mockClock.Now(),
|
||||
NodeKey: "test_key",
|
||||
Hostname: "test_hostname",
|
||||
UUID: "test_uuid",
|
||||
}
|
||||
|
||||
svc := &Service{clock: mockClock, config: config.TestConfig(), ds: ds}
|
||||
@@ -338,8 +338,8 @@ func TestLabelQueries(t *testing.T) {
|
||||
assert.NotZero(t, acc)
|
||||
|
||||
// Simulate the detail queries being added
|
||||
host.DetailUpdateTime = mockClock.Now().Add(-1 * time.Minute)
|
||||
host.HostName = "zwass.local"
|
||||
host.DetailUpdatedAt = mockClock.Now().Add(-1 * time.Minute)
|
||||
host.Hostname = "zwass.local"
|
||||
ctx = hostctx.NewContext(ctx, *host)
|
||||
|
||||
queries, acc, err = svc.GetDistributedQueries(ctx)
|
||||
@@ -381,7 +381,7 @@ func TestLabelQueries(t *testing.T) {
|
||||
map[string]string{},
|
||||
)
|
||||
assert.Nil(t, err)
|
||||
host.LabelUpdateTime = mockClock.Now()
|
||||
host.LabelUpdatedAt = mockClock.Now()
|
||||
assert.Equal(t, host, gotHost)
|
||||
assert.Equal(t, mockClock.Now(), gotTime)
|
||||
if assert.Len(t, gotResults, 1) {
|
||||
@@ -401,7 +401,7 @@ func TestLabelQueries(t *testing.T) {
|
||||
map[string]string{},
|
||||
)
|
||||
assert.Nil(t, err)
|
||||
host.LabelUpdateTime = mockClock.Now()
|
||||
host.LabelUpdatedAt = mockClock.Now()
|
||||
assert.Equal(t, host, gotHost)
|
||||
assert.Equal(t, mockClock.Now(), gotTime)
|
||||
if assert.Len(t, gotResults, 2) {
|
||||
@@ -648,8 +648,8 @@ func TestDetailQueriesWithEmptyStrings(t *testing.T) {
|
||||
assert.Equal(t, "1.8.2", gotHost.OsqueryVersion)
|
||||
|
||||
// system_info
|
||||
assert.Equal(t, int64(17179869184), gotHost.PhysicalMemory)
|
||||
assert.Equal(t, "computer.local", gotHost.HostName)
|
||||
assert.Equal(t, int64(17179869184), gotHost.Memory)
|
||||
assert.Equal(t, "computer.local", gotHost.Hostname)
|
||||
assert.Equal(t, "uuid", gotHost.UUID)
|
||||
|
||||
// os_version
|
||||
@@ -663,8 +663,8 @@ func TestDetailQueriesWithEmptyStrings(t *testing.T) {
|
||||
assert.Equal(t, uint(0), gotHost.DistributedInterval)
|
||||
assert.Equal(t, uint(0), gotHost.LoggerTLSPeriod)
|
||||
|
||||
host.HostName = "computer.local"
|
||||
host.DetailUpdateTime = mockClock.Now()
|
||||
host.Hostname = "computer.local"
|
||||
host.DetailUpdatedAt = mockClock.Now()
|
||||
mockClock.AddTime(1 * time.Minute)
|
||||
|
||||
// Now no detail queries should be required
|
||||
@@ -823,8 +823,8 @@ func TestDetailQueries(t *testing.T) {
|
||||
assert.Equal(t, "1.8.2", gotHost.OsqueryVersion)
|
||||
|
||||
// system_info
|
||||
assert.Equal(t, int64(17179869184), gotHost.PhysicalMemory)
|
||||
assert.Equal(t, "computer.local", gotHost.HostName)
|
||||
assert.Equal(t, int64(17179869184), gotHost.Memory)
|
||||
assert.Equal(t, "computer.local", gotHost.Hostname)
|
||||
assert.Equal(t, "uuid", gotHost.UUID)
|
||||
|
||||
// os_version
|
||||
@@ -838,9 +838,9 @@ func TestDetailQueries(t *testing.T) {
|
||||
assert.Equal(t, uint(5), gotHost.DistributedInterval)
|
||||
assert.Equal(t, uint(60), gotHost.LoggerTLSPeriod)
|
||||
|
||||
host.HostName = "computer.local"
|
||||
host.Hostname = "computer.local"
|
||||
host.Platform = "darwin"
|
||||
host.DetailUpdateTime = mockClock.Now()
|
||||
host.DetailUpdatedAt = mockClock.Now()
|
||||
mockClock.AddTime(1 * time.Minute)
|
||||
|
||||
// Now no detail queries should be required
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestSearchTargets(t *testing.T) {
|
||||
ctx := viewer.NewContext(context.Background(), viewer.Viewer{User: user})
|
||||
|
||||
hosts := []*fleet.Host{
|
||||
{HostName: "foo.local"},
|
||||
{Hostname: "foo.local"},
|
||||
}
|
||||
labels := []*fleet.Label{
|
||||
{
|
||||
|
||||
@@ -145,17 +145,6 @@ func listOptionsFromRequest(r *http.Request) (fleet.ListOptions, error) {
|
||||
|
||||
}
|
||||
|
||||
// Special some keys so that the frontend can use consistent names.
|
||||
// TODO #317 remove special cases
|
||||
switch orderKey {
|
||||
case "hostname":
|
||||
orderKey = "host_name"
|
||||
case "memory":
|
||||
orderKey = "physical_memory"
|
||||
case "detail_updated_at":
|
||||
orderKey = "detail_update_time"
|
||||
}
|
||||
|
||||
query := r.URL.Query().Get("query")
|
||||
|
||||
return fleet.ListOptions{
|
||||
|
||||
@@ -94,13 +94,13 @@ func AddAllHostsLabel(t *testing.T, ds fleet.Datastore) {
|
||||
func NewHost(t *testing.T, ds fleet.Datastore, name, ip, key, uuid string, now time.Time) *fleet.Host {
|
||||
osqueryHostID, _ := fleet.RandomText(10)
|
||||
h, err := ds.NewHost(&fleet.Host{
|
||||
HostName: name,
|
||||
NodeKey: key,
|
||||
UUID: uuid,
|
||||
DetailUpdateTime: now,
|
||||
LabelUpdateTime: now,
|
||||
SeenTime: now,
|
||||
OsqueryHostID: osqueryHostID,
|
||||
Hostname: name,
|
||||
NodeKey: key,
|
||||
UUID: uuid,
|
||||
DetailUpdatedAt: now,
|
||||
LabelUpdatedAt: now,
|
||||
SeenTime: now,
|
||||
OsqueryHostID: osqueryHostID,
|
||||
})
|
||||
|
||||
require.Nil(t, err)
|
||||
|
||||
Reference in New Issue
Block a user