forked from openbmc/phosphor-logging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_manager.hpp
944 lines (835 loc) · 30.1 KB
/
log_manager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
#pragma once
#include "bin.hpp"
#include "elog_block.hpp"
#include "elog_entry.hpp"
#ifdef ENABLE_LOG_STREAMING
#include "log_streamer.hpp"
#endif
#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
#include "xyz/openbmc_project/Logging/Capacity/server.hpp"
#include "xyz/openbmc_project/Logging/Create/server.hpp"
#include "xyz/openbmc_project/Logging/Entry/server.hpp"
#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
#include "xyz/openbmc_project/Logging/Namespace/server.hpp"
#include "xyz/openbmc_project/Logging/error.hpp"
#include <nlohmann/json.hpp>
#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/source/time.hpp>
#include <xyz/openbmc_project/Common/File/error.hpp>
#include <fstream>
#include <list>
#include <vector>
namespace phosphor
{
namespace logging
{
namespace fs = std::filesystem;
extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
extern const std::map<std::string, level> g_errLevelMap;
using CreateIface = sdbusplus::server::xyz::openbmc_project::logging::Create;
using DeleteAllIface =
sdbusplus::server::xyz::openbmc_project::collection::DeleteAll;
using NamespaceIface =
sdbusplus::xyz::openbmc_project::Logging::server::Namespace;
using CapacityIface =
sdbusplus::xyz::openbmc_project::Logging::server::Capacity;
using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
using LogsCleared =
sdbusplus::xyz::openbmc_project::Logging::Error::LogsCleared;
namespace details
{
template <typename... T>
using ServerObject = typename sdbusplus::server::object_t<T...>;
using ManagerIface =
sdbusplus::server::xyz::openbmc_project::logging::internal::Manager;
} // namespace details
constexpr size_t ffdcFormatPos = 0;
constexpr size_t ffdcSubtypePos = 1;
constexpr size_t ffdcVersionPos = 2;
constexpr size_t ffdcFDPos = 3;
using FFDCEntry = std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
sdbusplus::message::unix_fd>;
using FFDCEntries = std::vector<FFDCEntry>;
typedef std::variant<bool, uint32_t, int64_t, std::string, std::vector<uint8_t>,
std::vector<std::string>, uint64_t>
varType;
typedef std::map<std::string, varType> propMap;
typedef std::map<std::string, propMap> objMap;
using ManagedObject = std::map<sdbusplus::message::object_path, objMap>;
namespace internal
{
/** @class Manager
* @brief OpenBMC logging manager implementation.
* @details A concrete implementation for the
* xyz.openbmc_project.Logging.Internal.Manager DBus API.
*/
class Manager : public details::ServerObject<details::ManagerIface>
{
public:
Manager() = delete;
Manager(const Manager&) = delete;
Manager& operator=(const Manager&) = delete;
Manager(Manager&&) = delete;
Manager& operator=(Manager&&) = delete;
virtual ~Manager()
{
#ifdef ENABLE_LOG_STREAMING
logSocket.stop();
#endif
}
/** @brief Constructor to put object onto bus at a dbus path.
* @param[in] bus - Bus to attach to.
* @param[in] path - Path to attach at.
*/
Manager(sdbusplus::bus_t& bus, const std::string& objPath);
/**
* @fn parseJson
* @brief Method to parse input json config
*
* @param jsonPath
* @return true
* @return false
*/
uint32_t parseJson(const std::string& jsonPath)
{
std::ifstream jsonStream;
nlohmann::json data;
bool validJsonConfig = false;
try
{
jsonStream.open(jsonPath);
if (jsonStream.is_open())
{
data = nlohmann::json::parse(jsonStream, nullptr, false);
validJsonConfig = true;
jsonStream.close();
}
else
{
lg2::error("Couldn't open argument file passed in. Using only "
"default namespaces.");
return 1;
}
}
catch (const std::exception& e)
{
lg2::error("Failed to open/parse JSON file: {ERROR}", "ERROR",
e.what());
return 2;
}
std::vector<std::string> dirsToPreserve{};
if (validJsonConfig && !data.is_discarded())
{
for (auto& item : data["Namespaces"].items())
{
if (item.value()["ID"].is_string())
{
auto id =
item.value()["ID"].get_ptr<nlohmann::json::string_t*>();
dirsToPreserve.push_back(item.value()["ID"]);
auto errorCap =
item.value()["ErrorCapacity"]
.get_ptr<nlohmann::json::number_unsigned_t*>();
auto errorInfoCap =
item.value()["InfoErrorCapacity"]
.get_ptr<nlohmann::json::number_unsigned_t*>();
bool persistInfoLog =
true; // by default persist all info logs
if (item.value().contains("PersistInfoLog"))
{
persistInfoLog = item.value()["PersistInfoLog"];
}
auto bin = phosphor::logging::internal::Bin(
std::string(*id), *errorCap, *errorInfoCap,
std::string(ERRLOG_PERSIST_PATH) + "/" +
std::string(*id),
persistInfoLog);
if (std::string(*id) == "SEL")
{
bin.jsonPath = jsonPath;
}
this->addBin(bin);
}
}
}
else
{
lg2::error("Invalid JSON file passed.");
return 3;
}
std::filesystem::path logDir(std::string{ERRLOG_PERSIST_PATH});
// clear errlog path, skip configured dirnames, skip non-dirs
for (const auto& p : std::filesystem::directory_iterator(logDir))
{
auto dirName = p.path().filename().string();
if (std::find(dirsToPreserve.begin(), dirsToPreserve.end(),
dirName) != dirsToPreserve.end())
{
continue;
}
std::error_code ec{};
if (!std::filesystem::is_directory(p.path(), ec))
{
continue;
}
ec.clear();
std::filesystem::remove_all(p.path(), ec);
if (ec.value() != 0)
{
lg2::error("Failed to delete directory: {PATH}", "PATH",
p.path().string());
}
}
return 0;
}
uint32_t parseRWConfigJson(const std::string& jsonPath)
{
lg2::info("parseRWConfigJson {PATH}", "PATH", jsonPath);
this->rwConfigJsonPath = jsonPath;
std::ifstream jsonStream;
nlohmann::json data;
try
{
jsonStream.open(jsonPath);
if (jsonStream.is_open())
{
data = nlohmann::json::parse(jsonStream, nullptr);
jsonStream.close();
if (!data.is_object())
{
throw std::invalid_argument("R/W config parse result is "
"not an object");
}
}
else
{
lg2::info("Persistent R/W config file {FILE} doesn't exist. "
"Using default values.",
"FILE", jsonPath);
return 0; // It's not an error for this file to not exist
}
}
catch (const std::exception& e)
{
lg2::error("Failed to open/parse JSON file: {ERROR}", "ERROR",
e.what());
std::error_code ec{};
fs::remove(jsonPath, ec);
if (ec.value() != 0)
{
lg2::error("Also failed to delete malformed JSON file!");
}
throw; // rethrow to parseErrHandler
}
bool logPurgePolicy = data.value("LogPurgePolicy", false);
lg2::info(
"Set log purge policy enabled state from R/W config to {STATE}",
"STATE", logPurgePolicy);
this->_autoPurgeResolved = logPurgePolicy;
return 0;
}
uint32_t updateRWConfigJson()
{
nlohmann::json data({{"LogPurgePolicy", this->_autoPurgeResolved}});
std::ofstream jsonStream;
try
{
jsonStream.open(this->rwConfigJsonPath);
if (jsonStream.is_open())
{
jsonStream << data;
jsonStream.close();
}
else
{
lg2::error("Persistent R/W config file {FILE} could not be"
"opened for writing.",
"FILE", this->rwConfigJsonPath);
return 1;
}
}
catch (const std::exception& e)
{
lg2::error("Failed to open/write JSON file: {ERROR}", "ERROR",
e.what());
return 2;
}
return 0;
}
void updateConfigJsonWithSelCapacity(const std::string& jsonPath,
size_t errorInfoCapacity)
{
std::ifstream jsonInputStream;
std::ofstream jsonOutputStream;
nlohmann::json data;
try
{
jsonInputStream.open(jsonPath);
if (jsonInputStream.is_open())
{
data = nlohmann::json::parse(jsonInputStream, nullptr, false);
jsonInputStream.close();
}
else
{
lg2::error("Couldn't open argument file passed in.");
throw sdbusplus::xyz::openbmc_project::Common::File::Error::
Open();
}
}
catch (const std::exception& e)
{
lg2::error("Failed to update JSON file: {ERROR}", "ERROR",
e.what());
throw;
}
for (auto& item : data["Namespaces"].items())
{
if (item.value()["ID"].is_string())
{
auto id =
item.value()["ID"].get_ptr<nlohmann::json::string_t*>();
if (std::string(*id) == "SEL")
{
auto errorInfoCap =
item.value()["InfoErrorCapacity"]
.get_ptr<nlohmann::json::number_unsigned_t*>();
*errorInfoCap = errorInfoCapacity;
}
}
}
try
{
jsonOutputStream.open(jsonPath);
if (jsonOutputStream.is_open())
{
jsonOutputStream << data;
jsonOutputStream.close();
}
else
{
lg2::error(
"Config file {FILE} could not be opened for writing.",
"FILE", jsonPath);
throw sdbusplus::xyz::openbmc_project::Common::File::Error::
Open();
;
}
}
catch (const std::exception& e)
{
lg2::error("Failed to open/write JSON file: {ERROR}", "ERROR",
e.what());
throw;
}
}
/* @fn getSelPolicy()
* @brief retrive current sel policy from Settingsd.
*/
virtual std::string getSelPolicy();
/*
* @fn commit()
* @brief sd_bus Commit method implementation callback.
* @details Create an error/event log based on transaction id and
* error message.
* @param[in] transactionId - Unique identifier of the journal entries
* to be committed.
* @param[in] errMsg - The error exception message associated with the
* error log to be committed.
*/
uint32_t commit(uint64_t transactionId, std::string errMsg) override;
/*
* @fn commit()
* @brief sd_bus CommitWithLvl method implementation callback.
* @details Create an error/event log based on transaction id and
* error message.
* @param[in] transactionId - Unique identifier of the journal entries
* to be committed.
* @param[in] errMsg - The error exception message associated with the
* error log to be committed.
* @param[in] errLvl - level of the error
*/
uint32_t commitWithLvl(uint64_t transactionId, std::string errMsg,
uint32_t errLvl) override;
/** @brief Erase specified entry d-bus object
*
* @param[in] entryId - unique identifier of the entry
*/
void erase(uint32_t entryId);
/** @brief Construct error d-bus objects from their persisted
* representations.
*/
void restore();
/** @brief Erase all error log entries
*
* @return size_t - count of erased entries
*/
size_t eraseAll()
{
this->cancelPendingLogDeletion();
size_t entriesSize = entries.size();
auto iter = entries.begin();
while (iter != entries.end())
{
auto e = iter->first;
++iter;
erase(e);
}
entryId = 0;
lastCreatedTimeStamp = 0;
return entriesSize;
}
/** @brief Returns the count of high severity errors
*
* @return int - count of real errors
*/
int getRealErrSize(const std::string& binName = DEFAULT_BIN_NAME);
/** @brief Returns the count of Info errors
*
* @return int - count of info errors
*/
int getInfoErrSize(const std::string& binName = DEFAULT_BIN_NAME);
/** @brief Returns the number of blocking errors
*
* @return int - count of blocking errors
*/
int getBlockingErrSize()
{
return blockingErrors.size();
}
/** @brief Returns the number of property change callback objects
*
* @return int - count of property callback entries
*/
int getEntryCallbackSize()
{
return propChangedEntryCallback.size();
}
/**
* @brief Returns the sdbusplus bus object
*
* @return sdbusplus::bus_t&
*/
sdbusplus::bus_t& getBus()
{
return busLog;
}
/**
* @brief Returns the ID of the last created entry
*
* @return uint32_t - The ID
*/
uint32_t lastEntryID() const
{
return entryId;
}
/**
* @brief Returns the timestamp of the last created entry
*
* @return uint64_t - The Timestamp
*/
uint64_t lastEntryTimestamp() const
{
return lastCreatedTimeStamp;
}
void addBin(Bin& bin)
{
// Create a directory to persist errors for default path
std::filesystem::create_directories(bin.persistLocation);
// Insert into internal DS to keep track
binNameMap.insert(std::make_pair(bin.name, bin));
}
auto getBin(const std::string& binName)
{
return binNameMap[binName];
}
/** @brief Delete logs per namespace
*
* Some description
*
* @param[in] nspace - Namespace String
*/
bool
deleteAll(const std::string& nspace,
sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level
severity);
/** @brief Get logs per namespace
*
* Some description
*
* @param[in] nspace - Namespace String
*/
ManagedObject getAll(const std::string& nspaces,
NamespaceIface::ResolvedFilterType rfilter);
ManagedObject getAll(NamespaceIface::ResolvedFilterType rfilter);
/** @brief Get logs per namespace
*
* Gets Stats about Phosphor Logging Entries
*
* Currently returns lastEntryId, lastCreatedEntryTimeStamp
*
*/
std::tuple<uint32_t, uint64_t> getStats(const std::string& nspace);
/**
* @brief Gets the configuration about purging Resolved Logs
* @return true if Resolved Logs are currently purged, false otherwise
*/
bool getAutoPurgeResolved();
/**
* @brief Sets a new configuration for purging or not Resolved Logs
* @param [in] confPurgeResolvedLogs, if true Resolved Logs will be purged
* otherwise kept
*/
void setAutoPurgeResolved(bool confPurgeResolvedLogs);
/**
* @brief Adds a entry ID to the list of logs to be deleted asynchronously
*
* @param [in] entryId - entry ID of log to delete
*/
void addPendingLogDelete(uint32_t entryId);
/**
* @brief Get the number of log entries pending deletion (for unit tests)
*/
size_t getPendingLogDeleteCount()
{
return _pendingPurgeEvents.size();
}
/**
* @brief called from event loop to delete pending logs (one log per call)
*/
void pendingLogDeleteCallback();
/**
* @brief called when pending deletions should be cancelled
*
* This occurs in the following situations:
* - Log purge policy setting is disabled
* - eraseAll is called
*/
void cancelPendingLogDeletion();
/** @brief Configure the error info capacity.
*
* @param[in] infoLogCapacity - capacity of error info event
* @return the error info capacity
*/
size_t setInfoLogCapacity(size_t infoLogCapacity);
/** @brief Get the error info capacity.
*
* @return the error info capacity
*/
size_t getInfoLogCapacity();
/** @brief Creates an event log, and accepts FFDC files
*
* This is the same as create(), but also takes an FFDC argument.
*
* The FFDC argument is a vector of tuples that allows one to pass in file
* descriptors for files that contain FFDC (First Failure Data Capture).
* These will be passed to any event logging extensions.
*
* @param[in] errMsg - The error exception message associated with the
* error log to be committed.
* @param[in] severity - level of the error
* @param[in] additionalData - The AdditionalData property for the error
* @param[in] ffdc - A vector of tuples that allows one to pass in file
* descriptors for files that contain FFDC (First
* Failure Data Capture). These will be passed to any
* event logging extensions.
*/
void create(const std::string& message, Severity severity,
const std::map<std::string, std::string>& additionalData,
const FFDCEntries& ffdc = FFDCEntries{});
/** @brief Common wrapper for creating an Entry object
*
* @return true if quiesce on error setting is enabled, false otherwise
*/
bool isQuiesceOnErrorEnabled();
/** @brief Create boot block association and quiesce host if running
*
* @param[in] entryId - The ID of the phosphor logging error
*/
void quiesceOnError(const uint32_t entryId);
/** @brief Check if inventory callout present in input entry
*
* @param[in] entry - The error to check for callouts
*
* @return true if inventory item in associations, false otherwise
*/
bool isCalloutPresent(const Entry& entry);
/** @brief Check (and remove) entry being erased from blocking errors
*
* @param[in] entryId - The entry that is being erased
*/
void checkAndRemoveBlockingError(uint32_t entryId);
/** @brief Persistent map of Entry dbus objects and their ID */
std::map<uint32_t, std::unique_ptr<Entry>> entries;
/** @brief Persistent map of entry id to bin Name */
std::map<uint32_t, std::string> binEntryMap;
#ifdef ENABLE_LOG_STREAMING
/** @brief Starts SEL streaming */
bool startLogSocket()
{
return logSocket.start();
}
#endif
private:
/** @brief Persistent map of namespaces structure and their strings */
std::map<std::string, Bin> binNameMap;
/*
* @fn _commit()
* @brief commit() helper
* @param[in] transactionId - Unique identifier of the journal entries
* to be committed.
* @param[in] errMsg - The error exception message associated with the
* error log to be committed.
* @param[in] errLvl - level of the error
*/
void _commit(uint64_t transactionId, std::string&& errMsg,
Entry::Level errLvl);
/** @brief Call metadata handler(s), if any. Handlers may create
* associations.
* @param[in] errorName - name of the error
* @param[in] additionalData - list of metadata (in key=value format)
* @param[out] objects - list of error's association objects
*/
std::vector<std::string> processMetadata(
const std::string& errorName, std::vector<std::string>& additionalData,
const std::map<std::string,
const std::function<std::string(Entry&, std::string&)>>&
fnMap,
AssociationList& objects) const;
/** @brief Reads the BMC code level
*
* @return std::string - the version string
*/
static std::string readFWVersion();
/** @brief Call any create() functions provided by any extensions.
* This is called right after an event log is created to allow
* extensions to create their own log based on this one.
*
* @param[in] entry - the new event log entry
* @param[in] ffdc - A vector of FFDC file info
*/
void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
/** @brief Common wrapper for creating an Entry object
*
* @param[in] errMsg - The error exception message associated with the
* error log to be committed.
* @param[in] errLvl - level of the error
* @param[in] additionalData - The AdditionalData property for the error
* @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
* vector.
*/
void createEntry(std::string errMsg, Entry::Level errLvl,
std::vector<std::string> additionalData,
const FFDCEntries& ffdc = FFDCEntries{});
/** @brief Notified on entry property changes
*
* If an entry is blocking, this callback will be registered to monitor for
* the entry having it's Resolved field set to true. If it is then remove
* the blocking object.
*
* @param[in] msg - sdbusplus dbusmessage
*/
void onEntryResolve(sdbusplus::message_t& msg);
/** @brief Remove block objects for any resolved entries */
void findAndRemoveResolvedBlocks();
/** @brief Quiesce host if it is running
*
* This is called when the user has requested the system be quiesced
* if a log with a callout is created
*/
void checkAndQuiesceHost();
/** @brief Implementation for rfSendEvent
* Write the dbus log when resource created/deleted/modified or rebooted.
* The dbus log will be picked by the RF event framework and generates the
event
* @param[in] rfMessage - The Message property of the event entry.
* @param[in] rfSeverity - The Severity property of the event entry.
* @param[in] rfAdditionalData - The AdditionalData property of the event
entry. entry. e.g.:
{
"key1": "value1",
"key2": "value2"
}
ends up in AdditionaData like:
["KEY1=value1", "KEY2=value2"]
The keys supported by the RF event framework are:
REDFISH_MESSAGE_ID
REDFISH_MESSAGE_ARGS
REDFISH_ORIGIN_OF_CONDITION
*/
void rfSendEvent(
std::string rfMessage, Entry::Level rfSeverity,
std::map<std::string, std::string> rfAdditionalData) override;
/** @brief Persistent sdbusplus DBus bus connection. */
sdbusplus::bus_t& busLog;
/** @brief Id of last error log entry */
uint32_t entryId;
/** @brief Timestamp of the last created log entry */
uint64_t lastCreatedTimeStamp;
/** @brief The BMC firmware version */
const std::string fwVersion;
phosphor::logging::internal::Bin defaultBin;
#ifdef ENABLE_LOG_STREAMING
/** @brief Socket for SEL logging */
LogStreamer logSocket;
#endif
/** @brief Array of blocking errors */
std::vector<std::unique_ptr<Block>> blockingErrors;
/** @brief Map of entry id to call back object on properties changed */
std::map<uint32_t, std::unique_ptr<sdbusplus::bus::match_t>>
propChangedEntryCallback;
/** @brief Path to persistent R/W config (for log purge policy setting) */
std::string rwConfigJsonPath;
/** @brief Current value of the log purge policy setting */
bool _autoPurgeResolved;
/** @brief Stack containing resolved log entry IDs awaiting deletion */
std::vector<uint32_t> _pendingPurgeEvents;
/** @brief Event source used to trigger log deletion
*
* Time is used instead of Defer so it can round-robin with D-Bus
* (Defer is always prioritized ahead of epoll-based sources)
*/
sdeventplus::source::Time<sdeventplus::ClockId::Monotonic>
_autoPurgeEventSource;
};
} // namespace internal
/** @class Manager
* @brief Implementation for deleting all error log entries and
* creating new logs.
* @details A concrete implementation for the
* xyz.openbmc_project.Collection.DeleteAll,
* xyz.openbmc_project.Logging.Create and
* xyz.openbmc_project.Logging.Capacity and
* xyz.openbmc_project.Logging.Namespace interfaces.
*/
class Manager :
public details::ServerObject<DeleteAllIface, CreateIface, NamespaceIface,
CapacityIface>
{
public:
Manager() = delete;
Manager(const Manager&) = delete;
Manager& operator=(const Manager&) = delete;
Manager(Manager&&) = delete;
Manager& operator=(Manager&&) = delete;
virtual ~Manager() = default;
/** @brief Constructor to put object onto bus at a dbus path.
* Defer signal registration (pass true for deferSignal to the
* base class) until after the properties are set.
* @param[in] bus - Bus to attach to.
* @param[in] path - Path to attach at.
* @param[in] manager - Reference to internal manager object.
*/
Manager(sdbusplus::bus_t& bus, const std::string& path,
internal::Manager& manager) :
details::ServerObject<DeleteAllIface, CreateIface, NamespaceIface,
CapacityIface>(
bus, path.c_str(),
details::ServerObject<DeleteAllIface, CreateIface, NamespaceIface,
CapacityIface>::action::defer_emit),
manager(manager){};
/** @brief Delete all d-bus objects.
*/
void deleteAll() override
{
log<level::INFO>("Deleting all log entries");
auto numbersOfLogs = manager.eraseAll();
std::map<std::string, std::string> additionalData;
additionalData.emplace("NUM_LOGS", std::to_string(numbersOfLogs));
manager.create(LogsCleared::errName, Severity::Informational,
additionalData);
}
/** @brief getAll method call implementation to get event logs
*
*/
ManagedObject getAll(std::string nspace,
NamespaceIface::ResolvedFilterType rfilter) override
{
if (nspace.compare("Namespace.All") == 0)
{
return manager.getAll(rfilter);
}
return manager.getAll(nspace, rfilter);
}
bool autoClearResolvedLogEnabled() const
{
return manager.getAutoPurgeResolved();
}
bool autoClearResolvedLogEnabled(bool purgeResolvedLogs)
{
manager.setAutoPurgeResolved(purgeResolvedLogs);
return purgeResolvedLogs;
}
/** @brief getStats method call implementation to get Phosphor Logging Stats
*
*/
std::tuple<uint32_t, uint64_t> getStats(std::string nspace) override
{
return manager.getStats(nspace);
}
/** @brief deleteAll method call implementation to delete all logs per
* namespace
*
*/
bool
deleteAll(std::string nspace,
sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level
severity) override
{
return manager.deleteAll(nspace, severity);
}
/** @brief D-Bus method call implementation to create an event log.
*
* @param[in] errMsg - The error exception message associated with the
* error log to be committed.
* @param[in] severity - Level of the error
* @param[in] additionalData - The AdditionalData property for the error
*/
void create(std::string message, Severity severity,
std::map<std::string, std::string> additionalData) override
{
manager.create(message, severity, additionalData);
}
/** @brief D-Bus method call implementation to configure the info capacity.
*
* @param[in] infoLogCapacity - capacity of info event
*/
void setInfoLogCapacity(size_t infoLogCapacity) override
{
manager.setInfoLogCapacity(infoLogCapacity);
}
/** @brief D-Bus method call implementation to get the info capacity.
*
* @return the info capacity
*/
size_t infoLogCapacity() const override
{
return manager.getInfoLogCapacity();
}
/** @brief D-Bus method call implementation to create an event log with FFDC
*
* The same as create(), but takes an extra FFDC argument.
*
* @param[in] errMsg - The error exception message associated with the
* error log to be committed.
* @param[in] severity - Level of the error
* @param[in] additionalData - The AdditionalData property for the error
* @param[in] ffdc - A vector of FFDC file info
*/
void createWithFFDCFiles(
std::string message, Severity severity,
std::map<std::string, std::string> additionalData,
std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
sdbusplus::message::unix_fd>>
ffdc) override
{
manager.create(message, severity, additionalData, ffdc);
}
private:
/** @brief This is a reference to manager object */
internal::Manager& manager;
};
} // namespace logging
} // namespace phosphor