Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 16 | #include "severity.hpp" |
| 17 | |
| 18 | namespace openpower |
| 19 | { |
| 20 | namespace pels |
| 21 | { |
| 22 | |
| 23 | using LogSeverity = phosphor::logging::Entry::Level; |
| 24 | |
Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 25 | namespace |
| 26 | { |
| 27 | |
| 28 | LogSeverity convertPELSeverityToOBMC(SeverityType pelSeverity) |
| 29 | { |
| 30 | LogSeverity logSeverity = LogSeverity::Error; |
| 31 | |
| 32 | const std::map<SeverityType, LogSeverity> severities{ |
| 33 | {SeverityType::nonError, LogSeverity::Informational}, |
| 34 | {SeverityType::recovered, LogSeverity::Informational}, |
| 35 | {SeverityType::predictive, LogSeverity::Warning}, |
| 36 | {SeverityType::unrecoverable, LogSeverity::Error}, |
| 37 | {SeverityType::critical, LogSeverity::Critical}, |
| 38 | {SeverityType::diagnostic, LogSeverity::Error}, |
| 39 | {SeverityType::symptom, LogSeverity::Warning}}; |
| 40 | |
| 41 | auto s = severities.find(pelSeverity); |
| 42 | if (s != severities.end()) |
| 43 | { |
| 44 | logSeverity = s->second; |
| 45 | } |
| 46 | |
| 47 | return logSeverity; |
| 48 | } |
| 49 | |
| 50 | } // namespace |
| 51 | |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 52 | uint8_t convertOBMCSeverityToPEL(LogSeverity severity) |
| 53 | { |
Matt Spinler | a7525aa | 2019-11-01 11:11:07 -0500 | [diff] [blame] | 54 | uint8_t pelSeverity = static_cast<uint8_t>(SeverityType::unrecoverable); |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 55 | switch (severity) |
| 56 | { |
| 57 | case (LogSeverity::Notice): |
| 58 | case (LogSeverity::Informational): |
| 59 | case (LogSeverity::Debug): |
Matt Spinler | a7525aa | 2019-11-01 11:11:07 -0500 | [diff] [blame] | 60 | pelSeverity = static_cast<uint8_t>(SeverityType::nonError); |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 61 | break; |
| 62 | |
| 63 | case (LogSeverity::Warning): |
Matt Spinler | a7525aa | 2019-11-01 11:11:07 -0500 | [diff] [blame] | 64 | pelSeverity = static_cast<uint8_t>(SeverityType::predictive); |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 65 | break; |
| 66 | |
| 67 | case (LogSeverity::Critical): |
Matt Spinler | a7525aa | 2019-11-01 11:11:07 -0500 | [diff] [blame] | 68 | pelSeverity = static_cast<uint8_t>(SeverityType::critical); |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 69 | break; |
| 70 | |
| 71 | case (LogSeverity::Emergency): |
| 72 | case (LogSeverity::Alert): |
| 73 | case (LogSeverity::Error): |
Matt Spinler | a7525aa | 2019-11-01 11:11:07 -0500 | [diff] [blame] | 74 | pelSeverity = static_cast<uint8_t>(SeverityType::unrecoverable); |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 75 | break; |
| 76 | } |
| 77 | |
| 78 | return pelSeverity; |
| 79 | } |
Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 80 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame^] | 81 | std::optional<LogSeverity> |
| 82 | fixupLogSeverity(LogSeverity obmcSeverity, SeverityType pelSeverity) |
Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 83 | { |
| 84 | bool isNonErrPelSev = (pelSeverity == SeverityType::nonError) || |
| 85 | (pelSeverity == SeverityType::recovered); |
| 86 | |
| 87 | bool isNonErrObmcSev = (obmcSeverity == LogSeverity::Notice) || |
| 88 | (obmcSeverity == LogSeverity::Informational) || |
| 89 | (obmcSeverity == LogSeverity::Debug); |
| 90 | |
| 91 | // If a nonError/recovered PEL, then the LogSeverity must be |
| 92 | // Notice/Informational/Debug, otherwise set it to Informational. |
| 93 | if (isNonErrPelSev && !isNonErrObmcSev) |
| 94 | { |
| 95 | return LogSeverity::Informational; |
| 96 | } |
| 97 | |
| 98 | // If a Notice/Informational/Debug LogSeverity, then the PEL |
| 99 | // severity must be nonError/recovered, otherwise set it |
| 100 | // to an appropriate value based on the actual PEL severity. |
| 101 | if (isNonErrObmcSev && !isNonErrPelSev) |
| 102 | { |
| 103 | return convertPELSeverityToOBMC(pelSeverity); |
| 104 | } |
| 105 | |
| 106 | // If PEL is critical, the LogSeverity should be as well. |
| 107 | if ((obmcSeverity != LogSeverity::Critical) && |
| 108 | (pelSeverity == SeverityType::critical)) |
| 109 | { |
| 110 | return LogSeverity::Critical; |
| 111 | } |
| 112 | |
| 113 | return std::nullopt; |
| 114 | } |
| 115 | |
Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 116 | } // namespace pels |
| 117 | } // namespace openpower |