Skip to content

Commit

Permalink
Allow sudo command to be changed (#54)
Browse files Browse the repository at this point in the history
Fixes #53
  • Loading branch information
treydock committed Oct 13, 2022
1 parent 2c44571 commit 43214ee
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions collectors/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var (
lastExecution = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "exporter", "last_execution"),
"Last execution time of ", []string{"collector"}, nil)
sudoCmd = kingpin.Flag("config.sudo.command", "The command to run sudo").Default("sudo").String()
mmlsfsTimeout = kingpin.Flag("config.mmlsfs.timeout", "Timeout for mmlsfs execution").Default("5").Int()
)

Expand Down Expand Up @@ -172,7 +173,7 @@ func FileExists(filename string) bool {
}

func mmdiag(arg string, ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmdiag", arg, "-Y")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmdiag", arg, "-Y")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand All @@ -198,7 +199,7 @@ func mmlfsfsFilesystems(ctx context.Context, logger log.Logger) ([]string, error
}

func mmlsfs(ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmlsfs", "all", "-Y", "-T")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmlsfs", "all", "-Y", "-T")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmces.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *MmcesCollector) collect(nodename string) ([]CESMetric, error) {
}

func mmces(nodename string, ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmces", "state", "show", "-N", nodename, "-Y")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmces", "state", "show", "-N", nodename, "-Y")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *MmdfCollector) mmdfCollect(fs string) (DFMetric, error) {
}

func mmdf(fs string, ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmdf", fs, "-Y")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmdf", fs, "-Y")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmgetstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c *MmgetstateCollector) collect() (MmgetstateMetrics, error) {
}

func mmgetstate(ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmgetstate", "-Y")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmgetstate", "-Y")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmhealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *MmhealthCollector) collect() ([]HealthMetric, error) {
}

func mmhealth(ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmhealth", "node", "show", "-Y")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmhealth", "node", "show", "-Y")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmlsfileset.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (c *MmlsfilesetCollector) mmlsfilesetCollect(fs string) ([]FilesetMetric, e
}

func mmlsfileset(fs string, ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmlsfileset", fs, "-Y")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmlsfileset", fs, "-Y")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmlssnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func mmlssnapshot(fs string, ctx context.Context) (string, error) {
if *snapshotGetSize {
args = append(args, "-d")
}
cmd := execCommand(ctx, "sudo", args...)
cmd := execCommand(ctx, *sudoCmd, args...)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmpmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *MmpmonCollector) collect() ([]PerfMetrics, error) {
}

func mmpmon(ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmpmon", "-s", "-p")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmpmon", "-s", "-p")
cmd.Stdin = strings.NewReader("fs_io_s\n")
var out bytes.Buffer
cmd.Stdout = &out
Expand Down
2 changes: 1 addition & 1 deletion collectors/mmrepquota.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func mmrepquota(ctx context.Context) (string, error) {
} else {
args = append(args, strings.Split(*configMmrepquotaFilesystems, ",")...)
}
cmd := execCommand(ctx, "sudo", args...)
cmd := execCommand(ctx, *sudoCmd, args...)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion collectors/verbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *VerbsCollector) collect() (VerbsMetrics, error) {
}

func verbs(ctx context.Context) (string, error) {
cmd := execCommand(ctx, "sudo", "/usr/lpp/mmfs/bin/mmfsadm", "test", "verbs", "status")
cmd := execCommand(ctx, *sudoCmd, "/usr/lpp/mmfs/bin/mmfsadm", "test", "verbs", "status")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
Expand Down

0 comments on commit 43214ee

Please sign in to comment.