Documentation
¶
Overview ¶
Package progress is the one shape of "how far is it" for the long jobs a customer waits on (#830): a scan of a device, the scan of a public IP, its OpenVAS step. A job owns a Tracker; the code that does the work reports to the Sink it finds in its context, so the modules between the two (scan, exposure, sensor-active's Dispatcher, the adapters of cmd/vedette) need no new parameter. Only the latest state is kept, in memory: no history, no table, and it goes with the job (the owner drops the Tracker when the job ends).
What a Sink receives can come from a tool's output that a device or a compromised worker shaped (the scan worker's nmap and nuclei): Report checks every field and drops what is out of range, so a View is always well formed.
Standard library only.
Index ¶
Constants ¶
const ( PhaseDiscovery = "discovery" // is the host up (nmap ping or ARP scan) PhasePorts = "ports" // port scan PhaseServices = "services" // service and version detection (nmap -sV) PhaseScripts = "scripts" // nmap's scripts (titles, certificates, NTLM answers) PhaseVulns = "vulns" // vulnerability checks (nuclei templates) PhaseWeb = "web" // the passive web checks of a public address (ZAP) PhaseOpenVAS = "openvas" // the optional OpenVAS deep scan (Greenbone) PhaseSaving = "saving" // the result is being stored )
Phases of a job (contract: web/src/lib/progress.ts JobProgress.phase).
const ( UnitChecks = "checks" // template x target pairs of nuclei UnitHosts = "hosts" // addresses of a discovery batch )
Units of Done and Total.
const ( MaxCount = 1_000_000_000 MaxRemaining = 48 * time.Hour MaxMessage = 120 // runes )
Limits of what a View may hold.
Variables ¶
var Phases = []string{PhaseDiscovery, PhasePorts, PhaseServices, PhaseScripts, PhaseVulns, PhaseWeb, PhaseOpenVAS, PhaseSaving}
Phases is every phase a View can name.
var Units = []string{UnitChecks, UnitHosts}
Units is every unit a View can name.
Functions ¶
Types ¶
type Series ¶
type Series struct {
// contains filtered or unexported fields
}
Series is one count of checks over the jobs of a pass of a phase that run one after another (#830 FAIL 2). The deep scan of a public IP hands its templates to nuclei as many jobs, each reporting its own 0..N, and passed on as they came the page read 85 % → 39 % → 82 %. A Series adds the checks of the jobs that ended to the running job's count, against the total its owner plans for the pass, so the count only grows, the estimate of the end follows the whole pass, and a job's report never stands for the pass. The owner makes it with NewSeries, runs each job with the context of Job and calls the end function Job returns when the job is over. Safe for concurrent use; nothing happens when the context carries no Sink.
func NewSeries ¶
NewSeries starts a pass of phase with plan checks planned (an upper bound is fine: Plan lowers it when the owner knows better) and reports its 0 at once.
func (*Series) Job ¶
Job returns the context the next job of the series runs with, and the function that ends that job with the number of checks it stood for: they count as done whether the tool ran them all or not (a target it gave up, a template it did not load), and the job's later reports are dropped.
type Sink ¶
type Sink interface{ Report(Update) }
Sink receives the reports of a job. Report must be quick and must not block: it is called from the reader of a process's output.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker keeps the latest state of one job. The zero value is not usable; make it with NewTracker. Safe for concurrent use.
func NewTracker ¶
NewTracker starts a job now. now nil means time.Now.
func (*Tracker) Report ¶
Report implements Sink: it checks u and keeps it as the latest state. A report with an unknown phase is dropped whole; an out-of-range number is dropped alone.
Within a pass of a phase the bar never goes back (#830 FAIL 2: the page read 85 % → 39 % → 82 %): a report with a lower percent keeps the state shown before whole (percent, count, estimate, message); only updated_at moves. Only a new pass starts lower: a report that says so (NewPass), another phase, or a percent without a count that falls by more than restartDrop (the second nmap run of a device: that tool's percent restarts on its own). A count never starts a pass by falling: the jobs of one pass are added up by a Series.
type Update ¶
type Update struct {
Phase string
Percent float64
Done int64
Total int64
Unit string
Remaining time.Duration
Message string
// EndsBy is the latest time the phase ends, when its owner enforces one (OpenVAS's cap and its stop budget); zero: none.
EndsBy time.Time
// NewPass starts a new pass of the phase whatever came before it (the first report of a Series): its time and pace start
// again, and the percent may start again from 0.
NewPass bool
}
Update is one report. Percent < 0 means unknown; Total 0 means there is no count (Done and Unit are then ignored); Remaining 0 means the tool gave no estimate.
type View ¶
type View struct {
Phase string `json:"phase"`
Percent *float64 `json:"percent"`
Done *int64 `json:"done"`
Total *int64 `json:"total"`
Unit *string `json:"unit"`
StartedAt string `json:"started_at"`
PhaseStartedAt string `json:"phase_started_at"`
UpdatedAt string `json:"updated_at"`
ETA *string `json:"eta"`
Message *string `json:"message"`
EndsBy *string `json:"ends_by"`
}
View is the API shape (contract JobProgress). Times are UTC, millisecond ISO 8601 like every other time of the API.