Files
Pulse/pkg/server/telemetry_licensed_features.go
rcourtman c5b6d05107 feat(telemetry): add schema v26 map topology API/CLI/MCP telemetry
I added Schema v26 content-free Infrastructure Map topology read telemetry for external live GET /api/agent/topology requests (total read days, CLI days, MCP days, anonymized days, and an explicit availability flag) alongside hardened opt-out zero-write boundaries, credential-binding checks, and read-only SQLite/config guards.

Key changes:
- Added a dedicated root-scoped daily tally store (infrastructure_map_topology_tally.json) with strict schema validation, fail-closed degraded sidecar accounting, and strict zero-write guarantees when telemetry is disabled by settings or PULSE_TELEMETRY=false.
- Added X-Pulse-Agent-Surface attribution for pulse-cli and MCP clients while filtering out first-party browser traffic, mock-mode snapshots, and unverified monitor states.
- Updated Settings payload preview, localization copy, shipped PRIVACY.md disclosure, integration specs, and schema parity tooling for Schema v26.
- Hardened host/agent token hash binding, self-uninstall live authority and durable hash-scoped tombstones, Patrol investigation replay-floor provenance, bounded non-blocking regular-file config reads, and cold read-only legacy SQLite history queries.
2026-12-02 01:41:25 +00:00

89 lines
4.0 KiB
Go

package server
import (
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
"github.com/rcourtman/pulse-go-rewrite/internal/telemetry"
)
// applyLicensedFeatureConfigSnapshot adds content-free adoption counts for
// licensed features whose state lives in persisted config files.
//
// Counts only. Schedule names, delivery recipients, report scope, and profile
// names all stay on the install; the aggregate answers "how many are
// configured and how many ran", nothing about what they contain.
func applyLicensedFeatureConfigSnapshot(snap *telemetry.Snapshot, persistence *config.ConfigPersistence, now time.Time) {
applyLicensedFeatureConfigSnapshotWithMode(snap, persistence, now, false, false, 0)
}
func applyLicensedFeatureConfigSnapshotWithMode(snap *telemetry.Snapshot, persistence *config.ConfigPersistence, now time.Time, readOnly, checkConsent bool, expectedConsentGen uint64) {
if snap == nil || persistence == nil {
return
}
if store, err := persistence.LoadReportScheduleStore(); err == nil && store != nil {
since := now.Add(-telemetry.PulseIntelligenceTelemetryWindow)
for _, schedule := range store.Schedules {
snap.ReportSchedules++
if schedule.Enabled {
snap.ReportSchedulesEnabled++
}
if schedule.LastRunAt != nil && schedule.LastRunAt.After(since) {
snap.ReportSchedulesRun30d++
}
}
}
var (
activity config.ReportingActivitySummary
err error
)
if readOnly {
activity, err = persistence.ReportingActivitySnapshotReadOnly(now)
} else if checkConsent {
activity, err = persistence.ReportingActivitySnapshotWithConsentGen(now, expectedConsentGen)
} else {
activity, err = persistence.ReportingActivitySnapshot(now)
}
if err == nil {
snap.ReportingGeneratedResources30d = activity.Counts.Generated[0]
snap.ReportingGeneratedVMInventory30d = activity.Counts.Generated[1]
snap.ReportingGeneratedBackupHealth30d = activity.Counts.Generated[2]
snap.ReportingGeneratedPatrolDigest30d = activity.Counts.Generated[3]
snap.ReportingSuccessfulResourcesPeriods30d = activity.Counts.Successful[0]
snap.ReportingSuccessfulVMInventoryPeriods30d = activity.Counts.Successful[1]
snap.ReportingSuccessfulBackupHealthPeriods30d = activity.Counts.Successful[2]
snap.ReportingSuccessfulPatrolDigestPeriods30d = activity.Counts.Successful[3]
snap.ReportingRepeatResourcesPeriods30d = activity.Counts.Repeated[0]
snap.ReportingRepeatVMInventoryPeriods30d = activity.Counts.Repeated[1]
snap.ReportingRepeatBackupHealthPeriods30d = activity.Counts.Repeated[2]
snap.ReportingRepeatPatrolDigestPeriods30d = activity.Counts.Repeated[3]
snap.ReportingSaved30d = activity.Counts.Saved
snap.ReportingEmailAccepted30d = activity.Counts.EmailAccepted
snap.ReportingDeliveryFailed30d = activity.Counts.DeliveryFailed
snap.ReportingDeliveryUnconfirmed30d = activity.Counts.DeliveryUnconfirmed
snap.ReportingDataComplete30d = activity.Counts.DataComplete
snap.ReportingDataIncomplete30d = activity.Counts.DataIncomplete
snap.ReportingDataUnavailable30d = activity.Counts.DataUnavailable
snap.ReportingTelemetryAvailable = activity.Available
snap.ReportingObservationDays = activity.ObservationDays
snap.ReportingResourcesActiveDays30d = activity.ActiveDays[0]
snap.ReportingVMInventoryActiveDays30d = activity.ActiveDays[1]
snap.ReportingBackupHealthActiveDays30d = activity.ActiveDays[2]
snap.ReportingPatrolDigestActiveDays30d = activity.ActiveDays[3]
}
if profiles, err := persistence.LoadAgentProfilesReadOnly(); err == nil {
snap.AgentProfiles = len(profiles)
}
snap.SuccessfulHistoryReadsOver7d30d = persistence.CountSuccessfulExtendedHistoryReadsSince(now.Add(-telemetry.PulseIntelligenceTelemetryWindow), now)
// Audit adoption is a read count, not store presence: the SQLite audit
// logger is installed on every install for defense in depth, so only an
// operator reaching a license-gated read surface distinguishes an install
// that uses audit logging from one that merely has it.
snap.AuditReads30d = persistence.CountAuditReadActivitySinceReadOnly(now.Add(-telemetry.PulseIntelligenceTelemetryWindow))
}