entity

package
v0.0.0-...-9b5cd94 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CleanTaskTypeArchiveDisabled = iota
	CleanTaskTypeArchiveUnlinked
	CleanTaskTypeCleanArchived
)

Variables

View Source
var ErrNoFound = errors.New("entity not found")

Functions

func TransformInfosRequest

func TransformInfosRequest(infoRequests []InfoRequest) map[string]types.Info

Types

type API

type API interface {
	List(c *gin.Context)
	BulkEnable(c *gin.Context)
	BulkDisable(c *gin.Context)
	StartExport(c *gin.Context)
	GetExport(c *gin.Context)
	DownloadExport(c *gin.Context)
	ArchiveDisabled(c *gin.Context)
	ArchiveUnlinked(c *gin.Context)
	CleanArchived(c *gin.Context)
	GetContextGraph(c *gin.Context)
	CheckStateSetting(c *gin.Context)
	GetStateSetting(c *gin.Context)
}

func NewApi

func NewApi(
	store Store,
	exportExecutor export.TaskExecutor,
	cleanTaskChan chan<- CleanTask,
	entityChangeListener chan<- entityservice.ChangeEntityMessage,
	metricMetaUpdater metrics.MetaUpdater,
	actionLogger logger.ActionLogger,
	encoder encoding.Encoder,
	logger zerolog.Logger,
) API

type AggregationResult

type AggregationResult struct {
	Data       []Entity `bson:"data" json:"data"`
	TotalCount int64    `bson:"total_count" json:"total_count"`
}

func (AggregationResult) GetData

func (r AggregationResult) GetData() interface{}

func (AggregationResult) GetTotal

func (r AggregationResult) GetTotal() int64

type ArchiveDisabledRequest

type ArchiveDisabledRequest struct {
	WithDependencies bool `json:"with_dependencies"`
}

type ArchiveUnlinkedRequest

type ArchiveUnlinkedRequest struct {
	ArchiveBefore datetime.DurationWithUnit `json:"archive_before"`
}

type Archiver

type Archiver interface {
	ArchiveDisabledEntities(ctx context.Context, archiveDeps bool) (int64, error)
	ArchiveUnlinkedResources(ctx context.Context, before datetime.CpsTime) (int64, error)
	ArchiveUnlinkedComponents(ctx context.Context, before datetime.CpsTime) (int64, error)
	ArchiveUnlinkedConnectors(ctx context.Context, before datetime.CpsTime) (int64, error)
	DeleteArchivedEntities(ctx context.Context) (int64, error)
}

func NewArchiver

func NewArchiver(db mongo.DbClient) Archiver

type BaseFilterRequest

type BaseFilterRequest struct {
	Search        string   `form:"search" json:"search"`
	Filters       []string `form:"filters[]" json:"filters"`
	Category      string   `form:"category" json:"category"`
	Type          []string `form:"type[]" json:"type"`
	NoEvents      bool     `form:"no_events" json:"no_events"`
	EntityPattern string   `form:"entity_pattern" json:"entity_pattern"`
}

BaseFilterRequest easyjson:json

func (BaseFilterRequest) MarshalEasyJSON

func (v BaseFilterRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*BaseFilterRequest) UnmarshalEasyJSON

