Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
4da300c5
Commit
4da300c5
authored
May 24, 2019
by
Micha Mueller
Browse files
Minor improvements to RestAPI server
parent
af62fd36
Changes
3
Hide whitespace changes
Inline
Side-by-side
common/src/RESTHttpsServer.cpp
View file @
4da300c5
...
...
@@ -183,9 +183,8 @@ void RESTHttpsServer::handle_request(http::request<Body>& req, Send&& send) {
res
.
body
()
=
"Invalid endpoint
\n
"
;
}
#ifdef DEBUG
ServerLOG
(
info
)
<<
"Responding:
\n
"
<<
res
.
body
();
#endif
res
.
prepare_payload
();
send
(
std
::
move
(
res
));
return
;
...
...
dcdbpusher/RestAPI.cpp
View file @
4da300c5
...
...
@@ -28,14 +28,14 @@ RestAPI::RestAPI(serverSettings_t settings,
_manager
(
manager
),
_io
(
io
)
{
addEndpoint
(
"/help"
,
{
http
::
verb
::
get
,
stdBind
(
GET_help
)});
addEndpoint
(
"/plugins"
,
{
http
::
verb
::
get
,
stdBind
(
GET_plugins
)});
addEndpoint
(
"/sensors"
,
{
http
::
verb
::
get
,
stdBind
(
GET_sensors
)});
addEndpoint
(
"/average"
,
{
http
::
verb
::
get
,
stdBind
(
GET_average
)});
addEndpoint
(
"/help"
,
{
http
::
verb
::
get
,
stdBind
(
GET_help
)});
addEndpoint
(
"/plugins"
,
{
http
::
verb
::
get
,
stdBind
(
GET_plugins
)});
addEndpoint
(
"/sensors"
,
{
http
::
verb
::
get
,
stdBind
(
GET_sensors
)});
addEndpoint
(
"/average"
,
{
http
::
verb
::
get
,
stdBind
(
GET_average
)});
addEndpoint
(
"/start"
,
{
http
::
verb
::
put
,
stdBind
(
PUT_start
)});
addEndpoint
(
"/stop"
,
{
http
::
verb
::
put
,
stdBind
(
PUT_stop
)});
addEndpoint
(
"/reload"
,
{
http
::
verb
::
put
,
stdBind
(
PUT_reload
)});
addEndpoint
(
"/start"
,
{
http
::
verb
::
put
,
stdBind
(
PUT_start
)});
addEndpoint
(
"/stop"
,
{
http
::
verb
::
put
,
stdBind
(
PUT_stop
)});
addEndpoint
(
"/reload"
,
{
http
::
verb
::
put
,
stdBind
(
PUT_reload
)});
_manager
->
addRestEndpoints
(
this
);
...
...
@@ -44,7 +44,7 @@ RestAPI::RestAPI(serverSettings_t settings,
}
void
RestAPI
::
GET_help
(
endpointArgs
)
{
res
.
body
()
=
restCheatSheet
+
_manager
->
newR
estCheatSheet
;
res
.
body
()
=
restCheatSheet
+
_manager
->
r
estCheatSheet
;
res
.
result
(
http
::
status
::
ok
);
}
...
...
@@ -108,9 +108,7 @@ void RestAPI::GET_average(endpointArgs) {
const
std
::
string
interval
=
getQuery
(
"interval"
,
queries
);
if
(
plugin
==
""
||
sensor
==
""
)
{
const
std
::
string
err
=
"Request malformed: plugin or sensor query missing"
;
RESTAPILOG
(
error
)
<<
err
;
res
.
body
()
=
err
;
res
.
body
()
=
"Request malformed: plugin or sensor query missing
\n
"
;
res
.
result
(
http
::
status
::
bad_request
);
return
;
}
...
...
@@ -118,7 +116,14 @@ void RestAPI::GET_average(endpointArgs) {
uint64_t
time
=
0
;
if
(
interval
!=
""
)
{
time
=
std
::
stoul
(
interval
);
try
{
time
=
std
::
stoul
(
interval
);
}
catch
(
const
std
::
exception
&
e
)
{
RESTAPILOG
(
warning
)
<<
"Bad interval query: "
<<
e
.
what
();
res
.
body
()
=
"Bad interval query!
\n
"
;
res
.
result
(
http
::
status
::
bad_request
);
return
;
}
}
res
.
body
()
=
"Plugin not found!
\n
"
;
...
...
@@ -244,7 +249,7 @@ void RestAPI::PUT_reload(endpointArgs) {
removeTopics
(
p
);
p
.
configurator
->
clearConfig
();
}
else
{
res
.
body
()
=
"Plugin "
+
plugin
+
": Configuration reloaded
\n
"
;
res
.
body
()
=
"Plugin "
+
plugin
+
": Configuration reloaded
.
\n
"
;
res
.
result
(
http
::
status
::
ok
);
for
(
const
auto
&
g
:
p
.
configurator
->
getSensorGroups
())
{
g
->
init
(
_io
);
...
...
@@ -252,7 +257,7 @@ void RestAPI::PUT_reload(endpointArgs) {
}
}
}
else
{
res
.
body
()
=
"Plugin "
+
plugin
+
": Could not reload configuration"
;
res
.
body
()
=
"Plugin "
+
plugin
+
": Could not reload configuration
.
\n
"
;
res
.
result
(
http
::
status
::
internal_server_error
);
}
...
...
@@ -305,9 +310,7 @@ bool RestAPI::checkTopics(dl_t p) {
void
RestAPI
::
PUT_analytics_reload
(
endpointArgs
)
{
if
(
_manager
->
getStatus
()
!=
AnalyticsManager
::
LOADED
)
{
const
std
::
string
err
=
"AnalyticsManager is not loaded!
\n
"
;
RESTAPILOG
(
error
)
<<
err
;
res
.
body
()
=
err
;
res
.
body
()
=
"AnalyticsManager is not loaded!
\n
"
;
res
.
result
(
http
::
status
::
internal_server_error
);
return
;
}
...
...
dcdbpusher/RestAPI.h
View file @
4da300c5
...
...
@@ -13,7 +13,6 @@
#include
<boost/asio.hpp>
#include
"includes/PluginDefinitions.h"
#include
"globalconfiguration.h"
#include
"../analytics/AnalyticsManager.h"
#include
"mqttchecker.h"
#include
"MQTTPusher.h"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment