host

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CacheKeyMostVulnerable is the base key for caching vulnerable hosts data
	CacheKeyMostVulnerable = "dashboard:most_vulnerable_hosts"
	// CacheTTL is the cache time-to-live in seconds (5 minutes)
	CacheTTL = 300
)

Variables

View Source
var ErrInvalidReport = errors.New("invalid host report")

ErrInvalidReport identifies invalid input before any report writes occur.

View Source
var ErrPortIdentityDeleted = errors.New("port identity is soft-deleted; restore or reconcile it explicitly before recording observations")

ErrPortIdentityDeleted means an observation targets a retired shared identity. Automatic resurrection would expose other hosts' retired relationships.

Functions

func AddHost

func AddHost(host sirius.Host) error

AddHost Chain: SDK Consumer (e.g. Sirius REST API) -> SDK go-api sirius/host (Here) Legacy function - uses repository pattern with "legacy" source for backward compatibility

func AddHostWithSource added in v0.0.6

func AddHostWithSource(host sirius.Host, source models.ScanSource) error

AddHostWithSource atomically persists one source-attributed report.

func AddHostWithSourceAndJSONB added in v0.0.6

func AddHostWithSourceAndJSONB(host sirius.Host, source models.ScanSource,
	softwareInventory, systemFingerprint, agentMetadata map[string]interface{}) error

AddHostWithSourceAndJSONB atomically persists the report and enhanced inventory.

func AddReport added in v0.0.20

func AddReport(report Report) error

AddReport commits host, JSONB, shared identities, observations and scan history together. Any validation, statement or commit failure leaves no partial report.

func AddReportScoped added in v0.0.22

func AddReportScoped(resourceScope scope.ResourceScope, report Report) error

AddReportScoped persists a report under a scope authorized by the caller.

func DeleteHost

func DeleteHost(ip string) error

DeleteHost handles the POST /host/delete route DeleteHost Chain: SDK Consumer (e.g. Sirius REST API) -> SDK go-api sirius/host (Here)

func DetermineSourceFromContext added in v0.0.6

func DetermineSourceFromContext(userAgent, referer, ipAddress string) models.ScanSource

DetermineSourceFromContext attempts to determine scan source from various context clues

func GetAllHosts

func GetAllHosts() ([]sirius.Host, error)

func GetAllHostsScoped added in v0.0.22

func GetAllHostsScoped(resourceScope scope.ResourceScope) ([]sirius.Host, error)

GetAllHostsScoped lists hosts only from the given trusted scope.

func GetHost

func GetHost(ip string) (sirius.Host, error)

func GetHostScoped added in v0.0.22

func GetHostScoped(resourceScope scope.ResourceScope, ip string) (sirius.Host, error)

GetHostScoped retrieves a host only from the given trusted scope.

func GetHostWithSources added in v0.0.6

func GetHostWithSources(ip string) (models.HostWithSources, error)

GetHostWithSources retrieves a host with all source-attributed data

func GetSourceCoverageStats added in v0.0.6

func GetSourceCoverageStats() ([]models.SourceCoverageStats, error)

GetSourceCoverageStats gets statistics about scan source coverage

func GetVulnerabilityHistory added in v0.0.6

func GetVulnerabilityHistory(hostID uint, vulnID uint) ([]models.SourceAttribution, error)

GetVulnerabilityHistory gets the source history for a specific vulnerability on a host

func GetVulnerabilitySources added in v0.0.6

func GetVulnerabilitySources(vulnID string) ([]models.VulnerabilitySourceInfo, error)

GetVulnerabilitySources gets all sources that have reported a specific vulnerability

func InvalidateMostVulnerableHostsCache added in v0.0.12

func InvalidateMostVulnerableHostsCache() error

InvalidateMostVulnerableHostsCache clears all cached vulnerable hosts data This should be called when: - A scan completes and adds new vulnerabilities - Vulnerabilities are bulk updated or imported - Host vulnerability status changes significantly

func ValidateReport added in v0.0.20

func ValidateReport(report Report) error

ValidateReport validates every finding and JSON document before persistence. It is also safe to call at the HTTP boundary before expensive enrichment.

Types

type EnhancedHostData added in v0.0.6

type EnhancedHostData struct {
	Host              sirius.Host            `json:"host"`
	SoftwareInventory map[string]interface{} `json:"software_inventory,omitempty"`
	SystemFingerprint map[string]interface{} `json:"system_fingerprint,omitempty"`
	AgentMetadata     map[string]interface{} `json:"agent_metadata,omitempty"`
}

EnhancedHostData represents host data with JSONB fields

func GetHostWithEnhancedData added in v0.0.6

func GetHostWithEnhancedData(ip string, includeFields []string) (*EnhancedHostData, error)

GetHostWithEnhancedData retrieves host information including JSONB fields using repository pattern

type HostRepository added in v0.0.12

type HostRepository struct {
	// contains filtered or unexported fields
}

HostRepository provides explicit database operations for hosts without circular references

func NewHostRepository added in v0.0.12

func NewHostRepository() *HostRepository

NewHostRepository creates a new HostRepository instance

func (*HostRepository) GetAllHostsWithRelations added in v0.0.12

func (r *HostRepository) GetAllHostsWithRelations() ([]HostWithRelations, error)

GetAllHostsWithRelations retrieves all hosts with their ports and vulnerabilities

func (*HostRepository) GetAllHostsWithRelationsScoped added in v0.0.22

func (r *HostRepository) GetAllHostsWithRelationsScoped(resourceScope scope.ResourceScope) ([]HostWithRelations, error)

GetAllHostsWithRelationsScoped lists only hosts in the supplied scope.

func (*HostRepository) GetHostWithRelations added in v0.0.12

func (r *HostRepository) GetHostWithRelations(ip string) (*HostWithRelations, error)

GetHostWithRelations retrieves a host with ports and vulnerabilities using explicit JOINs

func (*HostRepository) GetHostWithRelationsScoped added in v0.0.22

func (r *HostRepository) GetHostWithRelationsScoped(resourceScope scope.ResourceScope, ip string) (*HostWithRelations, error)

GetHostWithRelationsScoped never searches outside the supplied scope.

func (*HostRepository) LinkHostPort added in v0.0.12

func (r *HostRepository) LinkHostPort(hostID, portID uint, source models.ScanSource) error

LinkHostPort refreshes a relationship without inventing observation state. Existing state is preserved; a new relationship has unknown state. Deprecated: use UpsertHostPort or LinkHostPortWithState for observations.

func (*HostRepository) LinkHostPortWithState added in v0.0.20

func (r *HostRepository) LinkHostPortWithState(hostID, portID uint, source models.ScanSource, state string) error

LinkHostPortWithState updates only the specified host/port/source observation.

func (*HostRepository) LinkHostVulnerability added in v0.0.12

func (r *HostRepository) LinkHostVulnerability(hostID, vulnID uint, source models.ScanSource) error

LinkHostVulnerability is the compatibility API for callers without a complete finding. It must not erase evidence/confidence from an existing modern report.

func (*HostRepository) UpdateHostJSONB added in v0.0.12

func (r *HostRepository) UpdateHostJSONB(hostID uint, softwareInventory, systemFingerprint, agentMetadata map[string]interface{}) error

UpdateHostJSONB updates JSONB fields for a host

func (*HostRepository) UpsertHost added in v0.0.12

func (r *HostRepository) UpsertHost(ip, hostname, os, osVersion, hid string) (hostID uint, err error)

UpsertHost creates or updates a host and returns its ID

func (*HostRepository) UpsertHostPort added in v0.0.20

func (r *HostRepository) UpsertHostPort(hostID uint, number int, protocol, state string, source models.ScanSource) error

UpsertHostPort atomically saves an observation scoped to host and source. An omitted scanner state retains the historical default of open.

func (*HostRepository) UpsertHostScoped added in v0.0.22

func (r *HostRepository) UpsertHostScoped(resourceScope scope.ResourceScope, ip, hostname, os, osVersion, hid string) (hostID uint, err error)

UpsertHostScoped stores a host in the scope supplied by a trusted caller.

func (*HostRepository) UpsertHostVulnerability added in v0.0.20

