core

package
v0.79.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package core contains the main functionality of Statup. This includes everything for Services, Hits, Failures, Users, service checking mechanisms, databases, and notifiers in the notifier package

More info on: https://github.com/hunterlong/statup

Index

Constants

This section is empty.

Variables

View Source
var (
	Configs   *DbConfig // Configs holds all of the config.yml and database info
	CoreApp   *Core     // CoreApp is a global variable that contains many elements
	SetupMode bool      // SetupMode will be true if Statup does not have a database connection
	VERSION   string    // VERSION is set on build automatically by setting a -ldflag
)
View Source
var (
	// DbSession stores the Statup database session
	DbSession *gorm.DB
)

Functions

func AuthUser

func AuthUser(username, password string) (*user, bool)

AuthUser will return the user and a boolean if authentication was correct. AuthUser accepts username, and password as a string

func CheckHash

func CheckHash(password, hash string) bool

CheckHash returns true if the password matches with a hashed bcrypt password

func CloseDB added in v0.79.1

func CloseDB()

CloseDB will close the database connection if available

func CountFailures

func CountFailures() uint64

CountFailures returns the total count of failures for all services

func DatabaseMaintence

func DatabaseMaintence()

DatabaseMaintence will automatically delete old records from 'failures' and 'hits' this function is currently set to delete records 7+ days old every 60 minutes

func Dbtimestamp added in v0.79.1

func Dbtimestamp(group string, column string) string

Dbtimestamp will return a SQL query for grouping by date

func DefaultPort added in v0.79.1

func DefaultPort(db string) int64

DefaultPort accepts a database type and returns its default port

func DeleteAllSince

func DeleteAllSince(table string, date time.Time)

DeleteAllSince will delete a specific table's records based on a time.

func DeleteConfig

func DeleteConfig() error

DeleteConfig will delete the 'config.yml' file

func ExportChartsJs added in v0.79.1

func ExportChartsJs() string

ExportChartsJs renders the charts for the index page

func ExportIndexHTML

func ExportIndexHTML() string

ExportIndexHTML returns the HTML of the index page as a string

func InitApp added in v0.28.6

func InitApp()

InitApp will initialize Statup

func InsertLargeSampleData added in v0.79.1

func InsertLargeSampleData() error

InsertLargeSampleData will create the example/dummy services for testing the Statup server

func InsertNotifierDB added in v0.79.1

func InsertNotifierDB() error

InsertNotifierDB inject the Statup database instance to the Notifier package

func InsertSampleData added in v0.79.1

func InsertSampleData() error

InsertSampleData will create the example/dummy services for a brand new Statup installation

func InsertSampleHits added in v0.79.1

func InsertSampleHits() error

InsertSampleHits will create a couple new hits for the sample services

func ReturnCheckinHit added in v0.79.1

func ReturnCheckinHit(c *types.CheckinHit) *checkinHit

ReturnCheckinHit converts *types.checkinHit to *core.checkinHit

func ReturnUser added in v0.79.1

func ReturnUser(u *types.User) *user

ReturnUser returns *core.user based off a *types.user

func SampleData added in v0.79.1

func SampleData() error

SampleData runs all the sample data for a new Statup installation

func SelectAllUsers

func SelectAllUsers() ([]*user, error)

SelectAllUsers returns all users

func SelectUser

func SelectUser(id int64) (*user, error)

SelectUser returns the user based on the user's ID.

func SelectUsername

func SelectUsername(username string) (*user, error)

SelectUsername returns the user based on the user's username

func Services added in v0.79.1

func Services() []types.ServiceInterface

Types

type Checkin

type Checkin struct {
	*types.Checkin
}

func ReturnCheckin added in v0.79.1

func ReturnCheckin(c *types.Checkin) *Checkin

ReturnCheckin converts *types.Checking to *core.Checkin

func SelectCheckin added in v0.79.1

func SelectCheckin(api string) *Checkin

SelectCheckin will find a Checkin based on the API supplied

func SelectCheckinId added in v0.79.1

func SelectCheckinId(id int64) *Checkin

SelectCheckin will find a Checkin based on the API supplied

func (*Checkin) AfterFind added in v0.79.1

func (c *Checkin) AfterFind() (err error)

AfterFind for Checkin will set the timezone

func (*Checkin) BeforeCreate added in v0.79.1

func (c *Checkin) BeforeCreate() (err error)

BeforeCreate for Checkin will set CreatedAt to UTC

func (*Checkin) Create

func (c *Checkin) Create() (int64, error)

Create will create a new Checkin

