mirror of https://github.com/statping/statping
added --config flag to specify config.yml file
parent
2f7778e61c
commit
1bd9e98163
|
@ -3,7 +3,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<b>Statping - Web and App Status Monitoring for Any Type of Project</b><br>
|
<b>Statping - Web and App Status Monitoring for Any Type of Project</b><br>
|
||||||
<a href="https://github.com/statping/statping/wiki">View Wiki</a> | <a href="https://demo.statping.com">Demo</a> | <a href="https://itunes.apple.com/us/app/apple-store/id1445513219">iPhone</a> | <a href="https://play.google.com/store/apps/details?id=com.statping">Android</a> <br> <a href="https://documenter.getpostman.com/view/1898229/SzmfXwi4?version=latest">API</a> | <a href="https://github.com/statping/statping/wiki/Docker">Docker</a> | <a href="https://github.com/statping/statping/wiki/AWS-EC2">EC2</a> | <a href="https://github.com/statping/statping/wiki/Mac">Mac</a> | <a href="https://github.com/statping/statping/wiki/Linux">Linux</a> | <a href="https://github.com/statping/statping/wiki/Windows">Windows</a>
|
<a href="https://github.com/statping/statping/wiki">View Wiki</a> | <a href="https://demo.statping.com">Demo</a> | <a href="https://itunes.apple.com/us/app/apple-store/id1445513219">iPhone</a> | <a href="https://play.google.com/store/apps/details?id=com.statping">Android</a> <br> <a href="http://docs.statping.com">API</a> | <a href="https://github.com/statping/statping/wiki/Docker">Docker</a> | <a href="https://github.com/statping/statping/wiki/AWS-EC2">EC2</a> | <a href="https://github.com/statping/statping/wiki/Mac">Mac</a> | <a href="https://github.com/statping/statping/wiki/Linux">Linux</a> | <a href="https://github.com/statping/statping/wiki/Windows">Windows</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Statping - Status Page & Monitoring Server
|
# Statping - Status Page & Monitoring Server
|
||||||
|
|
|
@ -46,7 +46,7 @@ func exportCli(args []string) error {
|
||||||
if err := source.Assets(); err != nil {
|
if err := source.Assets(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
config, err := configs.LoadConfigs()
|
config, err := configs.LoadConfigs(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ func importCli(args []string) error {
|
||||||
log.Printf("Messages: %d\n", len(exportData.Messages))
|
log.Printf("Messages: %d\n", len(exportData.Messages))
|
||||||
log.Printf("Users: %d\n", len(exportData.Users))
|
log.Printf("Users: %d\n", len(exportData.Users))
|
||||||
|
|
||||||
config, err := configs.LoadConfigs()
|
config, err := configs.LoadConfigs(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ func updateDisplay() error {
|
||||||
|
|
||||||
// runOnce will initialize the Statping application and check each service 1 time, will not run HTTP server
|
// runOnce will initialize the Statping application and check each service 1 time, will not run HTTP server
|
||||||
func runOnce() error {
|
func runOnce() error {
|
||||||
config, err := configs.LoadConfigs()
|
config, err := configs.LoadConfigs(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "config.yml file not found")
|
return errors.Wrap(err, "config.yml file not found")
|
||||||
}
|
}
|
||||||
|
|
11
cmd/flags.go
11
cmd/flags.go
|
@ -3,6 +3,14 @@ package main
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"github.com/statping/statping/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ipAddress string
|
||||||
|
configFile string
|
||||||
|
verboseMode int
|
||||||
|
port int
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseFlags(cmd *cobra.Command) {
|
func parseFlags(cmd *cobra.Command) {
|
||||||
|
@ -14,4 +22,7 @@ func parseFlags(cmd *cobra.Command) {
|
||||||
|
|
||||||
cmd.PersistentFlags().IntVarP(&verboseMode, "verbose", "v", 2, "verbose logging")
|
cmd.PersistentFlags().IntVarP(&verboseMode, "verbose", "v", 2, "verbose logging")
|
||||||
viper.BindPFlag("verbose", cmd.PersistentFlags().Lookup("verbose"))
|
viper.BindPFlag("verbose", cmd.PersistentFlags().Lookup("verbose"))
|
||||||
|
|
||||||
|
cmd.PersistentFlags().StringVarP(&configFile, "config", "c", utils.Directory+"/config.yml", "path to config.yml file")
|
||||||
|
viper.BindPFlag("config", cmd.PersistentFlags().Lookup("config"))
|
||||||
}
|
}
|
||||||
|
|
12
cmd/main.go
12
cmd/main.go
|
@ -20,13 +20,9 @@ var (
|
||||||
// VERSION stores the current version of Statping
|
// VERSION stores the current version of Statping
|
||||||
VERSION string
|
VERSION string
|
||||||
// COMMIT stores the git commit hash for this version of Statping
|
// COMMIT stores the git commit hash for this version of Statping
|
||||||
COMMIT string
|
COMMIT string
|
||||||
ipAddress string
|
log = utils.Log.WithField("type", "cmd")
|
||||||
//grpcPort int
|
confgs *configs.DbConfig
|
||||||
verboseMode int
|
|
||||||
port int
|
|
||||||
log = utils.Log.WithField("type", "cmd")
|
|
||||||
confgs *configs.DbConfig
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -83,7 +79,7 @@ func start() {
|
||||||
// log.Warnln(err)
|
// log.Warnln(err)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
confgs, err = configs.LoadConfigs()
|
confgs, err = configs.LoadConfigs(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infoln("Starting in Setup Mode")
|
log.Infoln("Starting in Setup Mode")
|
||||||
if err := SetupMode(); err != nil {
|
if err := SetupMode(); err != nil {
|
||||||
|
|
|
@ -34,11 +34,12 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
service_txt() {
|
service_txt() {
|
||||||
if (!this.service.online) {
|
const s = this.service
|
||||||
if (!this.toUnix(this.service.last_success)) {
|
if (!s.online) {
|
||||||
|
if (!this.toUnix(this.parseISO(s.last_success))) {
|
||||||
return `Always Offline`
|
return `Always Offline`
|
||||||
}
|
}
|
||||||
return `Offline for ${this.ago(this.service.last_success)}`
|
return `Offline for ${this.ago(s.last_success)}`
|
||||||
}
|
}
|
||||||
return `${this.service.online_24_hours}% Uptime`
|
return `${this.service.online_24_hours}% Uptime`
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ export default {
|
||||||
if (last) {
|
if (last) {
|
||||||
return `Offline, last error: ${last} ${this.ago(last.created_at)}`
|
return `Offline, last error: ${last} ${this.ago(last.created_at)}`
|
||||||
}
|
}
|
||||||
return `Service is offline for ${this.ago(s.last_success)}`
|
return `Service has been offline for ${this.ago(s.last_success)}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
visibleChart(isVisible, entry) {
|
visibleChart(isVisible, entry) {
|
||||||
|
|
|
@ -295,15 +295,23 @@
|
||||||
return this.$store.getters.notifiers
|
return this.$store.getters.notifiers
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
mounted() {
|
||||||
this.cache = await Api.cache()
|
this.update()
|
||||||
},
|
},
|
||||||
async created() {
|
created() {
|
||||||
const c = this.core
|
this.update()
|
||||||
this.qrurl = `statping://setup?domain=${c.domain}&api=${c.api_secret}`
|
|
||||||
this.qrcode = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=" + encodeURI(this.qrurl)
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async update() {
|
||||||
|
const c = await Api.core()
|
||||||
|
this.$store.commit('setCore', c)
|
||||||
|
const n = await Api.notifiers()
|
||||||
|
this.$store.commit('setNotifiers', n)
|
||||||
|
|
||||||
|
this.qrurl = `statping://setup?domain=${c.domain}&api=${c.api_secret}`
|
||||||
|
this.qrcode = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=" + encodeURI(this.qrurl)
|
||||||
|
this.cache = await Api.cache()
|
||||||
|
},
|
||||||
changeTab(e) {
|
changeTab(e) {
|
||||||
this.tab = e.target.id
|
this.tab = e.target.id
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,7 +21,7 @@ func ConnectConfigs(configs *DbConfig, retry bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfigs() (*DbConfig, error) {
|
func LoadConfigs(cfgFile string) (*DbConfig, error) {
|
||||||
writeAble, err := utils.DirWritable(utils.Directory)
|
writeAble, err := utils.DirWritable(utils.Directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -30,7 +30,7 @@ func LoadConfigs() (*DbConfig, error) {
|
||||||
return nil, errors.Errorf("Directory %s is not writable!", utils.Directory)
|
return nil, errors.Errorf("Directory %s is not writable!", utils.Directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadConfigFile(utils.Directory)
|
return LoadConfigFile(cfgFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func findDbFile(configs *DbConfig) (string, error) {
|
func findDbFile(configs *DbConfig) (string, error) {
|
||||||
|
|
|
@ -7,15 +7,15 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadConfigFile(directory string) (*DbConfig, error) {
|
func LoadConfigFile(configFile string) (*DbConfig, error) {
|
||||||
p := utils.Params
|
p := utils.Params
|
||||||
log.Infof("Attempting to read config file at: %s/config.yml ", directory)
|
log.Infof("Attempting to read config file at: %s", configFile)
|
||||||
p.SetConfigFile(directory + "/config.yml")
|
p.SetConfigFile(configFile)
|
||||||
p.SetConfigType("yaml")
|
p.SetConfigType("yaml")
|
||||||
p.ReadInConfig()
|
p.ReadInConfig()
|
||||||
|
|
||||||
db := new(DbConfig)
|
db := new(DbConfig)
|
||||||
content, err := utils.OpenFile(directory + "/config.yml")
|
content, err := utils.OpenFile(configFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := yaml.Unmarshal([]byte(content), &db); err != nil {
|
if err := yaml.Unmarshal([]byte(content), &db); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -66,7 +66,7 @@ func LoadConfigFile(directory string) (*DbConfig, error) {
|
||||||
Location: utils.Directory,
|
Location: utils.Directory,
|
||||||
SqlFile: p.GetString("SQL_FILE"),
|
SqlFile: p.GetString("SQL_FILE"),
|
||||||
}
|
}
|
||||||
log.WithFields(utils.ToFields(configs)).Debugln("read config file: " + directory + "/config.yml")
|
log.WithFields(utils.ToFields(configs)).Debugln("read config file: " + configFile)
|
||||||
|
|
||||||
if configs.DbConn == "" {
|
if configs.DbConn == "" {
|
||||||
return configs, errors.New("Starting in setup mode")
|
return configs, errors.New("Starting in setup mode")
|
||||||
|
|
Loading…
Reference in New Issue