mongo

package
v0.0.0-...-7ff62be Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DB                                = "canopsis"
	ConfigurationMongoCollection      = "configuration"
	SessionMongoCollection            = "session"
	AlarmMongoCollection              = "periodical_alarm"
	EntityMongoCollection             = "default_entities"
	PbehaviorMongoCollection          = "pbehavior"
	PbehaviorTypeMongoCollection      = "pbehavior_type"
	PbehaviorReasonMongoCollection    = "pbehavior_reason"
	PbehaviorExceptionMongoCollection = "pbehavior_exception"
	FileMongoCollection               = "files"
	MetaAlarmRulesMongoCollection     = "meta_alarm_rules"
	IdleRuleMongoCollection           = "idle_rule"
	ExportTaskMongoCollection         = "export_task"
	ActionLogMongoCollection          = "action_log"
	DynamicInfosRulesMongoCollection  = "dynamic_infos"
	EntityCategoryMongoCollection     = "entity_category"
	ImportJobMongoCollection          = "default_importgraph"
	JunitTestSuiteMongoCollection     = "junit_test_suite"
	JunitTestCaseMediaMongoCollection = "junit_test_case_media"
	PlaylistMongoCollection           = "view_playlist"
	StateSettingsMongoCollection      = "state_settings"
	BroadcastMessageMongoCollection   = "broadcast_message"
	AssociativeTableCollection        = "default_associativetable"
	NotificationMongoCollection       = "notification"

	ViewMongoCollection           = "views"
	ViewTabMongoCollection        = "viewtabs"
	WidgetMongoCollection         = "widgets"
	WidgetFiltersMongoCollection  = "widget_filters"
	WidgetTemplateMongoCollection = "widget_templates"
	ViewGroupMongoCollection      = "viewgroups"

	// MessageRateStatsHourCollectionName contains old stats
	// deprecated
	MessageRateStatsHourCollectionName = "message_rate_statistic_hour"

	// Collection for ok/ko event statistics
	EventStatistics = "event_statistics"

	EventRecordsMongoCollection = "event_records"

	// Remediation collections
	InstructionMongoCollection          = "instruction"
	InstructionExecutionMongoCollection = "instruction_execution"
	InstructionRatingMongoCollection    = "instruction_rating"
	JobConfigMongoCollection            = "job_config"
	JobMongoCollection                  = "job"
	JobHistoryMongoCollection           = "job_history"

	// Data storage alarm collections
	ResolvedAlarmMongoCollection = "resolved_alarms"
	ArchivedAlarmMongoCollection = "archived_alarms"
	// Data storage entity collections
	ArchivedEntitiesMongoCollection = "archived_entities"

	TokenMongoCollection               = "token"
	ShareTokenMongoCollection          = "share_token"
	WebsocketConnectionMongoCollection = "websocket_connection"

	ResolveRuleMongoCollection  = "resolve_rule"
	FlappingRuleMongoCollection = "flapping_rule"

	UserPreferencesMongoCollection = "userpreferences"

	KpiFilterMongoCollection = "kpi_filter"

	PatternMongoCollection = "pattern"

	EntityInfosDictionaryCollection  = "entity_infos_dictionary"
	DynamicInfosDictionaryCollection = "dynamic_infos_dictionary"

	MapMongoCollection = "map"

	AlarmTagCollection      = "alarm_tag"
	AlarmTagColorCollection = "alarm_tag_color"

	MibCollection       = "default_mibs"
	SnmpRulesCollection = "default_snmprules"

	ScenarioMongoCollection          = "action_scenario"
	DeclareTicketRuleMongoCollection = "declare_ticket_rule"
	WebhookHistoryMongoCollection    = "webhook_history"

	LinkRuleMongoCollection = "link_rule"

	UserCollection         = "user"
	RoleCollection         = "role"
	RoleTemplateCollection = "role_template"
	PermissionCollection   = "permission"

	EventFilterRuleCollection    = "eventfilter"
	EventFilterFailureCollection = "eventfilter_failure"

	EntityCountersCollection = "entity_counters"

	MetaAlarmStatesCollection = "meta_alarm_states"

	ColorThemeCollection = "color_theme"

	EngineNotificationCollection = "engine_notification"

	IconCollection = "icon"
)
View Source
const (
	DefaultClientTimeout          = 15 * time.Second
	DefaultServerSelectionTimeout = 30 * time.Second

	ChangeStreamTypeInsert = "insert"
	ChangeStreamTypeUpdate = "update"
	ChangeStreamTypeDelete = "delete"
)
View Source
const (
	SortAsc  = "asc"
	SortDesc = "desc"
)
View Source
const (
	EnvURL = "CPS_MONGO_URL"
)
View Source
const MigrationHelperComment = `` /* 140-byte string literal not displayed */

