statping: github.com/hunterlong/statping/core Index | Files | Directories

package core

import "github.com/hunterlong/statping/core"

Package core contains the main functionality of Statping. 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/statping

Index

Package Files

checker.go checkin.go configs.go core.go database.go doc.go export.go failures.go groups.go hits.go incidents.go messages.go sample.go services.go sparklines.go users.go

Variables

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 Statping does not have a database connection
    VERSION   string    // VERSION is set on build automatically by setting a -ldflag
)
var (
    // DbSession stores the Statping database session
    DbSession *gorm.DB
    DbModels  []interface{}
)
var (
    SampleHits = 9900.
)

func CheckHash Uses

func CheckHash(password, hash string) bool

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

func CloseDB Uses

func CloseDB()

CloseDB will close the database connection if available

func CountFailures Uses

func CountFailures() uint64

CountFailures returns the total count of failures for all services

func CountUsers Uses

func CountUsers() int64

CountUsers returns the amount of users

func DatabaseMaintence Uses

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 Uses

func Dbtimestamp(group string, column string) string

Dbtimestamp will return a SQL query for grouping by date

func DefaultPort Uses

func DefaultPort(db string) int64

DefaultPort accepts a database type and returns its default port

func DeleteAllSince Uses

func DeleteAllSince(table string, date time.Time)

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

func DeleteConfig Uses

func DeleteConfig() error

DeleteConfig will delete the 'config.yml' file

func ExportChartsJs Uses

func ExportChartsJs() string

ExportChartsJs renders the charts for the index page

func ExportSettings Uses

func ExportSettings() ([]byte, error)

ExportSettings will export a JSON file containing all of the settings below: - Core - Notifiers - Checkins - Users - Services - Groups - Messages

func GetLocalIP Uses

func GetLocalIP() string

GetLocalIP returns the non loopback local IP of the host

func InitApp Uses

func InitApp()

InitApp will initialize Statping

func InsertLargeSampleData Uses

func InsertLargeSampleData() error

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

func InsertNotifierDB Uses

func InsertNotifierDB() error

InsertNotifierDB inject the Statping database instance to the Notifier package

func InsertSampleData Uses

func InsertSampleData() error

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

func InsertSampleHits Uses

func InsertSampleHits() error

InsertSampleHits will create a couple new hits for the sample services

func SampleData Uses

func SampleData() error

SampleData runs all the sample data for a new Statping installation

func Services Uses

func Services() []types.ServiceInterface

type Checkin Uses

type Checkin struct {
    *types.Checkin
}

func AllCheckins Uses

func AllCheckins() []*Checkin

AllCheckins returns all checkin in system

func ReturnCheckin Uses

func ReturnCheckin(c *types.Checkin) *Checkin

ReturnCheckin converts *types.Checking to *core.Checkin

func SelectCheckin Uses

func SelectCheckin(api string) *Checkin

SelectCheckin will find a Checkin based on the API supplied

func (*Checkin) AfterFind Uses

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

AfterFind for Checkin will set the timezone

func (*Checkin) AllFailures Uses

func (c *Checkin) AllFailures() []*types.Failure

Hits returns all of the CheckinHits for a given Checkin

func (*Checkin) AllHits Uses

func (c *Checkin) AllHits() []*types.CheckinHit

AllHits returns all of the CheckinHits for a given Checkin

func (*Checkin) Create Uses

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

Create will create a new Checkin

func (*Checkin) CreateFailure Uses

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

func (*Checkin) Delete Uses

func (c *Checkin) Delete() error

Create will create a new Checkin

func (*Checkin) Expected Uses

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

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

func (*Checkin) Grace Uses

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) Last Uses

func (c *Checkin) Last() *CheckinHit

Last returns the last checkinHit for a Checkin

func (*Checkin) LimitedFailures Uses

func (c *Checkin) LimitedFailures(amount int64) []types.FailureInterface

Hits returns all of the CheckinHits for a given Checkin

func (*Checkin) LimitedHits Uses

func (c *Checkin) LimitedHits(amount int64) []*types.CheckinHit

LimitedHits will return the last amount of successful hits from a checkin

func (c *Checkin) Link() string

func (*Checkin) Period Uses

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

Period will return the duration of the Checkin interval

func (*Checkin) RecheckCheckinFailure Uses

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

RecheckCheckinFailure will check if a Service Checkin has been reported yet

func (*Checkin) Routine Uses

func (c *Checkin) Routine()

