Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 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 | */ |
| 16 | |
| 17 | #include "sensor_monitoring.hpp" |
| 18 | |
| 19 | #include "action_environment.hpp" |
| 20 | #include "action_utils.hpp" |
| 21 | #include "chassis.hpp" |
| 22 | #include "device.hpp" |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 23 | #include "error_logging_utils.hpp" |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 24 | #include "exception_utils.hpp" |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 25 | #include "rail.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 26 | #include "sensors.hpp" |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 27 | #include "system.hpp" |
| 28 | |
| 29 | #include <exception> |
| 30 | |
| 31 | namespace phosphor::power::regulators |
| 32 | { |
| 33 | |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 34 | void SensorMonitoring::execute(Services& services, System& system, |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 35 | Chassis& chassis, Device& device, Rail& rail) |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 36 | { |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 37 | // Notify sensors service that monitoring is starting for this rail |
| 38 | Sensors& sensors = services.getSensors(); |
| 39 | sensors.startRail(rail.getID(), device.getFRU(), |
| 40 | chassis.getInventoryPath()); |
| 41 | |
| 42 | // Read all sensors defined for this rail |
| 43 | bool errorOccurred{false}; |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 44 | try |
| 45 | { |
| 46 | // Create ActionEnvironment |
Bob King | 73eacee | 2020-10-23 13:58:02 +0800 | [diff] [blame] | 47 | ActionEnvironment environment{system.getIDMap(), device.getID(), |
| 48 | services}; |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 49 | |
| 50 | // Execute the actions |
| 51 | action_utils::execute(actions, environment); |
| 52 | } |
| 53 | catch (const std::exception& e) |
| 54 | { |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 55 | // Set flag to notify sensors service that an error occurred |
| 56 | errorOccurred = true; |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 57 | |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 58 | // Log error messages in journal for the first 3 errors |
| 59 | if (++errorCount <= 3) |
| 60 | { |
| 61 | services.getJournal().logError(exception_utils::getMessages(e)); |
| 62 | services.getJournal().logError( |
| 63 | "Unable to monitor sensors for rail " + rail.getID()); |
| 64 | } |
| 65 | |
| 66 | // Create error log entry if this type hasn't already been logged |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 67 | error_logging_utils::logError(std::current_exception(), |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 68 | Entry::Level::Warning, services, |
| 69 | errorHistory); |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 70 | } |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 71 | |
| 72 | // Notify sensors service that monitoring has ended for this rail |
| 73 | sensors.endRail(errorOccurred); |
Bob King | 833b8e0 | 2020-06-11 14:56:38 +0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | } // namespace phosphor::power::regulators |