Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bisohns/saido into FEAT/web-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurudeen38 committed Nov 9, 2022
2 parents cbf2774 + aea220f commit 813748c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions driver/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion inspector/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions inspector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 813748c

Please sign in to comment.