Skip to content

Commit

Permalink
Specify custom command
Browse files Browse the repository at this point in the history
  • Loading branch information
deven96 committed Nov 10, 2022
1 parent 9aac418 commit b1992df
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions inspector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/bisohns/saido/driver"
)

// CustomCommand : every custom command must be prefixed by this
var CustomCommand = `custom`

// Inspector : defines a particular metric supported by a driver
type Inspector interface {
Parse(output string)
Expand All @@ -19,22 +22,22 @@ type Inspector interface {
type NewInspector func(driver *driver.Driver, custom ...string) (Inspector, error)

var inspectorMap = map[string]NewInspector{
`disk`: NewDF,
`docker`: NewDockerStats,
`uptime`: NewUptime,
`memory`: NewMemInfo,
`process`: NewProcess,
`loadavg`: NewLoadAvg,
`tcp`: NewTcp,
`custom`: NewCustom,
`disk`: NewDF,
`docker`: NewDockerStats,
`uptime`: NewUptime,
`memory`: NewMemInfo,
`process`: NewProcess,
`loadavg`: NewLoadAvg,
`tcp`: NewTcp,
CustomCommand: NewCustom,
// NOTE: Inactive for now
`responsetime`: NewResponseTime,
}

// Valid : checks if inspector is a valid inspector
func Valid(name string) bool {
for key := range inspectorMap {
if name == key || strings.HasPrefix(name, "custom") {
if name == key || strings.HasPrefix(name, CustomCommand) {
return true
}
}
Expand All @@ -43,7 +46,7 @@ func Valid(name string) bool {

// Init : initializes the specified inspector using name and driver
func Init(name string, driver *driver.Driver, custom ...string) (Inspector, error) {
if strings.HasPrefix(name, "custom") {
if strings.HasPrefix(name, CustomCommand) {
name = "custom"
}
val, ok := inspectorMap[name]
Expand Down

0 comments on commit b1992df

Please sign in to comment.