From 43214ee40b13e759ef13cfd7731c6595b8be28a8 Mon Sep 17 00:00:00 2001 From: treydock Date: Thu, 13 Oct 2022 11:51:37 -0400 Subject: [PATCH] Allow sudo command to be changed (#54) Fixes #53 --- collectors/collector.go | 5 +++-- collectors/mmces.go | 2 +- collectors/mmdf.go | 2 +- collectors/mmgetstate.go | 2 +- collectors/mmhealth.go | 2 +- collectors/mmlsfileset.go | 2 +- collectors/mmlssnapshot.go | 2 +- collectors/mmpmon.go | 2 +- collectors/mmrepquota.go | 2 +- collectors/verbs.go | 2 +- 10 files changed, 12 insertions(+), 11 deletions(-) diff --git a/collectors/collector.go b/collectors/collector.go index 0aa639a..216b86e 100644 --- a/collectors/collector.go +++ b/collectors/collector.go @@ -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() ) @@ -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() @@ -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() diff --git a/collectors/mmces.go b/collectors/mmces.go index d177f00..f45854a 100644 --- a/collectors/mmces.go +++ b/collectors/mmces.go @@ -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() diff --git a/collectors/mmdf.go b/collectors/mmdf.go index 48f043c..62dc7cd 100644 --- a/collectors/mmdf.go +++ b/collectors/mmdf.go @@ -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() diff --git a/collectors/mmgetstate.go b/collectors/mmgetstate.go index fa64aa5..9a45ee6 100644 --- a/collectors/mmgetstate.go +++ b/collectors/mmgetstate.go @@ -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() diff --git a/collectors/mmhealth.go b/collectors/mmhealth.go index ad38b94..e8f0f97 100644 --- a/collectors/mmhealth.go +++ b/collectors/mmhealth.go @@ -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() diff --git a/collectors/mmlsfileset.go b/collectors/mmlsfileset.go index e7763b5..55664be 100644 --- a/collectors/mmlsfileset.go +++ b/collectors/mmlsfileset.go @@ -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() diff --git a/collectors/mmlssnapshot.go b/collectors/mmlssnapshot.go index 5572a6a..02346f7 100644 --- a/collectors/mmlssnapshot.go +++ b/collectors/mmlssnapshot.go @@ -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() diff --git a/collectors/mmpmon.go b/collectors/mmpmon.go index e75a4f7..13bea56 100644 --- a/collectors/mmpmon.go +++ b/collectors/mmpmon.go @@ -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 diff --git a/collectors/mmrepquota.go b/collectors/mmrepquota.go index 5c493ed..747eba6 100644 --- a/collectors/mmrepquota.go +++ b/collectors/mmrepquota.go @@ -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() diff --git a/collectors/verbs.go b/collectors/verbs.go index 0f9a877..9730ba1 100644 --- a/collectors/verbs.go +++ b/collectors/verbs.go @@ -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()