@@ -1140,3 +1140,106 @@ func (r *RedfishBaseBMC) DeleteEventSubscription(ctx context.Context, uri string
11401140 }
11411141 return nil
11421142}
1143+
1144+ // GetMetricReport retrieves the current metric report from the BMC via TelemetryService.
1145+ // If TelemetryService is not available, returns an empty report (fallback to events).
1146+ func (r * RedfishBaseBMC ) GetMetricReport (ctx context.Context ) (MetricsReport , error ) {
1147+ service := r .client .GetService ()
1148+
1149+ // Try TelemetryService first (Redfish 2018.3+)
1150+ telemetry , err := service .TelemetryService ()
1151+ if err == nil && telemetry != nil {
1152+ // Get metric reports
1153+ reports , err := telemetry .MetricReports ()
1154+ if err == nil && len (reports ) > 0 {
1155+ // Use the first available report and convert to our format
1156+ report := reports [0 ]
1157+ metricValues := make ([]MetricValue , 0 )
1158+
1159+ // Try to extract metric values - schema may vary by vendor
1160+ // The report.MetricValues is a slice of report-specific values
1161+ // We'll create a simple representation
1162+ for i := 0 ; i < len (report .MetricValues ); i ++ {
1163+ metricValues = append (metricValues , MetricValue {
1164+ MetricID : fmt .Sprintf ("Metric%d" , i ),
1165+ MetricProperty : report .ODataID ,
1166+ MetricValue : fmt .Sprintf ("%v" , report .MetricValues [i ]),
1167+ MetricValueKind : "Gauge" ,
1168+ Timestamp : time .Now ().Format (time .RFC3339 ),
1169+ })
1170+ }
1171+
1172+ return MetricsReport {
1173+ ODataID : report .ODataID ,
1174+ ODataType : report .ODataType ,
1175+ ID : report .ID ,
1176+ Name : report .Name ,
1177+ MetricValues : metricValues ,
1178+ }, nil
1179+ }
1180+ }
1181+
1182+ // Fallback: Return empty report - polling will rely on event subscriptions or vendor-specific implementations
1183+ return MetricsReport {
1184+ ID : "EmptyMetrics" ,
1185+ Name : "No TelemetryService available" ,
1186+ MetricValues : []MetricValue {},
1187+ }, nil
1188+ }
1189+
1190+ // GetEventLog retrieves recent events from the BMC's System Event Log (SEL).
1191+ // Returns events from the last 10 minutes by default.
1192+ func (r * RedfishBaseBMC ) GetEventLog (ctx context.Context ) ([]Event , error ) {
1193+ service := r .client .GetService ()
1194+ systems , err := service .Systems ()
1195+ if err != nil {
1196+ return nil , fmt .Errorf ("failed to get systems: %w" , err )
1197+ }
1198+ if len (systems ) == 0 {
1199+ return nil , fmt .Errorf ("no systems found" )
1200+ }
1201+
1202+ system := systems [0 ]
1203+
1204+ // Get log services
1205+ logServices , err := system .LogServices ()
1206+ if err != nil {
1207+ return nil , fmt .Errorf ("failed to get log services: %w" , err )
1208+ }
1209+
1210+ events := []Event {}
1211+
1212+ // Query each log service
1213+ for _ , logService := range logServices {
1214+ entries , err := logService .Entries ()
1215+ if err != nil {
1216+ continue // Skip log services that fail
1217+ }
1218+
1219+ // Filter to recent entries (last 10 minutes)
1220+ cutoff := time .Now ().Add (- 10 * time .Minute )
1221+
1222+ for _ , entry := range entries {
1223+ // Parse timestamp
1224+ var entryTime time.Time
1225+ if entry .Created != "" {
1226+ entryTime , _ = time .Parse (time .RFC3339 , entry .Created )
1227+ }
1228+
1229+ // Skip old entries
1230+ if ! entryTime .IsZero () && entryTime .Before (cutoff ) {
1231+ continue
1232+ }
1233+
1234+ events = append (events , Event {
1235+ EventID : entry .ID ,
1236+ Message : entry .Message ,
1237+ Severity : string (entry .Severity ),
1238+ EventTimestamp : entry .Created ,
1239+ OriginOfCondition : entry .ODataID ,
1240+ })
1241+ }
1242+ }
1243+
1244+ return events , nil
1245+ }
0 commit comments