Routine for checking if the last Checkin was within its interval

func (*Checkin) Select Uses

func (c *Checkin) Select() *types.Checkin

Select returns a *types.Checkin

func (*Checkin) Service Uses

func (c *Checkin) Service() *Service

func (*Checkin) String Uses

func (c *Checkin) String() string

String will return a Checkin API string

func (*Checkin) Update Uses

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

Update will update a Checkin

type CheckinHit Uses

type CheckinHit struct {
    *types.CheckinHit
}

func ReturnCheckinHit Uses

func ReturnCheckinHit(c *types.CheckinHit) *CheckinHit

ReturnCheckinHit converts *types.checkinHit to *core.checkinHit

func (*CheckinHit) AfterFind Uses

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

AfterFind for checkinHit will set the timezone

func (*CheckinHit) Ago Uses

func (c *CheckinHit) Ago() string

Ago returns the duration of time between now and the last successful checkinHit

func (*CheckinHit) Create Uses

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

Create will create a new successful checkinHit

type Core Uses

type Core struct {
    *types.Core
}

func NewCore Uses

func NewCore() *Core

NewCore return a new *core.Core struct

func SelectCore Uses

func SelectCore() (*Core, error)

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

func UpdateCore Uses

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

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

func (*Core) AfterFind Uses

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

AfterFind for Core will set the timezone

func (Core) AllOnline Uses

func (c Core) AllOnline() bool

AllOnline will be true if all services are online

func (Core) BaseSASS Uses

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 Uses

func (c *Core) Count24HFailures() uint64

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

func (*Core) CountOnline Uses

func (c *Core) CountOnline() int

CountOnline returns the amount of services online

func (Core) CurrentTime Uses

func (c Core) CurrentTime() string

CurrentTime will return the current local time

func (Core) Messages Uses

func (c Core) Messages() []*Message

Messages will return the current local time

func (Core) MobileSASS Uses

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 Uses

func (c Core) SassVars() string

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

func (*Core) SelectAllServices Uses

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) ToCore Uses

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

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

func (Core) UsingAssets Uses

func (c Core) UsingAssets() bool

UsingAssets will return true if /assets folder is present

type DateScan Uses

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 Uses

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

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

func GraphDataRaw Uses

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 Uses

func (d *DateScanObj) ToString() string

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

type DbConfig Uses

type DbConfig types.DbConfig

DbConfig stores the config.yml file for the statup configuration

func EnvToConfig Uses

func EnvToConfig() (*DbConfig, error)

EnvToConfig converts environment variables to a DbConfig variable

func LoadConfigFile Uses

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

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

func LoadUsingEnv Uses

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) Connect Uses

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

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

func (*DbConfig) CreateCore Uses

func (c *DbConfig) CreateCore() *Core

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

func (*DbConfig) CreateDatabase Uses

func (db *DbConfig) CreateDatabase() error

CreateDatabase will CREATE TABLES for each of the Statping elements

func (*DbConfig) DropDatabase Uses

func (db *DbConfig) DropDatabase() error

DropDatabase will DROP each table Statping created

func (*DbConfig) InsertCore Uses

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

InsertCore create the single row for the Core settings in Statping

func (*DbConfig) MigrateDatabase Uses

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 Uses

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

Save will initially create the config.yml file

func (*DbConfig) Update Uses

func (db *DbConfig) Update() error

Update will save the config.yml file

type ErrorResponse Uses

type ErrorResponse struct {
    Error string
}

ErrorResponse is used for HTTP errors to show to User

type ExportData Uses

type ExportData struct {
    Core      *types.Core              `json:"core"`
    Services  []types.ServiceInterface `json:"services"`
    Messages  []*Message               `json:"messages"`
    Checkins  []*Checkin               `json:"checkins"`
    Users     []*User                  `json:"users"`
    Groups    []*Group                 `json:"groups"`
    Notifiers []types.AllNotifiers     `json:"notifiers"`
}

type Failure Uses

type Failure struct {
    *types.Failure
}

func (*Failure) AfterFind Uses

func (f *Failure) AfterFind() (err error)

AfterFind for Failure will set the timezone

func (*Failure) Ago Uses

func (f *Failure) Ago() string

Ago returns a human readable timestamp for a Failure

func (*Failure) Delete Uses

func (f *Failure) Delete() error

Delete will remove a Failure record from the database

func (*Failure) ParseError Uses

func (f *Failure) ParseError() string

ParseError returns a human readable error for a Failure

