Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hpe events test #189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions oem/dell/eventservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func TestEventService(t *testing.T) {
}
}

// TestHpeSubmitTestEvent tests SubmitTestEvent for Dell using a mock server.
func TestDellSubmitTestEvent(t *testing.T) {
const redfishBaseURL = "/redfish/v1/"
var (
Expand Down Expand Up @@ -219,6 +220,7 @@ func TestDellSubmitTestEvent(t *testing.T) {
req.URL.String() == "/redfish/v1/EventService" &&
requestCounter == 2 {
requestCounter++

rw.Write([]byte(eventServiceBody)) // nolint:errcheck
} else if req.Method == http.MethodPost && // SubmitTestEvent
req.URL.String() == "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent" &&
Expand Down
79 changes: 79 additions & 0 deletions oem/hpe/eventservice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package hpe

import (
"encoding/json"
"fmt"
"net/http"
"time"

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

type PayloadType struct {
EventID string `json:"EventID"`
EventTimestamp string `json:"EventTimestamp"`
EventType string `json:"EventType"`
Message string
MessageArgs []string
MessageID string `json:"MessageId"`
OriginOfCondition string
Severity string
}

// EventService is the Hpe-specific handler for the EventService instance.
type EventService struct {
redfish.EventService
}

// SubmitTestEvent sends event according to msgId and returns error
// more info https://hewlettpackard.github.io/iLOAmpPack-Redfish-API-Docs/#submitting-a-test-event
func (eventservice *EventService) SubmitTestEvent(eventID, messageID, eType, message string) error {
const condition = "/redfish/v1/Systems/1/"
const severity = "OK"

var messageArgs = []string{"NoAMS", "Busy", "Cached"}

payload := PayloadType{
EventID: eventID,
EventTimestamp: time.Now().Format(time.RFC3339), // "2019-07-29T15:13:49Z",
EventType: eType, // redfish.SupportedEventTypes["Alert"],
Message: message,
MessageArgs: messageArgs,
MessageID: messageID,
OriginOfCondition: condition,
Severity: severity,
}
resp, err := eventservice.Client.Post(eventservice.SubmitTestEventTarget, payload)

if err != nil {
return fmt.Errorf("failed to send submitTestEvent due to: %w", err)
}
defer resp.Body.Close()

valid := map[int]bool{
http.StatusOK: true,
http.StatusNoContent: true,
http.StatusCreated: true}

if !valid[resp.StatusCode] {
return fmt.Errorf("on send event received response: %v due to: %s", resp.StatusCode, resp.Body)
}

return nil
}

// FromEventService converts a standard EventService object to the OEM implementation.
func FromEventService(eventservice *redfish.EventService) (*EventService, error) {
es := &EventService{}
err := json.Unmarshal(eventservice.RawData, es)
if err != nil {
return nil, err
}

es.SetClient(eventservice.Client)
return es, nil
}
Loading