func (r *HostRepository) UpsertHostVulnerability(hostID uint, finding sirius.Vulnerability, source models.ScanSource) error

UpsertHostVulnerability stores a complete observation on the host/source junction, not in the shared vulnerability catalog. Catalog fields remain for legacy consumers; changing another host's catalog cannot change this snapshot.

func (*HostRepository) UpsertPort added in v0.0.12

func (r *HostRepository) UpsertPort(number int, protocol, state string) (uint, error)

UpsertPort finds or creates a shared (number, protocol) identity. It never writes observation state to the global catalog. Deprecated: state is ignored; use UpsertHostPort to save a host observation.

func (*HostRepository) UpsertVulnerability added in v0.0.12

func (r *HostRepository) UpsertVulnerability(vid, title, desc string, score float64) (vulnID uint, err error)

UpsertVulnerability creates or finds a vulnerability by VID, returns its ID

type HostRiskStats

type HostRiskStats struct {
	VulnerabilityCount int                             `json:"vulnerabilityCount" gorm:"column:vulnerability_count"`
	TotalRiskScore     float64                         `json:"totalRiskScore" gorm:"column:total_risk_score"`
	AverageRiskScore   float64                         `json:"averageRiskScore" gorm:"column:average_risk_score"`
	HostSeverityCounts HostVulnerabilitySeverityCounts `json:"hostSeverityCounts" gorm:"-"`
	SoftwareStats      *SoftwareStatistics             `json:"softwareStats,omitempty" gorm:"-"`
	LastUpdated        string                          `json:"lastUpdated,omitempty" gorm:"-"`
}

HostRiskStats holds aggregated risk score statistics for vulnerabilities on a host.

func GetHostRiskStatistics

func GetHostRiskStatistics(ip string) (HostRiskStats, error)

GetHostRiskStatistics returns aggregated risk statistics for vulnerabilities on a given host identified by its IP.

type HostVulnerabilitySeverityCounts

type HostVulnerabilitySeverityCounts struct {
	Critical      int `json:"critical"`
	High          int `json:"high"`
	Medium        int `json:"medium"`
	Low           int `json:"low"`
	Informational int `json:"informational"`
}

HostVulnerabilitySeverityCounts holds the count of vulnerabilities by severity for a given host.

func GetHostVulnerabilitySeverityCounts

func GetHostVulnerabilitySeverityCounts(ip string) (HostVulnerabilitySeverityCounts, error)

GetHostVulnerabilitySeverityCounts retrieves vulnerability severity counts for a host identified by its IP.

type HostVulnerabilityStats added in v0.0.12

type HostVulnerabilityStats struct {
	HostID               string                          `json:"hostId" gorm:"column:host_id"`
	HostIP               string                          `json:"hostIp" gorm:"column:host_ip"`
	Hostname             string                          `json:"hostname,omitempty" gorm:"column:hostname"`
	TotalVulnerabilities int                             `json:"totalVulnerabilities" gorm:"column:total_vulnerabilities"`
	WeightedRiskScore    float64                         `json:"weightedRiskScore" gorm:"column:weighted_risk_score"`
	SeverityCounts       HostVulnerabilitySeverityCounts `json:"severityCounts" gorm:"-"`
	LastUpdated          string                          `json:"lastUpdated" gorm:"column:last_updated"`
}

HostVulnerabilityStats represents vulnerability statistics for a single host

func GetMostVulnerableHosts added in v0.0.12

func GetMostVulnerableHosts(limit int) ([]HostVulnerabilityStats, error)

GetMostVulnerableHosts returns hosts ranked by weighted vulnerability score The weighted risk score is the sum of all risk_scores for vulnerabilities on that host

type HostWithRelations added in v0.0.12

type HostWithRelations struct {
	Host            models.Host
	Ports           []PortRelation
	Vulnerabilities []VulnerabilityRelation
}

HostWithRelations represents a host with its ports and vulnerabilities loaded via explicit JOINs

type PortRelation added in v0.0.12

type PortRelation struct {
	Port          models.Port
	Source        string
	SourceVersion string
	FirstSeen     time.Time
	LastSeen      time.Time
	Status        string
	Notes         string
}

PortRelation represents a port with source attribution

