| #ifndef PLATFORMS_VBMC_PLATFORM_EIGER_EVENT_H_ |
| #define PLATFORMS_VBMC_PLATFORM_EIGER_EVENT_H_ |
| |
| #include <cstdint> |
| #include <optional> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "absl/container/flat_hash_map.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/string_view.h" |
| #include "proxy_config.pb.h" |
| #include "events.pb.h" |
| #include "vendor_events.pb.h" |
| |
| namespace milotic { |
| |
| inline constexpr int kInvalidReasonId = -1; |
| |
| enum class EventSeverity : std::uint8_t { |
| kOk = 0, |
| kLog, |
| kWarning, |
| kEmergent, |
| kCritical, |
| }; |
| |
| std::string EventSeverityToString(EventSeverity severity); |
| absl::StatusOr<EventSeverity> StringToEventSeverity(absl::string_view severity); |
| |
| struct EventParseConfig { |
| absl::flat_hash_map<int, platforms_vbmc::VendorEvent> registry; |
| milotic_grpc_proxy::EventParse event_parse; |
| }; |
| |
| // MessageId is of the format |
| // <MessageRegistryPrefix>.<MajorVersion>.<MinorVersion>.<MessageKey> |
| struct EventMessageId { |
| std::string message_registry_prefix; |
| std::string major_version; |
| std::string minor_version; |
| std::string message_key; |
| }; |
| |
| // Event |
| // Used to model Redfish Event received from RMC |
| // There are 3 types of Events currently |
| // - RedfishEvent: New events coming from RMC |
| // - ReplayedEvent: Already processed events to bootstrap MachineState |
| // - InitExpiryEvent: One time event used to transition plugin from Init to |
| // Serving state |
| class Event { |
| public: |
| struct CperEventData { |
| std::string origin; |
| int memory_errors = 0; |
| int cpu_errors = 0; |
| }; |
| |
| Event() = default; |
| Event(absl::string_view event_json, int64_t event_id, EventSeverity severity, |
| int reason_id = kInvalidReasonId, |
| std::optional<CperEventData> cper_event_data = std::nullopt) |
| : event_id_(event_id), |
| reason_id_(reason_id), |
| severity_(severity), |
| event_json_(std::string(event_json)), |
| cper_event_data_(std::move(cper_event_data)) {} |
| |
| // Movable |
| Event(Event&& other) = default; |
| Event& operator=(Event&& other) = default; |
| |
| // Copyable (for cache storage) |
| Event(const Event& other) = default; |
| Event& operator=(const Event& other) = default; |
| |
| int64_t event_id() const { return event_id_; } |
| EventSeverity severity() const { return severity_; } |
| std::string event_json() const { return event_json_; } |
| int reason_id() const { return reason_id_; } |
| bool is_cper_event() const { return cper_event_data_.has_value(); } |
| const std::optional<CperEventData>& cper_event_data() const { |
| return cper_event_data_; |
| } |
| |
| std::optional<CperEventData>& cper_event_data() { |
| return cper_event_data_; |
| } |
| |
| bool IsEmpty() const { return event_id_ == 0; } |
| |
| platforms_vbmc::OtsUpdate ToProto() const; |
| static absl::StatusOr<std::vector<Event>> ParseRedfishEvent( |
| const EventParseConfig& parse_config, absl::string_view event_json); |
| static absl::StatusOr<std::vector<Event>> ParseReplayEvents( |
| const EventParseConfig& parse_config, absl::string_view event_json); |
| |
| private: |
| int64_t event_id_ = 0; |
| int reason_id_; |
| EventSeverity severity_; |
| std::string event_json_; |
| std::optional<CperEventData> cper_event_data_; |
| }; |
| |
| } // namespace milotic |
| |
| #endif // PLATFORMS_VBMC_PLATFORM_EIGER_EVENT_H_ |