mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
4784217b57
Updating documentation of Fleetd tables as part of the oncall duty. Updating the json used by Fleet using the following command: ```sh cd website ./node_modules/sails/bin/sails.js run generate-merged-schema ``` Samples: ![Screenshot 2023-02-20 at 17 20 55](https://user-images.githubusercontent.com/2073526/220192112-69a116e4-badb-4328-92d3-9a2a6f8657fe.png) ![Screenshot 2023-02-20 at 17 21 09](https://user-images.githubusercontent.com/2073526/220192117-dfa06c69-2166-47d4-99c3-e108911e2084.png) @mikermcneil @eashaw: `generate-merged-schema` generates a different output every time it's executed. Guess: It seems it should sort the output lexicograhically?
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
// sntp_request allows querying SNTP servers to get the timestamp
|
|
// and clock offset from a NTP server (in millisecond precision).
|
|
package sntp_request
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/beevik/ntp"
|
|
"github.com/osquery/osquery-go/plugin/table"
|
|
)
|
|
|
|
func Columns() []table.ColumnDefinition {
|
|
return []table.ColumnDefinition{
|
|
table.TextColumn("server"),
|
|
|
|
table.BigIntColumn("timestamp_ms"),
|
|
table.BigIntColumn("clock_offset_ms"),
|
|
}
|
|
}
|
|
|
|
func GenerateFunc(_ context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
|
|
server := ""
|
|
if constraints, ok := queryContext.Constraints["server"]; ok {
|
|
for _, constraint := range constraints.Constraints {
|
|
if constraint.Operator == table.OperatorEquals {
|
|
server = constraint.Expression
|
|
}
|
|
}
|
|
}
|
|
if server == "" {
|
|
return nil, errors.New("missing SNTP server column constraint; e.g. WHERE server = 'my.sntp.server'")
|
|
}
|
|
|
|
options := ntp.QueryOptions{
|
|
Timeout: 30 * time.Second,
|
|
}
|
|
response, err := ntp.QueryWithOptions(server, options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return []map[string]string{{
|
|
"server": server,
|
|
|
|
"timestamp_ms": strconv.FormatInt(response.Time.UnixMilli(), 10),
|
|
"clock_offset_ms": strconv.FormatInt(response.ClockOffset.Milliseconds(), 10),
|
|
}}, nil
|
|
}
|