MXS-1220: Fix date formatting
Some of the dates were printed with a trailing newline. This was added by asctime_r. Fixed `/services` resource returning an empty array.
This commit is contained in:
parent
75b44198ba
commit
aa16980cec
@ -38,6 +38,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <maxscale/service.h>
|
||||
#include <maxscale/session.h>
|
||||
#include <maxscale/server.h>
|
||||
@ -48,6 +49,7 @@
|
||||
#include <maxscale/ssl.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/semaphore.hh>
|
||||
|
||||
#include "maxscale/monitor.h"
|
||||
@ -1438,7 +1440,13 @@ json_t* server_to_json(const SERVER* server)
|
||||
|
||||
if (server->node_ts > 0)
|
||||
{
|
||||
json_object_set_new(rval, "last_heartbeat", json_integer(server->node_ts));
|
||||
struct tm result;
|
||||
char timebuf[30];
|
||||
time_t tim = server->node_ts;
|
||||
asctime_r(localtime_r(&tim, &result), timebuf);
|
||||
trim(timebuf);
|
||||
|
||||
json_object_set_new(rval, "last_heartbeat", json_string(timebuf));
|
||||
}
|
||||
|
||||
json_t* stats = json_object();
|
||||
|
@ -2375,9 +2375,6 @@ json_t* service_to_json(const SERVICE* service)
|
||||
// TODO: Handle errors
|
||||
json_t* rval = json_object();
|
||||
|
||||
struct tm result;
|
||||
char timebuf[30];
|
||||
|
||||
json_object_set_new(rval, "name", json_string(service->name));
|
||||
json_object_set_new(rval, "router", json_string(service->routerModule));
|
||||
json_object_set_new(rval, "state", json_string(service_state_to_string(service->state)));
|
||||
@ -2388,7 +2385,12 @@ json_t* service_to_json(const SERVICE* service)
|
||||
//service->router->diagnostics(service->router_instance, dcb);
|
||||
}
|
||||
|
||||
struct tm result;
|
||||
char timebuf[30];
|
||||
|
||||
asctime_r(localtime_r(&service->stats.started, &result), timebuf);
|
||||
trim(timebuf);
|
||||
|
||||
json_object_set_new(rval, "started", json_string(timebuf));
|
||||
json_object_set_new(rval, "enable_root", json_boolean(service->enable_root));
|
||||
|
||||
@ -2448,7 +2450,7 @@ json_t* service_list_to_json()
|
||||
|
||||
spinlock_acquire(&service_spin);
|
||||
|
||||
for (SERVICE *service = allServices; service && !rval; service = service->next)
|
||||
for (SERVICE *service = allServices; service; service = service->next)
|
||||
{
|
||||
json_t* svc = service_to_json(service);
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <maxscale/router.h>
|
||||
#include <maxscale/service.h>
|
||||
#include <maxscale/spinlock.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
#include "maxscale/session.h"
|
||||
#include "maxscale/filter.h"
|
||||
@ -1015,8 +1016,11 @@ json_t* session_to_json(const MXS_SESSION *session)
|
||||
|
||||
struct tm result;
|
||||
char buf[60];
|
||||
json_object_set_new(rval, "connected",
|
||||
json_string(asctime_r(localtime_r(&session->stats.connect, &result), buf)));
|
||||
|
||||
asctime_r(localtime_r(&session->stats.connect, &result), buf);
|
||||
trim(buf);
|
||||
|
||||
json_object_set_new(rval, "connected", json_string(buf));
|
||||
|
||||
if (session->client_dcb->state == DCB_STATE_POLLING)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user