More config options, markdown in incidents

- Specify method to ping with
- Body regex match
- Markdown in incident messages
- Update existing incidents
This commit is contained in:
Matej Kramny
2016-05-19 18:40:01 +01:00
parent c729fbdf41
commit 0ceccccd45
7 changed files with 305 additions and 312 deletions

View File

@@ -12,7 +12,6 @@ type CachetMonitor struct {
APIUrl string `json:"api_url"`
APIToken string `json:"api_token"`
Interval int64 `json:"interval"`
SystemName string `json:"system_name"`
LogPath string `json:"log_path"`
InsecureAPI bool `json:"insecure_api"`
@@ -20,28 +19,30 @@ type CachetMonitor struct {
Monitors []*Monitor `json:"monitors"`
}
func (mon *CachetMonitor) ValidateConfiguration() error {
if mon.Logger == nil {
mon.Logger = log.New(os.Stdout, "", log.Llongfile|log.Ldate|log.Ltime)
func (cfg *CachetMonitor) ValidateConfiguration() error {
if cfg.Logger == nil {
cfg.Logger = log.New(os.Stdout, "", log.Llongfile|log.Ldate|log.Ltime)
}
if len(mon.SystemName) == 0 {
if len(cfg.SystemName) == 0 {
// get hostname
mon.SystemName = getHostname()
cfg.SystemName = getHostname()
}
if mon.Interval <= 0 {
mon.Interval = 60
}
if len(mon.APIToken) == 0 || len(mon.APIUrl) == 0 {
if len(cfg.APIToken) == 0 || len(cfg.APIUrl) == 0 {
return errors.New("API URL or API Token not set. cachet-monitor won't be able to report incidents.\n\nPlease set:\n CACHET_API and CACHET_TOKEN environment variable to override settings.\n\nGet help at https://github.com/castawaylabs/cachet-monitor\n")
}
if len(mon.Monitors) == 0 {
if len(cfg.Monitors) == 0 {
return errors.New("No monitors defined!\nSee sample configuration: https://github.com/castawaylabs/cachet-monitor/blob/master/example.config.json\n")
}
for _, monitor := range cfg.Monitors {
if err := monitor.ValidateConfiguration(); err != nil {
return err
}
}
return nil
}