Skip to content

Commit

Permalink
feat(supermicro): Reset Intrusion Alert if alerting
Browse files Browse the repository at this point in the history
  • Loading branch information
BirknerAlex committed Jun 4, 2024
1 parent 06312b0 commit 95992ee
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ docker run -d -p 0.0.0.0:9096:9096 \

Redfish Exporter is providing generic metrics fetched from Redfish endpoints.

## Example request

```bash
curl http://localhost:9096/metrics?host=https://<ip>
```

## Pre Actions

This exporter also allows to handle pre actions before fetching metrics. This can be useful to enable metrics on the server
or handle specific errors before fetching metrics.

Currently the following actions are supported:

- reset_intrusion_alert - Reset intrusion alert on the server

### Tested with
* HPE ILO4
* HPE ILO5
Expand Down
4 changes: 4 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ redfish:
verifyTls: true
username: Administrator
password: toor

# Actions to perform before collecting metrics
preActions:
- reset_intrusion_alert
27 changes: 27 additions & 0 deletions pkg/actions/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package actions

import (
"fmt"

"github.com/g-portal/redfish_exporter/pkg/api"
"github.com/g-portal/redfish_exporter/pkg/config"
)

const (
ResetIntrusionAlert config.Action = "reset_intrusion_alert"
)

func Execute(action config.Action, client api.Client) error {
switch action {
case ResetIntrusionAlert:
err := client.ResetChassisIntrusion()
if err != nil {
return fmt.Errorf("error resetting chassis intrusion: %w", err)
}

return nil
default:
//nolint: err113
return fmt.Errorf("unknown action %s", action)
}
}
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type Client interface {
Connect(host, username, password string, tlsVerify bool) error
GetMetrics() (*prometheus.Registry, error)
ResetChassisIntrusion() error
Disconnect() error
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/format.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package config

type Action string

type Config struct {
Verbose bool `yaml:"verbose"`

Expand All @@ -13,4 +15,6 @@ type Config struct {
// Verify Whether to verify the TLS certificate
VerifyTLS bool `yaml:"verifyTls"`
} `yaml:"redfish"`

PreActions []Action `yaml:"preActions"`
}
28 changes: 28 additions & 0 deletions pkg/drivers/redfish/intrusion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package redfish

import (
"fmt"

"github.com/stmcginnis/gofish/redfish"
)

func (rf *Redfish) ResetChassisIntrusion() error {
chassisCollection, err := rf.client.Service.Chassis()
if err != nil {
return fmt.Errorf("error getting chassis: %w", err)
}

for _, chassis := range chassisCollection {
if chassis.PhysicalSecurity.IntrusionSensor == redfish.HardwareIntrusionIntrusionSensor {
if err = chassis.Patch(chassis.ODataID, map[string]interface{}{
"PhysicalSecurity": map[string]interface{}{
"IntrusionSensor": redfish.NormalIntrusionSensor,
},
}); err != nil {
return fmt.Errorf("error updating chassis: %w", err)
}
}
}

return nil
}
12 changes: 12 additions & 0 deletions pkg/metric/handler.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package metric

import (
"fmt"
"log"
"net/http"

"github.com/g-portal/redfish_exporter/pkg/actions"
"github.com/g-portal/redfish_exporter/pkg/api"
"github.com/g-portal/redfish_exporter/pkg/config"
"github.com/gin-gonic/gin"
Expand All @@ -27,6 +29,16 @@ func Handle(ctx *gin.Context) {
}
}()

// Execute pre actions
for _, action := range config.GetConfig().PreActions {
if err = actions.Execute(action, client); err != nil {
ctx.JSON(http.StatusInternalServerError,
gin.H{"error": fmt.Errorf("error executing pre action %q: %w", action, err).Error()})

return
}
}

// Get metrics from the client.
registry, err := client.GetMetrics()
if err != nil {
Expand Down

0 comments on commit 95992ee

Please sign in to comment.