statping/dev/README.md

2602 lines
124 KiB
Markdown
Raw Normal View History

2019-02-06 18:51:30 +00:00
This readme is automatically generated from the Golang documentation. [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/hunterlong/statping)
2019-02-06 18:51:30 +00:00
# statping
--
import "github.com/hunterlong/statping"
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
Package statping is a server monitoring application that includs a status page
server. Visit the Statping repo at https://github.com/hunterlong/statping to get
a full understanding of what this application can do.
### Install Statping
Statping is available for Mac, Linux and Windows 64x. You can download the
tar.gz file or use a couple other methods. Download the latest release at
https://github.com/hunterlong/statping/releases/latest or view below. If you're
on windows, download the zip file from the latest releases link.
// MacOS using homebrew
brew tap hunterlong/statping
brew install statping
// Linux installation
bash <(curl -s https://assets.statping.com/install.sh)
statping version
### Docker
Statping can be built in many way, the best way is to use Docker!
docker run -it -p 8080:8080 hunterlong/statping
Enjoy Statping and tell me any issues you might be having on Github.
https://github.com/hunterlong
## Usage
# cmd
--
Package main for building the Statping CLI binary application. This package
connects to all the other packages to make a runnable binary for multiple
operating system.
### Compile Assets
Before building, you must compile the Statping Assets with Rice, to install rice
run the command below:
go get github.com/GeertJohan/go.rice
go get github.com/GeertJohan/go.rice/rice
Once you have rice install, you can run the following command to build all
assets inside the source directory.
cd source && rice embed-go
### Build Statping Binary
To build the statup binary for your local environment, run the command below:
go build -o statup ./cmd
Build All Binary Arch's
To build Statping for Mac, Windows, Linux, and ARM devices, you can run xgo to
build for all. xgo is an awesome golang package that requires Docker.
https://github.com/karalabe/xgo
docker pull karalabe/xgo-latest
build-all
More info on: https://github.com/hunterlong/statping
2018-10-06 09:50:39 +00:00
# core
2019-02-06 18:51:30 +00:00
--
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
## Usage
```go
2018-10-06 09:50:39 +00:00
var (
2019-02-06 18:51:30 +00:00
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
2018-10-06 09:50:39 +00:00
)
```
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
var (
2019-02-06 18:51:30 +00:00
// DbSession stores the Statping database session
DbSession *gorm.DB
DbModels []interface{}
2018-10-06 09:50:39 +00:00
)
```
2019-02-06 18:51:30 +00:00
#### func CheckHash
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func CheckHash(password, hash string) bool
```
CheckHash returns true if the password matches with a hashed bcrypt password
2019-02-06 18:51:30 +00:00
#### func CloseDB
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func CloseDB()
```
CloseDB will close the database connection if available
2019-02-06 18:51:30 +00:00
#### func CountFailures
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func CountFailures() uint64
```
CountFailures returns the total count of failures for all services
2019-02-06 18:51:30 +00:00
#### func CountUsers
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func CountUsers() int64
```
CountUsers returns the amount of users
2019-02-06 18:51:30 +00:00
#### func DatabaseMaintence
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func DatabaseMaintence()
```
2019-02-06 18:51:30 +00:00
DatabaseMaintence will automatically delete old records from 'failures' and
'hits' this function is currently set to delete records 7+ days old every 60
minutes
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func Dbtimestamp
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func Dbtimestamp(group string, column string) string
```
Dbtimestamp will return a SQL query for grouping by date
2019-02-06 18:51:30 +00:00
#### func DefaultPort
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func DefaultPort(db string) int64
```
DefaultPort accepts a database type and returns its default port
2019-02-06 18:51:30 +00:00
#### func DeleteAllSince
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func DeleteAllSince(table string, date time.Time)
```
DeleteAllSince will delete a specific table's records based on a time.
2019-02-06 18:51:30 +00:00
#### func DeleteConfig
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func DeleteConfig() error
2018-10-06 09:50:39 +00:00
```
DeleteConfig will delete the 'config.yml' file
2019-02-06 18:51:30 +00:00
#### func ExportChartsJs
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func ExportChartsJs() string
```
2018-10-07 08:16:38 +00:00
ExportChartsJs renders the charts for the index page
2019-02-06 18:51:30 +00:00
#### func ExportSettings
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func ExportSettings() ([]byte, error)
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
ExportSettings will export a JSON file containing all of the settings below: -
Core - Notifiers - Checkins - Users - Services - Groups - Messages
2018-10-07 08:16:38 +00:00
2019-02-06 18:51:30 +00:00
#### func GetLocalIP
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func GetLocalIP() string
```
GetLocalIP returns the non loopback local IP of the host
2019-02-06 18:51:30 +00:00
#### func InitApp
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func InitApp()
```
2018-12-04 05:57:11 +00:00
InitApp will initialize Statping
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func InsertLargeSampleData
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func InsertLargeSampleData() error
```
2019-02-06 18:51:30 +00:00
InsertLargeSampleData will create the example/dummy services for testing the
Statping server
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func InsertNotifierDB
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func InsertNotifierDB() error
```
2018-12-04 05:57:11 +00:00
InsertNotifierDB inject the Statping database instance to the Notifier package
2019-02-06 18:51:30 +00:00
#### func InsertSampleData
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func InsertSampleData() error
```
2019-02-06 18:51:30 +00:00
InsertSampleData will create the example/dummy services for a brand new Statping
installation
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func InsertSampleHits
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func InsertSampleHits() error
```
InsertSampleHits will create a couple new hits for the sample services
2019-02-06 18:51:30 +00:00
#### func SampleData
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func SampleData() error
```
2018-12-04 05:57:11 +00:00
SampleData runs all the sample data for a new Statping installation
2019-02-06 18:51:30 +00:00
#### func Services
2019-02-06 18:51:30 +00:00
```go
func Services() []types.ServiceInterface
```
2019-02-06 18:51:30 +00:00
#### type Checkin
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
type Checkin struct {
2019-02-06 18:51:30 +00:00
*types.Checkin
2018-10-08 21:15:01 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func AllCheckins
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func AllCheckins() []*Checkin
```
AllCheckins returns all checkin in system
2019-02-06 18:51:30 +00:00
#### func ReturnCheckin
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func ReturnCheckin(c *types.Checkin) *Checkin
```
ReturnCheckin converts *types.Checking to *core.Checkin
2019-02-06 18:51:30 +00:00
#### func SelectCheckin
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func SelectCheckin(api string) *Checkin
```
SelectCheckin will find a Checkin based on the API supplied
2019-02-06 18:51:30 +00:00
#### func (*Checkin) AfterFind
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) AfterFind() (err error)
```
AfterFind for Checkin will set the timezone
2019-02-06 18:51:30 +00:00
#### func (*Checkin) AllFailures
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c *Checkin) AllFailures() []*types.Failure
```
Hits returns all of the CheckinHits for a given Checkin
2019-02-06 18:51:30 +00:00
#### func (*Checkin) AllHits
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c *Checkin) AllHits() []*types.CheckinHit
```
AllHits returns all of the CheckinHits for a given Checkin
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Create
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Create() (int64, error)
```
Create will create a new Checkin
2019-02-06 18:51:30 +00:00
#### func (*Checkin) CreateFailure
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) CreateFailure() (int64, error)
```
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Delete
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Delete() error
```
Create will create a new Checkin
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Expected
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Expected() time.Duration
```
Expected returns the duration of when the serviec should receive a Checkin
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Grace
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Grace() time.Duration
```
2019-02-06 18:51:30 +00:00
Grace will return the duration of the Checkin Grace Period (after service hasn't
responded, wait a bit for a response)
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Last
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c *Checkin) Last() *CheckinHit
2018-10-08 21:15:01 +00:00
```
Last returns the last checkinHit for a Checkin
2019-02-06 18:51:30 +00:00
#### func (*Checkin) LimitedFailures
```go
func (c *Checkin) LimitedFailures(amount int64) []types.FailureInterface
```
Hits returns all of the CheckinHits for a given Checkin
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Checkin) LimitedHits
```go
func (c *Checkin) LimitedHits(amount int64) []*types.CheckinHit
```
LimitedHits will return the last amount of successful hits from a checkin
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Link
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Link() string
```
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Period
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Period() time.Duration
```
Period will return the duration of the Checkin interval
2019-02-06 18:51:30 +00:00
#### func (*Checkin) RecheckCheckinFailure
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) RecheckCheckinFailure(guard chan struct{})
```
RecheckCheckinFailure will check if a Service Checkin has been reported yet
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Routine
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Routine()
```
Routine for checking if the last Checkin was within its interval
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Select
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
func (c *Checkin) Select() *types.Checkin
```
Select returns a *types.Checkin
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Service
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Service() *Service
```
2019-02-06 18:51:30 +00:00
#### func (*Checkin) String
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) String() string
```
String will return a Checkin API string
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Update
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (c *Checkin) Update() (int64, error)
```
Update will update a Checkin
2019-02-06 18:51:30 +00:00
#### type CheckinHit
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
type CheckinHit struct {
2019-02-06 18:51:30 +00:00
*types.CheckinHit
2018-12-04 08:31:22 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func ReturnCheckinHit
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func ReturnCheckinHit(c *types.CheckinHit) *CheckinHit
```
ReturnCheckinHit converts *types.checkinHit to *core.checkinHit
2019-02-06 18:51:30 +00:00
#### func (*CheckinHit) AfterFind
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c *CheckinHit) AfterFind() (err error)
```
AfterFind for checkinHit will set the timezone
2019-02-06 18:51:30 +00:00
#### func (*CheckinHit) Ago
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c *CheckinHit) Ago() string
```
Ago returns the duration of time between now and the last successful checkinHit
2019-02-06 18:51:30 +00:00
#### func (*CheckinHit) Create
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c *CheckinHit) Create() (int64, error)
```
Create will create a new successful checkinHit
2019-02-06 18:51:30 +00:00
#### type Core
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type Core struct {
2019-02-06 18:51:30 +00:00
*types.Core
2018-10-06 09:50:39 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func NewCore
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func NewCore() *Core
```
NewCore return a new *core.Core struct
2019-02-06 18:51:30 +00:00
#### func SelectCore
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func SelectCore() (*Core, error)
```
2019-02-06 18:51:30 +00:00
SelectCore will return the CoreApp global variable and the settings/configs for
Statping
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func UpdateCore
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func UpdateCore(c *Core) (*Core, error)
```
2019-02-06 18:51:30 +00:00
UpdateCore will update the CoreApp variable inside of the 'core' table in
database
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Core) AfterFind
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c *Core) AfterFind() (err error)
```
AfterFind for Core will set the timezone
2019-02-06 18:51:30 +00:00
#### func (Core) AllOnline
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c Core) AllOnline() bool
```
AllOnline will be true if all services are online
2019-02-06 18:51:30 +00:00
#### func (Core) BaseSASS
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c Core) BaseSASS() string
```
2019-02-06 18:51:30 +00:00
BaseSASS is the base design , this opens the file /assets/scss/base.scss to be
edited in Theme
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Core) Count24HFailures
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c *Core) Count24HFailures() uint64
```
2019-02-06 18:51:30 +00:00
Count24HFailures returns the amount of failures for a service within the last 24
hours
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Core) CountOnline
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c *Core) CountOnline() int
```
2019-02-06 18:51:30 +00:00
CountOnline returns the amount of services online
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (Core) CurrentTime
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c Core) CurrentTime() string
```
2018-10-08 21:15:01 +00:00
CurrentTime will return the current local time
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (Core) Messages
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (c Core) Messages() []*Message
```
Messages will return the current local time
2019-02-06 18:51:30 +00:00
#### func (Core) MobileSASS
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c Core) MobileSASS() string
```
2019-02-06 18:51:30 +00:00
MobileSASS is the -webkit responsive custom css designs. This opens the file
/assets/scss/mobile.scss to be edited in Theme
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (Core) SassVars
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c Core) SassVars() string
```
SassVars opens the file /assets/scss/variables.scss to be edited in Theme
2019-02-06 18:51:30 +00:00
#### func (*Core) SelectAllServices
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (c *Core) SelectAllServices(start bool) ([]*Service, error)
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
SelectAllServices returns a slice of *core.Service to be store on
[]*core.Services, should only be called once on startup.
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Core) ToCore
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c *Core) ToCore() *types.Core
```
ToCore will convert *core.Core to *types.Core
2019-02-06 18:51:30 +00:00
#### func (Core) UsingAssets
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c Core) UsingAssets() bool
```
UsingAssets will return true if /assets folder is present
2019-02-06 18:51:30 +00:00
#### type DateScan
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type DateScan struct {
2019-02-06 18:51:30 +00:00
CreatedAt string `json:"x,omitempty"`
Value int64 `json:"y"`
2018-10-06 09:50:39 +00:00
}
```
2019-02-06 18:51:30 +00:00
DateScan struct is for creating the charts.js graph JSON array
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### type DateScanObj
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type DateScanObj struct {
2019-02-06 18:51:30 +00:00
Array []DateScan `json:"data"`
2018-10-06 09:50:39 +00:00
}
```
2019-02-06 18:51:30 +00:00
DateScanObj struct is for creating the charts.js graph JSON array
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func GraphDataRaw
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
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
2019-02-06 18:51:30 +00:00
#### func (*DateScanObj) ToString
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (d *DateScanObj) ToString() string
```
2019-02-06 18:51:30 +00:00
ToString will convert the DateScanObj into a JSON string for the charts to
render
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### type DbConfig
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type DbConfig types.DbConfig
```
2019-02-06 18:51:30 +00:00
DbConfig stores the config.yml file for the statup configuration
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func EnvToConfig
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func EnvToConfig() *DbConfig
```
EnvToConfig converts environment variables to a DbConfig variable
2019-02-06 18:51:30 +00:00
#### func LoadConfigFile
2019-02-06 18:51:30 +00:00
```go
func LoadConfigFile(directory string) (*DbConfig, error)
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
LoadConfigFile will attempt to load the 'config.yml' file in a specific
directory
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func LoadUsingEnv
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func LoadUsingEnv() (*DbConfig, error)
```
2019-02-06 18:51:30 +00:00
LoadUsingEnv will attempt to load database configs based on environment
variables. If DB_CONN is set if will force this function.
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) Connect
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (db *DbConfig) Connect(retry bool, location string) error
```
Connect will attempt to connect to the sqlite, postgres, or mysql database
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) CreateCore
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c *DbConfig) CreateCore() *Core
```
2019-02-06 18:51:30 +00:00
CreateCore will initialize the global variable 'CoreApp". This global variable
contains most of Statping app.
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) CreateDatabase
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (db *DbConfig) CreateDatabase() error
```
2018-12-04 05:57:11 +00:00
CreateDatabase will CREATE TABLES for each of the Statping elements
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) DropDatabase
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (db *DbConfig) DropDatabase() error
```
2018-12-04 05:57:11 +00:00
DropDatabase will DROP each table Statping created
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) InsertCore
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (db *DbConfig) InsertCore() (*Core, error)
```
2018-12-04 05:57:11 +00:00
InsertCore create the single row for the Core settings in Statping
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) MigrateDatabase
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (db *DbConfig) MigrateDatabase() error
```
2019-02-06 18:51:30 +00:00
MigrateDatabase will migrate the database structure to current version. This
function will NOT remove previous records, tables or columns from the database.
2018-10-06 09:50:39 +00:00
If this function has an issue, it will ROLLBACK to the previous state.
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) Save
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-07 08:16:38 +00:00
func (db *DbConfig) Save() (*DbConfig, error)
2018-10-06 09:50:39 +00:00
```
Save will initially create the config.yml file
2019-02-06 18:51:30 +00:00
#### func (*DbConfig) Update
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-07 08:16:38 +00:00
func (db *DbConfig) Update() error
2018-10-06 09:50:39 +00:00
```
Update will save the config.yml file
2019-02-06 18:51:30 +00:00
#### type ErrorResponse
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type ErrorResponse struct {
2019-02-06 18:51:30 +00:00
Error string
2018-10-06 09:50:39 +00:00
}
```
2019-02-06 18:51:30 +00:00
ErrorResponse is used for HTTP errors to show to User
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### type ExportData
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
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"`
}
```
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### type Failure
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
type Failure struct {
*types.Failure
}
```
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Failure) AfterFind
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (f *Failure) AfterFind() (err error)
```
AfterFind for Failure will set the timezone
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Failure) Ago
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
func (f *Failure) Ago() string
2018-12-04 08:31:22 +00:00
```
2019-02-06 18:51:30 +00:00
Ago returns a human readable timestamp for a Failure
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Failure) Delete
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
func (f *Failure) Delete() error
```
Delete will remove a Failure record from the database
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Failure) ParseError
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
func (f *Failure) ParseError() string
```
ParseError returns a human readable error for a Failure
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Failure) Select
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
func (f *Failure) Select() *types.Failure
```
Select returns a *types.Failure
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### type Group
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
type Group struct {
*types.Group
2018-10-06 09:50:39 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func SelectGroup
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func SelectGroup(id int64) *Group
```
SelectGroup returns a *core.Group
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func SelectGroups
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func SelectGroups(includeAll bool, auth bool) []*Group
```
SelectGroups returns all groups
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Group) Create
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (g *Group) Create() (int64, error)
```
Create will create a group and insert it into the database
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Group) Delete
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (g *Group) Delete() error
2018-12-04 08:31:22 +00:00
```
2019-02-06 18:51:30 +00:00
Delete will remove a group
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Group) Services
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
func (g *Group) Services() []*Service
```
Services returns all services belonging to a group
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### type Hit
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
type Hit struct {
*types.Hit
}
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
#### func (*Hit) AfterFind
```go
func (h *Hit) AfterFind() (err error)
```
AfterFind for Hit will set the timezone
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### type Message
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
type Message struct {
2019-02-06 18:51:30 +00:00
*types.Message
2018-11-07 09:33:51 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func ReturnMessage
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func ReturnMessage(m *types.Message) *Message
```
ReturnMessage will convert *types.Message to *core.Message
2019-02-06 18:51:30 +00:00
#### func SelectMessage
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func SelectMessage(id int64) (*Message, error)
```
SelectMessage returns a Message based on the ID passed
2019-02-06 18:51:30 +00:00
#### func SelectMessages
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func SelectMessages() ([]*Message, error)
```
SelectMessages returns all messages
2019-02-06 18:51:30 +00:00
#### func SelectServiceMessages
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func SelectServiceMessages(id int64) []*Message
```
SelectServiceMessages returns all messages for a service
2019-02-06 18:51:30 +00:00
#### func (*Message) AfterFind
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (u *Message) AfterFind() (err error)
```
AfterFind for Message will set the timezone
2019-02-06 18:51:30 +00:00
#### func (*Message) Create
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (m *Message) Create() (int64, error)
```
Create will create a Message and insert it into the database
2019-02-06 18:51:30 +00:00
#### func (*Message) Delete
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (m *Message) Delete() error
```
Delete will delete a Message from database
2019-02-06 18:51:30 +00:00
#### func (*Message) Service
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (m *Message) Service() *Service
```
2019-02-06 18:51:30 +00:00
#### func (*Message) Update
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (m *Message) Update() (*Message, error)
```
Update will update a Message in the database
2019-02-06 18:51:30 +00:00
#### type PluginJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type PluginJSON types.PluginJSON
```
2019-02-06 18:51:30 +00:00
#### type PluginRepos
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type PluginRepos types.PluginRepos
```
2019-02-06 18:51:30 +00:00
#### type Service
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type Service struct {
2019-02-06 18:51:30 +00:00
*types.Service
2018-10-06 09:50:39 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func ReturnService
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func ReturnService(s *types.Service) *Service
```
ReturnService will convert *types.Service to *core.Service
2019-02-06 18:51:30 +00:00
#### func SelectService
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func SelectService(id int64) *Service
```
SelectService returns a *core.Service from in memory
2019-02-06 18:51:30 +00:00
#### func SelectServiceLink
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func SelectServiceLink(permalink string) *Service
```
SelectServiceLink returns a *core.Service from the service permalink
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) ActiveMessages
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (s *Service) ActiveMessages() []*Message
```
2019-02-06 18:51:30 +00:00
ActiveMessages returns all service messages that are available based on the
current time
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) AfterFind
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) AfterFind() (err error)
```
AfterFind for Service will set the timezone
2019-02-06 18:51:30 +00:00
#### func (*Service) AllCheckins
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) AllCheckins() []*Checkin
```
AllCheckins will return a slice of AllCheckins for a Service
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) AllFailures
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) AllFailures() []*Failure
2018-10-06 09:50:39 +00:00
```
AllFailures will return all failures attached to a service
2019-02-06 18:51:30 +00:00
#### func (*Service) AvgTime
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) AvgTime() string
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
AvgTime will return the average amount of time for a service to response back
successfully
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) AvgUptime
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) AvgUptime(ago time.Time) string
```
AvgUptime returns average online status for last 24 hours
2019-02-06 18:51:30 +00:00
#### func (*Service) AvgUptime24
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) AvgUptime24() string
```
AvgUptime24 returns a service's average online status for last 24 hours
2019-02-06 18:51:30 +00:00
#### func (*Service) Check
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) Check(record bool)
```
Check will run checkHttp for HTTP services and checkTcp for TCP services
2019-02-06 18:51:30 +00:00
#### func (*Service) CheckQueue
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) CheckQueue(record bool)
```
CheckQueue is the main go routine for checking a service
2019-02-06 18:51:30 +00:00
#### func (*Service) CheckinProcess
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (s *Service) CheckinProcess()
```
CheckinProcess runs the checkin routine for each checkin attached to service
2019-02-06 18:51:30 +00:00
#### func (*Service) CountHits
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
func (s *Service) CountHits() (int64, error)
```
CountHits returns a int64 for all hits for a service
2019-02-06 18:51:30 +00:00
#### func (*Service) Create
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-07 08:16:38 +00:00
func (s *Service) Create(check bool) (int64, error)
2018-10-06 09:50:39 +00:00
```
Create will create a service and insert it into the database
2019-02-06 18:51:30 +00:00
#### func (*Service) CreateFailure
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-10 03:42:32 +00:00
func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error)
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
CreateFailure will create a new Failure record for a service
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) CreateHit
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) CreateHit(h *types.Hit) (int64, error)
```
2019-02-06 18:51:30 +00:00
CreateHit will create a new 'hit' record in the database for a successful/online
service
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) Delete
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-07 08:16:38 +00:00
func (s *Service) Delete() error
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
Delete will remove a service from the database, it will also end the service
checking go routine
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) DeleteFailures
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-07 08:16:38 +00:00
func (s *Service) DeleteFailures()
2018-10-06 09:50:39 +00:00
```
DeleteFailures will delete all failures for a service
2019-02-06 18:51:30 +00:00
#### func (*Service) Downtime
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) Downtime() time.Duration
```
Downtime returns the amount of time of a offline service
2019-02-06 18:51:30 +00:00
#### func (*Service) DowntimeText
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) DowntimeText() string
```
2019-02-06 18:51:30 +00:00
DowntimeText will return the amount of downtime for a service based on the
duration
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
service.DowntimeText()
// Service has been offline for 15 minutes
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) FailuresDaysAgo
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) FailuresDaysAgo(days int) uint64
```
FailuresDaysAgo returns the amount of failures since days ago
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) Hits
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) Hits() ([]*types.Hit, error)
```
Hits returns all successful hits for a service
2019-02-06 18:51:30 +00:00
#### func (*Service) HitsBetween
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) HitsBetween(t1, t2 time.Time, group string, column string) *gorm.DB
```
2019-02-06 18:51:30 +00:00
HitsBetween returns the gorm database query for a collection of service hits
between a time range
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) LimitedCheckinFailures
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) LimitedCheckinFailures(amount int64) []*Failure
2018-12-04 08:31:22 +00:00
```
LimitedFailures will return the last amount of failures from a service
2019-02-06 18:51:30 +00:00
#### func (*Service) LimitedFailures
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) LimitedFailures(amount int64) []*Failure
2018-10-06 09:50:39 +00:00
```
2018-11-10 03:42:32 +00:00
LimitedFailures will return the last amount of failures from a service
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) LimitedHits
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) LimitedHits(amount int64) ([]*types.Hit, error)
2018-10-06 09:50:39 +00:00
```
LimitedHits returns the last 1024 successful/online 'hit' records for a service
2019-02-06 18:51:30 +00:00
#### func (*Service) Messages
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (s *Service) Messages() []*Message
```
Messages returns all Messages for a Service
2019-02-06 18:51:30 +00:00
#### func (*Service) OnlineDaysPercent
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) OnlineDaysPercent(days int) float32
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
OnlineDaysPercent returns the service's uptime percent within last 24 hours
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) OnlineSince
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) OnlineSince(ago time.Time) float32
```
2019-02-06 18:51:30 +00:00
OnlineSince accepts a time since parameter to return the percent of a service's
uptime.
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) Select
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) Select() *types.Service
```
Select will return the *types.Service struct for Service
2019-02-06 18:51:30 +00:00
#### func (*Service) SmallText
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) SmallText() string
```
SmallText returns a short description about a services status
2019-02-06 18:51:30 +00:00
service.SmallText()
// Online since Monday 3:04:05PM, Jan _2 2006
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) SparklineDayFailures
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) SparklineDayFailures(days int) string
```
SparklineDayFailures returns a string array of daily service failures
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) SparklineHourResponse
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) SparklineHourResponse(hours int, method string) string
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
SparklineHourResponse returns a string array for the average response or ping
time for a service
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) Sum
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) Sum() float64
```
Sum returns the added value Latency for all of the services successful hits.
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) ToJSON
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) ToJSON() string
```
ToJSON will convert a service to a JSON string
2019-02-06 18:51:30 +00:00
#### func (*Service) TotalFailures
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) TotalFailures() (uint64, error)
```
TotalFailures returns the total amount of failures for a service
2019-02-06 18:51:30 +00:00
#### func (*Service) TotalFailures24
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) TotalFailures24() (uint64, error)
```
2019-02-06 18:51:30 +00:00
TotalFailures24 returns the amount of failures for a service within the last 24
hours
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) TotalFailuresOnDate
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) TotalFailuresOnDate(ago time.Time) (uint64, error)
```
TotalFailuresOnDate returns the total amount of failures for a service on a
specific time/date
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) TotalFailuresSince
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) TotalFailuresSince(ago time.Time) (uint64, error)
```
2019-02-06 18:51:30 +00:00
TotalFailuresSince returns the total amount of failures for a service since a
specific time/date
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) TotalHits
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) TotalHits() (uint64, error)
```
TotalHits returns the total amount of successful hits a service has
2019-02-06 18:51:30 +00:00
#### func (*Service) TotalHitsSince
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) TotalHitsSince(ago time.Time) (uint64, error)
```
TotalHitsSince returns the total amount of hits based on a specific time/date
2019-02-06 18:51:30 +00:00
#### func (*Service) TotalUptime
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (s *Service) TotalUptime() string
```
TotalUptime returns the total uptime percent of a service
2019-02-06 18:51:30 +00:00
#### func (*Service) Update
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-07 08:16:38 +00:00
func (s *Service) Update(restart bool) error
2018-10-06 09:50:39 +00:00
```
2019-02-06 18:51:30 +00:00
Update will update a service in the database, the service's checking routine can
be restarted by passing true
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### type ServiceOrder
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
type ServiceOrder []types.ServiceInterface
```
2019-02-06 18:51:30 +00:00
ServiceOrder will reorder the services based on 'order_id' (Order)
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (ServiceOrder) Len
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c ServiceOrder) Len() int
```
2018-10-08 21:15:01 +00:00
Sort interface for resroting the Services in order
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
#### func (ServiceOrder) Less
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c ServiceOrder) Less(i, j int) bool
```
2019-02-06 18:51:30 +00:00
#### func (ServiceOrder) Swap
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 09:50:39 +00:00
func (c ServiceOrder) Swap(i, j int)
```
2019-02-06 18:51:30 +00:00
#### type User
2018-10-06 09:50:39 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
type User struct {
2019-02-06 18:51:30 +00:00
*types.User
2018-12-04 08:31:22 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func AuthUser
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
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
2019-02-06 18:51:30 +00:00
#### func ReturnUser
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func ReturnUser(u *types.User) *User
```
ReturnUser returns *core.User based off a *types.User
2019-02-06 18:51:30 +00:00
#### func SelectAllUsers
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func SelectAllUsers() ([]*User, error)
```
SelectAllUsers returns all users
2019-02-06 18:51:30 +00:00
#### func SelectUser
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func SelectUser(id int64) (*User, error)
```
SelectUser returns the User based on the User's ID.
2019-02-06 18:51:30 +00:00
#### func SelectUsername
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func SelectUsername(username string) (*User, error)
```
SelectUsername returns the User based on the User's username
2019-02-06 18:51:30 +00:00
#### func (*User) AfterFind
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (u *User) AfterFind() (err error)
```
AfterFind for USer will set the timezone
2019-02-06 18:51:30 +00:00
#### func (*User) Create
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (u *User) Create() (int64, error)
```
Create will insert a new User into the database
2019-02-06 18:51:30 +00:00
#### func (*User) Delete
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (u *User) Delete() error
```
Delete will remove the User record from the database
2019-02-06 18:51:30 +00:00
#### func (*User) Update
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (u *User) Update() error
```
Update will update the User's record in database
2018-10-06 10:07:34 +00:00
# handlers
2019-02-06 18:51:30 +00:00
--
import "github.com/hunterlong/statping/handlers"
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
Package handlers contains the HTTP server along with the requests and routes.
All HTTP related functions are in this package.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
More info on: https://github.com/hunterlong/statping
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
## Usage
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func ExecuteResponse
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}, redirect interface{})
```
ExecuteResponse will render a HTTP response for the front end user
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func IsAdmin
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func IsAdmin(r *http.Request) bool
```
IsAdmin returns true if the user session is an administrator
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func IsFullAuthenticated
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func IsFullAuthenticated(r *http.Request) bool
2018-10-06 10:07:34 +00:00
```
2019-02-06 18:51:30 +00:00
IsFullAuthenticated 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.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func IsReadAuthenticated
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func IsReadAuthenticated(r *http.Request) bool
2018-12-04 08:31:22 +00:00
```
2019-02-06 18:51:30 +00:00
IsReadAuthenticated will allow Read Only authentication for some routes
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### func IsUser
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
func IsUser(r *http.Request) bool
2018-10-06 10:07:34 +00:00
```
2019-02-06 18:51:30 +00:00
IsUser returns true if the user is registered
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func Router
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func Router() *mux.Router
```
2019-02-06 18:51:30 +00:00
Router returns all of the routes used in Statping. Server will use static assets
if the 'assets' directory is found in the root directory.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func RunHTTPServer
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func RunHTTPServer(ip string, port int) error
```
RunHTTPServer will start a HTTP server on a specific IP and port
2019-02-06 18:51:30 +00:00
#### type Cacher
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
type Cacher interface {
2019-02-06 18:51:30 +00:00
Get(key string) []byte
Delete(key string)
Set(key string, content []byte, duration time.Duration)
List() map[string]Item
2018-11-02 23:19:52 +00:00
}
```
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
var CacheStorage Cacher
```
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
#### type Item
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
type Item struct {
2019-02-06 18:51:30 +00:00
Content []byte
Expiration int64
2018-11-02 23:19:52 +00:00
}
```
2019-02-06 18:51:30 +00:00
Item is a cached reference
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
#### func (Item) Expired
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
func (item Item) Expired() bool
```
Expired returns true if the item has expired.
2019-02-06 18:51:30 +00:00
#### type PluginSelect
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type PluginSelect struct {
2019-02-06 18:51:30 +00:00
Plugin string
Form string
Params map[string]interface{}
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type Storage
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
type Storage struct {
}
```
2019-02-06 18:51:30 +00:00
Storage mecanism for caching strings in memory
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
#### func NewStorage
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
func NewStorage() *Storage
```
2018-11-07 09:33:51 +00:00
NewStorage creates a new in memory CacheStorage
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
#### func (Storage) Delete
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (s Storage) Delete(key string)
```
2019-02-06 18:51:30 +00:00
#### func (Storage) Get
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
func (s Storage) Get(key string) []byte
```
Get a cached content by key
2019-02-06 18:51:30 +00:00
#### func (Storage) List
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s Storage) List() map[string]Item
```
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
#### func (Storage) Set
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-02 23:19:52 +00:00
func (s Storage) Set(key string, content []byte, duration time.Duration)
```
Set a cached content by key
2019-02-06 18:51:30 +00:00
# notifiers
--
import "github.com/hunterlong/statping/notifiers"
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
Package notifiers holds all the notifiers for Statping, 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 Statping's notifier
example code: https://github.com/hunterlong/statping/wiki/Notifier-Example
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
This package shouldn't contain any exports, to see how notifiers work visit the
core/notifier package at:
https://godoc.org/github.com/hunterlong/statping/core/notifier and learn how to
create your own custom notifier.
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
## Usage
2018-11-02 23:19:52 +00:00
2019-02-06 18:51:30 +00:00
#### type MobileResponse
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
type MobileResponse struct {
Counts int `json:"counts"`
Logs []*MobileResponseLogs `json:"logs"`
Success string `json:"success"`
}
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type MobileResponseLogs
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
type MobileResponseLogs struct {
Type string `json:"type"`
Platform string `json:"platform"`
Token string `json:"token"`
Message string `json:"message"`
Error string `json:"error"`
}
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type PushArray
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
type PushArray struct {
Tokens []string `json:"tokens"`
Platform int64 `json:"platform"`
Message string `json:"message"`
Topic string `json:"topic"`
Title string `json:"title,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
}
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type PushNotification
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
type PushNotification struct {
Array []*PushArray `json:"notifications"`
}
```
# plugin
--
import "github.com/hunterlong/statping/plugin"
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
Package plugin contains the interfaces to build your own Golang Plugin that will
receive triggers on Statping events.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
## Usage
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
var (
AllPlugins []*types.PluginObject
)
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func LoadPlugin
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func LoadPlugin(file string) error
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func LoadPlugins
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func LoadPlugins()
```
# source
--
import "github.com/hunterlong/statping/source"
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
Package source holds all the assets for Statping. 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.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
### Required Dependencies
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
- rice -> https://github.com/GeertJohan/go.rice - sass ->
https://sass-lang.com/install
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
### Compile Assets
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
To compile all the HTML, JS, SCSS, CSS and image assets you'll need to have rice
and sass installed on your local system.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
sass source/scss/base.scss source/css/base.css
cd source && rice embed-go
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
More info on: https://github.com/hunterlong/statping
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
Code generated by go generate; DO NOT EDIT. This file was generated by robots at
2019-02-06 21:08:01 +00:00
2019-02-06 12:42:08.202468 -0800 PST m=+0.598756678
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
This contains the most recently Markdown source for the Statping Wiki.
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
## Usage
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
```go
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'
FontBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
)
```
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
```go
var CompiledWiki = []byte("<a class=\"scrollclick\" href=\"#\" data-id=\"page_0\">Types of Monitoring</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_1\">Features</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_2\">Start Statping</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_3\">Linux</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_4\">Mac</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_5\">Windows</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_6\">AWS EC2</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_7\">Docker</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_8\">Mobile App</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_9\">Heroku</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_10\">API</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_11\">Makefile</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_12\">Notifiers</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_13\">Notifier Events</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_14\">Notifier Example</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_15\">Prometheus Exporter</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_16\">SSL</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_17\">Config with .env File</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_18\">Static Export</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_19\">Statping Plugins</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_20\">Statuper</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_21\">Build and Test</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_22\">Contributing</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_23\">PGP Signature</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_24\">Testing</a><br><a class=\"scrollclick\" href=\"#\" data-id=\"page_25\">Deployment</a><br>\n\n<div class=\"mt-5\" id=\"page_0\"><h1>Types of Monitoring</h1></div>\nYou can monitor your application by using a simple HTTP GET to the endpoint to return back a response and status code. Normally you want a 200 status code on an HTTP request. You might want to require a 404 or 500 error as a response code though. With each service you can include a Timeout in seconds to work with your long running services.\n\n# HTTP Endpoints with Custom POST\nFor more advanced monitoring you can add a data as a HTTP POST request. This is useful for automatically submitting JSON, or making sure your signup form is working correctly.\n\n<p align=\"center\">\n<img width=\"100%\" src=\"https://img.cjx.io/statup-httpservice.png\">\n</p>\n\nWith a HTTP service, you can POST a JSON string to your endpoint to retrieve any type of response back. You can then use Regex in the Expected Response field to parse a custom response that exactly matches your status requirements. \n\n# TCP Services\nFor other services that don't use HTTP, you can monitor any type of service by using the PORT of the service. If you're Ethereum Blockchain server is running on 8545, you can use TCP to monitor your server. With a TCP service, you can monitor your Docker containers, or remove service running on a custom port. You don't need to include `http` in the endpoint field, just IP or Hostname.\n\n<p align=\"center\">\n<img width=\"100%\" src=\"https://img.cjx.io/statup-tcpservice.png\">\n</p>\n\n\n<div class=\"mt-5\" id=\"page_1\"><h1>Features</h1></div>\nStatping is a great Status Page that can be deployed with 0 effort.\n\n# 3 Different Databases\nYou can use MySQL, Postgres, or SQLite as a database for your Statping status page. The server will automatically upgrade your database tables depending on which database you have.\n\n# Easy to Startup\nStatping is an extremely easy to setup website monitoring tool without fussing with dependencies or packages. Simply download and install the precompile binary for your operating system. Statping works on Windows, Mac, Linux, Docker, and even the Raspberry Pi.\n\n# Plugins\nStatping is an awesome Stat
```
CompiledWiki contains all of the Statping Wiki pages from the Github Wiki repo.
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
#### func Assets
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
```go
func Assets()
```
Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files.
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
#### func CompileSASS
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
```go
func CompileSASS(folder string) error
```
CompileSASS will attempt to compile the SASS files into CSS
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
#### func CopyAllToPublic
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
```go
func CopyAllToPublic(box *rice.Box, folder string) error
2018-10-06 10:11:36 +00:00
```
2019-02-06 18:51:30 +00:00
CopyAllToPublic will copy all the files in a rice box into a local folder
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
#### func CopyToPublic
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
```go
func CopyToPublic(box *rice.Box, folder, file string) error
2018-10-06 10:11:36 +00:00
```
2019-02-06 18:51:30 +00:00
CopyToPublic will create a file from a rice Box to the '/assets' directory
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
#### func CreateAllAssets
2018-10-06 10:11:36 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func CreateAllAssets(folder string) error
```
2019-02-06 18:51:30 +00:00
CreateAllAssets will dump HTML, CSS, SCSS, and JS assets into the '/assets'
directory
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func DeleteAllAssets
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func DeleteAllAssets(folder string) error
```
DeleteAllAssets will delete the '/assets' folder
2019-02-06 18:51:30 +00:00
#### func HelpMarkdown
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func HelpMarkdown() string
```
HelpMarkdown will return the Markdown of help.md into HTML
2019-02-06 18:51:30 +00:00
#### func MakePublicFolder
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func MakePublicFolder(folder string) error
```
MakePublicFolder will create a new folder
2019-02-06 18:51:30 +00:00
#### func OpenAsset
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func OpenAsset(folder, file string) string
```
OpenAsset returns a file's contents as a string
2019-02-06 18:51:30 +00:00
#### func SaveAsset
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func SaveAsset(data []byte, folder, file string) error
```
SaveAsset will save an asset to the '/assets/' folder.
2019-02-06 18:51:30 +00:00
#### func UsingAssets
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func UsingAssets(folder string) bool
```
UsingAssets returns true if the '/assets' folder is found in the directory
2019-02-06 18:51:30 +00:00
# types
--
import "github.com/hunterlong/statping/types"
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
Package types contains all of the structs for objects in Statping including
services, hits, failures, Core, and others.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
More info on: https://github.com/hunterlong/statping
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
## Usage
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
const (
2019-02-06 18:51:30 +00:00
TIME_NANO = "2006-01-02T15:04:05Z"
TIME = "2006-01-02 15:04:05"
POSTGRES_TIME = "2006-01-02 15:04"
CHART_TIME = "2006-01-02T15:04:05.999999-07:00"
TIME_DAY = "2006-01-02"
2018-10-06 10:07:34 +00:00
)
```
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
var (
2019-02-06 18:51:30 +00:00
NOW = func() time.Time { return time.Now() }()
2018-10-06 10:07:34 +00:00
)
```
2019-02-06 18:51:30 +00:00
#### type AllNotifiers
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type AllNotifiers interface{}
```
2019-02-06 18:51:30 +00:00
AllNotifiers contains all the Notifiers loaded
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type Asseter
2018-10-07 08:16:38 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type Asseter interface {
2019-02-06 18:51:30 +00:00
Asset(string) ([]byte, error)
2018-10-11 02:45:45 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type Checkin
2018-10-11 02:45:45 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Checkin struct {
2019-02-06 18:51:30 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
ServiceId int64 `gorm:"index;column:service" json:"service_id"`
Name string `gorm:"column:name" json:"name"`
Interval int64 `gorm:"column:check_interval" json:"interval"`
GracePeriod int64 `gorm:"column:grace_period" json:"grace"`
ApiKey string `gorm:"column:api_key" json:"api_key"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
Running chan bool `gorm:"-" json:"-"`
Failing bool `gorm:"-" json:"failing"`
LastHit time.Time `gorm:"-" json:"last_hit"`
Hits []*CheckinHit `gorm:"-" json:"hits"`
Failures []FailureInterface `gorm:"-" json:"failures"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
Checkin struct will allow an application to send a recurring HTTP GET to confirm
a service is online
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Checkin) BeforeCreate
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func (c *Checkin) BeforeCreate() (err error)
```
BeforeCreate for Checkin will set CreatedAt to UTC
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Close
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (s *Checkin) Close()
```
Close will stop the checkin routine
2019-02-06 18:51:30 +00:00
#### func (*Checkin) IsRunning
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (s *Checkin) IsRunning() bool
```
IsRunning returns true if the checkin go routine is running
2019-02-06 18:51:30 +00:00
#### func (*Checkin) Start
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-08 21:15:01 +00:00
func (s *Checkin) Start()
```
Start will create a channel for the checkin checking go routine
2019-02-06 18:51:30 +00:00
#### type CheckinHit
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type CheckinHit struct {
2019-02-06 18:51:30 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
Checkin int64 `gorm:"index;column:checkin" json:"-"`
From string `gorm:"column:from_location" json:"from"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
CheckinHit is a successful response from a Checkin
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*CheckinHit) BeforeCreate
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func (c *CheckinHit) BeforeCreate() (err error)
```
BeforeCreate for checkinHit will set CreatedAt to UTC
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type CheckinInterface
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
type CheckinInterface interface {
Select() *Checkin
}
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type Core
2018-10-07 08:16:38 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Core struct {
2019-02-06 18:51:30 +00:00
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 NullString `gorm:"column:footer" json:"footer"`
Domain string `gorm:"not null;column:domain" json:"domain"`
Version string `gorm:"column:version" json:"version"`
MigrationId int64 `gorm:"column:migration_id" json:"migration_id,omitempty"`
UseCdn NullBool `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:"-"`
Plugins []*Info `gorm:"-" json:"-"`
Repos []PluginJSON `gorm:"-" json:"-"`
AllPlugins []PluginActions `gorm:"-" json:"-"`
Notifications []AllNotifiers `gorm:"-" json:"-"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
Core struct contains all the required fields for Statping. 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.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type Databaser
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type Databaser interface {
2019-02-06 18:51:30 +00:00
StatpingDatabase(*gorm.DB)
2018-10-11 02:45:45 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type DbConfig
2018-10-11 02:45:45 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type DbConfig struct {
2019-02-06 18:51:30 +00:00
DbConn string `yaml:"connection"`
DbHost string `yaml:"host"`
DbUser string `yaml:"user"`
DbPass string `yaml:"password"`
DbData string `yaml:"database"`
DbPort int64 `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"`
LocalIP string `yaml:"-"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
DbConfig struct is used for the database connection and creates the 'config.yml'
file
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type FailSort
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
type FailSort []FailureInterface
```
2019-02-06 18:51:30 +00:00
#### func (FailSort) Len
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (s FailSort) Len() int
```
2019-02-06 18:51:30 +00:00
#### func (FailSort) Less
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (s FailSort) Less(i, j int) bool
```
2019-02-06 18:51:30 +00:00
#### func (FailSort) Swap
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func (s FailSort) Swap(i, j int)
```
2019-02-06 18:51:30 +00:00
#### type Failure
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Failure struct {
2019-02-06 18:51:30 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
Issue string `gorm:"column:issue" json:"issue"`
Method string `gorm:"column:method" json:"method,omitempty"`
MethodId int64 `gorm:"column:method_id" json:"method_id,omitempty"`
ErrorCode int `gorm:"column:error_code" json:"error_code"`
Service int64 `gorm:"index;column:service" json:"-"`
Checkin int64 `gorm:"index;column:checkin" json:"-"`
PingTime float64 `gorm:"column:ping_time" json:"ping"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
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.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Failure) BeforeCreate
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func (f *Failure) BeforeCreate() (err error)
```
BeforeCreate for Failure will set CreatedAt to UTC
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type FailureInterface
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type FailureInterface interface {
2019-02-06 18:51:30 +00:00
Select() *Failure
Ago() string // Ago returns a human readable timestamp
ParseError() string // ParseError returns a human readable error for a service failure
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type Group
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
type Group struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Name string `gorm:"column:name" json:"name"`
Public NullBool `gorm:"default:true;column:public" json:"public"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
}
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
Group is the main struct for Groups
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type Hit
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Hit struct {
2019-02-06 18:51:30 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
Service int64 `gorm:"column:service" json:"-"`
Latency float64 `gorm:"column:latency" json:"latency"`
PingTime float64 `gorm:"column:ping_time" json:"ping_time"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
Hit struct is a 'successful' ping or web response entry for a service.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Hit) BeforeCreate
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func (h *Hit) BeforeCreate() (err error)
```
BeforeCreate for Hit will set CreatedAt to UTC
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type Info
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Info struct {
2019-02-06 18:51:30 +00:00
Name string
Description string
Form string
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type Message
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
type Message struct {
2019-02-06 18:51:30 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
Title string `gorm:"column:title" json:"title"`
Description string `gorm:"column:description" json:"description"`
StartOn time.Time `gorm:"column:start_on" json:"start_on"`
EndOn time.Time `gorm:"column:end_on" json:"end_on"`
ServiceId int64 `gorm:"index;column:service" json:"service"`
NotifyUsers NullBool `gorm:"column:notify_users" json:"notify_users"`
NotifyMethod string `gorm:"column:notify_method" json:"notify_method"`
NotifyBefore NullInt64 `gorm:"column:notify_before" json:"notify_before"`
NotifyBeforeScale string `gorm:"column:notify_before_scale" json:"notify_before_scale"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" json:"updated_at"`
2018-11-07 09:33:51 +00:00
}
```
2019-02-06 18:51:30 +00:00
Message is for creating Announcements, Alerts and other messages for the end
users
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Message) BeforeCreate
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
func (u *Message) BeforeCreate() (err error)
```
BeforeCreate for Message will set CreatedAt to UTC
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
#### type NullBool
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
type NullBool struct {
2019-02-06 18:51:30 +00:00
sql.NullBool
2018-11-07 09:33:51 +00:00
}
```
2019-02-06 18:51:30 +00:00
NullBool is an alias for sql.NullBool data type
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
#### func NewNullBool
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func NewNullBool(s bool) NullBool
```
NewNullBool returns a sql.NullBool for JSON parsing
2019-02-06 18:51:30 +00:00
#### func (*NullBool) MarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (nb *NullBool) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullBool
2019-02-06 18:51:30 +00:00
#### func (*NullBool) UnmarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (nf *NullBool) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullBool
2019-02-06 18:51:30 +00:00
#### type NullFloat64
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
type NullFloat64 struct {
2019-02-06 18:51:30 +00:00
sql.NullFloat64
2018-11-07 09:33:51 +00:00
}
```
2019-02-06 18:51:30 +00:00
NullFloat64 is an alias for sql.NullFloat64 data type
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
#### func NewNullFloat64
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func NewNullFloat64(s float64) NullFloat64
```
NewNullFloat64 returns a sql.NullFloat64 for JSON parsing
2019-02-06 18:51:30 +00:00
#### func (*NullFloat64) MarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (ni *NullFloat64) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullFloat64
2019-02-06 18:51:30 +00:00
#### func (*NullFloat64) UnmarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (nf *NullFloat64) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullFloat64
2019-02-06 18:51:30 +00:00
#### type NullInt64
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
type NullInt64 struct {
2019-02-06 18:51:30 +00:00
sql.NullInt64
2018-11-07 09:33:51 +00:00
}
```
2019-02-06 18:51:30 +00:00
NullInt64 is an alias for sql.NullInt64 data type
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
#### func NewNullInt64
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func NewNullInt64(s int64) NullInt64
```
NewNullInt64 returns a sql.NullInt64 for JSON parsing
2019-02-06 18:51:30 +00:00
#### func (*NullInt64) MarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (ni *NullInt64) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullInt64
2019-02-06 18:51:30 +00:00
#### func (*NullInt64) UnmarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (nf *NullInt64) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullInt64
2019-02-06 18:51:30 +00:00
#### type NullString
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
type NullString struct {
2019-02-06 18:51:30 +00:00
sql.NullString
2018-11-07 09:33:51 +00:00
}
```
2019-02-06 18:51:30 +00:00
NullString is an alias for sql.NullString data type
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
#### func NewNullString
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func NewNullString(s string) NullString
```
NewNullString returns a sql.NullString for JSON parsing
2019-02-06 18:51:30 +00:00
#### func (*NullString) MarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (ns *NullString) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullString
2019-02-06 18:51:30 +00:00
#### func (*NullString) UnmarshalJSON
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
func (nf *NullString) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullString
2019-02-06 18:51:30 +00:00
#### type Plugin
2018-11-07 09:33:51 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type Plugin struct {
2019-02-06 18:51:30 +00:00
Name string
Description string
2018-10-11 02:45:45 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type PluginActions
2018-10-11 02:45:45 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type PluginActions interface {
2019-02-06 18:51:30 +00:00
GetInfo() *Info
OnLoad() error
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type PluginInfo
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type PluginInfo struct {
2019-02-06 18:51:30 +00:00
Info *Info
Routes []*PluginRoute
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type PluginJSON
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type PluginJSON struct {
2019-02-06 18:51:30 +00:00
Name string `json:"name"`
Description string `json:"description"`
Repo string `json:"repo"`
Author string `json:"author"`
Namespace string `json:"namespace"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type PluginObject
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type PluginObject struct {
2019-02-06 18:51:30 +00:00
Pluginer
2018-10-11 02:45:45 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type PluginRepos
2018-10-11 02:45:45 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type PluginRepos struct {
2019-02-06 18:51:30 +00:00
Plugins []PluginJSON
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type PluginRoute
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type PluginRoute struct {
2019-02-06 18:51:30 +00:00
Url string
Method string
Func http.HandlerFunc
2018-10-11 02:45:45 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type PluginRouting
2018-10-11 02:45:45 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type PluginRouting struct {
2019-02-06 18:51:30 +00:00
URL string
Method string
Handler func(http.ResponseWriter, *http.Request)
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type Pluginer
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type Pluginer interface {
2019-02-06 18:51:30 +00:00
Select() *Plugin
2018-10-11 02:45:45 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type Router
2018-10-11 02:45:45 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-11 02:45:45 +00:00
type Router interface {
2019-02-06 18:51:30 +00:00
Routes() []*PluginRoute
AddRoute(string, string, http.HandlerFunc) error
2018-10-11 02:45:45 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type Service
2018-10-11 02:45:45 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Service struct {
2019-02-06 18:51:30 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
Name string `gorm:"column:name" json:"name"`
Domain string `gorm:"column:domain" json:"domain"`
Expected NullString `gorm:"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 NullString `gorm:"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"`
AllowNotifications NullBool `gorm:"default:true;column:allow_notifications" json:"allow_notifications"`
Public NullBool `gorm:"default:true;column:public" json:"public"`
GroupId int `gorm:"default:0;column:group_id" json:"group_id"`
Permalink NullString `gorm:"column:permalink" json:"permalink"`
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:"online_24_hours"`
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_success"`
Failures []FailureInterface `gorm:"-" json:"failures,omitempty"`
Checkins []CheckinInterface `gorm:"-" json:"checkins,omitempty"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
Service is the main struct for Services
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) BeforeCreate
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func (s *Service) BeforeCreate() (err error)
```
BeforeCreate for Service will set CreatedAt to UTC
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*Service) Close
2018-10-07 02:44:31 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func (s *Service) Close()
```
Close will stop the go routine that is checking if service is online or not
2019-02-06 18:51:30 +00:00
#### func (*Service) IsRunning
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func (s *Service) IsRunning() bool
```
IsRunning returns true if the service go routine is running
2019-02-06 18:51:30 +00:00
#### func (*Service) Start
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func (s *Service) Start()
```
Start will create a channel for the service checking go routine
2019-02-06 18:51:30 +00:00
#### type ServiceInterface
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type ServiceInterface interface {
2019-02-06 18:51:30 +00:00
Select() *Service
CheckQueue(bool)
Check(bool)
Create(bool) (int64, error)
Update(bool) error
Delete() error
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### type User
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type User struct {
2019-02-06 18:51:30 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
Username string `gorm:"type:varchar(100);unique;column:username;" json:"username,omitempty"`
Password string `gorm:"column:password" json:"password,omitempty"`
Email string `gorm:"type:varchar(100);unique;column:email" json:"email,omitempty"`
ApiKey string `gorm:"column:api_key" json:"api_key,omitempty"`
ApiSecret string `gorm:"column:api_secret" json:"api_secret,omitempty"`
Admin NullBool `gorm:"column:administrator" json:"admin,omitempty"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
UserInterface `gorm:"-" json:"-"`
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
User is the main struct for Users
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func (*User) BeforeCreate
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
func (u *User) BeforeCreate() (err error)
```
BeforeCreate for User will set CreatedAt to UTC
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type UserInterface
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type UserInterface interface {
2019-02-06 18:51:30 +00:00
Create() (int64, error)
Update() error
Delete() error
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
UserInterface interfaces the database functions
# utils
--
import "github.com/hunterlong/statping/utils"
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
Package utils contains common methods used in most packages in Statping. This
package contains multiple function like: Logging, encryption, type conversions,
setting utils.Directory as the current directory, running local CMD commands,
and creating/deleting files/folder.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
You can overwrite the utils.Directory global variable by including STATPING_DIR
environment variable to be an absolute path.
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
More info on: https://github.com/hunterlong/statping
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
## Usage
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-11-07 09:33:51 +00:00
const (
2019-02-06 18:51:30 +00:00
FlatpickrTime = "2006-01-02 15:04"
FlatpickrDay = "2006-01-02"
FlatpickrReadable = "Mon, 02 Jan 2006"
2018-11-07 09:33:51 +00:00
)
```
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
var (
2019-02-06 18:51:30 +00:00
LastLines []*LogRow
LockLines sync.Mutex
2018-10-06 10:07:34 +00:00
)
```
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
var (
2019-02-06 18:51:30 +00:00
// Directory returns the current path or the STATPING_DIR environment variable
Directory string
2018-10-06 10:07:34 +00:00
)
```
2019-02-06 18:51:30 +00:00
#### func Command
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func Command(cmd string) (string, string, error)
```
2019-02-06 18:51:30 +00:00
Command will run a terminal command with 'sh -c COMMAND' and return stdout and
errOut as strings
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
in, out, err := Command("sass assets/scss assets/css/base.css")
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func DeleteDirectory
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func DeleteDirectory(directory string) error
```
DeleteDirectory will attempt to delete a directory and all contents inside
2019-02-06 18:51:30 +00:00
DeleteDirectory("assets")
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func DeleteFile
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func DeleteFile(file string) error
```
DeleteFile will attempt to delete a file
2019-02-06 18:51:30 +00:00
DeleteFile("newfile.json")
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func DurationReadable
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func DurationReadable(d time.Duration) string
```
2019-02-06 18:51:30 +00:00
DurationReadable will return a time.Duration into a human readable string // t
:= time.Duration(5 * time.Minute) // DurationReadable(t) // returns: 5 minutes
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func FileExists
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func FileExists(name string) bool
```
FileExists returns true if a file exists
2019-02-06 18:51:30 +00:00
exists := FileExists("assets/css/base.css")
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func FormatDuration
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func FormatDuration(d time.Duration) string
```
2018-10-07 08:16:38 +00:00
FormatDuration converts a time.Duration into a string
2019-02-06 18:51:30 +00:00
#### func HashPassword
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func HashPassword(password string) string
```
HashPassword returns the bcrypt hash of a password string
2019-02-06 18:51:30 +00:00
#### func Http
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func Http(r *http.Request) string
```
Http returns a log for a HTTP request
2019-02-06 18:51:30 +00:00
#### func HttpRequest
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func HttpRequest(url, method string, content interface{}, headers []string, body io.Reader, timeout time.Duration) ([]byte, *http.Response, error)
```
2019-02-06 18:51:30 +00:00
HttpRequest is a global function to send a HTTP request // url - The URL for
HTTP request // method - GET, POST, DELETE, PATCH // content - The HTTP request
content type (text/plain, application/json, or nil) // headers - An array of
Headers to be sent (KEY=VALUE) []string{"Authentication=12345", ...} // body -
The body or form data to send with HTTP request // timeout - Specific duration
to timeout on. time.Duration(30 * time.Seconds) // You can use a HTTP Proxy if
you HTTP_PROXY environment variable
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
#### func InitLogs
2018-12-04 08:31:22 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func InitLogs() error
```
2019-02-06 18:51:30 +00:00
InitLogs will create the '/logs' directory and creates a file '/logs/statup.log'
for application logging
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func Log
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func Log(level int, err interface{}) error
```
Log creates a new entry in the utils.Log. Log has 1-5 levels depending on how
2019-02-06 18:51:30 +00:00
critical the log/error is
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### func NewSHA1Hash
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func NewSHA1Hash(n ...int) string
```
NewSHA1Hash returns a random SHA1 hash based on a specific length
2019-02-06 18:51:30 +00:00
#### func RandomString
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func RandomString(n int) string
```
RandomString generates a random string of n length
2019-02-06 18:51:30 +00:00
#### func SaveFile
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-07 08:16:38 +00:00
func SaveFile(filename string, data []byte) error
```
2018-10-08 21:15:01 +00:00
SaveFile will create a new file with data inside it
2019-02-06 18:51:30 +00:00
SaveFile("newfile.json", []byte('{"data": "success"}')
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func Timezoner
2018-10-07 08:16:38 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func Timezoner(t time.Time, zone float32) time.Time
2018-10-08 21:15:01 +00:00
```
2018-12-04 08:31:22 +00:00
Timezoner returns the time.Time with the user set timezone
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func ToInt
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-12-04 08:31:22 +00:00
func ToInt(s interface{}) int64
2018-10-06 10:07:34 +00:00
```
2018-12-04 08:31:22 +00:00
ToInt converts a int to a string
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
#### func ToString
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func ToString(s interface{}) string
```
ToString converts a int to a string
2019-02-06 18:51:30 +00:00
#### func UnderScoreString
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func UnderScoreString(str string) string
```
2019-02-06 18:51:30 +00:00
UnderScoreString will return a string that replaces spaces and other characters
to underscores
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
UnderScoreString("Example String")
// example_string
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type LogRow
2018-10-08 21:15:01 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type LogRow struct {
2019-02-06 18:51:30 +00:00
Date time.Time
Line interface{}
2018-10-06 10:07:34 +00:00
}
```
2019-02-06 18:51:30 +00:00
#### func GetLastLine
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func GetLastLine() *LogRow
```
GetLastLine returns 1 line for a recent log entry
2019-02-06 18:51:30 +00:00
#### func (*LogRow) FormatForHtml
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func (o *LogRow) FormatForHtml() string
```
2019-02-06 18:51:30 +00:00
#### type Timestamp
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Timestamp time.Time
```
2019-02-06 18:51:30 +00:00
#### func (Timestamp) Ago
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
func (t Timestamp) Ago() string
```
2019-02-06 18:51:30 +00:00
Ago returns a human readable timestamp based on the Timestamp (time.Time)
interface
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
#### type Timestamper
2018-10-06 10:07:34 +00:00
2019-02-06 18:51:30 +00:00
```go
2018-10-06 10:07:34 +00:00
type Timestamper interface {
2019-02-06 18:51:30 +00:00
Ago() string
2018-10-06 10:07:34 +00:00
}
```