database

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Seed struct {
	Sites    []Site
	Contacts []Contact
}

Seed represents the initial seed to the DB.~

Functions

func CompareSites added in v1.3.0

func CompareSites(s1 Site, s2 Site) bool

CompareSites is set up as function due to an issue in the DeepEqual with zero dates.

func GetReportYears added in v1.3.1

func GetReportYears(db *sql.DB) ([]int, error)

GetReportYears returns the years where there is data for reports

func GetYTDReports

func GetYTDReports(db *sql.DB, year int) (map[string]Reports, error)

GetYTDReports gets reports for the active sites. Site status is based on the SiteDown flag in the pings table.

func InitializeDB

func InitializeDB(dbPath string, seedFile string) (*sql.DB, error)

InitializeDB creates the DB file and the schema if the file doesn't exist.

func InitializeReportDB

func InitializeReportDB() (*sql.DB, error)

InitializeReportDB is for test packages to initialize a Report DB for integration testing.

func InitializeTestDB

func InitializeTestDB(seedFile string) (*sql.DB, error)

InitializeTestDB is for test packages to initialize a DB for integration testing.

Types

type Contact

type Contact struct {
	ContactID    int64
	Name         string
	EmailAddress string
	SmsNumber    string
	SmsActive    bool
	EmailActive  bool
	SiteCount    int
	Sites        []Site
}

Contact is one of the contacts for a particular site.

func (*Contact) CreateContact

func (c *Contact) CreateContact(db *sql.DB) error

CreateContact inserts a new contact in the DB.

func (*Contact) DeleteContact added in v1.1.0

func (c *Contact) DeleteContact(db *sql.DB) error

DeleteContact deletes the contact from the DB.

func (*Contact) GetContact

func (c *Contact) GetContact(db *sql.DB, contactID int64) error

GetContact gets the contact details for a given contact.

func (*Contact) GetContactSites added in v1.2.0

func (c *Contact) GetContactSites(db *sql.DB) error

GetContactSites gets the collection of sites for a given contact.

func (*Contact) UpdateContact

func (c *Contact) UpdateContact(db *sql.DB) error

UpdateContact updates the contact information in the DB.

type Contacts

type Contacts []Contact

Contacts is a slice of contacts that aren't necessarily associated with a given site.

func (*Contacts) GetContacts

func (c *Contacts) GetContacts(db *sql.DB) error

GetContacts gets all contacts

type Ping

type Ping struct {
	SiteID         int64
	TimeRequest    time.Time
	Duration       int
	HTTPStatusCode int
	SiteDown       bool
}

Ping contains information about a request to ping a site and details about the result

func (Ping) CreatePing

func (p Ping) CreatePing(db *sql.DB) error

CreatePing inserts a new ping row and last check for the site in the DB.

type Report

type Report struct {
	AvgResponse float64
	PingsUp     int
	PingsDown   int
}

Report contains information about performance where AvgResponse is the average response time for successful requests, PingsUp are the number of successful pings when the site was up and PingsDown is the number of pings when the site was down.

type Reports

type Reports []Report

Reports is a slice of reports, usually the index will represent the month.

type Site

type Site struct {
	SiteID              int64
	Name                string
	IsActive            bool
	URL                 string
	PingIntervalSeconds int
	TimeoutSeconds      int
	IsSiteUp            bool
	ContentExpected     string
	ContentUnexpected   string
	LastStatusChange    time.Time
	LastPing            time.Time
	FirstPing           time.Time
	Contacts            []Contact
	Pings               []Ping
}

Site is the website that will be monitored.

func (Site) AddContactToSite

func (s Site) AddContactToSite(db *sql.DB, contactID int64) error

AddContactToSite associates a contact with a site.

func (*Site) CreateSite

func (s *Site) CreateSite(db *sql.DB) error

CreateSite inserts a new site in the DB.

func (*Site) GetFirstPing

func (s *Site) GetFirstPing(db *sql.DB) (time.Time, error)

GetFirstPing gets the earliest ping for a given site based on the recorded pings.

func (*Site) GetSite

func (s *Site) GetSite(db *sql.DB, siteID int64) error

GetSite gets the site details for a given site.

func (*Site) GetSiteContacts

func (s *Site) GetSiteContacts(db *sql.DB, siteID int64) error

GetSiteContacts gets the collection of contacts for a given site.

func (*Site) GetSitePings

func (s *Site) GetSitePings(db *sql.DB, siteID int64, startTime time.Time, endTime time.Time) error

GetSitePings gets the pings for a given site for a given time interval.

func (Site) RemoveContactFromSite

func (s Site) RemoveContactFromSite(db *sql.DB, contactID int64) error

RemoveContactFromSite deletes the association of a contact with a site.

func (*Site) UpdateSite

func (s *Site) UpdateSite(db *sql.DB) error

UpdateSite updates the site information in the DB.

func (*Site) UpdateSiteFirstPing

func (s *Site) UpdateSiteFirstPing(db *sql.DB, firstPingTime time.Time) error

UpdateSiteFirstPing updates the up/down status and last status change of a Site.

func (*Site) UpdateSiteStatus

func (s *Site) UpdateSiteStatus(db *sql.DB, isSiteUp bool) error

UpdateSiteStatus updates the up/down status and last status change of a Site.

type Sites

type Sites []Site

Sites is a slice of sites

func (*Sites) GetSites

func (s *Sites) GetSites(db *sql.DB, activeOnly bool, withContacts bool) error

GetSites gets all of the sites without contacts. The switch activeOnly controls whether to get only active sites. The option withContacts controls whether to also get the associated contacts.

Jump to

Keyboard shortcuts

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