Detects hostname/interface ip

- Hostname is monitor's id. Incidents will be created with the monitor id.
This commit is contained in:
Matej Kramny
2015-03-21 11:44:52 +01:00
parent bdb426c232
commit dce1978b51
4 changed files with 50 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/castawaylabs/cachet-monitor/system"
"io/ioutil"
"net/http"
"net/url"
@@ -15,14 +16,17 @@ var Config CachetConfig
// CachetConfig is the monitoring tool configuration
type CachetConfig struct {
APIUrl string `json:"api_url"`
APIToken string `json:"api_token"`
Monitors []*Monitor `json:"monitors"`
APIUrl string `json:"api_url"`
APIToken string `json:"api_token"`
Monitors []*Monitor `json:"monitors"`
SystemName string `json:"system_name"`
}
func init() {
var configPath string
var systemName string
flag.StringVar(&configPath, "c", "/etc/cachet-monitor.config.json", "Config path")
flag.StringVar(&systemName, "name", "", "System Name")
flag.Parse()
var data []byte
@@ -57,6 +61,14 @@ func init() {
os.Exit(1)
}
if len(systemName) > 0 {
Config.SystemName = systemName
}
if len(Config.SystemName) == 0 {
// get hostname
Config.SystemName = system.GetHostname()
}
if len(os.Getenv("CACHET_API")) > 0 {
Config.APIUrl = os.Getenv("CACHET_API")
}

View File

@@ -78,7 +78,7 @@ func (monitor *Monitor) AnalyseData() {
fmt.Println("Creating incident...")
monitor.Incident = &Incident{
Name: monitor.Name,
Name: monitor.Name + " - " + Config.SystemName,
Message: monitor.Name + " failed",
}