func (*Failure) Select Uses

func (f *Failure) Select() *types.Failure

Select returns a *types.Failure

type Group Uses

type Group struct {
    *types.Group
}

func SelectGroup Uses

func SelectGroup(id int64) *Group

SelectGroup returns a *core.Group

func SelectGroups Uses

func SelectGroups(includeAll bool, auth bool) []*Group

SelectGroups returns all groups

func (*Group) Create Uses

func (g *Group) Create() (int64, error)

Create will create a group and insert it into the database

func (*Group) Delete Uses

func (g *Group) Delete() error

Delete will remove a group

func (*Group) Services Uses

func (g *Group) Services() []*Service

Services returns all services belonging to a group

func (*Group) Update Uses

func (g *Group) Update() (int64, error)

Update will update a group

func (*Group) VisibleServices Uses

func (g *Group) VisibleServices(auth bool) []*Service

VisibleServices returns all services based on authentication

type GroupOrder Uses

type GroupOrder []*Group

GroupOrder will reorder the groups based on 'order_id' (Order)

func (GroupOrder) Len Uses

func (c GroupOrder) Len() int

Sort interface for resorting the Groups in order

func (GroupOrder) Less Uses

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

func (GroupOrder) Swap Uses

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

type Hit Uses

type Hit struct {
    *types.Hit
}

func (*Hit) AfterFind Uses

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

AfterFind for Hit will set the timezone

type Incident Uses

type Incident struct {
    *types.Incident
}

func AllIncidents Uses

func AllIncidents() []*Incident

AllIncidents will return all incidents and updates recorded

func (*Incident) AllUpdates Uses

func (i *Incident) AllUpdates() []*IncidentUpdate

AllUpdates will return the all updates for an incident

func (*Incident) Create Uses

func (i *Incident) Create() (int64, error)

Create will create a incident and insert it into the database

func (*Incident) Delete Uses

func (i *Incident) Delete() error

Delete will remove a incident

func (*Incident) Update Uses

func (i *Incident) Update() (int64, error)

Update will update a incident

type IncidentUpdate Uses

type IncidentUpdate struct {
    *types.IncidentUpdate
}

func (*IncidentUpdate) Create Uses

func (i *IncidentUpdate) Create() (int64, error)

Create will create a incident update and insert it into the database

func (*IncidentUpdate) Delete Uses

func (i *IncidentUpdate) Delete() error

Delete will remove a incident update

type Message Uses

type Message struct {
    *types.Message
}

func ReturnMessage Uses

func ReturnMessage(m *types.Message) *Message

ReturnMessage will convert *types.Message to *core.Message

func SelectMessage Uses

func SelectMessage(id int64) (*Message, error)

SelectMessage returns a Message based on the ID passed

func SelectMessages Uses

func SelectMessages() ([]*Message, error)

SelectMessages returns all messages

func SelectServiceMessages Uses

func SelectServiceMessages(id int64) []*Message

SelectServiceMessages returns all messages for a service

func (*Message) AfterFind Uses

func (u *Message) AfterFind() (err error)

AfterFind for Message will set the timezone

func (*Message) Create Uses

func (m *Message) Create() (int64, error)

Create will create a Message and insert it into the database

func (*Message) Delete Uses

func (m *Message) Delete() error

Delete will delete a Message from database

func (*Message) Service Uses

func (m *Message) Service() *Service

func (*Message) Update Uses

func (m *Message) Update() (*Message, error)

Update will update a Message in the database

type PluginJSON Uses

type PluginJSON types.PluginJSON

type PluginRepos Uses

type PluginRepos types.PluginRepos

type Service Uses

type Service struct {
    *types.Service
}

func ReturnService Uses

func ReturnService(s *types.Service) *Service

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

func SelectService Uses

func SelectService(id int64) *Service

SelectService returns a *core.Service from in memory

func SelectServiceLink(permalink string) *Service

SelectServiceLink returns a *core.Service from the service permalink

func SelectServices Uses

func SelectServices(auth bool) []*Service

func (*Service) ActiveMessages Uses

func (s *Service) ActiveMessages() []*Message

ActiveMessages returns all service messages that are available based on the current time

func (*Service) AfterFind Uses

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

AfterFind for Service will set the timezone

func (*Service) AllCheckins Uses

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

AllCheckins will return a slice of AllCheckins for a Service

func (*Service) AllFailures Uses

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

AllFailures will return all failures attached to a service

func (*Service) AvgTime Uses