func (v *BaseFilterRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

type BulkToggleRequestItem

type BulkToggleRequestItem struct {
	ID string `json:"_id" binding:"required"`
}

type Category

type Category struct {
	ID   string `bson:"_id" json:"_id"`
	Name string `bson:"name" json:"name"`
}

type CheckStateSettingRequest

type CheckStateSettingRequest struct {
	ID          string        `json:"_id"`
	Name        string        `json:"name" binding:"required,max=255"`
	Connector   string        `json:"connector"`
	Type        string        `json:"type" binding:"required,oneof=component service"`
	Infos       []InfoRequest `json:"infos" binding:"dive"`
	Category    string        `json:"category"`
	ImpactLevel int64         `json:"impact_level" binding:"required,min=1,max=10"`
}

CheckStateSettingRequest contains some required fields because they are required in entitybasic.EditRequest they are not needed to be required for check logic, we're just keeping the validation consistency between request models.

type CleanTask

type CleanTask struct {
	Type                    int
	ArchiveWithDependencies bool
	ArchiveBefore           *datetime.DurationWithUnit
	UserID                  string
}

type ContextGraphRequest

type ContextGraphRequest struct {
	ID string `form:"_id" binding:"required"`
}

type ContextGraphResponse

type ContextGraphResponse struct {
	Impacts []string `bson:"impact" json:"impact"`
	Depends []string `bson:"depends" json:"depends"`
}

type DisabledCleaner

type DisabledCleaner interface {
	RunCleanerProcess(ctx context.Context, ch <-chan CleanTask)
}

func NewDisabledCleaner

func NewDisabledCleaner(
	redisClient redis.Cmdable,
	adapter datastorage.Adapter,
	dataStorageConfigProvider config.DataStorageConfigProvider,
	metricMetaUpdater metrics.MetaUpdater,
	logger zerolog.Logger,
) DisabledCleaner

type Entity

type Entity struct {
	ID             string            `bson:"_id" json:"_id"`
	Name           string            `bson:"name" json:"name"`
	Enabled        bool              `bson:"enabled" json:"enabled"`
	Infos          Infos             `bson:"infos" json:"infos"`
	ComponentInfos Infos             `bson:"component_infos,omitempty" json:"component_infos,omitempty"`
	Type           string            `bson:"type" json:"type"`
	ImpactLevel    int64             `bson:"impact_level" json:"impact_level"`
	Category       *Category         `bson:"category" json:"category"`
	IdleSince      *datetime.CpsTime `bson:"idle_since,omitempty" json:"idle_since,omitempty" swaggertype:"integer"`
	LastEventDate  *datetime.CpsTime `bson:"last_event_date,omitempty" json:"last_event_date,omitempty" swaggertype:"integer"`

	PbehaviorInfo     *PbehaviorInfo    `bson:"pbehavior_info,omitempty" json:"pbehavior_info,omitempty"`
	LastPbehaviorDate *datetime.CpsTime `bson:"last_pbehavior_date,omitempty" json:"last_pbehavior_date,omitempty" swaggertype:"integer"`

	Connector string `bson:"connector,omitempty" json:"connector,omitempty"`
	Component string `bson:"component,omitempty" json:"component,omitempty"`

	// ConnectorType contains a part before "/" of connector id.
	ConnectorType string `bson:"-" json:"connector_type,omitempty"`

	// Flags
	Deletable *bool `bson:"deletable,omitempty" json:"deletable,omitempty"`

	// Stats
	OKEvents *int `bson:"ok_events" json:"ok_events,omitempty"`
	KOEvents *int `bson:"ko_events" json:"ko_events,omitempty"`

	// Alarm fields
	State               *int              `bson:"state" json:"state,omitempty"`
	ImpactState         *int              `bson:"impact_state" json:"impact_state,omitempty"`
	Status              *int              `bson:"status" json:"status,omitempty"`
	Ack                 *common.AlarmStep `bson:"ack" json:"ack,omitempty"`
	Snooze              *common.AlarmStep `bson:"snooze" json:"snooze,omitempty"`
	AlarmLastUpdateDate *datetime.CpsTime `bson:"alarm_last_update_date" json:"alarm_last_update_date,omitempty" swaggertype:"integer"`

	// Links
	Links link.LinksByCategory `bson:"-" json:"links,omitempty"`

	// DependsCount contains only service's dependencies
	DependsCount *int `bson:"depends_count" json:"depends_count,omitempty"`
	// ImpactsCount contains only services
	ImpactsCount *int `bson:"impacts_count" json:"impacts_count,omitempty"`

	Coordinates *types.Coordinates `bson:"coordinates,omitempty" json:"coordinates,omitempty"`

	savedpattern.EntityPatternFields `bson:",inline"`

	Resources []string `bson:"resources,omitempty" json:"-"`

	ImportSource string            `bson:"import_source,omitempty" json:"import_source,omitempty"`
	Imported     *datetime.CpsTime `bson:"imported,omitempty" json:"imported,omitempty" swaggertype:"integer"`

	PerfData         []string `bson:"perf_data" json:"-"`
	FilteredPerfData []string `bson:"filtered_perf_data" json:"filtered_perf_data,omitempty"`
}

type ExportRequest

type ExportRequest struct {
	BaseFilterRequest
	Fields    export.Fields `json:"fields"`
	Separator string        `json:"separator" binding:"oneoforempty=comma semicolon tab space"`
}

type ExportResponse

type ExportResponse struct {
	ID string `json:"_id"`
	// Possible values.
	//   * `0` - Running
	//   * `1` - Succeeded
	//   * `2` - Failed
	Status int64 `json:"status"`
}

type Info

type Info struct {
	Name        string      `bson:"name" json:"name"`
	Description string      `bson:"description" json:"description"`
	Value       interface{} `bson:"value" json:"value"`
}

type InfoRequest

type InfoRequest struct {
	Name        string      `json:"name" binding:"required,max=255"`
	Description string      `json:"description" binding:"max=255"`
	Value       interface{} `json:"value"`
}

func (*InfoRequest) UnmarshalJSON

func (r *InfoRequest) UnmarshalJSON(b []byte) error

type Infos

type Infos map[string]Info

func (*Infos) UnmarshalBSONValue

func (i *Infos) UnmarshalBSONValue(_ bsontype.Type, b []byte) error

type ListRequest

type ListRequest struct {
	BaseFilterRequest
	SortRequest
	SearchBy []string `form:"active_columns[]" json:"active_columns[]"`
}

type ListRequestWithPagination

type ListRequestWithPagination struct {
	pagination.Query
	ListRequest
	WithFlags bool     `form:"with_flags" json:"with_flags"`
	PerfData  []string `form:"perf_data[]" json:"perf_data"`
}

type MongoQueryBuilder

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

func NewMongoQueryBuilder

func NewMongoQueryBuilder(client mongo.DbClient) *MongoQueryBuilder

func (*MongoQueryBuilder) CreateCountAggregationPipeline

func (q *MongoQueryBuilder) CreateCountAggregationPipeline(ctx context.Context, r ListRequestWithPagination, now datetime.CpsTime) ([]bson.M, error)

func (*MongoQueryBuilder) CreateListAggregationPipeline

func (q *MongoQueryBuilder) CreateListAggregationPipeline(ctx context.Context, r ListRequestWithPagination, now datetime.CpsTime) ([]bson.M, error)

func (*MongoQueryBuilder) CreateOnlyListAggregationPipeline

func (q *MongoQueryBuilder) CreateOnlyListAggregationPipeline(ctx context.Context, r ListRequest, now datetime.CpsTime) ([]bson.M, error)

func (*MongoQueryBuilder) CreateTreeOfDepsAggregationPipeline

func (q *MongoQueryBuilder) CreateTreeOfDepsAggregationPipeline(
	match bson.M,
	paginationQuery pagination.Query,
	sortRequest SortRequest,
	category, search string,
	withFlags bool,
	withStateDependsCount bool,
	now datetime.CpsTime,
) []bson.M

type PbehaviorInfo

type PbehaviorInfo struct {
	types.PbehaviorInfo `bson:",inline"`

	IconName string `bson:"icon_name" json:"icon_name"`
}

type SimplifiedEntity

type SimplifiedEntity struct {
	ID        string   `bson:"_id"`
	Name      string   `bson:"name"`
	Component string   `bson:"component"`
	Type      string   `bson:"type"`
	Enabled   bool     `bson:"enabled"`
	Resources []string `bson:"resources"`
}

type SortRequest

type SortRequest struct {
	Sort   string `form:"sort" json:"sort" binding:"oneoforempty=asc desc"`
	SortBy string `form:"sort_by" json:"sort_by"`
}

type StateSettingResponse

type StateSettingResponse struct {
	ID                     string                         `bson:"_id" json:"_id"`
	Title                  string                         `json:"title"`
	Method                 string                         `json:"method"`
	Type                   string                         `json:"type,omitempty"`
	InheritedEntityPattern *pattern.Entity                `bson:"inherited_entity_pattern,omitempty" json:"inherited_entity_pattern,omitempty"`
	StateThresholds        *statesettings.StateThresholds `bson:"state_thresholds,omitempty" json:"state_thresholds,omitempty"`

	DependsCount               int    `bson:"-" json:"depends_count,omitempty"`
	ThresholdState             string `bson:"-" json:"threshold_state,omitempty"`
	ThresholdStateDependsCount int    `bson:"-" json:"threshold_state_depends_count,omitempty"`
}

type Store

type Store interface {
	Find(ctx context.Context, r ListRequestWithPagination) (*AggregationResult, error)
	Toggle(ctx context.Context, id string, enabled bool) (bool, SimplifiedEntity, error)
	GetContextGraph(ctx context.Context, id string) (*ContextGraphResponse, error)
	Export(ctx context.Context, t export.Task) (export.DataCursor, error)
	CheckStateSetting(ctx context.Context, r CheckStateSettingRequest) (StateSettingResponse, error)
	GetStateSetting(ctx context.Context, id string) (StateSettingResponse, error)
}

func NewStore

func NewStore(db, dbExport mongo.DbClient, timezoneConfigProvider config.TimezoneConfigProvider, decoder encoding.Decoder) Store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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