database

package
v0.0.0-...-cc99bfc Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: GPL-3.0, GPL-3.0-or-later Imports: 11 Imported by: 0

Documentation

Overview

Package database contains methods used to perform CRUD operations to the MongoDB database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoDatabase

type MongoDatabase struct {
	// Config contains the dataservice global configuration
	Config config.Configuration
	// Client contain the mongodb client
	Client *mongo.Client
	// TimeNow contains a function that return the current time
	TimeNow func() time.Time
	// Log contains logger formatted
	Log *logrus.Logger
}

MongoDatabase is a implementation

func (*MongoDatabase) ConnectToMongodb

func (md *MongoDatabase) ConnectToMongodb()

ConnectToMongodb connects to the MongoDB and return the connection

func (*MongoDatabase) DeleteAllNoDataAlerts

func (md *MongoDatabase) DeleteAllNoDataAlerts() utils.AdvancedErrorInterface

DeleteAllNoDataAlerts delete all alerts with code NO_DATA

func (*MongoDatabase) DeleteNoDataAlertByHost

func (md *MongoDatabase) DeleteNoDataAlertByHost(hostname string) utils.AdvancedErrorInterface

DeleteNoDataAlertByHost delete NO_DATA alert by hostname

func (*MongoDatabase) ExistNoDataAlertByHost

func (md *MongoDatabase) ExistNoDataAlertByHost(hostname string) (bool, utils.AdvancedErrorInterface)

ExistNoDataAlertByHost return true if the host has associated a new NO_DATA alert

func (*MongoDatabase) FindHostData

FindHostData find a host data

func (*MongoDatabase) FindMostRecentHostDataOlderThan

func (md *MongoDatabase) FindMostRecentHostDataOlderThan(hostname string, t time.Time) (model.HostDataBE, utils.AdvancedErrorInterface)

FindMostRecentHostDataOlderThan return the most recest hostdata that is older than t

func (*MongoDatabase) FindOldCurrentHosts

func (md *MongoDatabase) FindOldCurrentHosts(t time.Time) ([]model.HostDataBE, utils.AdvancedErrorInterface)

FindOldCurrentHosts return the list of current hosts that haven't sent hostdata after time t

func (*MongoDatabase) Init

func (md *MongoDatabase) Init()

Init initializes the connection to the database

func (*MongoDatabase) InsertAlert

InsertAlert insert the alert in the database

type MongoDatabaseInterface

type MongoDatabaseInterface interface {
	// Init initializes the connection to the database
	Init()
	// FindHostData find a host data
	FindHostData(id primitive.ObjectID) (model.HostDataBE, utils.AdvancedErrorInterface)
	// FindMostRecentHostDataOlderThan return the most recest hostdata that is older than t
	FindMostRecentHostDataOlderThan(hostname string, t time.Time) (model.HostDataBE, utils.AdvancedErrorInterface)
	// InsertAlert inserr the alert in the database
	InsertAlert(alert model.Alert) (*mongo.InsertOneResult, utils.AdvancedErrorInterface)
	// FindOldCurrentHost return the list of current hosts that haven't sent hostdata after time t
	FindOldCurrentHosts(t time.Time) ([]model.HostDataBE, utils.AdvancedErrorInterface)
	// ExistNoDataAlertByHost return true if the host has associated a new NO_DATA alert
	ExistNoDataAlertByHost(hostname string) (bool, utils.AdvancedErrorInterface)
	// DeleteNoDataAlertByHost delete NO_DATA alert by hostname
	DeleteNoDataAlertByHost(hostname string) utils.AdvancedErrorInterface
	// DeleteAllNoDataAlerts delete all alerts with code NO_DATA
	DeleteAllNoDataAlerts() utils.AdvancedErrorInterface
}

MongoDatabaseInterface is a interface that wrap methods used to perform CRUD operations in the mongodb database

Jump to

Keyboard shortcuts

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