summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0016-Redfish-implement-Syslog-config.patch
blob: d07a6cb3b799ced94b94a354c7e75e197b144177 (plain)
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
From fce8aebcb0c307a7a797708a26dd39e2b173b1cd Mon Sep 17 00:00:00 2001
From: Nikita Kosenkov <NKosenkov@IBS.RU>
Date: Thu, 15 Sep 2022 18:22:26 +0300
Subject: [PATCH] Redfish: implement Syslog config

1. Get config:
    curl -u <Login>:<Password> -k -s -X GET https://<BMC>/redfish/v1/Syslog

2. Update config:
    curl -u <Login>:<Password> -k -s -X POST https://<BMC>/redfish/v1/Syslog/Actions/Syslog.UpdateConfig -d '{"Address": "10.0.0.10", "Port": 777}'
---
 redfish-core/include/redfish.hpp              |   5 +
 .../include/registries/privilege_registry.hpp |   8 +
 redfish-core/lib/service_root.hpp             |   1 +
 redfish-core/lib/syslog.hpp                   | 143 ++++++++++++++++++
 4 files changed, 157 insertions(+)
 create mode 100644 redfish-core/lib/syslog.hpp

diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp
index 9db3a2b8..ebaabdfa 100644
--- a/redfish-core/include/redfish.hpp
+++ b/redfish-core/include/redfish.hpp
@@ -49,6 +49,7 @@
 #include "../lib/update_service.hpp"
 #include "../lib/virtual_media.hpp"
 #include "../lib/smtp.hpp"
+#include "../lib/syslog.hpp"
 
 namespace redfish
 {
@@ -229,6 +230,10 @@ class RedfishService
         requestRoutesTrigger(app);
         requestRoutesSmtp(app);
         requestSmtpFunctions(app);
+
+        requestRoutesSyslog(app);
+        requestRoutesSyslogUpdateConfig(app);
+
         // Note, this must be the last route registered
         requestRoutesRedfish(app);
     }
diff --git a/redfish-core/include/registries/privilege_registry.hpp b/redfish-core/include/registries/privilege_registry.hpp
index 5ec62749..95dba316 100644
--- a/redfish-core/include/registries/privilege_registry.hpp
+++ b/redfish-core/include/registries/privilege_registry.hpp
@@ -1435,6 +1435,14 @@ const static auto& postSwitchCollection = privilegeSetConfigureComponents;
 const static auto& putSwitchCollection = privilegeSetConfigureComponents;
 const static auto& deleteSwitchCollection = privilegeSetConfigureComponents;
 
+// Syslog
+const static auto& getSyslog = privilegeSetLogin;
+const static auto& headSyslog = privilegeSetLogin;
+const static auto& patchSyslog = privilegeSetConfigureComponents;
+const static auto& postSyslog = privilegeSetConfigureComponents;
+const static auto& putSyslog = privilegeSetConfigureComponents;
+const static auto& deleteSyslog = privilegeSetConfigureComponents;
+
 // Task
 const static auto& getTask = privilegeSetLogin;
 const static auto& headTask = privilegeSetLogin;
