github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/monitor/config/config.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"sync"
     7  
     8  	"go.aporeto.io/enforcerd/trireme-lib/collector"
     9  	"go.aporeto.io/enforcerd/trireme-lib/monitor/external"
    10  	"go.aporeto.io/enforcerd/trireme-lib/policy"
    11  )
    12  
    13  // Type specifies the type of monitors supported.
    14  type Type int
    15  
    16  // Types supported.
    17  const (
    18  	Docker Type = iota + 1
    19  	LinuxProcess
    20  	LinuxHost
    21  	K8s
    22  	Windows
    23  )
    24  
    25  // MonitorConfig specifies the configs for monitors.
    26  type MonitorConfig struct {
    27  	Common    *ProcessorConfig
    28  	MergeTags []string
    29  	Monitors  map[Type]interface{}
    30  }
    31  
    32  // String returns the configuration in string
    33  func (c *MonitorConfig) String() string {
    34  	buf := fmt.Sprintf("MergeTags:[%s] ", strings.Join(c.MergeTags, ","))
    35  	buf += fmt.Sprintf("Common:%+v ", c.Common)
    36  	buf += fmt.Sprintf("Monitors:{") // nolint
    37  	for k, v := range c.Monitors {
    38  		buf += fmt.Sprintf("{%d:%+v},", k, v)
    39  	}
    40  	buf += fmt.Sprintf("}") // nolint:gosimple // lint:ignore S1039
    41  	return buf
    42  }
    43  
    44  // ProcessorConfig holds configuration for the processors
    45  type ProcessorConfig struct {
    46  	Collector           collector.EventCollector
    47  	Policy              policy.Resolver
    48  	ExternalEventSender []external.ReceiverRegistration
    49  	MergeTags           []string
    50  	ResyncLock          *sync.RWMutex
    51  }
    52  
    53  // IsComplete checks if configuration is complete
    54  func (c *ProcessorConfig) IsComplete() error {
    55  
    56  	if c.Collector == nil {
    57  		return fmt.Errorf("Missing configuration: collector")
    58  	}
    59  
    60  	if c.Policy == nil {
    61  		return fmt.Errorf("Missing configuration: puHandler")
    62  	}
    63  	if c.ResyncLock == nil {
    64  		return fmt.Errorf("Missing resyncLock: puHandler")
    65  	}
    66  	// not all monitors implement external.ReceiveEvents
    67  	// so ExternalEventSender is optional
    68  
    69  	return nil
    70  }