Documentation ¶
Overview ¶
Package database contains methods used to perform CRUD operations to the MongoDB database
Index ¶
- type MongoDatabase
- func (md *MongoDatabase) ConnectToMongodb()
- func (md *MongoDatabase) DeleteAllNoDataAlerts() utils.AdvancedErrorInterface
- func (md *MongoDatabase) DeleteNoDataAlertByHost(hostname string) utils.AdvancedErrorInterface
- func (md *MongoDatabase) ExistNoDataAlertByHost(hostname string) (bool, utils.AdvancedErrorInterface)
- func (md *MongoDatabase) FindHostData(id primitive.ObjectID) (model.HostDataBE, utils.AdvancedErrorInterface)
- func (md *MongoDatabase) FindMostRecentHostDataOlderThan(hostname string, t time.Time) (model.HostDataBE, utils.AdvancedErrorInterface)
- func (md *MongoDatabase) FindOldCurrentHosts(t time.Time) ([]model.HostDataBE, utils.AdvancedErrorInterface)
- func (md *MongoDatabase) Init()
- func (md *MongoDatabase) InsertAlert(alert model.Alert) (*mongo.InsertOneResult, utils.AdvancedErrorInterface)
- type MongoDatabaseInterface
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 ¶
func (md *MongoDatabase) FindHostData(id primitive.ObjectID) (model.HostDataBE, utils.AdvancedErrorInterface)
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 ¶
func (md *MongoDatabase) InsertAlert(alert model.Alert) (*mongo.InsertOneResult, utils.AdvancedErrorInterface)
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