Files
George Karr a25ae3ddfc Adding initial tool - dibble the tapir for seeding data (#46122)
## Overview

`dibble` is a one-stop CLI for seeding a Fleet server with test data —
users, teams, policies, reports, labels, scripts, MDM profiles,
software, secrets, CAs, and vulns — replacing ~8 ad-hoc seeding tools
with a single binary.

It makes it easy to:
- **Spin up a populated dev/test server in one command** — `dibble all`
plants everything with sensible, idempotent defaults.
- **Skip the flag-memorization** — running `dibble` with no args
launches an interactive wizard that prompts for Fleet URL, API token,
theme, and which entities to seed, and offers to save the config to
`~/.dibble.yaml`.
- **Seed individual entity types** — `dibble users`, `dibble teams`,
`dibble policies`, etc., when you only need one slice.
- **Get themed, recognizable test data** — pick a theme (hitchhikers,
tng, lotr, ghibli, parksrec, …) so seeded names are easy to eyeball in
the UI.

Hosts are intentionally out of scope — `cmd/osquery-perf` still owns
that. `dibble hosts` is a thin convenience wrapper that picks a fleet,
fetches its enroll secret, and prints/runs the osquery-perf invocation
for you.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Dibble: a CLI tool to seed realistic test data, including an
interactive wizard and subcommands for
teams/users/software/policies/scripts/reports/profiles/labels/activities/enroll-secrets/hosts/vulns,
plus theme-driven “cas” and “ping”.
* Theme system: multiple curated themes to generate consistent seeded
identities, policies, software, labels, and scripts.
* **Chores**
* Ignored the built dibble binary and added a Makefile build target to
compile the dibble tool.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-17 11:07:05 -05:00

71 lines
2.1 KiB
Go

package seed
import (
"fmt"
"github.com/fleetdm/fleet/v4/tools/dibble/pkg/themes"
)
// Reports (formerly "queries") are saved SQL queries with an interval. We seed
// a mix of global and team-scoped reports, alternating intervals (0 = never,
// 60s, 3600s) so the schedule grid shows variety in the UI.
func Reports(c Client, log Logger, theme themes.Theme, teams []Team, count int) Result {
res := Result{Entity: "reports"}
exampleSQL := []string{
"SELECT version FROM osquery_info;",
"SELECT name FROM apps WHERE name LIKE '%Slack%';",
"SELECT pid, name FROM processes ORDER BY pid LIMIT 5;",
"SELECT * FROM users WHERE shell != '/usr/bin/false' LIMIT 10;",
"SELECT path, type FROM mounts WHERE path LIKE '/Volumes/%';",
}
intervals := []int{0, 60, 3600}
for i := 0; i < count; i++ {
n := themes.Pick(theme, "policy", i) // reuse policy names — they read fine as queries too
body := map[string]any{
"name": fmt.Sprintf("%s report", n.Name),
"description": n.Desc,
"query": exampleSQL[i%len(exampleSQL)],
"interval": intervals[i%len(intervals)],
"observer_can_run": i%2 == 0,
"platform": seededPlatforms[i%len(seededPlatforms)],
"logging": "snapshot",
}
err := c.Post("/api/latest/fleet/reports", body, nil)
switch {
case err == nil:
res.Created++
log.Printf("report (global) %q", body["name"])
case IsAlreadyExists(err):
res.Skipped++
default:
res.Errors = append(res.Errors, err)
}
}
// One report per team.
for _, t := range teams {
n := themes.Pick(theme, "policy", count)
teamID := t.ID
body := map[string]any{
"name": fmt.Sprintf("%s — %s report", n.Name, t.Name),
"description": n.Desc,
"query": exampleSQL[0],
"interval": 0,
"team_id": teamID,
}
err := c.Post("/api/latest/fleet/reports", body, nil)
switch {
case err == nil:
res.Created++
log.Printf("report (team=%s) %q", t.Name, body["name"])
case IsAlreadyExists(err):
res.Skipped++
default:
res.Errors = append(res.Errors, err)
}
}
return res
}