type Report added in v0.0.20

type Report struct {
	Host              sirius.Host
	Source            models.ScanSource
	SoftwareInventory map[string]interface{}
	SystemFingerprint map[string]interface{}
	AgentMetadata     map[string]interface{}
	Catalog           []sirius.Vulnerability
}

Report is one ingestion unit. Catalog contains optional enriched catalog entries for its findings; original scanner evidence in Host is never replaced. Perform external enrichment before AddReport, not while holding a transaction.

type SoftwareInventoryData added in v0.0.6

type SoftwareInventoryData struct {
	Packages     []map[string]interface{} `json:"packages"`
	PackageCount int                      `json:"package_count"`
	CollectedAt  string                   `json:"collected_at"`
	Source       string                   `json:"source"`
	Statistics   map[string]interface{}   `json:"statistics,omitempty"`
}

SoftwareInventoryData represents structured software inventory information

func GetHostSoftwareInventory added in v0.0.6

func GetHostSoftwareInventory(ip string) (*SoftwareInventoryData, error)

GetHostSoftwareInventory retrieves only software inventory data for a host

type SoftwareStatistics added in v0.0.6

type SoftwareStatistics struct {
	TotalPackages    int            `json:"total_packages"`
	Architectures    map[string]int `json:"architectures"`
	Publishers       map[string]int `json:"publishers"`
	LastUpdated      string         `json:"last_updated"`
	PackagesBySource map[string]int `json:"packages_by_source,omitempty"`
}

SoftwareStatistics represents aggregated software inventory statistics

func GetHostSoftwareStatistics added in v0.0.6

func GetHostSoftwareStatistics(ip string) (*SoftwareStatistics, error)

GetHostSoftwareStatistics retrieves aggregated software statistics for a host

type SystemFingerprintData added in v0.0.6

type SystemFingerprintData struct {
	Fingerprint          map[string]interface{} `json:"fingerprint"`
	CollectedAt          string                 `json:"collected_at"`
	Source               string                 `json:"source"`
	Platform             string                 `json:"platform"`
	CollectionDurationMs int64                  `json:"collection_duration_ms"`
	Summary              map[string]interface{} `json:"summary,omitempty"`
}

SystemFingerprintData represents structured system fingerprint information

func GetHostSystemFingerprint added in v0.0.6

func GetHostSystemFingerprint(ip string) (*SystemFingerprintData, error)

GetHostSystemFingerprint retrieves only system fingerprint data for a host

type VulnerabilityRelation added in v0.0.12

type VulnerabilityRelation struct {
	Finding       *sirius.Vulnerability
	Vulnerability models.Vulnerability
	Source        string
	SourceVersion string
	FirstSeen     time.Time
	LastSeen      time.Time
	Status        string
	Confidence    float64
	Port          *int
	ServiceInfo   string
	Notes         string
}

VulnerabilityRelation represents a vulnerability with source attribution

type VulnerabilitySummary

type VulnerabilitySummary struct {
	VID         string  `json:"vid"`
	Title       string  `json:"title"`
	HostCount   int     `json:"hostCount"`
	Description string  `json:"description"`
	RiskScore   float64 `json:"riskScore"`
}

VulnerabilitySummary represents a vulnerability with its associated host count

func GetAllVulnerabilities

func GetAllVulnerabilities() ([]VulnerabilitySummary, error)

GetAllVulnerabilities host/vulnerabilities SDK

type VulnerableHostsResponse added in v0.0.12

type VulnerableHostsResponse struct {
	Hosts      []HostVulnerabilityStats `json:"hosts"`
	TotalHosts int                      `json:"totalHosts"`
	Cached     bool                     `json:"cached"`
	CachedAt   *string                  `json:"cachedAt,omitempty"`
	TTL        int                      `json:"ttl"`
}

VulnerableHostsResponse is the complete response structure for the API

func GetMostVulnerableHostsCached added in v0.0.12

func GetMostVulnerableHostsCached(limit int) (VulnerableHostsResponse, error)

GetMostVulnerableHostsCached returns cached data or calculates fresh statistics This function implements a caching layer with Valkey to reduce database load

Jump to

Keyboard shortcuts

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