diff --git a/redfish-core/lib/service_root.hpp b/redfish-core/lib/service_root.hpp
index 1904e8e3..b6eea99b 100644
--- a/redfish-core/lib/service_root.hpp
+++ b/redfish-core/lib/service_root.hpp
@@ -78,6 +78,7 @@ inline void handleServiceRootGetImpl(
         "/redfish/v1/TelemetryService";
     asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
     asyncResp->res.jsonValue["Smtp"]["@odata.id"] = "/redfish/v1/Smtp";
+    asyncResp->res.jsonValue["Syslog"]["@odata.id"] = "/redfish/v1/Syslog";
 
     nlohmann::json& protocolFeatures =
         asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
diff --git a/redfish-core/lib/syslog.hpp b/redfish-core/lib/syslog.hpp
new file mode 100644
index 00000000..bf7c0073
--- /dev/null
+++ b/redfish-core/lib/syslog.hpp
@@ -0,0 +1,143 @@
+#pragma once
+
+#include <app.hpp>
+#include <registries/privilege_registry.hpp>
+#include <query.hpp>
+
+
+namespace redfish
+{
+    constexpr const char* SYSLOG_SERVICE_PATH = "xyz.openbmc_project.Syslog.Config";
+    constexpr const char* SYSLOG_OBJECT_PATH = "/xyz/openbmc_project/logging/config/remote";
+    constexpr const char* SYSLOG_INTERFACE_PATH = "xyz.openbmc_project.Network.Client";
+
+    namespace syslog
+    {
+        inline void updateSyslogProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
+                                 const std::string& address,
+                                 const uint16_t& port)
+        {
+            auto errorHandler = [asyncResp](const boost::system::error_code ec) {
+                if (ec)
+                {
+                    BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+                    messages::internalError(asyncResp->res);
+                }
+            };
+
+            crow::connections::systemBus->async_method_call(
+                errorHandler,
+                SYSLOG_SERVICE_PATH, SYSLOG_OBJECT_PATH,
+                "org.freedesktop.DBus.Properties", "Set",
+                SYSLOG_INTERFACE_PATH,
+                "Address", dbus::utility::DbusVariantType(address));
+
+            crow::connections::systemBus->async_method_call(
+                errorHandler,
+                SYSLOG_SERVICE_PATH, SYSLOG_OBJECT_PATH,
+                "org.freedesktop.DBus.Properties", "Set",
+                SYSLOG_INTERFACE_PATH,
+                "Port", dbus::utility::DbusVariantType(port));
+        }
+    }
+
+    inline void requestRoutesSyslogUpdateConfig(App& app)
+    {
+        BMCWEB_ROUTE(app, "/redfish/v1/Syslog/Actions/Syslog.UpdateConfig")
+            .privileges(redfish::privileges::postSyslog)
+            .methods(boost::beast::http::verb::post)(
+                [&app](const crow::Request& req,
+                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+        {
+            if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+            {
+                return;
+            }
+
+            std::optional<std::string> address;
+            std::optional<uint16_t> port;
+            if (!json_util::readJsonAction(req, asyncResp->res,
+                                        "Address", address,
+                                        "Port", port))
+            {
+                return;
+            }
+
+            if(!address)
+            {
+                messages::propertyMissing(asyncResp->res, "Address");
+                return;
+            }
+
+            if(!port)
+            {
+                messages::propertyMissing(asyncResp->res, "Port");
+                return;
+            }
+
+            syslog::updateSyslogProperties(asyncResp, *address, *port);
+        });
+    }
+
+    inline void requestRoutesSyslog(App& app)
+    {
+        BMCWEB_ROUTE(app, "/redfish/v1/Syslog/")
+            .privileges(redfish::privileges::getSyslog)
+            .methods(boost::beast::http::verb::get)(
+                [&app](const crow::Request& req,
+                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+        {
+            if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+            {
+                return;
+            }
+
+            sdbusplus::asio::getAllProperties(
+                *crow::connections::systemBus,
+                SYSLOG_SERVICE_PATH,
+                SYSLOG_OBJECT_PATH,
+                SYSLOG_INTERFACE_PATH,
+                [asyncResp](const boost::system::error_code ec,
+                            const dbus::utility::DBusPropertiesMap& propertiesList) {
+                    if (ec)
+                    {
+                        BMCWEB_LOG_ERROR << "D-Bus response error on GetSubTree " << ec;
+                        messages::internalError(asyncResp->res);
+                        return;
+                    }
+
+                    const std::string* address = nullptr;
+                    const uint16_t* port = nullptr;
+
+                    const bool success = sdbusplus::unpackPropertiesNoThrow(
+                        dbus_utils::UnpackErrorPrinter(),
+                        propertiesList,
+                        "Address", address,
+                        "Port", port);
+
+                    if (!success)
+                    {
+                        messages::internalError(asyncResp->res);
+                        return;
+                    }
+
+                    if (address != nullptr && port != nullptr)
+                    {
+                        nlohmann::json& configuration =
+                            asyncResp->res.jsonValue["Configuration"];
+                        configuration["Address"] = *address;
+                        configuration["Port"] = *port;
+                    }
+                }
+            );
+
+            asyncResp->res.jsonValue["@odata.type"] ="#Syslog";
+            asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Syslog";
+            asyncResp->res.jsonValue["Name"] = "Syslog";
+            asyncResp->res.jsonValue["Description"] = "Remote Syslog destination";
+            asyncResp->res.jsonValue["Actions"]["#Syslog.UpdateConfig"] = {
+                {"target", "/redfish/v1/Syslog/Actions/Syslog.UpdateConfig"}
+            };
+        });
+    }
+}
\ No newline at end of file
-- 
2.35.1