forked from cloudwatt/mod_bunny
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmb_json.c
More file actions
662 lines (540 loc) · 22.7 KB
/
mb_json.c
File metadata and controls
662 lines (540 loc) · 22.7 KB
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/*
** Copyright (c) 2013 Marc Falzon / Cloudwatt
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
*/
#include <jansson.h>
#include "mod_bunny.h"
#include "mb_json.h"
static inline int mb_json_config_check_broker_port(void *data) {
/* {{{ */
int port = *(int *)data;
if (port <= 0 || port > 65535) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: configuration error: "
"invalid `port' setting value %d", port);
return (MB_NOK);
}
return (MB_OK);
/* }}} */
}
static inline int mb_json_config_check_retry_wait_time(void *data) {
/* {{{ */
int retry_wait_time = *(int *)data;
if (retry_wait_time <= 0 || retry_wait_time > MB_MAX_RETRY_WAIT_TIME) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_config: error: "
"invalid `retry_wait_time' setting value %d", retry_wait_time);
return (MB_NOK);
}
return (MB_OK);
/* }}} */
}
static inline bool mb_json_is_string(json_t *obj) {
/* {{{ */
return json_is_string(obj);
/* }}} */
}
static inline bool mb_json_is_integer(json_t *obj) {
/* {{{ */
return json_is_integer(obj);
/* }}} */
}
static inline bool mb_json_is_boolean(json_t *obj) {
/* {{{ */
return json_is_boolean(obj);
/* }}} */
}
static inline bool mb_json_is_array(json_t *obj) {
/* {{{ */
return json_is_array(obj);
/* }}} */
}
static inline bool mb_json_is_object(json_t *obj) {
/* {{{ */
return json_is_object(obj);
/* }}} */
}
static inline int mb_json_parse_string(json_t *json_obj, void *dst, int (*check)(void *)) {
/* {{{ */
const char *tmp_str = NULL;
tmp_str = json_string_value(json_obj);
memset(dst, 0, MB_BUF_LEN);
strncpy((char *)dst, tmp_str, MB_BUF_LEN - 1);
/* Perform check on parsed value if specified */
if (check) {
if (!check(dst))
return (MB_NOK);
}
return (MB_OK);
/* }}} */
}
static inline int mb_json_parse_int(json_t *json_obj, void *dst, int (*check)(void *)) {
/* {{{ */
*(int *)dst = json_integer_value(json_obj);
/* Perform check on parsed value if specified */
if (check) {
if (!check(dst))
return (MB_NOK);
}
return (MB_OK);
/* }}} */
}
static inline int mb_json_parse_bool(json_t *json_obj, void *dst,
int (*check)(void *) __attribute__((__unused__))) {
/* {{{ */
*(bool *)dst = (json_is_true(json_obj) ? true : false);
return (MB_OK);
/* }}} */
}
static inline mb_hstgroups_t *mb_json_parse_hostgroups(json_t *json_hostgroups) {
/* {{{ */
mb_hstgroups_t *hostgroups = NULL;
mb_hstgroup_t *hostgroup = NULL;
const char *hostgroup_pattern = NULL;
int hostgroups_added = 0;
if (!(hostgroups = calloc(1, sizeof(mb_hstgroups_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_hostgroup_list: error: "
"unable to allocate memory");
return (NULL);
}
TAILQ_INIT(hostgroups);
for (int i = 0; i < (int)json_array_size(json_hostgroups); i++) {
if (!(hostgroup_pattern = json_string_value(json_array_get(json_hostgroups, i)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_hostgroup_list: error: "
"unable to get hostgroup value, skipping");
continue;
}
if (!(hostgroup = calloc(1, sizeof(mb_hstgroup_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_hostgroup_list: error: "
"unable to allocate memory");
goto error;
}
if (!(hostgroup->pattern = strdup(hostgroup_pattern))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_hostgroup_list: error: "
"unable to allocate memory");
free(hostgroup);
goto error;
}
TAILQ_INSERT_TAIL(hostgroups, hostgroup, tq);
hostgroups_added++;
}
/* If no hostgroup pattern were successfully added to the list, destroy it */
if (hostgroups_added == 0)
goto error;
return (hostgroups);
error:
mb_free_hostgroups(hostgroups);
free(hostgroups);
return (NULL);
/* }}} */
}
static inline int mb_json_parse_hostgroups_routing_table(json_t *json_hostgroups_routing_table, void *dst,
int (*check)(void *) __attribute__((__unused__))) {
/* {{{ */
mb_hstgroup_routes_t **hostgroups_routing_table = NULL;
mb_hstgroup_route_t *hostgroup_route = NULL;
const char *routing_key = NULL;
json_t *json_hostgroups = NULL;
int hostgroups_routes_added = 0;
if (json_object_size(json_hostgroups_routing_table) == 0)
return (MB_OK);
hostgroups_routing_table = (mb_hstgroup_routes_t **)dst;
if (!(*hostgroups_routing_table = calloc(1, sizeof(mb_hstgroup_routes_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_hostgroups_routing_table: error: "
"unable to allocate memory");
return (MB_NOK);
}
TAILQ_INIT(*hostgroups_routing_table);
json_object_foreach(json_hostgroups_routing_table, routing_key, json_hostgroups) {
if (!(hostgroup_route = calloc(1, sizeof(mb_hstgroup_route_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_hostgroups_routing_table: error: "
"unable to allocate memory");
goto error;
}
strncpy(hostgroup_route->routing_key, routing_key, MB_BUF_LEN - 1);
/* If hostgroups array is empty, discard this route and skip to the next */
if (json_array_size(json_hostgroups) == 0) {
free(hostgroup_route);
continue;
}
if (!(hostgroup_route->hstgroups = mb_json_parse_hostgroups(json_hostgroups))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_hostgroups_routing_table: error: "
"unable to parse hostgroups for routing key \"%s\"", routing_key);
goto error;
}
TAILQ_INSERT_TAIL(*hostgroups_routing_table, hostgroup_route, tq);
hostgroups_routes_added++;
}
return (MB_OK);
error:
mb_free_hostgroups_routing_table(*hostgroups_routing_table);
free(*hostgroups_routing_table);
*hostgroups_routing_table = NULL;
return (MB_NOK);
/* }}} */
}
static inline int mb_json_parse_local_hostgroups(json_t *json_local_hostgroups, void *dst,
int (*check)(void *) __attribute__((__unused__))) {
/* {{{ */
mb_hstgroups_t **local_hostgroups = NULL;
if (json_array_size(json_local_hostgroups) == 0)
return (MB_OK);
local_hostgroups = (mb_hstgroups_t **)dst;
if (!(*local_hostgroups = mb_json_parse_hostgroups(json_local_hostgroups))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_local_hostgroups: error: "
"unable to parse local hostgroups");
return (MB_NOK);
}
return (MB_OK);
/* }}} */
}
static inline mb_svcgroups_t *mb_json_parse_servicegroups(json_t *json_servicegroups) {
/* {{{ */
mb_svcgroups_t *servicegroups = NULL;
mb_svcgroup_t *servicegroup = NULL;
const char *servicegroup_pattern = NULL;
int servicegroups_added = 0;
if (!(servicegroups = calloc(1, sizeof(mb_svcgroups_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_servicegroup_list: error: "
"unable to allocate memory");
return (NULL);
}
TAILQ_INIT(servicegroups);
for (int i = 0; i < (int)json_array_size(json_servicegroups); i++) {
if (!(servicegroup_pattern = json_string_value(json_array_get(json_servicegroups, i)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_servicegroup_list: error: "
"unable to get servicegroup value, skipping");
continue;
}
if (!(servicegroup = calloc(1, sizeof(mb_svcgroup_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_servicegroup_list: error: "
"unable to allocate memory");
goto error;
}
if (!(servicegroup->pattern = strdup(servicegroup_pattern))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_servicegroup_list: error: "
"unable to allocate memory");
free(servicegroup);
goto error;
}
TAILQ_INSERT_TAIL(servicegroups, servicegroup, tq);
servicegroups_added++;
}
/* If no servicegroup pattern were successfully added to the list, destroy it */
if (servicegroups_added == 0)
goto error;
return (servicegroups);
error:
mb_free_servicegroups(servicegroups);
free(servicegroups);
return (NULL);
/* }}} */
}
static inline int mb_json_parse_servicegroups_routing_table(json_t *json_servicegroups_routing_table, void *dst,
int (*check)(void *) __attribute__((__unused__))) {
/* {{{ */
mb_svcgroup_routes_t **servicegroups_routing_table = NULL;
mb_svcgroup_route_t *servicegroup_route = NULL;
const char *routing_key = NULL;
json_t *json_servicegroups = NULL;
int servicegroups_routes_added = 0;
if (json_object_size(json_servicegroups_routing_table) == 0)
return (MB_OK);
servicegroups_routing_table = (mb_svcgroup_routes_t **)dst;
if (!(*servicegroups_routing_table = calloc(1, sizeof(mb_svcgroup_routes_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_servicegroups_routing_table: error: "
"unable to allocate memory");
return (MB_NOK);
}
TAILQ_INIT(*servicegroups_routing_table);
json_object_foreach(json_servicegroups_routing_table, routing_key, json_servicegroups) {
if (!(servicegroup_route = calloc(1, sizeof(mb_svcgroup_route_t)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_servicegroups_routing_table: error: "
"unable to allocate memory");
goto error;
}
strncpy(servicegroup_route->routing_key, routing_key, MB_BUF_LEN - 1);
/* If servicegroups array is empty, discard this route and skip to the next */
if (json_array_size(json_servicegroups) == 0) {
free(servicegroup_route);
continue;
}
if (!(servicegroup_route->svcgroups = mb_json_parse_servicegroups(json_servicegroups))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_servicegroups_routing_table: error: "
"unable to parse servicegroups for routing key \"%s\"", routing_key);
goto error;
}
TAILQ_INSERT_TAIL(*servicegroups_routing_table, servicegroup_route, tq);
servicegroups_routes_added++;
}
return (MB_OK);
error:
mb_free_servicegroups_routing_table(*servicegroups_routing_table);
free(*servicegroups_routing_table);
*servicegroups_routing_table = NULL;
return (MB_NOK);
/* }}} */
}
static inline int mb_json_parse_local_servicegroups(json_t *json_local_servicegroups, void *dst,
int (*check)(void *) __attribute__((__unused__))) {
/* {{{ */
mb_svcgroups_t **local_servicegroups = NULL;
if (json_array_size(json_local_servicegroups) == 0)
return (MB_OK);
local_servicegroups = (mb_svcgroups_t **)dst;
if (!(*local_servicegroups = mb_json_parse_servicegroups(json_local_servicegroups))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_local_servicegroups: error: "
"unable to parse local servicegroups");
return (MB_NOK);
}
return (MB_OK);
/* }}} */
}
int mb_json_parse_config(char *file, mb_config_t *mb_config) {
/* {{{ */
json_error_t json_error;
json_t *json_config = NULL;
json_t *json_setting_value = NULL;
mb_json_config_setting_t config_settings[] = {
{ "host", mb_config->host, mb_json_is_string,
mb_json_parse_string, NULL },
{ "port", &mb_config->port, mb_json_is_integer, mb_json_parse_int,
mb_json_config_check_broker_port },
{ "vhost", mb_config->vhost, mb_json_is_string,
mb_json_parse_string, NULL },
{ "user", mb_config->user, mb_json_is_string,
mb_json_parse_string, NULL },
{ "password", mb_config->password, mb_json_is_string,
mb_json_parse_string, NULL },
{ "publisher_exchange", mb_config->publisher_exchange, mb_json_is_string,
mb_json_parse_string, NULL },
{ "publisher_exchange_type", mb_config->publisher_exchange_type, mb_json_is_string,
mb_json_parse_string, NULL },
{ "publisher_routing_key", mb_config->publisher_routing_key, mb_json_is_string,
mb_json_parse_string, NULL },
{ "consumer_exchange", mb_config->consumer_exchange, mb_json_is_string,
mb_json_parse_string, NULL },
{ "consumer_exchange_type", mb_config->consumer_exchange_type, mb_json_is_string,
mb_json_parse_string, NULL },
{ "consumer_queue", mb_config->consumer_queue, mb_json_is_string,
mb_json_parse_string, NULL },
{ "consumer_binding_key", mb_config->consumer_binding_key, mb_json_is_string,
mb_json_parse_string, NULL },
{ "hostgroups_routing_table", &mb_config->hstgroups_routing_table, mb_json_is_object,
mb_json_parse_hostgroups_routing_table, NULL },
{ "servicegroups_routing_table", &mb_config->svcgroups_routing_table, mb_json_is_object,
mb_json_parse_servicegroups_routing_table, NULL },
{ "local_hostgroups", &mb_config->local_hstgroups, mb_json_is_array,
mb_json_parse_local_hostgroups, NULL },
{ "local_servicegroups", &mb_config->local_svcgroups, mb_json_is_array,
mb_json_parse_local_servicegroups, NULL },
{ "retry_wait_time", &mb_config->retry_wait_time, mb_json_is_integer,
mb_json_parse_int, mb_json_config_check_retry_wait_time },
{ "debug_level", &mb_config->debug_level, mb_json_is_integer,
mb_json_parse_int, NULL },
{ NULL, NULL, NULL, NULL, NULL },
};
if (!(json_config = json_load_file(file, 0, &json_error))) {
if (json_error.line == -1)
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_config: error: "
"unable to read configuration file %s: %s",
file,
(strlen(json_error.text) == 0 ? "(unknown error)" : json_error.text));
else
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_config: error: "
"syntax error in file %s at line %d: %s", file, json_error.line, json_error.text);
return (MB_NOK);
}
for (mb_json_config_setting_t *setting = config_settings; setting->name; setting++) {
if ((json_setting_value = json_object_get(json_config, setting->name))) {
if (!setting->type_check(json_setting_value)) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_config: error: "
"incorrect value type for setting `%s'", setting->name);
return (MB_NOK);
}
if (!setting->parse(json_setting_value, setting->value, setting->check)) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_parse_config: error: "
"invalid value for setting `%s'", setting->name);
return (MB_NOK);
}
}
}
json_decref(json_config);
return (MB_OK);
/* }}} */
}
char *mb_json_pack_host_check(nebstruct_host_check_data *hst_check, int check_options, char *command_line) {
/* {{{ */
json_t *json_hst_check = NULL;
char *json_buf = NULL;
if (!hst_check)
return (NULL);
json_hst_check = json_pack(
"{s:s s:s s:s s:i s:f s:f s:i}",
"type", "host",
"host_name", (hst_check->host_name ? hst_check->host_name : ""),
"command_line", command_line,
"check_options", check_options,
"start_time", TIMEVAL_TO_FLOAT(hst_check->start_time),
"latency", hst_check->latency,
"timeout", hst_check->timeout
);
if (!json_hst_check) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_pack_host_check: error: "
"json_pack() failed");
return (NULL);
}
json_buf = json_dumps(json_hst_check, JSON_COMPACT);
if (!json_buf)
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_pack_host_check: error: "
"json_dumps() failed");
json_decref(json_hst_check);
return (json_buf);
/* }}} */
}
char *mb_json_pack_service_check(nebstruct_service_check_data *svc_check, int check_options, char *command_line) {
/* {{{ */
json_t *json_svc_check = NULL;
char *json_buf = NULL;
if (!svc_check)
return (NULL);
json_svc_check = json_pack(
"{s:s s:s s:s s:s s:i s:f s:f s:i}",
"type", "service",
"host_name", (svc_check->host_name ? svc_check->host_name : ""),
"service_description", (svc_check->service_description ? svc_check->service_description : ""),
"command_line", command_line,
"check_options", check_options,
"start_time", TIMEVAL_TO_FLOAT(svc_check->start_time),
"latency", svc_check->latency,
"timeout", svc_check->timeout
);
if (!json_svc_check) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_pack_service_check: error: "
"json_pack() failed");
return (NULL);
}
json_buf = json_dumps(json_svc_check, JSON_COMPACT);
if (!json_buf)
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_pack_service_check: error: "
"json_dumps() failed");
json_decref(json_svc_check);
return (json_buf);
/* }}} */
}
check_result *mb_json_unpack_check_result(char *msg) {
/* {{{ */
check_result *cr = NULL;
json_t *json_cr = NULL;
json_t *json_host_name = NULL;
json_t *json_service_description = NULL;
json_t *json_check_options = NULL;
json_t *json_scheduled_check = NULL;
json_t *json_reschedule_check = NULL;
json_t *json_latency = NULL;
json_t *json_start_time = NULL;
json_t *json_finish_time = NULL;
json_t *json_early_timeout = NULL;
json_t *json_exited_ok = NULL;
json_t *json_return_code = NULL;
json_t *json_output = NULL;
const char *host_name = NULL;
const char *service_description = NULL;
const char *output = NULL;
if (!(json_cr = json_loads(msg, 0, NULL))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_unpack_check_result: error: "
"unable to parse JSON data");
return (NULL);
}
if (!(cr = (check_result *)calloc(1, sizeof(check_result)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: process_check_result: error: "
"unable to allocate memory");
return (NULL);
}
init_check_result(cr);
cr->output_file = NULL;
if (!(json_host_name = json_object_get(json_cr, "host_name"))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_unpack_check_result: error: "
"missing `host_name` entry in received JSON data");
goto error;
} else {
if ((host_name = json_string_value(json_host_name))) {
cr->host_name = strdup(host_name);
}
}
if (!(json_return_code = json_object_get(json_cr, "return_code"))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_unpack_check_result: error: "
"missing `return_code` entry in received JSON data");
goto error;
} else {
cr->return_code = json_integer_value(json_return_code);
}
if (!(json_start_time = json_object_get(json_cr, "start_time"))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_unpack_check_result: error: "
"missing `start_time` entry in received JSON data");
goto error;
} else {
FLOAT_TO_TIMEVAL(json_real_value(json_start_time), cr->start_time);
}
if (!(json_finish_time = json_object_get(json_cr, "finish_time"))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "mod_bunny: mb_json_unpack_check_result: error: "
"missing `finish_time` entry in received JSON data");
goto error;
} else {
FLOAT_TO_TIMEVAL(json_real_value(json_finish_time), cr->finish_time);
}
/* Set this check result as service check only if `service_description`
element exists and is not empty */
if ((json_service_description = json_object_get(json_cr, "service_description"))) {
if ((service_description = json_string_value(json_service_description))
&& strlen(service_description) > 0) {
cr->service_description = strdup(service_description);
cr->object_check_type = SERVICE_CHECK;
}
}
if ((json_output = json_object_get(json_cr, "output"))) {
if ((output = json_string_value(json_output))) {
cr->output = strdup(output);
}
}
if ((json_check_options = json_object_get(json_cr, "check_options"))) {
cr->check_options = json_integer_value(json_check_options);
}
if ((json_scheduled_check = json_object_get(json_cr, "scheduled_check"))) {
cr->scheduled_check = json_integer_value(json_scheduled_check);
}
if ((json_reschedule_check = json_object_get(json_cr, "reschedule_check"))) {
cr->reschedule_check = json_integer_value(json_reschedule_check);
}
if ((json_exited_ok = json_object_get(json_cr, "exited_ok"))) {
cr->exited_ok = json_integer_value(json_exited_ok);
}
if ((json_early_timeout = json_object_get(json_cr, "early_timeout"))) {
cr->early_timeout = json_integer_value(json_early_timeout);
}
if ((json_latency = json_object_get(json_cr, "latency"))) {
cr->latency = json_real_value(json_latency);
}
json_decref(json_cr);
return (cr);
error:
free(cr);
return (NULL);
/* }}} */
}
// vim: ft=c ts=4 et foldmethod=marker