func (*Checkin) CreateFailure

func (c *Checkin) CreateFailure() (int64, error)

func (*Checkin) Delete added in v0.79.1

func (c *Checkin) Delete() error

Create will create a new Checkin

func (*Checkin) Expected added in v0.79.1

func (c *Checkin) Expected() time.Duration

Expected returns the duration of when the serviec should receive a Checkin

func (*Checkin) Grace added in v0.79.1

func (c *Checkin) Grace() time.Duration

Grace will return the duration of the Checkin Grace Period (after service hasn't responded, wait a bit for a response)

func (*Checkin) Hits added in v0.79.1

func (c *Checkin) Hits() []*checkinHit

Hits returns all of the CheckinHits for a given Checkin

func (*Checkin) Last added in v0.79.1

func (c *Checkin) Last() *checkinHit

Last returns the last checkinHit for a Checkin

func (c *Checkin) Link() string

func (*Checkin) Period added in v0.79.1

func (c *Checkin) Period() time.Duration

Period will return the duration of the Checkin interval

func (*Checkin) RecheckCheckinFailure

func (c *Checkin) RecheckCheckinFailure(guard chan struct{})

RecheckCheckinFailure will check if a Service Checkin has been reported yet

func (*Checkin) Routine added in v0.79.1

func (c *Checkin) Routine()

Routine for checking if the last Checkin was within its interval

func (*Checkin) Service added in v0.79.1

func (c *Checkin) Service() *Service

func (*Checkin) String

func (c *Checkin) String() string

String will return a Checkin API string

func (*Checkin) Update added in v0.79.1

func (c *Checkin) Update() (int64, error)

Update will update a Checkin

type Core

type Core struct {
	*types.Core
}

func NewCore added in v0.29.1

func NewCore() *Core

NewCore return a new *core.Core struct

func SelectCore

func SelectCore() (*Core, error)

SelectCore will return the CoreApp global variable and the settings/configs for Statup

func UpdateCore added in v0.79.1

func UpdateCore(c *Core) (*Core, error)

UpdateCore will update the CoreApp variable inside of the 'core' table in database

func (Core) AllOnline

func (c Core) AllOnline() bool

AllOnline will be true if all services are online

func (Core) BaseSASS

func (c Core) BaseSASS() string

BaseSASS is the base design , this opens the file /assets/scss/base.scss to be edited in Theme

func (*Core) Count24HFailures added in v0.79.1

func (c *Core) Count24HFailures() uint64

Count24HFailures returns the amount of failures for a service within the last 24 hours

func (*Core) CountOnline added in v0.79.1

func (c *Core) CountOnline() int

CountOnline

func (Core) CurrentTime added in v0.79.1

func (c Core) CurrentTime() string

CurrentTime will return the current local time

func (Core) MobileSASS added in v0.28.5

func (c Core) MobileSASS() string

MobileSASS is the -webkit responsive custom css designs. This opens the file /assets/scss/mobile.scss to be edited in Theme

func (Core) SassVars

func (c Core) SassVars() string

SassVars opens the file /assets/scss/variables.scss to be edited in Theme

func (*Core) SelectAllServices added in v0.79.1

func (c *Core) SelectAllServices(start bool) ([]*Service, error)

SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup.

func (*Core) ServicesCount added in v0.79.1

func (c *Core) ServicesCount() int

ServicesCount returns the amount of services inside the []*core.Services slice

func (*Core) ToCore added in v0.79.1

func (c *Core) ToCore() *types.Core

ToCore will convert *core.Core to *types.Core

func (Core) UsingAssets

func (c Core) UsingAssets() bool

UsingAssets will return true if /assets folder is present

type DateScan

type DateScan struct {
	CreatedAt string `json:"x,omitempty"`
	Value     int64  `json:"y"`
}

DateScan struct is for creating the charts.js graph JSON array

type DateScanObj added in v0.79.1

type DateScanObj struct {
	Array []DateScan `json:"data"`
}

DateScanObj struct is for creating the charts.js graph JSON array

func GraphDataRaw added in v0.79.1

func GraphDataRaw(service types.ServiceInterface, start, end time.Time, group string, column string) *DateScanObj

GraphDataRaw will return all the hits between 2 times for a Service

func (*DateScanObj) ToString added in v0.79.1

func (d *DateScanObj) ToString() string

ToString will convert the DateScanObj into a JSON string for the charts to render

type DbConfig

type DbConfig types.DbConfig

DbConfig stores the config.yml file for the statup configuration

func EnvToConfig added in v0.79.1

func EnvToConfig() *DbConfig

EnvToConfig converts environment variables to a DbConfig variable

func LoadConfigFile added in v0.79.1

func LoadConfigFile(directory string) (*DbConfig, error)

LoadConfigFile will attempt to load the 'config.yml' file in a specific directory

func LoadUsingEnv added in v0.29.7

func LoadUsingEnv() (*DbConfig, error)

LoadUsingEnv will attempt to load database configs based on environment variables. If DB_CONN is set if will force this function.

func (*DbConfig) Close added in v0.79.1

func (db *DbConfig) Close() error

Close shutsdown the database connection

func (*DbConfig) Connect added in v0.79.1

func (db *DbConfig) Connect(retry bool, location string) error

Connect will attempt to connect to the sqlite, postgres, or mysql database

func (*DbConfig) CreateCore added in v0.79.1

func (c *DbConfig) CreateCore() *Core

CreateCore will initialize the global variable 'CoreApp". This global variable contains most of Statup app.

func (*DbConfig) CreateDatabase added in v0.79.1

func (db *DbConfig) CreateDatabase() error

CreateDatabase will CREATE TABLES for each of the Statup elements

func (*DbConfig) DropDatabase added in v0.79.1

func (db *DbConfig) DropDatabase() error

DropDatabase will DROP each table Statup created

func (*DbConfig) InsertCore added in v0.79.1

func (db *DbConfig) InsertCore() (*Core, error)

InsertCore create the single row for the Core settings in Statup

func (*DbConfig) MigrateDatabase added in v0.79.1

func (db *DbConfig) MigrateDatabase() error

MigrateDatabase will migrate the database structure to current version. This function will NOT remove previous records, tables or columns from the database. If this function has an issue, it will ROLLBACK to the previous state.

func (*DbConfig) Save

func (db *DbConfig) Save() (*DbConfig, error)

Save will initially create the config.yml file

func (*DbConfig) Update added in v0.79.1

func (db *DbConfig) Update() error

Update will save the config.yml file

type ErrorResponse

type ErrorResponse struct {
	Error string
}

ErrorResponse is used for HTTP errors to show to user

type Hit

type Hit struct {
	*types.Hit
}

func (*Hit) BeforeCreate added in v0.79.1

func (h *Hit) BeforeCreate() (err error)

BeforeCreate for Hit will set CreatedAt to UTC

type PluginJSON

type PluginJSON types.PluginJSON

type PluginRepos

type PluginRepos types.PluginRepos

type Service

type Service struct {
	*types.Service
}

func ReturnService added in v0.79.1

func ReturnService(s *types.Service) *Service

ReturnService will convert *types.Service to *core.Service

func SelectService

func SelectService(id int64) *Service

SelectService returns a *core.Service from in memory

func (*Service) AfterFind added in v0.79.1

func (s *Service) AfterFind() (err error)

AfterFind for Service will set the timezone

func (*Service) AllFailures added in v0.79.1

func (s *Service) AllFailures() []*failure

AllFailures will return all failures attached to a service

func (*Service) AvgTime

func (s *Service) AvgTime() float64

AvgTime will return the average amount of time for a service to response back successfully

func (*Service) AvgUptime

func (s *Service) AvgUptime(ago time.Time) string

AvgUptime returns average online status for last 24 hours

func (*Service) AvgUptime24 added in v0.79.1

func (s *Service) AvgUptime24() string

AvgUptime24 returns a service's average online status for last 24 hours

func (*Service) BeforeCreate added in v0.79.1

func (s *Service) BeforeCreate() (err error)

BeforeCreate for Service will set CreatedAt to UTC

func (*Service) Check

func (s *Service) Check(record bool)

Check will run checkHttp for HTTP services and checkTcp for TCP services

func (*Service) CheckQueue

func (s *Service) CheckQueue(record bool)

CheckQueue is the main go routine for checking a service

func (*Service) CheckinProcess added in v0.79.1

func (s *Service) CheckinProcess()

CheckinProcess runs the checkin routine for each checkin attached to service

func (*Service) Checkins

func (s *Service) Checkins() []*Checkin

Checkins will return a slice of Checkins for a Service

func (*Service) CountHits added in v0.79.1

func (s *Service) CountHits() (int64, error)

CountHits returns a int64 for all hits for a service

func (*Service) Create

func (s *Service) Create(check bool) (int64, error)

Create will create a service and insert it into the database

func (*Service) CreateFailure

func (s *Service) CreateFailure(f *types.Failure) (int64, error)

CreateFailure will create a new failure record for a service

func (*Service) CreateHit

func (s *Service) CreateHit(h *types.Hit) (int64, error)

CreateHit will create a new 'hit' record in the database for a successful/online service

func (*Service) Delete

func (s *Service) Delete() error

Delete will remove a service from the database, it will also end the service checking go routine

func (*Service) DeleteFailures

func (s *Service) DeleteFailures()

DeleteFailures will delete all failures for a service

func (*Service) Downtime added in v0.79.1

func (s *Service) Downtime() time.Duration

Downtime returns the amount of time of a offline service

func (*Service) DowntimeText added in v0.79.1

func (s *Service) DowntimeText() string

DowntimeText will return the amount of downtime for a service based on the duration

service.DowntimeText()
// Service has been offline for 15 minutes

func (*Service) Hits

func (s *Service) Hits() ([]*types.Hit, error)

Hits returns all successful hits for a service

func (*Service) HitsBetween added in v0.79.1

func (s *Service) HitsBetween(t1, t2 time.Time, group string, column string) *gorm.DB

HitsBetween returns the gorm database query for a collection of service hits between a time range

func (*Service) LimitedCheckins added in v0.79.1

func (s *Service) LimitedCheckins() []*Checkin

LimitedCheckins will return a slice of Checkins for a Service

func (*Service) LimitedFailures

func (s *Service) LimitedFailures() []*failure

LimitedFailures will return the last 10 failures from a service

func (*Service) LimitedHits

func (s *Service) LimitedHits() ([]*types.Hit, error)

LimitedHits returns the last 1024 successful/online 'hit' records for a service

func (*Service) Online24

func (s *Service) Online24() float32

Online24 returns the service's uptime percent within last 24 hours

func (*Service) OnlineSince added in v0.79.1

func (s *Service) OnlineSince(ago time.Time) float32

OnlineSince accepts a time since parameter to return the percent of a service's uptime.

func (*Service) Select added in v0.79.1

func (s *Service) Select() *types.Service

Select will return the *types.Service struct for Service

func (*Service) SmallText added in v0.27.9

func (s *Service) SmallText() string

SmallText returns a short description about a services status

service.SmallText()
// Online since Monday 3:04:05PM, Jan _2 2006

func (*Service) Sum

func (s *Service) Sum() (float64, error)

Sum returns the added value Latency for all of the services successful hits.

func (*Service) ToJSON added in v0.79.1

func (s *Service) ToJSON() string

ToJSON will convert a service to a JSON string

func (*Service) TotalFailures

func (s *Service) TotalFailures() (uint64, error)

TotalFailures returns the total amount of failures for a service

func (*Service) TotalFailures24 added in v0.79.1

func (s *Service) TotalFailures24() (uint64, error)

TotalFailures24 returns the amount of failures for a service within the last 24 hours

func (*Service) TotalFailuresSince added in v0.79.1

func (s *Service) TotalFailuresSince(ago time.Time) (uint64, error)

TotalFailuresSince returns the total amount of failures for a service since a specific time/date

func (*Service) TotalHits

func (s *Service) TotalHits() (uint64, error)

TotalHits returns the total amount of successful hits a service has

func (*Service) TotalHitsSince added in v0.79.1

func (s *Service) TotalHitsSince(ago time.Time) (uint64, error)

TotalHitsSince returns the total amount of hits based on a specific time/date

func (*Service) TotalUptime

func (s *Service) TotalUptime() string

TotalUptime returns the total uptime percent of a service

func (*Service) Update

func (s *Service) Update(restart bool) error

Update will update a service in the database, the service's checking routine can be restarted by passing true

func (*Service) UpdateSingle added in v0.79.1

func (s *Service) UpdateSingle(attr ...interface{}) error

UpdateSingle will update a single column for a service

type ServiceOrder added in v0.79.1

type ServiceOrder []types.ServiceInterface

ServiceOrder will reorder the services based on 'order_id' (Order)

func (ServiceOrder) Len added in v0.79.1

func (c ServiceOrder) Len() int

Sort interface for resroting the Services in order

func (ServiceOrder) Less added in v0.79.1

func (c ServiceOrder) Less(i, j int) bool

func (ServiceOrder) Swap added in v0.79.1

func (c ServiceOrder) Swap(i, j int)

Directories

Path Synopsis
Package notifier contains the main functionality for the Statup Notification system Example Notifier Below is an example of a Notifier with multiple Form values to custom your inputs.
Package notifier contains the main functionality for the Statup Notification system Example Notifier Below is an example of a Notifier with multiple Form values to custom your inputs.

Jump to

Keyboard shortcuts

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