From a40c21130c8df86ffbbf53628db29ba2517abd67 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Thu, 23 May 2024 15:49:15 -0500 Subject: [PATCH] Handle LogService v1.3.0 ClearLog payload Starting with the 1.3.0 schema, the ClearLog call expects to have the etag of the LogEntryCollection as an argument. This adds a retry to make sure we cover both the pre-1.3 and post-1.3 methods. Signed-off-by: Sean McGinnis --- redfish/logservice.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/redfish/logservice.go b/redfish/logservice.go index d5080e16..1766e588 100644 --- a/redfish/logservice.go +++ b/redfish/logservice.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "reflect" + "strings" "github.com/stmcginnis/gofish/common" ) @@ -241,6 +242,29 @@ func (logservice *LogService) FilteredEntries(options ...common.FilterOption) ([ // ClearLog shall delete all entries found in the Entries collection for this // Log Service. func (logservice *LogService) ClearLog() error { + err := logservice.Post(logservice.clearLogTarget, struct{}{}) + if err == nil { + return nil + } + + // As of LogService 1.3.0, need to pass the LogEntryCollection etag. If our first attempt failed, try that. + entryCollection := &struct { + ETag string `json:"@odata.etag"` + }{} + + retryErr := logservice.Get(logservice.GetClient(), logservice.entries, entryCollection) + if retryErr == nil { + payload := struct { + LogEntriesETag string + }{LogEntriesETag: strings.Trim(entryCollection.ETag, "\"")} + + retryErr = logservice.Post(logservice.clearLogTarget, payload) + if retryErr == nil { + return nil + } + } + + // Fall back to broken implementation to workaround vendor bug t := struct { Action string }{