1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
|
/*
** Zabbix
** Copyright (C) 2001-2021 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#include "common.h"
#ifdef HAVE_SQLITE3
# error SQLite is not supported as a main Zabbix database backend.
#endif
#include "cfg.h"
#include "pid.h"
#include "db.h"
#include "dbcache.h"
#include "zbxdbupgrade.h"
#include "log.h"
#include "zbxgetopt.h"
#include "mutexs.h"
#include "sysinfo.h"
#include "zbxmodules.h"
#include "zbxserver.h"
#include "zbxnix.h"
#include "daemon.h"
#include "zbxself.h"
#include "../libs/zbxnix/control.h"
#include "alerter/alerter.h"
#include "alerter/alert_manager.h"
#include "alerter/alert_syncer.h"
#include "dbsyncer/dbsyncer.h"
#include "dbconfig/dbconfig.h"
#include "discoverer/discoverer.h"
#include "httppoller/httppoller.h"
#include "housekeeper/housekeeper.h"
#include "pinger/pinger.h"
#include "poller/poller.h"
#include "timer/timer.h"
#include "trapper/trapper.h"
#include "snmptrapper/snmptrapper.h"
#include "escalator/escalator.h"
#include "proxypoller/proxypoller.h"
#include "selfmon/selfmon.h"
#include "vmware/vmware.h"
#include "taskmanager/taskmanager.h"
#include "preprocessor/preproc_manager.h"
#include "preprocessor/preproc_worker.h"
#include "availability/avail_manager.h"
#include "lld/lld_manager.h"
#include "lld/lld_worker.h"
#include "reporter/report_manager.h"
#include "reporter/report_writer.h"
#include "events.h"
#include "../libs/zbxdbcache/valuecache.h"
#include "setproctitle.h"
#include "zbxcrypto.h"
#include "zbxipcservice.h"
#include "zbxhistory.h"
#include "postinit.h"
#include "export.h"
#include "zbxvault.h"
#include "zbxdiag.h"
#include "zbxtrends.h"
#ifdef HAVE_OPENIPMI
#include "ipmi/ipmi_manager.h"
#include "ipmi/ipmi_poller.h"
#endif
const char *progname = NULL;
const char title_message[] = "zabbix_server";
const char syslog_app_name[] = "zabbix_server";
const char *usage_message[] = {
"[-c config-file]", NULL,
"[-c config-file]", "-R runtime-option", NULL,
"-h", NULL,
"-V", NULL,
NULL /* end of text */
};
const char *help_message[] = {
"The core daemon of Zabbix software.",
"",
"Options:",
" -c --config config-file Path to the configuration file",
" (default: \"" DEFAULT_CONFIG_FILE "\")",
" -f --foreground Run Zabbix server in foreground",
" -R --runtime-control runtime-option Perform administrative functions",
"",
" Runtime control options:",
" " ZBX_CONFIG_CACHE_RELOAD " Reload configuration cache",
" " ZBX_HOUSEKEEPER_EXECUTE " Execute the housekeeper",
" " ZBX_LOG_LEVEL_INCREASE "=target Increase log level, affects all processes if",
" target is not specified",
" " ZBX_LOG_LEVEL_DECREASE "=target Decrease log level, affects all processes if",
" target is not specified",
" " ZBX_SNMP_CACHE_RELOAD " Reload SNMP cache",
" " ZBX_SECRETS_RELOAD " Reload secrets from Vault",
" " ZBX_DIAGINFO "=section Log internal diagnostic information of the",
" section (historycache, preprocessing, alerting,",
" lld, valuecache, locks) or everything if section is",
" not specified",
"",
" Log level control targets:",
" process-type All processes of specified type",
" (alerter, alert manager, configuration syncer,",
" discoverer, escalator, history syncer,",
" housekeeper, http poller, icmp pinger,",
" ipmi manager, ipmi poller, java poller,",
" poller, preprocessing manager,",
" preprocessing worker, proxy poller,",
" self-monitoring, snmp trapper, task manager,",
" timer, trapper, unreachable poller,",
" vmware collector, history poller, availability manager)",
" process-type,N Process type and number (e.g., poller,3)",
" pid Process identifier, up to 65535. For larger",
" values specify target as \"process-type,N\"",
"",
" -h --help Display this help message",
" -V --version Display version number",
"",
"Some configuration parameter default locations:",
" AlertScriptsPath \"" DEFAULT_ALERT_SCRIPTS_PATH "\"",
" ExternalScripts \"" DEFAULT_EXTERNAL_SCRIPTS_PATH "\"",
#ifdef HAVE_LIBCURL
" SSLCertLocation \"" DEFAULT_SSL_CERT_LOCATION "\"",
" SSLKeyLocation \"" DEFAULT_SSL_KEY_LOCATION "\"",
#endif
" LoadModulePath \"" DEFAULT_LOAD_MODULE_PATH "\"",
NULL /* end of text */
};
/* COMMAND LINE OPTIONS */
/* long options */
static struct zbx_option longopts[] =
{
{"config", 1, NULL, 'c'},
{"foreground", 0, NULL, 'f'},
{"runtime-control", 1, NULL, 'R'},
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
{NULL}
};
/* short options */
static char shortopts[] = "c:hVR:f";
/* end of COMMAND LINE OPTIONS */
int threads_num = 0;
pid_t *threads = NULL;
static int *threads_flags;
unsigned char program_type = ZBX_PROGRAM_TYPE_SERVER;
unsigned char process_type = ZBX_PROCESS_TYPE_UNKNOWN;
int process_num = 0;
int server_num = 0;
int CONFIG_ALERTER_FORKS = 3;
int CONFIG_DISCOVERER_FORKS = 1;
int CONFIG_HOUSEKEEPER_FORKS = 1;
int CONFIG_PINGER_FORKS = 1;
int CONFIG_POLLER_FORKS = 5;
int CONFIG_UNREACHABLE_POLLER_FORKS = 1;
int CONFIG_HTTPPOLLER_FORKS = 1;
int CONFIG_IPMIPOLLER_FORKS = 0;
int CONFIG_TIMER_FORKS = 1;
int CONFIG_TRAPPER_FORKS = 5;
int CONFIG_SNMPTRAPPER_FORKS = 0;
int CONFIG_JAVAPOLLER_FORKS = 0;
int CONFIG_ESCALATOR_FORKS = 1;
int CONFIG_SELFMON_FORKS = 1;
int CONFIG_DATASENDER_FORKS = 0;
int CONFIG_HEARTBEAT_FORKS = 0;
int CONFIG_COLLECTOR_FORKS = 0;
int CONFIG_PASSIVE_FORKS = 0;
int CONFIG_ACTIVE_FORKS = 0;
int CONFIG_TASKMANAGER_FORKS = 1;
int CONFIG_IPMIMANAGER_FORKS = 0;
int CONFIG_ALERTMANAGER_FORKS = 1;
int CONFIG_PREPROCMAN_FORKS = 1;
int CONFIG_PREPROCESSOR_FORKS = 3;
int CONFIG_LLDMANAGER_FORKS = 1;
int CONFIG_LLDWORKER_FORKS = 2;
int CONFIG_ALERTDB_FORKS = 1;
int CONFIG_HISTORYPOLLER_FORKS = 5;
int CONFIG_AVAILMAN_FORKS = 1;
int CONFIG_REPORTMANAGER_FORKS = 0;
int CONFIG_REPORTWRITER_FORKS = 0;
int CONFIG_LISTEN_PORT = ZBX_DEFAULT_SERVER_PORT;
char *CONFIG_LISTEN_IP = NULL;
char *CONFIG_SOURCE_IP = NULL;
int CONFIG_TRAPPER_TIMEOUT = 300;
char *CONFIG_SERVER = NULL; /* not used in zabbix_server, required for linking */
int CONFIG_HOUSEKEEPING_FREQUENCY = 1;
int CONFIG_MAX_HOUSEKEEPER_DELETE = 5000; /* applies for every separate field value */
int CONFIG_HISTSYNCER_FORKS = 4;
int CONFIG_HISTSYNCER_FREQUENCY = 1;
int CONFIG_CONFSYNCER_FORKS = 1;
int CONFIG_CONFSYNCER_FREQUENCY = 60;
int CONFIG_VMWARE_FORKS = 0;
int CONFIG_VMWARE_FREQUENCY = 60;
int CONFIG_VMWARE_PERF_FREQUENCY = 60;
int CONFIG_VMWARE_TIMEOUT = 10;
zbx_uint64_t CONFIG_CONF_CACHE_SIZE = 8 * ZBX_MEBIBYTE;
zbx_uint64_t CONFIG_HISTORY_CACHE_SIZE = 16 * ZBX_MEBIBYTE;
zbx_uint64_t CONFIG_HISTORY_INDEX_CACHE_SIZE = 4 * ZBX_MEBIBYTE;
zbx_uint64_t CONFIG_TRENDS_CACHE_SIZE = 4 * ZBX_MEBIBYTE;
zbx_uint64_t CONFIG_TREND_FUNC_CACHE_SIZE = 4 * ZBX_MEBIBYTE;
zbx_uint64_t CONFIG_VALUE_CACHE_SIZE = 8 * ZBX_MEBIBYTE;
zbx_uint64_t CONFIG_VMWARE_CACHE_SIZE = 8 * ZBX_MEBIBYTE;
zbx_uint64_t CONFIG_EXPORT_FILE_SIZE = ZBX_GIBIBYTE;
int CONFIG_UNREACHABLE_PERIOD = 45;
int CONFIG_UNREACHABLE_DELAY = 15;
int CONFIG_UNAVAILABLE_DELAY = 60;
int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING;
char *CONFIG_ALERT_SCRIPTS_PATH = NULL;
char *CONFIG_EXTERNALSCRIPTS = NULL;
char *CONFIG_TMPDIR = NULL;
char *CONFIG_FPING_LOCATION = NULL;
char *CONFIG_FPING6_LOCATION = NULL;
char *CONFIG_DBHOST = NULL;
char *CONFIG_DBNAME = NULL;
char *CONFIG_DBSCHEMA = NULL;
char *CONFIG_DBUSER = NULL;
char *CONFIG_DBPASSWORD = NULL;
char *CONFIG_VAULTTOKEN = NULL;
char *CONFIG_VAULTURL = NULL;
char *CONFIG_VAULTDBPATH = NULL;
char *CONFIG_DBSOCKET = NULL;
char *CONFIG_DB_TLS_CONNECT = NULL;
char *CONFIG_DB_TLS_CERT_FILE = NULL;
char *CONFIG_DB_TLS_KEY_FILE = NULL;
char *CONFIG_DB_TLS_CA_FILE = NULL;
char *CONFIG_DB_TLS_CIPHER = NULL;
char *CONFIG_DB_TLS_CIPHER_13 = NULL;
char *CONFIG_EXPORT_DIR = NULL;
char *CONFIG_EXPORT_TYPE = NULL;
int CONFIG_DBPORT = 0;
int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
int CONFIG_LOG_REMOTE_COMMANDS = 0;
int CONFIG_UNSAFE_USER_PARAMETERS = 0;
char *CONFIG_SNMPTRAP_FILE = NULL;
char *CONFIG_JAVA_GATEWAY = NULL;
int CONFIG_JAVA_GATEWAY_PORT = ZBX_DEFAULT_GATEWAY_PORT;
char *CONFIG_SSH_KEY_LOCATION = NULL;
int CONFIG_LOG_SLOW_QUERIES = 0; /* ms; 0 - disable */
int CONFIG_SERVER_STARTUP_TIME = 0; /* zabbix server startup time */
int CONFIG_PROXYPOLLER_FORKS = 1; /* parameters for passive proxies */
/* how often Zabbix server sends configuration data to proxy, in seconds */
int CONFIG_PROXYCONFIG_FREQUENCY = SEC_PER_HOUR;
int CONFIG_PROXYDATA_FREQUENCY = 1; /* 1s */
char *CONFIG_LOAD_MODULE_PATH = NULL;
char **CONFIG_LOAD_MODULE = NULL;
char *CONFIG_USER = NULL;
/* web monitoring */
char *CONFIG_SSL_CA_LOCATION = NULL;
char *CONFIG_SSL_CERT_LOCATION = NULL;
char *CONFIG_SSL_KEY_LOCATION = NULL;
/* TLS parameters */
unsigned int configured_tls_connect_mode = ZBX_TCP_SEC_UNENCRYPTED; /* not used in server, defined for linking */
/* with tls.c */
unsigned int configured_tls_accept_modes = ZBX_TCP_SEC_UNENCRYPTED; /* not used in server, defined for linking */
/* with tls.c */
char *CONFIG_TLS_CA_FILE = NULL;
char *CONFIG_TLS_CRL_FILE = NULL;
char *CONFIG_TLS_CERT_FILE = NULL;
char *CONFIG_TLS_KEY_FILE = NULL;
char *CONFIG_TLS_CIPHER_CERT13 = NULL;
char *CONFIG_TLS_CIPHER_CERT = NULL;
char *CONFIG_TLS_CIPHER_PSK13 = NULL;
char *CONFIG_TLS_CIPHER_PSK = NULL;
char *CONFIG_TLS_CIPHER_ALL13 = NULL;
char *CONFIG_TLS_CIPHER_ALL = NULL;
char *CONFIG_TLS_CIPHER_CMD13 = NULL; /* not used in server, defined for linking with tls.c */
char *CONFIG_TLS_CIPHER_CMD = NULL; /* not used in server, defined for linking with tls.c */
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
/* the following TLS parameters are not used in server, they are defined for linking with tls.c */
char *CONFIG_TLS_CONNECT = NULL;
char *CONFIG_TLS_ACCEPT = NULL;
char *CONFIG_TLS_SERVER_CERT_ISSUER = NULL;
char *CONFIG_TLS_SERVER_CERT_SUBJECT = NULL;
char *CONFIG_TLS_PSK_IDENTITY = NULL;
char *CONFIG_TLS_PSK_FILE = NULL;
#endif
static char *CONFIG_SOCKET_PATH = NULL;
char *CONFIG_HISTORY_STORAGE_URL = NULL;
char *CONFIG_HISTORY_STORAGE_OPTS = NULL;
int CONFIG_HISTORY_STORAGE_PIPELINES = 0;
char *CONFIG_STATS_ALLOWED_IP = NULL;
int CONFIG_DOUBLE_PRECISION = ZBX_DB_DBL_PRECISION_DISABLED;
char *CONFIG_WEBSERVICE_URL = NULL;
volatile sig_atomic_t zbx_diaginfo_scope = ZBX_DIAGINFO_UNDEFINED;
int get_process_info_by_thread(int local_server_num, unsigned char *local_process_type, int *local_process_num);
int get_process_info_by_thread(int local_server_num, unsigned char *local_process_type, int *local_process_num)
{
int server_count = 0;
if (0 == local_server_num)
{
/* fail if the main process is queried */
return FAIL;
}
else if (local_server_num <= (server_count += CONFIG_CONFSYNCER_FORKS))
{
/* make initial configuration sync before worker processes are forked */
*local_process_type = ZBX_PROCESS_TYPE_CONFSYNCER;
*local_process_num = local_server_num - server_count + CONFIG_CONFSYNCER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_IPMIMANAGER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_IPMIMANAGER;
*local_process_num = local_server_num - server_count + CONFIG_TASKMANAGER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_HOUSEKEEPER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_HOUSEKEEPER;
*local_process_num = local_server_num - server_count + CONFIG_HOUSEKEEPER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_TIMER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_TIMER;
*local_process_num = local_server_num - server_count + CONFIG_TIMER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_HTTPPOLLER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_HTTPPOLLER;
*local_process_num = local_server_num - server_count + CONFIG_HTTPPOLLER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_DISCOVERER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_DISCOVERER;
*local_process_num = local_server_num - server_count + CONFIG_DISCOVERER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_HISTSYNCER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_HISTSYNCER;
*local_process_num = local_server_num - server_count + CONFIG_HISTSYNCER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_ESCALATOR_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_ESCALATOR;
*local_process_num = local_server_num - server_count + CONFIG_ESCALATOR_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_IPMIPOLLER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_IPMIPOLLER;
*local_process_num = local_server_num - server_count + CONFIG_IPMIPOLLER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_JAVAPOLLER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_JAVAPOLLER;
*local_process_num = local_server_num - server_count + CONFIG_JAVAPOLLER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_SNMPTRAPPER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_SNMPTRAPPER;
*local_process_num = local_server_num - server_count + CONFIG_SNMPTRAPPER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_PROXYPOLLER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_PROXYPOLLER;
*local_process_num = local_server_num - server_count + CONFIG_PROXYPOLLER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_SELFMON_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_SELFMON;
*local_process_num = local_server_num - server_count + CONFIG_SELFMON_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_VMWARE_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_VMWARE;
*local_process_num = local_server_num - server_count + CONFIG_VMWARE_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_TASKMANAGER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_TASKMANAGER;
*local_process_num = local_server_num - server_count + CONFIG_TASKMANAGER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_POLLER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_POLLER;
*local_process_num = local_server_num - server_count + CONFIG_POLLER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_UNREACHABLE_POLLER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_UNREACHABLE;
*local_process_num = local_server_num - server_count + CONFIG_UNREACHABLE_POLLER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_TRAPPER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_TRAPPER;
*local_process_num = local_server_num - server_count + CONFIG_TRAPPER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_PINGER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_PINGER;
*local_process_num = local_server_num - server_count + CONFIG_PINGER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_ALERTMANAGER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_ALERTMANAGER;
*local_process_num = local_server_num - server_count + CONFIG_ALERTMANAGER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_ALERTER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_ALERTER;
*local_process_num = local_server_num - server_count + CONFIG_ALERTER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_PREPROCMAN_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_PREPROCMAN;
*local_process_num = local_server_num - server_count + CONFIG_PREPROCMAN_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_PREPROCESSOR_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_PREPROCESSOR;
*local_process_num = local_server_num - server_count + CONFIG_PREPROCESSOR_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_LLDMANAGER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_LLDMANAGER;
*local_process_num = local_server_num - server_count + CONFIG_LLDMANAGER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_LLDWORKER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_LLDWORKER;
*local_process_num = local_server_num - server_count + CONFIG_LLDWORKER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_ALERTDB_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_ALERTSYNCER;
*local_process_num = local_server_num - server_count + CONFIG_ALERTDB_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_HISTORYPOLLER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_HISTORYPOLLER;
*local_process_num = local_server_num - server_count + CONFIG_HISTORYPOLLER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_AVAILMAN_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_AVAILMAN;
*local_process_num = local_server_num - server_count + CONFIG_AVAILMAN_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_REPORTMANAGER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_REPORTMANAGER;
*local_process_num = local_server_num - server_count + CONFIG_REPORTMANAGER_FORKS;
}
else if (local_server_num <= (server_count += CONFIG_REPORTWRITER_FORKS))
{
*local_process_type = ZBX_PROCESS_TYPE_REPORTWRITER;
*local_process_num = local_server_num - server_count + CONFIG_REPORTWRITER_FORKS;
}
else
return FAIL;
return SUCCEED;
}
/******************************************************************************
* *
* Function: zbx_set_defaults *
* *
* Purpose: set configuration defaults *
* *
* Author: Vladimir Levijev *
* *
******************************************************************************/
static void zbx_set_defaults(void)
{
CONFIG_SERVER_STARTUP_TIME = time(NULL);
if (NULL == CONFIG_DBHOST)
CONFIG_DBHOST = zbx_strdup(CONFIG_DBHOST, "localhost");
if (NULL == CONFIG_SNMPTRAP_FILE)
CONFIG_SNMPTRAP_FILE = zbx_strdup(CONFIG_SNMPTRAP_FILE, "/tmp/zabbix_traps.tmp");
if (NULL == CONFIG_PID_FILE)
CONFIG_PID_FILE = zbx_strdup(CONFIG_PID_FILE, "/tmp/zabbix_server.pid");
if (NULL == CONFIG_ALERT_SCRIPTS_PATH)
CONFIG_ALERT_SCRIPTS_PATH = zbx_strdup(CONFIG_ALERT_SCRIPTS_PATH, DEFAULT_ALERT_SCRIPTS_PATH);
if (NULL == CONFIG_LOAD_MODULE_PATH)
CONFIG_LOAD_MODULE_PATH = zbx_strdup(CONFIG_LOAD_MODULE_PATH, DEFAULT_LOAD_MODULE_PATH);
if (NULL == CONFIG_TMPDIR)
CONFIG_TMPDIR = zbx_strdup(CONFIG_TMPDIR, "/tmp");
if (NULL == CONFIG_FPING_LOCATION)
CONFIG_FPING_LOCATION = zbx_strdup(CONFIG_FPING_LOCATION, "/usr/sbin/fping");
#ifdef HAVE_IPV6
if (NULL == CONFIG_FPING6_LOCATION)
CONFIG_FPING6_LOCATION = zbx_strdup(CONFIG_FPING6_LOCATION, "/usr/sbin/fping6");
#endif
if (NULL == CONFIG_EXTERNALSCRIPTS)
CONFIG_EXTERNALSCRIPTS = zbx_strdup(CONFIG_EXTERNALSCRIPTS, DEFAULT_EXTERNAL_SCRIPTS_PATH);
#ifdef HAVE_LIBCURL
if (NULL == CONFIG_SSL_CERT_LOCATION)
CONFIG_SSL_CERT_LOCATION = zbx_strdup(CONFIG_SSL_CERT_LOCATION, DEFAULT_SSL_CERT_LOCATION);
if (NULL == CONFIG_SSL_KEY_LOCATION)
CONFIG_SSL_KEY_LOCATION = zbx_strdup(CONFIG_SSL_KEY_LOCATION, DEFAULT_SSL_KEY_LOCATION);
if (NULL == CONFIG_HISTORY_STORAGE_OPTS)
CONFIG_HISTORY_STORAGE_OPTS = zbx_strdup(CONFIG_HISTORY_STORAGE_OPTS, "uint,dbl,str,log,text");
#endif
#ifdef HAVE_SQLITE3
CONFIG_MAX_HOUSEKEEPER_DELETE = 0;
#endif
if (NULL == CONFIG_LOG_TYPE_STR)
CONFIG_LOG_TYPE_STR = zbx_strdup(CONFIG_LOG_TYPE_STR, ZBX_OPTION_LOGTYPE_FILE);
if (NULL == CONFIG_SOCKET_PATH)
CONFIG_SOCKET_PATH = zbx_strdup(CONFIG_SOCKET_PATH, "/tmp");
if (0 != CONFIG_IPMIPOLLER_FORKS)
CONFIG_IPMIMANAGER_FORKS = 1;
if (NULL == CONFIG_VAULTURL)
CONFIG_VAULTURL = zbx_strdup(CONFIG_VAULTURL, "https://127.0.0.1:8200");
if (0 != CONFIG_REPORTWRITER_FORKS)
CONFIG_REPORTMANAGER_FORKS = 1;
}
/******************************************************************************
* *
* Function: zbx_validate_config *
* *
* Purpose: validate configuration parameters *
* *
* Author: Vladimir Levijev *
* *
******************************************************************************/
static void zbx_validate_config(ZBX_TASK_EX *task)
{
char *ch_error;
int err = 0;
if (0 == CONFIG_UNREACHABLE_POLLER_FORKS && 0 != CONFIG_POLLER_FORKS + CONFIG_JAVAPOLLER_FORKS)
{
zabbix_log(LOG_LEVEL_CRIT, "\"StartPollersUnreachable\" configuration parameter must not be 0"
" if regular or Java pollers are started");
err = 1;
}
if ((NULL == CONFIG_JAVA_GATEWAY || '\0' == *CONFIG_JAVA_GATEWAY) && 0 < CONFIG_JAVAPOLLER_FORKS)
{
zabbix_log(LOG_LEVEL_CRIT, "\"JavaGateway\" configuration parameter is not specified or empty");
err = 1;
}
if (0 != CONFIG_VALUE_CACHE_SIZE && 128 * ZBX_KIBIBYTE > CONFIG_VALUE_CACHE_SIZE)
{
zabbix_log(LOG_LEVEL_CRIT, "\"ValueCacheSize\" configuration parameter must be either 0"
" or greater than 128KB");
err = 1;
}
if (0 != CONFIG_TREND_FUNC_CACHE_SIZE && 128 * ZBX_KIBIBYTE > CONFIG_TREND_FUNC_CACHE_SIZE)
{
zabbix_log(LOG_LEVEL_CRIT, "\"TrendFunctionCacheSize\" configuration parameter must be either 0"
" or greater than 128KB");
err = 1;
}
if (NULL != CONFIG_SOURCE_IP && SUCCEED != is_supported_ip(CONFIG_SOURCE_IP))
{
zabbix_log(LOG_LEVEL_CRIT, "invalid \"SourceIP\" configuration parameter: '%s'", CONFIG_SOURCE_IP);
err = 1;
}
if (NULL != CONFIG_STATS_ALLOWED_IP && FAIL == zbx_validate_peer_list(CONFIG_STATS_ALLOWED_IP, &ch_error))
{
zabbix_log(LOG_LEVEL_CRIT, "invalid entry in \"StatsAllowedIP\" configuration parameter: %s", ch_error);
zbx_free(ch_error);
err = 1;
}
if (SUCCEED != zbx_validate_export_type(CONFIG_EXPORT_TYPE, NULL))
{
zabbix_log(LOG_LEVEL_CRIT, "invalid \"ExportType\" configuration parameter: %s", CONFIG_EXPORT_TYPE);
err = 1;
}
#if !defined(HAVE_IPV6)
err |= (FAIL == check_cfg_feature_str("Fping6Location", CONFIG_FPING6_LOCATION, "IPv6 support"));
#endif
#if !defined(HAVE_LIBCURL)
err |= (FAIL == check_cfg_feature_str("SSLCALocation", CONFIG_SSL_CA_LOCATION, "cURL library"));
err |= (FAIL == check_cfg_feature_str("SSLCertLocation", CONFIG_SSL_CERT_LOCATION, "cURL library"));
err |= (FAIL == check_cfg_feature_str("SSLKeyLocation", CONFIG_SSL_KEY_LOCATION, "cURL library"));
err |= (FAIL == check_cfg_feature_str("HistoryStorageURL", CONFIG_HISTORY_STORAGE_URL, "cURL library"));
err |= (FAIL == check_cfg_feature_str("HistoryStorageTypes", CONFIG_HISTORY_STORAGE_OPTS, "cURL library"));
err |= (FAIL == check_cfg_feature_int("HistoryStorageDateIndex", CONFIG_HISTORY_STORAGE_PIPELINES,
"cURL library"));
err |= (FAIL == check_cfg_feature_str("VaultToken", CONFIG_VAULTTOKEN, "cURL library"));
err |= (FAIL == check_cfg_feature_str("VaultDBPath", CONFIG_VAULTDBPATH, "cURL library"));
err |= (FAIL == check_cfg_feature_int("StartReportWriters", CONFIG_REPORTWRITER_FORKS, "cURL library"));
#endif
#if !defined(HAVE_LIBXML2) || !defined(HAVE_LIBCURL)
err |= (FAIL == check_cfg_feature_int("StartVMwareCollectors", CONFIG_VMWARE_FORKS, "VMware support"));
/* parameters VMwareFrequency, VMwarePerfFrequency, VMwareCacheSize, VMwareTimeout are not checked here */
/* because they have non-zero default values */
#endif
if (SUCCEED != zbx_validate_log_parameters(task))
err = 1;
#if !(defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL))
err |= (FAIL == check_cfg_feature_str("TLSCAFile", CONFIG_TLS_CA_FILE, "TLS support"));
err |= (FAIL == check_cfg_feature_str("TLSCRLFile", CONFIG_TLS_CRL_FILE, "TLS support"));
err |= (FAIL == check_cfg_feature_str("TLSCertFile", CONFIG_TLS_CERT_FILE, "TLS support"));
err |= (FAIL == check_cfg_feature_str("TLSKeyFile", CONFIG_TLS_KEY_FILE, "TLS support"));
#endif
#if !(defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL))
err |= (FAIL == check_cfg_feature_str("TLSCipherCert", CONFIG_TLS_CIPHER_CERT, "GnuTLS or OpenSSL"));
err |= (FAIL == check_cfg_feature_str("TLSCipherPSK", CONFIG_TLS_CIPHER_PSK, "GnuTLS or OpenSSL"));
err |= (FAIL == check_cfg_feature_str("TLSCipherAll", CONFIG_TLS_CIPHER_ALL, "GnuTLS or OpenSSL"));
#endif
#if !defined(HAVE_OPENSSL)
err |= (FAIL == check_cfg_feature_str("TLSCipherCert13", CONFIG_TLS_CIPHER_CERT13, "OpenSSL 1.1.1 or newer"));
err |= (FAIL == check_cfg_feature_str("TLSCipherPSK13", CONFIG_TLS_CIPHER_PSK13, "OpenSSL 1.1.1 or newer"));
err |= (FAIL == check_cfg_feature_str("TLSCipherAll13", CONFIG_TLS_CIPHER_ALL13, "OpenSSL 1.1.1 or newer"));
#endif
#if !defined(HAVE_OPENIPMI)
err |= (FAIL == check_cfg_feature_int("StartIPMIPollers", CONFIG_IPMIPOLLER_FORKS, "IPMI support"));
#endif
err |= (FAIL == zbx_db_validate_config_features());
if (0 != CONFIG_REPORTWRITER_FORKS && NULL == CONFIG_WEBSERVICE_URL)
{
zabbix_log(LOG_LEVEL_CRIT, "\"WebServiceURL\" configuration parameter must be set when "
" setting \"StartReportWriters\" configuration parameter");
}
if (0 != err)
exit(EXIT_FAILURE);
}
/******************************************************************************
* *
* Function: zbx_load_config *
* *
* Purpose: parse config file and update configuration parameters *
* *
* Parameters: *
* *
* Return value: *
* *
* Author: Alexei Vladishev *
* *
* Comments: will terminate process if parsing fails *
* *
******************************************************************************/
static void zbx_load_config(ZBX_TASK_EX *task)
{
static struct cfg_line cfg[] =
{
/* PARAMETER, VAR, TYPE,
MANDATORY, MIN, MAX */
{"StartDBSyncers", &CONFIG_HISTSYNCER_FORKS, TYPE_INT,
PARM_OPT, 1, 100},
{"StartDiscoverers", &CONFIG_DISCOVERER_FORKS, TYPE_INT,
PARM_OPT, 0, 250},
{"StartHTTPPollers", &CONFIG_HTTPPOLLER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartPingers", &CONFIG_PINGER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartPollers", &CONFIG_POLLER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartPollersUnreachable", &CONFIG_UNREACHABLE_POLLER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartIPMIPollers", &CONFIG_IPMIPOLLER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartTimers", &CONFIG_TIMER_FORKS, TYPE_INT,
PARM_OPT, 1, 1000},
{"StartTrappers", &CONFIG_TRAPPER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartJavaPollers", &CONFIG_JAVAPOLLER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartEscalators", &CONFIG_ESCALATOR_FORKS, TYPE_INT,
PARM_OPT, 1, 100},
{"JavaGateway", &CONFIG_JAVA_GATEWAY, TYPE_STRING,
PARM_OPT, 0, 0},
{"JavaGatewayPort", &CONFIG_JAVA_GATEWAY_PORT, TYPE_INT,
PARM_OPT, 1024, 32767},
{"SNMPTrapperFile", &CONFIG_SNMPTRAP_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"StartSNMPTrapper", &CONFIG_SNMPTRAPPER_FORKS, TYPE_INT,
PARM_OPT, 0, 1},
{"CacheSize", &CONFIG_CONF_CACHE_SIZE, TYPE_UINT64,
PARM_OPT, 128 * ZBX_KIBIBYTE, __UINT64_C(64) * ZBX_GIBIBYTE},
{"HistoryCacheSize", &CONFIG_HISTORY_CACHE_SIZE, TYPE_UINT64,
PARM_OPT, 128 * ZBX_KIBIBYTE, __UINT64_C(2) * ZBX_GIBIBYTE},
{"HistoryIndexCacheSize", &CONFIG_HISTORY_INDEX_CACHE_SIZE, TYPE_UINT64,
PARM_OPT, 128 * ZBX_KIBIBYTE, __UINT64_C(2) * ZBX_GIBIBYTE},
{"TrendCacheSize", &CONFIG_TRENDS_CACHE_SIZE, TYPE_UINT64,
PARM_OPT, 128 * ZBX_KIBIBYTE, __UINT64_C(2) * ZBX_GIBIBYTE},
{"TrendFunctionCacheSize", &CONFIG_TREND_FUNC_CACHE_SIZE, TYPE_UINT64,
PARM_OPT, 0, __UINT64_C(2) * ZBX_GIBIBYTE},
{"ValueCacheSize", &CONFIG_VALUE_CACHE_SIZE, TYPE_UINT64,
PARM_OPT, 0, __UINT64_C(64) * ZBX_GIBIBYTE},
{"CacheUpdateFrequency", &CONFIG_CONFSYNCER_FREQUENCY, TYPE_INT,
PARM_OPT, 1, SEC_PER_HOUR},
{"HousekeepingFrequency", &CONFIG_HOUSEKEEPING_FREQUENCY, TYPE_INT,
PARM_OPT, 0, 24},
{"MaxHousekeeperDelete", &CONFIG_MAX_HOUSEKEEPER_DELETE, TYPE_INT,
PARM_OPT, 0, 1000000},
{"TmpDir", &CONFIG_TMPDIR, TYPE_STRING,
PARM_OPT, 0, 0},
{"FpingLocation", &CONFIG_FPING_LOCATION, TYPE_STRING,
PARM_OPT, 0, 0},
{"Fping6Location", &CONFIG_FPING6_LOCATION, TYPE_STRING,
PARM_OPT, 0, 0},
{"Timeout", &CONFIG_TIMEOUT, TYPE_INT,
PARM_OPT, 1, 30},
{"TrapperTimeout", &CONFIG_TRAPPER_TIMEOUT, TYPE_INT,
PARM_OPT, 1, 300},
{"UnreachablePeriod", &CONFIG_UNREACHABLE_PERIOD, TYPE_INT,
PARM_OPT, 1, SEC_PER_HOUR},
{"UnreachableDelay", &CONFIG_UNREACHABLE_DELAY, TYPE_INT,
PARM_OPT, 1, SEC_PER_HOUR},
{"UnavailableDelay", &CONFIG_UNAVAILABLE_DELAY, TYPE_INT,
PARM_OPT, 1, SEC_PER_HOUR},
{"ListenIP", &CONFIG_LISTEN_IP, TYPE_STRING_LIST,
PARM_OPT, 0, 0},
{"ListenPort", &CONFIG_LISTEN_PORT, TYPE_INT,
PARM_OPT, 1024, 32767},
{"SourceIP", &CONFIG_SOURCE_IP, TYPE_STRING,
PARM_OPT, 0, 0},
{"DebugLevel", &CONFIG_LOG_LEVEL, TYPE_INT,
PARM_OPT, 0, 5},
{"PidFile", &CONFIG_PID_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"LogType", &CONFIG_LOG_TYPE_STR, TYPE_STRING,
PARM_OPT, 0, 0},
{"LogFile", &CONFIG_LOG_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"LogFileSize", &CONFIG_LOG_FILE_SIZE, TYPE_INT,
PARM_OPT, 0, 1024},
{"AlertScriptsPath", &CONFIG_ALERT_SCRIPTS_PATH, TYPE_STRING,
PARM_OPT, 0, 0},
{"ExternalScripts", &CONFIG_EXTERNALSCRIPTS, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBHost", &CONFIG_DBHOST, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBName", &CONFIG_DBNAME, TYPE_STRING,
PARM_MAND, 0, 0},
{"DBSchema", &CONFIG_DBSCHEMA, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBUser", &CONFIG_DBUSER, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBPassword", &CONFIG_DBPASSWORD, TYPE_STRING,
PARM_OPT, 0, 0},
{"VaultToken", &CONFIG_VAULTTOKEN, TYPE_STRING,
PARM_OPT, 0, 0},
{"VaultURL", &CONFIG_VAULTURL, TYPE_STRING,
PARM_OPT, 0, 0},
{"VaultDBPath", &CONFIG_VAULTDBPATH, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBSocket", &CONFIG_DBSOCKET, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBPort", &CONFIG_DBPORT, TYPE_INT,
PARM_OPT, 1024, 65535},
{"DBTLSConnect", &CONFIG_DB_TLS_CONNECT, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBTLSCertFile", &CONFIG_DB_TLS_CERT_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBTLSKeyFile", &CONFIG_DB_TLS_KEY_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBTLSCAFile", &CONFIG_DB_TLS_CA_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBTLSCipher", &CONFIG_DB_TLS_CIPHER, TYPE_STRING,
PARM_OPT, 0, 0},
{"DBTLSCipher13", &CONFIG_DB_TLS_CIPHER_13, TYPE_STRING,
PARM_OPT, 0, 0},
{"SSHKeyLocation", &CONFIG_SSH_KEY_LOCATION, TYPE_STRING,
PARM_OPT, 0, 0},
{"LogSlowQueries", &CONFIG_LOG_SLOW_QUERIES, TYPE_INT,
PARM_OPT, 0, 3600000},
{"StartProxyPollers", &CONFIG_PROXYPOLLER_FORKS, TYPE_INT,
PARM_OPT, 0, 250},
{"ProxyConfigFrequency", &CONFIG_PROXYCONFIG_FREQUENCY, TYPE_INT,
PARM_OPT, 1, SEC_PER_WEEK},
{"ProxyDataFrequency", &CONFIG_PROXYDATA_FREQUENCY, TYPE_INT,
PARM_OPT, 1, SEC_PER_HOUR},
{"LoadModulePath", &CONFIG_LOAD_MODULE_PATH, TYPE_STRING,
PARM_OPT, 0, 0},
{"LoadModule", &CONFIG_LOAD_MODULE, TYPE_MULTISTRING,
PARM_OPT, 0, 0},
{"StartVMwareCollectors", &CONFIG_VMWARE_FORKS, TYPE_INT,
PARM_OPT, 0, 250},
{"VMwareFrequency", &CONFIG_VMWARE_FREQUENCY, TYPE_INT,
PARM_OPT, 10, SEC_PER_DAY},
{"VMwarePerfFrequency", &CONFIG_VMWARE_PERF_FREQUENCY, TYPE_INT,
PARM_OPT, 10, SEC_PER_DAY},
{"VMwareCacheSize", &CONFIG_VMWARE_CACHE_SIZE, TYPE_UINT64,
PARM_OPT, 256 * ZBX_KIBIBYTE, __UINT64_C(2) * ZBX_GIBIBYTE},
{"VMwareTimeout", &CONFIG_VMWARE_TIMEOUT, TYPE_INT,
PARM_OPT, 1, 300},
{"AllowRoot", &CONFIG_ALLOW_ROOT, TYPE_INT,
PARM_OPT, 0, 1},
{"User", &CONFIG_USER, TYPE_STRING,
PARM_OPT, 0, 0},
{"SSLCALocation", &CONFIG_SSL_CA_LOCATION, TYPE_STRING,
PARM_OPT, 0, 0},
{"SSLCertLocation", &CONFIG_SSL_CERT_LOCATION, TYPE_STRING,
PARM_OPT, 0, 0},
{"SSLKeyLocation", &CONFIG_SSL_KEY_LOCATION, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCAFile", &CONFIG_TLS_CA_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCRLFile", &CONFIG_TLS_CRL_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCertFile", &CONFIG_TLS_CERT_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSKeyFile", &CONFIG_TLS_KEY_FILE, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCipherCert13", &CONFIG_TLS_CIPHER_CERT13, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCipherCert", &CONFIG_TLS_CIPHER_CERT, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCipherPSK13", &CONFIG_TLS_CIPHER_PSK13, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCipherPSK", &CONFIG_TLS_CIPHER_PSK, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCipherAll13", &CONFIG_TLS_CIPHER_ALL13, TYPE_STRING,
PARM_OPT, 0, 0},
{"TLSCipherAll", &CONFIG_TLS_CIPHER_ALL, TYPE_STRING,
PARM_OPT, 0, 0},
{"SocketDir", &CONFIG_SOCKET_PATH, TYPE_STRING,
PARM_OPT, 0, 0},
{"StartAlerters", &CONFIG_ALERTER_FORKS, TYPE_INT,
PARM_OPT, 1, 100},
{"StartPreprocessors", &CONFIG_PREPROCESSOR_FORKS, TYPE_INT,
PARM_OPT, 1, 1000},
{"HistoryStorageURL", &CONFIG_HISTORY_STORAGE_URL, TYPE_STRING,
PARM_OPT, 0, 0},
{"HistoryStorageTypes", &CONFIG_HISTORY_STORAGE_OPTS, TYPE_STRING_LIST,
PARM_OPT, 0, 0},
{"HistoryStorageDateIndex", &CONFIG_HISTORY_STORAGE_PIPELINES, TYPE_INT,
PARM_OPT, 0, 1},
{"ExportDir", &CONFIG_EXPORT_DIR, TYPE_STRING,
PARM_OPT, 0, 0},
{"ExportType", &CONFIG_EXPORT_TYPE, TYPE_STRING_LIST,
PARM_OPT, 0, 0},
{"ExportFileSize", &CONFIG_EXPORT_FILE_SIZE, TYPE_UINT64,
PARM_OPT, ZBX_MEBIBYTE, ZBX_GIBIBYTE},
{"StartLLDProcessors", &CONFIG_LLDWORKER_FORKS, TYPE_INT,
PARM_OPT, 1, 100},
{"StatsAllowedIP", &CONFIG_STATS_ALLOWED_IP, TYPE_STRING_LIST,
PARM_OPT, 0, 0},
{"StartHistoryPollers", &CONFIG_HISTORYPOLLER_FORKS, TYPE_INT,
PARM_OPT, 0, 1000},
{"StartReportWriters", &CONFIG_REPORTWRITER_FORKS, TYPE_INT,
PARM_OPT, 0, 100},
{"WebServiceURL", &CONFIG_WEBSERVICE_URL, TYPE_STRING,
PARM_OPT, 0, 0},
{NULL}
};
/* initialize multistrings */
zbx_strarr_init(&CONFIG_LOAD_MODULE);
parse_cfg_file(CONFIG_FILE, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_STRICT);
zbx_set_defaults();
CONFIG_LOG_TYPE = zbx_get_log_type(CONFIG_LOG_TYPE_STR);
zbx_validate_config(task);
#if defined(HAVE_MYSQL) || defined(HAVE_POSTGRESQL)
zbx_db_validate_config();
#endif
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
zbx_tls_validate_config();
#endif
}
/******************************************************************************
* *
* Function: zbx_free_config *
* *
* Purpose: free configuration memory *
* *
******************************************************************************/
static void zbx_free_config(void)
{
zbx_strarr_free(CONFIG_LOAD_MODULE);
}
/******************************************************************************
* *
* Function: main *
* *
* Purpose: executes server processes *
* *
* Author: Eugene Grigorjev *
* *
******************************************************************************/
int main(int argc, char **argv)
{
ZBX_TASK_EX t = {ZBX_TASK_START};
char ch, *error = NULL;
int opt_c = 0, opt_r = 0;
#if defined(PS_OVERWRITE_ARGV) || defined(PS_PSTAT_ARGV)
argv = setproctitle_save_env(argc, argv);
#endif
progname = get_program_name(argv[0]);
/* parse the command-line */
while ((char)EOF != (ch = (char)zbx_getopt_long(argc, argv, shortopts, longopts, NULL)))
{
switch (ch)
{
case 'c':
opt_c++;
if (NULL == CONFIG_FILE)
CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
break;
case 'R':
opt_r++;
if (SUCCEED != parse_rtc_options(zbx_optarg, program_type, &t.data))
exit(EXIT_FAILURE);
t.task = ZBX_TASK_RUNTIME_CONTROL;
break;
case 'h':
help();
exit(EXIT_SUCCESS);
break;
case 'V':
version();
exit(EXIT_SUCCESS);
break;
case 'f':
t.flags |= ZBX_TASK_FLAG_FOREGROUND;
break;
default:
usage();
exit(EXIT_FAILURE);
break;
}
}
/* every option may be specified only once */
if (1 < opt_c || 1 < opt_r)
{
if (1 < opt_c)
zbx_error("option \"-c\" or \"--config\" specified multiple times");
if (1 < opt_r)
zbx_error("option \"-R\" or \"--runtime-control\" specified multiple times");
exit(EXIT_FAILURE);
}
/* Parameters which are not option values are invalid. The check relies on zbx_getopt_internal() which */
/* always permutes command line arguments regardless of POSIXLY_CORRECT environment variable. */
if (argc > zbx_optind)
{
int i;
for (i = zbx_optind; i < argc; i++)
zbx_error("invalid parameter \"%s\"", argv[i]);
exit(EXIT_FAILURE);
}
if (NULL == CONFIG_FILE)
CONFIG_FILE = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
/* required for simple checks */
init_metrics();
zbx_load_config(&t);
if (ZBX_TASK_RUNTIME_CONTROL == t.task)
exit(SUCCEED == zbx_sigusr_send(t.data) ? EXIT_SUCCESS : EXIT_FAILURE);
zbx_initialize_events();
if (FAIL == zbx_ipc_service_init_env(CONFIG_SOCKET_PATH, &error))
{
zbx_error("Cannot initialize IPC services: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, t.flags);
}
static void zbx_main_sigusr_handler(int flags)
{
if (ZBX_RTC_DIAGINFO == ZBX_RTC_GET_MSG(flags))
{
int scope = ZBX_RTC_GET_SCOPE(flags);
if (ZBX_DIAGINFO_ALL == scope)
{
zbx_diaginfo_scope = (1 << ZBX_DIAGINFO_HISTORYCACHE) | (1 << ZBX_DIAGINFO_VALUECACHE) |
(1 << ZBX_DIAGINFO_PREPROCESSING) | (1 << ZBX_DIAGINFO_LLD) |
(1 << ZBX_DIAGINFO_ALERTING) | (1 << ZBX_DIAGINFO_LOCKS);
}
else
zbx_diaginfo_scope = 1 << scope;
}
}
int MAIN_ZABBIX_ENTRY(int flags)
{
zbx_socket_t listen_sock;
char *error = NULL;
int i, db_type;
if (0 != (flags & ZBX_TASK_FLAG_FOREGROUND))
{
printf("Starting Zabbix Server. Zabbix %s (revision %s).\nPress Ctrl+C to exit.\n\n",
ZABBIX_VERSION, ZABBIX_REVISION);
}
if (SUCCEED != zbx_locks_create(&error))
{
zbx_error("cannot create locks: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != zabbix_open_log(CONFIG_LOG_TYPE, CONFIG_LOG_LEVEL, CONFIG_LOG_FILE, &error))
{
zbx_error("cannot open log: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
#ifdef HAVE_NETSNMP
# define SNMP_FEATURE_STATUS "YES"
#else
# define SNMP_FEATURE_STATUS " NO"
#endif
#ifdef HAVE_OPENIPMI
# define IPMI_FEATURE_STATUS "YES"
#else
# define IPMI_FEATURE_STATUS " NO"
#endif
#ifdef HAVE_LIBCURL
# define LIBCURL_FEATURE_STATUS "YES"
#else
# define LIBCURL_FEATURE_STATUS " NO"
#endif
#if defined(HAVE_LIBCURL) && defined(HAVE_LIBXML2)
# define VMWARE_FEATURE_STATUS "YES"
#else
# define VMWARE_FEATURE_STATUS " NO"
#endif
#ifdef HAVE_SMTP_AUTHENTICATION
# define SMTP_AUTH_FEATURE_STATUS "YES"
#else
# define SMTP_AUTH_FEATURE_STATUS " NO"
#endif
#ifdef HAVE_UNIXODBC
# define ODBC_FEATURE_STATUS "YES"
#else
# define ODBC_FEATURE_STATUS " NO"
#endif
#if defined(HAVE_SSH2) || defined(HAVE_SSH)
# define SSH_FEATURE_STATUS "YES"
#else
# define SSH_FEATURE_STATUS " NO"
#endif
#ifdef HAVE_IPV6
# define IPV6_FEATURE_STATUS "YES"
#else
# define IPV6_FEATURE_STATUS " NO"
#endif
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
# define TLS_FEATURE_STATUS "YES"
#else
# define TLS_FEATURE_STATUS " NO"
#endif
zabbix_log(LOG_LEVEL_INFORMATION, "Starting Zabbix Server. Zabbix %s (revision %s).",
ZABBIX_VERSION, ZABBIX_REVISION);
zabbix_log(LOG_LEVEL_INFORMATION, "****** Enabled features ******");
zabbix_log(LOG_LEVEL_INFORMATION, "SNMP monitoring: " SNMP_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "IPMI monitoring: " IPMI_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "Web monitoring: " LIBCURL_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "VMware monitoring: " VMWARE_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "SMTP authentication: " SMTP_AUTH_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "ODBC: " ODBC_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "SSH support: " SSH_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "IPv6 support: " IPV6_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "TLS support: " TLS_FEATURE_STATUS);
zabbix_log(LOG_LEVEL_INFORMATION, "******************************");
zabbix_log(LOG_LEVEL_INFORMATION, "using configuration file: %s", CONFIG_FILE);
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
if (SUCCEED != zbx_coredump_disable())
{
zabbix_log(LOG_LEVEL_CRIT, "cannot disable core dump, exiting...");
exit(EXIT_FAILURE);
}
#endif
if (FAIL == zbx_load_modules(CONFIG_LOAD_MODULE_PATH, CONFIG_LOAD_MODULE, CONFIG_TIMEOUT, 1))
{
zabbix_log(LOG_LEVEL_CRIT, "loading modules failed, exiting...");
exit(EXIT_FAILURE);
}
zbx_free_config();
if (SUCCEED != init_database_cache(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize database cache: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != init_configuration_cache(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize configuration cache: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != init_selfmon_collector(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize self-monitoring: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (0 != CONFIG_VMWARE_FORKS && SUCCEED != zbx_vmware_init(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize VMware cache: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != zbx_vc_init(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize history value cache: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != zbx_create_itservices_lock(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot create IT services lock: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != zbx_history_init(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize history storage: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != zbx_tfc_init(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize trends read cache: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (FAIL == zbx_export_init(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize export: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != zbx_vault_init_token_from_env(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize vault token: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (SUCCEED != zbx_vault_init_db_credentials(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize database credentials from vault: %s", error);
zbx_free(error);
exit(EXIT_FAILURE);
}
if (ZBX_DB_UNKNOWN == (db_type = zbx_db_get_database_type()))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot use database \"%s\": database is not a Zabbix database",
CONFIG_DBNAME);
exit(EXIT_FAILURE);
}
else if (ZBX_DB_SERVER != db_type)
{
zabbix_log(LOG_LEVEL_CRIT, "cannot use database \"%s\": its \"users\" table is empty (is this the"
" Zabbix proxy database?)", CONFIG_DBNAME);
exit(EXIT_FAILURE);
}
DBcheck_capabilities();
if (SUCCEED != DBcheck_version())
exit(EXIT_FAILURE);
DBcheck_character_set();
if (SUCCEED == DBcheck_double_type())
CONFIG_DOUBLE_PRECISION = ZBX_DB_DBL_PRECISION_ENABLED;
else
zabbix_log(LOG_LEVEL_WARNING, "database is not upgraded to use double precision values");
if (SUCCEED != zbx_db_check_instanceid())
exit(EXIT_FAILURE);
threads_num = CONFIG_CONFSYNCER_FORKS + CONFIG_POLLER_FORKS
+ CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_TRAPPER_FORKS + CONFIG_PINGER_FORKS
+ CONFIG_ALERTER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS
+ CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS + CONFIG_HISTSYNCER_FORKS
+ CONFIG_ESCALATOR_FORKS + CONFIG_IPMIPOLLER_FORKS + CONFIG_JAVAPOLLER_FORKS
+ CONFIG_SNMPTRAPPER_FORKS + CONFIG_PROXYPOLLER_FORKS + CONFIG_SELFMON_FORKS
+ CONFIG_VMWARE_FORKS + CONFIG_TASKMANAGER_FORKS + CONFIG_IPMIMANAGER_FORKS
+ CONFIG_ALERTMANAGER_FORKS + CONFIG_PREPROCMAN_FORKS + CONFIG_PREPROCESSOR_FORKS
+ CONFIG_LLDMANAGER_FORKS + CONFIG_LLDWORKER_FORKS + CONFIG_ALERTDB_FORKS
+ CONFIG_HISTORYPOLLER_FORKS + CONFIG_AVAILMAN_FORKS + CONFIG_REPORTMANAGER_FORKS
+ CONFIG_REPORTWRITER_FORKS;
threads = (pid_t *)zbx_calloc(threads, threads_num, sizeof(pid_t));
threads_flags = (int *)zbx_calloc(threads_flags, threads_num, sizeof(int));
if (0 != CONFIG_TRAPPER_FORKS)
{
if (FAIL == zbx_tcp_listen(&listen_sock, CONFIG_LISTEN_IP, (unsigned short)CONFIG_LISTEN_PORT))
{
zabbix_log(LOG_LEVEL_CRIT, "listener failed: %s", zbx_socket_strerror());
exit(EXIT_FAILURE);
}
}
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
zbx_tls_init_parent();
#endif
zabbix_log(LOG_LEVEL_INFORMATION, "server #0 started [main process]");
for (i = 0; i < threads_num; i++)
{
zbx_thread_args_t thread_args;
unsigned char poller_type;
if (FAIL == get_process_info_by_thread(i + 1, &thread_args.process_type, &thread_args.process_num))
{
THIS_SHOULD_NEVER_HAPPEN;
exit(EXIT_FAILURE);
}
thread_args.server_num = i + 1;
thread_args.args = NULL;
switch (thread_args.process_type)
{
case ZBX_PROCESS_TYPE_CONFSYNCER:
zbx_thread_start(dbconfig_thread, &thread_args, &threads[i]);
DCconfig_wait_sync();
DBconnect(ZBX_DB_CONNECT_NORMAL);
if (SUCCEED != zbx_check_postinit_tasks(&error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot complete post initialization tasks: %s",
error);
zbx_free(error);
exit(EXIT_FAILURE);
}
/* update maintenance states */
zbx_dc_update_maintenances();
DBclose();
zbx_vc_enable();
break;
case ZBX_PROCESS_TYPE_POLLER:
poller_type = ZBX_POLLER_TYPE_NORMAL;
thread_args.args = &poller_type;
zbx_thread_start(poller_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_UNREACHABLE:
poller_type = ZBX_POLLER_TYPE_UNREACHABLE;
thread_args.args = &poller_type;
zbx_thread_start(poller_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_TRAPPER:
thread_args.args = &listen_sock;
zbx_thread_start(trapper_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_PINGER:
zbx_thread_start(pinger_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_ALERTER:
zbx_thread_start(alerter_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_HOUSEKEEPER:
zbx_thread_start(housekeeper_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_TIMER:
zbx_thread_start(timer_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_HTTPPOLLER:
zbx_thread_start(httppoller_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_DISCOVERER:
zbx_thread_start(discoverer_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_HISTSYNCER:
threads_flags[i] = ZBX_THREAD_WAIT_EXIT;
zbx_thread_start(dbsyncer_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_ESCALATOR:
zbx_thread_start(escalator_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_JAVAPOLLER:
poller_type = ZBX_POLLER_TYPE_JAVA;
thread_args.args = &poller_type;
zbx_thread_start(poller_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_SNMPTRAPPER:
zbx_thread_start(snmptrapper_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_PROXYPOLLER:
zbx_thread_start(proxypoller_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_SELFMON:
zbx_thread_start(selfmon_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_VMWARE:
zbx_thread_start(vmware_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_TASKMANAGER:
zbx_thread_start(taskmanager_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_PREPROCMAN:
zbx_thread_start(preprocessing_manager_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_PREPROCESSOR:
zbx_thread_start(preprocessing_worker_thread, &thread_args, &threads[i]);
break;
#ifdef HAVE_OPENIPMI
case ZBX_PROCESS_TYPE_IPMIMANAGER:
zbx_thread_start(ipmi_manager_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_IPMIPOLLER:
zbx_thread_start(ipmi_poller_thread, &thread_args, &threads[i]);
break;
#endif
case ZBX_PROCESS_TYPE_ALERTMANAGER:
zbx_thread_start(alert_manager_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_LLDMANAGER:
zbx_thread_start(lld_manager_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_LLDWORKER:
zbx_thread_start(lld_worker_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_ALERTSYNCER:
zbx_thread_start(alert_syncer_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_HISTORYPOLLER:
poller_type = ZBX_POLLER_TYPE_HISTORY;
thread_args.args = &poller_type;
zbx_thread_start(poller_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_AVAILMAN:
threads_flags[i] = ZBX_THREAD_WAIT_EXIT;
zbx_thread_start(availability_manager_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_REPORTMANAGER:
zbx_thread_start(report_manager_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_REPORTWRITER:
zbx_thread_start(report_writer_thread, &thread_args, &threads[i]);
break;
}
}
if (SUCCEED == zbx_is_export_enabled(ZBX_FLAG_EXPTYPE_EVENTS))
zbx_problems_export_init("main-process", 0);
if (SUCCEED == zbx_is_export_enabled(ZBX_FLAG_EXPTYPE_HISTORY))
zbx_history_export_init("main-process", 0);
if (SUCCEED == zbx_is_export_enabled(ZBX_FLAG_EXPTYPE_TRENDS))
zbx_trends_export_init("main-process", 0);
zbx_set_sigusr_handler(zbx_main_sigusr_handler);
while (-1 == wait(&i)) /* wait for any child to exit */
{
if (EINTR != errno)
{
zabbix_log(LOG_LEVEL_ERR, "failed to wait on child processes: %s", zbx_strerror(errno));
break;
}
/* check if the wait was interrupted because of diaginfo remote command */
if (ZBX_DIAGINFO_UNDEFINED != zbx_diaginfo_scope)
{
zbx_diag_log_info(zbx_diaginfo_scope);
zbx_diaginfo_scope = ZBX_DIAGINFO_UNDEFINED;
}
}
/* all exiting child processes should be caught by signal handlers */
THIS_SHOULD_NEVER_HAPPEN;
zbx_on_exit(FAIL);
return SUCCEED;
}
void zbx_on_exit(int ret)
{
zabbix_log(LOG_LEVEL_DEBUG, "zbx_on_exit() called");
if (SUCCEED == DBtxn_ongoing())
DBrollback();
if (NULL != threads)
{
zbx_threads_wait(threads, threads_flags, threads_num, ret); /* wait for all child processes to exit */
zbx_free(threads);
zbx_free(threads_flags);
}
#ifdef HAVE_PTHREAD_PROCESS_SHARED
zbx_locks_disable();
#endif
free_metrics();
zbx_ipc_service_free_env();
DBconnect(ZBX_DB_CONNECT_EXIT);
free_database_cache();
DBclose();
free_configuration_cache();
/* free history value cache */
zbx_vc_destroy();
zbx_destroy_itservices_lock();
/* free vmware support */
if (0 != CONFIG_VMWARE_FORKS)
zbx_vmware_destroy();
free_selfmon_collector();
zbx_uninitialize_events();
zbx_unload_modules();
zabbix_log(LOG_LEVEL_INFORMATION, "Zabbix Server stopped. Zabbix %s (revision %s).",
ZABBIX_VERSION, ZABBIX_REVISION);
zabbix_close_log();
#if defined(PS_OVERWRITE_ARGV)
setproctitle_free_env();
#endif
exit(EXIT_SUCCESS);
}
|