1 #pragma once
2 
3 #include "elog_entry.hpp"
4 #include "log_manager.hpp"
5 #include "paths.hpp"
6 #include "repository.hpp"
7 
8 namespace openpower
9 {
10 namespace pels
11 {
12 
13 using namespace phosphor::logging;
14 
15 /**
16  * @brief PEL manager object
17  */
18 class Manager
19 {
20   public:
21     Manager() = delete;
22     ~Manager() = default;
23     Manager(const Manager&) = default;
24     Manager& operator=(const Manager&) = default;
25     Manager(Manager&&) = default;
26     Manager& operator=(Manager&&) = default;
27 
28     /**
29      * @brief constructor
30      *
31      * @param[in] logManager - internal::Manager object
32      */
33     explicit Manager(internal::Manager& logManager) :
34         _logManager(logManager), _repo(getPELRepoPath())
35     {
36     }
37 
38     /**
39      * @brief Creates a PEL based on the OpenBMC event log contents.  If
40      *        a PEL was passed in via the RAWPEL specifier in the
41      *        additionalData parameter, use that instead.
42      *
43      * @param[in] message - the event log message property
44      * @param[in] obmcLogID - the corresponding OpenBMC event log id
45      * @param[in] timestamp - the Timestamp property
46      * @param[in] severity - the event log severity
47      * @param[in] additionalData - the AdditionalData property
48      * @param[in] associations - the Associations property
49      */
50     void create(const std::string& message, uint32_t obmcLogID,
51                 uint64_t timestamp, Entry::Level severity,
52                 const std::vector<std::string>& additionalData,
53                 const std::vector<std::string>& associations);
54 
55     /**
56      * @brief Erase a PEL based on its OpenBMC event log ID
57      *
58      * @param[in] obmcLogID - the corresponding OpenBMC event log id
59      */
60     void erase(uint32_t obmcLogID);
61 
62     /** @brief Says if an OpenBMC event log may not be manually deleted at this
63      *         time because its corresponding PEL cannot be.
64      *
65      * There are PEL retention policies that can prohibit the manual deletion
66      * of PELs (and therefore OpenBMC event logs).
67      *
68      * @param[in] obmcLogID - the OpenBMC event log ID
69      * @return bool - true if prohibited
70      */
71     bool isDeleteProhibited(uint32_t obmcLogID);
72 
73   private:
74     /**
75      * @brief Adds a received raw PEL to the PEL repository
76      *
77      * @param[in] rawPelPath - The path to the file that contains the
78      *                         raw PEL.
79      * @param[in] obmcLogID - the corresponding OpenBMC event log id
80      */
81     void addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID);
82 
83     /**
84      * @brief Creates a PEL based on the OpenBMC event log contents.
85      *
86      * @param[in] message - The event log message property
87      * @param[in] obmcLogID - the corresponding OpenBMC event log id
88      * @param[in] timestamp - The timestamp property
89      * @param[in] severity - The event log severity
90      * @param[in] additionalData - The AdditionalData property
91      * @param[in] associations - The associations property
92      */
93     void createPEL(const std::string& message, uint32_t obmcLogID,
94                    uint64_t timestamp, Entry::Level severity,
95                    const std::vector<std::string>& additionalData,
96                    const std::vector<std::string>& associations);
97 
98     /**
99      * @brief Reference to phosphor-logging's Manager class
100      */
101     internal::Manager& _logManager;
102 
103     /**
104      * @brief The PEL repository object
105      */
106     Repository _repo;
107 };
108 
109 } // namespace pels
110 } // namespace openpower
111