forked from ibm-openbmc/bmcweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_dbus_monitor.hpp
641 lines (559 loc) · 20.2 KB
/
event_dbus_monitor.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
#include <dbus_utility.hpp>
#include <dump_offload.hpp>
#include <error_messages.hpp>
#include <event_service_manager.hpp>
#include <resource_messages.hpp>
namespace crow
{
namespace dbus_monitor
{
static std::shared_ptr<sdbusplus::bus::match::match> matchHostStateChange;
static std::shared_ptr<sdbusplus::bus::match::match> matchBMCStateChange;
static std::shared_ptr<sdbusplus::bus::match::match>
matchVMIIPEnabledPropChange;
static std::shared_ptr<sdbusplus::bus::match::match> matchVMIIPChange;
static std::shared_ptr<sdbusplus::bus::match::match> matchVMIEthIntfPropChange;
static std::shared_ptr<sdbusplus::bus::match::match> matchDumpCreatedSignal;
static std::shared_ptr<sdbusplus::bus::match::match> matchDumpDeletedSignal;
static std::shared_ptr<sdbusplus::bus::match::match> matchBIOSAttrUpdate;
static std::shared_ptr<sdbusplus::bus::match::match> matchBootProgressChange;
static std::shared_ptr<sdbusplus::bus::match::match> matchEventLogCreated;
static std::shared_ptr<sdbusplus::bus::match::match> matchPostCodeChange;
static std::shared_ptr<sdbusplus::bus::match::match> matchPlatformSAIChange;
static std::shared_ptr<sdbusplus::bus::match::match> matchPartitionSAIChange;
static uint64_t postCodeCounter = 0;
void registerHostStateChangeSignal();
void registerBMCStateChangeSignal();
void registerVMIIPEnabledPropChangeSignal();
void registerVMIIPChangeSignal();
void registerVMIEthIntfPropChangeSignal();
void registerDumpCreatedSignal();
void registerDumpDeletedSignal();
void registerBIOSAttrUpdateSignal();
void registerBootProgressChangeSignal();
void registerEventLogCreatedSignal();
void registerPostCodeChangeSignal();
void registerSAIStateChangeSignal();
inline void sendEventOnEthIntf(const std::string& origin)
{
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceChanged(), origin, "EthernetInterface");
}
inline void vmiNwPropertyChange(sdbusplus::message::message& msg)
{
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR
<< "BMC Hypervisor Network properties changed Signal error";
return;
}
std::string objPath = msg.get_path();
if (!(objPath.starts_with(
"/xyz/openbmc_project/network/hypervisor/eth0")) &&
!(objPath.starts_with("/xyz/openbmc_project/network/hypervisor/eth1")))
{
return;
}
std::string infName;
if (objPath.find("/eth0") != std::string::npos)
{
infName = "eth0";
}
else if (objPath.find("/eth1") != std::string::npos)
{
infName = "eth1";
}
std::string origin = "/redfish/v1/Systems/hypervisor/EthernetInterfaces/" +
infName;
BMCWEB_LOG_DEBUG << "Pushing the VMI Nw property change event for IP "
"property with origin: "
<< origin;
sendEventOnEthIntf(origin);
}
inline void bmcStatePropertyChange(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "BMC state change match fired";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "BMC state property changed Signal error";
return;
}
std::string iface;
boost::container::flat_map<std::string, std::variant<std::string, uint8_t>>
values;
std::string objName;
msg.read(objName, values);
auto find = values.find("CurrentBMCState");
if (find == values.end())
{
return;
}
std::string* type = std::get_if<std::string>(&(find->second));
if (type != nullptr)
{
BMCWEB_LOG_DEBUG << *type;
// Push an event
std::string origin = "/redfish/v1/Managers/bmc";
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceChanged(), origin, "Manager");
}
}
inline void hostStatePropertyChange(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "Host state change match fired";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "Host state property changed Signal error";
return;
}
std::string iface;
boost::container::flat_map<std::string, std::variant<std::string, uint8_t>>
values;
std::string objName;
msg.read(objName, values);
auto find = values.find("CurrentHostState");
if (find == values.end())
{
return;
}
std::string* type = std::get_if<std::string>(&(find->second));
if (type != nullptr)
{
BMCWEB_LOG_DEBUG << *type;
if (*type == "xyz.openbmc_project.State.Host.HostState.Off")
{
// Reset system dump handler to handle power off scenarios
crow::obmc_dump::resetHandlers();
// reset the postCodeCounter
postCodeCounter = 0;
BMCWEB_LOG_CRITICAL
<< "INFO: Host is powered off. Reset the postcode counter to "
<< postCodeCounter;
}
// Push an event
std::string origin = "/redfish/v1/Systems/system";
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceChanged(), origin, "ComputerSystem");
}
}
inline void bootProgressPropertyChange(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "BootProgress change match fired";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "BootProgress property changed Signal error";
return;
}
std::string iface;
boost::container::flat_map<std::string, std::variant<std::string, uint8_t>>
values;
std::string objName;
msg.read(objName, values);
auto find = values.find("BootProgress");
if (find == values.end())
{
return;
}
std::string* type = std::get_if<std::string>(&(find->second));
if (type != nullptr)
{
BMCWEB_LOG_DEBUG << *type;
// Push an event
std::string origin = "/redfish/v1/Systems/system";
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceChanged(), origin, "ComputerSystem");
}
}
inline void postCodePropertyChange(sdbusplus::message::message& msg)
{
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "PostCode property changed Signal error";
return;
}
std::string postcodeEntryID = "B1-" + std::to_string(++postCodeCounter);
BMCWEB_LOG_DEBUG << "Current post code: " << postcodeEntryID;
// Push an event
std::string eventOrigin = "/redfish/v1/Systems/system/"
"LogServices/PostCodes/Entries/" +
postcodeEntryID;
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceCreated(), eventOrigin, "ComputerSystem");
}
inline void saiStateChangeSignal(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "System Attention Indicator State change match fired";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "SAI State change signal error";
return;
}
boost::container::flat_map<std::string, std::variant<bool>> values;
std::string objName;
msg.read(objName, values);
auto find = values.find("Asserted");
if (find == values.end())
{
return;
}
// Push an event
std::string origin = "/redfish/v1/Systems/system";
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceChanged(), origin, "ComputerSystem");
}
void registerHostStateChangeSignal()
{
BMCWEB_LOG_DEBUG << "Host state change signal - Register";
matchHostStateChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',path='/xyz/openbmc_project/state/host0',"
"arg0='xyz.openbmc_project.State.Host'",
hostStatePropertyChange);
}
void registerBMCStateChangeSignal()
{
BMCWEB_LOG_DEBUG << "BMC state change signal - Register";
matchBMCStateChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',path='/xyz/openbmc_project/state/bmc0',"
"arg0='xyz.openbmc_project.State.BMC'",
bmcStatePropertyChange);
}
void registerVMIIPEnabledPropChangeSignal()
{
BMCWEB_LOG_DEBUG << "VMI IP change signal match - Registered";
matchVMIIPEnabledPropChange = std::make_unique<
sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',arg0namespace='xyz.openbmc_project.Object.Enable'",
vmiNwPropertyChange);
}
void registerVMIIPChangeSignal()
{
matchVMIIPChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',arg0namespace='xyz.openbmc_project.Network.IP'",
vmiNwPropertyChange);
}
void registerVMIEthIntfPropChangeSignal()
{
matchVMIEthIntfPropChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',arg0namespace='xyz.openbmc_project.Network."
"EthernetInterface'",
vmiNwPropertyChange);
}
void registerBootProgressChangeSignal()
{
BMCWEB_LOG_DEBUG << "BootProgress change signal - Register";
matchBootProgressChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',path='/xyz/openbmc_project/state/host0',"
"arg0='xyz.openbmc_project.State.Boot.Progress'",
bootProgressPropertyChange);
}
static void eventLogCreatedSignal(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "Event Log Created - match fired";
constexpr auto pelEntryInterface = "org.open_power.Logging.PEL.Entry";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "Event Log Created signal error";
return;
}
sdbusplus::message::object_path objPath;
std::map<std::string,
std::map<std::string, std::variant<std::string, bool>>>
interfaces;
msg.read(objPath, interfaces);
std::string logID;
dbus::utility::getNthStringFromPath(objPath, 4, logID);
const auto pelProperties = interfaces.find(pelEntryInterface);
if (pelProperties == interfaces.end())
{
return;
}
const auto hiddenProperty = pelProperties->second.find("Hidden");
if (hiddenProperty == pelProperties->second.end())
{
return;
}
const bool* hiddenPropertyPtr =
std::get_if<bool>(&(hiddenProperty->second));
if (hiddenPropertyPtr == nullptr)
{
BMCWEB_LOG_ERROR << "Failed to get Hidden property";
return;
}
std::string eventOrigin;
if (*hiddenPropertyPtr)
{
eventOrigin = "/redfish/v1/Systems/system/LogServices/CELog/Entries/" +
logID;
BMCWEB_LOG_DEBUG << "CELog path: " << eventOrigin;
}
else
{
eventOrigin =
"/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + logID;
BMCWEB_LOG_DEBUG << "EventLog path: " << eventOrigin;
}
BMCWEB_LOG_DEBUG << "Sending event for log ID " << logID;
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceCreated(), eventOrigin, "LogEntry");
}
void registerEventLogCreatedSignal()
{
BMCWEB_LOG_DEBUG << "Register EventLog Created Signal";
matchEventLogCreated = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='InterfacesAdded',interface='org.freedesktop."
"DBus.ObjectManager',path='/xyz/openbmc_project/logging',",
eventLogCreatedSignal);
}
static void registerStateChangeSignal()
{
registerHostStateChangeSignal();
registerBMCStateChangeSignal();
registerBootProgressChangeSignal();
}
static void registerVMIConfigChangeSignal()
{
registerVMIIPEnabledPropChangeSignal();
registerVMIIPChangeSignal();
registerVMIEthIntfPropChangeSignal();
}
void registerPostCodeChangeSignal()
{
BMCWEB_LOG_DEBUG << "PostCode change signal - Register";
matchPostCodeChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',path='/xyz/openbmc_project/state/boot/raw0',"
"arg0='xyz.openbmc_project.State.Boot.Raw'",
postCodePropertyChange);
}
inline void dumpCreatedSignal(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "Dump Created - match fired";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "Dump Created signal error";
return;
}
std::string dumpType;
std::string dumpId;
dbus::utility::getNthStringFromPath(msg.get_path(), 3, dumpType);
dbus::utility::getNthStringFromPath(msg.get_path(), 5, dumpId);
boost::container::flat_map<std::string, std::variant<std::string, uint8_t>>
values;
std::string objName;
msg.read(objName, values);
auto find = values.find("Status");
if (find == values.end())
{
BMCWEB_LOG_DEBUG
<< "Status property not found. Continuing to listen...";
return;
}
std::string* propValue = std::get_if<std::string>(&(find->second));
if (propValue != nullptr &&
*propValue ==
"xyz.openbmc_project.Common.Progress.OperationStatus.Completed")
{
BMCWEB_LOG_DEBUG << "Sending event\n";
std::string eventOrigin;
// Push an event
if (dumpType == "bmc")
{
eventOrigin = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" +
dumpId;
}
else if (dumpType == "system")
{
eventOrigin =
"/redfish/v1/Systems/system/LogServices/Dump/Entries/System_" +
dumpId;
}
else if (dumpType == "resource")
{
eventOrigin = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"
"Resource_" +
dumpId;
}
else if (dumpType == "hostboot")
{
eventOrigin = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"
"Hostboot_" +
dumpId;
}
else if (dumpType == "hardware")
{
eventOrigin = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"
"Hardware_" +
dumpId;
}
else if (dumpType == "sbe")
{
eventOrigin = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"
"SBE_" +
dumpId;
}
else
{
BMCWEB_LOG_ERROR << "Invalid dump type received when listening for "
"dump created signal";
return;
}
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceCreated(), eventOrigin, "LogEntry");
}
}
inline void dumpDeletedSignal(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "Dump Deleted - match fired";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "Dump Deleted signal error";
return;
}
std::vector<std::string> interfacesList;
sdbusplus::message::object_path objPath;
msg.read(objPath, interfacesList);
std::string dumpType;
std::string dumpId;
dbus::utility::getNthStringFromPath(objPath, 3, dumpType);
dbus::utility::getNthStringFromPath(objPath, 5, dumpId);
std::string eventOrigin;
if (dumpType == "bmc")
{
eventOrigin = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/" +
dumpId;
}
else if (dumpType == "system")
{
eventOrigin =
"/redfish/v1/Systems/system/LogServices/Dump/Entries/System_" +
dumpId;
}
else if (dumpType == "resource")
{
eventOrigin =
"/redfish/v1/Systems/system/LogServices/Dump/Entries/Resource_" +
dumpId;
}
else if (dumpType == "hostboot")
{
eventOrigin =
"/redfish/v1/Systems/system/LogServices/Dump/Entries/Hostboot_" +
dumpId;
}
else if (dumpType == "hardware")
{
eventOrigin =
"/redfish/v1/Systems/system/LogServices/Dump/Entries/Hardware_" +
dumpId;
}
else if (dumpType == "sbe")
{
eventOrigin =
"/redfish/v1/Systems/system/LogServices/Dump/Entries/SBE_" + dumpId;
}
else
{
BMCWEB_LOG_ERROR << "Invalid dump type received when listening for "
"dump deleted signal";
return;
}
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceRemoved(), eventOrigin, "LogEntry");
}
void registerDumpCreatedSignal()
{
BMCWEB_LOG_DEBUG << "Dump Created signal - Register";
matchDumpCreatedSignal = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',arg0namespace='xyz.openbmc_project.Common.Progress',",
dumpCreatedSignal);
}
void registerDumpDeletedSignal()
{
BMCWEB_LOG_DEBUG << "Dump Deleted signal - Register";
matchDumpDeletedSignal = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='InterfacesRemoved',interface='org.freedesktop."
"DBus.ObjectManager',path='/xyz/openbmc_project/dump',",
dumpDeletedSignal);
}
static void registerDumpUpdateSignal()
{
registerDumpCreatedSignal();
registerDumpDeletedSignal();
}
inline void biosAttrUpdate(sdbusplus::message::message& msg)
{
BMCWEB_LOG_DEBUG << "BIOS attribute change match fired";
if (msg.is_method_error())
{
BMCWEB_LOG_ERROR << "BIOS attribute changed Signal error";
return;
}
boost::container::flat_map<std::string, std::variant<std::string, uint8_t>>
values;
std::string objName;
msg.read(objName, values);
auto find = values.find("BaseBIOSTable");
if (find == values.end())
{
BMCWEB_LOG_DEBUG
<< "BaseBIOSTable property not found. Continuing to listen...";
return;
}
std::string* type = std::get_if<std::string>(&(find->second));
if (type != nullptr)
{
BMCWEB_LOG_DEBUG << "Sending event\n";
// Push an event
std::string origin = "/redfish/v1/Systems/system/Bios";
redfish::EventServiceManager::getInstance().sendEvent(
redfish::messages::resourceChanged(), origin, "Bios");
}
}
void registerBIOSAttrUpdateSignal()
{
BMCWEB_LOG_DEBUG << "BIOS Attribute update signal match - Registered";
matchBIOSAttrUpdate = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',arg0namespace='xyz.openbmc_project.BIOSConfig."
"Manager'",
biosAttrUpdate);
}
void registerSAIStateChangeSignal()
{
BMCWEB_LOG_DEBUG
<< "Platform System attention Indicator state change signal - Register";
matchPlatformSAIChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',path='/xyz/openbmc_project/led/groups/platform_system_attention_indicator',"
"arg0='xyz.openbmc_project.Led.Group'",
saiStateChangeSignal);
BMCWEB_LOG_DEBUG
<< "Partition System attention Indicator state change signal - Register";
matchPartitionSAIChange = std::make_unique<sdbusplus::bus::match::match>(
*crow::connections::systemBus,
"type='signal',member='PropertiesChanged',interface='org.freedesktop."
"DBus.Properties',path='/xyz/openbmc_project/led/groups/partition_system_attention_indicator',"
"arg0='xyz.openbmc_project.Led.Group'",
saiStateChangeSignal);
}
} // namespace dbus_monitor
} // namespace crow