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
|
#pragma once
#include "app.hpp"
#include "async_resp.hpp"
#include "http_request.hpp"
#include "privileges.hpp"
#include "query.hpp"
#include "registries/privilege_registry.hpp"
#include "routing.hpp"
#include <nlohmann/json.hpp>
#include <sdbusplus/asio/property.hpp>
#include <string>
namespace redfish
{
inline void
afterGetManagerStartTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
const boost::system::error_code& ec,
uint64_t bmcwebResetTime)
{
if (ec)
{
// Not all servers will be running in systemd, so ignore the error.
return;
}
using std::chrono::steady_clock;
std::chrono::duration<steady_clock::rep, std::micro> usReset{
bmcwebResetTime};
steady_clock::time_point resetTime{usReset};
steady_clock::time_point now = steady_clock::now();
steady_clock::duration runTime = now - resetTime;
if (runTime < steady_clock::duration::zero())
{
BMCWEB_LOG_CRITICAL << "Uptime was negative????";
messages::internalError(aResp->res);
return;
}
// Floor to the closest millisecond
using Milli = std::chrono::duration<steady_clock::rep, std::milli>;
Milli milli = std::chrono::floor<Milli>(runTime);
using SecondsFloat = std::chrono::duration<double>;
SecondsFloat sec = std::chrono::duration_cast<SecondsFloat>(milli);
aResp->res.jsonValue["ServiceRootUptimeSeconds"] = sec.count();
}
inline void
managerGetServiceRootUptime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
sdbusplus::asio::getProperty<uint64_t>(
*crow::connections::systemBus, "org.freedesktop.systemd1",
"/org/freedesktop/systemd1/unit/bmcweb_2eservice",
"org.freedesktop.systemd1.Unit", "ActiveEnterTimestampMonotonic",
std::bind_front(afterGetManagerStartTime, aResp));
}
/**
* handleManagerDiagnosticData supports ManagerDiagnosticData.
* It retrieves BMC health information from various DBus resources and returns
* the information through the response.
*/
inline void handleManagerDiagnosticDataGet(
crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
asyncResp->res.jsonValue["@odata.type"] =
"#ManagerDiagnosticData.v1_2_0.ManagerDiagnosticData";
asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/Managers/bmc/ManagerDiagnosticData";
asyncResp->res.jsonValue["Id"] = "ManagerDiagnosticData";
asyncResp->res.jsonValue["Name"] = "Manager Diagnostic Data";
managerGetServiceRootUptime(asyncResp);
}
inline void requestRoutesManagerDiagnosticData(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ManagerDiagnosticData")
.privileges(redfish::privileges::getManagerDiagnosticData)
.methods(boost::beast::http::verb::get)(
std::bind_front(handleManagerDiagnosticDataGet, std::ref(app)));
}
} // namespace redfish
|