Skip to content

Commit

Permalink
Add further flags to disable subchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
martialblog committed Mar 15, 2024
1 parent dea24b4 commit 9118a3b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 53 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -12,6 +12,7 @@ issues:
linters:
- nosnakecase
- funlen
- gocognit
- path: 'hp/ilo/firmware.go'
linters:
- wastedassign
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -62,6 +62,8 @@ Arguments:
--timeout int SNMP timeout in seconds (default 15)
--snmpwalk-file string Read output from snmpwalk
-I, --ignore-ilo-version Don't check the ILO version
-D, --ignore-drives Don't check the drive firmware
-C, --ignore-controller Don't check the controller firmware
-4, --ipv4 Use IPv4
-6, --ipv6 Use IPv6
-V, --version Show version
Expand Down
115 changes: 62 additions & 53 deletions main.go
Expand Up @@ -44,16 +44,20 @@ func main() {
config.Timeout = 15

// Variables for CLI flags
// Personally, I would have preferred to add "enable" flags that enable further subchecks.
// However, this would have broken the current behaviour completely. Thus I opted for "ignore" flags
var (
fs = config.FlagSet
host = fs.StringP("hostname", "H", "localhost", "SNMP host")
community = fs.StringP("community", "c", "public", "SNMP community")
protocol = fs.StringP("protocol", "P", "2c", "SNMP protocol")
port = fs.Uint16P("port", "p", 161, "SNMP port")
file = fs.String("snmpwalk-file", "", "Read output from snmpwalk")
ignoreIlo = fs.BoolP("ignore-ilo-version", "I", false, "Don't check the ILO version")
ipv4 = fs.BoolP("ipv4", "4", false, "Use IPv4")
ipv6 = fs.BoolP("ipv6", "6", false, "Use IPv6")
fs = config.FlagSet
host = fs.StringP("hostname", "H", "localhost", "SNMP host")
community = fs.StringP("community", "c", "public", "SNMP community")
protocol = fs.StringP("protocol", "P", "2c", "SNMP protocol")
port = fs.Uint16P("port", "p", 161, "SNMP port")
file = fs.String("snmpwalk-file", "", "Read output from snmpwalk")
ignoreIlo = fs.BoolP("ignore-ilo-version", "I", false, "Don't check the ILO version")
ignoreDrives = fs.BoolP("ignore-drives", "D", false, "Don't check the drive firmware")
ignoreController = fs.BoolP("ignore-controller", "C", false, "Don't check the controller firmware")
ipv4 = fs.BoolP("ipv4", "4", false, "Use IPv4")
ipv6 = fs.BoolP("ipv6", "6", false, "Use IPv6")
)

config.ParseArguments()
Expand Down Expand Up @@ -108,43 +112,10 @@ func main() {
_ = client.Close()
}()

// Load controller data
cntlrTable, err = cntlr.GetCpqDaCntlrTable(client)
if err != nil {
check.ExitError(err)
}

// Load drive data
driveTable, err = drive.GetCpqDaPhyDrvTable(client)
if err != nil {
check.ExitError(err)
}

if len(cntlrTable.Snmp.Values) == 0 {
check.ExitRaw(3, "No HP controller data found!")
}

// Extract controller data from SNMP Table
controllers, err := cntlr.GetControllersFromTable(cntlrTable)

if err != nil {
check.ExitError(err)
}

if len(driveTable.Snmp.Values) == 0 {
check.ExitRaw(3, "No HP drive data found!")
}

// Extract drive data from SNMP Table
drives, err := drive.GetPhysicalDrivesFromTable(driveTable)
if err != nil {
check.ExitError(err)
}

// Overall is a singleton that has several partial results
overall := result.Overall{}

// Load iLO Version if flag is set
// Load iLO Version data
if !*ignoreIlo {
iloData, err := ilo.GetIloInformation(client)
if err != nil {
Expand All @@ -154,20 +125,58 @@ func main() {
overall.Add(iloData.GetNagiosStatus())
}

// Retrieve the status from each controller and add the result
for _, controller := range controllers {
controllerStatus, desc := controller.GetNagiosStatus()
overall.Add(controllerStatus, desc)
countControllers++
// Load controller data
if !*ignoreController {
cntlrTable, err = cntlr.GetCpqDaCntlrTable(client)
if err != nil {
check.ExitError(err)
}

if len(cntlrTable.Snmp.Values) == 0 {
check.ExitRaw(3, "No HP controller data found!")
}

// Extract controller data from SNMP Table
controllers, err := cntlr.GetControllersFromTable(cntlrTable)

if err != nil {
check.ExitError(err)
}

// Retrieve the status from each controller and add the result
for _, controller := range controllers {
controllerStatus, desc := controller.GetNagiosStatus()
overall.Add(controllerStatus, desc)
countControllers++
}
}

// Retrieve the status from each drive and add the result
for _, drive := range drives {
driveStatus, desc := drive.GetNagiosStatus()
overall.Add(driveStatus, desc)
countDrives++
// Load drive data
if !*ignoreDrives {
driveTable, err = drive.GetCpqDaPhyDrvTable(client)
if err != nil {
check.ExitError(err)
}

if len(driveTable.Snmp.Values) == 0 {
check.ExitRaw(3, "No HP drive data found!")
}

// Extract drive data from SNMP Table
drives, err := drive.GetPhysicalDrivesFromTable(driveTable)
if err != nil {
check.ExitError(err)
}

// Retrieve the status from each drive and add the result
for _, drive := range drives {
driveStatus, desc := drive.GetNagiosStatus()
overall.Add(driveStatus, desc)
countDrives++
}
}

// Get the overall status for all subchecks
status := overall.GetStatus()

switch status {
Expand Down

0 comments on commit 9118a3b

Please sign in to comment.