Variables

This section is empty.

Functions

func GetSort

func GetSort(sortBy, sort string) bson.D

func IsConnectionError

func IsConnectionError(err error) bool

Types

type ChangeStream

type ChangeStream interface {
	ID() int64
	Decode(val interface{}) error
	Err() error
	Close(ctx context.Context) error
	ResumeToken() bson.Raw
	Next(ctx context.Context) bool
	TryNext(ctx context.Context) bool
}

type CommandsRegister

type CommandsRegister interface {
	Clear()
	RegisterInsert(i any)
	RegisterUpdate(id string, set bson.M)
	Commit(ctx context.Context) error
}

func NewCommandsRegister

func NewCommandsRegister(collection DbCollection, bulkSize int) CommandsRegister

type Cursor

type Cursor interface {
	All(ctx context.Context, results interface{}) error
	Next(ctx context.Context) bool
	Close(ctx context.Context) error
	Decode(val interface{}) error
	Err() error
}

type DbClient

type DbClient interface {
	Name() string
	Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
	Collection(string) DbCollection
	CreateCollection(ctx context.Context, name string, opts ...*options.CreateCollectionOptions) error
	Disconnect(ctx context.Context) error
	SetRetry(count int, timeout time.Duration)
	Ping(ctx context.Context, rp *readpref.ReadPref) error
	WithTransaction(ctx context.Context, f func(context.Context) error) error
	ListCollectionNames(ctx context.Context, filter interface{}, opts ...*options.ListCollectionsOptions) ([]string, error)
	IsDistributed() bool
	RunCommand(ctx context.Context, runCommand any, opts ...*options.RunCmdOptions) SingleResultHelper
	RunAdminCommand(ctx context.Context, runCommand any, opts ...*options.RunCmdOptions) SingleResultHelper
}

DbClient connected MongoDB client settings

func NewClient

func NewClient(ctx context.Context, retryCount int, minRetryTimeout time.Duration, logger zerolog.Logger) (DbClient, error)

NewClient creates a new connection to the MongoDB database. It uses EnvURL as configuration source.

func NewClientWithOptions

func NewClientWithOptions(
	ctx context.Context,
	retryCount int,
	minRetryTimeout time.Duration,
	serverSelectionTimeout time.Duration,
	clientTimeout time.Duration,
	logger zerolog.Logger,
) (DbClient, error)

type DbCollection

type DbCollection interface {
	Name() string
	Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (Cursor, error)
	BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)
	CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)
	DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (int64, error)
	DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (int64, error)
	Distinct(ctx context.Context, fieldName string, filter interface{},
		opts ...*options.DistinctOptions) ([]interface{}, error)
	Drop(ctx context.Context) error
	Find(ctx context.Context, filter interface{},
		opts ...*options.FindOptions) (Cursor, error)
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) SingleResultHelper
	FindOneAndDelete(ctx context.Context, filter interface{},
		opts ...*options.FindOneAndDeleteOptions) SingleResultHelper
	FindOneAndReplace(ctx context.Context, filter interface{}, replacement interface{},
		opts ...*options.FindOneAndReplaceOptions) SingleResultHelper
	FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.FindOneAndUpdateOptions) SingleResultHelper
	Indexes() mongo.IndexView
	InsertOne(ctx context.Context, document interface{},
		opts ...*options.InsertOneOptions) (interface{}, error)
	InsertMany(ctx context.Context, documents []interface{},
		opts ...*options.InsertManyOptions) ([]interface{}, error)
	ReplaceOne(ctx context.Context, filter interface{},
		replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)
	UpdateMany(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	UpdateOne(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	Watch(ctx context.Context, pipeline interface{},
		opts ...*options.ChangeStreamOptions) (ChangeStream, error)
}

type ScriptExecutor

type ScriptExecutor interface {
	Exec(ctx context.Context, file string) error
}

ScriptExecutor is used to execute JavaScript migration scripts. Each implementation has to support global functions described above.

type SingleResultHelper

type SingleResultHelper interface {
	Decode(v interface{}) error
	DecodeBytes() (bson.Raw, error)
	Err() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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