func (s *Service) AvgTime() string

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

func (*Service) AvgUptime Uses

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

AvgUptime returns average online status for last 24 hours

func (*Service) AvgUptime24 Uses

func (s *Service) AvgUptime24() string

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

func (*Service) Check Uses

func (s *Service) Check(record bool)

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

func (*Service) CheckQueue Uses

func (s *Service) CheckQueue(record bool)

CheckQueue is the main go routine for checking a service

func (*Service) CheckinProcess Uses

func (s *Service) CheckinProcess()

CheckinProcess runs the checkin routine for each checkin attached to service

func (*Service) CountHits Uses

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

CountHits returns a int64 for all hits for a service

func (*Service) Create Uses

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

Create will create a service and insert it into the database

func (*Service) CreateFailure Uses

func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error)

CreateFailure will create a new Failure record for a service

func (*Service) CreateHit Uses

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 Uses

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 Uses

func (s *Service) DeleteFailures()

DeleteFailures will delete all failures for a service

func (*Service) Downtime Uses

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

Downtime returns the amount of time of a offline service

func (*Service) DowntimeText Uses

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) FailuresDaysAgo Uses

func (s *Service) FailuresDaysAgo(days int) uint64

FailuresDaysAgo returns the amount of failures since days ago

func (*Service) Hits Uses

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

Hits returns all successful hits for a service

func (*Service) HitsBetween Uses

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) Incidents Uses

func (s *Service) Incidents() []*Incident

Incidents will return the all incidents for a service

func (*Service) LimitedCheckinFailures Uses

func (s *Service) LimitedCheckinFailures(amount int64) []*Failure

LimitedFailures will return the last amount of failures from a service

func (*Service) LimitedFailures Uses

func (s *Service) LimitedFailures(amount int64) []*Failure

LimitedFailures will return the last amount of failures from a service

func (*Service) LimitedHits Uses

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

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

func (*Service) Messages Uses

func (s *Service) Messages() []*Message

Messages returns all Messages for a Service

func (*Service) OnlineDaysPercent Uses

func (s *Service) OnlineDaysPercent(days int) float32

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

func (*Service) OnlineSince Uses

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 Uses

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

Select will return the *types.Service struct for Service

func (*Service) SmallText Uses

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) SparklineDayFailures Uses

func (s *Service) SparklineDayFailures(days int) string

SparklineDayFailures returns a string array of daily service failures

func (*Service) SparklineHourResponse Uses

func (s *Service) SparklineHourResponse(hours int, method string) string

SparklineHourResponse returns a string array for the average response or ping time for a service

func (*Service) Sum Uses

func (s *Service) Sum() float64

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

func (*Service) TotalFailures Uses

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

TotalFailures returns the total amount of failures for a service

func (*Service) TotalFailures24 Uses

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

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

func (*Service) TotalFailuresOnDate Uses

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

TotalFailuresOnDate returns the total amount of failures for a service on a specific time/date

func (*Service) TotalFailuresSince Uses

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 Uses

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

TotalHits returns the total amount of successful hits a service has

func (*Service) TotalHitsSince Uses

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 Uses

func (s *Service) TotalUptime() string

TotalUptime returns the total uptime percent of a service

func (*Service) Update Uses

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

type ServiceOrder Uses

type ServiceOrder []types.ServiceInterface

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

func (ServiceOrder) Len Uses

func (c ServiceOrder) Len() int

Sort interface for resroting the Services in order

func (ServiceOrder) Less Uses

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

func (ServiceOrder) Swap Uses

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

type User Uses

type User struct {
    *types.User
}

func AuthUser Uses

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 ReturnUser Uses

func ReturnUser(u *types.User) *User

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

func SelectAllUsers Uses

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

SelectAllUsers returns all users

func SelectUser Uses

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

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

func SelectUsername Uses

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

SelectUsername returns the User based on the User's username

func (*User) AfterFind Uses

func (u *User) AfterFind() (err error)

AfterFind for USer will set the timezone

func (*User) Create Uses

func (u *User) Create() (int64, error)

Create will insert a new User into the database

func (*User) Delete Uses

func (u *User) Delete() error

Delete will remove the User record from the database

func (*User) Update Uses

func (u *User) Update() error

Update will update the User's record in database

Directories

PathSynopsis
notifierPackage notifier contains the main functionality for the Statping Notification system

Package core imports 27 packages (graph) and is imported by 8 packages. Updated 2019-07-20. Refresh now. Tools for package owners.