Documentation
¶
Overview ¶
Package reporting provides comprehensive reporting capabilities including real-time reports, ad-hoc reports, and scheduled report generation.
This file contains integration helpers for connecting to other AegisGate packages.
Package reporting provides comprehensive reporting capabilities including real-time reports, ad-hoc reports, and scheduled report generation.
Features:
- Real-time report generation (current state snapshot)
- Ad-hoc report generation (custom date ranges, filters)
- Scheduled report execution (periodic automated reports)
- Multiple output formats (JSON, CSV, HTML)
- Report storage with automatic cleanup
- Report template system
- Email/webhook delivery interfaces
- Cron-like scheduling syntax
Example usage:
// Create reporter with defaults
reporter, err := reporting.New(Config{
CleanupInterval: 24 * time.Hour,
MaxReportAge: 30 * 24 * time.Hour,
})
if err != nil {
log.Fatal(err)
}
defer reporter.Stop()
// Start the scheduler
reporter.Start()
// Generate an ad-hoc report
report, err := reporter.Generate(ReportRequest{
Type: ReportTypeSummary,
Format: ReportFormatJSON,
StartTime: time.Now().Add(-24 * time.Hour),
EndTime: time.Now(),
})
Index ¶
- func GetAggregateData() (map[string]interface{}, error)
- func GetComplianceData() (map[string]interface{}, error)
- func GetGlobalScannerData() (map[string]interface{}, error)
- type AggregateDataSource
- func (a *AggregateDataSource) GetAllData() (map[string]interface{}, error)
- func (a *AggregateDataSource) SetComplianceManager(m *compliance.ComplianceManager)
- func (a *AggregateDataSource) SetMetricsCollector(collector *metrics.MetricsCollector)
- func (a *AggregateDataSource) SetScanner(s *scanner.Scanner)
- type ComplianceDataSource
- type Config
- type DeliveryConfig
- type DeliveryHandler
- type MetricsDataSource
- type NoOpDelivery
- type Report
- type ReportFilter
- type ReportFormat
- type ReportRequest
- type ReportSchedule
- type ReportStatus
- type ReportTemplate
- type ReportType
- type Reporter
- func (r *Reporter) AddTemplate(template ReportTemplate) (*ReportTemplate, error)
- func (r *Reporter) CancelSchedule(id string) error
- func (r *Reporter) Cleanup() error
- func (r *Reporter) DeleteReport(id string) error
- func (r *Reporter) Export(reportID string, format ReportFormat) (io.Reader, error)
- func (r *Reporter) Generate(req ReportRequest) (*Report, error)
- func (r *Reporter) GetReport(id string) (*Report, error)
- func (r *Reporter) GetTemplate(id string) (*ReportTemplate, error)
- func (r *Reporter) ListReports(filterType ReportType, filterStatus ReportStatus) []*Report
- func (r *Reporter) ListSchedules() []*ReportSchedule
- func (r *Reporter) Schedule(schedule ReportSchedule) (*ReportSchedule, error)
- func (r *Reporter) Start()
- func (r *Reporter) Stop()
- type ScannerDataSource
- type ScheduleType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAggregateData ¶
GetAggregateData returns all data from connected sources
func GetComplianceData ¶
GetComplianceData returns compliance data
func GetGlobalScannerData ¶
GetGlobalScannerData returns scanner data using a default scanner instance
Types ¶
type AggregateDataSource ¶
type AggregateDataSource struct {
// contains filtered or unexported fields
}
AggregateDataSource combines multiple data sources into one
func NewAggregateDataSource ¶
func NewAggregateDataSource( metricsCollector *metrics.MetricsCollector, scannerInstance *scanner.Scanner, complianceManager *compliance.ComplianceManager, ) *AggregateDataSource
NewAggregateDataSource creates a new aggregate data source
func (*AggregateDataSource) GetAllData ¶
func (a *AggregateDataSource) GetAllData() (map[string]interface{}, error)
GetAllData retrieves all data from all sources
func (*AggregateDataSource) SetComplianceManager ¶
func (a *AggregateDataSource) SetComplianceManager(m *compliance.ComplianceManager)
SetComplianceManager updates the compliance manager
func (*AggregateDataSource) SetMetricsCollector ¶
func (a *AggregateDataSource) SetMetricsCollector(collector *metrics.MetricsCollector)
SetMetricsCollector updates the metrics collector
func (*AggregateDataSource) SetScanner ¶
func (a *AggregateDataSource) SetScanner(s *scanner.Scanner)
SetScanner updates the scanner instance
type ComplianceDataSource ¶
type ComplianceDataSource struct {
// contains filtered or unexported fields
}
ComplianceDataSource integrates with the compliance package
func NewComplianceDataSource ¶
func NewComplianceDataSource(manager *compliance.ComplianceManager) *ComplianceDataSource
NewComplianceDataSource creates a new compliance data source
func (*ComplianceDataSource) GetComplianceData ¶
func (c *ComplianceDataSource) GetComplianceData() (map[string]interface{}, error)
GetComplianceData retrieves compliance status for all frameworks
func (*ComplianceDataSource) GetComplianceReport ¶
func (c *ComplianceDataSource) GetComplianceReport(framework compliance.Framework) (*compliance.ComplianceReport, error)
GetComplianceReport retrieves a detailed compliance report for a framework
type Config ¶
type Config struct {
// StoragePath is where reports are persisted (empty = in-memory only)
StoragePath string `json:"storage_path,omitempty"`
// MaxConcurrent is the maximum concurrent report generations
MaxConcurrent int `json:"max_concurrent,omitempty"`
// CleanupInterval is how often to run cleanup
CleanupInterval time.Duration `json:"cleanup_interval,omitempty"`
// MaxReportAge is how long to keep reports before cleanup
MaxReportAge time.Duration `json:"max_report_age,omitempty"`
// DefaultFormat is the default output format
DefaultFormat ReportFormat `json:"default_format,omitempty"`
// EnableScheduler turns on scheduled report background execution
EnableScheduler bool `json:"enable_scheduler,omitempty"`
// MaxReports limits the number of reports stored (0 = unlimited)
MaxReports int `json:"max_reports,omitempty"`
}
Config contains reporter configuration.
type DeliveryConfig ¶
type DeliveryConfig struct {
// Email addresses for email delivery
Email []string `json:"email,omitempty"`
// WebhookURL for webhook delivery
WebhookURL string `json:"webhook_url,omitempty"`
// WebhookHeaders for webhook requests
WebhookHeaders map[string]string `json:"webhook_headers,omitempty"`
}
DeliveryConfig contains settings for report delivery.
type DeliveryHandler ¶
type DeliveryHandler interface {
// DeliverReport sends a report via the configured method
DeliverReport(report *Report, config DeliveryConfig) error
}
DeliveryHandler interface for report delivery.
type MetricsDataSource ¶
type MetricsDataSource struct {
// contains filtered or unexported fields
}
MetricsDataSource integrates with the metrics package
func NewMetricsDataSource ¶
func NewMetricsDataSource(collector *metrics.MetricsCollector) *MetricsDataSource
NewMetricsDataSource creates a new metrics data source
func (*MetricsDataSource) GetMetricsData ¶
func (m *MetricsDataSource) GetMetricsData() (map[string]interface{}, error)
GetMetricsData retrieves current metrics from the collector
type NoOpDelivery ¶
type NoOpDelivery struct{}
NoOpDelivery is a delivery handler that does nothing.
func (*NoOpDelivery) DeliverReport ¶
func (n *NoOpDelivery) DeliverReport(report *Report, config DeliveryConfig) error
DeliverReport implements DeliveryHandler with no operation.
type Report ¶
type Report struct {
// ID is the unique identifier for this report
ID string `json:"id"`
// Type is the kind of report
Type ReportType `json:"type"`
// Format is the output format used
Format ReportFormat `json:"format"`
// Status is the current generation status
Status ReportStatus `json:"status"`
// Created is when the report was requested
Created time.Time `json:"created"`
// Completed is when the report finished (zero if not complete)
Completed time.Time `json:"completed,omitempty"`
// Data contains the report data
Data interface{} `json:"data,omitempty"`
// Error contains error message if generation failed
Error string `json:"error,omitempty"`
// Filename is the output filename (if persisted)
Filename string `json:"filename,omitempty"`
// Size is the report size in bytes
Size int64 `json:"size,omitempty"`
}
Report represents a generated report with its metadata and data.
type ReportFilter ¶
type ReportFilter struct {
// Patterns to include in the report (empty = all)
Patterns []string `json:"patterns,omitempty"`
// Severity minimum level to include
Severity string `json:"severity,omitempty"`
// Sources to include (empty = all)
Sources []string `json:"sources,omitempty"`
// Categories to include
Categories []string `json:"categories,omitempty"`
// Keyword search string
Keyword string `json:"keyword,omitempty"`
// Custom filter parameters
Custom map[string]interface{} `json:"custom,omitempty"`
}
ReportFilter contains criteria for filtering report data.
type ReportFormat ¶
type ReportFormat string
ReportFormat defines the output format for reports.
const ( // ReportFormatJSON outputs report as JSON ReportFormatJSON ReportFormat = "json" // ReportFormatCSV outputs report as CSV ReportFormatCSV ReportFormat = "csv" // ReportFormatHTML outputs report as HTML ReportFormatHTML ReportFormat = "html" // ReportFormatPDF is a placeholder for PDF output (requires external library) ReportFormatPDF ReportFormat = "pdf" )
type ReportRequest ¶
type ReportRequest struct {
// Type is the report type to generate
Type ReportType `json:"type"`
// Format is the desired output format
Format ReportFormat `json:"format"`
// StartTime is the beginning of the reporting period (for time-based reports)
StartTime time.Time `json:"start_time,omitempty"`
// EndTime is the end of the reporting period (for time-based reports)
EndTime time.Time `json:"end_time,omitempty"`
// Filters to apply when generating the report
Filters ReportFilter `json:"filters,omitempty"`
// TemplateID is an optional template to use
TemplateID string `json:"template_id,omitempty"`
}
ReportRequest contains parameters for generating a new report.
type ReportSchedule ¶
type ReportSchedule struct {
// ID is the unique schedule identifier
ID string `json:"id"`
// Name is a human-readable name
Name string `json:"name"`
// Type is the schedule frequency
Type ScheduleType `json:"type"`
// ReportType is the type of report to generate
ReportType ReportType `json:"report_type"`
// Format is the output format
Format ReportFormat `json:"format"`
// Hour is the hour to run (0-23, for daily/weekly)
Hour int `json:"hour,omitempty"`
// Minute is the minute to run (0-59)
Minute int `json:"minute,omitempty"`
// DayOfWeek is the day to run (0=Sunday, 6=Saturday, for weekly)
DayOfWeek int `json:"day_of_week,omitempty"`
// DayOfMonth is the day to run (1-31, for monthly)
DayOfMonth int `json:"day_of_month,omitempty"`
// Filters to apply
Filters ReportFilter `json:"filters,omitempty"`
// Enabled indicates if the schedule is active
Enabled bool `json:"enabled"`
// Created is when the schedule was created
Created time.Time `json:"created"`
// LastRun is when the schedule last executed
LastRun *time.Time `json:"last_run,omitempty"`
// NextRun is the scheduled next execution time
NextRun time.Time `json:"next_run"`
// Delivery contains optional delivery settings
Delivery DeliveryConfig `json:"delivery,omitempty"`
}
ReportSchedule defines a recurring scheduled report.
type ReportStatus ¶
type ReportStatus string
ReportStatus defines the current status of a report.
const ( // ReportStatusQueued indicates the report is waiting to be processed ReportStatusQueued ReportStatus = "queued" // ReportStatusRunning indicates the report is being generated ReportStatusRunning ReportStatus = "running" // ReportStatusCompleted indicates the report completed successfully ReportStatusCompleted ReportStatus = "completed" // ReportStatusFailed indicates the report generation failed ReportStatusFailed ReportStatus = "failed" )
type ReportTemplate ¶
type ReportTemplate struct {
// ID is the unique template identifier
ID string `json:"id"`
// Name is a human-readable name
Name string `json:"name"`
// Description describes the template
Description string `json:"description"`
// ReportType is the type of report
ReportType ReportType `json:"report_type"`
// DefaultFormat is the default output format
DefaultFormat ReportFormat `json:"default_format"`
// DefaultFilters are the default filters
DefaultFilters ReportFilter `json:"default_filters,omitempty"`
// CustomTemplate for specialized formatting
CustomTemplate string `json:"custom_template,omitempty"`
// Created is when the template was created
Created time.Time `json:"created"`
}
ReportTemplate defines a reusable report template.
type ReportType ¶
type ReportType string
ReportType defines the type of report to generate.
const ( // ReportTypeRealtime generates a snapshot of current system state ReportTypeRealtime ReportType = "realtime" // ReportTypeSummary generates a summary report for a time period ReportTypeSummary ReportType = "summary" // ReportTypeCompliance generates compliance framework reports ReportTypeCompliance ReportType = "compliance" // ReportTypeSecurity generates security and violation reports ReportTypeSecurity ReportType = "security" // ReportTypePerformance generates performance metrics reports ReportTypePerformance ReportType = "performance" )
type Reporter ¶
type Reporter struct {
// Delivery interface (can be set by user)
Delivery DeliveryHandler
// contains filtered or unexported fields
}
Reporter manages report generation, scheduling, and storage.
func New ¶
New creates a new Reporter with the given configuration. If cfg is empty, uses the default configuration.
func (*Reporter) AddTemplate ¶
func (r *Reporter) AddTemplate(template ReportTemplate) (*ReportTemplate, error)
AddTemplate adds a report template.
func (*Reporter) CancelSchedule ¶
CancelSchedule disables a scheduled report.
func (*Reporter) DeleteReport ¶
DeleteReport removes a report by ID.
func (*Reporter) Export ¶
Export exports a report to a specific format. If the report already exists in the desired format, it may be re-used.
func (*Reporter) Generate ¶
func (r *Reporter) Generate(req ReportRequest) (*Report, error)
Generate creates and executes a new ad-hoc report based on the request. Returns the report ID immediately; use GetReport to check status.
func (*Reporter) GetTemplate ¶
func (r *Reporter) GetTemplate(id string) (*ReportTemplate, error)
GetTemplate retrieves a template by ID.
func (*Reporter) ListReports ¶
func (r *Reporter) ListReports(filterType ReportType, filterStatus ReportStatus) []*Report
ListReports returns all reports, optionally filtered by status or type.
func (*Reporter) ListSchedules ¶
func (r *Reporter) ListSchedules() []*ReportSchedule
ListSchedules returns all scheduled reports.
func (*Reporter) Schedule ¶
func (r *Reporter) Schedule(schedule ReportSchedule) (*ReportSchedule, error)
Schedule creates a new scheduled report.
type ScannerDataSource ¶
type ScannerDataSource struct {
// contains filtered or unexported fields
}
ScannerDataSource integrates with the scanner package
func NewScannerDataSource ¶
func NewScannerDataSource(s *scanner.Scanner) *ScannerDataSource
NewScannerDataSource creates a new scanner data source
func (*ScannerDataSource) GetScannerData ¶
func (s *ScannerDataSource) GetScannerData() (map[string]interface{}, error)
GetScannerData retrieves scanner statistics
type ScheduleType ¶
type ScheduleType string
ScheduleType defines the frequency of scheduled reports.
const ( // ScheduleHourly runs every hour ScheduleHourly ScheduleType = "hourly" // ScheduleDaily runs daily at a specific time ScheduleDaily ScheduleType = "daily" // ScheduleWeekly runs weekly on a specific day/time ScheduleWeekly ScheduleType = "weekly" // ScheduleMonthly runs monthly on a specific day ScheduleMonthly ScheduleType = "monthly" )