Skip to content

Commit

Permalink
healthcheck: add check for scst
Browse files Browse the repository at this point in the history
Checking for the scstadmin binary, the loaded SCST modules, and the
userspace daemon.
  • Loading branch information
chrboe committed Mar 21, 2024
1 parent d3441f5 commit 138c1f6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/google/uuid v1.4.0
github.com/gorilla/mux v1.8.0
github.com/icza/gog v0.0.0-20220909135443-35d926f98ec3
github.com/mitchellh/go-ps v1.0.0
github.com/moul/http2curl v1.0.0
github.com/olekukonko/tablewriter v0.0.5
github.com/pelletier/go-toml v1.9.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
Expand Down
7 changes: 6 additions & 1 deletion pkg/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ func checkAgent() error {
}
err = category(
"iSCSI",
&checkInPath{binary: "targetcli", packageName: "targetcli"},
&checkInPath{binary: "targetcli", packageName: "targetcli", hint: "targetcli is only required for the LIO backend. If you are not planning on using LIO, you can ignore this warning."},
&checkInPath{binary: "scstadmin", packageName: "scstadmin", hint: "scstadmin is only required for the SCST backend. If you are not planning on using SCST, you can ignore this warning."},
&checkKernelModuleLoaded{"scst", "scst"},
&checkKernelModuleLoaded{"iscsi_scst", "scst"},
&checkKernelModuleLoaded{"scst_vdisk", "scst"},
&checkProcessRunning{"iscsi-scstd", "scst"},
)
if err != nil {
errs++
Expand Down
29 changes: 29 additions & 0 deletions pkg/healthcheck/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/coreos/go-systemd/v22/dbus"
"github.com/fatih/color"
"github.com/mitchellh/go-ps"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -208,3 +209,31 @@ func (c *checkInPath) format(err error) string {
}
return b.String()
}

type checkProcessRunning struct {
process string
packageName string
}

func (c *checkProcessRunning) check(prevError bool) error {
procs, err := ps.Processes()
if err != nil {
return err
}
for _, p := range procs {
if p.Executable() == c.process {
return nil
}
}
return fmt.Errorf("%s not found in process list", c.process)
}

func (c *checkProcessRunning) format(err error) string {
var b strings.Builder
fmt.Fprintf(&b, " %s Process %s is not running\n", color.RedString("✗"), bold(c.process))
fmt.Fprintf(&b, " %s\n", err.Error())
fmt.Fprintf(&b, " Make sure that:\n")
fmt.Fprintf(&b, " • the %s package is installed\n", bold(c.packageName))
fmt.Fprintf(&b, " • the %s process is started\n", bold(c.process))
return b.String()
}

0 comments on commit 138c1f6

Please sign in to comment.