Code cleanup (#16448)
* Code cleanup * More cleanup * More cleanup * Use FILENAME_MAX * query fix
Stelios Fragkakis committed
Dec 1, 2023 at 15:45 UTC
096d1b1b2b455375e94738220acb49df847fb269
57 files changed
+488
-483
collectors/diskspace.plugin/plugin_diskspace.c
+2
-2
@@ -225,7 +225,7 @@ static void calculate_values_and_show_charts(
225
m->st_space = rrdset_find_active_bytype_localhost("disk_space", disk);
226
if(unlikely(!m->st_space || m->st_space->update_every != update_every)) {
227
char title[4096 + 1];
228
- snprintfz(title, 4096, "Disk Space Usage");
228
+ snprintfz(title, sizeof(title) - 1, "Disk Space Usage");
229
m->st_space = rrdset_create_localhost(
230
"disk_space"
231
, disk
@@ -265,7 +265,7 @@ static void calculate_values_and_show_charts(
265
m->st_inodes = rrdset_find_active_bytype_localhost("disk_inodes", disk);
266
if(unlikely(!m->st_inodes) || m->st_inodes->update_every != update_every) {
267
char title[4096 + 1];
268
- snprintfz(title, 4096, "Disk Files (inodes) Usage");
268
+ snprintfz(title, sizeof(title) - 1, "Disk Files (inodes) Usage");
269
m->st_inodes = rrdset_create_localhost(
270
"disk_inodes"
271
, disk
collectors/ebpf.plugin/ebpf.c
+2
-2
@@ -3803,7 +3803,7 @@ static void ebpf_create_statistic_charts(int update_every)
3803
continue;
3804
3805
em->functions.order_thread_chart = j;
3806
- snprintfz(name, 255,"%s_%s", NETDATA_EBPF_THREADS, em->info.thread_name);
3806
+ snprintfz(name, sizeof(name) - 1, "%s_%s", NETDATA_EBPF_THREADS, em->info.thread_name);
3807
em->functions.fcnt_thread_chart_name = strdupz(name);
3808
ebpf_create_thread_chart(name,
3809
"Threads running.",
@@ -3816,7 +3816,7 @@ static void ebpf_create_statistic_charts(int update_every)
3816
#endif
3817
3818
em->functions.order_thread_lifetime = j;
3819
- snprintfz(name, 255,"%s_%s", NETDATA_EBPF_LIFE_TIME, em->info.thread_name);
3819
+ snprintfz(name, sizeof(name) - 1, "%s_%s", NETDATA_EBPF_LIFE_TIME, em->info.thread_name);
3820
em->functions.fcnt_thread_lifetime_name = strdupz(name);
3821
ebpf_create_thread_chart(name,
3822
"Time remaining for thread.",
collectors/ebpf.plugin/ebpf_filesystem.c
+10
-10
@@ -392,9 +392,9 @@ static void ebpf_create_fs_charts(int update_every)
392
ebpf_filesystem_partitions_t *efp = &localfs[i];
393
uint32_t flags = efp->flags;
394
if (flags & NETDATA_FILESYSTEM_FLAG_HAS_PARTITION && !(flags & test)) {
395
- snprintfz(title, 255, "%s latency for each read request.", efp->filesystem);
396
- snprintfz(family, 63, "%s_latency", efp->family);
397
- snprintfz(chart_name, 63, "%s_read_latency", efp->filesystem);
395
+ snprintfz(title, sizeof(title) - 1, "%s latency for each read request.", efp->filesystem);
396
+ snprintfz(family, sizeof(family) - 1, "%s_latency", efp->family);
397
+ snprintfz(chart_name, sizeof(chart_name) - 1, "%s_read_latency", efp->filesystem);
398
efp->hread.name = strdupz(chart_name);
399
efp->hread.title = strdupz(title);
400
efp->hread.ctx = NULL;
@@ -410,8 +410,8 @@ static void ebpf_create_fs_charts(int update_every)
410
update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM);
411
order++;
412
413
- snprintfz(title, 255, "%s latency for each write request.", efp->filesystem);
414
- snprintfz(chart_name, 63, "%s_write_latency", efp->filesystem);
413
+ snprintfz(title, sizeof(title) - 1, "%s latency for each write request.", efp->filesystem);
414
+ snprintfz(chart_name, sizeof(chart_name) - 1, "%s_write_latency", efp->filesystem);
415
efp->hwrite.name = strdupz(chart_name);
416
efp->hwrite.title = strdupz(title);
417
efp->hwrite.ctx = NULL;
@@ -425,8 +425,8 @@ static void ebpf_create_fs_charts(int update_every)
425
update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM);
426
order++;
427
428
- snprintfz(title, 255, "%s latency for each open request.", efp->filesystem);
429
- snprintfz(chart_name, 63, "%s_open_latency", efp->filesystem);
428
+ snprintfz(title, sizeof(title) - 1, "%s latency for each open request.", efp->filesystem);
429
+ snprintfz(chart_name, sizeof(chart_name) - 1, "%s_open_latency", efp->filesystem);
430
efp->hopen.name = strdupz(chart_name);
431
efp->hopen.title = strdupz(title);
432
efp->hopen.ctx = NULL;
@@ -441,9 +441,9 @@ static void ebpf_create_fs_charts(int update_every)
441
order++;
442
443
char *type = (efp->flags & NETDATA_FILESYSTEM_ATTR_CHARTS) ? "attribute" : "sync";
444
- snprintfz(title, 255, "%s latency for each %s request.", efp->filesystem, type);
445
- snprintfz(chart_name, 63, "%s_%s_latency", efp->filesystem, type);
446
- snprintfz(ctx, 63, "filesystem.%s_latency", type);
444
+ snprintfz(title, sizeof(title) - 1, "%s latency for each %s request.", efp->filesystem, type);
445
+ snprintfz(chart_name, sizeof(chart_name) - 1, "%s_%s_latency", efp->filesystem, type);
446
+ snprintfz(ctx, sizeof(ctx) - 1, "filesystem.%s_latency", type);
447
efp->hadditional.name = strdupz(chart_name);
448
efp->hadditional.title = strdupz(title);
449
efp->hadditional.ctx = strdupz(ctx);
collectors/ebpf.plugin/ebpf_functions.c
+3
-3
@@ -160,7 +160,7 @@ static void ebpf_function_thread_manipulation(const char *transaction,
160
161
lem = ebpf_functions_select_module(thread_name);
162
if (!lem) {
163
- snprintfz(message, 511, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name);
163
+ snprintfz(message, sizeof(message) - 1, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name);
164
ebpf_function_error(transaction, HTTP_RESP_NOT_FOUND, message);
165
return;
166
}
@@ -189,7 +189,7 @@ static void ebpf_function_thread_manipulation(const char *transaction,
189
const char *name = &keyword[sizeof(EBPF_THREADS_DISABLE_CATEGORY) - 1];
190
lem = ebpf_functions_select_module(name);
191
if (!lem) {
192
- snprintfz(message, 511, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name);
192
+ snprintfz(message, sizeof(message) - 1, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name);
193
ebpf_function_error(transaction, HTTP_RESP_NOT_FOUND, message);
194
return;
195
}
@@ -205,7 +205,7 @@ static void ebpf_function_thread_manipulation(const char *transaction,
205
const char *name = &keyword[sizeof(EBPF_THREADS_SELECT_THREAD) - 1];
206
lem = ebpf_functions_select_module(name);
207
if (!lem) {
208
- snprintfz(message, 511, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name);
208
+ snprintfz(message, sizeof(message) - 1, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name);
209
ebpf_function_error(transaction, HTTP_RESP_NOT_FOUND, message);
210
return;
211
}
collectors/freebsd.plugin/freebsd_getmntinfo.c
+2
-2
@@ -216,7 +216,7 @@ int do_getmntinfo(int update_every, usec_t dt) {
216
(mntbuf[i].f_blocks > 2 ||
217
netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
218
if (unlikely(!m->st_space)) {
219
- snprintfz(title, 4096, "Disk Space Usage for %s [%s]",
219
+ snprintfz(title, sizeof(title) - 1, "Disk Space Usage for %s [%s]",
220
mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
221
m->st_space = rrdset_create_localhost("disk_space",
222
mntbuf[i].f_mntonname,
@@ -254,7 +254,7 @@ int do_getmntinfo(int update_every, usec_t dt) {
254
(mntbuf[i].f_files > 1 ||
255
netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
256
if (unlikely(!m->st_inodes)) {
257
- snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]",
257
+ snprintfz(title, sizeof(title) - 1, "Disk Files (inodes) Usage for %s [%s]",
258
mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
259
m->st_inodes = rrdset_create_localhost("disk_inodes",
260
mntbuf[i].f_mntonname,
collectors/macos.plugin/macos_fw.c
+2
-2
@@ -435,7 +435,7 @@ int do_macos_iokit(int update_every, usec_t dt) {
435
if (likely(do_space)) {
436
st = rrdset_find_active_bytype_localhost("disk_space", mntbuf[i].f_mntonname);
437
if (unlikely(!st)) {
438
- snprintfz(title, 4096, "Disk Space Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
438
+ snprintfz(title, sizeof(title) - 1, "Disk Space Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
439
st = rrdset_create_localhost(
440
"disk_space"
441
, mntbuf[i].f_mntonname
@@ -467,7 +467,7 @@ int do_macos_iokit(int update_every, usec_t dt) {
467
if (likely(do_inodes)) {
468
st = rrdset_find_active_bytype_localhost("disk_inodes", mntbuf[i].f_mntonname);
469
if (unlikely(!st)) {
470
- snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
470
+ snprintfz(title, sizeof(title) - 1, "Disk Files (inodes) Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname);
471
st = rrdset_create_localhost(
472
"disk_inodes"
473
, mntbuf[i].f_mntonname
collectors/plugins.d/pluginsd_parser.c
+2
-2
@@ -929,7 +929,7 @@ static void inflight_functions_insert_callback(const DICTIONARY_ITEM *item, void
929
const char *transaction = dictionary_acquired_item_name(item);
930
931
char buffer[2048 + 1];
932
- snprintfz(buffer, 2048, "%s %s %d \"%s\"\n",
932
+ snprintfz(buffer, sizeof(buffer) - 1, "%s %s %d \"%s\"\n",
933
pf->payload ? "FUNCTION_PAYLOAD" : "FUNCTION",
934
transaction,
935
pf->timeout,
@@ -1102,7 +1102,7 @@ void pluginsd_function_cancel(void *data) {
1102
internal_error(true, "PLUGINSD: sending function cancellation to plugin for transaction '%s'", transaction);
1103
1104
char buffer[2048 + 1];
1105
- snprintfz(buffer, 2048, "%s %s\n",
1105
+ snprintfz(buffer, sizeof(buffer) - 1, "%s %s\n",
1106
PLUGINSD_KEYWORD_FUNCTION_CANCEL,
1107
transaction);
1108
collectors/proc.plugin/proc_diskstats.c
+4
-4
@@ -500,7 +500,7 @@ static inline bool ends_with(const char *str, const char *suffix) {
500
501
static inline char *get_disk_by_id(char *device) {
502
char pathname[256 + 1];
503
- snprintfz(pathname, 256, "%s/by-id", path_to_dev_disk);
503
+ snprintfz(pathname, sizeof(pathname) - 1, "%s/by-id", path_to_dev_disk);
504
505
struct dirent *entry;
506
DIR *dp = opendir(pathname);
@@ -546,9 +546,9 @@ static inline char *get_disk_model(char *device) {
546
char path[256 + 1];
547
char buffer[256 + 1];
548
549
- snprintfz(path, 256, "%s/%s/device/model", path_to_sys_block, device);
549
+ snprintfz(path, sizeof(path) - 1, "%s/%s/device/model", path_to_sys_block, device);
550
if(read_file(path, buffer, 256) != 0) {
551
- snprintfz(path, 256, "%s/%s/device/name", path_to_sys_block, device);
551
+ snprintfz(path, sizeof(path) - 1, "%s/%s/device/name", path_to_sys_block, device);
552
if(read_file(path, buffer, 256) != 0)
553
return NULL;
554
}
@@ -564,7 +564,7 @@ static inline char *get_disk_serial(char *device) {
564
char path[256 + 1];
565
char buffer[256 + 1];
566
567
- snprintfz(path, 256, "%s/%s/device/serial", path_to_sys_block, device);
567
+ snprintfz(path, sizeof(path) - 1, "%s/%s/device/serial", path_to_sys_block, device);
568
if(read_file(path, buffer, 256) != 0)
569
return NULL;
570
collectors/proc.plugin/proc_interrupts.c
+3
-3
@@ -201,10 +201,10 @@ int do_proc_interrupts(int update_every, usec_t dt) {
201
for(c = 0; c < cpus ;c++) {
202
if(unlikely(!core_st[c])) {
203
char id[50+1];
204
- snprintfz(id, 50, "cpu%d_interrupts", c);
204
+ snprintfz(id, sizeof(id) - 1, "cpu%d_interrupts", c);
205
206
char title[100+1];
207
- snprintfz(title, 100, "CPU Interrupts");
207
+ snprintfz(title, sizeof(title) - 1, "CPU Interrupts");
208
core_st[c] = rrdset_create_localhost(
209
"cpu"
210
, id
@@ -221,7 +221,7 @@ int do_proc_interrupts(int update_every, usec_t dt) {
221
);
222
223
char core[50+1];
224
- snprintfz(core, 50, "cpu%d", c);
224
+ snprintfz(core, sizeof(core) - 1, "cpu%d", c);
225
rrdlabels_add(core_st[c]->rrdlabels, "cpu", core, RRDLABEL_SRC_AUTO);
226
}
227
collectors/proc.plugin/proc_mdstat.c
+13
-13
@@ -70,7 +70,7 @@ static inline void make_chart_obsolete(char *name, const char *id_modifier)
70
RRDSET *st = NULL;
71
72
if (likely(name && id_modifier)) {
73
- snprintfz(id, 50, "mdstat.%s_%s", name, id_modifier);
73
+ snprintfz(id, sizeof(id) - 1, "mdstat.%s_%s", name, id_modifier);
74
st = rrdset_find_active_byname_localhost(id);
75
if (likely(st))
76
rrdset_is_obsolete___safe_from_collector_thread(st);
@@ -438,10 +438,10 @@ int do_proc_mdstat(int update_every, usec_t dt)
438
439
if (likely(raid->redundant)) {
440
if (likely(do_disks)) {
441
- snprintfz(id, 50, "%s_disks", raid->name);
441
+ snprintfz(id, sizeof(id) - 1, "%s_disks", raid->name);
442
443
if (unlikely(!raid->st_disks && !(raid->st_disks = rrdset_find_active_byname_localhost(id)))) {
444
- snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
444
+ snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level);
445
446
raid->st_disks = rrdset_create_localhost(
447
"mdstat",
@@ -473,10 +473,10 @@ int do_proc_mdstat(int update_every, usec_t dt)
473
}
474
475
if (likely(do_mismatch)) {
476
- snprintfz(id, 50, "%s_mismatch", raid->name);
476
+ snprintfz(id, sizeof(id) - 1, "%s_mismatch", raid->name);
477
478
if (unlikely(!raid->st_mismatch_cnt && !(raid->st_mismatch_cnt = rrdset_find_active_byname_localhost(id)))) {
479
- snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
479
+ snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level);
480
481
raid->st_mismatch_cnt = rrdset_create_localhost(
482
"mdstat",
@@ -505,10 +505,10 @@ int do_proc_mdstat(int update_every, usec_t dt)
505
}
506
507
if (likely(do_operations)) {
508
- snprintfz(id, 50, "%s_operation", raid->name);
508
+ snprintfz(id, sizeof(id) - 1, "%s_operation", raid->name);
509
510
if (unlikely(!raid->st_operation && !(raid->st_operation = rrdset_find_active_byname_localhost(id)))) {
511
- snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
511
+ snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level);
512
513
raid->st_operation = rrdset_create_localhost(
514
"mdstat",
@@ -544,9 +544,9 @@ int do_proc_mdstat(int update_every, usec_t dt)
544
rrddim_set_by_pointer(raid->st_operation, raid->rd_reshape, raid->reshape);
545
rrdset_done(raid->st_operation);
546
547
- snprintfz(id, 50, "%s_finish", raid->name);
547
+ snprintfz(id, sizeof(id) - 1, "%s_finish", raid->name);
548
if (unlikely(!raid->st_finish && !(raid->st_finish = rrdset_find_active_byname_localhost(id)))) {
549
- snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
549
+ snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level);
550
551
raid->st_finish = rrdset_create_localhost(
552
"mdstat",
@@ -572,9 +572,9 @@ int do_proc_mdstat(int update_every, usec_t dt)
572
rrddim_set_by_pointer(raid->st_finish, raid->rd_finish_in, raid->finish_in);
573
rrdset_done(raid->st_finish);
574
575
- snprintfz(id, 50, "%s_speed", raid->name);
575
+ snprintfz(id, sizeof(id) - 1, "%s_speed", raid->name);
576
if (unlikely(!raid->st_speed && !(raid->st_speed = rrdset_find_active_byname_localhost(id)))) {
577
- snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
577
+ snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level);
578
579
raid->st_speed = rrdset_create_localhost(
580
"mdstat",
@@ -603,10 +603,10 @@ int do_proc_mdstat(int update_every, usec_t dt)
603
}
604
} else {
605
if (likely(do_nonredundant)) {
606
- snprintfz(id, 50, "%s_availability", raid->name);
606
+ snprintfz(id, sizeof(id) - 1, "%s_availability", raid->name);
607
608
if (unlikely(!raid->st_nonredundant && !(raid->st_nonredundant = rrdset_find_active_localhost(id)))) {
609
- snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
609
+ snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level);
610
611
raid->st_nonredundant = rrdset_create_localhost(
612
"mdstat",
collectors/proc.plugin/proc_net_softnet_stat.c
+2
-2
@@ -111,12 +111,12 @@ int do_proc_net_softnet_stat(int update_every, usec_t dt) {
111
if(do_per_core) {
112
for(l = 0; l < lines ;l++) {
113
char id[50+1];
114
- snprintfz(id, 50, "cpu%zu_softnet_stat", l);
114
+ snprintfz(id, sizeof(id) - 1,"cpu%zu_softnet_stat", l);
115
116
st = rrdset_find_active_bytype_localhost("cpu", id);
117
if(unlikely(!st)) {
118
char title[100+1];
119
- snprintfz(title, 100, "CPU softnet_stat");
119
+ snprintfz(title, sizeof(title) - 1, "CPU softnet_stat");
120
121
st = rrdset_create_localhost(
122
"cpu"
collectors/proc.plugin/proc_pagetypeinfo.c
+4
-4
@@ -211,7 +211,7 @@ int do_proc_pagetypeinfo(int update_every, usec_t dt) {
211
);
212
for (o = 0; o < pageorders_cnt; o++) {
213
char id[3+1];
214
- snprintfz(id, 3, "%lu", o);
214
+ snprintfz(id, sizeof(id) - 1, "%lu", o);
215
216
char name[20+1];
217
dim_name(name, o, pagesize);
@@ -234,7 +234,7 @@ int do_proc_pagetypeinfo(int update_every, usec_t dt) {
234
235
// "pagetype Node" + NUMA-NodeId + ZoneName + TypeName
236
char setid[13+1+2+1+MAX_ZONETYPE_NAME+1+MAX_PAGETYPE_NAME+1];
237
- snprintfz(setid, 13+1+2+1+MAX_ZONETYPE_NAME+1+MAX_PAGETYPE_NAME, "pagetype_Node%d_%s_%s", pgl->node, pgl->zone, pgl->type);
237
+ snprintfz(setid, sizeof(setid) - 1, "pagetype_Node%d_%s_%s", pgl->node, pgl->zone, pgl->type);
238
239
// Skip explicitly refused charts
240
if (simple_pattern_matches(filter_types, setid))
@@ -260,14 +260,14 @@ int do_proc_pagetypeinfo(int update_every, usec_t dt) {
260
);
261
262
char node[50+1];
263
- snprintfz(node, 50, "node%d", pgl->node);
263
+ snprintfz(node, sizeof(node) - 1, "node%d", pgl->node);
264
rrdlabels_add(st_nodezonetype[p]->rrdlabels, "node_id", node, RRDLABEL_SRC_AUTO);
265
rrdlabels_add(st_nodezonetype[p]->rrdlabels, "node_zone", pgl->zone, RRDLABEL_SRC_AUTO);
266
rrdlabels_add(st_nodezonetype[p]->rrdlabels, "node_type", pgl->type, RRDLABEL_SRC_AUTO);
267
268
for (o = 0; o < pageorders_cnt; o++) {
269
char dimid[3+1];
270
- snprintfz(dimid, 3, "%lu", o);
270
+ snprintfz(dimid, sizeof(dimid) - 1, "%lu", o);
271
char dimname[20+1];
272
dim_name(dimname, o, pagesize);
273
collectors/proc.plugin/proc_softirqs.c
+3
-3
@@ -197,10 +197,10 @@ int do_proc_softirqs(int update_every, usec_t dt) {
197
if (unlikely(core_sum == 0)) continue; // try next core
198
199
char id[50 + 1];
200
- snprintfz(id, 50, "cpu%d_softirqs", c);
200
+ snprintfz(id, sizeof(id) - 1, "cpu%d_softirqs", c);
201
202
char title[100 + 1];
203
- snprintfz(title, 100, "CPU softirqs");
203
+ snprintfz(title, sizeof(title) - 1, "CPU softirqs");
204
205
core_st[c] = rrdset_create_localhost(
206
"cpu"
@@ -218,7 +218,7 @@ int do_proc_softirqs(int update_every, usec_t dt) {
218
);
219
220
char core[50+1];
221
- snprintfz(core, 50, "cpu%d", c);
221
+ snprintfz(core, sizeof(core) - 1, "cpu%d", c);
222
rrdlabels_add(core_st[c]->rrdlabels, "cpu", core, RRDLABEL_SRC_AUTO);
223
}
224
collectors/proc.plugin/proc_stat.c
+1
-1
@@ -1038,7 +1038,7 @@ int do_proc_stat(int update_every, usec_t dt) {
1038
);
1039
1040
char corebuf[50+1];
1041
- snprintfz(corebuf, 50, "cpu%zu", core);
1041
+ snprintfz(corebuf, sizeof(corebuf) - 1, "cpu%zu", core);
1042
rrdlabels_add(cpuidle_charts[core].st->rrdlabels, "cpu", corebuf, RRDLABEL_SRC_AUTO);
1043
1044
char cpuidle_dim_id[RRD_ID_LENGTH_MAX + 1];
collectors/proc.plugin/sys_fs_btrfs.c
+8
-8
@@ -795,7 +795,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
795
796
snprintfz(id, RRD_ID_LENGTH_MAX, "disk_%s", node->id);
797
snprintfz(name, RRD_ID_LENGTH_MAX, "disk_%s", node->label);
798
- snprintfz(title, 200, "BTRFS Physical Disk Allocation");
798
+ snprintfz(title, sizeof(title) - 1, "BTRFS Physical Disk Allocation");
799
800
netdata_fix_chart_id(id);
801
netdata_fix_chart_name(name);
@@ -854,7 +854,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
854
855
snprintfz(id, RRD_ID_LENGTH_MAX, "data_%s", node->id);
856
snprintfz(name, RRD_ID_LENGTH_MAX, "data_%s", node->label);
857
- snprintfz(title, 200, "BTRFS Data Allocation");
857
+ snprintfz(title, sizeof(title) - 1, "BTRFS Data Allocation");
858
859
netdata_fix_chart_id(id);
860
netdata_fix_chart_name(name);
@@ -898,7 +898,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
898
899
snprintfz(id, RRD_ID_LENGTH_MAX, "metadata_%s", node->id);
900
snprintfz(name, RRD_ID_LENGTH_MAX, "metadata_%s", node->label);
901
- snprintfz(title, 200, "BTRFS Metadata Allocation");
901
+ snprintfz(title, sizeof(title) - 1, "BTRFS Metadata Allocation");
902
903
netdata_fix_chart_id(id);
904
netdata_fix_chart_name(name);
@@ -944,7 +944,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
944
945
snprintfz(id, RRD_ID_LENGTH_MAX, "system_%s", node->id);
946
snprintfz(name, RRD_ID_LENGTH_MAX, "system_%s", node->label);
947
- snprintfz(title, 200, "BTRFS System Allocation");
947
+ snprintfz(title, sizeof(title) - 1, "BTRFS System Allocation");
948
949
netdata_fix_chart_id(id);
950
netdata_fix_chart_name(name);
@@ -988,7 +988,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
988
989
snprintfz(id, RRD_ID_LENGTH_MAX, "commits_%s", node->id);
990
snprintfz(name, RRD_ID_LENGTH_MAX, "commits_%s", node->label);
991
- snprintfz(title, 200, "BTRFS Commits");
991
+ snprintfz(title, sizeof(title) - 1, "BTRFS Commits");
992
993
netdata_fix_chart_id(id);
994
netdata_fix_chart_name(name);
@@ -1021,7 +1021,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
1021
1022
snprintfz(id, RRD_ID_LENGTH_MAX, "commits_perc_time_%s", node->id);
1023
snprintfz(name, RRD_ID_LENGTH_MAX, "commits_perc_time_%s", node->label);
1024
- snprintfz(title, 200, "BTRFS Commits Time Share");
1024
+ snprintfz(title, sizeof(title) - 1, "BTRFS Commits Time Share");
1025
1026
netdata_fix_chart_id(id);
1027
netdata_fix_chart_name(name);
@@ -1055,7 +1055,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
1055
1056
snprintfz(id, RRD_ID_LENGTH_MAX, "commit_timings_%s", node->id);
1057
snprintfz(name, RRD_ID_LENGTH_MAX, "commit_timings_%s", node->label);
1058
- snprintfz(title, 200, "BTRFS Commit Timings");
1058
+ snprintfz(title, sizeof(title) - 1, "BTRFS Commit Timings");
1059
1060
netdata_fix_chart_id(id);
1061
netdata_fix_chart_name(name);
@@ -1101,7 +1101,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
1101
1102
snprintfz(id, RRD_ID_LENGTH_MAX, "device_errors_dev%d_%s", d->id, node->id);
1103
snprintfz(name, RRD_ID_LENGTH_MAX, "device_errors_dev%d_%s", d->id, node->label);
1104
- snprintfz(title, 200, "BTRFS Device Errors");
1104
+ snprintfz(title, sizeof(title) - 1, "BTRFS Device Errors");
1105
1106
netdata_fix_chart_id(id);
1107
netdata_fix_chart_name(name);
collectors/statsd.plugin/statsd.c
+1
-1
@@ -2514,7 +2514,7 @@ void *statsd_main(void *ptr) {
2514
}
2515
{
2516
char buffer[314 + 1];
2517
- snprintfz(buffer, 314, "%0.1f%%", statsd.histogram_percentile);
2517
+ snprintfz(buffer, sizeof(buffer) - 1, "%0.1f%%", statsd.histogram_percentile);
2518
statsd.histogram_percentile_str = strdupz(buffer);
2519
}
2520
collectors/systemd-journal.plugin/systemd-journal.c
+1
-1
@@ -1564,7 +1564,7 @@ static void function_systemd_journal_progress(BUFFER *wb, const char *transactio
1564
buffer_json_member_add_uint64(wb, "running_duration_usec", duration_ut);
1565
buffer_json_member_add_double(wb, "progress", (double)file_working * 100.0 / (double)files_matched);
1566
char msg[1024 + 1];
1567
- snprintfz(msg, 1024,
1567
+ snprintfz(msg, sizeof(msg) - 1,
1568
"Read %zu rows (%0.0f rows/s), "
1569
"data %0.1f MB (%0.1f MB/s), "
1570
"file %zu of %zu",
daemon/analytics.c
+23
-23
@@ -149,7 +149,7 @@ void analytics_log_prometheus(void)
149
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.prometheus_hits < ANALYTICS_MAX_PROMETHEUS_HITS)) {
150
analytics_data.prometheus_hits++;
151
char b[21];
152
- snprintfz(b, 20, "%zu", analytics_data.prometheus_hits);
152
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.prometheus_hits);
153
analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b);
154
}
155
}
@@ -162,7 +162,7 @@ void analytics_log_shell(void)
162
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.shell_hits < ANALYTICS_MAX_SHELL_HITS)) {
163
analytics_data.shell_hits++;
164
char b[21];
165
- snprintfz(b, 20, "%zu", analytics_data.shell_hits);
165
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.shell_hits);
166
analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b);
167
}
168
}
@@ -175,7 +175,7 @@ void analytics_log_json(void)
175
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.json_hits < ANALYTICS_MAX_JSON_HITS)) {
176
analytics_data.json_hits++;
177
char b[21];
178
- snprintfz(b, 20, "%zu", analytics_data.json_hits);
178
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.json_hits);
179
analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b);
180
}
181
}
@@ -188,7 +188,7 @@ void analytics_log_dashboard(void)
188
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.dashboard_hits < ANALYTICS_MAX_DASHBOARD_HITS)) {
189
analytics_data.dashboard_hits++;
190
char b[21];
191
- snprintfz(b, 20, "%zu", analytics_data.dashboard_hits);
191
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.dashboard_hits);
192
analytics_set_data(&analytics_data.netdata_dashboard_used, b);
193
}
194
}
@@ -198,7 +198,7 @@ void analytics_log_dashboard(void)
198
*/
199
void analytics_report_oom_score(long long int score){
200
char b[21];
201
- snprintfz(b, 20, "%lld", score);
201
+ snprintfz(b, sizeof(b) - 1, "%lld", score);
202
analytics_set_data(&analytics_data.netdata_config_oom_score, b);
203
}
204
@@ -222,11 +222,11 @@ void analytics_mirrored_hosts(void)
222
}
223
rrd_unlock();
224
225
- snprintfz(b, 20, "%zu", count);
225
+ snprintfz(b, sizeof(b) - 1, "%zu", count);
226
analytics_set_data(&analytics_data.netdata_mirrored_host_count, b);
227
- snprintfz(b, 20, "%zu", reachable);
227
+ snprintfz(b, sizeof(b) - 1, "%zu", reachable);
228
analytics_set_data(&analytics_data.netdata_mirrored_hosts_reachable, b);
229
- snprintfz(b, 20, "%zu", unreachable);
229
+ snprintfz(b, sizeof(b) - 1, "%zu", unreachable);
230
analytics_set_data(&analytics_data.netdata_mirrored_hosts_unreachable, b);
231
}
232
@@ -281,7 +281,7 @@ void analytics_collectors(void)
281
.plugin = rrdset_plugin_name(st),
282
.module = rrdset_module_name(st)
283
};
284
- snprintfz(name, 499, "%s:%s", col.plugin, col.module);
284
+ snprintfz(name, sizeof(name) - 1, "%s:%s", col.plugin, col.module);
285
dictionary_set(dict, name, &col, sizeof(struct collector));
286
}
287
rrdset_foreach_done(st);
@@ -297,7 +297,7 @@ void analytics_collectors(void)
297
298
{
299
char b[21];
300
- snprintfz(b, 20, "%d", ap.c);
300
+ snprintfz(b, sizeof(b) - 1, "%d", ap.c);
301
analytics_set_data(&analytics_data.netdata_collectors_count, b);
302
}
303
@@ -402,7 +402,7 @@ void analytics_charts(void)
402
analytics_data.charts_count = c;
403
{
404
char b[21];
405
- snprintfz(b, 20, "%zu", c);
405
+ snprintfz(b, sizeof(b) - 1, "%zu", c);
406
analytics_set_data(&analytics_data.netdata_charts_count, b);
407
}
408
}
@@ -427,7 +427,7 @@ void analytics_metrics(void)
427
analytics_data.metrics_count = dimensions;
428
{
429
char b[21];
430
- snprintfz(b, 20, "%zu", dimensions);
430
+ snprintfz(b, sizeof(b) - 1, "%zu", dimensions);
431
analytics_set_data(&analytics_data.netdata_metrics_count, b);
432
}
433
}
@@ -454,11 +454,11 @@ void analytics_alarms(void)
454
}
455
foreach_rrdcalc_in_rrdhost_done(rc);
456
457
- snprintfz(b, 20, "%zu", alarm_normal);
457
+ snprintfz(b, sizeof(b) - 1, "%zu", alarm_normal);
458
analytics_set_data(&analytics_data.netdata_alarms_normal, b);
459
- snprintfz(b, 20, "%zu", alarm_warn);
459
+ snprintfz(b, sizeof(b) - 1, "%zu", alarm_warn);
460
analytics_set_data(&analytics_data.netdata_alarms_warning, b);
461
- snprintfz(b, 20, "%zu", alarm_crit);
461
+ snprintfz(b, sizeof(b) - 1, "%zu", alarm_crit);
462
analytics_set_data(&analytics_data.netdata_alarms_critical, b);
463
}
464
@@ -540,19 +540,19 @@ void analytics_gather_mutable_meta_data(void)
540
541
{
542
char b[21];
543
- snprintfz(b, 20, "%zu", analytics_data.prometheus_hits);
543
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.prometheus_hits);
544
analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b);
545
546
- snprintfz(b, 20, "%zu", analytics_data.shell_hits);
546
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.shell_hits);
547
analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b);
548
549
- snprintfz(b, 20, "%zu", analytics_data.json_hits);
549
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.json_hits);
550
analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b);
551
552
- snprintfz(b, 20, "%zu", analytics_data.dashboard_hits);
552
+ snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.dashboard_hits);
553
analytics_set_data(&analytics_data.netdata_dashboard_used, b);
554
555
- snprintfz(b, 20, "%zu", rrdhost_hosts_available());
555
+ snprintfz(b, sizeof(b) - 1, "%zu", rrdhost_hosts_available());
556
analytics_set_data(&analytics_data.netdata_config_hosts_available, b);
557
}
558
}
@@ -664,10 +664,10 @@ void set_late_global_environment(struct rrdhost_system_info *system_info)
664
#ifdef ENABLE_DBENGINE
665
{
666
char b[16];
667
- snprintfz(b, 15, "%d", default_rrdeng_page_cache_mb);
667
+ snprintfz(b, sizeof(b) - 1, "%d", default_rrdeng_page_cache_mb);
668
analytics_set_data(&analytics_data.netdata_config_page_cache_size, b);
669
670
- snprintfz(b, 15, "%d", default_multidb_disk_quota_mb);
670
+ snprintfz(b, sizeof(b) - 1, "%d", default_multidb_disk_quota_mb);
671
analytics_set_data(&analytics_data.netdata_config_multidb_disk_quota, b);
672
}
673
#endif
@@ -827,7 +827,7 @@ void get_system_timezone(void)
827
void set_global_environment() {
828
{
829
char b[16];
830
- snprintfz(b, 15, "%d", default_rrd_update_every);
830
+ snprintfz(b, sizeof(b) - 1, "%d", default_rrd_update_every);
831
setenv("NETDATA_UPDATE_EVERY", b, 1);
832
}
833
daemon/daemon.c
+2
-2
@@ -213,7 +213,7 @@ static void oom_score_adj(void) {
213
// check the environment
214
char *s = getenv("OOMScoreAdjust");
215
if(!s || !*s) {
216
- snprintfz(buf, 30, "%d", (int)wanted_score);
216
+ snprintfz(buf, sizeof(buf) - 1, "%d", (int)wanted_score);
217
s = buf;
218
}
219
@@ -248,7 +248,7 @@ static void oom_score_adj(void) {
248
int written = 0;
249
int fd = open("/proc/self/oom_score_adj", O_WRONLY);
250
if(fd != -1) {
251
- snprintfz(buf, 30, "%d", (int)wanted_score);
251
+ snprintfz(buf, sizeof(buf) - 1, "%d", (int)wanted_score);
252
ssize_t len = strlen(buf);
253
if(len > 0 && write(fd, buf, (size_t)len) == len) written = 1;
254
close(fd);
daemon/global_statistics.c
+1
-1
@@ -842,7 +842,7 @@ static void global_statistics_charts(void) {
842
843
for(size_t tier = 0; tier < storage_tiers ;tier++) {
844
char buf[30 + 1];
845
- snprintfz(buf, 30, "tier%zu", tier);
845
+ snprintfz(buf, sizeof(buf) - 1, "tier%zu", tier);
846
rds[tier] = rrddim_add(st_points_stored, buf, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
847
}
848
}
daemon/main.c
+1
-1
@@ -1913,7 +1913,7 @@ int main(int argc, char **argv) {
1913
1914
{
1915
char buf[20 + 1];
1916
- snprintfz(buf, 20, "%d", libuv_worker_threads);
1916
+ snprintfz(buf, sizeof(buf) - 1, "%d", libuv_worker_threads);
1917
setenv("UV_THREADPOOL_SIZE", buf, 1);
1918
}
1919
daemon/signals.c
+1
-1
@@ -42,7 +42,7 @@ static void signal_handler(int signo) {
42
43
if(signals_waiting[i].action == NETDATA_SIGNAL_FATAL) {
44
char buffer[200 + 1];
45
- snprintfz(buffer, 200, "\nSIGNAL HANDLER: received: %s. Oops! This is bad!\n", signals_waiting[i].name);
45
+ snprintfz(buffer, sizeof(buffer) - 1, "\nSIGNAL HANDLER: received: %s. Oops! This is bad!\n", signals_waiting[i].name);
46
if(write(STDERR_FILENO, buffer, strlen(buffer)) == -1) {
47
// nothing to do - we cannot write but there is no way to complain about it
48
;
daemon/unit_test.c
+7
-7
@@ -97,7 +97,7 @@ static int check_number_printing(void) {
97
int i, failed = 0;
98
for(i = 0; values[i].correct ; i++) {
99
print_netdata_double(netdata, values[i].n);
100
- snprintfz(system, 512, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n);
100
+ snprintfz(system, sizeof(system) - 1, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n);
101
102
int ok = 1;
103
if(strcmp(netdata, values[i].correct) != 0) {
@@ -319,7 +319,7 @@ void benchmark_storage_number(int loop, int multiplier) {
319
for(i = 0; i < loop ;i++) {
320
n *= multiplier;
321
if(n > storage_number_positive_max) n = storage_number_positive_min;
322
- snprintfz(buffer, 100, NETDATA_DOUBLE_FORMAT, n);
322
+ snprintfz(buffer, sizeof(buffer) - 1, NETDATA_DOUBLE_FORMAT, n);
323
}
324
}
325
@@ -507,7 +507,7 @@ int unit_test_buffer() {
507
508
const char *fmt = "string1: %s\nstring2: %s\nstring3: %s\nstring4: %s";
509
buffer_sprintf(wb, fmt, string, string, string, string);
510
- snprintfz(final, 9000, fmt, string, string, string, string);
510
+ snprintfz(final, sizeof(final) - 1, fmt, string, string, string, string);
511
512
const char *s = buffer_tostring(wb);
513
@@ -1272,7 +1272,7 @@ int run_test(struct test *test)
1272
default_rrd_update_every = test->update_every;
1273
1274
char name[101];
1275
- snprintfz(name, 100, "unittest-%s", test->name);
1275
+ snprintfz(name, sizeof(name) - 1, "unittest-%s", test->name);
1276
1277
// create the chart
1278
RRDSET *st = rrdset_create_localhost("netdata", name, name, "netdata", NULL, "Unit Testing", "a value", "unittest", NULL, 1
@@ -1534,7 +1534,7 @@ int unit_test(long delay, long shift)
1534
repeat++;
1535
1536
char name[101];
1537
- snprintfz(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
1537
+ snprintfz(name, sizeof(name) - 1, "unittest-%d-%ld-%ld", repeat, delay, shift);
1538
1539
//debug_flags = 0xffffffff;
1540
default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC;
@@ -1870,7 +1870,7 @@ static void test_dbengine_create_charts(RRDHOST *host, RRDSET *st[CHARTS], RRDDI
1870
char name[101];
1871
1872
for (i = 0 ; i < CHARTS ; ++i) {
1873
- snprintfz(name, 100, "dbengine-chart-%d", i);
1873
+ snprintfz(name, sizeof(name) - 1, "dbengine-chart-%d", i);
1874
1875
// create the chart
1876
st[i] = rrdset_create(host, "netdata", name, name, "netdata", NULL, "Unit Testing", "a value", "unittest",
@@ -1878,7 +1878,7 @@ static void test_dbengine_create_charts(RRDHOST *host, RRDSET *st[CHARTS], RRDDI
1878
rrdset_flag_set(st[i], RRDSET_FLAG_DEBUG);
1879
rrdset_flag_set(st[i], RRDSET_FLAG_STORE_FIRST);
1880
for (j = 0 ; j < DIMS ; ++j) {
1881
- snprintfz(name, 100, "dim-%d", j);
1881
+ snprintfz(name, sizeof(name) - 1, "dim-%d", j);
1882
1883
rd[i][j] = rrddim_add(st[i], name, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1884
}
database/contexts/api_v2.c
+6
-6
@@ -507,7 +507,7 @@ static bool rrdcontext_matches_alert(struct rrdcontext_to_json_v2_data *ctl, RRD
507
508
if (ctl->options & (CONTEXT_V2_OPTION_ALERTS_WITH_INSTANCES | CONTEXT_V2_OPTION_ALERTS_WITH_VALUES)) {
509
char key[20 + 1];
510
- snprintfz(key, 20, "%p", rcl);
510
+ snprintfz(key, sizeof(key) - 1, "%p", rcl);
511
512
struct sql_alert_instance_v2_entry z = {
513
.ati = ati,
@@ -616,10 +616,10 @@ static void rrdhost_receiver_to_json(BUFFER *wb, RRDHOST_STATUS *s, const char *
616
buffer_json_member_add_object(wb, "source");
617
{
618
char buf[1024 + 1];
619
- snprintfz(buf, 1024, "[%s]:%d%s", s->ingest.peers.local.ip, s->ingest.peers.local.port, s->ingest.ssl ? ":SSL" : "");
619
+ snprintfz(buf, sizeof(buf) - 1, "[%s]:%d%s", s->ingest.peers.local.ip, s->ingest.peers.local.port, s->ingest.ssl ? ":SSL" : "");
620
buffer_json_member_add_string(wb, "local", buf);
621
622
- snprintfz(buf, 1024, "[%s]:%d%s", s->ingest.peers.peer.ip, s->ingest.peers.peer.port, s->ingest.ssl ? ":SSL" : "");
622
+ snprintfz(buf, sizeof(buf) - 1, "[%s]:%d%s", s->ingest.peers.peer.ip, s->ingest.peers.peer.port, s->ingest.ssl ? ":SSL" : "");
623
buffer_json_member_add_string(wb, "remote", buf);
624
625
stream_capabilities_to_json_array(wb, s->ingest.capabilities, "capabilities");
@@ -659,10 +659,10 @@ static void rrdhost_sender_to_json(BUFFER *wb, RRDHOST_STATUS *s, const char *ke
659
buffer_json_member_add_object(wb, "destination");
660
{
661
char buf[1024 + 1];
662
- snprintfz(buf, 1024, "[%s]:%d%s", s->stream.peers.local.ip, s->stream.peers.local.port, s->stream.ssl ? ":SSL" : "");
662
+ snprintfz(buf, sizeof(buf) - 1, "[%s]:%d%s", s->stream.peers.local.ip, s->stream.peers.local.port, s->stream.ssl ? ":SSL" : "");
663
buffer_json_member_add_string(wb, "local", buf);
664
665
- snprintfz(buf, 1024, "[%s]:%d%s", s->stream.peers.peer.ip, s->stream.peers.peer.port, s->stream.ssl ? ":SSL" : "");
665
+ snprintfz(buf, sizeof(buf) - 1, "[%s]:%d%s", s->stream.peers.peer.ip, s->stream.peers.peer.port, s->stream.ssl ? ":SSL" : "");
666
buffer_json_member_add_string(wb, "remote", buf);
667
668
stream_capabilities_to_json_array(wb, s->stream.capabilities, "capabilities");
@@ -686,7 +686,7 @@ static void rrdhost_sender_to_json(BUFFER *wb, RRDHOST_STATUS *s, const char *ke
686
{
687
688
if (d->ssl) {
689
- snprintfz(buf, 1024, "%s:SSL", string2str(d->destination));
689
+ snprintfz(buf, sizeof(buf) - 1, "%s:SSL", string2str(d->destination));
690
buffer_json_member_add_string(wb, "destination", buf);
691
}
692
else
database/engine/cache.c
+3
-6
@@ -1803,7 +1803,7 @@ PGC *pgc_create(const char *name,
1803
cache->aral = callocz(cache->config.partitions, sizeof(ARAL *));
1804
for(size_t part = 0; part < cache->config.partitions ; part++) {
1805
char buf[100 +1];
1806
- snprintfz(buf, 100, "%s[%zu]", name, part);
1806
+ snprintfz(buf, sizeof(buf) - 1, "%s[%zu]", name, part);
1807
cache->aral[part] = aral_create(
1808
buf,
1809
sizeof(PGC_PAGE) + cache->config.additional_bytes_per_page,
@@ -1862,9 +1862,6 @@ void pgc_destroy(PGC *cache) {
1862
1863
freez(cache->aral);
1864
#endif
1865
-
1866
- // TODO: @stelfrag/@ktsaou is this correct? address sanitizer says
1867
- // we miss memory without this on shutdown.
1865
freez(cache->index);
1866
freez(cache);
1867
}
@@ -2522,7 +2519,7 @@ void unittest_stress_test(void) {
2519
for(size_t i = 0; i < pgc_uts.collect_threads ;i++) {
2520
collect_thread_ids[i] = i;
2521
char buffer[100 + 1];
2525
- snprintfz(buffer, 100, "COLLECT_%zu", i);
2522
+ snprintfz(buffer, sizeof(buffer) - 1, "COLLECT_%zu", i);
2523
netdata_thread_create(&collect_threads[i], buffer,
2524
NETDATA_THREAD_OPTION_JOINABLE | NETDATA_THREAD_OPTION_DONT_LOG,
2525
unittest_stress_test_collector, &collect_thread_ids[i]);
@@ -2534,7 +2531,7 @@ void unittest_stress_test(void) {
2531
for(size_t i = 0; i < pgc_uts.query_threads ;i++) {
2532
query_thread_ids[i] = i;
2533
char buffer[100 + 1];
2537
- snprintfz(buffer, 100, "QUERY_%zu", i);
2534
+ snprintfz(buffer, sizeof(buffer) - 1, "QUERY_%zu", i);
2535
initstate_r(1, pgc_uts.rand_statebufs, 1024, &pgc_uts.random_data[i]);
2536
netdata_thread_create(&queries_threads[i], buffer,
2537
NETDATA_THREAD_OPTION_JOINABLE | NETDATA_THREAD_OPTION_DONT_LOG,
database/engine/datafile.c
+1
-1
@@ -160,7 +160,7 @@ bool datafile_acquire_for_deletion(struct rrdengine_datafile *df) {
160
161
void generate_datafilepath(struct rrdengine_datafile *datafile, char *str, size_t maxlen)
162
{
163
- (void) snprintfz(str, maxlen, "%s/" DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION,
163
+ (void) snprintfz(str, maxlen - 1, "%s/" DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION,
164
datafile->ctx->config.dbfiles_path, datafile->tier, datafile->fileno);
165
}
166
database/engine/journalfile.c
+1
-1
@@ -67,7 +67,7 @@ void journalfile_v2_generate_path(struct rrdengine_datafile *datafile, char *str
67
68
void journalfile_v1_generate_path(struct rrdengine_datafile *datafile, char *str, size_t maxlen)
69
{
70
- (void) snprintfz(str, maxlen, "%s/" WALFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL WALFILE_EXTENSION,
70
+ (void) snprintfz(str, maxlen - 1, "%s/" WALFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL WALFILE_EXTENSION,
71
datafile->ctx->config.dbfiles_path, datafile->tier, datafile->fileno);
72
}
73
database/engine/metric.c
+1
-1
@@ -832,7 +832,7 @@ int mrg_unittest(void) {
832
pthread_t th[threads];
833
for(size_t i = 0; i < threads ; i++) {
834
char buf[15 + 1];
835
- snprintfz(buf, 15, "TH[%zu]", i);
835
+ snprintfz(buf, sizeof(buf) - 1, "TH[%zu]", i);
836
netdata_thread_create(&th[i], buf,
837
NETDATA_THREAD_OPTION_JOINABLE | NETDATA_THREAD_OPTION_DONT_LOG,
838
mrg_stress, &t);
database/engine/page.c
+5
-4
@@ -72,7 +72,7 @@ void pgd_init_arals(void)
72
// pgd aral
73
{
74
char buf[20 + 1];
75
- snprintfz(buf, 20, "pgd");
75
+ snprintfz(buf, sizeof(buf) - 1, "pgd");
76
77
// FIXME: add stats
78
pgd_alloc_globals.aral_pgd = aral_create(
@@ -91,7 +91,7 @@ void pgd_init_arals(void)
91
size_t tier = storage_tiers - i;
92
93
char buf[20 + 1];
94
- snprintfz(buf, 20, "tier%zu-pages", tier);
94
+ snprintfz(buf, sizeof(buf) - 1, "tier%zu-pages", tier);
95
96
pgd_alloc_globals.aral_data[tier] = aral_create(
97
buf,
@@ -106,7 +106,7 @@ void pgd_init_arals(void)
106
// gorilla buffers aral
107
for (size_t i = 0; i != 4; i++) {
108
char buf[20 + 1];
109
- snprintfz(buf, 20, "gbuffer-%zu", i);
109
+ snprintfz(buf, sizeof(buf) - 1, "gbuffer-%zu", i);
110
111
// FIXME: add stats
112
pgd_alloc_globals.aral_gorilla_buffer[i] = aral_create(
@@ -121,7 +121,7 @@ void pgd_init_arals(void)
121
// gorilla writers aral
122
for (size_t i = 0; i != 4; i++) {
123
char buf[20 + 1];
124
- snprintfz(buf, 20, "gwriter-%zu", i);
124
+ snprintfz(buf, sizeof(buf) - 1, "gwriter-%zu", i);
125
126
// FIXME: add stats
127
pgd_alloc_globals.aral_gorilla_writer[i] = aral_create(
@@ -449,6 +449,7 @@ void pgd_copy_to_extent(PGD *pg, uint8_t *dst, uint32_t dst_size)
449
"pgd_copy_to_extent() gorilla writer does not have any buffers");
450
451
bool ok = gorilla_writer_serialize(pg->gorilla.writer, dst, dst_size);
452
+ UNUSED(ok);
453
internal_fatal(!ok,
454
"pgd_copy_to_extent() tried to serialize pg=%p, gw=%p (with dst_size=%u bytes, num_buffers=%zu)",
455
pg, pg->gorilla.writer, dst_size, pg->gorilla.num_buffers);
database/engine/pdc.c
+3
-3
@@ -1039,7 +1039,7 @@ static bool epdl_populate_pages_from_extent_data(
1039
1040
if(!page_length || !start_time_s) {
1041
char log[200 + 1];
1042
- snprintfz(log, 200, "page %u (out of %u) is EMPTY", i, count);
1042
+ snprintfz(log, sizeof(log) - 1, "page %u (out of %u) is EMPTY", i, count);
1043
epdl_extent_loading_error_log(ctx, epdl, &header->descr[i], log);
1044
continue;
1045
}
@@ -1048,7 +1048,7 @@ static bool epdl_populate_pages_from_extent_data(
1048
Word_t metric_id = (Word_t)metric;
1049
if(!metric) {
1050
char log[200 + 1];
1051
- snprintfz(log, 200, "page %u (out of %u) has unknown UUID", i, count);
1051
+ snprintfz(log, sizeof(log) - 1, "page %u (out of %u) has unknown UUID", i, count);
1052
epdl_extent_loading_error_log(ctx, epdl, &header->descr[i], log);
1053
continue;
1054
}
@@ -1082,7 +1082,7 @@ static bool epdl_populate_pages_from_extent_data(
1082
else {
1083
if (unlikely(page_offset + vd.page_length > uncompressed_payload_length)) {
1084
char log[200 + 1];
1085
- snprintfz(log, 200, "page %u (out of %u) offset %u + page length %zu, "
1085
+ snprintfz(log, sizeof(log) - 1, "page %u (out of %u) offset %u + page length %zu, "
1086
"exceeds the uncompressed buffer size %u",
1087
i, count, page_offset, vd.page_length, uncompressed_payload_length);
1088
epdl_extent_loading_error_log(ctx, epdl, &header->descr[i], log);
database/engine/rrdenginelib.h
+1
-1
@@ -58,7 +58,7 @@ static inline void modify_bit(unsigned *x, unsigned pos, uint8_t val)
58
}
59
}
60
61
-#define RRDENG_PATH_MAX (4096)
61
+#define RRDENG_PATH_MAX (FILENAME_MAX + 1)
62
63
/* returns old *ptr value */
64
static inline unsigned long ulong_compare_and_swap(volatile unsigned long *ptr,
database/rrdhost.c
+3
-3
@@ -930,10 +930,10 @@ void dbengine_init(char *hostname) {
930
RRD_BACKFILL backfill = storage_tiers_backfill[tier];
931
932
if(tier > 0) {
933
- snprintfz(dbengineconfig, 200, "dbengine tier %zu multihost disk space MB", tier);
933
+ snprintfz(dbengineconfig, sizeof(dbengineconfig) - 1, "dbengine tier %zu multihost disk space MB", tier);
934
disk_space_mb = config_get_number(CONFIG_SECTION_DB, dbengineconfig, disk_space_mb);
935
936
- snprintfz(dbengineconfig, 200, "dbengine tier %zu update every iterations", tier);
936
+ snprintfz(dbengineconfig, sizeof(dbengineconfig) - 1, "dbengine tier %zu update every iterations", tier);
937
grouping_iterations = config_get_number(CONFIG_SECTION_DB, dbengineconfig, grouping_iterations);
938
if(grouping_iterations < 2) {
939
grouping_iterations = 2;
@@ -943,7 +943,7 @@ void dbengine_init(char *hostname) {
943
hostname, tier);
944
}
945
946
- snprintfz(dbengineconfig, 200, "dbengine tier %zu backfill", tier);
946
+ snprintfz(dbengineconfig, sizeof(dbengineconfig) - 1, "dbengine tier %zu backfill", tier);
947
const char *bf = config_get(CONFIG_SECTION_DB, dbengineconfig, backfill == RRD_BACKFILL_NEW ? "new" : backfill == RRD_BACKFILL_FULL ? "full" : "none");
948
if(strcmp(bf, "new") == 0) backfill = RRD_BACKFILL_NEW;
949
else if(strcmp(bf, "full") == 0) backfill = RRD_BACKFILL_FULL;
database/sqlite/sqlite_aclk.c
+17
-17
@@ -164,7 +164,7 @@ static int create_host_callback(void *data, int argc, char **argv, char **column
164
165
#ifdef ENABLE_ACLK
166
167
-#define SQL_SELECT_HOST_BY_UUID "SELECT host_id FROM host WHERE host_id = @host_id;"
167
+#define SQL_SELECT_HOST_BY_UUID "SELECT host_id FROM host WHERE host_id = @host_id"
168
static int is_host_available(uuid_t *host_id)
169
{
170
sqlite3_stmt *res = NULL;
@@ -223,7 +223,7 @@ static void sql_delete_aclk_table_list(char *host_guid)
223
BUFFER *sql = buffer_create(ACLK_SYNC_QUERY_SIZE, &netdata_buffers_statistics.buffers_sqlite);
224
225
buffer_sprintf(sql,"SELECT 'drop '||type||' IF EXISTS '||name||';' FROM sqlite_schema " \
226
- "WHERE name LIKE 'aclk_%%_%s' AND type IN ('table', 'trigger', 'index');", uuid_str);
226
+ "WHERE name LIKE 'aclk_%%_%s' AND type IN ('table', 'trigger', 'index')", uuid_str);
227
228
rc = sqlite3_prepare_v2(db_meta, buffer_tostring(sql), -1, &res, 0);
229
if (rc != SQLITE_OK) {
@@ -303,7 +303,7 @@ static int sql_check_aclk_table(void *data __maybe_unused, int argc __maybe_unus
303
}
304
305
#define SQL_SELECT_ACLK_ACTIVE_LIST "SELECT REPLACE(SUBSTR(name,19),'_','-') FROM sqlite_schema " \
306
- "WHERE name LIKE 'aclk_chart_latest_%' AND type IN ('table');"
306
+ "WHERE name LIKE 'aclk_chart_latest_%' AND type IN ('table')"
307
308
static void sql_check_aclk_table_list(void)
309
{
@@ -315,18 +315,18 @@ static void sql_check_aclk_table_list(void)
315
}
316
}
317
318
-#define SQL_ALERT_CLEANUP "DELETE FROM aclk_alert_%s WHERE date_submitted IS NOT NULL AND CAST(date_cloud_ack AS INT) < unixepoch()-%d;"
318
+#define SQL_ALERT_CLEANUP "DELETE FROM aclk_alert_%s WHERE date_submitted IS NOT NULL AND CAST(date_cloud_ack AS INT) < unixepoch()-%d"
319
320
static int sql_maint_aclk_sync_database(void *data __maybe_unused, int argc __maybe_unused, char **argv, char **column __maybe_unused)
321
{
322
- char sql[512];
323
- snprintfz(sql,511, SQL_ALERT_CLEANUP, (char *) argv[0], ACLK_DELETE_ACK_ALERTS_INTERNAL);
322
+ char sql[ACLK_SYNC_QUERY_SIZE];
323
+ snprintfz(sql,sizeof(sql) - 1, SQL_ALERT_CLEANUP, (char *) argv[0], ACLK_DELETE_ACK_ALERTS_INTERNAL);
324
if (unlikely(db_execute(db_meta, sql)))
325
error_report("Failed to clean stale ACLK alert entries");
326
return 0;
327
}
328
329
-#define SQL_SELECT_ACLK_ALERT_LIST "SELECT SUBSTR(name,12) FROM sqlite_schema WHERE name LIKE 'aclk_alert_%' AND type IN ('table');"
329
+#define SQL_SELECT_ACLK_ALERT_LIST "SELECT SUBSTR(name,12) FROM sqlite_schema WHERE name LIKE 'aclk_alert_%' AND type IN ('table')"
330
331
static void sql_maint_aclk_sync_database_all(void)
332
{
@@ -368,9 +368,7 @@ static void timer_cb(uv_timer_t *handle)
368
struct aclk_database_cmd cmd;
369
memset(&cmd, 0, sizeof(cmd));
370
371
- time_t now = now_realtime_sec();
372
-
373
- if (config->cleanup_after < now) {
371
+ if (config->cleanup_after < now_realtime_sec()) {
372
cmd.opcode = ACLK_DATABASE_CLEANUP;
373
aclk_database_enq_cmd(&cmd);
374
config->cleanup_after += ACLK_DATABASE_CLEANUP_INTERVAL;
@@ -458,7 +456,7 @@ static void aclk_synchronization(void *arg __maybe_unused)
456
sql_unregister_node(cmd.param[0]);
457
458
break;
461
-// ALERTS
459
+ // ALERTS
460
case ACLK_DATABASE_PUSH_ALERT_CONFIG:
461
aclk_push_alert_config_event(cmd.param[0], cmd.param[1]);
462
break;
@@ -511,20 +509,22 @@ void sql_create_aclk_table(RRDHOST *host __maybe_unused, uuid_t *host_uuid __may
509
510
char sql[ACLK_SYNC_QUERY_SIZE];
511
514
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE-1, TABLE_ACLK_ALERT, uuid_str);
512
+ snprintfz(sql, sizeof(sql) - 1, TABLE_ACLK_ALERT, uuid_str);
513
rc = db_execute(db_meta, sql);
514
if (unlikely(rc))
515
error_report("Failed to create ACLK alert table for host %s", host ? rrdhost_hostname(host) : host_guid);
516
else {
519
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE -1, INDEX_ACLK_ALERT1, uuid_str, uuid_str);
517
+ snprintfz(sql, sizeof(sql) - 1, INDEX_ACLK_ALERT1, uuid_str, uuid_str);
518
rc = db_execute(db_meta, sql);
519
if (unlikely(rc))
522
- error_report("Failed to create ACLK alert table index 1 for host %s", host ? string2str(host->hostname) : host_guid);
520
+ error_report(
521
+ "Failed to create ACLK alert table index 1 for host %s", host ? string2str(host->hostname) : host_guid);
522
524
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE -1, INDEX_ACLK_ALERT2, uuid_str, uuid_str);
523
+ snprintfz(sql, sizeof(sql) - 1, INDEX_ACLK_ALERT2, uuid_str, uuid_str);
524
rc = db_execute(db_meta, sql);
525
if (unlikely(rc))
527
- error_report("Failed to create ACLK alert table index 2 for host %s", host ? string2str(host->hostname) : host_guid);
526
+ error_report(
527
+ "Failed to create ACLK alert table index 2 for host %s", host ? string2str(host->hostname) : host_guid);
528
}
529
if (likely(host) && unlikely(host->aclk_config))
530
return;
@@ -560,7 +560,7 @@ void sql_create_aclk_table(RRDHOST *host __maybe_unused, uuid_t *host_uuid __may
560
561
#define SQL_FETCH_ALL_INSTANCES \
562
"SELECT ni.host_id, ni.node_id FROM host h, node_instance ni " \
563
- "WHERE h.host_id = ni.host_id AND ni.node_id IS NOT NULL; "
563
+ "WHERE h.host_id = ni.host_id AND ni.node_id IS NOT NULL"
564
565
void sql_aclk_sync_init(void)
566
{
database/sqlite/sqlite_aclk.h
+4
-4
@@ -11,7 +11,7 @@
11
#ifndef ACLK_MAX_CHART_BATCH_COUNT
12
#define ACLK_MAX_CHART_BATCH_COUNT (10)
13
#endif
14
-#define ACLK_MAX_ALERT_UPDATES (5)
14
+#define ACLK_MAX_ALERT_UPDATES "5"
15
#define ACLK_DATABASE_CLEANUP_FIRST (1200)
16
#define ACLK_DATABASE_CLEANUP_INTERVAL (3600)
17
#define ACLK_DELETE_ACK_ALERTS_INTERNAL (86400)
@@ -43,10 +43,10 @@ static inline int claimed()
43
#define TABLE_ACLK_ALERT \
44
"CREATE TABLE IF NOT EXISTS aclk_alert_%s (sequence_id INTEGER PRIMARY KEY, " \
45
"alert_unique_id, date_created, date_submitted, date_cloud_ack, filtered_alert_unique_id NOT NULL, " \
46
- "UNIQUE(alert_unique_id));"
46
+ "UNIQUE(alert_unique_id))"
47
48
-#define INDEX_ACLK_ALERT1 "CREATE INDEX IF NOT EXISTS aclk_alert_index1_%s ON aclk_alert_%s (filtered_alert_unique_id);"
49
-#define INDEX_ACLK_ALERT2 "CREATE INDEX IF NOT EXISTS aclk_alert_index2_%s ON aclk_alert_%s (date_submitted);"
48
+#define INDEX_ACLK_ALERT1 "CREATE INDEX IF NOT EXISTS aclk_alert_index1_%s ON aclk_alert_%s (filtered_alert_unique_id)"
49
+#define INDEX_ACLK_ALERT2 "CREATE INDEX IF NOT EXISTS aclk_alert_index2_%s ON aclk_alert_%s (date_submitted)"
50
51
enum aclk_database_opcode {
52
ACLK_DATABASE_NOOP = 0,
database/sqlite/sqlite_aclk_alert.c
+41
-64
@@ -22,10 +22,10 @@ static void update_filtered(ALARM_ENTRY *ae, int64_t unique_id, char *uuid_str)
22
sqlite3_stmt *res = NULL;
23
24
char sql[ACLK_SYNC_QUERY_SIZE];
25
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE-1, SQL_UPDATE_FILTERED_ALERT, uuid_str);
25
+ snprintfz(sql, sizeof(sql) - 1, SQL_UPDATE_FILTERED_ALERT, uuid_str);
26
int rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
27
if (rc != SQLITE_OK) {
28
- error_report("Failed to prepare statement when trying to check for alert variables.");
28
+ error_report("Failed to prepare statement when trying to update_filtered");
29
return;
30
}
31
@@ -99,7 +99,7 @@ done:
99
"SELECT hld.new_status, hl.config_hash_id, hld.unique_id FROM health_log hl, aclk_alert_%s aa, health_log_detail hld " \
100
"WHERE hl.host_id = @host_id AND +hld.unique_id = aa.filtered_alert_unique_id " \
101
"AND hld.alarm_id = @alarm_id AND hl.health_log_id = hld.health_log_id " \
102
- "ORDER BY hld.rowid DESC LIMIT 1;"
102
+ "ORDER BY hld.rowid DESC LIMIT 1"
103
104
static bool should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae)
105
{
@@ -115,7 +115,7 @@ static bool should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae)
115
116
//get the previous sent event of this alarm_id
117
//base the search on the last filtered event
118
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE - 1, SQL_SELECT_ALERT_BY_ID, host->aclk_config->uuid_str);
118
+ snprintfz(sql, sizeof(sql) - 1, SQL_SELECT_ALERT_BY_ID, host->aclk_config->uuid_str);
119
120
int rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
121
if (rc != SQLITE_OK) {
@@ -165,7 +165,7 @@ done:
165
166
#define SQL_QUEUE_ALERT_TO_CLOUD \
167
"INSERT INTO aclk_alert_%s (alert_unique_id, date_created, filtered_alert_unique_id) " \
168
- "VALUES (@alert_unique_id, UNIXEPOCH(), @alert_unique_id) ON CONFLICT (alert_unique_id) DO NOTHING;"
168
+ "VALUES (@alert_unique_id, UNIXEPOCH(), @alert_unique_id) ON CONFLICT (alert_unique_id) DO NOTHING"
169
170
void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae, bool skip_filter)
171
{
@@ -184,7 +184,7 @@ void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae, bool skip_filter)
184
if (is_event_from_alert_variable_config(ae->unique_id, &host->host_uuid))
185
return;
186
187
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE - 1, SQL_QUEUE_ALERT_TO_CLOUD, host->aclk_config->uuid_str);
187
+ snprintfz(sql, sizeof(sql) - 1, SQL_QUEUE_ALERT_TO_CLOUD, host->aclk_config->uuid_str);
188
189
int rc = sqlite3_prepare_v2(db_meta, sql, -1, &res_alert, 0);
190
if (unlikely(rc != SQLITE_OK)) {
@@ -259,11 +259,9 @@ static inline char *sqlite3_text_strdupz_empty(sqlite3_stmt *res, int iCol) {
259
}
260
261
262
-void aclk_push_alert_event(struct aclk_sync_cfg_t *wc)
262
+static void aclk_push_alert_event(struct aclk_sync_cfg_t *wc __maybe_unused)
263
{
264
-#ifndef ENABLE_ACLK
265
- UNUSED(wc);
266
-#else
264
+#ifdef ENABLE_ACLK
265
int rc;
266
267
if (unlikely(!wc->alert_updates)) {
@@ -285,23 +283,20 @@ void aclk_push_alert_event(struct aclk_sync_cfg_t *wc)
283
284
BUFFER *sql = buffer_create(1024, &netdata_buffers_statistics.buffers_sqlite);
285
288
- int limit = ACLK_MAX_ALERT_UPDATES;
289
-
286
sqlite3_stmt *res = NULL;
287
288
buffer_sprintf(
289
sql,
294
- "select aa.sequence_id, hld.unique_id, hld.alarm_id, hl.config_hash_id, hld.updated_by_id, hld.when_key, "
290
+ "SELECT aa.sequence_id, hld.unique_id, hld.alarm_id, hl.config_hash_id, hld.updated_by_id, hld.when_key, "
291
" hld.duration, hld.non_clear_duration, hld.flags, hld.exec_run_timestamp, hld.delay_up_to_timestamp, hl.name, "
292
" hl.chart, hl.exec, hl.recipient, ha.source, hl.units, hld.info, hld.exec_code, hld.new_status, "
293
" hld.old_status, hld.delay, hld.new_value, hld.old_value, hld.last_repeat, hl.chart_context, hld.transition_id, "
294
" hld.alarm_event_id, hl.chart_name, hld.summary "
299
- " from health_log hl, aclk_alert_%s aa, alert_hash ha, health_log_detail hld "
300
- " where hld.unique_id = aa.alert_unique_id and hl.config_hash_id = ha.hash_id and aa.date_submitted is null "
301
- " and hl.host_id = @host_id and hl.health_log_id = hld.health_log_id "
302
- " order by aa.sequence_id asc limit %d;",
303
- wc->uuid_str,
304
- limit);
295
+ " FROM health_log hl, aclk_alert_%s aa, alert_hash ha, health_log_detail hld "
296
+ " WHERE hld.unique_id = aa.alert_unique_id AND hl.config_hash_id = ha.hash_id AND aa.date_submitted IS NULL "
297
+ " AND hl.host_id = @host_id AND hl.health_log_id = hld.health_log_id "
298
+ " ORDER BY aa.sequence_id ASC LIMIT "ACLK_MAX_ALERT_UPDATES,
299
+ wc->uuid_str);
300
301
rc = sqlite3_prepare_v2(db_meta, buffer_tostring(sql), -1, &res, 0);
302
if (rc != SQLITE_OK) {
@@ -328,10 +323,7 @@ void aclk_push_alert_event(struct aclk_sync_cfg_t *wc)
323
rc = sqlite3_bind_blob(res, 1, &wc->host->host_uuid, sizeof(wc->host->host_uuid), SQLITE_STATIC);
324
if (unlikely(rc != SQLITE_OK)) {
325
error_report("Failed to bind host_id for pushing alert event.");
331
- sqlite3_finalize(res);
332
- buffer_free(sql);
333
- freez(claim_id);
334
- return;
326
+ goto done;
327
}
328
329
uint64_t first_sequence_id = 0;
@@ -411,7 +403,7 @@ void aclk_push_alert_event(struct aclk_sync_cfg_t *wc)
403
buffer_sprintf(
404
sql,
405
"UPDATE aclk_alert_%s SET date_submitted=unixepoch() "
414
- "WHERE +date_submitted IS NULL AND sequence_id BETWEEN %" PRIu64 " AND %" PRIu64 ";",
406
+ "WHERE +date_submitted IS NULL AND sequence_id BETWEEN %" PRIu64 " AND %" PRIu64,
407
wc->uuid_str,
408
first_sequence_id,
409
last_sequence_id);
@@ -434,6 +426,7 @@ void aclk_push_alert_event(struct aclk_sync_cfg_t *wc)
426
wc->alerts_log_last_sequence_id = 0;
427
}
428
429
+done:
430
rc = sqlite3_finalize(res);
431
if (unlikely(rc != SQLITE_OK))
432
error_report("Failed to finalize statement to send alert entries from the database, rc = %d", rc);
@@ -480,10 +473,10 @@ void sql_queue_existing_alerts_to_aclk(RRDHOST *host)
473
474
buffer_sprintf(
475
sql,
483
- "insert into aclk_alert_%s (alert_unique_id, date_created, filtered_alert_unique_id) "
484
- "select hld.unique_id alert_unique_id, unixepoch(), hld.unique_id alert_unique_id from health_log_detail hld, health_log hl "
485
- "where hld.new_status <> 0 and hld.new_status <> -2 and hl.health_log_id = hld.health_log_id and hl.config_hash_id is not null "
486
- "and hld.updated_by_id = 0 and hl.host_id = @host_id order by hld.unique_id asc on conflict (alert_unique_id) do nothing;",
476
+ "INSERT INTO aclk_alert_%s (alert_unique_id, date_created, filtered_alert_unique_id) "
477
+ "SELECT hld.unique_id alert_unique_id, unixepoch(), hld.unique_id alert_unique_id FROM health_log_detail hld, health_log hl "
478
+ "WHERE hld.new_status <> 0 AND hld.new_status <> -2 AND hl.health_log_id = hld.health_log_id AND hl.config_hash_id IS NOT NULL "
479
+ "AND hld.updated_by_id = 0 AND hl.host_id = @host_id ORDER BY hld.unique_id ASC ON CONFLICT (alert_unique_id) DO NOTHING",
480
wc->uuid_str);
481
482
rc = sqlite3_prepare_v2(db_meta, buffer_tostring(sql), -1, &res, 0);
@@ -536,15 +529,12 @@ void aclk_send_alarm_configuration(char *config_hash)
529
"SELECT alarm, template, on_key, class, type, component, os, hosts, plugin," \
530
"module, charts, lookup, every, units, green, red, calc, warn, crit, to_key, exec, delay, repeat, info," \
531
"options, host_labels, p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after," \
539
- "p_db_lookup_before, p_update_every, chart_labels, summary FROM alert_hash WHERE hash_id = @hash_id;"
532
+ "p_db_lookup_before, p_update_every, chart_labels, summary FROM alert_hash WHERE hash_id = @hash_id"
533
541
-int aclk_push_alert_config_event(char *node_id __maybe_unused, char *config_hash __maybe_unused)
534
+void aclk_push_alert_config_event(char *node_id __maybe_unused, char *config_hash __maybe_unused)
535
{
543
- int rc;
544
-
536
#ifdef ENABLE_ACLK
546
-
547
- CHECK_SQLITE_CONNECTION(db_meta);
537
+ int rc;
538
539
sqlite3_stmt *res = NULL;
540
struct aclk_sync_cfg_t *wc;
@@ -554,18 +544,18 @@ int aclk_push_alert_config_event(char *node_id __maybe_unused, char *config_hash
544
if (unlikely(!host || !(wc = host->aclk_config))) {
545
freez(config_hash);
546
freez(node_id);
557
- return 1;
547
+ return;
548
}
549
550
rc = sqlite3_prepare_v2(db_meta, SQL_SELECT_ALERT_CONFIG, -1, &res, 0);
551
if (rc != SQLITE_OK) {
552
error_report("Failed to prepare statement when trying to fetch an alarm hash configuration");
563
- return 1;
553
+ return;
554
}
555
556
uuid_t hash_uuid;
557
if (uuid_parse(config_hash, hash_uuid))
568
- return 1;
558
+ return;
559
560
rc = sqlite3_bind_blob(res, 1, &hash_uuid , sizeof(hash_uuid), SQLITE_STATIC);
561
if (unlikely(rc != SQLITE_OK))
@@ -653,7 +643,6 @@ bind_fail:
643
freez(config_hash);
644
freez(node_id);
645
#endif
656
- return rc;
646
}
647
648
@@ -691,10 +680,11 @@ void aclk_start_alert_streaming(char *node_id, bool resets)
680
"SELECT hld.unique_id alert_unique_id, UNIXEPOCH(), hld.unique_id alert_unique_id FROM health_log hl, health_log_detail hld " \
681
"WHERE hl.host_id = @host_id AND hl.health_log_id = hld.health_log_id AND hld.new_status = -2 AND hld.updated_by_id = 0 " \
682
"AND hld.unique_id NOT IN (SELECT alert_unique_id FROM aclk_alert_%s) " \
694
- "AND hl.config_hash_id NOT IN (select hash_id from alert_hash where warn is null and crit is null) " \
695
- "AND hl.name || hl.chart NOT IN (select name || chart from health_log where name = hl.name and " \
696
- "chart = hl.chart and alarm_id > hl.alarm_id and host_id = hl.host_id) " \
697
- "ORDER BY hld.unique_id ASC ON CONFLICT (alert_unique_id) DO NOTHING;"
683
+ "AND hl.config_hash_id NOT IN (SELECT hash_id FROM alert_hash WHERE warn IS NULL AND crit IS NULL) " \
684
+ "AND hl.name || hl.chart NOT IN (select name || chart FROM health_log WHERE name = hl.name AND " \
685
+ "chart = hl.chart AND alarm_id > hl.alarm_id AND host_id = hl.host_id) " \
686
+ "ORDER BY hld.unique_id ASC ON CONFLICT (alert_unique_id) DO NOTHING"
687
+
688
void sql_process_queue_removed_alerts_to_aclk(char *node_id)
689
{
690
struct aclk_sync_cfg_t *wc;
@@ -707,7 +697,7 @@ void sql_process_queue_removed_alerts_to_aclk(char *node_id)
697
char sql[ACLK_SYNC_QUERY_SIZE * 2];
698
sqlite3_stmt *res = NULL;
699
710
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE * 2 - 1, SQL_QUEUE_REMOVE_ALERTS, wc->uuid_str, wc->uuid_str);
700
+ snprintfz(sql, sizeof(sql) - 1, SQL_QUEUE_REMOVE_ALERTS, wc->uuid_str, wc->uuid_str);
701
702
int rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
703
if (rc != SQLITE_OK) {
@@ -902,7 +892,7 @@ void aclk_push_alert_snapshot_event(char *node_id __maybe_unused)
892
}
893
894
if (cnt) {
905
- uint32_t chunk = 1, chunks;
895
+ uint32_t chunks;
896
897
chunks = (cnt / ALARM_EVENTS_PER_CHUNK) + (cnt % ALARM_EVENTS_PER_CHUNK != 0);
898
ae = host->health_log.alarms;
@@ -913,15 +903,12 @@ void aclk_push_alert_snapshot_event(char *node_id __maybe_unused)
903
alarm_snap.claim_id = claim_id;
904
alarm_snap.snapshot_uuid = wc->alerts_snapshot_uuid;
905
alarm_snap.chunks = chunks;
916
- alarm_snap.chunk = chunk;
906
+ alarm_snap.chunk = 1;
907
908
alarm_snapshot_proto_ptr_t snapshot_proto = NULL;
909
910
for (; ae; ae = ae->next) {
921
- if (likely(ae->updated_by_id))
922
- continue;
923
-
924
- if (unlikely(ae->new_status == RRDCALC_STATUS_UNINITIALIZED))
911
+ if (likely(ae->updated_by_id) || unlikely(ae->new_status == RRDCALC_STATUS_UNINITIALIZED))
912
continue;
913
914
if (have_recent_alarm(host, ae->alarm_id, ae->unique_id))
@@ -944,19 +931,9 @@ void aclk_push_alert_snapshot_event(char *node_id __maybe_unused)
931
932
if (cnt == ALARM_EVENTS_PER_CHUNK) {
933
aclk_send_alarm_snapshot(snapshot_proto);
947
-
934
cnt = 0;
949
-
950
- if (chunk < chunks) {
951
- chunk++;
952
-
953
- struct alarm_snapshot alarm_snap;
954
- alarm_snap.node_id = wc->node_id;
955
- alarm_snap.claim_id = claim_id;
956
- alarm_snap.snapshot_uuid = wc->alerts_snapshot_uuid;
957
- alarm_snap.chunks = chunks;
958
- alarm_snap.chunk = chunk;
959
-
935
+ if (alarm_snap.chunk < chunks) {
936
+ alarm_snap.chunk++;
937
snapshot_proto = generate_alarm_snapshot_proto(&alarm_snap);
938
}
939
}
@@ -982,7 +959,7 @@ void sql_aclk_alert_clean_dead_entries(RRDHOST *host)
959
return;
960
961
char sql[ACLK_SYNC_QUERY_SIZE];
985
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE - 1, SQL_DELETE_ALERT_ENTRIES, wc->uuid_str);
962
+ snprintfz(sql, sizeof(sql) - 1, SQL_DELETE_ALERT_ENTRIES, wc->uuid_str);
963
964
sqlite3_stmt *res = NULL;
965
int rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
@@ -1009,7 +986,7 @@ skip:
986
987
#define SQL_GET_MIN_MAX_ALERT_SEQ "SELECT MIN(sequence_id), MAX(sequence_id), " \
988
"(SELECT MAX(sequence_id) FROM aclk_alert_%s WHERE date_submitted IS NOT NULL) " \
1012
- "FROM aclk_alert_%s WHERE date_submitted IS NULL;"
989
+ "FROM aclk_alert_%s WHERE date_submitted IS NULL"
990
int get_proto_alert_status(RRDHOST *host, struct proto_alert_status *proto_alert_status)
991
{
992
@@ -1022,7 +999,7 @@ int get_proto_alert_status(RRDHOST *host, struct proto_alert_status *proto_alert
999
char sql[ACLK_SYNC_QUERY_SIZE];
1000
1001
sqlite3_stmt *res = NULL;
1025
- snprintfz(sql, ACLK_SYNC_QUERY_SIZE - 1, SQL_GET_MIN_MAX_ALERT_SEQ, wc->uuid_str, wc->uuid_str);
1002
+ snprintfz(sql, sizeof(sql) - 1, SQL_GET_MIN_MAX_ALERT_SEQ, wc->uuid_str, wc->uuid_str);
1003
1004
int rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
1005
if (rc != SQLITE_OK) {
database/sqlite/sqlite_aclk_alert.h
+1
-2
@@ -15,9 +15,8 @@ struct proto_alert_status {
15
uint64_t last_submitted_sequence_id;
16
};
17
18
-void aclk_push_alert_event(struct aclk_sync_cfg_t *wc);
18
void aclk_send_alarm_configuration (char *config_hash);
20
-int aclk_push_alert_config_event(char *node_id, char *config_hash);
19
+void aclk_push_alert_config_event(char *node_id, char *config_hash);
20
void aclk_start_alert_streaming(char *node_id, bool resets);
21
void sql_queue_removed_alerts_to_aclk(RRDHOST *host);
22
void sql_process_queue_removed_alerts_to_aclk(char *node_id);
database/sqlite/sqlite_aclk_node.c
+28
-18
@@ -12,13 +12,11 @@ DICTIONARY *collectors_from_charts(RRDHOST *host, DICTIONARY *dict) {
12
RRDSET *st;
13
char name[500];
14
15
- rrdset_foreach_read(st, host) {
15
+ rrdset_foreach_read(st, host)
16
+ {
17
if (rrdset_is_available_for_viewers(st)) {
17
- struct collector_info col = {
18
- .plugin = rrdset_plugin_name(st),
19
- .module = rrdset_module_name(st)
20
- };
21
- snprintfz(name, 499, "%s:%s", col.plugin, col.module);
18
+ struct collector_info col = {.plugin = rrdset_plugin_name(st), .module = rrdset_module_name(st)};
19
+ snprintfz(name, sizeof(name) - 1, "%s:%s", col.plugin, col.module);
20
dictionary_set(dict, name, &col, sizeof(struct collector_info));
21
}
22
}
@@ -56,18 +54,20 @@ static void build_node_info(RRDHOST *host)
54
node_info.node_id = wc->node_id;
55
node_info.claim_id = get_agent_claimid();
56
node_info.machine_guid = host->machine_guid;
59
- node_info.child = (wc->host != localhost);
57
+ node_info.child = (host != localhost);
58
node_info.ml_info.ml_capable = ml_capable();
61
- node_info.ml_info.ml_enabled = ml_enabled(wc->host);
59
+ node_info.ml_info.ml_enabled = ml_enabled(host);
60
63
- node_info.node_instance_capabilities = aclk_get_node_instance_capas(wc->host);
61
+ node_info.node_instance_capabilities = aclk_get_node_instance_capas(host);
62
63
now_realtime_timeval(&node_info.updated_at);
64
65
char *host_version = NULL;
66
if (host != localhost) {
67
netdata_mutex_lock(&host->receiver_lock);
70
- host_version = strdupz(host->receiver && host->receiver->program_version ? host->receiver->program_version : rrdhost_program_version(host));
68
+ host_version = strdupz(
69
+ host->receiver && host->receiver->program_version ? host->receiver->program_version :
70
+ rrdhost_program_version(host));
71
netdata_mutex_unlock(&host->receiver_lock);
72
}
73
@@ -91,10 +91,11 @@ static void build_node_info(RRDHOST *host)
91
node_info.data.machine_guid = host->machine_guid;
92
93
struct capability node_caps[] = {
94
- { .name = "ml", .version = host->system_info->ml_capable, .enabled = host->system_info->ml_enabled },
95
- { .name = "mc", .version = host->system_info->mc_version ? host->system_info->mc_version : 0, .enabled = host->system_info->mc_version ? 1 : 0 },
96
- { .name = NULL, .version = 0, .enabled = 0 }
97
- };
94
+ {.name = "ml", .version = host->system_info->ml_capable, .enabled = host->system_info->ml_enabled},
95
+ {.name = "mc",
96
+ .version = host->system_info->mc_version ? host->system_info->mc_version : 0,
97
+ .enabled = host->system_info->mc_version ? 1 : 0},
98
+ {.name = NULL, .version = 0, .enabled = 0}};
99
node_info.node_capabilities = node_caps;
100
101
node_info.data.ml_info.ml_capable = host->system_info->ml_capable;
@@ -103,7 +104,14 @@ static void build_node_info(RRDHOST *host)
104
node_info.data.host_labels_ptr = host->rrdlabels;
105
106
aclk_update_node_info(&node_info);
106
- nd_log(NDLS_ACCESS, NDLP_DEBUG, "ACLK RES [%s (%s)]: NODE INFO SENT for guid [%s] (%s)", wc->node_id, rrdhost_hostname(wc->host), host->machine_guid, wc->host == localhost ? "parent" : "child");
107
+ nd_log(
108
+ NDLS_ACCESS,
109
+ NDLP_DEBUG,
110
+ "ACLK RES [%s (%s)]: NODE INFO SENT for guid [%s] (%s)",
111
+ wc->node_id,
112
+ rrdhost_hostname(host),
113
+ host->machine_guid,
114
+ host == localhost ? "parent" : "child");
115
116
rrd_unlock();
117
freez(node_info.claim_id);
@@ -113,7 +121,7 @@ static void build_node_info(RRDHOST *host)
121
wc->node_collectors_send = now_realtime_sec();
122
}
123
116
-bool host_is_replicating(RRDHOST *host)
124
+static bool host_is_replicating(RRDHOST *host)
125
{
126
bool replicating = false;
127
RRDSET *st;
@@ -137,6 +145,8 @@ void aclk_check_node_info_and_collectors(void)
145
size_t context_loading = 0;
146
size_t replicating = 0;
147
size_t context_pp = 0;
148
+
149
+ time_t now = now_realtime_sec();
150
dfe_start_reentrant(rrdhost_root_index, host)
151
{
152
struct aclk_sync_cfg_t *wc = host->aclk_config;
@@ -160,13 +170,13 @@ void aclk_check_node_info_and_collectors(void)
170
if (!pp_queue_empty && (wc->node_info_send_time || wc->node_collectors_send))
171
context_pp++;
172
163
- if (pp_queue_empty && wc->node_info_send_time && wc->node_info_send_time + 30 < now_realtime_sec()) {
173
+ if (pp_queue_empty && wc->node_info_send_time && wc->node_info_send_time + 30 < now) {
174
wc->node_info_send_time = 0;
175
build_node_info(host);
176
internal_error(true, "ACLK SYNC: Sending node info for %s", rrdhost_hostname(host));
177
}
178
169
- if (pp_queue_empty && wc->node_collectors_send && wc->node_collectors_send + 30 < now_realtime_sec()) {
179
+ if (pp_queue_empty && wc->node_collectors_send && wc->node_collectors_send + 30 < now) {
180
build_node_collectors(host);
181
internal_error(true, "ACLK SYNC: Sending collectors for %s", rrdhost_hostname(host));
182
wc->node_collectors_send = 0;
database/sqlite/sqlite_aclk_node.h
-1
@@ -4,5 +4,4 @@
4
#define NETDATA_SQLITE_ACLK_NODE_H
5
6
void aclk_check_node_info_and_collectors(void);
7
-bool host_finished_replication(RRDHOST *host);
7
#endif //NETDATA_SQLITE_ACLK_NODE_H
database/sqlite/sqlite_context.c
+23
-27
@@ -7,16 +7,16 @@
7
#define DB_CONTEXT_METADATA_VERSION 1
8
9
const char *database_context_config[] = {
10
- "CREATE TABLE IF NOT EXISTS context (host_id BLOB, id TEXT NOT NULL, version INT NOT NULL, title TEXT NOT NULL, " \
10
+ "CREATE TABLE IF NOT EXISTS context (host_id BLOB, id TEXT NOT NULL, version INT NOT NULL, title TEXT NOT NULL, "
11
"chart_type TEXT NOT NULL, unit TEXT NOT NULL, priority INT NOT NULL, first_time_t INT NOT NULL, "
12
"last_time_t INT NOT NULL, deleted INT NOT NULL, "
13
- "family TEXT, PRIMARY KEY (host_id, id));",
13
+ "family TEXT, PRIMARY KEY (host_id, id))",
14
15
NULL
16
};
17
18
const char *database_context_cleanup[] = {
19
- "VACUUM;",
19
+ "VACUUM",
20
NULL
21
};
22
@@ -31,7 +31,7 @@ int sql_init_context_database(int memory)
31
int rc;
32
33
if (likely(!memory))
34
- snprintfz(sqlite_database, FILENAME_MAX, "%s/context-meta.db", netdata_configured_cache_dir);
34
+ snprintfz(sqlite_database, sizeof(sqlite_database) - 1, "%s/context-meta.db", netdata_configured_cache_dir);
35
else
36
strcpy(sqlite_database, ":memory:");
37
@@ -56,9 +56,9 @@ int sql_init_context_database(int memory)
56
return 1;
57
58
if (likely(!memory))
59
- snprintfz(buf, 1024, "ATTACH DATABASE \"%s/netdata-meta.db\" as meta;", netdata_configured_cache_dir);
59
+ snprintfz(buf, sizeof(buf) - 1, "ATTACH DATABASE \"%s/netdata-meta.db\" as meta", netdata_configured_cache_dir);
60
else
61
- snprintfz(buf, 1024, "ATTACH DATABASE ':memory:' as meta;");
61
+ snprintfz(buf, sizeof(buf) - 1, "ATTACH DATABASE ':memory:' as meta");
62
63
if(init_database_batch(db_context_meta, list)) return 1;
64
@@ -92,7 +92,7 @@ void sql_close_context_database(void)
92
// Fetching data
93
//
94
#define CTX_GET_CHART_LIST "SELECT c.chart_id, c.type||'.'||c.id, c.name, c.context, c.title, c.unit, c.priority, " \
95
- "c.update_every, c.chart_type, c.family FROM chart c WHERE c.host_id = @host_id and c.chart_id is not null; "
95
+ "c.update_every, c.chart_type, c.family FROM chart c WHERE c.host_id = @host_id AND c.chart_id IS NOT NULL"
96
97
void ctx_get_chart_list(uuid_t *host_uuid, void (*dict_cb)(SQL_CHART_DATA *, void *), void *data)
98
{
@@ -141,7 +141,7 @@ skip_load:
141
142
// Dimension list
143
#define CTX_GET_DIMENSION_LIST "SELECT d.dim_id, d.id, d.name, CASE WHEN INSTR(d.options,\"hidden\") > 0 THEN 1 ELSE 0 END " \
144
- "FROM dimension d WHERE d.chart_id = @id and d.dim_id is not null ORDER BY d.rowid ASC;"
144
+ "FROM dimension d WHERE d.chart_id = @id AND d.dim_id IS NOT NULL ORDER BY d.rowid ASC"
145
void ctx_get_dimension_list(uuid_t *chart_uuid, void (*dict_cb)(SQL_DIMENSION_DATA *, void *), void *data)
146
{
147
int rc;
@@ -178,7 +178,8 @@ failed:
178
}
179
180
// LABEL LIST
181
-#define CTX_GET_LABEL_LIST "SELECT l.label_key, l.label_value, l.source_type FROM meta.chart_label l WHERE l.chart_id = @id;"
181
+#define CTX_GET_LABEL_LIST "SELECT l.label_key, l.label_value, l.source_type FROM meta.chart_label l WHERE l.chart_id = @id"
182
+
183
void ctx_get_label_list(uuid_t *chart_uuid, void (*dict_cb)(SQL_CLABEL_DATA *, void *), void *data)
184
{
185
int rc;
@@ -215,7 +216,8 @@ failed:
216
217
// CONTEXT LIST
218
#define CTX_GET_CONTEXT_LIST "SELECT id, version, title, chart_type, unit, priority, first_time_t, " \
218
- "last_time_t, deleted, family FROM context c WHERE c.host_id = @host_id;"
219
+ "last_time_t, deleted, family FROM context c WHERE c.host_id = @host_id"
220
+
221
void ctx_get_context_list(uuid_t *host_uuid, void (*dict_cb)(VERSIONED_CONTEXT_DATA *, void *), void *data)
222
{
223
@@ -266,9 +268,10 @@ failed:
268
//
269
// Storing Data
270
//
269
-#define CTX_STORE_CONTEXT "INSERT OR REPLACE INTO context " \
270
- "(host_id, id, version, title, chart_type, unit, priority, first_time_t, last_time_t, deleted, family) " \
271
- "VALUES (@host_id, @context, @version, @title, @chart_type, @unit, @priority, @first_time_t, @last_time_t, @deleted, @family);"
271
+#define CTX_STORE_CONTEXT \
272
+ "INSERT OR REPLACE INTO context " \
273
+ "(host_id, id, version, title, chart_type, unit, priority, first_time_t, last_time_t, deleted, family) " \
274
+ "VALUES (@host_id, @context, @version, @title, @chart_type, @unit, @priority, @first_t, @last_t, @delete, @family)"
275
276
int ctx_store_context(uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data)
277
{
@@ -292,7 +295,7 @@ int ctx_store_context(uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data)
295
296
rc = bind_text_null(res, 2, context_data->id, 0);
297
if (unlikely(rc != SQLITE_OK)) {
295
- error_report("Failed to bind context to store details");
298
+ error_report("Failed to bind context to store context details");
299
goto skip_store;
300
}
301
@@ -304,19 +307,19 @@ int ctx_store_context(uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data)
307
308
rc = bind_text_null(res, 4, context_data->title, 0);
309
if (unlikely(rc != SQLITE_OK)) {
307
- error_report("Failed to bind context to store details");
310
+ error_report("Failed to bind context to store context details");
311
goto skip_store;
312
}
313
314
rc = bind_text_null(res, 5, context_data->chart_type, 0);
315
if (unlikely(rc != SQLITE_OK)) {
313
- error_report("Failed to bind context to store details");
316
+ error_report("Failed to bind context to store context details");
317
goto skip_store;
318
}
319
320
rc = bind_text_null(res, 6, context_data->units, 0);
321
if (unlikely(rc != SQLITE_OK)) {
319
- error_report("Failed to bind context to store details");
322
+ error_report("Failed to bind context to store context details");
323
goto skip_store;
324
}
325
@@ -365,7 +368,7 @@ skip_store:
368
369
// Delete a context
370
368
-#define CTX_DELETE_CONTEXT "DELETE FROM context WHERE host_id = @host_id AND id = @context;"
371
+#define CTX_DELETE_CONTEXT "DELETE FROM context WHERE host_id = @host_id AND id = @context"
372
int ctx_delete_context(uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data)
373
{
374
int rc, rc_stored = 1;
@@ -382,13 +385,13 @@ int ctx_delete_context(uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data)
385
386
rc = sqlite3_bind_blob(res, 1, host_uuid, sizeof(*host_uuid), SQLITE_STATIC);
387
if (unlikely(rc != SQLITE_OK)) {
385
- error_report("Failed to bind host_id to delete context data");
388
+ error_report("Failed to bind host_id for context data deletion");
389
goto skip_delete;
390
}
391
392
rc = sqlite3_bind_text(res, 2, context_data->id, -1, SQLITE_STATIC);
393
if (unlikely(rc != SQLITE_OK)) {
391
- error_report("Failed to bind context id for data deletion");
394
+ error_report("Failed to bind context id for context data deletion");
395
goto skip_delete;
396
}
397
@@ -396,13 +399,6 @@ int ctx_delete_context(uuid_t *host_uuid, VERSIONED_CONTEXT_DATA *context_data)
399
400
if (rc_stored != SQLITE_DONE)
401
error_report("Failed to delete context %s, rc = %d", context_data->id, rc_stored);
399
-#ifdef NETDATA_INTERNAL_CHECKS
400
- else {
401
- char host_uuid_str[UUID_STR_LEN];
402
- uuid_unparse_lower(*host_uuid, host_uuid_str);
403
- netdata_log_info("%s: Deleted context %s under host %s", __FUNCTION__, context_data->id, host_uuid_str);
404
- }
405
-#endif
402
403
skip_delete:
404
rc = sqlite3_finalize(res);
database/sqlite/sqlite_db_migration.c
+51
-51
@@ -7,7 +7,7 @@ static int return_int_cb(void *data, int argc, char **argv, char **column)
7
int *status = data;
8
UNUSED(argc);
9
UNUSED(column);
10
- *status = str2uint32_t(argv[0], NULL);
10
+ *status = (int) str2uint32_t(argv[0], NULL);
11
return 0;
12
}
13
@@ -18,7 +18,7 @@ static int get_auto_vaccum(sqlite3 *database)
18
19
int exists = 0;
20
21
- snprintf(sql, 127, "PRAGMA auto_vacuum");
21
+ snprintf(sql, sizeof(sql) - 1, "PRAGMA auto_vacuum");
22
23
int rc = sqlite3_exec_monitored(database, sql, return_int_cb, (void *) &exists, &err_msg);
24
if (rc != SQLITE_OK) {
@@ -35,7 +35,7 @@ int db_table_count(sqlite3 *database)
35
char sql[128];
36
37
int count = 0;
38
- snprintf(sql, 127, "select count(1) from sqlite_schema where type = 'table'");
38
+ snprintf(sql, sizeof(sql) - 1, "select count(1) from sqlite_schema where type = 'table'");
39
int rc = sqlite3_exec_monitored(database, sql, return_int_cb, (void *) &count, &err_msg);
40
if (rc != SQLITE_OK) {
41
netdata_log_info("Error checking database table count; %s", err_msg);
@@ -51,7 +51,7 @@ int table_exists_in_database(sqlite3 *database, const char *table)
51
52
int exists = 0;
53
54
- snprintf(sql, 127, "select 1 from sqlite_schema where type = 'table' and name = '%s';", table);
54
+ snprintf(sql, sizeof(sql) - 1, "select 1 from sqlite_schema where type = 'table' and name = '%s'", table);
55
56
int rc = sqlite3_exec_monitored(database, sql, return_int_cb, (void *) &exists, &err_msg);
57
if (rc != SQLITE_OK) {
@@ -69,7 +69,7 @@ static int column_exists_in_table(sqlite3 *database, const char *table, const ch
69
70
int exists = 0;
71
72
- snprintf(sql, 127, "SELECT 1 FROM pragma_table_info('%s') where name = '%s';", table, column);
72
+ snprintf(sql, sizeof(sql) - 1, "SELECT 1 FROM pragma_table_info('%s') where name = '%s'", table, column);
73
74
int rc = sqlite3_exec_monitored(database, sql, return_int_cb, (void *) &exists, &err_msg);
75
if (rc != SQLITE_OK) {
@@ -92,64 +92,64 @@ static int get_database_user_version(sqlite3 *database)
92
}
93
94
const char *database_migrate_v1_v2[] = {
95
- "ALTER TABLE host ADD hops INTEGER NOT NULL DEFAULT 0;",
95
+ "ALTER TABLE host ADD hops INTEGER NOT NULL DEFAULT 0",
96
NULL
97
};
98
99
const char *database_migrate_v2_v3[] = {
100
- "ALTER TABLE host ADD memory_mode INT NOT NULL DEFAULT 0;",
101
- "ALTER TABLE host ADD abbrev_timezone TEXT NOT NULL DEFAULT '';",
102
- "ALTER TABLE host ADD utc_offset INT NOT NULL DEFAULT 0;",
103
- "ALTER TABLE host ADD program_name TEXT NOT NULL DEFAULT 'unknown';",
104
- "ALTER TABLE host ADD program_version TEXT NOT NULL DEFAULT 'unknown';",
105
- "ALTER TABLE host ADD entries INT NOT NULL DEFAULT 0;",
106
- "ALTER TABLE host ADD health_enabled INT NOT NULL DEFAULT 0;",
100
+ "ALTER TABLE host ADD memory_mode INT NOT NULL DEFAULT 0",
101
+ "ALTER TABLE host ADD abbrev_timezone TEXT NOT NULL DEFAULT ''",
102
+ "ALTER TABLE host ADD utc_offset INT NOT NULL DEFAULT 0",
103
+ "ALTER TABLE host ADD program_name TEXT NOT NULL DEFAULT 'unknown'",
104
+ "ALTER TABLE host ADD program_version TEXT NOT NULL DEFAULT 'unknown'",
105
+ "ALTER TABLE host ADD entries INT NOT NULL DEFAULT 0",
106
+ "ALTER TABLE host ADD health_enabled INT NOT NULL DEFAULT 0",
107
NULL
108
};
109
110
const char *database_migrate_v4_v5[] = {
111
- "DROP TABLE IF EXISTS chart_active;",
112
- "DROP TABLE IF EXISTS dimension_active;",
113
- "DROP TABLE IF EXISTS chart_hash;",
114
- "DROP TABLE IF EXISTS chart_hash_map;",
115
- "DROP VIEW IF EXISTS v_chart_hash;",
111
+ "DROP TABLE IF EXISTS chart_active",
112
+ "DROP TABLE IF EXISTS dimension_active",
113
+ "DROP TABLE IF EXISTS chart_hash",
114
+ "DROP TABLE IF EXISTS chart_hash_map",
115
+ "DROP VIEW IF EXISTS v_chart_hash",
116
NULL
117
};
118
119
const char *database_migrate_v5_v6[] = {
120
- "DROP TRIGGER IF EXISTS tr_dim_del;",
121
- "DROP TABLE IF EXISTS dimension_delete;",
120
+ "DROP TRIGGER IF EXISTS tr_dim_del",
121
+ "DROP TABLE IF EXISTS dimension_delete",
122
NULL
123
};
124
125
const char *database_migrate_v9_v10[] = {
126
- "ALTER TABLE alert_hash ADD chart_labels TEXT;",
126
+ "ALTER TABLE alert_hash ADD chart_labels TEXT",
127
NULL
128
};
129
130
const char *database_migrate_v10_v11[] = {
131
- "ALTER TABLE health_log ADD chart_name TEXT;",
131
+ "ALTER TABLE health_log ADD chart_name TEXT",
132
NULL
133
};
134
135
const char *database_migrate_v11_v12[] = {
136
- "ALTER TABLE health_log_detail ADD summary TEXT;",
137
- "ALTER TABLE alert_hash ADD summary TEXT;",
136
+ "ALTER TABLE health_log_detail ADD summary TEXT",
137
+ "ALTER TABLE alert_hash ADD summary TEXT",
138
NULL
139
};
140
141
const char *database_migrate_v12_v13_detail[] = {
142
- "ALTER TABLE health_log_detail ADD summary TEXT;",
142
+ "ALTER TABLE health_log_detail ADD summary TEXT",
143
NULL
144
};
145
146
const char *database_migrate_v12_v13_hash[] = {
147
- "ALTER TABLE alert_hash ADD summary TEXT;",
147
+ "ALTER TABLE alert_hash ADD summary TEXT",
148
NULL
149
};
150
151
const char *database_migrate_v13_v14[] = {
152
- "ALTER TABLE host ADD last_connected INT NOT NULL DEFAULT 0;",
152
+ "ALTER TABLE host ADD last_connected INT NOT NULL DEFAULT 0",
153
NULL
154
};
155
@@ -173,7 +173,7 @@ static int do_migration_v3_v4(sqlite3 *database)
173
174
int rc;
175
sqlite3_stmt *res = NULL;
176
- snprintfz(sql, 255, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'health_log_%%';");
176
+ snprintfz(sql, sizeof(sql) - 1, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'health_log_%%'");
177
rc = sqlite3_prepare_v2(database, sql, -1, &res, 0);
178
if (rc != SQLITE_OK) {
179
error_report("Failed to prepare statement to alter health_log tables");
@@ -183,7 +183,7 @@ static int do_migration_v3_v4(sqlite3 *database)
183
while (sqlite3_step_monitored(res) == SQLITE_ROW) {
184
char *table = strdupz((char *) sqlite3_column_text(res, 0));
185
if (!column_exists_in_table(database, table, "chart_context")) {
186
- snprintfz(sql, 255, "ALTER TABLE %s ADD chart_context text", table);
186
+ snprintfz(sql, sizeof(sql) - 1, "ALTER TABLE %s ADD chart_context text", table);
187
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
188
}
189
freez(table);
@@ -212,7 +212,7 @@ static int do_migration_v6_v7(sqlite3 *database)
212
213
int rc;
214
sqlite3_stmt *res = NULL;
215
- snprintfz(sql, 255, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'aclk_alert_%%';");
215
+ snprintfz(sql, sizeof(sql) - 1, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'aclk_alert_%%'");
216
rc = sqlite3_prepare_v2(database, sql, -1, &res, 0);
217
if (rc != SQLITE_OK) {
218
error_report("Failed to prepare statement to alter aclk_alert tables");
@@ -222,9 +222,9 @@ static int do_migration_v6_v7(sqlite3 *database)
222
while (sqlite3_step_monitored(res) == SQLITE_ROW) {
223
char *table = strdupz((char *) sqlite3_column_text(res, 0));
224
if (!column_exists_in_table(database, table, "filtered_alert_unique_id")) {
225
- snprintfz(sql, 255, "ALTER TABLE %s ADD filtered_alert_unique_id", table);
225
+ snprintfz(sql, sizeof(sql) - 1, "ALTER TABLE %s ADD filtered_alert_unique_id", table);
226
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
227
- snprintfz(sql, 255, "UPDATE %s SET filtered_alert_unique_id = alert_unique_id", table);
227
+ snprintfz(sql, sizeof(sql) - 1, "UPDATE %s SET filtered_alert_unique_id = alert_unique_id", table);
228
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
229
}
230
freez(table);
@@ -243,7 +243,7 @@ static int do_migration_v7_v8(sqlite3 *database)
243
244
int rc;
245
sqlite3_stmt *res = NULL;
246
- snprintfz(sql, 255, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'health_log_%%';");
246
+ snprintfz(sql, sizeof(sql) - 1, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'health_log_%%'");
247
rc = sqlite3_prepare_v2(database, sql, -1, &res, 0);
248
if (rc != SQLITE_OK) {
249
error_report("Failed to prepare statement to alter health_log tables");
@@ -253,7 +253,7 @@ static int do_migration_v7_v8(sqlite3 *database)
253
while (sqlite3_step_monitored(res) == SQLITE_ROW) {
254
char *table = strdupz((char *) sqlite3_column_text(res, 0));
255
if (!column_exists_in_table(database, table, "transition_id")) {
256
- snprintfz(sql, 255, "ALTER TABLE %s ADD transition_id blob", table);
256
+ snprintfz(sql, sizeof(sql) - 1, "ALTER TABLE %s ADD transition_id blob", table);
257
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
258
}
259
freez(table);
@@ -273,38 +273,38 @@ static int do_migration_v8_v9(sqlite3 *database)
273
sqlite3_stmt *res = NULL;
274
275
//create the health_log table and it's index
276
- snprintfz(sql, 2047, "CREATE TABLE IF NOT EXISTS health_log (health_log_id INTEGER PRIMARY KEY, host_id blob, alarm_id int, " \
276
+ snprintfz(sql, sizeof(sql) - 1, "CREATE TABLE IF NOT EXISTS health_log (health_log_id INTEGER PRIMARY KEY, host_id blob, alarm_id int, " \
277
"config_hash_id blob, name text, chart text, family text, recipient text, units text, exec text, " \
278
- "chart_context text, last_transition_id blob, UNIQUE (host_id, alarm_id)) ;");
278
+ "chart_context text, last_transition_id blob, UNIQUE (host_id, alarm_id))");
279
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
280
281
//TODO indexes
282
- snprintfz(sql, 2047, "CREATE INDEX IF NOT EXISTS health_log_ind_1 ON health_log (host_id);");
282
+ snprintfz(sql, sizeof(sql) - 1, "CREATE INDEX IF NOT EXISTS health_log_ind_1 ON health_log (host_id)");
283
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
284
285
- snprintfz(sql, 2047, "CREATE TABLE IF NOT EXISTS health_log_detail (health_log_id int, unique_id int, alarm_id int, alarm_event_id int, " \
285
+ snprintfz(sql, sizeof(sql) - 1, "CREATE TABLE IF NOT EXISTS health_log_detail (health_log_id int, unique_id int, alarm_id int, alarm_event_id int, " \
286
"updated_by_id int, updates_id int, when_key int, duration int, non_clear_duration int, " \
287
"flags int, exec_run_timestamp int, delay_up_to_timestamp int, " \
288
"info text, exec_code int, new_status real, old_status real, delay int, " \
289
- "new_value double, old_value double, last_repeat int, transition_id blob, global_id int, summary text, host_id blob);");
289
+ "new_value double, old_value double, last_repeat int, transition_id blob, global_id int, summary text, host_id blob)");
290
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
291
292
- snprintfz(sql, 2047, "CREATE INDEX IF NOT EXISTS health_log_d_ind_1 ON health_log_detail (unique_id);");
292
+ snprintfz(sql, sizeof(sql) - 1, "CREATE INDEX IF NOT EXISTS health_log_d_ind_1 ON health_log_detail (unique_id)");
293
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
294
- snprintfz(sql, 2047, "CREATE INDEX IF NOT EXISTS health_log_d_ind_2 ON health_log_detail (global_id);");
294
+ snprintfz(sql, sizeof(sql) - 1, "CREATE INDEX IF NOT EXISTS health_log_d_ind_2 ON health_log_detail (global_id)");
295
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
296
- snprintfz(sql, 2047, "CREATE INDEX IF NOT EXISTS health_log_d_ind_3 ON health_log_detail (transition_id);");
296
+ snprintfz(sql, sizeof(sql) - 1, "CREATE INDEX IF NOT EXISTS health_log_d_ind_3 ON health_log_detail (transition_id)");
297
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
298
- snprintfz(sql, 2047, "CREATE INDEX IF NOT EXISTS health_log_d_ind_4 ON health_log_detail (health_log_id);");
298
+ snprintfz(sql, sizeof(sql) - 1, "CREATE INDEX IF NOT EXISTS health_log_d_ind_4 ON health_log_detail (health_log_id)");
299
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
300
301
- snprintfz(sql, 2047, "ALTER TABLE alert_hash ADD source text;");
301
+ snprintfz(sql, sizeof(sql) - 1, "ALTER TABLE alert_hash ADD source text");
302
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
303
304
- snprintfz(sql, 2047, "CREATE INDEX IF NOT EXISTS alert_hash_index ON alert_hash (hash_id);");
304
+ snprintfz(sql, sizeof(sql) - 1, "CREATE INDEX IF NOT EXISTS alert_hash_index ON alert_hash (hash_id)");
305
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
306
307
- snprintfz(sql, 2047, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'health_log_%%' AND name <> 'health_log_detail';");
307
+ snprintfz(sql, sizeof(sql) - 1, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'health_log_%%' AND name <> 'health_log_detail'");
308
rc = sqlite3_prepare_v2(database, sql, -1, &res, 0);
309
if (rc != SQLITE_OK) {
310
error_report("Failed to prepare statement to alter health_log tables");
@@ -332,7 +332,7 @@ static int do_migration_v8_v9(sqlite3 *database)
332
dfe_done(table);
333
dictionary_destroy(dict_tables);
334
335
- snprintfz(sql, 2047, "ALTER TABLE health_log_detail DROP COLUMN host_id;");
335
+ snprintfz(sql, sizeof(sql) - 1, "ALTER TABLE health_log_detail DROP COLUMN host_id");
336
sqlite3_exec_monitored(database, sql, 0, 0, NULL);
337
338
return 0;
@@ -353,7 +353,7 @@ static int do_migration_v10_v11(sqlite3 *database)
353
return 0;
354
}
355
356
-#define MIGR_11_12_UPD_HEALTH_LOG_DETAIL "UPDATE health_log_detail SET summary = (select name from health_log where health_log_id = health_log_detail.health_log_id);"
356
+#define MIGR_11_12_UPD_HEALTH_LOG_DETAIL "UPDATE health_log_detail SET summary = (select name from health_log where health_log_id = health_log_detail.health_log_id)"
357
static int do_migration_v11_v12(sqlite3 *database)
358
{
359
int rc = 0;
@@ -374,7 +374,7 @@ static int do_migration_v14_v15(sqlite3 *database)
374
375
int rc;
376
sqlite3_stmt *res = NULL;
377
- snprintfz(sql, 255, "SELECT name FROM sqlite_schema WHERE type = \"index\" AND name LIKE \"aclk_alert_index@_%%\" ESCAPE \"@\"");
377
+ snprintfz(sql, sizeof(sql) - 1, "SELECT name FROM sqlite_schema WHERE type = \"index\" AND name LIKE \"aclk_alert_index@_%%\" ESCAPE \"@\"");
378
rc = sqlite3_prepare_v2(database, sql, -1, &res, 0);
379
if (rc != SQLITE_OK) {
380
error_report("Failed to prepare statement to drop unused indices");
@@ -383,7 +383,7 @@ static int do_migration_v14_v15(sqlite3 *database)
383
384
BUFFER *wb = buffer_create(128, NULL);
385
while (sqlite3_step_monitored(res) == SQLITE_ROW)
386
- buffer_sprintf(wb, "DROP INDEX IF EXISTS %s;", (char *) sqlite3_column_text(res, 0));
386
+ buffer_sprintf(wb, "DROP INDEX IF EXISTS %s", (char *) sqlite3_column_text(res, 0));
387
388
rc = sqlite3_finalize(res);
389
if (unlikely(rc != SQLITE_OK))
@@ -452,7 +452,7 @@ static int migrate_database(sqlite3 *database, int target_version, char *db_name
452
int user_version = 0;
453
char *err_msg = NULL;
454
455
- int rc = sqlite3_exec_monitored(database, "PRAGMA user_version;", return_int_cb, (void *) &user_version, &err_msg);
455
+ int rc = sqlite3_exec_monitored(database, "PRAGMA user_version", return_int_cb, (void *) &user_version, &err_msg);
456
if (rc != SQLITE_OK) {
457
netdata_log_info("Error checking the %s database version; %s", db_name, err_msg);
458
sqlite3_free(err_msg);
database/sqlite/sqlite_functions.c
+60
-52
@@ -14,70 +14,76 @@ const char *database_config[] = {
14
"memory_mode INT DEFAULT 0, abbrev_timezone TEXT DEFAULT '', utc_offset INT NOT NULL DEFAULT 0,"
15
"program_name TEXT NOT NULL DEFAULT 'unknown', program_version TEXT NOT NULL DEFAULT 'unknown', "
16
"entries INT NOT NULL DEFAULT 0,"
17
- "health_enabled INT NOT NULL DEFAULT 0, last_connected INT NOT NULL DEFAULT 0);",
17
+ "health_enabled INT NOT NULL DEFAULT 0, last_connected INT NOT NULL DEFAULT 0)",
18
19
"CREATE TABLE IF NOT EXISTS chart(chart_id blob PRIMARY KEY, host_id blob, type text, id text, name text, "
20
"family text, context text, title text, unit text, plugin text, module text, priority int, update_every int, "
21
- "chart_type int, memory_mode int, history_entries);",
21
+ "chart_type int, memory_mode int, history_entries)",
22
+
23
"CREATE TABLE IF NOT EXISTS dimension(dim_id blob PRIMARY KEY, chart_id blob, id text, name text, "
23
- "multiplier int, divisor int , algorithm int, options text);",
24
+ "multiplier int, divisor int , algorithm int, options text)",
25
+
26
+ "CREATE TABLE IF NOT EXISTS metadata_migration(filename text, file_size, date_created int)",
27
+
28
+ "CREATE INDEX IF NOT EXISTS ind_d2 on dimension (chart_id)",
29
+
30
+ "CREATE INDEX IF NOT EXISTS ind_c3 on chart (host_id)",
31
25
- "CREATE TABLE IF NOT EXISTS metadata_migration(filename text, file_size, date_created int);",
26
- "CREATE INDEX IF NOT EXISTS ind_d2 on dimension (chart_id);",
27
- "CREATE INDEX IF NOT EXISTS ind_c3 on chart (host_id);",
32
"CREATE TABLE IF NOT EXISTS chart_label(chart_id blob, source_type int, label_key text, "
29
- "label_value text, date_created int, PRIMARY KEY (chart_id, label_key));",
30
- "CREATE TABLE IF NOT EXISTS node_instance (host_id blob PRIMARY KEY, claim_id, node_id, date_created);",
33
+ "label_value text, date_created int, PRIMARY KEY (chart_id, label_key))",
34
+
35
+ "CREATE TABLE IF NOT EXISTS node_instance (host_id blob PRIMARY KEY, claim_id, node_id, date_created)",
36
+
37
"CREATE TABLE IF NOT EXISTS alert_hash(hash_id blob PRIMARY KEY, date_updated int, alarm text, template text, "
38
"on_key text, class text, component text, type text, os text, hosts text, lookup text, "
39
"every text, units text, calc text, families text, plugin text, module text, charts text, green text, "
40
"red text, warn text, crit text, exec text, to_key text, info text, delay text, options text, "
41
"repeat text, host_labels text, p_db_lookup_dimensions text, p_db_lookup_method text, p_db_lookup_options int, "
36
- "p_db_lookup_after int, p_db_lookup_before int, p_update_every int, source text, chart_labels text, summary text);",
42
+ "p_db_lookup_after int, p_db_lookup_before int, p_update_every int, source text, chart_labels text, summary text)",
43
44
"CREATE TABLE IF NOT EXISTS host_info(host_id blob, system_key text NOT NULL, system_value text NOT NULL, "
39
- "date_created INT, PRIMARY KEY(host_id, system_key));",
45
+ "date_created INT, PRIMARY KEY(host_id, system_key))",
46
47
"CREATE TABLE IF NOT EXISTS host_label(host_id blob, source_type int, label_key text NOT NULL, "
42
- "label_value text NOT NULL, date_created INT, PRIMARY KEY (host_id, label_key));",
48
+ "label_value text NOT NULL, date_created INT, PRIMARY KEY (host_id, label_key))",
49
50
"CREATE TRIGGER IF NOT EXISTS ins_host AFTER INSERT ON host BEGIN INSERT INTO node_instance (host_id, date_created)"
45
- " SELECT new.host_id, unixepoch() WHERE new.host_id NOT IN (SELECT host_id FROM node_instance); END;",
51
+ " SELECT new.host_id, unixepoch() WHERE new.host_id NOT IN (SELECT host_id FROM node_instance); END",
52
53
"CREATE TABLE IF NOT EXISTS health_log (health_log_id INTEGER PRIMARY KEY, host_id blob, alarm_id int, "
54
"config_hash_id blob, name text, chart text, family text, recipient text, units text, exec text, "
49
- "chart_context text, last_transition_id blob, chart_name text, UNIQUE (host_id, alarm_id)) ;",
55
+ "chart_context text, last_transition_id blob, chart_name text, UNIQUE (host_id, alarm_id))",
56
51
- "CREATE INDEX IF NOT EXISTS health_log_ind_1 ON health_log (host_id);",
57
+ "CREATE INDEX IF NOT EXISTS health_log_ind_1 ON health_log (host_id)",
58
59
"CREATE TABLE IF NOT EXISTS health_log_detail (health_log_id int, unique_id int, alarm_id int, alarm_event_id int, "
60
"updated_by_id int, updates_id int, when_key int, duration int, non_clear_duration int, "
61
"flags int, exec_run_timestamp int, delay_up_to_timestamp int, "
62
"info text, exec_code int, new_status real, old_status real, delay int, "
57
- "new_value double, old_value double, last_repeat int, transition_id blob, global_id int, summary text);",
63
+ "new_value double, old_value double, last_repeat int, transition_id blob, global_id int, summary text)",
64
59
- "CREATE INDEX IF NOT EXISTS health_log_d_ind_2 ON health_log_detail (global_id);",
60
- "CREATE INDEX IF NOT EXISTS health_log_d_ind_3 ON health_log_detail (transition_id);",
61
- "CREATE INDEX IF NOT EXISTS health_log_d_ind_5 ON health_log_detail (health_log_id, unique_id DESC);",
65
+ "CREATE INDEX IF NOT EXISTS health_log_d_ind_2 ON health_log_detail (global_id)",
66
+ "CREATE INDEX IF NOT EXISTS health_log_d_ind_3 ON health_log_detail (transition_id)",
67
+ "CREATE INDEX IF NOT EXISTS health_log_d_ind_5 ON health_log_detail (health_log_id, unique_id DESC)",
68
"CREATE INDEX IF NOT EXISTS health_log_d_ind_6 on health_log_detail (health_log_id, when_key)",
63
- "CREATE INDEX IF NOT EXISTS health_log_d_ind_7 on health_log_detail (alarm_id);",
64
- "CREATE INDEX IF NOT EXISTS health_log_d_ind_8 on health_log_detail (new_status, updated_by_id);",
69
+ "CREATE INDEX IF NOT EXISTS health_log_d_ind_7 on health_log_detail (alarm_id)",
70
+ "CREATE INDEX IF NOT EXISTS health_log_d_ind_8 on health_log_detail (new_status, updated_by_id)",
71
72
NULL
73
};
74
75
const char *database_cleanup[] = {
70
- "DELETE FROM host WHERE host_id NOT IN (SELECT host_id FROM chart);",
71
- "DELETE FROM node_instance WHERE host_id NOT IN (SELECT host_id FROM host);",
72
- "DELETE FROM host_info WHERE host_id NOT IN (SELECT host_id FROM host);",
73
- "DELETE FROM host_label WHERE host_id NOT IN (SELECT host_id FROM host);",
74
- "DROP TRIGGER IF EXISTS tr_dim_del;",
75
- "DROP INDEX IF EXISTS ind_d1;",
76
- "DROP INDEX IF EXISTS ind_c1;",
77
- "DROP INDEX IF EXISTS ind_c2;",
78
- "DROP INDEX IF EXISTS alert_hash_index;",
79
- "DROP INDEX IF EXISTS health_log_d_ind_4;",
80
- "DROP INDEX IF EXISTS health_log_d_ind_1;",
76
+ "DELETE FROM host WHERE host_id NOT IN (SELECT host_id FROM chart)",
77
+ "DELETE FROM node_instance WHERE host_id NOT IN (SELECT host_id FROM host)",
78
+ "DELETE FROM host_info WHERE host_id NOT IN (SELECT host_id FROM host)",
79
+ "DELETE FROM host_label WHERE host_id NOT IN (SELECT host_id FROM host)",
80
+ "DROP TRIGGER IF EXISTS tr_dim_del",
81
+ "DROP INDEX IF EXISTS ind_d1",
82
+ "DROP INDEX IF EXISTS ind_c1",
83
+ "DROP INDEX IF EXISTS ind_c2",
84
+ "DROP INDEX IF EXISTS alert_hash_index",
85
+ "DROP INDEX IF EXISTS health_log_d_ind_4",
86
+ "DROP INDEX IF EXISTS health_log_d_ind_1",
87
NULL
88
};
89
@@ -202,42 +208,42 @@ int configure_sqlite_database(sqlite3 *database, int target_version)
208
209
// https://www.sqlite.org/pragma.html#pragma_auto_vacuum
210
// PRAGMA schema.auto_vacuum = 0 | NONE | 1 | FULL | 2 | INCREMENTAL;
205
- snprintfz(buf, 1024, "PRAGMA auto_vacuum=%s;", config_get(CONFIG_SECTION_SQLITE, "auto vacuum", "INCREMENTAL"));
211
+ snprintfz(buf, sizeof(buf) - 1, "PRAGMA auto_vacuum=%s", config_get(CONFIG_SECTION_SQLITE, "auto vacuum", "INCREMENTAL"));
212
if (init_database_batch(database, list))
213
return 1;
214
215
// https://www.sqlite.org/pragma.html#pragma_synchronous
216
// PRAGMA schema.synchronous = 0 | OFF | 1 | NORMAL | 2 | FULL | 3 | EXTRA;
211
- snprintfz(buf, 1024, "PRAGMA synchronous=%s;", config_get(CONFIG_SECTION_SQLITE, "synchronous", "NORMAL"));
217
+ snprintfz(buf, sizeof(buf) - 1, "PRAGMA synchronous=%s", config_get(CONFIG_SECTION_SQLITE, "synchronous", "NORMAL"));
218
if (init_database_batch(database, list))
219
return 1;
220
221
// https://www.sqlite.org/pragma.html#pragma_journal_mode
222
// PRAGMA schema.journal_mode = DELETE | TRUNCATE | PERSIST | MEMORY | WAL | OFF
217
- snprintfz(buf, 1024, "PRAGMA journal_mode=%s;", config_get(CONFIG_SECTION_SQLITE, "journal mode", "WAL"));
223
+ snprintfz(buf, sizeof(buf) - 1, "PRAGMA journal_mode=%s", config_get(CONFIG_SECTION_SQLITE, "journal mode", "WAL"));
224
if (init_database_batch(database, list))
225
return 1;
226
227
// https://www.sqlite.org/pragma.html#pragma_temp_store
228
// PRAGMA temp_store = 0 | DEFAULT | 1 | FILE | 2 | MEMORY;
223
- snprintfz(buf, 1024, "PRAGMA temp_store=%s;", config_get(CONFIG_SECTION_SQLITE, "temp store", "MEMORY"));
229
+ snprintfz(buf, sizeof(buf) - 1, "PRAGMA temp_store=%s", config_get(CONFIG_SECTION_SQLITE, "temp store", "MEMORY"));
230
if (init_database_batch(database, list))
231
return 1;
232
233
// https://www.sqlite.org/pragma.html#pragma_journal_size_limit
234
// PRAGMA schema.journal_size_limit = N ;
229
- snprintfz(buf, 1024, "PRAGMA journal_size_limit=%lld;", config_get_number(CONFIG_SECTION_SQLITE, "journal size limit", 16777216));
235
+ snprintfz(buf, sizeof(buf) - 1, "PRAGMA journal_size_limit=%lld", config_get_number(CONFIG_SECTION_SQLITE, "journal size limit", 16777216));
236
if (init_database_batch(database, list))
237
return 1;
238
239
// https://www.sqlite.org/pragma.html#pragma_cache_size
240
// PRAGMA schema.cache_size = pages;
241
// PRAGMA schema.cache_size = -kibibytes;
236
- snprintfz(buf, 1024, "PRAGMA cache_size=%lld;", config_get_number(CONFIG_SECTION_SQLITE, "cache size", -2000));
242
+ snprintfz(buf, sizeof(buf) - 1, "PRAGMA cache_size=%lld", config_get_number(CONFIG_SECTION_SQLITE, "cache size", -2000));
243
if (init_database_batch(database, list))
244
return 1;
245
240
- snprintfz(buf, 1024, "PRAGMA user_version=%d;", target_version);
246
+ snprintfz(buf, sizeof(buf) - 1, "PRAGMA user_version=%d", target_version);
247
if (init_database_batch(database, list))
248
return 1;
249
@@ -384,13 +390,13 @@ int sql_init_database(db_check_action_type_t rebuild, int memory)
390
int rc;
391
392
if (likely(!memory)) {
387
- snprintfz(sqlite_database, FILENAME_MAX, "%s/.netdata-meta.db.recover", netdata_configured_cache_dir);
393
+ snprintfz(sqlite_database, sizeof(sqlite_database) - 1, "%s/.netdata-meta.db.recover", netdata_configured_cache_dir);
394
rc = unlink(sqlite_database);
395
snprintfz(sqlite_database, FILENAME_MAX, "%s/netdata-meta.db", netdata_configured_cache_dir);
396
397
if (rc == 0 || (rebuild & DB_CHECK_RECOVER)) {
398
char new_sqlite_database[FILENAME_MAX + 1];
393
- snprintfz(new_sqlite_database, FILENAME_MAX, "%s/netdata-meta-recover.db", netdata_configured_cache_dir);
399
+ snprintfz(new_sqlite_database, sizeof(new_sqlite_database) - 1, "%s/netdata-meta-recover.db", netdata_configured_cache_dir);
400
recover_database(sqlite_database, new_sqlite_database);
401
if (rebuild & DB_CHECK_RECOVER)
402
return 0;
@@ -410,7 +416,7 @@ int sql_init_database(db_check_action_type_t rebuild, int memory)
416
417
if (rebuild & DB_CHECK_RECLAIM_SPACE) {
418
netdata_log_info("Reclaiming space of %s", sqlite_database);
413
- rc = sqlite3_exec_monitored(db_meta, "VACUUM;", 0, 0, &err_msg);
419
+ rc = sqlite3_exec_monitored(db_meta, "VACUUM", 0, 0, &err_msg);
420
if (rc != SQLITE_OK) {
421
error_report("Failed to execute VACUUM rc = %d (%s)", rc, err_msg);
422
sqlite3_free(err_msg);
@@ -565,7 +571,7 @@ static inline void set_host_node_id(RRDHOST *host, uuid_t *node_id)
571
uuid_unparse_lower(*node_id, wc->node_id);
572
}
573
568
-#define SQL_UPDATE_NODE_ID "update node_instance set node_id = @node_id where host_id = @host_id;"
574
+#define SQL_UPDATE_NODE_ID "UPDATE node_instance SET node_id = @node_id WHERE host_id = @host_id"
575
576
int update_node_id(uuid_t *host_id, uuid_t *node_id)
577
{
@@ -617,7 +623,7 @@ failed:
623
return rc - 1;
624
}
625
620
-#define SQL_SELECT_NODE_ID "SELECT node_id FROM node_instance WHERE host_id = @host_id AND node_id IS NOT NULL;"
626
+#define SQL_SELECT_NODE_ID "SELECT node_id FROM node_instance WHERE host_id = @host_id AND node_id IS NOT NULL"
627
628
int get_node_id(uuid_t *host_id, uuid_t *node_id)
629
{
@@ -653,8 +659,9 @@ failed:
659
return (rc == SQLITE_ROW) ? 0 : -1;
660
}
661
656
-#define SQL_INVALIDATE_NODE_INSTANCES "UPDATE node_instance SET node_id = NULL WHERE EXISTS " \
657
- "(SELECT host_id FROM node_instance WHERE host_id = @host_id AND (@claim_id IS NULL OR claim_id <> @claim_id));"
662
+#define SQL_INVALIDATE_NODE_INSTANCES \
663
+ "UPDATE node_instance SET node_id = NULL WHERE EXISTS " \
664
+ "(SELECT host_id FROM node_instance WHERE host_id = @host_id AND (@claim_id IS NULL OR claim_id <> @claim_id))"
665
666
void invalidate_node_instances(uuid_t *host_id, uuid_t *claim_id)
667
{
@@ -698,8 +705,9 @@ failed:
705
error_report("Failed to finalize the prepared statement when invalidating node instance information");
706
}
707
701
-#define SQL_GET_NODE_INSTANCE_LIST "SELECT ni.node_id, ni.host_id, h.hostname " \
702
- "FROM node_instance ni, host h WHERE ni.host_id = h.host_id AND h.hops >=0;"
708
+#define SQL_GET_NODE_INSTANCE_LIST \
709
+ "SELECT ni.node_id, ni.host_id, h.hostname " \
710
+ "FROM node_instance ni, host h WHERE ni.host_id = h.host_id AND h.hops >=0"
711
712
struct node_instance_list *get_node_list(void)
713
{
@@ -768,7 +776,7 @@ failed:
776
return node_list;
777
};
778
771
-#define SQL_GET_HOST_NODE_ID "select node_id from node_instance where host_id = @host_id;"
779
+#define SQL_GET_HOST_NODE_ID "SELECT node_id FROM node_instance WHERE host_id = @host_id"
780
781
void sql_load_node_id(RRDHOST *host)
782
{
@@ -807,7 +815,7 @@ failed:
815
};
816
817
810
-#define SELECT_HOST_INFO "SELECT system_key, system_value FROM host_info WHERE host_id = @host_id;"
818
+#define SELECT_HOST_INFO "SELECT system_key, system_value FROM host_info WHERE host_id = @host_id"
819
820
void sql_build_host_system_info(uuid_t *host_id, struct rrdhost_system_info *system_info)
821
{
@@ -838,7 +846,7 @@ skip:
846
}
847
848
#define SELECT_HOST_LABELS "SELECT label_key, label_value, source_type FROM host_label WHERE host_id = @host_id " \
841
- "AND label_key IS NOT NULL AND label_value IS NOT NULL;"
849
+ "AND label_key IS NOT NULL AND label_value IS NOT NULL"
850
851
RRDLABELS *sql_load_host_labels(uuid_t *host_id)
852
{
@@ -894,7 +902,7 @@ int sql_metadata_cache_stats(int op)
902
return count;
903
}
904
897
-#define SQL_DROP_TABLE "DROP table %s;"
905
+#define SQL_DROP_TABLE "DROP table %s"
906
907
void sql_drop_table(const char *table)
908
{
@@ -902,7 +910,7 @@ void sql_drop_table(const char *table)
910
return;
911
912
char wstr[255];
905
- snprintfz(wstr, 254, SQL_DROP_TABLE, table);
913
+ snprintfz(wstr, sizeof(wstr) - 1, SQL_DROP_TABLE, table);
914
915
int rc = sqlite3_exec_monitored(db_meta, wstr, 0, 0, NULL);
916
if (rc != SQLITE_OK) {
database/sqlite/sqlite_health.c
+80
-60
@@ -95,18 +95,22 @@ failed:
95
/* Health related SQL queries
96
Inserts an entry in the table
97
*/
98
+
99
#define SQL_INSERT_HEALTH_LOG \
100
"INSERT INTO health_log (host_id, alarm_id, " \
100
- "config_hash_id, name, chart, exec, recipient, units, chart_context, last_transition_id, chart_name) " \
101
- "VALUES (?,?,?,?,?,?,?,?,?,?,?) " \
102
- "ON CONFLICT (host_id, alarm_id) DO UPDATE SET last_transition_id = excluded.last_transition_id, " \
103
- "chart_name = excluded.chart_name RETURNING health_log_id; "
104
-
105
-#define SQL_INSERT_HEALTH_LOG_DETAIL \
106
- "INSERT INTO health_log_detail (health_log_id, unique_id, alarm_id, alarm_event_id, " \
107
- "updated_by_id, updates_id, when_key, duration, non_clear_duration, flags, exec_run_timestamp, delay_up_to_timestamp, " \
101
+ "config_hash_id, name, chart, exec, recipient, units, chart_context, last_transition_id, chart_name) " \
102
+ "VALUES (@host_id,@alarm_id, @config_hash_id,@name,@chart,@exec,@recipient,@units,@chart_context," \
103
+ "@last_transition_id,@chart_name) ON CONFLICT (host_id, alarm_id) DO UPDATE " \
104
+ "SET last_transition_id = excluded.last_transition_id, chart_name = excluded.chart_name RETURNING health_log_id"
105
+
106
+#define SQL_INSERT_HEALTH_LOG_DETAIL \
107
+ "INSERT INTO health_log_detail (health_log_id, unique_id, alarm_id, alarm_event_id, " \
108
+ "updated_by_id, updates_id, when_key, duration, non_clear_duration, flags, exec_run_timestamp, delay_up_to_timestamp, " \
109
"info, exec_code, new_status, old_status, delay, new_value, old_value, last_repeat, transition_id, global_id, summary) " \
109
- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,@global_id,?); "
110
+ "VALUES (@health_log_id,@unique_id,@alarm_id,@alarm_event_id,@updated_by_id,@updates_id,@when_key,@duration," \
111
+ "@non_clear_duration,@flags,@exec_run_timestamp,@delay_up_to_timestamp, @info,@exec_code,@new_status,@old_status," \
112
+ "@delay,@new_value,@old_value,@last_repeat,@transition_id,@global_id,@summary)"
113
+
114
static void sql_health_alarm_log_insert(RRDHOST *host, ALARM_ENTRY *ae) {
115
sqlite3_stmt *res = NULL;
116
int rc;
@@ -423,19 +427,22 @@ done:
427
*
428
*/
429
426
-#define SQL_CLEANUP_HEALTH_LOG_DETAIL_NOT_CLAIMED "DELETE FROM health_log_detail WHERE health_log_id IN " \
427
- "(SELECT health_log_id FROM health_log WHERE host_id = @host_id) AND when_key < unixepoch() - @history " \
428
- "AND updated_by_id <> 0 AND transition_id NOT IN " \
429
- "(SELECT last_transition_id FROM health_log hl WHERE hl.host_id = @host_id);"
430
-
431
-#define SQL_CLEANUP_HEALTH_LOG_DETAIL_CLAIMED(guid) "DELETE from health_log_detail WHERE unique_id NOT IN " \
432
- "(SELECT filtered_alert_unique_id FROM aclk_alert_%s) " \
433
- "AND unique_id IN (SELECT hld.unique_id FROM health_log hl, health_log_detail hld WHERE " \
434
- "hl.host_id = @host_id AND hl.health_log_id = hld.health_log_id) " \
435
- "AND health_log_id IN (SELECT health_log_id FROM health_log WHERE host_id = @host_id) " \
436
- "AND when_key < unixepoch() - @history " \
437
- "AND updated_by_id <> 0 AND transition_id NOT IN " \
438
- "(SELECT last_transition_id FROM health_log hl WHERE hl.host_id = @host_id);", guid
430
+#define SQL_CLEANUP_HEALTH_LOG_DETAIL_NOT_CLAIMED \
431
+ "DELETE FROM health_log_detail WHERE health_log_id IN " \
432
+ "(SELECT health_log_id FROM health_log WHERE host_id = @host_id) AND when_key < UNIXEPOCH() - @history " \
433
+ "AND updated_by_id <> 0 AND transition_id NOT IN " \
434
+ "(SELECT last_transition_id FROM health_log hl WHERE hl.host_id = @host_id)"
435
+
436
+#define SQL_CLEANUP_HEALTH_LOG_DETAIL_CLAIMED(guid) \
437
+ "DELETE from health_log_detail WHERE unique_id NOT IN " \
438
+ "(SELECT filtered_alert_unique_id FROM aclk_alert_%s) " \
439
+ "AND unique_id IN (SELECT hld.unique_id FROM health_log hl, health_log_detail hld WHERE " \
440
+ "hl.host_id = @host_id AND hl.health_log_id = hld.health_log_id) " \
441
+ "AND health_log_id IN (SELECT health_log_id FROM health_log WHERE host_id = @host_id) " \
442
+ "AND when_key < unixepoch() - @history " \
443
+ "AND updated_by_id <> 0 AND transition_id NOT IN " \
444
+ "(SELECT last_transition_id FROM health_log hl WHERE hl.host_id = @host_id)", \
445
+ guid
446
447
void sql_health_alarm_log_cleanup(RRDHOST *host, bool claimed) {
448
sqlite3_stmt *res = NULL;
@@ -450,14 +457,14 @@ void sql_health_alarm_log_cleanup(RRDHOST *host, bool claimed) {
457
458
char uuid_str[UUID_STR_LEN];
459
uuid_unparse_lower_fix(&host->host_uuid, uuid_str);
453
- snprintfz(command, MAX_HEALTH_SQL_SIZE, "aclk_alert_%s", uuid_str);
460
+ snprintfz(command, sizeof(command) - 1, "aclk_alert_%s", uuid_str);
461
462
bool aclk_table_exists = table_exists_in_database(db_meta, command);
463
464
char *sql = SQL_CLEANUP_HEALTH_LOG_DETAIL_NOT_CLAIMED;
465
466
if (claimed && aclk_table_exists) {
460
- snprintfz(command, MAX_HEALTH_SQL_SIZE, SQL_CLEANUP_HEALTH_LOG_DETAIL_CLAIMED(uuid_str));
467
+ snprintfz(command, sizeof(command) - 1, SQL_CLEANUP_HEALTH_LOG_DETAIL_CLAIMED(uuid_str));
468
sql = command;
469
}
470
@@ -497,17 +504,25 @@ done:
504
}
505
506
#define SQL_INJECT_REMOVED \
500
- "insert into health_log_detail (health_log_id, unique_id, alarm_id, alarm_event_id, updated_by_id, updates_id, when_key, " \
507
+ "INSERT INTO health_log_detail (health_log_id, unique_id, alarm_id, alarm_event_id, updated_by_id, updates_id, when_key, " \
508
"duration, non_clear_duration, flags, exec_run_timestamp, delay_up_to_timestamp, info, exec_code, new_status, old_status, " \
509
"delay, new_value, old_value, last_repeat, transition_id, global_id, summary) " \
503
- "select health_log_id, ?1, ?2, ?3, 0, ?4, unixepoch(), 0, 0, flags, exec_run_timestamp, unixepoch(), info, exec_code, -2, " \
504
- "new_status, delay, NULL, new_value, 0, ?5, now_usec(0), summary from health_log_detail where unique_id = ?6 and transition_id = ?7;"
505
-
506
-#define SQL_INJECT_REMOVED_UPDATE_DETAIL "update health_log_detail set flags = flags | ?1, updated_by_id = ?2 where unique_id = ?3 and transition_id = ?4;"
507
-
508
-#define SQL_INJECT_REMOVED_UPDATE_LOG "update health_log set last_transition_id = ?1 where alarm_id = ?2 and last_transition_id = ?3 and host_id = ?4;"
509
-
510
-void sql_inject_removed_status(RRDHOST *host, uint32_t alarm_id, uint32_t alarm_event_id, uint32_t unique_id, uint32_t max_unique_id, uuid_t *prev_transition_id)
510
+ "SELECT health_log_id, ?1, ?2, ?3, 0, ?4, UNIXEPOCH(), 0, 0, flags, exec_run_timestamp, UNIXEPOCH(), info, exec_code, -2, " \
511
+ "new_status, delay, NULL, new_value, 0, ?5, NOW_USEC(0), summary FROM health_log_detail WHERE unique_id = ?6 AND transition_id = ?7"
512
+
513
+#define SQL_INJECT_REMOVED_UPDATE_DETAIL \
514
+ "UPDATE health_log_detail SET flags = flags | ?1, updated_by_id = ?2 WHERE unique_id = ?3 AND transition_id = ?4"
515
+
516
+#define SQL_INJECT_REMOVED_UPDATE_LOG \
517
+ "UPDATE health_log SET last_transition_id = ?1 WHERE alarm_id = ?2 AND last_transition_id = ?3 AND host_id = ?4"
518
+
519
+void sql_inject_removed_status(
520
+ RRDHOST *host,
521
+ uint32_t alarm_id,
522
+ uint32_t alarm_event_id,
523
+ uint32_t unique_id,
524
+ uint32_t max_unique_id,
525
+ uuid_t *prev_transition_id)
526
{
527
int rc;
528
@@ -737,13 +752,14 @@ void sql_check_removed_alerts_state(RRDHOST *host)
752
/* Health related SQL queries
753
Load from the health log table
754
*/
740
-#define SQL_LOAD_HEALTH_LOG "SELECT hld.unique_id, hld.alarm_id, hld.alarm_event_id, hl.config_hash_id, hld.updated_by_id, " \
741
- "hld.updates_id, hld.when_key, hld.duration, hld.non_clear_duration, hld.flags, hld.exec_run_timestamp, " \
742
- "hld.delay_up_to_timestamp, hl.name, hl.chart, hl.exec, hl.recipient, ah.source, hl.units, " \
743
- "hld.info, hld.exec_code, hld.new_status, hld.old_status, hld.delay, hld.new_value, hld.old_value, " \
744
- "hld.last_repeat, ah.class, ah.component, ah.type, hl.chart_context, hld.transition_id, hld.global_id, hl.chart_name, hld.summary " \
745
- "FROM health_log hl, alert_hash ah, health_log_detail hld " \
746
- "WHERE hl.config_hash_id = ah.hash_id and hl.host_id = @host_id and hl.last_transition_id = hld.transition_id;"
755
+#define SQL_LOAD_HEALTH_LOG \
756
+ "SELECT hld.unique_id, hld.alarm_id, hld.alarm_event_id, hl.config_hash_id, hld.updated_by_id, " \
757
+ "hld.updates_id, hld.when_key, hld.duration, hld.non_clear_duration, hld.flags, hld.exec_run_timestamp, " \
758
+ "hld.delay_up_to_timestamp, hl.name, hl.chart, hl.exec, hl.recipient, ah.source, hl.units, " \
759
+ "hld.info, hld.exec_code, hld.new_status, hld.old_status, hld.delay, hld.new_value, hld.old_value, " \
760
+ "hld.last_repeat, ah.class, ah.component, ah.type, hl.chart_context, hld.transition_id, hld.global_id, " \
761
+ "hl.chart_name, hld.summary FROM health_log hl, alert_hash ah, health_log_detail hld " \
762
+ "WHERE hl.config_hash_id = ah.hash_id and hl.host_id = @host_id and hl.last_transition_id = hld.transition_id"
763
764
void sql_health_alarm_log_load(RRDHOST *host)
765
{
@@ -931,12 +947,16 @@ void sql_health_alarm_log_load(RRDHOST *host)
947
/*
948
* Store an alert config hash in the database
949
*/
934
-#define SQL_STORE_ALERT_CONFIG_HASH "insert or replace into alert_hash (hash_id, date_updated, alarm, template, " \
935
- "on_key, class, component, type, os, hosts, lookup, every, units, calc, plugin, module, " \
936
- "charts, green, red, warn, crit, exec, to_key, info, delay, options, repeat, host_labels, " \
937
- "p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after, " \
938
- "p_db_lookup_before, p_update_every, source, chart_labels, summary) values (?1,unixepoch(),?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12," \
939
- "?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30,?31,?32,?33,?34,?35,?36);"
950
+#define SQL_STORE_ALERT_CONFIG_HASH \
951
+ "insert or replace into alert_hash (hash_id, date_updated, alarm, template, " \
952
+ "on_key, class, component, type, os, hosts, lookup, every, units, calc, plugin, module, " \
953
+ "charts, green, red, warn, crit, exec, to_key, info, delay, options, repeat, host_labels, " \
954
+ "p_db_lookup_dimensions, p_db_lookup_method, p_db_lookup_options, p_db_lookup_after, " \
955
+ "p_db_lookup_before, p_update_every, source, chart_labels, summary) values (@hash_id,UNIXEPOCH(),@alarm,@template," \
956
+ "@on_key,@class,@component,@type,@os,@hosts,@lookup,@every,@units,@calc,@plugin,@module," \
957
+ "@charts,@green,@red,@warn,@crit,@exec,@to_key,@info,@delay,@options,@repeat,@host_labels," \
958
+ "@p_db_lookup_dimensions,@p_db_lookup_method,@p_db_lookup_options,@p_db_lookup_after," \
959
+ "@p_db_lookup_before,@p_update_every,@source,@chart_labels,@summary)"
960
961
int sql_store_alert_config_hash(uuid_t *hash_id, struct alert_config *cfg)
962
{
@@ -1214,7 +1234,7 @@ int alert_hash_and_store_config(
1234
#define SQL_SELECT_HEALTH_LAST_EXECUTED_EVENT \
1235
"SELECT hld.new_status FROM health_log hl, health_log_detail hld " \
1236
"WHERE hl.host_id = @host_id AND hl.alarm_id = @alarm_id AND hld.unique_id != @unique_id AND hld.flags & @flags " \
1217
- "AND hl.health_log_id = hld.health_log_id ORDER BY hld.unique_id DESC LIMIT 1;"
1237
+ "AND hl.health_log_id = hld.health_log_id ORDER BY hld.unique_id DESC LIMIT 1"
1238
1239
int sql_health_get_last_executed_event(RRDHOST *host, ALARM_ENTRY *ae, RRDCALC_STATUS *last_executed_status)
1240
{
@@ -1423,11 +1443,11 @@ finish:
1443
error_report("Failed to reset statement for SQL_SELECT_HEALTH_LOG");
1444
}
1445
1426
-#define SQL_COPY_HEALTH_LOG(table) "INSERT OR IGNORE INTO health_log (host_id, alarm_id, config_hash_id, name, chart, family, exec, recipient, units, chart_context) SELECT ?1, alarm_id, config_hash_id, name, chart, family, exec, recipient, units, chart_context from %s;", table
1427
-#define SQL_COPY_HEALTH_LOG_DETAIL(table) "INSERT INTO health_log_detail (unique_id, alarm_id, alarm_event_id, updated_by_id, updates_id, when_key, duration, non_clear_duration, flags, exec_run_timestamp, delay_up_to_timestamp, info, exec_code, new_status, old_status, delay, new_value, old_value, last_repeat, transition_id, global_id, host_id) SELECT unique_id, alarm_id, alarm_event_id, updated_by_id, updates_id, when_key, duration, non_clear_duration, flags, exec_run_timestamp, delay_up_to_timestamp, info, exec_code, new_status, old_status, delay, new_value, old_value, last_repeat, transition_id, now_usec(1), ?1 from %s;", table
1428
-#define SQL_UPDATE_HEALTH_LOG_DETAIL_TRANSITION_ID "update health_log_detail set transition_id = uuid_random() where transition_id is null;"
1429
-#define SQL_UPDATE_HEALTH_LOG_DETAIL_HEALTH_LOG_ID "update health_log_detail set health_log_id = (select health_log_id from health_log where host_id = ?1 and alarm_id = health_log_detail.alarm_id) where health_log_id is null and host_id = ?2;"
1430
-#define SQL_UPDATE_HEALTH_LOG_LAST_TRANSITION_ID "update health_log set last_transition_id = (select transition_id from health_log_detail where health_log_id = health_log.health_log_id and alarm_id = health_log.alarm_id group by (alarm_id) having max(alarm_event_id)) where host_id = ?1;"
1446
+#define SQL_COPY_HEALTH_LOG(table) "INSERT OR IGNORE INTO health_log (host_id, alarm_id, config_hash_id, name, chart, family, exec, recipient, units, chart_context) SELECT ?1, alarm_id, config_hash_id, name, chart, family, exec, recipient, units, chart_context from %s", table
1447
+#define SQL_COPY_HEALTH_LOG_DETAIL(table) "INSERT INTO health_log_detail (unique_id, alarm_id, alarm_event_id, updated_by_id, updates_id, when_key, duration, non_clear_duration, flags, exec_run_timestamp, delay_up_to_timestamp, info, exec_code, new_status, old_status, delay, new_value, old_value, last_repeat, transition_id, global_id, host_id) SELECT unique_id, alarm_id, alarm_event_id, updated_by_id, updates_id, when_key, duration, non_clear_duration, flags, exec_run_timestamp, delay_up_to_timestamp, info, exec_code, new_status, old_status, delay, new_value, old_value, last_repeat, transition_id, now_usec(1), ?1 from %s", table
1448
+#define SQL_UPDATE_HEALTH_LOG_DETAIL_TRANSITION_ID "update health_log_detail set transition_id = uuid_random() where transition_id is null"
1449
+#define SQL_UPDATE_HEALTH_LOG_DETAIL_HEALTH_LOG_ID "update health_log_detail set health_log_id = (select health_log_id from health_log where host_id = ?1 and alarm_id = health_log_detail.alarm_id) where health_log_id is null and host_id = ?2"
1450
+#define SQL_UPDATE_HEALTH_LOG_LAST_TRANSITION_ID "update health_log set last_transition_id = (select transition_id from health_log_detail where health_log_id = health_log.health_log_id and alarm_id = health_log.alarm_id group by (alarm_id) having max(alarm_event_id)) where host_id = ?1"
1451
int health_migrate_old_health_log_table(char *table) {
1452
if (!table)
1453
return 0;
@@ -1449,7 +1469,7 @@ int health_migrate_old_health_log_table(char *table) {
1469
int rc;
1470
char command[MAX_HEALTH_SQL_SIZE + 1];
1471
sqlite3_stmt *res = NULL;
1452
- snprintfz(command, MAX_HEALTH_SQL_SIZE, SQL_COPY_HEALTH_LOG(table));
1472
+ snprintfz(command, sizeof(command) - 1, SQL_COPY_HEALTH_LOG(table));
1473
rc = sqlite3_prepare_v2(db_meta, command, -1, &res, 0);
1474
if (unlikely(rc != SQLITE_OK)) {
1475
error_report("Failed to prepare statement to copy health log, rc = %d", rc);
@@ -1476,7 +1496,7 @@ int health_migrate_old_health_log_table(char *table) {
1496
}
1497
1498
//detail
1479
- snprintfz(command, MAX_HEALTH_SQL_SIZE, SQL_COPY_HEALTH_LOG_DETAIL(table));
1499
+ snprintfz(command, sizeof(command) - 1, SQL_COPY_HEALTH_LOG_DETAIL(table));
1500
rc = sqlite3_prepare_v2(db_meta, command, -1, &res, 0);
1501
if (unlikely(rc != SQLITE_OK)) {
1502
error_report("Failed to prepare statement to copy health log detail, rc = %d", rc);
@@ -1886,12 +1906,12 @@ void sql_alert_transitions(
1906
goto run_query;
1907
}
1908
1889
- snprintfz(sql, 511, SQL_BUILD_ALERT_TRANSITION, nodes);
1909
+ snprintfz(sql, sizeof(sql) - 1, SQL_BUILD_ALERT_TRANSITION, nodes);
1910
rc = db_execute(db_meta, sql);
1911
if (rc)
1912
return;
1913
1894
- snprintfz(sql, 511, SQL_POPULATE_TEMP_ALERT_TRANSITION_TABLE, nodes);
1914
+ snprintfz(sql, sizeof(sql) - 1, SQL_POPULATE_TEMP_ALERT_TRANSITION_TABLE, nodes);
1915
1916
// Prepare statement to add things
1917
rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
@@ -2019,7 +2039,7 @@ done:
2039
2040
done_only_drop:
2041
if (likely(!transition)) {
2022
- (void)snprintfz(sql, 511, "DROP TABLE IF EXISTS v_%p", nodes);
2042
+ (void)snprintfz(sql, sizeof(sql) - 1, "DROP TABLE IF EXISTS v_%p", nodes);
2043
(void)db_execute(db_meta, sql);
2044
buffer_free(command);
2045
}
@@ -2051,12 +2071,12 @@ int sql_get_alert_configuration(
2071
if (unlikely(!configs))
2072
return added;
2073
2054
- snprintfz(sql, 511, SQL_BUILD_CONFIG_TARGET_LIST, configs);
2074
+ snprintfz(sql, sizeof(sql) - 1, SQL_BUILD_CONFIG_TARGET_LIST, configs);
2075
rc = db_execute(db_meta, sql);
2076
if (rc)
2077
return added;
2078
2059
- snprintfz(sql, 511, SQL_POPULATE_TEMP_CONFIG_TARGET_TABLE, configs);
2079
+ snprintfz(sql, sizeof(sql) - 1, SQL_POPULATE_TEMP_CONFIG_TARGET_TABLE, configs);
2080
2081
// Prepare statement to add things
2082
rc = sqlite3_prepare_v2(db_meta, sql, -1, &res, 0);
@@ -2153,7 +2173,7 @@ int sql_get_alert_configuration(
2173
error_report("Failed to finalize statement for sql_get_alert_configuration");
2174
2175
fail_only_drop:
2156
- (void)snprintfz(sql, 511, "DROP TABLE IF EXISTS c_%p", configs);
2176
+ (void)snprintfz(sql, sizeof(sql) - 1, "DROP TABLE IF EXISTS c_%p", configs);
2177
(void)db_execute(db_meta, sql);
2178
buffer_free(command);
2179
return added;
database/sqlite/sqlite_metadata.c
+19
-20
@@ -4,11 +4,12 @@
4
5
// SQL statements
6
7
-#define SQL_STORE_CLAIM_ID "INSERT INTO node_instance " \
8
- "(host_id, claim_id, date_created) VALUES (@host_id, @claim_id, unixepoch()) " \
9
- "ON CONFLICT(host_id) DO UPDATE SET claim_id = excluded.claim_id;"
7
+#define SQL_STORE_CLAIM_ID \
8
+ "INSERT INTO node_instance " \
9
+ "(host_id, claim_id, date_created) VALUES (@host_id, @claim_id, UNIXEPOCH()) " \
10
+ "ON CONFLICT(host_id) DO UPDATE SET claim_id = excluded.claim_id"
11
11
-#define SQL_DELETE_HOST_LABELS "DELETE FROM host_label WHERE host_id = @uuid;"
12
+#define SQL_DELETE_HOST_LABELS "DELETE FROM host_label WHERE host_id = @uuid"
13
14
#define STORE_HOST_LABEL \
15
"INSERT INTO host_label (host_id, source_type, label_key, label_value, date_created) VALUES "
@@ -18,13 +19,13 @@
19
20
#define STORE_HOST_OR_CHART_LABEL_VALUE "(u2h('%s'), %d,'%s','%s', unixepoch())"
21
21
-#define DELETE_DIMENSION_UUID "DELETE FROM dimension WHERE dim_id = @uuid;"
22
+#define DELETE_DIMENSION_UUID "DELETE FROM dimension WHERE dim_id = @uuid"
23
24
#define SQL_STORE_HOST_INFO \
25
"INSERT OR REPLACE INTO host (host_id, hostname, registry_hostname, update_every, os, timezone, tags, hops, " \
26
"memory_mode, abbrev_timezone, utc_offset, program_name, program_version, entries, health_enabled, last_connected) " \
27
"VALUES (@host_id, @hostname, @registry_hostname, @update_every, @os, @timezone, @tags, @hops, " \
27
- "@memory_mode, @abbrev_tz, @utc_offset, @prog_name, @prog_version, @entries, @health_enabled, @last_connected);"
28
+ "@memory_mode, @abbrev_tz, @utc_offset, @prog_name, @prog_version, @entries, @health_enabled, @last_connected)"
29
30
#define SQL_STORE_CHART \
31
"INSERT INTO chart (chart_id, host_id, type, id, name, family, context, title, unit, plugin, module, priority, " \
@@ -51,9 +52,9 @@
52
"(@uuid, @name, @value, UNIXEPOCH())"
53
54
#define MIGRATE_LOCALHOST_TO_NEW_MACHINE_GUID \
54
- "UPDATE chart SET host_id = @host_id WHERE host_id in (SELECT host_id FROM host where host_id <> @host_id and hops = 0);"
55
-#define DELETE_NON_EXISTING_LOCALHOST "DELETE FROM host WHERE hops = 0 AND host_id <> @host_id;"
56
-#define DELETE_MISSING_NODE_INSTANCES "DELETE FROM node_instance WHERE host_id NOT IN (SELECT host_id FROM host);"
55
+ "UPDATE chart SET host_id = @host_id WHERE host_id in (SELECT host_id FROM host where host_id <> @host_id and hops = 0)"
56
+#define DELETE_NON_EXISTING_LOCALHOST "DELETE FROM host WHERE hops = 0 AND host_id <> @host_id"
57
+#define DELETE_MISSING_NODE_INSTANCES "DELETE FROM node_instance WHERE host_id NOT IN (SELECT host_id FROM host)"
58
59
#define METADATA_MAINTENANCE_FIRST_CHECK (1800) // Maintenance first run after agent startup in seconds
60
#define METADATA_MAINTENANCE_REPEAT (60) // Repeat if last run for dimensions, charts, labels needs more work
@@ -190,8 +191,8 @@ static int chart_label_store_to_sql_callback(const char *name, const char *value
191
return 1;
192
}
193
193
-#define SQL_DELETE_CHART_LABEL "DELETE FROM chart_label WHERE chart_id = @chart_id;"
194
-#define SQL_DELETE_CHART_LABEL_HISTORY "DELETE FROM chart_label WHERE date_created < %ld AND chart_id = @chart_id;"
194
+#define SQL_DELETE_CHART_LABEL "DELETE FROM chart_label WHERE chart_id = @chart_id"
195
+#define SQL_DELETE_CHART_LABEL_HISTORY "DELETE FROM chart_label WHERE date_created < %ld AND chart_id = @chart_id"
196
197
static void clean_old_chart_labels(RRDSET *st)
198
{
@@ -199,9 +200,9 @@ static void clean_old_chart_labels(RRDSET *st)
200
time_t first_time_s = rrdset_first_entry_s(st);
201
202
if (unlikely(!first_time_s))
202
- snprintfz(sql, 511,SQL_DELETE_CHART_LABEL);
203
+ snprintfz(sql, sizeof(sql) - 1, SQL_DELETE_CHART_LABEL);
204
else
204
- snprintfz(sql, 511,SQL_DELETE_CHART_LABEL_HISTORY, first_time_s);
205
+ snprintfz(sql, sizeof(sql) - 1, SQL_DELETE_CHART_LABEL_HISTORY, first_time_s);
206
207
int rc = exec_statement_with_uuid(sql, &st->chart_uuid);
208
if (unlikely(rc))
@@ -1152,9 +1153,7 @@ static void timer_cb(uv_timer_t* handle)
1153
struct metadata_cmd cmd;
1154
memset(&cmd, 0, sizeof(cmd));
1155
1155
- time_t now = now_realtime_sec();
1156
-
1157
- if (wc->metadata_check_after && wc->metadata_check_after < now) {
1156
+ if (wc->metadata_check_after < now_realtime_sec()) {
1157
cmd.opcode = METADATA_SCAN_HOSTS;
1158
metadata_enq_cmd(wc, &cmd);
1159
}
@@ -1177,7 +1176,7 @@ void vacuum_database(sqlite3 *database, const char *db_alias, int threshold, int
1176
nd_log(NDLS_DAEMON, NDLP_DEBUG, "%s: Freeing %d database pages", db_alias, do_free_pages);
1177
1178
char sql[128];
1180
- snprintfz(sql, 127, "PRAGMA incremental_vacuum(%d)", do_free_pages);
1179
+ snprintfz(sql, sizeof(sql) - 1, "PRAGMA incremental_vacuum(%d)", do_free_pages);
1180
(void) db_execute(database, sql);
1181
}
1182
}
@@ -1490,7 +1489,7 @@ static void start_metadata_hosts(uv_work_t *req __maybe_unused)
1489
worker_is_busy(UV_EVENT_METADATA_STORE);
1490
1491
if (!data->max_count)
1493
- transaction_started = !db_execute(db_meta, "BEGIN TRANSACTION;");
1492
+ transaction_started = !db_execute(db_meta, "BEGIN TRANSACTION");
1493
1494
dfe_start_reentrant(rrdhost_root_index, host) {
1495
if (rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED) || !rrdhost_flag_check(host, RRDHOST_FLAG_METADATA_UPDATE))
@@ -1560,7 +1559,7 @@ static void start_metadata_hosts(uv_work_t *req __maybe_unused)
1559
dfe_done(host);
1560
1561
if (!data->max_count && transaction_started)
1563
- transaction_started = db_execute(db_meta, "COMMIT TRANSACTION;");
1562
+ transaction_started = db_execute(db_meta, "COMMIT TRANSACTION");
1563
1564
usec_t all_ended_ut = now_monotonic_usec(); (void)all_ended_ut;
1565
internal_error(true, "METADATA: checking all hosts completed in %0.2f ms",
@@ -1958,7 +1957,7 @@ static void *metadata_unittest_threads(void)
1957
tu.join = 0;
1958
for (int i = 0; i < threads_to_create; i++) {
1959
char buf[100 + 1];
1961
- snprintf(buf, 100, "META[%d]", i);
1960
+ snprintf(buf, sizeof(buf) - 1, "META[%d]", i);
1961
netdata_thread_create(
1962
&threads[i],
1963
buf,
health/health.c
+11
-12
@@ -912,10 +912,9 @@ static void health_sleep(time_t next_run, unsigned int loop __maybe_unused) {
912
}
913
}
914
915
-static SILENCE_TYPE check_silenced(RRDCALC *rc, const char *host, SILENCERS *silencers) {
915
+static SILENCE_TYPE check_silenced(RRDCALC *rc, const char *host)
916
+{
917
SILENCER *s;
917
- netdata_log_debug(D_HEALTH, "Checking if alarm was silenced via the command API. Alarm info name:%s context:%s chart:%s host:%s",
918
- rrdcalc_name(rc), (rc->rrdset)?rrdset_context(rc->rrdset):"", rrdcalc_chart_name(rc), host);
918
919
for (s = silencers->silencers; s!=NULL; s=s->next){
920
if (
@@ -960,20 +959,20 @@ static int update_disabled_silenced(RRDHOST *host, RRDCALC *rc) {
959
if (silencers->stype == STYPE_DISABLE_ALARMS) rc->run_flags |= RRDCALC_FLAG_DISABLED;
960
else if (silencers->stype == STYPE_SILENCE_NOTIFICATIONS) rc->run_flags |= RRDCALC_FLAG_SILENCED;
961
} else {
963
- SILENCE_TYPE st = check_silenced(rc, rrdhost_hostname(host), silencers);
962
+ SILENCE_TYPE st = check_silenced(rc, rrdhost_hostname(host));
963
if (st == STYPE_DISABLE_ALARMS) rc->run_flags |= RRDCALC_FLAG_DISABLED;
964
else if (st == STYPE_SILENCE_NOTIFICATIONS) rc->run_flags |= RRDCALC_FLAG_SILENCED;
965
}
966
967
if (rrdcalc_flags_old != rc->run_flags) {
969
- netdata_log_info("Alarm silencing changed for host '%s' alarm '%s': Disabled %s->%s Silenced %s->%s",
970
- rrdhost_hostname(host),
971
- rrdcalc_name(rc),
972
- (rrdcalc_flags_old & RRDCALC_FLAG_DISABLED)?"true":"false",
973
- (rc->run_flags & RRDCALC_FLAG_DISABLED)?"true":"false",
974
- (rrdcalc_flags_old & RRDCALC_FLAG_SILENCED)?"true":"false",
975
- (rc->run_flags & RRDCALC_FLAG_SILENCED)?"true":"false"
976
- );
968
+ netdata_log_info(
969
+ "Alarm silencing changed for host '%s' alarm '%s': Disabled %s->%s Silenced %s->%s",
970
+ rrdhost_hostname(host),
971
+ rrdcalc_name(rc),
972
+ (rrdcalc_flags_old & RRDCALC_FLAG_DISABLED) ? "true" : "false",
973
+ (rc->run_flags & RRDCALC_FLAG_DISABLED) ? "true" : "false",
974
+ (rrdcalc_flags_old & RRDCALC_FLAG_SILENCED) ? "true" : "false",
975
+ (rc->run_flags & RRDCALC_FLAG_SILENCED) ? "true" : "false");
976
}
977
if (rc->run_flags & RRDCALC_FLAG_DISABLED)
978
return 1;
libnetdata/dictionary/dictionary.c
+4
-4
@@ -2627,7 +2627,7 @@ static char **dictionary_unittest_generate_names(size_t entries) {
2627
char **names = mallocz(sizeof(char *) * entries);
2628
for(size_t i = 0; i < entries ;i++) {
2629
char buf[25 + 1] = "";
2630
- snprintfz(buf, 25, "name.%zu.0123456789.%zu!@#$%%^&*(),./[]{}\\|~`", i, entries / 2 + i);
2630
+ snprintfz(buf, sizeof(buf) - 1, "name.%zu.0123456789.%zu!@#$%%^&*(),./[]{}\\|~`", i, entries / 2 + i);
2631
names[i] = strdupz(buf);
2632
}
2633
return names;
@@ -2637,7 +2637,7 @@ static char **dictionary_unittest_generate_values(size_t entries) {
2637
char **values = mallocz(sizeof(char *) * entries);
2638
for(size_t i = 0; i < entries ;i++) {
2639
char buf[25 + 1] = "";
2640
- snprintfz(buf, 25, "value-%zu-0987654321.%zu%%^&*(),. \t !@#$/[]{}\\|~`", i, entries / 2 + i);
2640
+ snprintfz(buf, sizeof(buf) - 1, "value-%zu-0987654321.%zu%%^&*(),. \t !@#$/[]{}\\|~`", i, entries / 2 + i);
2641
values[i] = strdupz(buf);
2642
}
2643
return values;
@@ -3253,13 +3253,13 @@ static void *unittest_dict_thread(void *arg) {
3253
char buf [256 + 1];
3254
3255
for (int i = 0; i < 1000; i++) {
3256
- snprintfz(buf, 256, "del/flush test %d", i);
3256
+ snprintfz(buf, sizeof(buf) - 1, "del/flush test %d", i);
3257
dictionary_set(tu->dict, buf, NULL, 0);
3258
tu->stats.ops.inserts++;
3259
}
3260
3261
for (int i = 0; i < 1000; i++) {
3262
- snprintfz(buf, 256, "del/flush test %d", i);
3262
+ snprintfz(buf, sizeof(buf) - 1, "del/flush test %d", i);
3263
dictionary_del(tu->dict, buf);
3264
tu->stats.ops.deletes++;
3265
}
libnetdata/eval/eval.c
+1
-1
@@ -384,7 +384,7 @@ static inline void print_parsed_as_constant(BUFFER *out, NETDATA_DOUBLE n) {
384
}
385
386
char b[100+1], *s;
387
- snprintfz(b, 100, NETDATA_DOUBLE_FORMAT, n);
387
+ snprintfz(b, sizeof(b) - 1, NETDATA_DOUBLE_FORMAT, n);
388
389
s = &b[strlen(b) - 1];
390
while(s > b && *s == '0') {
libnetdata/facets/facets.c
+1
-1
@@ -1463,7 +1463,7 @@ static void facets_histogram_generate(FACETS *facets, FACET_KEY *k, BUFFER *wb)
1463
char title[1024 + 1] = "Events Distribution";
1464
FACET_KEY *kt = FACETS_KEY_GET_FROM_INDEX(facets, facets->histogram.hash);
1465
if(kt && kt->name)
1466
- snprintfz(title, 1024, "Events Distribution by %s", kt->name);
1466
+ snprintfz(title, sizeof(title) - 1, "Events Distribution by %s", kt->name);
1467
1468
buffer_json_member_add_string(wb, "title", title);
1469
buffer_json_member_add_time_t(wb, "update_every", facets->histogram.slot_width_ut / USEC_PER_SEC);
libnetdata/health/health.c
+11
-11
@@ -29,9 +29,13 @@ void health_silencers_add(SILENCER *silencer) {
29
// Add the created instance to the linked list in silencers
30
silencer->next = silencers->silencers;
31
silencers->silencers = silencer;
32
- netdata_log_debug(D_HEALTH, "HEALTH command API: Added silencer %s:%s:%s:%s", silencer->alarms,
33
- silencer->charts, silencer->contexts, silencer->hosts
34
- );
32
+ netdata_log_debug(
33
+ D_HEALTH,
34
+ "HEALTH command API: Added silencer %s:%s:%s:%s",
35
+ silencer->alarms,
36
+ silencer->charts,
37
+ silencer->contexts,
38
+ silencer->hosts);
39
}
40
41
/**
@@ -71,10 +75,6 @@ SILENCER *health_silencers_addparam(SILENCER *silencer, char *key, char *value)
75
(hash == hash_host && !strcasecmp(key, HEALTH_HOST_KEY))
76
) {
77
silencer = create_silencer();
74
- if(!silencer) {
75
- netdata_log_error("Cannot add a new silencer to Netdata");
76
- return NULL;
77
- }
78
}
79
}
80
@@ -160,10 +160,10 @@ int health_silencers_json_read_callback(JSON_ENTRY *e)
160
* @return It returns 0 on success and -1 otherwise
161
*/
162
int health_initialize_global_silencers() {
163
- silencers = mallocz(sizeof(SILENCERS));
164
- silencers->all_alarms=0;
165
- silencers->stype=STYPE_NONE;
166
- silencers->silencers=NULL;
163
+ silencers = mallocz(sizeof(SILENCERS));
164
+ silencers->all_alarms = 0;
165
+ silencers->stype = STYPE_NONE;
166
+ silencers->silencers = NULL;
167
168
return 0;
169
}
libnetdata/libnetdata.c
+1
-1
@@ -42,7 +42,7 @@ void aral_judy_init(void) {
42
for(size_t Words = 0; Words <= MAX_JUDY_SIZE_TO_ARAL; Words++)
43
if(judy_sizes_config[Words]) {
44
char buf[30+1];
45
- snprintfz(buf, 30, "judy-%zu", Words * sizeof(Word_t));
45
+ snprintfz(buf, sizeof(buf) - 1, "judy-%zu", Words * sizeof(Word_t));
46
judy_sizes_aral[Words] = aral_create(
47
buf,
48
Words * sizeof(Word_t),
libnetdata/socket/socket.c
+3
-3
@@ -240,16 +240,16 @@ char *strdup_client_description(int family, const char *protocol, const char *ip
240
241
switch(family) {
242
case AF_INET:
243
- snprintfz(buffer, 100, "%s:%s:%d", protocol, ip, port);
243
+ snprintfz(buffer, sizeof(buffer) - 1, "%s:%s:%d", protocol, ip, port);
244
break;
245
246
case AF_INET6:
247
default:
248
- snprintfz(buffer, 100, "%s:[%s]:%d", protocol, ip, port);
248
+ snprintfz(buffer, sizeof(buffer) - 1, "%s:[%s]:%d", protocol, ip, port);
249
break;
250
251
case AF_UNIX:
252
- snprintfz(buffer, 100, "%s:%s", protocol, ip);
252
+ snprintfz(buffer, sizeof(buffer) - 1, "%s:%s", protocol, ip);
253
break;
254
}
255
libnetdata/string/string.c
+1
-1
@@ -416,7 +416,7 @@ static char **string_unittest_generate_names(size_t entries) {
416
char **names = mallocz(sizeof(char *) * entries);
417
for(size_t i = 0; i < entries ;i++) {
418
char buf[25 + 1] = "";
419
- snprintfz(buf, 25, "name.%zu.0123456789.%zu \t !@#$%%^&*(),./[]{}\\|~`", i, entries / 2 + i);
419
+ snprintfz(buf, sizeof(buf) - 1, "name.%zu.0123456789.%zu \t !@#$%%^&*(),./[]{}\\|~`", i, entries / 2 + i);
420
names[i] = strdupz(buf);
421
}
422
return names;
streaming/receiver.c
+1
-1
@@ -835,7 +835,7 @@ static void rrdpush_receive(struct receiver_state *rpt)
835
836
{
837
char msg[100 + 1];
838
- snprintfz(msg, 100, "disconnected (completed %zu updates)", count);
838
+ snprintfz(msg, sizeof(msg) - 1, "disconnected (completed %zu updates)", count);
839
rrdpush_receive_log_status(
840
rpt, msg,
841
RRDPUSH_STATUS_DISCONNECTED, NDLP_WARNING);
streaming/replication.c
+1
-1
@@ -822,7 +822,7 @@ static bool send_replay_chart_cmd(struct replication_request_details *r, const c
822
#endif // NETDATA_LOG_REPLICATION_REQUESTS
823
824
char buffer[2048 + 1];
825
- snprintfz(buffer, 2048, PLUGINSD_KEYWORD_REPLAY_CHART " \"%s\" \"%s\" %llu %llu\n",
825
+ snprintfz(buffer, sizeof(buffer) - 1, PLUGINSD_KEYWORD_REPLAY_CHART " \"%s\" \"%s\" %llu %llu\n",
826
rrdset_id(st), r->wanted.start_streaming ? "true" : "false",
827
(unsigned long long)r->wanted.after, (unsigned long long)r->wanted.before);
828
streaming/rrdpush.c
+2
-2
@@ -1239,7 +1239,7 @@ int rrdpush_receiver_thread_spawn(struct web_client *w, char *decoded_query_stri
1239
spinlock_unlock(&spinlock);
1240
1241
char msg[100 + 1];
1242
- snprintfz(msg, 100,
1242
+ snprintfz(msg, sizeof(msg) - 1,
1243
"rate limit, will accept new connection in %ld secs",
1244
(long)(web_client_streaming_rate_t - (now - last_stream_accepted_t)));
1245
@@ -1305,7 +1305,7 @@ int rrdpush_receiver_thread_spawn(struct web_client *w, char *decoded_query_stri
1305
// try again later
1306
1307
char msg[200 + 1];
1308
- snprintfz(msg, 200,
1308
+ snprintfz(msg, sizeof(msg) - 1,
1309
"multiple connections for same host, "
1310
"old connection was last used %ld secs ago%s",
1311
age, receiver_stale ? " (signaled old receiver to stop)" : " (new connection not accepted)");
streaming/sender.c
+1
-1
@@ -31,7 +31,7 @@
31
#define WORKER_SENDER_JOB_DISCONNECT_CANT_UPGRADE_CONNECTION 24
32
33
#if WORKER_UTILIZATION_MAX_JOB_TYPES < 25
34
-#error WORKER_UTILIZATION_MAX_JOB_TYPES has to be at least 21
34
+#error WORKER_UTILIZATION_MAX_JOB_TYPES has to be at least 25
35
#endif
36
37
extern struct config stream_config;
web/api/queries/weights.c
+3
-3
@@ -112,7 +112,7 @@ static void register_result(DICTIONARY *results, RRDHOST *host, RRDCONTEXT_ACQUI
112
113
// we can use the pointer address or RMA as a unique key for each metric
114
char buf[20 + 1];
115
- ssize_t len = snprintfz(buf, 20, "%p", rma);
115
+ ssize_t len = snprintfz(buf, sizeof(buf) - 1, "%p", rma);
116
dictionary_set_advanced(results, buf, len + 1, &t, sizeof(struct register_result), NULL);
117
}
118
@@ -717,7 +717,7 @@ static inline struct dict_unique_name_units *dict_unique_name_units_add(DICTIONA
717
718
static inline struct dict_unique_id_name *dict_unique_id_name_add(DICTIONARY *dict, const char *id, const char *name, ssize_t *max_id) {
719
char key[1024 + 1];
720
- snprintfz(key, 1024, "%s:%s", id, name);
720
+ snprintfz(key, sizeof(key) - 1, "%s:%s", id, name);
721
struct dict_unique_id_name *dun = dictionary_set(dict, key, NULL, sizeof(struct dict_unique_id_name));
722
if(!dun->existing) {
723
dun->existing = true;
@@ -2047,7 +2047,7 @@ print("\nprob", prob)
2047
2048
static int double_expect(double v, const char *str, const char *descr) {
2049
char buf[100 + 1];
2050
- snprintfz(buf, 100, "%0.6f", v);
2050
+ snprintfz(buf, sizeof(buf) - 1, "%0.6f", v);
2051
int ret = strcmp(buf, str) ? 1 : 0;
2052
2053
fprintf(stderr, "%s %s, expected %s, got %s\n", ret?"FAILED":"OK", descr, str, buf);
web/server/static/static-threaded.c
+1
-1
@@ -544,7 +544,7 @@ void *socket_listen_main_static_threaded(void *ptr) {
544
static_workers_private_data[i].max_sockets = max_sockets / static_threaded_workers_count;
545
546
char tag[50 + 1];
547
- snprintfz(tag, 50, "WEB[%d]", i+1);
547
+ snprintfz(tag, sizeof(tag) - 1, "WEB[%d]", i+1);
548
549
netdata_log_info("starting worker %d", i+1);
550
netdata_thread_create(&static_workers_private_data[i].thread, tag, NETDATA_THREAD_OPTION_DEFAULT,