progress

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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).

View Source
const (
	UnitChecks = "checks" // template x target pairs of nuclei
	UnitHosts  = "hosts"  // addresses of a discovery batch
)

Units of Done and Total.

View Source
const (
	MaxCount     = 1_000_000_000
	MaxRemaining = 48 * time.Hour
	MaxMessage   = 120 // runes

)

Limits of what a View may hold.

Variables

Phases is every phase a View can name.

Units is every unit a View can name.

Functions

func Report

func Report(ctx context.Context, u Update)

Report sends u to the Sink of ctx; nothing when there is none.

func WithSink

func WithSink(ctx context.Context, s Sink) context.Context

WithSink returns ctx carrying s.

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

func NewSeries(ctx context.Context, phase string, plan int64) *Series

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

func (s *Series) Job(ctx context.Context) (context.Context, func(checks int64))

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.

func (*Series) Plan

func (s *Series) Plan(plan int64)

Plan sets the total the owner plans for the pass, the jobs that ended included (the templates of a port once its technologies are known).

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.

func SinkFrom

func SinkFrom(ctx context.Context) Sink

SinkFrom is the Sink ctx carries, or nil.

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

func NewTracker(now func() time.Time) *Tracker

NewTracker starts a job now. now nil means time.Now.

func (*Tracker) Report

func (t *Tracker) Report(u Update)

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.

func (*Tracker) View

func (t *Tracker) View() *View

View is the latest state, nil before the first report.

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.

func Phase

func Phase(phase, message string) Update

Phase is an Update that names a phase only (no percent, no count).

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL