diff --git a/client/controller.go b/client/controller.go index a581fb5..7b06421 100644 --- a/client/controller.go +++ b/client/controller.go @@ -76,6 +76,9 @@ func (hosts *HostsController) sendMetric(host config.Host, client *Client) { for metric, custom := range hosts.Info.Metrics { driver := hosts.getDriver(host.Address) initializedMetric, err := inspector.Init(metric, driver, custom) + if err != nil { + log.Error(err) + } data, err := initializedMetric.Execute() if err == nil { var unmarsh interface{} diff --git a/config/config.go b/config/config.go index 4e185c8..565efea 100644 --- a/config/config.go +++ b/config/config.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "github.com/bisohns/saido/driver" + "github.com/bisohns/saido/inspector" "github.com/mitchellh/mapstructure" log "github.com/sirupsen/logrus" @@ -102,7 +103,12 @@ func GetDashboardInfoConfig(config *Config) *DashboardInfo { dashboardInfo.Hosts = parseConfig("root", "", config.Hosts, &Connection{}) for metric, customCommand := range config.Metrics { - metrics[fmt.Sprintf("%v", metric)] = fmt.Sprintf("%v", customCommand) + metric := fmt.Sprintf("%v", metric) + if inspector.Valid(metric) { + metrics[metric] = fmt.Sprintf("%v", customCommand) + } else { + log.Fatalf("Found invalid metric %v", metric) + } } dashboardInfo.Metrics = metrics for _, host := range dashboardInfo.Hosts { diff --git a/driver/local.go b/driver/local.go index 01048e1..8fe7683 100644 --- a/driver/local.go +++ b/driver/local.go @@ -41,6 +41,7 @@ func (d *Local) RunCommand(command string) (string, error) { if d.Info.IsLinux || d.Info.IsDarwin { cmd = exec.Command("bash", "-c", command) } else { + command = strings.ReplaceAll(command, "\\", "") cmd = exec.Command("cmd", "/C", command) } cmd.Env = os.Environ() diff --git a/inspector/custom.go b/inspector/custom.go index 1d985c3..22a776c 100644 --- a/inspector/custom.go +++ b/inspector/custom.go @@ -67,7 +67,7 @@ func NewCustom(driver *driver.Driver, custom ...string) (Inspector, error) { return nil, errors.New("Must specify command for custom") } customInspector = &Custom{ - Command: fmt.Sprintf(`%s`, custom[0]), + Command: custom[0], } customInspector.SetDriver(driver) return customInspector, nil diff --git a/inspector/inspector.go b/inspector/inspector.go index 5f87a02..d19936f 100644 --- a/inspector/inspector.go +++ b/inspector/inspector.go @@ -30,6 +30,16 @@ var inspectorMap = map[string]NewInspector{ `responsetime`: NewResponseTime, } +// Valid : checks if inspector is a valid inspector +func Valid(name string) bool { + for key, _ := range inspectorMap { + if name == key { + return true + } + } + return false +} + // Init : initializes the specified inspector using name and driver func Init(name string, driver *driver.Driver, custom ...string) (Inspector, error) { val, ok := inspectorMap[name]