import "github.com/hunterlong/statup/core"
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
- Variables
- func CheckHash(password, hash string) bool
- func CloseDB()
- func CountFailures() uint64
- func DatabaseMaintence()
- func Dbtimestamp(group string, column string) string
- func DeleteAllSince(table string, date time.Time)
- func DeleteConfig()
- func ExportChartsJs() string
- func ExportIndexHTML() string
- func InitApp()
- func InsertLargeSampleData() error
- func InsertSampleData() error
- func InsertSampleHits() error
- func SaveFile(filename string, data []byte) error
- type Checkin
- func ReturnCheckin(s *types.Checkin) *Checkin
- func SelectCheckin(api string) *Checkin
- func (s *Checkin) AfterFind() (err error)
- func (u *Checkin) BeforeCreate() (err error)
- func (u *Checkin) Create() (int64, error)
- func (u *Checkin) Expected() time.Duration
- func (u *Checkin) Grace() time.Duration
- func (u *Checkin) Hits() []CheckinHit
- func (u *Checkin) Last() CheckinHit
- func (u *Checkin) Period() time.Duration
- func (c *Checkin) RecheckCheckinFailure(guard chan struct{})
- func (c *Checkin) String() string
- func (u *Checkin) Update() (int64, error)
- type CheckinHit
- type Core
- func NewCore() *Core
- func SelectCore() (*Core, error)
- func UpdateCore(c *Core) (*Core, error)
- func (c Core) AllOnline() bool
- func (c Core) BaseSASS() string
- func (c *Core) Count24HFailures() uint64
- func (c *Core) CountOnline() int
- func (c Core) CurrentTime() string
- func (c Core) MobileSASS() string
- func (c Core) SassVars() string
- func (c *Core) SelectAllServices() ([]*Service, error)
- func (c *Core) ServicesCount() int
- func (c *Core) ToCore() *types.Core
- func (c Core) UsingAssets() bool
- type DateScan
- type DateScanObj
- type DbConfig
- func LoadConfig(directory string) (*DbConfig, error)
- func LoadUsingEnv() (*DbConfig, error)
- func (db *DbConfig) Close() error
- func (db *DbConfig) Connect(retry bool, location string) error
- func (c *DbConfig) CreateCore() *Core
- func (db *DbConfig) CreateDatabase() error
- func (db *DbConfig) DropDatabase() error
- func (db *DbConfig) InsertCore() (*Core, error)
- func (db *DbConfig) MigrateDatabase() error
- func (c *DbConfig) Save() (*DbConfig, error)
- func (c *DbConfig) Update() error
- type ErrorResponse
- type Failure
- type Hit
- type PluginJSON
- type PluginRepos
- type Service
- func ReturnService(s *types.Service) *Service
- func SelectService(id int64) *Service
- func (s *Service) AfterFind() (err error)
- func (s *Service) AllFailures() []*Failure
- func (s *Service) AvgTime() float64
- func (s *Service) AvgUptime(ago time.Time) string
- func (s *Service) AvgUptime24() string
- func (u *Service) BeforeCreate() (err error)
- func (s *Service) Check(record bool)
- func (s *Service) CheckQueue(record bool)
- func (s *Service) Checkins() []*Checkin
- func (u *Service) Create(check bool) (int64, error)
- func (s *Service) CreateFailure(f *types.Failure) (int64, error)
- func (s *Service) CreateHit(h *types.Hit) (int64, error)
- func (u *Service) Delete() error
- func (u *Service) DeleteFailures()
- func (s *Service) Downtime() time.Duration
- func (s *Service) DowntimeText() string
- func (s *Service) GraphData() string
- func (s *Service) Hits() ([]*types.Hit, error)
- func (s *Service) HitsBetween(t1, t2 time.Time, group string, column string) *gorm.DB
- func (s *Service) LimitedFailures() []*Failure
- func (s *Service) LimitedHits() ([]*types.Hit, error)
- func (s *Service) Online24() float32
- func (s *Service) OnlineSince(ago time.Time) float32
- func (s *Service) Select() *types.Service
- func (s *Service) SmallText() string
- func (s *Service) Sum() (float64, error)
- func (s *Service) ToJSON() string
- func (s *Service) TotalFailures() (uint64, error)
- func (s *Service) TotalFailures24() (uint64, error)
- func (s *Service) TotalFailuresSince(ago time.Time) (uint64, error)
- func (s *Service) TotalHits() (uint64, error)
- func (s *Service) TotalHitsSince(ago time.Time) (uint64, error)
- func (s *Service) TotalUptime() string
- func (u *Service) Update(restart bool) error
- func (u *Service) UpdateSingle(attr ...interface{}) error
- type ServiceOrder
- type User
- func AuthUser(username, password string) (*User, bool)
- func ReturnUser(u *types.User) *User
- func SelectAllUsers() ([]*User, error)
- func SelectUser(id int64) (*User, error)
- func SelectUsername(username string) (*User, error)
- func (u *User) AfterFind() (err error)
- func (u *User) BeforeCreate() (err error)
- func (u *User) Create() (int64, error)
- func (u *User) Delete() error
- func (u *User) Update() error
checker.go checkin.go configs.go core.go database.go doc.go export.go failures.go hits.go sample.go services.go users.go
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
)
var (
DbSession *gorm.DB
)
func CheckHash(password, hash string) bool
CheckHash returns true if the password matches with a hashed bcrypt password
func CloseDB()
CloseDB will close the database connection if available
func CountFailures() uint64
CountFailures returns the total count of failures for all services
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(group string, column string) string
Dbtimestamp will return a SQL query for grouping by date
func DeleteAllSince(table string, date time.Time)
DeleteAllSince will delete a specific table's records based on a time.
func DeleteConfig()
DeleteConfig will delete the 'config.yml' file
func ExportChartsJs() string
func ExportIndexHTML() string
func InitApp()
InitApp will initialize Statup
func InsertLargeSampleData() error
InsertSampleData will create the example/dummy services for a brand new Statup installation
func InsertSampleData() error
InsertSampleData will create the example/dummy services for a brand new Statup installation
func InsertSampleHits() error
InsertSampleHits will create a couple new hits for the sample services
func SaveFile(filename string, data []byte) error
type Checkin struct {
*types.Checkin
}
func ReturnCheckin(s *types.Checkin) *Checkin
ReturnCheckin converts *types.Checking to *core.Checkin
func SelectCheckin(api string) *Checkin
SelectCheckin will find a Checkin based on the API supplied
func (s *Checkin) AfterFind() (err error)
AfterFind for Checkin will set the timezone
func (*Checkin) BeforeCreate
func (u *Checkin) BeforeCreate() (err error)
BeforeCreate for Checkin will set CreatedAt to UTC
func (u *Checkin) Create() (int64, error)
Create will create a new Checkin
func (u *Checkin) Expected() time.Duration
Expected returns the duration of when the serviec should receive a checkin
func (u *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 (u *Checkin) Hits() []CheckinHit
Hits returns all of the CheckinHits for a given Checkin
func (u *Checkin) Last() CheckinHit
Last returns the last CheckinHit for a Checkin
func (u *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 (c *Checkin) String() string
String will return a Checkin API string
func (u *Checkin) Update() (int64, error)
Update will update a Checkin
type CheckinHit struct {
*types.CheckinHit
}
func ReturnCheckinHit(h *types.CheckinHit) *CheckinHit
ReturnCheckinHit converts *types.CheckinHit to *core.CheckinHit
func (s *CheckinHit) AfterFind() (err error)
AfterFind for CheckinHit will set the timezone
func (f *CheckinHit) Ago() string
Ago returns the duration of time between now and the last successful CheckinHit
func (*CheckinHit) BeforeCreate
func (u *CheckinHit) BeforeCreate() (err error)
BeforeCreate for CheckinHit will set CreatedAt to UTC
func (u *CheckinHit) Create() (int64, error)
Create will create a new successful CheckinHit
type Core struct {
*types.Core
}
func NewCore() *Core
NewCore return a new *core.Core struct
func SelectCore() (*Core, error)
SelectCore will return the CoreApp global variable and the settings/configs for Statup
func UpdateCore(c *Core) (*Core, error)
UpdateCore will update the CoreApp variable inside of the 'core' table in database
func (c Core) AllOnline() bool
AllOnline will be true if all services are online
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
func (c *Core) Count24HFailures() uint64
Count24HFailures returns the amount of failures for a service within the last 24 hours
func (*Core) CountOnline
func (c *Core) CountOnline() int
CountOnline
func (Core) CurrentTime
func (c Core) CurrentTime() string
UsingAssets will return true if /assets folder is present
func (Core) MobileSASS
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 (c Core) SassVars() string
SassVars opens the file /assets/scss/variables.scss to be edited in Theme
func (*Core) SelectAllServices
func (c *Core) SelectAllServices() ([]*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
func (c *Core) ServicesCount() int
ServicesCount returns the amount of services inside the []*core.Services slice
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 struct {
CreatedAt string `json:"x"`
Value int64 `json:"y"`
}
DateScan struct is for creating the charts.js graph JSON array
type DateScanObj struct {
Array []DateScan `json:"data"`
}
DateScanObj struct is for creating the charts.js graph JSON array
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 (d *DateScanObj) ToString() string
ToString will convert the DateScanObj into a JSON string for the charts to render
type DbConfig types.DbConfig
func LoadConfig(directory string) (*DbConfig, error)
LoadConfig will attempt to load the 'config.yml' file in a specific directory
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 (db *DbConfig) Close() error
Close shutsdown the database connection
func (db *DbConfig) Connect(retry bool, location string) error
Connect will attempt to connect to the sqlite, postgres, or mysql database
func (*DbConfig) CreateCore
func (c *DbConfig) CreateCore() *Core
CreateCore will initialize the global variable 'CoreApp". This global variable contains most of Statup app.
func (*DbConfig) CreateDatabase
func (db *DbConfig) CreateDatabase() error
CreateDatabase will CREATE TABLES for each of the Statup elements
func (*DbConfig) DropDatabase
func (db *DbConfig) DropDatabase() error
DropDatabase will DROP each table Statup created
func (*DbConfig) InsertCore
func (db *DbConfig) InsertCore() (*Core, error)
InsertCore create the single row for the Core settings in Statup
func (*DbConfig) MigrateDatabase
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 (c *DbConfig) Save() (*DbConfig, error)
Save will initially create the config.yml file
func (c *DbConfig) Update() error
Update will save the config.yml file
type ErrorResponse struct {
Error string
}
ErrorResponse is used for HTTP errors to show to user
type Failure struct {
*types.Failure
}
func (f *Failure) AfterFind() (err error)
AfterFind for Failure will set the timezone
func (f *Failure) Ago() string
Ago returns a human readable timestamp for a failure
func (*Failure) BeforeCreate
func (u *Failure) BeforeCreate() (err error)
BeforeCreate for Failure will set CreatedAt to UTC
func (f *Failure) Delete() error
Delete will remove a failure record from the database
func (*Failure) ParseError
func (f *Failure) ParseError() string
ParseError returns a human readable error for a failure
type Hit struct {
*types.Hit
}
func (s *Hit) AfterFind() (err error)
AfterFind for Hit will set the timezone
func (*Hit) BeforeCreate
func (u *Hit) BeforeCreate() (err error)
BeforeCreate for Hit will set CreatedAt to UTC
type PluginJSON types.PluginJSON
type PluginRepos types.PluginRepos
type Service struct {
*types.Service
}
func ReturnService(s *types.Service) *Service
ReturnService will convert *types.Service to *core.Service
func SelectService(id int64) *Service
SelectService returns a *core.Service from in memory
func (s *Service) AfterFind() (err error)
AfterFind for Service will set the timezone
func (*Service) AllFailures
func (s *Service) AllFailures() []*Failure
AllFailures will return all failures attached to a service
func (s *Service) AvgTime() float64
AvgTime will return the average amount of time for a service to response back successfully
func (s *Service) AvgUptime(ago time.Time) string
AvgUptime returns average online status for last 24 hours
func (*Service) AvgUptime24
func (s *Service) AvgUptime24() string
AvgUptime24 returns a service's average online status for last 24 hours
func (*Service) BeforeCreate
func (u *Service) BeforeCreate() (err error)
BeforeCreate for Service will set CreatedAt to UTC
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 (s *Service) Checkins() []*Checkin
Checkins will return a slice of Checkins for a Service
func (u *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 (s *Service) CreateHit(h *types.Hit) (int64, error)
CreateHit will create a new 'hit' record in the database for a successful/online service
func (u *Service) Delete() error
Delete will remove a service from the database, it will also end the service checking go routine
func (*Service) DeleteFailures
func (u *Service) DeleteFailures()
DeleteFailures will delete all failures for a service
func (s *Service) Downtime() time.Duration
Downtime returns the amount of time of a offline service
func (*Service) DowntimeText
func (s *Service) DowntimeText() string
DowntimeText will return the amount of downtime for a service based on the duration
func (s *Service) GraphData() string
GraphData returns the JSON object used by Charts.js to render the chart
func (s *Service) Hits() ([]*types.Hit, error)
Hits returns all successful hits for a service
func (*Service) HitsBetween
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) 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 (s *Service) Online24() float32
Online24 returns the service's uptime percent within last 24 hours
func (*Service) OnlineSince
func (s *Service) OnlineSince(ago time.Time) float32
OnlineSince accepts a time since parameter to return the percent of a service's uptime.
func (s *Service) Select() *types.Service
Select will return the *types.Service struct for Service
func (s *Service) SmallText() string
SmallText returns a short description about a services status
func (s *Service) Sum() (float64, error)
Sum returns the added value Latency for all of the services successful hits.
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
func (s *Service) TotalFailures24() (uint64, error)
TotalFailures24 returns the amount of failures for a service within the last 24 hours
func (*Service) TotalFailuresSince
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 (s *Service) TotalHits() (uint64, error)
TotalHits returns the total amount of successful hits a service has
func (*Service) TotalHitsSince
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 (u *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
func (u *Service) UpdateSingle(attr ...interface{}) error
UpdateSingle will update a single column for a service
type ServiceOrder []types.ServiceInterface
ServiceOrder will reorder the services based on 'order_id' (Order)
func (c ServiceOrder) Len() int
func (c ServiceOrder) Less(i, j int) bool
func (c ServiceOrder) Swap(i, j int)
type User struct {
*types.User
}
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(u *types.User) *User
ReturnUser returns *core.User based off a *types.User
func SelectAllUsers() ([]*User, error)
SelectAllUsers returns all users
func SelectUser(id int64) (*User, error)
SelectUser returns the User based on the user's ID.
func SelectUsername(username string) (*User, error)
SelectUser returns the User based on the user's username
func (u *User) AfterFind() (err error)
AfterFind for USer will set the timezone
func (*User) BeforeCreate
func (u *User) BeforeCreate() (err error)
BeforeCreate for User will set CreatedAt to UTC
func (u *User) Create() (int64, error)
Create will insert a new user into the database
func (u *User) Delete() error
Delete will remove the user record from the database
func (u *User) Update() error
Update will update the user's record in database
import "github.com/hunterlong/statup/handlers"
Package handlers contains the HTTP server along with the requests and routes. All HTTP related functions are in this package.
More info on: https://github.com/hunterlong/statup
- func DesktopInit(ip string, port int)
- func IsAuthenticated(r *http.Request) bool
- func Router() *mux.Router
- func RunHTTPServer(ip string, port int) error
- type PluginSelect
api.go dashboard.go doc.go handlers.go index.go plugins.go prometheus.go routes.go services.go settings.go setup.go users.go
func DesktopInit(ip string, port int)
func IsAuthenticated(r *http.Request) bool
IsAuthenticated returns true if the HTTP request is authenticated. You can set the environment variable GO_ENV=test to bypass the admin authenticate to the dashboard features.
func Router() *mux.Router
Router returns all of the routes used in Statup
func RunHTTPServer(ip string, port int) error
RunHTTPServer will start a HTTP server on a specific IP and port
type PluginSelect struct {
Plugin string
Form string
Params map[string]interface{}
}
import "github.com/hunterlong/statup/notifiers"
Package notifiers holds all the notifiers for Statup, which also includes user created notifiers that have been accepted in a Push Request. Read the wiki to see a full example of a notifier with all events, visit Statup's notifier example code: https://github.com/hunterlong/statup/wiki/Notifier-Example
This package shouldn't contain any exports, to see how notifiers work visit the core/notifier package at: https://godoc.org/github.com/hunterlong/statup/core/notifier and learn how to create your own custom notifier.
discord.go doc.go email.go line_notify.go slack.go twilio.go webhook.go
import "github.com/hunterlong/statup/plugin"
Package plugin contains the interfaces to build your own Golang Plugin that will receive triggers on Statup events.
- Variables
- func SetDatabase(database *gorm.DB)
- type AdvancedNotifier
- type Database
- type Databaser
- type Info
- type Notifier
- type Plugin
- type PluginDatabase
- type PluginInfo
- type PluginObject
- type Pluginer
- type Router
- type Routing
var (
AllPlugins []*PluginObject
)
var (
DB *gorm.DB
)
func SetDatabase(database *gorm.DB)
type AdvancedNotifier interface {
notifier.Notifier
notifier.BasicEvents
notifier.UserEvents
notifier.CoreEvents
notifier.NotifierEvents
}
type Database *gorm.DB
type Databaser interface {
StatupDatabase(*gorm.DB)
}
type Info struct {
Name string
Description string
Form string
}
type Notifier interface {
notifier.Notifier
notifier.BasicEvents
}
type Plugin struct {
Name string
Description string
}
type PluginDatabase interface {
Database(gorm.DB)
Update() error
}
type PluginInfo struct {
// contains filtered or unexported fields
}
func (p *PluginInfo) Form() string
type PluginObject struct{}
func Add(p Pluginer) *PluginObject
func (p *PluginObject) AddRoute(s string, i string, f http.HandlerFunc)
type Pluginer interface {
Select() *PluginObject
}
type Router interface {
AddRoute(string, string, http.HandlerFunc) error
}
type Routing struct {
URL string
Method string
Handler func(http.ResponseWriter, *http.Request)
}
import "github.com/hunterlong/statup/source"
Package source holds all the assets for Statup. This includes CSS, JS, SCSS, HTML and other website related content. This package uses Rice to compile all assets into a single 'rice-box.go' file.
To compile all the assets run rice embed-go
in the source directory.
More info on: https://github.com/hunterlong/statup
- Variables
- func Assets()
- func CompileSASS(folder string) error
- func CopyToPublic(box *rice.Box, folder, file string) error
- func CreateAllAssets(folder string) error
- func DeleteAllAssets(folder string) error
- func HelpMarkdown() string
- func MakePublicFolder(folder string) error
- func OpenAsset(folder, file string) string
- func SaveAsset(data []byte, folder, file string) error
- func UsingAssets(folder string) bool
var (
CssBox *rice.Box // CSS files from the 'source/css' directory, this will be loaded into '/assets/css'
ScssBox *rice.Box // SCSS files from the 'source/scss' directory, this will be loaded into '/assets/scss'
JsBox *rice.Box // JS files from the 'source/js' directory, this will be loaded into '/assets/js'
TmplBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
)
func Assets()
Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files.
func CompileSASS(folder string) error
CompileSASS will attempt to compile the SASS files into CSS
func CopyToPublic(box *rice.Box, folder, file string) error
CopyToPublic will create a file from a rice Box to the '/assets' directory
func CreateAllAssets(folder string) error
CreateAllAssets will dump HTML, CSS, SCSS, and JS assets into the '/assets' directory
func DeleteAllAssets(folder string) error
DeleteAllAssets will delete the '/assets' folder
func HelpMarkdown() string
HelpMarkdown will return the Markdown of help.md into HTML
func MakePublicFolder(folder string) error
MakePublicFolder will create a new folder
func OpenAsset(folder, file string) string
OpenAsset returns a file's contents as a string
Code:
OpenAsset("js", "main.js")
func SaveAsset(data []byte, folder, file string) error
SaveAsset will save an asset to the '/assets/' folder.
Code:
data := []byte("alert('helloooo')")
SaveAsset(data, "js", "test.js")
func UsingAssets(folder string) bool
UsingAssets returns true if the '/assets' folder is found in the directory
import "github.com/hunterlong/statup/types"
Package types contains all of the structs for objects in Statup including services, hits, failures, Core, and others.
More info on: https://github.com/hunterlong/statup
- Constants
- Variables
- type AllNotifiers
- type Checkin
- type CheckinHit
- type Core
- type CoreInterface
- type DbConfig
- type Failure
- type FailureInterface
- type Hit
- type Info
- type PluginActions
- type PluginInfo
- type PluginJSON
- type PluginRepos
- type Routing
- type Service
- type ServiceInterface
- type User
- type UserInterface
checkin.go core.go doc.go failure.go service.go time.go types.go user.go
const (
TIME_NANOZ = "2006-01-02 15:04:05.999999-0700 MST"
TIME_NANO = "2006-01-02T15:04:05Z"
TIME = "2006-01-02 15:04:05"
TIME_DAY = "2006-01-02"
)
var (
NOW = func() time.Time { return time.Now() }()
HOUR_1_AGO = time.Now().Add(-1 * time.Hour)
HOUR_24_AGO = time.Now().Add(-24 * time.Hour)
HOUR_72_AGO = time.Now().Add(-72 * time.Hour)
DAY_7_AGO = NOW.AddDate(0, 0, -7)
MONTH_1_AGO = NOW.AddDate(0, -1, 0)
YEAR_1_AGO = NOW.AddDate(-1, 0, 0)
)
type AllNotifiers interface{}
type Checkin struct {
Id int64 `gorm:"primary_key;column:id"`
Service int64 `gorm:"index;column:service"`
Interval int64 `gorm:"column:check_interval"`
GracePeriod int64 `gorm:"column:grace_period"`
ApiKey string `gorm:"column:api_key"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
}
type CheckinHit struct {
Id int64 `gorm:"primary_key;column:id"`
Checkin int64 `gorm:"index;column:checkin"`
From string `gorm:"column:from_location"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
}
type Core struct {
Name string `gorm:"not null;column:name" json:"name"`
Description string `gorm:"not null;column:description" json:"description,omitempty"`
Config string `gorm:"column:config" json:"-"`
ApiKey string `gorm:"column:api_key" json:"-"`
ApiSecret string `gorm:"column:api_secret" json:"-"`
Style string `gorm:"not null;column:style" json:"style,omitempty"`
Footer string `gorm:"not null;column:footer" json:"footer,omitempty"`
Domain string `gorm:"not null;column:domain" json:"domain,omitempty"`
Version string `gorm:"column:version" json:"version"`
MigrationId int64 `gorm:"column:migration_id" json:"migration_id,omitempty"`
UseCdn bool `gorm:"column:use_cdn;default:false" json:"using_cdn,omitempty"`
Timezone float32 `gorm:"column:timezone;default:-8.0" json:"timezone,omitempty"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
DbConnection string `gorm:"-" json:"database"`
Started time.Time `gorm:"-" json:"started_on"`
Services []ServiceInterface `gorm:"-" json:"services,omitempty"`
Plugins []Info `gorm:"-" json:"-"`
Repos []PluginJSON `gorm:"-" json:"-"`
AllPlugins []PluginActions `gorm:"-" json:"-"`
Notifications []AllNotifiers `gorm:"-" json:"-"`
CoreInterface `gorm:"-" json:"-"`
}
Core struct contains all the required fields for Statup. All application settings will be saved into 1 row in the 'core' table. You can use the core.CoreApp global variable to interact with the attributes to the application, such as services.
type CoreInterface interface {
SelectAllServices() ([]*Service, error)
Count24HFailures() uint64
ServicesCount() int
CountOnline() int
}
type DbConfig struct {
DbConn string `yaml:"connection"`
DbHost string `yaml:"host"`
DbUser string `yaml:"user"`
DbPass string `yaml:"password"`
DbData string `yaml:"database"`
DbPort int `yaml:"port"`
ApiKey string `yaml:"api_key"`
ApiSecret string `yaml:"api_secret"`
Project string `yaml:"-"`
Description string `yaml:"-"`
Domain string `yaml:"-"`
Username string `yaml:"-"`
Password string `yaml:"-"`
Email string `yaml:"-"`
Error error `yaml:"-"`
Location string `yaml:"location"`
}
DbConfig struct is used for the database connection and creates the 'config.yml' file
type Failure struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Issue string `gorm:"column:issue" json:"issue"`
Method string `gorm:"column:method" json:"method,omitempty"`
Service int64 `gorm:"index;column:service" json:"-"`
PingTime float64 `gorm:"column:ping_time"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
FailureInterface `gorm:"-" json:"-"`
}
Failure is a failed attempt to check a service. Any a service does not meet the expected requirements, a new Failure will be inserted into database.
type FailureInterface interface {
Ago() string // Ago returns a human readble timestamp
ParseError() string // ParseError returns a human readable error for a service failure
}
type Hit struct {
Id int64 `gorm:"primary_key;column:id"`
Service int64 `gorm:"column:service"`
Latency float64 `gorm:"column:latency"`
PingTime float64 `gorm:"column:ping_time"`
CreatedAt time.Time `gorm:"column:created_at"`
}
Hit struct is a 'successful' ping or web response entry for a service.
type Info struct {
Name string
Description string
Form string
}
type PluginActions interface {
GetInfo() Info
GetForm() string
OnLoad(db gorm.DB)
SetInfo(map[string]interface{}) Info
Routes() []Routing
OnSave(map[string]interface{})
OnFailure(map[string]interface{})
OnSuccess(map[string]interface{})
OnSettingsSaved(map[string]interface{})
OnNewUser(map[string]interface{})
OnNewService(map[string]interface{})
OnUpdatedService(map[string]interface{})
OnDeletedService(map[string]interface{})
OnInstall(map[string]interface{})
OnUninstall(map[string]interface{})
OnBeforeRequest(map[string]interface{})
OnAfterRequest(map[string]interface{})
OnShutdown()
}
type PluginInfo struct {
Info Info
PluginActions
}
type PluginJSON struct {
Name string `json:"name"`
Description string `json:"description"`
Repo string `json:"repo"`
Author string `json:"author"`
Namespace string `json:"namespace"`
}
type PluginRepos struct {
Plugins []PluginJSON
}
type Routing struct {
URL string
Method string
Handler func(http.ResponseWriter, *http.Request)
}
type Service struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Name string `gorm:"column:name" json:"name"`
Domain string `gorm:"column:domain" json:"domain"`
Expected string `gorm:"not null;column:expected" json:"expected"`
ExpectedStatus int `gorm:"default:200;column:expected_status" json:"expected_status"`
Interval int `gorm:"default:30;column:check_interval" json:"check_interval"`
Type string `gorm:"column:check_type" json:"type"`
Method string `gorm:"column:method" json:"method"`
PostData string `gorm:"not null;column:post_data" json:"post_data"`
Port int `gorm:"not null;column:port" json:"port"`
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
Order int `gorm:"default:0;column:order_id" json:"order_id"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
Online bool `gorm:"-" json:"online"`
Latency float64 `gorm:"-" json:"latency"`
PingTime float64 `gorm:"-" json:"ping_time"`
Online24Hours float32 `gorm:"-" json:"24_hours_online"`
AvgResponse string `gorm:"-" json:"avg_response"`
Running chan bool `gorm:"-" json:"-"`
Checkpoint time.Time `gorm:"-" json:"-"`
SleepDuration time.Duration `gorm:"-" json:"-"`
LastResponse string `gorm:"-" json:"-"`
LastStatusCode int `gorm:"-" json:"status_code"`
LastOnline time.Time `gorm:"-" json:"last_online"`
Failures []interface{} `gorm:"-" json:"failures,omitempty"`
}
Service is the main struct for Services
func (s *Service) Close()
Close will stop the go routine that is checking if service is online or not
func (s *Service) IsRunning() bool
IsRunning returns true if the service go routine is running
func (s *Service) Start()
Start will create a channel for the service checking go routine
type ServiceInterface interface {
Select() *Service
CheckQueue(bool)
Check(bool)
Create(bool) (int64, error)
Update(bool) error
Delete() error
}
type User struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Username string `gorm:"type:varchar(100);unique;column:username;" json:"username"`
Password string `gorm:"column:password" json:"-"`
Email string `gorm:"type:varchar(100);unique;column:email" json:"-"`
ApiKey string `gorm:"column:api_key" json:"api_key"`
ApiSecret string `gorm:"column:api_secret" json:"-"`
Admin bool `gorm:"column:administrator" json:"admin"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
UserInterface `gorm:"-" json:"-"`
}
type UserInterface interface {
// Database functions
Create() (int64, error)
Update() error
Delete() error
}
import "github.com/hunterlong/statup/utils"
Package utils contains common methods used in most packages in Statup. This package contains multiple function like: Logging, encryption, type conversions, setting utils.Directory as the current directory, running local CMD commands, and creaing/deleting files/folder.
You can overwrite the utils.Directory global variable by including STATUP_DIR environment variable to be an absolute path.
More info on: https://github.com/hunterlong/statup
- Variables
- func Command(cmd string) (string, string, error)
- func DeleteDirectory(directory string) error
- func DeleteFile(file string) error
- func DurationReadable(d time.Duration) string
- func FileExists(name string) bool
- func FormatDuration(d time.Duration) string
- func HashPassword(password string) string
- func Http(r *http.Request) string
- func InitLogs() error
- func Log(level int, err interface{}) error
- func NewSHA1Hash(n ...int) string
- func RandomString(n int) string
- func StringInt(s string) int64
- func Timezoner(t time.Time, zone float32) time.Time
- func ToString(s interface{}) string
- func UnderScoreString(str string) string
- type LogRow
- type Timestamp
- type Timestamper
doc.go encryption.go log.go time.go utils.go
var (
LastLines []*LogRow
LockLines sync.Mutex
)
var (
Directory string
)
func Command(cmd string) (string, string, error)
Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings
func DeleteDirectory(directory string) error
DeleteDirectory will attempt to delete a directory and all contents inside
func DeleteFile(file string) error
DeleteFile will attempt to delete a file
func DurationReadable(d time.Duration) string
func FileExists(name string) bool
FileExists returns true if a file exists
func FormatDuration(d time.Duration) string
func HashPassword(password string) string
HashPassword returns the bcrypt hash of a password string
func Http(r *http.Request) string
Http returns a log for a HTTP request
func InitLogs() error
InitLogs will create the '/logs' directory and creates a file '/logs/statup.log' for application logging
func Log(level int, err interface{}) error
Log creates a new entry in the Logger. Log has 1-5 levels depending on how critical the log/error is
func NewSHA1Hash(n ...int) string
NewSHA1Hash returns a random SHA1 hash based on a specific length
func RandomString(n int) string
RandomString generates a random string of n length
func StringInt(s string) int64
StringInt converts a string to an int64
func Timezoner(t time.Time, zone float32) time.Time
func ToString(s interface{}) string
ToString converts a int to a string
func UnderScoreString(str string) string
UnderScoreString will return a string that replaces spaces and other characters to underscores
type LogRow struct {
Date time.Time
Line interface{}
}
func GetLastLine() *LogRow
GetLastLine returns 1 line for a recent log entry
func (*LogRow) FormatForHtml
func (o *LogRow) FormatForHtml() string
type Timestamp time.Time
func (t Timestamp) Ago() string
Ago returns a human readable timestamp based on the Timestamp (time.Time) interface
type Timestamper interface {
Ago() string
}