Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2022-11-04 12:18:04 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2022-11-04 12:18:04 +0300
commit6835ef59b1bef2bbe783f90b8399bee0f1f93ab8 (patch)
tree0ff5d278eafba845eaa3b781ce60946f60b755c2 /src
parent4002ee1805523ade2a39e560f13a23128078524b (diff)
parentc69f0a13490c3893b103c1a6a28f38fb16e0c23d (diff)
.......... [ZBXNEXT-8040] merged branch 'master' of ssh://git.zabbix.com:7999/zbx/zabbix into feature/ZBXNEXT-8040-6.3
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/go/conf/zabbix_agent2.d/plugins.d/postgres.conf96
-rw-r--r--src/go/go.mod14
-rw-r--r--src/go/go.sum168
-rw-r--r--src/go/pkg/tlsconfig/tlsconfig.go102
-rw-r--r--src/go/pkg/version/version.go4
-rw-r--r--src/go/pkg/zbxlib/checks_darwin.go54
-rw-r--r--src/go/pkg/zbxlib/checks_linux.go80
-rw-r--r--src/go/pkg/zbxlib/checks_windows.go52
-rw-r--r--src/go/pkg/zbxlib/globals_windows.go8
-rw-r--r--src/go/plugins/mysql/conn.go2
-rw-r--r--src/go/plugins/mysql/mysql.go2
-rw-r--r--src/go/plugins/plugins_darwin.go1
-rw-r--r--src/go/plugins/plugins_linux.go1
-rw-r--r--src/go/plugins/plugins_windows.go1
-rw-r--r--src/go/plugins/postgres/README.md632
-rwxr-xr-xsrc/go/plugins/postgres/config.go96
-rwxr-xr-xsrc/go/plugins/postgres/conn.go333
-rw-r--r--src/go/plugins/postgres/handler_archive.go92
-rw-r--r--src/go/plugins/postgres/handler_archive_test.go70
-rw-r--r--src/go/plugins/postgres/handler_autovacuum.go56
-rw-r--r--src/go/plugins/postgres/handler_autovacuum_test.go67
-rw-r--r--src/go/plugins/postgres/handler_bgwriter.go68
-rw-r--r--src/go/plugins/postgres/handler_bgwriter_test.go66
-rw-r--r--src/go/plugins/postgres/handler_cache.go52
-rw-r--r--src/go/plugins/postgres/handler_cache_test.go67
-rw-r--r--src/go/plugins/postgres/handler_connections.go65
-rw-r--r--src/go/plugins/postgres/handler_connections_test.go67
-rw-r--r--src/go/plugins/postgres/handler_custom_query.go102
-rw-r--r--src/go/plugins/postgres/handler_database_age.go55
-rw-r--r--src/go/plugins/postgres/handler_database_age_test.go66
-rw-r--r--src/go/plugins/postgres/handler_database_size.go55
-rw-r--r--src/go/plugins/postgres/handler_database_size_test.go67
-rw-r--r--src/go/plugins/postgres/handler_databases_bloating.go55
-rw-r--r--src/go/plugins/postgres/handler_databases_bloating_test.go67
-rw-r--r--src/go/plugins/postgres/handler_databases_discovery.go55
-rw-r--r--src/go/plugins/postgres/handler_databases_discovery_test.go71
-rw-r--r--src/go/plugins/postgres/handler_dbstat.go117
-rw-r--r--src/go/plugins/postgres/handler_dbstat_test.go72
-rw-r--r--src/go/plugins/postgres/handler_locks.go97
-rw-r--r--src/go/plugins/postgres/handler_locks_test.go74
-rw-r--r--src/go/plugins/postgres/handler_oldest_xid.go53
-rw-r--r--src/go/plugins/postgres/handler_oldest_xid_test.go71
-rw-r--r--src/go/plugins/postgres/handler_ping.go49
-rwxr-xr-xsrc/go/plugins/postgres/handler_ping_test.go73
-rw-r--r--src/go/plugins/postgres/handler_queries.go237
-rw-r--r--src/go/plugins/postgres/handler_queries_test.go72
-rw-r--r--src/go/plugins/postgres/handler_replication.go168
-rw-r--r--src/go/plugins/postgres/handler_replication_process_name_discovery.go55
-rw-r--r--src/go/plugins/postgres/handler_replication_test.go106
-rw-r--r--src/go/plugins/postgres/handler_uptime.go54
-rw-r--r--src/go/plugins/postgres/handler_uptime_test.go66
-rw-r--r--src/go/plugins/postgres/handler_wal.go65
-rw-r--r--src/go/plugins/postgres/handler_wal_test.go66
-rw-r--r--src/go/plugins/postgres/metrics.go291
-rwxr-xr-xsrc/go/plugins/postgres/postgres.go125
-rwxr-xr-xsrc/go/plugins/postgres/postgres_test.go145
-rw-r--r--src/go/plugins/postgres/testpool.go91
-rw-r--r--src/libs/Makefile.am6
-rw-r--r--src/libs/zbxcommon/misc.c2
-rw-r--r--src/libs/zbxconf/cfg.c3
-rw-r--r--src/libs/zbxdb/db.c61
-rw-r--r--src/libs/zbxdbcache/Makefile.am1
-rw-r--r--src/libs/zbxdbcache/dbcache.c162
-rw-r--r--src/libs/zbxdbcache/dbconfig.c3
-rw-r--r--src/libs/zbxdbcache/lld_macro.c (renamed from src/libs/zbxdbhigh/lld_macro.c)0
-rw-r--r--src/libs/zbxdbhigh/Makefile.am11
-rw-r--r--src/libs/zbxdbhigh/db.c101
-rw-r--r--src/libs/zbxdbhigh/proxy.c3321
-rw-r--r--src/libs/zbxdbhigh/trigger.c162
-rw-r--r--src/libs/zbxdbwrap/Makefile.am20
-rw-r--r--src/libs/zbxdbwrap/event.c (renamed from src/libs/zbxdbhigh/event.c)2
-rw-r--r--src/libs/zbxdbwrap/graph_linking.c (renamed from src/libs/zbxdbhigh/graph_linking.c)0
-rw-r--r--src/libs/zbxdbwrap/graph_linking.h (renamed from src/libs/zbxdbhigh/graph_linking.h)0
-rw-r--r--src/libs/zbxdbwrap/host.c (renamed from src/libs/zbxdbhigh/host.c)10
-rw-r--r--src/libs/zbxdbwrap/proxy.c3334
-rw-r--r--src/libs/zbxdbwrap/template.h (renamed from src/libs/zbxdbhigh/template.h)0
-rw-r--r--src/libs/zbxdbwrap/template_item.c (renamed from src/libs/zbxdbhigh/template_item.c)0
-rw-r--r--src/libs/zbxdbwrap/trigger_dep_linking.c (renamed from src/libs/zbxdbhigh/trigger_dep_linking.c)2
-rw-r--r--src/libs/zbxdbwrap/trigger_dep_linking.h (renamed from src/libs/zbxdbhigh/trigger_dep_linking.h)0
-rw-r--r--src/libs/zbxdbwrap/trigger_linking.c (renamed from src/libs/zbxdbhigh/trigger_linking.c)2
-rw-r--r--src/libs/zbxdbwrap/trigger_linking.h (renamed from src/libs/zbxdbhigh/trigger_linking.h)0
-rw-r--r--src/libs/zbxnix/dshm.c2
-rw-r--r--src/libs/zbxnum/num.c2
-rw-r--r--src/libs/zbxrtc/rtc_client.c10
-rw-r--r--src/libs/zbxself/selfmon.c76
-rw-r--r--src/libs/zbxsysinfo/agent/agent.c32
-rw-r--r--src/libs/zbxsysinfo/agent/modbus.c2
-rw-r--r--src/libs/zbxsysinfo/aix/aix.c51
-rw-r--r--src/libs/zbxsysinfo/aix/cpu.c11
-rw-r--r--src/libs/zbxsysinfo/aix/diskio.c21
-rw-r--r--src/libs/zbxsysinfo/aix/diskspace.c34
-rw-r--r--src/libs/zbxsysinfo/aix/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/aix/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/aix/memory.c35
-rw-r--r--src/libs/zbxsysinfo/aix/net.c11
-rw-r--r--src/libs/zbxsysinfo/aix/proc.c4
-rw-r--r--src/libs/zbxsysinfo/aix/software.c3
-rw-r--r--src/libs/zbxsysinfo/aix/swap.c3
-rw-r--r--src/libs/zbxsysinfo/aix/system.c3
-rw-r--r--src/libs/zbxsysinfo/aix/uptime.c3
-rw-r--r--src/libs/zbxsysinfo/aix/vmstats.c3
-rw-r--r--src/libs/zbxsysinfo/common/cpu.c2
-rw-r--r--src/libs/zbxsysinfo/common/cpu.h2
-rw-r--r--src/libs/zbxsysinfo/common/dir.c28
-rw-r--r--src/libs/zbxsysinfo/common/dir.h6
-rw-r--r--src/libs/zbxsysinfo/common/dns.c4
-rw-r--r--src/libs/zbxsysinfo/common/dns.h4
-rw-r--r--src/libs/zbxsysinfo/common/file.c36
-rw-r--r--src/libs/zbxsysinfo/common/file.h22
-rw-r--r--src/libs/zbxsysinfo/common/http.c6
-rw-r--r--src/libs/zbxsysinfo/common/http.h6
-rw-r--r--src/libs/zbxsysinfo/common/http_metrics.c6
-rw-r--r--src/libs/zbxsysinfo/common/net.c3
-rw-r--r--src/libs/zbxsysinfo/common/net.h2
-rw-r--r--src/libs/zbxsysinfo/common/system.c17
-rw-r--r--src/libs/zbxsysinfo/common/system.h4
-rw-r--r--src/libs/zbxsysinfo/common/zabbix_stats.c2
-rw-r--r--src/libs/zbxsysinfo/common/zabbix_stats.h2
-rw-r--r--src/libs/zbxsysinfo/common/zbxsysinfo_common.c108
-rw-r--r--src/libs/zbxsysinfo/common/zbxsysinfo_common.h8
-rw-r--r--src/libs/zbxsysinfo/freebsd/boottime.c3
-rw-r--r--src/libs/zbxsysinfo/freebsd/cpu.c11
-rw-r--r--src/libs/zbxsysinfo/freebsd/diskio.c5
-rw-r--r--src/libs/zbxsysinfo/freebsd/diskspace.c34
-rw-r--r--src/libs/zbxsysinfo/freebsd/freebsd.c61
-rw-r--r--src/libs/zbxsysinfo/freebsd/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/freebsd/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/freebsd/kernel.c5
-rw-r--r--src/libs/zbxsysinfo/freebsd/memory.c51
-rw-r--r--src/libs/zbxsysinfo/freebsd/net.c19
-rw-r--r--src/libs/zbxsysinfo/freebsd/proc.c6
-rw-r--r--src/libs/zbxsysinfo/freebsd/software.c3
-rw-r--r--src/libs/zbxsysinfo/freebsd/swap.c3
-rw-r--r--src/libs/zbxsysinfo/freebsd/system.c3
-rw-r--r--src/libs/zbxsysinfo/freebsd/uptime.c3
-rw-r--r--src/libs/zbxsysinfo/hpux/cpu.c7
-rw-r--r--src/libs/zbxsysinfo/hpux/diskspace.c34
-rw-r--r--src/libs/zbxsysinfo/hpux/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/hpux/hpux.c33
-rw-r--r--src/libs/zbxsysinfo/hpux/inodes.c8
-rw-r--r--src/libs/zbxsysinfo/hpux/memory.c31
-rw-r--r--src/libs/zbxsysinfo/hpux/net.c9
-rw-r--r--src/libs/zbxsysinfo/hpux/proc.c2
-rw-r--r--src/libs/zbxsysinfo/hpux/software.c3
-rw-r--r--src/libs/zbxsysinfo/hpux/system.c3
-rw-r--r--src/libs/zbxsysinfo/linux/boottime.c3
-rw-r--r--src/libs/zbxsysinfo/linux/cpu.c11
-rw-r--r--src/libs/zbxsysinfo/linux/diskio.c7
-rw-r--r--src/libs/zbxsysinfo/linux/diskspace.c14
-rw-r--r--src/libs/zbxsysinfo/linux/hardware.c15
-rw-r--r--src/libs/zbxsysinfo/linux/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/linux/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/linux/kernel.c7
-rw-r--r--src/libs/zbxsysinfo/linux/linux.c89
-rw-r--r--src/libs/zbxsysinfo/linux/memory.c50
-rw-r--r--src/libs/zbxsysinfo/linux/net.c19
-rw-r--r--src/libs/zbxsysinfo/linux/proc.c8
-rw-r--r--src/libs/zbxsysinfo/linux/sensors.c2
-rw-r--r--src/libs/zbxsysinfo/linux/software.c9
-rw-r--r--src/libs/zbxsysinfo/linux/swap.c7
-rw-r--r--src/libs/zbxsysinfo/linux/system.c3
-rw-r--r--src/libs/zbxsysinfo/linux/uptime.c3
-rw-r--r--src/libs/zbxsysinfo/netbsd/boottime.c3
-rw-r--r--src/libs/zbxsysinfo/netbsd/cpu.c11
-rw-r--r--src/libs/zbxsysinfo/netbsd/diskspace.c34
-rw-r--r--src/libs/zbxsysinfo/netbsd/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/netbsd/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/netbsd/kernel.c5
-rw-r--r--src/libs/zbxsysinfo/netbsd/memory.c51
-rw-r--r--src/libs/zbxsysinfo/netbsd/net.c11
-rw-r--r--src/libs/zbxsysinfo/netbsd/netbsd.c65
-rw-r--r--src/libs/zbxsysinfo/netbsd/proc.c6
-rw-r--r--src/libs/zbxsysinfo/netbsd/software.c3
-rw-r--r--src/libs/zbxsysinfo/netbsd/system.c3
-rw-r--r--src/libs/zbxsysinfo/netbsd/uptime.c3
-rw-r--r--src/libs/zbxsysinfo/openbsd/boottime.c3
-rw-r--r--src/libs/zbxsysinfo/openbsd/cpu.c11
-rw-r--r--src/libs/zbxsysinfo/openbsd/diskio.c21
-rw-r--r--src/libs/zbxsysinfo/openbsd/diskspace.c34
-rw-r--r--src/libs/zbxsysinfo/openbsd/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/openbsd/inodes.c7
-rw-r--r--src/libs/zbxsysinfo/openbsd/kernel.c5
-rw-r--r--src/libs/zbxsysinfo/openbsd/memory.c51
-rw-r--r--src/libs/zbxsysinfo/openbsd/net.c11
-rw-r--r--src/libs/zbxsysinfo/openbsd/openbsd.c63
-rw-r--r--src/libs/zbxsysinfo/openbsd/proc.c6
-rw-r--r--src/libs/zbxsysinfo/openbsd/sensors.c4
-rw-r--r--src/libs/zbxsysinfo/openbsd/software.c3
-rw-r--r--src/libs/zbxsysinfo/openbsd/swap.c27
-rw-r--r--src/libs/zbxsysinfo/openbsd/system.c3
-rw-r--r--src/libs/zbxsysinfo/openbsd/uptime.c3
-rw-r--r--src/libs/zbxsysinfo/osf/cpu.c19
-rw-r--r--src/libs/zbxsysinfo/osf/diskspace.c26
-rw-r--r--src/libs/zbxsysinfo/osf/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/osf/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/osf/kernel.c5
-rw-r--r--src/libs/zbxsysinfo/osf/memory.c45
-rw-r--r--src/libs/zbxsysinfo/osf/osf.c29
-rw-r--r--src/libs/zbxsysinfo/osf/proc.c4
-rw-r--r--src/libs/zbxsysinfo/osf/software.c3
-rw-r--r--src/libs/zbxsysinfo/osf/swap.c31
-rw-r--r--src/libs/zbxsysinfo/osf/system.c3
-rw-r--r--src/libs/zbxsysinfo/osf/uptime.c3
-rw-r--r--src/libs/zbxsysinfo/osx/boottime.c3
-rw-r--r--src/libs/zbxsysinfo/osx/cpu.c5
-rw-r--r--src/libs/zbxsysinfo/osx/diskspace.c34
-rw-r--r--src/libs/zbxsysinfo/osx/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/osx/inodes.c9
-rw-r--r--src/libs/zbxsysinfo/osx/kernel.c5
-rw-r--r--src/libs/zbxsysinfo/osx/memory.c39
-rw-r--r--src/libs/zbxsysinfo/osx/net.c19
-rw-r--r--src/libs/zbxsysinfo/osx/osx.c41
-rw-r--r--src/libs/zbxsysinfo/osx/software.c3
-rw-r--r--src/libs/zbxsysinfo/osx/system.c3
-rw-r--r--src/libs/zbxsysinfo/osx/uptime.c3
-rw-r--r--src/libs/zbxsysinfo/simple/simple.c21
-rw-r--r--src/libs/zbxsysinfo/simple/simple.h6
-rw-r--r--src/libs/zbxsysinfo/solaris/boottime.c3
-rw-r--r--src/libs/zbxsysinfo/solaris/cpu.c11
-rw-r--r--src/libs/zbxsysinfo/solaris/diskio.c20
-rw-r--r--src/libs/zbxsysinfo/solaris/diskspace.c34
-rw-r--r--src/libs/zbxsysinfo/solaris/hostname.c4
-rw-r--r--src/libs/zbxsysinfo/solaris/inodes.c9
-rw-r--r--src/libs/zbxsysinfo/solaris/kernel.c3
-rw-r--r--src/libs/zbxsysinfo/solaris/memory.c35
-rw-r--r--src/libs/zbxsysinfo/solaris/net.c55
-rw-r--r--src/libs/zbxsysinfo/solaris/proc.c6
-rw-r--r--src/libs/zbxsysinfo/solaris/software.c3
-rw-r--r--src/libs/zbxsysinfo/solaris/solaris.c63
-rw-r--r--src/libs/zbxsysinfo/solaris/swap.c27
-rw-r--r--src/libs/zbxsysinfo/solaris/system.c3
-rw-r--r--src/libs/zbxsysinfo/solaris/uptime.c5
-rw-r--r--src/libs/zbxsysinfo/sysinfo.c2
-rw-r--r--src/libs/zbxsysinfo/sysinfo.h73
-rw-r--r--src/libs/zbxsysinfo/unknown/hostname.c5
-rw-r--r--src/libs/zbxsysinfo/win32/cpu.c7
-rw-r--r--src/libs/zbxsysinfo/win32/diskspace.c14
-rw-r--r--src/libs/zbxsysinfo/win32/hostname.c5
-rw-r--r--src/libs/zbxsysinfo/win32/memory.c3
-rw-r--r--src/libs/zbxsysinfo/win32/net.c13
-rw-r--r--src/libs/zbxsysinfo/win32/pdhmon.c13
-rw-r--r--src/libs/zbxsysinfo/win32/proc.c11
-rw-r--r--src/libs/zbxsysinfo/win32/registry.c6
-rw-r--r--src/libs/zbxsysinfo/win32/services.c23
-rw-r--r--src/libs/zbxsysinfo/win32/software.c3
-rw-r--r--src/libs/zbxsysinfo/win32/swap.c5
-rw-r--r--src/libs/zbxsysinfo/win32/system.c5
-rw-r--r--src/libs/zbxsysinfo/win32/uptime.c11
-rw-r--r--src/libs/zbxsysinfo/win32/win32.c71
-rw-r--r--src/libs/zbxsysinfo/win32/wmi.cpp4
-rw-r--r--src/libs/zbxtime/time.c138
-rw-r--r--src/libs/zbxwin32/disk.c4
-rw-r--r--src/libs/zbxwin32/fatal.c65
-rw-r--r--src/libs/zbxwin32/perfmon.c29
-rw-r--r--src/libs/zbxwinservice/service.c (renamed from src/libs/zbxwin32/service.c)19
-rw-r--r--src/libs/zbxxml/xml.c21
-rw-r--r--src/zabbix_agent/active.c13
-rw-r--r--src/zabbix_agent/active.h1
-rw-r--r--src/zabbix_agent/cpustat.c12
-rw-r--r--src/zabbix_agent/cpustat.h2
-rw-r--r--src/zabbix_agent/listener.c14
-rw-r--r--src/zabbix_agent/listener.h1
-rw-r--r--src/zabbix_agent/perfstat.c10
-rw-r--r--src/zabbix_agent/perfstat.h2
-rw-r--r--src/zabbix_agent/stats.c11
-rw-r--r--src/zabbix_agent/zabbix_agentd.c65
-rw-r--r--src/zabbix_agent/zbxconf.c18
-rw-r--r--src/zabbix_agent/zbxconf.h2
-rw-r--r--src/zabbix_java/src/com/zabbix/gateway/GeneralInformation.java4
-rw-r--r--src/zabbix_proxy/Makefile.am3
-rw-r--r--src/zabbix_proxy/datasender/datasender.c29
-rw-r--r--src/zabbix_proxy/housekeeper/housekeeper.c14
-rw-r--r--src/zabbix_proxy/proxy.c39
-rw-r--r--src/zabbix_proxy/proxyconfig/proxyconfig.c26
-rw-r--r--src/zabbix_proxy/proxyconfigwrite/proxyconfig_write.c2
-rw-r--r--src/zabbix_proxy/rtc/rtc_proxy.c2
-rw-r--r--src/zabbix_proxy/stats/zabbix_stats_proxy.c2
-rw-r--r--src/zabbix_proxy/taskmanager/taskmanager.c16
-rw-r--r--src/zabbix_sender/win32/zabbix_sender.c2
-rw-r--r--src/zabbix_sender/zabbix_sender.c14
-rw-r--r--src/zabbix_server/Makefile.am4
-rw-r--r--src/zabbix_server/actions.c1
-rw-r--r--src/zabbix_server/alerter/alert_manager.c16
-rw-r--r--src/zabbix_server/alerter/alert_syncer.c20
-rw-r--r--src/zabbix_server/alerter/alerter.c18
-rw-r--r--src/zabbix_server/availability/avail_manager.c16
-rw-r--r--src/zabbix_server/dbconfig/dbconfig.c14
-rw-r--r--src/zabbix_server/dbsyncer/dbsyncer.c27
-rw-r--r--src/zabbix_server/discoverer/discoverer.c14
-rw-r--r--src/zabbix_server/escalator/escalator.c27
-rw-r--r--src/zabbix_server/housekeeper/housekeeper.c134
-rw-r--r--src/zabbix_server/housekeeper/housekeeper.h8
-rw-r--r--src/zabbix_server/housekeeper/trigger_housekeeper.c18
-rw-r--r--src/zabbix_server/httppoller/httppoller.c20
-rw-r--r--src/zabbix_server/ipmi/ipmi_manager.c16
-rw-r--r--src/zabbix_server/ipmi/ipmi_poller.c17
-rw-r--r--src/zabbix_server/lld/lld.c2
-rw-r--r--src/zabbix_server/lld/lld.h2
-rw-r--r--src/zabbix_server/lld/lld_graph.c1
-rw-r--r--src/zabbix_server/lld/lld_host.c1
-rw-r--r--src/zabbix_server/lld/lld_item.c1
-rw-r--r--src/zabbix_server/lld/lld_manager.c16
-rw-r--r--src/zabbix_server/lld/lld_trigger.c1
-rw-r--r--src/zabbix_server/lld/lld_worker.c19
-rw-r--r--src/zabbix_server/lld/lld_worker.h4
-rw-r--r--src/zabbix_server/operations.c1
-rw-r--r--src/zabbix_server/pinger/pinger.c18
-rw-r--r--src/zabbix_server/poller/checks_internal.c8
-rw-r--r--src/zabbix_server/poller/checks_simple.c6
-rw-r--r--src/zabbix_server/poller/checks_simple_vmware.c268
-rw-r--r--src/zabbix_server/poller/checks_simple_vmware.h4
-rw-r--r--src/zabbix_server/poller/poller.c14
-rw-r--r--src/zabbix_server/preprocessor/preproc_manager.c16
-rw-r--r--src/zabbix_server/preprocessor/preproc_worker.c98
-rw-r--r--src/zabbix_server/proxyconfigread/proxyconfig_read.c2
-rw-r--r--src/zabbix_server/proxypoller/proxypoller.c15
-rw-r--r--src/zabbix_server/reporter/report_manager.c16
-rw-r--r--src/zabbix_server/reporter/report_writer.c16
-rw-r--r--src/zabbix_server/selfmon/Makefile.am7
-rw-r--r--src/zabbix_server/selfmon/selfmon.c64
-rw-r--r--src/zabbix_server/selfmon/selfmon.h27
-rw-r--r--src/zabbix_server/server.c65
-rw-r--r--src/zabbix_server/service/service_manager.c16
-rw-r--r--src/zabbix_server/snmptrapper/snmptrapper.c18
-rw-r--r--src/zabbix_server/snmptrapper/snmptrapper.h1
-rw-r--r--src/zabbix_server/taskmanager/taskmanager.c14
-rw-r--r--src/zabbix_server/timer/timer.c33
-rw-r--r--src/zabbix_server/trapper/nodecommand.c1
-rw-r--r--src/zabbix_server/trapper/proxydata.c2
-rw-r--r--src/zabbix_server/trapper/trapper.c19
-rw-r--r--src/zabbix_server/vmware/vmware.c1543
-rw-r--r--src/zabbix_server/vmware/vmware.h82
-rw-r--r--src/zabbix_server/vmware/vmware_manager.c28
-rw-r--r--src/zabbix_server/vmware/vmware_rest.c242
335 files changed, 7754 insertions, 10728 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d963c0c0d80..82dbf89fb9f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,7 +67,6 @@ PROXY_SUBDIRS = \
zabbix_server/pinger \
zabbix_server/poller \
zabbix_server/trapper \
- zabbix_server/selfmon \
zabbix_server/snmptrapper \
zabbix_server/vmware \
zabbix_server/ipmi \
diff --git a/src/go/conf/zabbix_agent2.d/plugins.d/postgres.conf b/src/go/conf/zabbix_agent2.d/plugins.d/postgres.conf
deleted file mode 100644
index 6c0be4c6eb3..00000000000
--- a/src/go/conf/zabbix_agent2.d/plugins.d/postgres.conf
+++ /dev/null
@@ -1,96 +0,0 @@
-### Option: Plugins.Postgres.CallTimeout
-# The maximum time in seconds for waiting when a request has to be done.
-#
-# Mandatory: no
-# Range: 1-30
-# Default:
-# Plugins.Postgres.CallTimeout=<Global timeout>
-
-### Option: Plugins.Postgres.Timeout
-# The maximum time in seconds for waiting when a connection has to be established.
-#
-# Mandatory: no
-# Range: 1-30
-# Default:
-# Plugins.Postgres.Timeout=<Global timeout>
-
-### Option: Plugins.Postgres.KeepAlive
-# Time in seconds for waiting before unused connections will be closed.
-#
-# Mandatory: no
-# Range: 60-900
-# Default:
-# Plugins.Postgres.KeepAlive=300
-
-### Option: Plugins.Postgres.CustomQueriesPath
-# Full pathname of a directory containing *.sql* files with custom queries.
-#
-# Mandatory: no
-# Default:
-# Plugins.Postgres.CustomQueriesPath=
-
-### Option: Plugins.Postgres.Sessions.*.Uri
-# Uri to connect. "*" should be replaced with a session name.
-#
-# Mandatory: no
-# Range:
-# Must matches the URI format.
-# Supported schemas: "tcp" and "unix".
-# Embedded credentials will be ignored.
-# Default:
-# Plugins.Postgres.Sessions.*.Uri=
-
-### Option: Plugins.Postgres.Sessions.*.User
-# Username for session connection. "*" should be replaced with a session name.
-#
-# Mandatory: no
-# Range: Must matches PostgreSQL user name.
-# Default:
-# Plugins.Postgres.Sessions.*.User=
-
-### Option: Plugins.Postgres.Sessions.*.Password
-# Password for session connection. "*" should be replaced with a session name.
-#
-# Mandatory: no
-# Range: Must matches the Password format.
-# Default:
-# Plugins.Postgres.Sessions.*.Password=
-
-### Option: Plugins.Postgres.Sessions.*.Database
-# Database for session connection. "*" should be replaced with a session name.
-#
-# Mandatory: no
-# Default:
-# Plugins.Postgres.Sessions.*.Database=
-
-### Option: Plugins.Postgres.Sessions.*.TLSConnect
-# Encryption type for Postgres connection. "*" should be replaced with a session name.
-# tls connection required - required
-# verifies certificates - verify_ca
-# verify certificates and ip - verify_full
-#
-# Mandatory: no
-# Default:
-# Plugins.Postgres.Sessions.*.TLSConnect=
-
-### Option: Plugins.Postgres.Sessions.*.TLSCAFile
-# Full pathname of a file containing the top-level CA(s) certificate
-# peer certificate verification.
-#
-# Mandatory: no
-# Default:
-# Plugins.Postgres.Sessions.*.TLSCAFile=
-
-### Option: Plugins.Postgres.Sessions.*.TLSCertFile
-# Full pathname of a file containing the postgres certificate or certificate chain.
-#
-# Mandatory: no
-# Default:
-# Plugins.Postgres.Sessions.*.TLSCertFile=
-
-### Option: Plugins.Postgres.Sessions.*.TLSKeyFile
-# Full pathname of a file containing the postgres private key.
-#
-# Mandatory: no
-# Default:
-# Plugins.Postgres.Sessions.*.TLSKeyFile=
diff --git a/src/go/go.mod b/src/go/go.mod
index e1592e57866..184dfa1a672 100644
--- a/src/go/go.mod
+++ b/src/go/go.mod
@@ -3,7 +3,7 @@ module zabbix.com
go 1.18
require (
- git.zabbix.com/ap/plugin-support v1.1.0
+ git.zabbix.com/ap/plugin-support v1.1.1-0.20221021133846-49ba2b4b6cb5
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5
github.com/chromedp/cdproto v0.0.0-20220827030233-358ed4af73cf
@@ -17,7 +17,6 @@ require (
github.com/goburrow/modbus v0.1.0
github.com/godbus/dbus v4.1.0+incompatible
github.com/godror/godror v0.34.0
- github.com/jackc/pgx/v4 v4.17.2
github.com/mattn/go-sqlite3 v1.14.15
github.com/mediocregopher/radix/v3 v3.8.1
github.com/memcachier/mc/v3 v3.0.3
@@ -37,22 +36,11 @@ require (
github.com/gobwas/ws v1.1.0 // indirect
github.com/godror/knownpb v0.1.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
- github.com/jackc/chunkreader/v2 v2.0.1 // indirect
- github.com/jackc/pgconn v1.13.0 // indirect
- github.com/jackc/pgio v1.0.0 // indirect
- github.com/jackc/pgpassfile v1.0.0 // indirect
- github.com/jackc/pgproto3/v2 v2.3.1 // indirect
- github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
- github.com/jackc/pgtype v1.12.0 // indirect
- github.com/jackc/puddle v1.3.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
- github.com/pkg/errors v0.9.1 // indirect
- golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
- golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
diff --git a/src/go/go.sum b/src/go/go.sum
index e204247a5fe..c7e752c442f 100644
--- a/src/go/go.sum
+++ b/src/go/go.sum
@@ -1,10 +1,7 @@
-git.zabbix.com/ap/plugin-support v1.1.0 h1:t2a2ijsup3KSm0fXkPr9mnQw9xPskZ0PzWnQwGVjxzw=
-git.zabbix.com/ap/plugin-support v1.1.0/go.mod h1:R3QzQWgpxlA+ddJNkOhsPTcGOVtrR69WS0hXIsnBurY=
+git.zabbix.com/ap/plugin-support v1.1.1-0.20221021133846-49ba2b4b6cb5 h1:2r/hEHm1xE7tcnP1jPKY0aEimj/Y64RZijaWigJSSFw=
+git.zabbix.com/ap/plugin-support v1.1.1-0.20221021133846-49ba2b4b6cb5/go.mod h1:R3QzQWgpxlA+ddJNkOhsPTcGOVtrR69WS0hXIsnBurY=
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69 h1:+tu3HOoMXB7RXEINRVIpxJCT+KdYiI7LAEAUrOw3dIU=
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69/go.mod h1:L1AbZdiDllfyYH5l5OkAaZtk7VkWe89bPJFmnDBNHxg=
-github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
-github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
-github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 h1:BjkPE3785EwPhhyuFkbINB+2a1xATwk8SNDWnJiD41g=
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5/go.mod h1:jtAfVaU/2cu1+wdSRPWE2c1N2qeAA3K4RH9pYgqwets=
github.com/chromedp/cdproto v0.0.0-20220827030233-358ed4af73cf h1:e0oJZmGJidTRZ0FvWXNhdj9OaOMN30Yf+T3K2Tf3L+s=
@@ -13,12 +10,6 @@ github.com/chromedp/chromedp v0.8.5 h1:HAVg54yQFcn7sg5reVjXtoI1eQaFxhjAjflHACicU
github.com/chromedp/chromedp v0.8.5/go.mod h1:xal2XY5Di7m/bzlGwtoYpmgIOfDqCakOIVg5OfdkPZ4=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
-github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
-github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
-github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
-github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
-github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/gomemcached v0.0.0-20160817010731-a2284a01c143 h1:K9CFK8HRZWzmoIWbpA7u0XYLggCyfa/N77eVaq/nUiA=
@@ -27,10 +18,8 @@ github.com/eclipse/paho.mqtt.golang v1.4.1 h1:tUSpviiL5G3P9SZZJPC4ZULZJsxQKXxfEN
github.com/eclipse/paho.mqtt.golang v1.4.1/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
-github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-ldap/ldap v3.0.3+incompatible h1:HTeSZO8hWMS1Rgb2Ziku6b8a7qRIZZMHjsvuZyatzwk=
github.com/go-ldap/ldap v3.0.3+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc=
-github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
@@ -39,7 +28,6 @@ github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
-github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/goburrow/modbus v0.1.0 h1:DejRZY73nEM6+bt5JSP6IsFolJ9dVcqxsYbpLbeW/ro=
github.com/goburrow/modbus v0.1.0/go.mod h1:Kx552D5rLIS8E7TyUwQ/UdHEqvX5T8tyiGBTlzMcZBg=
github.com/goburrow/serial v0.1.0 h1:v2T1SQa/dlUqQiYIT8+Cu7YolfqAi3K96UmhwYyuSrA=
@@ -56,84 +44,16 @@ github.com/godror/godror v0.34.0 h1:/D40cxuWY3PtMa1oIcfXqqInlts5anEL3vj6IkTW8Q8=
github.com/godror/godror v0.34.0/go.mod h1:9QtjJWw+r1v9zh93Qx+hSOfYRVgj11a/7TUnU/00Wbc=
github.com/godror/knownpb v0.1.0 h1:dJPK8s/I3PQzGGaGcUStL2zIaaICNzKKAK8BzP1uLio=
github.com/godror/knownpb v0.1.0/go.mod h1:4nRFbQo1dDuwKnblRXDxrfCFYeT4hjg3GjMqef58eRE=
-github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
-github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
-github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
-github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
-github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
-github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
-github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
-github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA=
-github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE=
-github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s=
-github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
-github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
-github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
-github.com/jackc/pgconn v1.13.0 h1:3L1XMNV2Zvca/8BYhzcRFS70Lr0WlDg16Di6SFGAbys=
-github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI=
-github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
-github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
-github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
-github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c=
-github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc=
-github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
-github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
-github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
-github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
-github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
-github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
-github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
-github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
-github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
-github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
-github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y=
-github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
-github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
-github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
-github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
-github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
-github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
-github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM=
-github.com/jackc/pgtype v1.12.0 h1:Dlq8Qvcch7kiehm8wPGIW0W3KsCCHJnRacKW0UM8n5w=
-github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
-github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
-github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
-github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
-github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
-github.com/jackc/pgx/v4 v4.17.2 h1:0Ut0rpeKwvIVbMQ1KbMBU4h6wxehBI535LK6Flheh8E=
-github.com/jackc/pgx/v4 v4.17.2/go.mod h1:lcxIZN44yMIrWI78a5CpucdD14hX0SBDbNRvjDBItsw=
-github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
-github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
-github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
-github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
-github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
-github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
-github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
-github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
-github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
-github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
-github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
-github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
-github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
-github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
-github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
-github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
-github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
-github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
-github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
-github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
-github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
-github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mediocregopher/radix/v3 v3.8.1 h1:rOkHflVuulFKlwsLY01/M2cM2tWCjDoETcMqKbAWu1M=
@@ -148,68 +68,18 @@ github.com/oklog/ulid/v2 v2.0.2 h1:r4fFzBm+bv0wNKNh5eXTwU7i85y5x+uwkxCUTNVQqLc=
github.com/omeid/go-yarn v0.0.1 h1:mUQExNwUrYn7tZRwQdsUuoQWHIujtjjpjb/PAtUj9dk=
github.com/omeid/go-yarn v0.0.1/go.mod h1:JYxmAvShSw7YmX/9vFsccpJE4o/KW111eUh3n/TQ5h8=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
-github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
-github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
-github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
-github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
-github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
-github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
-github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
-github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
-github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
-github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
-github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
-github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
-github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
-github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
-github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
-github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
-go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
-go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
-go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
-go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
-go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
-go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
-go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
-go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
-go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
-go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
-go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
-golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
-golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
-golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
-golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
-golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
-golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
-golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
@@ -218,50 +88,27 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
-golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
-golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
-golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
-golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 h1:BonxutuHCTL0rBDnZlKjpGIQFTjyUVTexFOdWkB6Fg0=
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
-golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -272,13 +119,4 @@ google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+Rur
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d h1:TxyelI5cVkbREznMhfzycHdkp5cLA7DpE+GKjSslYhM=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
-gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
-gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
diff --git a/src/go/pkg/tlsconfig/tlsconfig.go b/src/go/pkg/tlsconfig/tlsconfig.go
deleted file mode 100644
index 492a920bb4c..00000000000
--- a/src/go/pkg/tlsconfig/tlsconfig.go
+++ /dev/null
@@ -1,102 +0,0 @@
-package tlsconfig
-
-import (
- "crypto/tls"
- "crypto/x509"
- "errors"
- "fmt"
- "io/ioutil"
-
- "git.zabbix.com/ap/plugin-support/uri"
-)
-
-type Details struct {
- SessionName string
- TlsConnect string
- TlsCaFile string
- TlsCertFile string
- TlsKeyFile string
- RawUri string
-}
-
-func CreateConfig(details Details, skipVerify bool) (*tls.Config, error) {
- rootCertPool := x509.NewCertPool()
- pem, err := ioutil.ReadFile(details.TlsCaFile)
- if err != nil {
- return nil, err
- }
-
- if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
- return nil, errors.New("Failed to append PEM.")
- }
-
- clientCerts := make([]tls.Certificate, 0, 1)
- certs, err := tls.LoadX509KeyPair(details.TlsCertFile, details.TlsKeyFile)
- if err != nil {
- return nil, err
- }
-
- clientCerts = append(clientCerts, certs)
-
- if skipVerify {
- return &tls.Config{RootCAs: rootCertPool, Certificates: clientCerts, InsecureSkipVerify: skipVerify}, nil
- }
-
- url, err := uri.New(details.RawUri, nil)
- if err != nil {
- return nil, err
- }
-
- return &tls.Config{
- RootCAs: rootCertPool, Certificates: clientCerts, InsecureSkipVerify: skipVerify, ServerName: url.Host(),
- }, nil
-}
-
-func CreateDetails(session, dbConnect, caFile, certFile, keyFile, uri string) (Details, error) {
- if dbConnect != "" && dbConnect != "required" {
- if err := validateSetTLSFiles(caFile, certFile, keyFile); err != nil {
- return Details{}, fmt.Errorf("%s uri %s, with session %s", err.Error(), uri, session)
- }
- } else {
- if err := validateUnsetTLSFiles(caFile, certFile, keyFile); err != nil {
- return Details{}, fmt.Errorf("%s uri %s, with session %s", err.Error(), uri, session)
- }
- }
-
- return Details{session, dbConnect, caFile, certFile, keyFile, uri}, nil
-}
-
-func validateSetTLSFiles(caFile, certFile, keyFile string) error {
- if caFile == "" {
- return errors.New("missing TLS CA file for database")
- }
-
- if certFile == "" {
- return errors.New("missing TLS certificate file for database")
- }
-
- if keyFile == "" {
- return errors.New("missing TLS key file for database")
- }
-
- return nil
-}
-
-func validateUnsetTLSFiles(caFile, certFile, keyFile string) error {
- if caFile != "" {
- return errors.New(
- "TLS CA file configuration parameter set without certificates being used for database")
- }
-
- if certFile != "" {
- return errors.New(
- "TLS certificate file configuration parameter set without certificates being used for database")
- }
-
- if keyFile != "" {
- return errors.New(
- "TLS key file configuration parameter set without certificates being used for database")
- }
-
- return nil
-}
diff --git a/src/go/pkg/version/version.go b/src/go/pkg/version/version.go
index 67eb292ae04..faa436d3db6 100644
--- a/src/go/pkg/version/version.go
+++ b/src/go/pkg/version/version.go
@@ -26,11 +26,11 @@ import (
)
const (
- ZABBIX_REVDATE = "29 September 2022"
+ ZABBIX_REVDATE = "27 October 2022"
ZABBIX_VERSION_MAJOR = 6
ZABBIX_VERSION_MINOR = 4
ZABBIX_VERSION_PATCH = 0
- ZABBIX_VERSION_RC = "beta2"
+ ZABBIX_VERSION_RC = "beta3"
ZABBIX_VERSION_RC_NUM = "{ZABBIX_RC_NUM}"
ZABBIX_VERSION_REVISION = "{ZABBIX_REVISION}"
copyrightMessage = "Copyright (C) 2022 Zabbix SIA\n" +
diff --git a/src/go/pkg/zbxlib/checks_darwin.go b/src/go/pkg/zbxlib/checks_darwin.go
index c6f95593f1f..a3c00f1b4ab 100644
--- a/src/go/pkg/zbxlib/checks_darwin.go
+++ b/src/go/pkg/zbxlib/checks_darwin.go
@@ -29,21 +29,21 @@ package zbxlib
#include "zbxsysinfo.h"
-int SYSTEM_LOCALTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_TCP_PORT(AGENT_REQUEST *request, AGENT_RESULT *result);
-int CHECK_SERVICE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int CHECK_SERVICE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_USERS_NUM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_DIR_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_localtime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_tcp_port(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service_perf(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_users_num(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dir_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result);
*/
import "C"
@@ -55,29 +55,29 @@ import (
func resolveMetric(key string) (cfunc unsafe.Pointer) {
switch key {
case "system.localtime":
- return unsafe.Pointer(C.SYSTEM_LOCALTIME)
+ return unsafe.Pointer(C.system_localtime)
case "system.boottime":
- return unsafe.Pointer(C.SYSTEM_BOOTTIME)
+ return unsafe.Pointer(C.system_boottime)
case "net.tcp.listen":
- return unsafe.Pointer(C.NET_TCP_LISTEN)
+ return unsafe.Pointer(C.net_tcp_listen)
case "net.tcp.port":
- return unsafe.Pointer(C.NET_TCP_PORT)
+ return unsafe.Pointer(C.net_tcp_port)
case "net.udp.listen":
- return unsafe.Pointer(C.NET_UDP_LISTEN)
+ return unsafe.Pointer(C.net_udp_listen)
case "system.cpu.load":
- return unsafe.Pointer(C.SYSTEM_CPU_LOAD)
+ return unsafe.Pointer(C.system_cpu_load)
case "vfs.dir.get":
- return unsafe.Pointer(C.VFS_DIR_GET)
+ return unsafe.Pointer(C.vfs_dir_get)
case "vfs.fs.discovery":
- return unsafe.Pointer(C.VFS_FS_DISCOVERY)
+ return unsafe.Pointer(C.vfs_fs_discovery)
case "vfs.fs.inode":
- return unsafe.Pointer(C.VFS_FS_INODE)
+ return unsafe.Pointer(C.vfs_fs_inode)
case "vfs.fs.size":
- return unsafe.Pointer(C.VFS_FS_SIZE)
+ return unsafe.Pointer(C.vfs_fs_size)
case "vfs.fs.get":
- return unsafe.Pointer(C.VFS_FS_GET)
+ return unsafe.Pointer(C.vfs_fs_get)
case "vm.memory.size":
- return unsafe.Pointer(C.VM_MEMORY_SIZE)
+ return unsafe.Pointer(C.vm_memory_size)
default:
return
diff --git a/src/go/pkg/zbxlib/checks_linux.go b/src/go/pkg/zbxlib/checks_linux.go
index e86fd1234d1..57ec46cb0ec 100644
--- a/src/go/pkg/zbxlib/checks_linux.go
+++ b/src/go/pkg/zbxlib/checks_linux.go
@@ -27,32 +27,32 @@ package zbxlib
#include "zbxsysinfo.h"
#include "module.h"
-int SYSTEM_LOCALTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int CHECK_SERVICE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int CHECK_SERVICE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_HW_CPU(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_HW_MACADDR(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SW_OS(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SW_PACKAGES(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SWAP_OUT(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_USERS_NUM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_DIR_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_localtime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result);
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service_perf(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int get_sensor(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_cpu(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_macaddr(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_sw_os(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_sw_packages(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_in(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_out(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_users_num(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dir_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result);
*/
import "C"
@@ -63,33 +63,33 @@ import (
func resolveMetric(key string) (cfunc unsafe.Pointer) {
switch key {
case "system.localtime":
- cfunc = unsafe.Pointer(C.SYSTEM_LOCALTIME)
+ cfunc = unsafe.Pointer(C.system_localtime)
case "system.boottime":
- cfunc = unsafe.Pointer(C.SYSTEM_BOOTTIME)
+ cfunc = unsafe.Pointer(C.system_boottime)
case "net.tcp.listen":
- cfunc = unsafe.Pointer(C.NET_TCP_LISTEN)
+ cfunc = unsafe.Pointer(C.net_tcp_listen)
case "net.udp.listen":
- cfunc = unsafe.Pointer(C.NET_UDP_LISTEN)
+ cfunc = unsafe.Pointer(C.net_udp_listen)
case "sensor":
- cfunc = unsafe.Pointer(C.GET_SENSOR)
+ cfunc = unsafe.Pointer(C.get_sensor)
case "system.cpu.load":
- cfunc = unsafe.Pointer(C.SYSTEM_CPU_LOAD)
+ cfunc = unsafe.Pointer(C.system_cpu_load)
case "system.cpu.switches":
- cfunc = unsafe.Pointer(C.SYSTEM_CPU_SWITCHES)
+ cfunc = unsafe.Pointer(C.system_cpu_switches)
case "system.cpu.intr":
- cfunc = unsafe.Pointer(C.SYSTEM_CPU_INTR)
+ cfunc = unsafe.Pointer(C.system_cpu_intr)
case "system.hw.cpu":
- cfunc = unsafe.Pointer(C.SYSTEM_HW_CPU)
+ cfunc = unsafe.Pointer(C.system_hw_cpu)
case "system.hw.macaddr":
- cfunc = unsafe.Pointer(C.SYSTEM_HW_MACADDR)
+ cfunc = unsafe.Pointer(C.system_hw_macaddr)
case "system.sw.os":
- cfunc = unsafe.Pointer(C.SYSTEM_SW_OS)
+ cfunc = unsafe.Pointer(C.system_sw_os)
case "system.swap.in":
- cfunc = unsafe.Pointer(C.SYSTEM_SWAP_IN)
+ cfunc = unsafe.Pointer(C.system_swap_in)
case "system.swap.out":
- cfunc = unsafe.Pointer(C.SYSTEM_SWAP_OUT)
+ cfunc = unsafe.Pointer(C.system_swap_out)
case "vfs.dir.get":
- cfunc = unsafe.Pointer(C.VFS_DIR_GET)
+ cfunc = unsafe.Pointer(C.vfs_dir_get)
}
return
}
diff --git a/src/go/pkg/zbxlib/checks_windows.go b/src/go/pkg/zbxlib/checks_windows.go
index 7c1f930f884..0343b370285 100644
--- a/src/go/pkg/zbxlib/checks_windows.go
+++ b/src/go/pkg/zbxlib/checks_windows.go
@@ -27,30 +27,30 @@ package zbxlib
#include "zbxsysinfo.h"
#include "module.h"
-int SYSTEM_LOCALTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int CHECK_SERVICE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int CHECK_SERVICE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_HW_CHASSIS(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_HW_CPU(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_HW_DEVICES(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_HW_MACADDR(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SW_OS(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SW_PACKAGES(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SWAP_OUT(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_DIR_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_localtime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result);
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service_perf(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int get_sensor(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_chassis(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_cpu(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_devices(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_macaddr(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_sw_os(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_sw_packages(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_in(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_out(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dir_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result);
*/
import "C"
@@ -61,9 +61,9 @@ import (
func resolveMetric(key string) (cfunc unsafe.Pointer) {
switch key {
case "system.localtime":
- cfunc = unsafe.Pointer(C.SYSTEM_LOCALTIME)
+ cfunc = unsafe.Pointer(C.system_localtime)
case "vfs.dir.get":
- cfunc = unsafe.Pointer(C.VFS_DIR_GET)
+ cfunc = unsafe.Pointer(C.vfs_dir_get)
}
return
diff --git a/src/go/pkg/zbxlib/globals_windows.go b/src/go/pkg/zbxlib/globals_windows.go
index 126123dc817..12873d2aa62 100644
--- a/src/go/pkg/zbxlib/globals_windows.go
+++ b/src/go/pkg/zbxlib/globals_windows.go
@@ -23,7 +23,7 @@ package zbxlib
#include "zbxstr.h"
#include "zbxsysinfo.h"
#include "zbxcomms.h"
-#include "perfmon.h"
+#include "zbxwin32.h"
#include "../src/zabbix_agent/metrics.h"
#cgo LDFLAGS: -Wl,--start-group
@@ -115,18 +115,18 @@ char *strerror_from_system(unsigned long error)
return utf8_string;
}
-int PERF_COUNTER(AGENT_REQUEST *request, AGENT_RESULT *result)
+int perf_counter(AGENT_REQUEST *request, AGENT_RESULT *result)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Not supported."));
return SYSINFO_RET_FAIL;
}
-DWORD get_builtin_counter_index(zbx_builtin_counter_ref_t counter_ref)
+DWORD zbx_get_builtin_counter_index(zbx_builtin_counter_ref_t counter_ref)
{
return 0;
}
-DWORD get_builtin_object_index(zbx_builtin_counter_ref_t object_ref)
+DWORD zbx_get_builtin_object_index(zbx_builtin_counter_ref_t object_ref)
{
return 0;
}
diff --git a/src/go/plugins/mysql/conn.go b/src/go/plugins/mysql/conn.go
index e4b4a9fa10a..e478eb72129 100644
--- a/src/go/plugins/mysql/conn.go
+++ b/src/go/plugins/mysql/conn.go
@@ -28,8 +28,8 @@ import (
"github.com/go-sql-driver/mysql"
+ "git.zabbix.com/ap/plugin-support/tlsconfig"
"git.zabbix.com/ap/plugin-support/uri"
- "zabbix.com/pkg/tlsconfig"
"git.zabbix.com/ap/plugin-support/log"
"git.zabbix.com/ap/plugin-support/zbxerr"
diff --git a/src/go/plugins/mysql/mysql.go b/src/go/plugins/mysql/mysql.go
index 6598059c7bf..56b429e8f60 100644
--- a/src/go/plugins/mysql/mysql.go
+++ b/src/go/plugins/mysql/mysql.go
@@ -24,9 +24,9 @@ import (
"time"
"git.zabbix.com/ap/plugin-support/plugin"
+ "git.zabbix.com/ap/plugin-support/tlsconfig"
"git.zabbix.com/ap/plugin-support/uri"
"git.zabbix.com/ap/plugin-support/zbxerr"
- "zabbix.com/pkg/tlsconfig"
)
const (
diff --git a/src/go/plugins/plugins_darwin.go b/src/go/plugins/plugins_darwin.go
index 8a8b58a26b3..0430703f550 100644
--- a/src/go/plugins/plugins_darwin.go
+++ b/src/go/plugins/plugins_darwin.go
@@ -29,7 +29,6 @@ import (
_ "zabbix.com/plugins/net/dns"
_ "zabbix.com/plugins/net/tcp"
_ "zabbix.com/plugins/oracle"
- _ "zabbix.com/plugins/postgres"
_ "zabbix.com/plugins/redis"
_ "zabbix.com/plugins/smart"
_ "zabbix.com/plugins/system/sw"
diff --git a/src/go/plugins/plugins_linux.go b/src/go/plugins/plugins_linux.go
index 5d7ce08bb5f..4dade1f66d2 100644
--- a/src/go/plugins/plugins_linux.go
+++ b/src/go/plugins/plugins_linux.go
@@ -33,7 +33,6 @@ import (
_ "zabbix.com/plugins/net/tcp"
_ "zabbix.com/plugins/net/udp"
_ "zabbix.com/plugins/oracle"
- _ "zabbix.com/plugins/postgres"
_ "zabbix.com/plugins/proc"
_ "zabbix.com/plugins/redis"
_ "zabbix.com/plugins/smart"
diff --git a/src/go/plugins/plugins_windows.go b/src/go/plugins/plugins_windows.go
index a18f8a7fa80..747c6ddc37f 100644
--- a/src/go/plugins/plugins_windows.go
+++ b/src/go/plugins/plugins_windows.go
@@ -31,7 +31,6 @@ import (
_ "zabbix.com/plugins/net/tcp"
_ "zabbix.com/plugins/net/udp"
_ "zabbix.com/plugins/oracle"
- _ "zabbix.com/plugins/postgres"
_ "zabbix.com/plugins/proc"
_ "zabbix.com/plugins/redis"
_ "zabbix.com/plugins/smart"
diff --git a/src/go/plugins/postgres/README.md b/src/go/plugins/postgres/README.md
deleted file mode 100644
index 0a688736d5a..00000000000
--- a/src/go/plugins/postgres/README.md
+++ /dev/null
@@ -1,632 +0,0 @@
-# PostgreSQL plugin
-Provides native Zabbix solution for monitoring PostgreSQL (object-relational database system).
-It can monitor several PostgreSQL instances simultaneously, remote or local to the Zabbix Agent.
-Native connection encryption is supported. The plugin keeps connections in the open state to reduce network
-congestion, latency, CPU and memory usage. Best for use in conjunction with the official
-[PostgreSQL template.](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/postgresql_agent2)
-You can extend it or create your template for your specific needs.
-
-## Requirements
-- Zabbix Agent 2
-- Go >= 1.13 (required only to build from source)
-
-## Supported versions
-PostgreSQL, version 10, 11, 12
-
-## Installation
-The plugin is supplied as part of the Zabbix Agent 2 and does not require any special installation steps.
-Once Zabbix Agent 2 is installed, the plugin is ready to work. You only need to make sure a PostgreSQL instance is
-available for connection, and you have necessary access rights.
-
-## Configuration
-The Zabbix Agent's configuration file is used to configure plugins.
-
-**Plugins.Postgres.CallTimeout** — The maximum time in seconds for waiting when a request has to be done.
-*Default value:* equals the global Timeout configuration parameter.
-*Limits:* 1-30
-
-**Plugins.Postgres.Timeout** — The maximum time in seconds for waiting when a connection has to be established.
-*Default value:* equals the global Timeout configuration parameter.
-*Limits:* 1-30
-
-**Plugins.Postgres.CustomQueriesPath** — Full pathname of a directory containing *.sql* files with custom queries.
-*Default value:* — (the feature is disabled by default)
-
-**Plugins.Postgres.KeepAlive** — Sets a time for waiting before unused connections will be closed.
-*Default value:* 300 sec.
-*Limits:* 60-900
-
-**Plugins.Postgres.Sessions.<session_name>.TLSConnect** — Encryption type for postgres connection. "*" should be replaced with a session name.
-*Default value:*
-*Accepted values:* required, verify_ca, verify_full
-
-**Plugins.Postgres.Sessions.<session_name>.TLSCAFile** — Full pathname of a file containing the top-level CA(s) certificates for postgres
-*Default value:*
-
-**Plugins.Postgres.Sessions.<session_name>.TLSCertFile** — Full pathname of a file containing the postgres certificate or certificate chain.
-*Default value:*
-
-**Plugins.Postgres.Sessions.*.TLSKeyFile** — Full pathname of a file containing the postgres private key.
-*Default value:*
-
-### Configuring connection
-A connection can be configured using either keys' parameters or named sessions.
-
-*Notes*:
-* It is not possible to mix configuration using named sessions and keys' parameters simultaneously.
-* You can leave any connection parameter empty, a default hard-coded value will be used in the such case.
-* TLS information can be passed only with sessions.
-* Embedded URI credentials (userinfo) are forbidden and will be ignored. So, you can't pass the credentials by this:
-
- pgsql.ping[tcp://user:password@127.0.0.1/postgres] — WRONG
-
- The correct way is:
-
- pgsql.ping[tcp://127.0.0.1,user,password,postgres]
-
-* The only supported network schema for a URI are "tcp" and "unix".
-Examples of valid URIs:
- - tcp://127.0.0.1:5432
- - tcp://localhost
- - localhost
- - unix:/var/run/postgresql/.s.PGSQL.5432 (**Note:** a full socket file path expected, not a socket directory)
- - /var/run/postgresql/.s.PGSQL.5432
-
-#### Using keys' parameters
-The common parameters for all keys are: [ConnString][,User][,Password][,Database]
-Where ConnString can be either a URI or a session name.
-ConnString will be treated as a URI if no session with the given name is found.
-If you use ConnString as a session name, just skip the rest of the connection parameters.
-
-#### Using named sessions
-Named sessions allow you to define specific parameters for each PostgreSQL instance. Currently, these are the
-supported parameters: Uri, User, Password, Service, TLSConnect, TLSCAFile, TLSCertFile and TLSKeyFile.
-It's a bit more secure way to store credentials compared to item keys or macros.
-
-E.g: suppose you have two PostgreSQL instances: "Prod" and "Test".
-You should add the following options to the agent configuration file:
-
- Plugins.Postgres.Sessions.Prod.Uri=tcp://192.168.1.1:5432
- Plugins.Postgres.Sessions.Prod.User=<UserForProd>
- Plugins.Postgres.Sessions.Prod.Password=<PasswordForProd>
- Plugins.Postgres.Sessions.Prod.Database=proddb
- Plugins.Postgres.Sessions.Prod.TLSConnect=verify_full
- Plugins.Postgres.Sessions.Prod.TLSCAFile=/path/to/ca_file
- Plugins.Postgres.Sessions.Prod.TLSCertFile=/path/to/cert_file
- Plugins.Postgres.Sessions.Prod.TLSKeyFile=/path/to/key_file
-
- Plugins.Postgres.Sessions.Test.Uri=tcp://192.168.0.1:5432
- Plugins.Postgres.Sessions.Test.User=<UserForTest>
- Plugins.Postgres.Sessions.Test.Password=<PasswordForTest>
- Plugins.Postgres.Sessions.Test.Service=testdb
- Plugins.Postgres.Sessions.Test.TLSConnect=verify_ca
- Plugins.Postgres.Sessions.Test.TLSCAFile=/path/to/test/ca_file
- Plugins.Postgres.Sessions.Test.TLSCertFile=/path/to/test/cert_file
- Plugins.Postgres.Sessions.Test.TLSKeyFile=/path/to/test/key_file
-
-Then you will be able to use these names as the 1st parameter (ConnString) in keys instead of URIs, e.g:
-
- pgsql.ping[Prod]
- pgsql.ping[Test]
-
-*Note*: sessions names are case-sensitive, the first letter of a name must be upper-cased.
-
-## Supported keys
-**pgsql.archive[\<commonParams\>]** — returns info about archive files.
-*Returns:* Result of the
-```sql
-SELECT row_to_json(T)
-FROM (SELECT archived_count, failed_count from pg_stat_archiver) T
-SELECT row_to_json(T)
-FROM ( SELECT count(name) AS count_files ,
-coalesce(sum((pg_stat_file('./pg_wal/' || rtrim(ready.name,'.ready'))).size),0) AS size_files
-FROM ( SELECT name
-FROM pg_ls_dir('./pg_wal/archive_status') name WHERE right( name,6)= '.ready' ) ready) T;
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of:
-- pgsql.archive.count_archived_files — number of WAL files that have been successfully archived.
-- pgsql.archive.failed_trying_to_archive — number of failed attempts for archiving WAL files.
-- pgsql.archive.count_files_to_archive — number of files to archive.
-- pgsql.archive.size_files_to_archive — size of files to archive.
-
-**pgsql.autovacum.count[\<commonParams\>]** — number of autovacuum workers.
-*Returns:* Result of the
-```sql
-SELECT count(*)
-FROM pg_catalog.pg_stat_activity
-WHERE query like '%%autovacuum%%'
-AND state <> 'idle'
-AND pid <> pg_catalog.pg_backend_pid()
-```
-> SQL query.
-
-**pgsql.bgwriter[\<commonParams\>]** — statistics about the background writer process's activity.
-*Returns:* Result of the
-```sql
-SELECT row_to_json (T)
-FROM (
-SELECT
-checkpoints_timed
-, checkpoints_req
-, checkpoint_write_time
-, checkpoint_sync_time
-, buffers_checkpoint
-, buffers_clean
-, maxwritten_clean
-, buffers_backend
-, buffers_backend_fsync
-, buffers_alloc
-FROM pg_catalog.pg_stat_bgwriter
-) T
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of:
-- pgsql.bgwriter.buffers_alloc — number of buffers allocated.
-- pgsql.bgwriter.buffers_backend — number of buffers written directly by a backend.
-- pgsql.bgwriter.maxwritten_clean — number of times the background writer stopped a cleaning scan because it had written
- too many buffers.
-- pgsql.bgwriter.buffers_backend_fsync — number of times a backend had to execute its own fsync call (normally the
-background writer handles those even when the backend does its own write).
-- pgsql.bgwriter.buffers_clean — number of buffers written by the background writer.
-- pgsql.bgwriter.buffers_checkpoint — number of buffers written during checkpoints.
-- pgsql.bgwriter.checkpoints_timed — number of scheduled checkpoints that have been performed.
-- pgsql.bgwriter.checkpoints_req — number of requested checkpoints that have been performed.
-- pgsql.bgwriter.checkpoint_write_time — total amount of time has been spent in the portion of checkpoint processing
-where files are written to disk, in milliseconds.
-- pgsql.bgwriter.sync_time — total amount of time has been spent in the portion of checkpoint processing where files
-are synchronized to disk.
-
-**pgsql.cache.hit[\<commonParams\>]** — cache hit rate.
-*Returns:* Result of the
-```sql
-SELECT round(sum(blks_hit)*100/sum(blks_hit+blks_read), 2)
-FROM pg_catalog.pg_stat_database;
-```
-> SQL query in percentage.
-
-**pgsql.connections[\<commonParams\>]** — connections by types.
-*Returns:* Result of the
-```sql
-SELECT row_to_json(T)
-FROM (
-SELECT
-sum(CASE WHEN state = 'active' THEN 1 ELSE 0 END) AS active,
-sum(CASE WHEN state = 'idle' THEN 1 ELSE 0 END) AS idle,
-sum(CASE WHEN state = 'idle in transaction' THEN 1 ELSE 0 END) AS idle_in_transaction,
-sum(CASE WHEN state = 'idle in transaction (aborted)' THEN 1 ELSE 0 END) AS idle_in_transaction_aborted,
-sum(CASE WHEN state = 'fastpath function call' THEN 1 ELSE 0 END) AS fastpath_function_call,
-count(*) AS total,
-count(*)*100/(SELECT current_setting('max_connections')::int) AS total_pct,
-sum(CASE WHEN wait_event IS NOT NULL THEN 1 ELSE 0 END) AS waiting,
-(SELECT count(*) FROM pg_prepared_xacts) AS prepared
-FROM pg_stat_activity
-WHERE datid is not NULL) T;
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of pgsql.connections:
-- pgsql.connections.active — the backend is executing a query.
-- pgsql.connections.fastpath_function_call — the backend is executing a fast-path function.
-- pgsql.connections.idle — the backend is waiting for a new client command.
-- pgsql.connections.idle_in_transaction — the backend is in a transaction, but is not currently executing a query.
-- pgsql.connections.prepared — number of prepared connections.
-- pgsql.connections.total — total number of connection.
-- pgsql.connections.total_pct — percentage of total connections in respect to ‘max_connections’ setting of PostgreSQL
-server.
-- pgsql.connections.waiting — number of waiting connections.
-- pgsql.connections.idle_in_transaction_aborted — This state is similar to idle in transaction, except one of the
-statements in the transaction caused an error.
-
-**pgsql.custom.query[\<commonParams\>,queryName[,args...]]** — Returns result of a custom query.
-*Parameters:*
-queryName (required) — name of a custom query (must be equal to a name of a sql file without an extension).
-args (optional) — one or more arguments to pass to a query.
-
-**pgsql.dbstat[\<commonParams\>]** — statistics per database. Used in databases discovery.
-*Returns:* Result of the
-```sql
-SELECT
-json_object_agg(coalesce (datname,'null'), row_to_json(T))
-FROM (
-SELECT
-datname
-, numbackends as numbackends
-, xact_commit as xact_commit
-, xact_rollback as xact_rollback
-, blks_read as blks_read
-, blks_hit as blks_hit
-, tup_returned as tup_returned
-, tup_fetched as tup_fetched
-, tup_inserted as tup_inserted
-, tup_updated as tup_updated
-, tup_deleted as tup_deleted
-, conflicts as conflicts
-, temp_files as temp_files
-, temp_bytes as temp_bytes
-, deadlocks as deadlocks
-, %s as checksum_failures
-, blk_read_time as blk_read_time
-, blk_write_time as blk_write_time
-FROM pg_catalog.pg_stat_database
-) T;
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of:
-- pgsql.dbstat.numbackends["{#DBNAME}"] — number of backends currently connected to this database.
-- pgsql.dbstat.sum.blk_read_time["{#DBNAME}"] — time spent reading data file blocks by backends in this database,
-in milliseconds.
-- pgsql.dbstat.sum.blk_write_time["{#DBNAME}"] — time spent writing data file blocks by backends in this database,
-in milliseconds.
-- pgsql.dbstat.sum.checksum_failures["{#DBNAME}"] — number of data page checksum failures detected (or on a shared
-object), or NULL if data checksums are not enabled (PostgreSQL version 12 only).
-- pgsql.dbstat.blks_read.rate["{#DBNAME}"] — number of disk blocks read in this database.
-- pgsql.dbstat.deadlocks.rate["{#DBNAME}"] — number of deadlocks detected in this database.
-- pgsql.dbstat.blks_hit.rate["{#DBNAME}"] — number of times disk blocks were found already in the buffer cache, so that
-a read was not necessary (this only includes hits in the PostgreSQL Pro buffer cache, not the operating system's file
-system cache).
-- pgsql.dbstat.xact_rollback.rate["{#DBNAME}"] — number of transactions in this database that have been rolled back.
-- pgsql.dbstat.xact_commit.rate["{#DBNAME}"] — number of transactions in this database that have been committed.
-- pgsql.dbstat.tup_updated.rate["{#DBNAME}"] — number of rows updated by queries in this database.
-- pgsql.dbstat.tup_returned.rate["{#DBNAME}"] — number of rows returned by queries in this database.
-- pgsql.dbstat.tup_inserted.rate["{#DBNAME}"] — number of rows inserted by queries in this database.
-- pgsql.dbstat.tup_fetched.rate["{#DBNAME}"] — number of rows fetched by queries in this database.
-- pgsql.dbstat.tup_deleted.rate["{#DBNAME}"] — number of rows deleted by queries in this database.
-- pgsql.dbstat.conflicts.rate["{#DBNAME}"] — number of queries canceled due to conflicts with recovery in this database.
-Conflicts occur only on standby servers; see pg_stat_database_conflicts for details.
-- pgsql.dbstat.temp_files.rate["{#DBNAME}"] — number of temporary files created by queries in this database.
-All temporary files are counted, regardless of why the temporary file was created (e.g., sorting or hashing), and
-regardless of the log_temp_files setting.
-- pgsql.dbstat.temp_bytes.rate["{#DBNAME}"] — total amount of data written to temporary files by queries in this
-database. All temporary files are counted, regardless of why the temporary file was created, and regardless of the
-log_temp_files setting.
-
-**pgsql.dbstat.sum[\<commonParams\>]** — statistics for all databases combined.
-*Returns:* Result of the
-```sql
-SELECT row_to_json (T)
-FROM (
-SELECT
-sum(numbackends) as numbackends
-, sum(xact_commit) as xact_commit
-, sum(xact_rollback) as xact_rollback
-, sum(blks_read) as blks_read
-, sum(blks_hit) as blks_hit
-, sum(tup_returned) as tup_returned
-, sum(tup_fetched) as tup_fetched
-, sum(tup_inserted) as tup_inserted
-, sum(tup_updated) as tup_updated
-, sum(tup_deleted) as tup_deleted
-, sum(conflicts) as conflicts
-, sum(temp_files) as temp_files
-, sum(temp_bytes) as temp_bytes
-, sum(deadlocks) as deadlocks
-, sum(checksum_failures) as checksum_failures
-, sum(blk_read_time) as blk_read_time
-, sum(blk_write_time) as blk_write_time
-FROM pg_catalog.pg_stat_database
-) T
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of:
-- pgsql.dbstat.numbackends — number of backends currently connected to this database.
-- pgsql.dbstat.sum.blk_read_time — time spent reading data file blocks by backends in this database, in milliseconds.
-- pgsql.dbstat.sum.blk_write_time — time spent writing data file blocks by backends in this database, in milliseconds.
-- pgsql.dbstat.sum.checksum_failures — number of data page checksum failures detected (or on a shared object), or NULL
-if data checksums are not enabled (PostgreSQL version 12 only).
-- pgsql.dbstat.sum.xact_commit — number of transactions in this database that have been committed.
-- pgsql.dbstat.sum.conflicts — number of queries canceled due to conflicts with recovery in this database.
-Conflicts occur only on standby servers; see pg_stat_database_conflicts for details.
-- pgsql.dbstat.sum.deadlocks — number of deadlocks detected in this database.
-- pgsql.dbstat.sum.blks_read — number of disk blocks read in this database.
-- pgsql.dbstat.sum.blks_hit — number of times disk blocks were found already in the buffer cache, so that a read was not
-necessary (this only includes hits in the PostgreSQL Pro buffer cache, not the operating system's file system cache).
-- pgsql.dbstat.sum.temp_bytes — total amount of data written to temporary files by queries in this database. All
-temporary files are counted, regardless of why the temporary file was created, and regardless of the log_temp_files
-setting.
-- pgsql.dbstat.sum.temp_files — number of temporary files created by queries in this database. All temporary files are
-counted, regardless of why the temporary file was created (e.g., sorting or hashing), and regardless of the
-log_temp_files setting.
-- pgsql.dbstat.sum.xact_rollback — number of transactions in this database that have been rolled back.
-- pgsql.dbstat.sum.tup_deleted — number of rows deleted by queries in this database.
-- pgsql.dbstat.sum.tup_fetched — number of rows fetched by queries in this database.
-- pgsql.dbstat.sum.tup_inserted — number of rows inserted by queries in this database.
-- pgsql.dbstat.sum.tup_returned — number of rows returned by queries in this database.
-- pgsql.dbstat.sum.tup_updated — number of rows updated by queries in this database.
-
-**pgsql.db.age[\<commonParams\>]** — age of the oldest xid for the specific database. Used in databases discovery.
-*Returns:* Result of the
-```sql
-SELECT age(datfrozenxid)
-FROM pg_catalog.pg_database
-WHERE datistemplate = false
-AND datname = <dbName>
-```
-> SQL query for specific database in transactions.
-
-**pgsql.db.bloating_tables[\<commonParams\>]** — number of bloating tables per database. Used in databases discovery.
-*Returns:* Result of the
-```sql
-SELECT count(*)
-FROM pg_catalog.pg_stat_all_tables
-WHERE (n_dead_tup/(n_live_tup+n_dead_tup)::float8) > 0.2
-AND (n_live_tup+n_dead_tup) > 50;
-```
-> SQL query.
-
-Result of this query differs depending on the database to which agent is currently connected.
-
-**pgsql.db.discovery[\<commonParams\>]** — Databases discovery.
-*Returns:* Result of the
-```sql
-SELECT json_build_object('data',json_agg(json_build_object('{#DBNAME}',d.datname)))
-FROM pg_database
-WHERE NOT datistemplate
-AND datallowconn;
-```
-> SQL query in LLD JSON format.
-
-**pgsql.db.size[\<commonParams\>]** — database size in bytes. Used in databases discovery.
-*Returns:* Result of the
-```sql
-SELECT pg_database_size(datname::text)
-FROM pg_catalog.pg_database
-WHERE datistemplate = false
-AND datname = <dbName>;
-```
-> SQL query for specific database in bytes.
-
-**pgsql.locks[\<commonParams\>]** — locks statistics per database. Used in databases discovery.
-*Returns:* Result of the
-```sql
-WITH T AS
-(SELECT
-db.datname dbname,
-lower(replace(Q.mode, 'Lock', '')) AS MODE,
-coalesce(T.qty, 0) val
-FROM pg_database db
-JOIN (
-VALUES ('AccessShareLock') ,('RowShareLock') ,('RowExclusiveLock') ,('ShareUpdateExclusiveLock') ,('ShareLock') ,('ShareRowExclusiveLock') ,('ExclusiveLock') ,('AccessExclusiveLock')) Q(MODE) ON TRUE NATURAL
-LEFT JOIN
-(SELECT datname,
-MODE,
-count(MODE) qty
-FROM pg_locks lc
-RIGHT JOIN pg_database db ON db.oid = lc.database
-GROUP BY 1, 2) T
-WHERE NOT db.datistemplate
-ORDER BY 1, 2)
-SELECT json_object_agg(dbname, row_to_json(T2))
-FROM
-(SELECT dbname,
-sum(val) AS total,
-sum(CASE
-WHEN MODE = 'accessexclusive' THEN val
-END) AS accessexclusive,
-sum (CASE
-WHEN MODE = 'accessshare' THEN val
-END) AS accessshare,
-sum(CASE
-WHEN MODE = 'exclusive' THEN val
-END) AS EXCLUSIVE,
-sum(CASE
-WHEN MODE = 'rowexclusive' THEN val
-END) AS rowexclusive,
-sum(CASE
-WHEN MODE = 'rowshare' THEN val
-END) AS rowshare,
-sum(CASE
-WHEN MODE = 'share' THEN val
-END) AS SHARE,
-sum(CASE
-WHEN MODE = 'sharerowexclusive' THEN val
-END) AS sharerowexclusive,
-sum(CASE
-WHEN MODE = 'shareupdateexclusive' THEN val
-END) AS shareupdateexclusive
-FROM T
-GROUP BY dbname) T2;
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of:
-- pgsql.locks.shareupdateexclusive["{#DBNAME}"] — number of share update exclusive locks.
-- pgsql.locks.accessexclusive["{#DBNAME}"] — number of access exclusive locks.
-- pgsql.locks.accessshare["{#DBNAME}"] — number of access share locks.
-- pgsql.locks.exclusive["{#DBNAME}"] — number of exclusive locks.
-- pgsql.locks.rowexclusive["{#DBNAME}"] — number of row exclusive locks.
-- pgsql.locks.rowshare["{#DBNAME}"] — number of row share locks.
-- pgsql.locks.share["{#DBNAME}"] — number of share locks.
-- pgsql.locks.sharerowexclusive["{#DBNAME}"] — number of share row exclusive locks.
-
-**pgsql.pgsql.oldest.xid[\<commonParams\>]** — PostgreSQL age of the oldest XID.
-*Returns:* Result of the
-```sql
-SELECT greatest(max(age(backend_xmin)), max(age(backend_xid)))
-FROM pg_catalog.pg_stat_activity" SQL query.
-```
-
-**pgsql.ping[\<commonParams\>]** — tests whether a connection is alive or not.
-*Returns:*
-- "1" if the connection is alive.
-- "0" if the connection is broken (returned if there was any error during the test, including AUTH and configuration issues).
-
-**pgsql.queries[\<commonParams\>,TimePeriod]** - queries metrics by execution time.
-*Parameters:*
-TimePeriod (required) — execution time limit for count of slow queries. (must be an integer, must be greater than 0).
-
-*Returns:* Result of the
-```sql
-WITH T AS
-(SELECT db.datname,
-coalesce(T.query_time_max, 0) query_time_max,
-coalesce(T.tx_time_max, 0) tx_time_max,
-coalesce(T.mro_time_max, 0) mro_time_max,
-coalesce(T.query_time_sum, 0) query_time_sum,
-coalesce(T.tx_time_sum, 0) tx_time_sum,
-coalesce(T.mro_time_sum, 0) mro_time_sum,
-coalesce(T.query_slow_count, 0) query_slow_count,
-coalesce(T.tx_slow_count, 0) tx_slow_count,
-coalesce(T.mro_slow_count, 0) mro_slow_count
-FROM pg_database db NATURAL
-LEFT JOIN (
-SELECT datname,
-extract(epoch FROM now())::integer ts,
-coalesce(max(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle', 'idle in transaction', 'idle in transaction (aborted)') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) query_time_max,
-coalesce(max(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) tx_time_max,
-coalesce(max(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query ~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) mro_time_max,
-coalesce(sum(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle', 'idle in transaction', 'idle in transaction (aborted)') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) query_time_sum,
-coalesce(sum(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) tx_time_sum,
-coalesce(sum(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query ~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) mro_time_sum,
-coalesce(sum((extract('epoch' FROM (clock_timestamp() - query_start)) > %d)::integer * (state NOT IN ('idle', 'idle in transaction', 'idle in transaction (aborted)') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) query_slow_count,
-coalesce(sum((extract('epoch' FROM (clock_timestamp() - query_start)) > %d)::integer * (state NOT IN ('idle') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) tx_slow_count,
-coalesce(sum((extract('epoch' FROM (clock_timestamp() - query_start)) > %d)::integer * (state NOT IN ('idle') AND query ~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) mro_slow_count
-FROM pg_stat_activity
-WHERE pid <> pg_backend_pid()
-GROUP BY 1) T
-WHERE NOT db.datistemplate )
-SELECT json_object_agg(datname, row_to_json(T))
-FROM T
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of:
-- pgsql.queries.mro.time_max["{#DBNAME}"] - max maintenance query time.
-- pgsql.queries.query.time_max["{#DBNAME}"] - max query time.
-- pgsql.queries.tx.time_max["{#DBNAME}"] - max transaction query time.
-- pgsql.queries.mro.slow_count["{#DBNAME}"] - slow maintenance query count.
-- pgsql.queries.query.slow_count["{#DBNAME}"] - slow query count.
-- pgsql.queries.tx.slow_count["{#DBNAME}"] - slow transaction query count.
-- pgsql.queries.mro.time_sum["{#DBNAME}"] - sum maintenance query time.
-- pgsql.queries.query.time_sum["{#DBNAME}"] - sum query time.
-- pgsql.queries.tx.time_sum["{#DBNAME}"] - sum transaction query time.
-
-**pgsql.replication.count[uri,username,password]** — number of standby servers.
-*Returns:* Result of the
-```sql
-SELECT count(*) FROM pg_stat_replication
-```
-> SQL query.
-
-**pgsql.replication_lag.b[uri,username,password]** — replication lag in bytes.
-*Returns:* Result of the
-```sql
-SELECT pg_catalog.pg_wal_lsn_diff (received_lsn, pg_last_wal_replay_lsn())
-FROM pg_stat_wal_receiver;
-```
-> SQL query in bytes
-
-**pgsql.replication_lag.sec[uri,username,password]** — replication lag in seconds.
-*Returns:* Result of the
-```sql
-SELECT
-CASE
-WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0
-ELSE
-COALESCE(EXTRACT(EPOCH FROM now() - pg_last_xact_replay_timestamp())::integer, 0)
-END as lag
-```
-> SQL query in seconds.
-
-**pgsql.replication.recovery_role[uri,username,password]** — recovery status.
-*Returns:*
-- 1 — recovery is still in progress (standby mode)
-- 0 — master mode.
-
-**pgsql.replication.status[uri,username,password]** — status of replication.
-*Returns:*
-- 0 — streaming is down
-- 1 — streaming is up
-- 2 — mastermode
-
-**pgsql.replication.process[uri,username,password]** — flush lag, write lag and replay lag per each sender process.
-*Returns:* Result of the
-```sql
-SELECT json_object_agg(application_name, row_to_json(T))
-FROM (
- SELECT
- CONCAT(application_name, ' ', pid) AS application_name,
- EXTRACT(epoch FROM COALESCE(flush_lag,'0'::interval)) as flush_lag,
- EXTRACT(epoch FROM COALESCE(replay_lag,'0'::interval)) as replay_lag,
- EXTRACT(epoch FROM COALESCE(write_lag, '0'::interval)) as write_lag
- FROM pg_stat_replication
- ) T;
-```
-
-**pgsql.replication.process.discovery[uri,username,password]** - replication procces name discovery.
-*Returns:* Result of the
-```sql
-SELECT
-json_build_object('data',
-json_agg(json_build_object('{#APPLICATION_NAME}',
-CONCAT(application_name, ' ', pid))))
-FROM
-pg_stat_replication
-```
-
-**pgsql.uptime[\<commonParams\>]** — PostgreSQL uptime, in milliseconds.
-*Returns:* Result of the
-```sql
-SELECT date_part('epoch', now() - pg_postmaster_start_time());
-```
-> SQL query in ms.
-
-**pgsql.wal.stat[\<commonParams\>]** — returns WAL statistics.
-*Returns:* Result of the
-```sql
-SELECT row_to_json(T)
-FROM (
-SELECT
-pg_wal_lsn_diff(pg_current_wal_lsn(),'0/00000000') AS WRITE,
-count(*)
-FROM pg_ls_waldir() AS COUNT
-) T;
-```
-> SQL query JSON format.
-
-Then JSON is proceeded by dependent items of:
-- pgsql.wal.count — number of wal files.
-- pgsql.wal.write — wal lsn used, in bytes.
-
-## Custom queries
-It's possible to extend functionality of the plugin using user-defined queries. To do that you should place all your
-queries in a directory specified in Plugins.Postgres.CustomQueriesPath (there is no default path) as *.sql files.
-For example, you have a tree:
-
- /etc/zabbix/postgres/sql/
- ├── long_tx.sql
- ├── payment.sql
- └── top_proc.sql
-
-You should set Plugins.Postgres.CustomQueriesPath=/etc/zabbix/postgres/sql
-
-So, when the queries are in place, you can execute them:
-
- pgsql.custom.query[<commonParams>,top_proc]
- pgsql.custom.query[<commonParams>,long_tx,600]
-
-You can pass as many parameters to a query as you need.
-The syntax for placeholder parameters uses "$#", where "#" is an index number of a parameter.
-E.g:
-```
-/* payment.sql */
-
-SELECT
- amount
-FROM
- payment
-WHERE
- user = $1
- AND service_id = $2
- AND date = $3
-```
-
- pgsql.custom.query[<commonParams>,payment,"John Doe",1,"10/25/2020"]
-
-## Troubleshooting
-The plugin uses Zabbix agent's logs. You can increase debugging level of Zabbix Agent if you need more details about
-what is happening.
diff --git a/src/go/plugins/postgres/config.go b/src/go/plugins/postgres/config.go
deleted file mode 100755
index 4f37d9ae77f..00000000000
--- a/src/go/plugins/postgres/config.go
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "git.zabbix.com/ap/plugin-support/conf"
- "git.zabbix.com/ap/plugin-support/plugin"
-)
-
-// Session struct holds individual options for PostgreSQL connection for each session.
-type Session struct {
- // URI is a connection string consisting of a network scheme, a host address and a port or a path to a Unix-socket.
- URI string `conf:"name=Uri,optional"`
-
- // User of PostgreSQL server.
- User string `conf:"optional"`
-
- // Password to send to protected PostgreSQL server.
- Password string `conf:"optional"`
-
- // Database of PostgreSQL server.
- Database string `conf:"optional"`
-
- // Connection type of PostgreSQL server.
- TLSConnect string `conf:"name=TLSConnect,optional"`
-
- // Certificate Authority filepath for PostgreSQL server.
- TLSCAFile string `conf:"name=TLSCAFile,optional"`
-
- // Certificate filepath for PostgreSQL server.
- TLSCertFile string `conf:"name=TLSCertFile,optional"`
-
- // Key filepath for PostgreSQL server.
- TLSKeyFile string `conf:"name=TLSKeyFile,optional"`
-}
-
-// PluginOptions are options for PostgreSQL connection.
-type PluginOptions struct {
- // Timeout is the maximum time in seconds for waiting when a connection has to be established.
- // Default value equals to the global agent timeout.
- Timeout int `conf:"optional,range=1:30"`
-
- // CallTimeout is the maximum time in seconds for waiting when a request has to be done.
- // Default value equals to the global agent timeout.
- CallTimeout int `conf:"optional,range=1:30"`
-
- // KeepAlive is a time to wait before unused connections will be closed.
- KeepAlive int `conf:"optional,range=60:900,default=300"`
-
- // Sessions stores pre-defined named sets of connections settings.
- Sessions map[string]Session `conf:"optional"`
-
- // CustomQueriesPath is a full pathname of a directory containing *.sql files with custom queries.
- CustomQueriesPath string `conf:"optional"`
-}
-
-// Configure implements the Configurator interface.
-// Initializes configuration structures.
-func (p *Plugin) Configure(global *plugin.GlobalOptions, options interface{}) {
- if err := conf.Unmarshal(options, &p.options); err != nil {
- p.Errf("cannot unmarshal configuration options: %s", err)
- }
-
- if p.options.Timeout == 0 {
- p.options.Timeout = global.Timeout
- }
-
- if p.options.CallTimeout == 0 {
- p.options.CallTimeout = global.Timeout
- }
-}
-
-// Validate implements the Configurator interface.
-// Returns an error if validation of a plugin's configuration is failed.
-func (p *Plugin) Validate(options interface{}) error {
- var opts PluginOptions
-
- return conf.Unmarshal(options, &opts)
-}
diff --git a/src/go/plugins/postgres/conn.go b/src/go/plugins/postgres/conn.go
deleted file mode 100755
index fd697e49cf3..00000000000
--- a/src/go/plugins/postgres/conn.go
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "crypto/tls"
- "database/sql"
- "fmt"
- "net"
- "net/url"
- "path/filepath"
- "strings"
- "sync"
- "time"
-
- "git.zabbix.com/ap/plugin-support/log"
- "git.zabbix.com/ap/plugin-support/uri"
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4/pgxpool"
- "github.com/jackc/pgx/v4/stdlib"
- "github.com/omeid/go-yarn"
- "zabbix.com/pkg/tlsconfig"
-)
-
-const MinSupportedPGVersion = 100000
-
-type PostgresClient interface {
- Query(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error)
- QueryByName(ctx context.Context, queryName string, args ...interface{}) (rows *sql.Rows, err error)
- QueryRow(ctx context.Context, query string, args ...interface{}) (row *sql.Row, err error)
- QueryRowByName(ctx context.Context, queryName string, args ...interface{}) (row *sql.Row, err error)
- PostgresVersion() int
-}
-
-// PGConn holds pointer to the Pool of Postgres Instance.
-type PGConn struct {
- client *sql.DB
- callTimeout time.Duration
- ctx context.Context
- lastTimeAccess time.Time
- version int
- queryStorage *yarn.Yarn
- address string
-}
-
-var errorQueryNotFound = "query %q not found"
-
-// Query wraps pgxpool.Query.
-func (conn *PGConn) Query(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error) {
- rows, err = conn.client.QueryContext(ctx, query, args...)
-
- if ctxErr := ctx.Err(); ctxErr != nil {
- err = ctxErr
- }
-
- return
-}
-
-// QueryByName executes a query from queryStorage by its name and returns a single row.
-func (conn *PGConn) QueryByName(ctx context.Context, queryName string, args ...interface{}) (rows *sql.Rows, err error) {
- if sql, ok := (*conn.queryStorage).Get(queryName + sqlExt); ok {
- normalizedSQL := strings.TrimRight(strings.TrimSpace(sql), ";")
-
- return conn.Query(ctx, normalizedSQL, args...)
- }
-
- return nil, fmt.Errorf(errorQueryNotFound, queryName)
-}
-
-// QueryRow wraps pgxpool.QueryRow.
-func (conn *PGConn) QueryRow(ctx context.Context, query string, args ...interface{}) (row *sql.Row, err error) {
- row = conn.client.QueryRowContext(ctx, query, args...)
-
- if ctxErr := ctx.Err(); ctxErr != nil {
- err = ctxErr
- }
-
- return
-}
-
-// QueryRowByName executes a query from queryStorage by its name and returns a single row.
-func (conn *PGConn) QueryRowByName(ctx context.Context, queryName string, args ...interface{}) (row *sql.Row, err error) {
- if sql, ok := (*conn.queryStorage).Get(queryName + sqlExt); ok {
- normalizedSQL := strings.TrimRight(strings.TrimSpace(sql), ";")
-
- return conn.QueryRow(ctx, normalizedSQL, args...)
- }
-
- return nil, fmt.Errorf(errorQueryNotFound, queryName)
-}
-
-// GetPostgresVersion exec SQL query to retrieve the version of PostgreSQL server we are currently connected to.
-func getPostgresVersion(ctx context.Context, conn *sql.DB) (version int, err error) {
- err = conn.QueryRowContext(ctx, `select current_setting('server_version_num');`).Scan(&version)
-
- return
-}
-
-// PostgresVersion returns the version of PostgreSQL server we are currently connected to.
-func (conn *PGConn) PostgresVersion() int {
- return conn.version
-}
-
-// updateAccessTime updates the last time a connection was accessed.
-func (conn *PGConn) updateAccessTime() {
- conn.lastTimeAccess = time.Now()
-}
-
-// ConnManager is a thread-safe structure for manage connections.
-type ConnManager struct {
- sync.Mutex
- connMutex sync.Mutex
- connections map[string]*PGConn
- keepAlive time.Duration
- connectTimeout time.Duration
- callTimeout time.Duration
- Destroy context.CancelFunc
- queryStorage yarn.Yarn
-}
-
-// NewConnManager initializes connManager structure and runs Go Routine that watches for unused connections.
-func NewConnManager(keepAlive, connectTimeout, callTimeout,
- hkInterval time.Duration, queryStorage yarn.Yarn) *ConnManager {
- ctx, cancel := context.WithCancel(context.Background())
-
- connMgr := &ConnManager{
- connections: make(map[string]*PGConn),
- keepAlive: keepAlive,
- connectTimeout: connectTimeout,
- callTimeout: callTimeout,
- Destroy: cancel, // Destroy stops originated goroutines and closes connections.
- queryStorage: queryStorage,
- }
-
- go connMgr.housekeeper(ctx, hkInterval)
-
- return connMgr
-}
-
-// closeUnused closes each connection that has not been accessed at least within the keepalive interval.
-func (c *ConnManager) closeUnused() {
- c.connMutex.Lock()
- defer c.connMutex.Unlock()
-
- for uri, conn := range c.connections {
- if time.Since(conn.lastTimeAccess) > c.keepAlive {
- conn.client.Close()
- delete(c.connections, uri)
- log.Debugf("[%s] Closed unused connection: %s", pluginName, conn.address)
- }
- }
-}
-
-// closeAll closes all existed connections.
-func (c *ConnManager) closeAll() {
- c.connMutex.Lock()
- for uri, conn := range c.connections {
- conn.client.Close()
- delete(c.connections, uri)
- }
- c.connMutex.Unlock()
-}
-
-// housekeeper repeatedly checks for unused connections and closes them.
-func (c *ConnManager) housekeeper(ctx context.Context, interval time.Duration) {
- ticker := time.NewTicker(interval)
-
- for {
- select {
- case <-ctx.Done():
- ticker.Stop()
- c.closeAll()
-
- return
- case <-ticker.C:
- c.closeUnused()
- }
- }
-}
-
-// create creates a new connection with given credentials.
-func (c *ConnManager) create(uri uri.URI, details tlsconfig.Details) (*PGConn, error) {
- c.connMutex.Lock()
- defer c.connMutex.Unlock()
-
- if _, ok := c.connections[uri.NoQueryString()]; ok {
- // Should never happen.
- panic("connection already exists")
- }
-
- ctx := context.Background()
-
- host := uri.Host()
- port := uri.Port()
-
- if uri.Scheme() == "unix" {
- socket := uri.Addr()
- host = filepath.Dir(socket)
-
- ext := filepath.Ext(filepath.Base(socket))
- if len(ext) <= 1 {
- return nil, fmt.Errorf("incorrect socket: %q", socket)
- }
-
- port = ext[1:]
- }
-
- dbname, err := url.QueryUnescape(uri.GetParam("dbname"))
- if err != nil {
- return nil, err
- }
-
- dsn := fmt.Sprintf("host=%s port=%s dbname=%s user=%s",
- host, port, dbname, uri.User())
-
- if uri.Password() != "" {
- dsn += " password=" + uri.Password()
- }
-
- client, err := createTLSClient(dsn, c.connectTimeout, details)
- if err != nil {
- return nil, err
- }
-
- serverVersion, err := getPostgresVersion(ctx, client)
- if err != nil {
- return nil, err
- }
-
- if serverVersion < MinSupportedPGVersion {
- return nil, fmt.Errorf("postgres version %d is not supported", serverVersion)
- }
-
- c.connections[uri.NoQueryString()] = &PGConn{
- client: client,
- callTimeout: c.callTimeout,
- version: serverVersion,
- lastTimeAccess: time.Now(),
- ctx: ctx,
- queryStorage: &c.queryStorage,
- address: uri.Addr(),
- }
-
- log.Debugf("[%s] Created new connection: %s", pluginName, uri.Addr())
-
- return c.connections[uri.NoQueryString()], nil
-}
-
-func createTLSClient(dsn string, timeout time.Duration, details tlsconfig.Details) (*sql.DB, error) {
- config, err := pgxpool.ParseConfig(dsn)
- if err != nil {
- return nil, err
- }
-
- config.ConnConfig.DialFunc = func(ctx context.Context, network, addr string) (net.Conn, error) {
- d := net.Dialer{}
- ctxTimeout, cancel := context.WithTimeout(context.Background(), timeout)
- defer cancel()
-
- conn, err := d.DialContext(ctxTimeout, network, addr)
-
- return conn, err
- }
-
- config.ConnConfig.TLSConfig, err = getTLSConfig(details)
- if err != nil {
- return nil, err
- }
-
- return stdlib.OpenDB(*config.ConnConfig), nil
-}
-
-func getTLSConfig(details tlsconfig.Details) (*tls.Config, error) {
- switch details.TlsConnect {
- case "required":
- return &tls.Config{InsecureSkipVerify: true}, nil
- case "verify_ca":
- return tlsconfig.CreateConfig(details, true)
- case "verify_full":
- return tlsconfig.CreateConfig(details, false)
- }
-
- return nil, nil
-}
-
-// get returns a connection with given uri if it exists and also updates lastTimeAccess, otherwise returns nil.
-func (c *ConnManager) get(uri uri.URI) *PGConn {
- c.connMutex.Lock()
- defer c.connMutex.Unlock()
-
- if conn, ok := c.connections[uri.NoQueryString()]; ok {
- conn.updateAccessTime()
- return conn
- }
-
- return nil
-}
-
-// GetConnection returns an existing connection or creates a new one.
-func (c *ConnManager) GetConnection(uri uri.URI, details tlsconfig.Details) (conn *PGConn, err error) {
- c.Lock()
- defer c.Unlock()
-
- conn = c.get(uri)
-
- if conn == nil {
- conn, err = c.create(uri, details)
- }
-
- if err != nil {
- err = zbxerr.ErrorConnectionFailed.Wrap(err)
- }
-
- return
-}
diff --git a/src/go/plugins/postgres/handler_archive.go b/src/go/plugins/postgres/handler_archive.go
deleted file mode 100644
index 9a0641d0165..00000000000
--- a/src/go/plugins/postgres/handler_archive.go
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// archiveHandler gets info about count and size of archive files and returns JSON if all is OK or nil otherwise.
-func archiveHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var archiveCountJSON, archiveSizeJSON string
-
- queryArchiveCount := `SELECT row_to_json(T)
- FROM (
- SELECT archived_count, failed_count
- FROM pg_stat_archiver
- ) T;`
-
- queryArchiveSize := `SELECT row_to_json(T)
- FROM (
- WITH values AS (
- SELECT
- 4096/(ceil(pg_settings.setting::numeric/1024/1024))::int AS segment_parts_count,
- setting::bigint AS segment_size,
- ('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
- ('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,
- CASE WHEN pg_is_in_recovery() THEN NULL
- ELSE ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int END AS current_wal_div,
- CASE WHEN pg_is_in_recovery() THEN NULL
- ELSE ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int END AS current_wal_mod
- FROM pg_settings, pg_stat_archiver
- WHERE pg_settings.name = 'wal_segment_size')
- SELECT
- greatest(coalesce((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1, 0), 0) AS count_files,
- greatest(coalesce(((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1) * segment_size, 0), 0) AS size_files
- FROM values
- ) T;`
-
- row, err := conn.QueryRow(ctx, queryArchiveCount)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&archiveCountJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- row, err = conn.QueryRow(ctx, queryArchiveSize)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&archiveSizeJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- result := archiveCountJSON[:len(archiveCountJSON)-1] + "," + archiveSizeJSON[1:]
-
- return result, nil
-}
diff --git a/src/go/plugins/postgres/handler_archive_test.go b/src/go/plugins/postgres/handler_archive_test.go
deleted file mode 100644
index 03473493a44..00000000000
--- a/src/go/plugins/postgres/handler_archive_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_archiveHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("archiveHandler should return json with data if OK "),
- &impl,
- args{context.Background(), sharedPool, keyArchiveSize, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- got, err := archiveHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.archiveHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
-
- if len(got.(string)) == 0 {
- t.Errorf("Plugin.archiveHandler() = %v", got)
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_autovacuum.go b/src/go/plugins/postgres/handler_autovacuum.go
deleted file mode 100644
index 9274328ef1a..00000000000
--- a/src/go/plugins/postgres/handler_autovacuum.go
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// autovacuumHandler returns count of autovacuum workers if all is OK or nil otherwise.
-func autovacuumHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var countAutovacuumWorkers int64
-
- query := `SELECT count(*)
- FROM pg_catalog.pg_stat_activity
- WHERE query like '%%autovacuum%%'
- AND state <> 'idle'
- AND pid <> pg_catalog.pg_backend_pid()`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&countAutovacuumWorkers)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return countAutovacuumWorkers, nil
-}
diff --git a/src/go/plugins/postgres/handler_autovacuum_test.go b/src/go/plugins/postgres/handler_autovacuum_test.go
deleted file mode 100644
index 9fa0c52ae4a..00000000000
--- a/src/go/plugins/postgres/handler_autovacuum_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_autovacuumHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("autovacuumHandler should return count of autovacuum workers if OK "),
- &impl,
- args{context.Background(), sharedPool, keyAutovacuum, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := autovacuumHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
-
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.autovacuumHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_bgwriter.go b/src/go/plugins/postgres/handler_bgwriter.go
deleted file mode 100644
index f5a29fb3f74..00000000000
--- a/src/go/plugins/postgres/handler_bgwriter.go
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// bgwriterHandler executes select with statistics from pg_stat_bgwriter
-// and returns JSON if all is OK or nil otherwise.
-func bgwriterHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var bgwriterJSON string
-
- query := `
- SELECT row_to_json (T)
- FROM (
- SELECT
- checkpoints_timed
- , checkpoints_req
- , checkpoint_write_time
- , checkpoint_sync_time
- , buffers_checkpoint
- , buffers_clean
- , maxwritten_clean
- , buffers_backend
- , buffers_backend_fsync
- , buffers_alloc
- FROM pg_catalog.pg_stat_bgwriter
- ) T ;`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&bgwriterJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return bgwriterJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_bgwriter_test.go b/src/go/plugins/postgres/handler_bgwriter_test.go
deleted file mode 100644
index e4c098b76ab..00000000000
--- a/src/go/plugins/postgres/handler_bgwriter_test.go
+++ /dev/null
@@ -1,66 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_bgwriterHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("statHandler should return json with data if OK"),
- &impl,
- args{context.Background(), sharedPool, keyBgwriter, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := bgwriterHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.statHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_cache.go b/src/go/plugins/postgres/handler_cache.go
deleted file mode 100644
index 84ce45cf3ce..00000000000
--- a/src/go/plugins/postgres/handler_cache.go
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// cacheHandler finds cache hit percent and returns int64 if all is OK or nil otherwise.
-func cacheHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var cache float64
-
- query := `SELECT round(sum(blks_hit)*100/sum(blks_hit+blks_read), 2) FROM pg_catalog.pg_stat_database;`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&cache)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return cache, nil
-}
diff --git a/src/go/plugins/postgres/handler_cache_test.go b/src/go/plugins/postgres/handler_cache_test.go
deleted file mode 100644
index b1702913904..00000000000
--- a/src/go/plugins/postgres/handler_cache_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_cacheHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("cacheHandler should return int64 with data "),
- &impl,
- args{context.Background(), sharedPool, keyCache, nil, []string{}},
-
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := cacheHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.cacheHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_connections.go b/src/go/plugins/postgres/handler_connections.go
deleted file mode 100644
index 74e82a9705a..00000000000
--- a/src/go/plugins/postgres/handler_connections.go
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// connectionsHandler executes select from pg_stat_activity command and returns JSON if all is OK or nil otherwise.
-func connectionsHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var connectionsJSON string
-
- query := `SELECT row_to_json(T)
- FROM (
- SELECT
- sum(CASE WHEN state = 'active' THEN 1 ELSE 0 END) AS active,
- sum(CASE WHEN state = 'idle' THEN 1 ELSE 0 END) AS idle,
- sum(CASE WHEN state = 'idle in transaction' THEN 1 ELSE 0 END) AS idle_in_transaction,
- sum(CASE WHEN state = 'idle in transaction (aborted)' THEN 1 ELSE 0 END) AS idle_in_transaction_aborted,
- sum(CASE WHEN state = 'fastpath function call' THEN 1 ELSE 0 END) AS fastpath_function_call,
- sum(CASE WHEN state = 'disabled' THEN 1 ELSE 0 END) AS disabled,
- count(*) AS total,
- count(*)*100/(SELECT current_setting('max_connections')::int) AS total_pct,
- sum(CASE WHEN wait_event IS NOT NULL THEN 1 ELSE 0 END) AS waiting,
- (SELECT count(*) FROM pg_prepared_xacts) AS prepared
- FROM pg_stat_activity WHERE datid IS NOT NULL AND state IS NOT NULL) T;`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&connectionsJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return connectionsJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_connections_test.go b/src/go/plugins/postgres/handler_connections_test.go
deleted file mode 100644
index 85d5e68e38c..00000000000
--- a/src/go/plugins/postgres/handler_connections_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_connectionsHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("connectionsHandler should return json with data if OK "),
- &impl,
- args{context.Background(), sharedPool, keyConnections, nil, []string{}},
-
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := connectionsHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.connectionsHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_custom_query.go b/src/go/plugins/postgres/handler_custom_query.go
deleted file mode 100644
index 57c640b3b7f..00000000000
--- a/src/go/plugins/postgres/handler_custom_query.go
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "encoding/json"
- "errors"
- "strings"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// customQueryHandler executes custom user queries from *.sql files.
-func customQueryHandler(ctx context.Context, conn PostgresClient,
- _ string, params map[string]string, extraParams ...string) (interface{}, error) {
- queryName := params["QueryName"]
-
- queryArgs := make([]interface{}, len(extraParams))
- for i, v := range extraParams {
- queryArgs[i] = v
- }
-
- rows, err := conn.QueryByName(ctx, queryName, queryArgs...)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
- defer rows.Close()
-
- // JSON marshaling
- var data []string
-
- columns, err := rows.Columns()
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- values := make([]interface{}, len(columns))
- valuePointers := make([]interface{}, len(values))
-
- for i := range values {
- valuePointers[i] = &values[i]
- }
-
- results := make(map[string]interface{})
-
- for rows.Next() {
- err = rows.Scan(valuePointers...)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- setResult(results, values, columns)
-
- jsonRes, err := json.Marshal(results)
- if err != nil {
- return nil, err
- }
-
- data = append(data, strings.TrimSpace(string(jsonRes)))
- }
-
- // Any errors encountered by rows.Next or rows.Scan will be returned here
- if rows.Err() != nil {
- return nil, err
- }
-
- return "[" + strings.Join(data, ",") + "]", nil
-}
-
-func setResult(results map[string]interface{}, values []interface{}, columns []string) {
- for i, value := range values {
- switch v := value.(type) {
- case []uint8:
- results[columns[i]] = string(v)
- default:
- results[columns[i]] = value
- }
- }
-}
diff --git a/src/go/plugins/postgres/handler_database_age.go b/src/go/plugins/postgres/handler_database_age.go
deleted file mode 100644
index 384ace13541..00000000000
--- a/src/go/plugins/postgres/handler_database_age.go
+++ /dev/null
@@ -1,55 +0,0 @@
-/* /*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// databaseAgeHandler gets age of specific database respectively or nil otherwise.
-func databaseAgeHandler(ctx context.Context, conn PostgresClient,
- _ string, params map[string]string, _ ...string) (interface{}, error) {
- var countAge int64
-
- query := `SELECT age(datfrozenxid)
- FROM pg_catalog.pg_database
- WHERE datistemplate = false
- AND datname = $1;`
- row, err := conn.QueryRow(ctx, query, params["Database"])
-
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&countAge)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return countAge, nil
-}
diff --git a/src/go/plugins/postgres/handler_database_age_test.go b/src/go/plugins/postgres/handler_database_age_test.go
deleted file mode 100644
index b96bf678d30..00000000000
--- a/src/go/plugins/postgres/handler_database_age_test.go
+++ /dev/null
@@ -1,66 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_databasesAgeHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("databaseAgeHandler should return age of each database "),
- &impl,
- args{context.Background(), sharedPool, keyDatabaseAge, testParamDatabase, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := databaseAgeHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.databaseAgeHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_database_size.go b/src/go/plugins/postgres/handler_database_size.go
deleted file mode 100644
index 69f75fc818f..00000000000
--- a/src/go/plugins/postgres/handler_database_size.go
+++ /dev/null
@@ -1,55 +0,0 @@
-/* /*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// databaseSizeHandler gets info about count and size of archive files and returns JSON if all is OK or nil otherwise.
-func databaseSizeHandler(ctx context.Context, conn PostgresClient,
- _ string, params map[string]string, _ ...string) (interface{}, error) {
- var countSize int64
-
- query := `SELECT pg_database_size(datname::text)
- FROM pg_catalog.pg_database
- WHERE datistemplate = false
- AND datname = $1;`
-
- row, err := conn.QueryRow(ctx, query, params["Database"])
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&countSize)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return countSize, nil
-}
diff --git a/src/go/plugins/postgres/handler_database_size_test.go b/src/go/plugins/postgres/handler_database_size_test.go
deleted file mode 100644
index 52970058d3d..00000000000
--- a/src/go/plugins/postgres/handler_database_size_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_databasesSizeHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("databaseSizeHandler should return size of each database "),
- &impl,
- args{context.Background(), sharedPool, keyDatabaseSize, testParamDatabase, []string{}},
-
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := databaseSizeHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.databaseSizeHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_databases_bloating.go b/src/go/plugins/postgres/handler_databases_bloating.go
deleted file mode 100644
index c865cf68ad0..00000000000
--- a/src/go/plugins/postgres/handler_databases_bloating.go
+++ /dev/null
@@ -1,55 +0,0 @@
-/* /*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// databasesBloatingHandler gets info about count and size of archive files and returns JSON if all is OK or nil otherwise.
-func databasesBloatingHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var countBloating int64
-
- query := `SELECT count(*)
- FROM pg_catalog.pg_stat_all_tables
- WHERE (n_dead_tup/(n_live_tup+n_dead_tup)::float8) > 0.2
- AND (n_live_tup+n_dead_tup) > 50;`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&countBloating)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return countBloating, nil
-}
diff --git a/src/go/plugins/postgres/handler_databases_bloating_test.go b/src/go/plugins/postgres/handler_databases_bloating_test.go
deleted file mode 100644
index 14e9e0d4f5a..00000000000
--- a/src/go/plugins/postgres/handler_databases_bloating_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_databasesBloatingHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("databasesBloatingHandler should return size of bloating tables for each database "),
- &impl,
- args{context.Background(), sharedPool, keyDatabasesBloating, nil, []string{}},
-
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := databasesBloatingHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.databaseBloatingHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_databases_discovery.go b/src/go/plugins/postgres/handler_databases_discovery.go
deleted file mode 100644
index 2010cd79377..00000000000
--- a/src/go/plugins/postgres/handler_databases_discovery.go
+++ /dev/null
@@ -1,55 +0,0 @@
-/* /*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// databasesDiscoveryHandler gets names of all databases and returns JSON if all is OK or nil otherwise.
-func databasesDiscoveryHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var databasesJSON string
-
- query := `SELECT json_build_object ('data',json_agg(json_build_object('{#DBNAME}',d.datname)))
- FROM pg_database d
- WHERE NOT datistemplate
- AND datallowconn;`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&databasesJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return databasesJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_databases_discovery_test.go b/src/go/plugins/postgres/handler_databases_discovery_test.go
deleted file mode 100644
index 2abc7937a0c..00000000000
--- a/src/go/plugins/postgres/handler_databases_discovery_test.go
+++ /dev/null
@@ -1,71 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_databasesDiscoveryHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("databasesDiscoveryHandler should return JSON with data if OK "),
- &impl,
- args{context.Background(), sharedPool, keyDatabasesDiscovery, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
-
- got, err := databasesDiscoveryHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.databaseDiscoveryHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
-
- if len(got.(string)) == 0 {
- t.Errorf("Plugin.databaseDiscoveryHandler() = %v", got)
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_dbstat.go b/src/go/plugins/postgres/handler_dbstat.go
deleted file mode 100644
index 0818ab83569..00000000000
--- a/src/go/plugins/postgres/handler_dbstat.go
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
- "fmt"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-const pgVersionWithChecksum = 120000
-
-// dbStatHandler executes select from pg_catalog.pg_stat_database
-// command for each database and returns JSON if all is OK or nil otherwise.
-func dbStatHandler(ctx context.Context, conn PostgresClient,
- key string, _ map[string]string, _ ...string) (interface{}, error) {
- var statJSON, query string
-
- switch key {
- case keyDBStatSum:
- query = `
- SELECT row_to_json (T)
- FROM (
- SELECT
- sum(numbackends) as numbackends
- , sum(xact_commit) as xact_commit
- , sum(xact_rollback) as xact_rollback
- , sum(blks_read) as blks_read
- , sum(blks_hit) as blks_hit
- , sum(tup_returned) as tup_returned
- , sum(tup_fetched) as tup_fetched
- , sum(tup_inserted) as tup_inserted
- , sum(tup_updated) as tup_updated
- , sum(tup_deleted) as tup_deleted
- , sum(conflicts) as conflicts
- , sum(temp_files) as temp_files
- , sum(temp_bytes) as temp_bytes
- , sum(deadlocks) as deadlocks
- , %s as checksum_failures
- , sum(blk_read_time) as blk_read_time
- , sum(blk_write_time) as blk_write_time
- FROM pg_catalog.pg_stat_database
- ) T ;`
- if conn.PostgresVersion() >= pgVersionWithChecksum {
- query = fmt.Sprintf(query, "sum(COALESCE(checksum_failures, 0))")
- } else {
- query = fmt.Sprintf(query, "null")
- }
-
- case keyDBStat:
- query = `
- SELECT json_object_agg(coalesce (datname,'null'), row_to_json(T))
- FROM (
- SELECT
- datname
- , numbackends as numbackends
- , xact_commit as xact_commit
- , xact_rollback as xact_rollback
- , blks_read as blks_read
- , blks_hit as blks_hit
- , tup_returned as tup_returned
- , tup_fetched as tup_fetched
- , tup_inserted as tup_inserted
- , tup_updated as tup_updated
- , tup_deleted as tup_deleted
- , conflicts as conflicts
- , temp_files as temp_files
- , temp_bytes as temp_bytes
- , deadlocks as deadlocks
- , %s as checksum_failures
- , blk_read_time as blk_read_time
- , blk_write_time as blk_write_time
- FROM pg_catalog.pg_stat_database
- ) T ;`
- if conn.PostgresVersion() >= pgVersionWithChecksum {
- query = fmt.Sprintf(query, "COALESCE(checksum_failures, 0)")
- } else {
- query = fmt.Sprintf(query, "null")
- }
- }
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&statJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return statJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_dbstat_test.go b/src/go/plugins/postgres/handler_dbstat_test.go
deleted file mode 100644
index 6383a295f39..00000000000
--- a/src/go/plugins/postgres/handler_dbstat_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_dbStatHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("dbStatHandler should return json with data for pgsql.dbstat.sum key if OK"),
- &impl,
- args{context.Background(), sharedPool, keyDBStatSum, nil, []string{}},
- false,
- },
- {
- fmt.Sprintf("dbStatHandler should return json with data for pgsql.dbstat key if OK"),
- &impl,
- args{context.Background(), sharedPool, keyDBStat, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := dbStatHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.statHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_locks.go b/src/go/plugins/postgres/handler_locks.go
deleted file mode 100644
index 1dfba036d9e..00000000000
--- a/src/go/plugins/postgres/handler_locks.go
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
-)
-
-// locksHandler executes select from pg_stat_database command and returns JSON if all is OK or nil otherwise.
-func locksHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var locksJSON string
-
- query := `
-WITH T AS
- (SELECT db.datname dbname,
- lower(replace(Q.mode, 'Lock', '')) AS MODE,
- coalesce(T.qty, 0) val
- FROM pg_database db
- JOIN (
- VALUES ('AccessShareLock') ,('RowShareLock') ,('RowExclusiveLock') ,('ShareUpdateExclusiveLock') ,('ShareLock') ,('ShareRowExclusiveLock') ,('ExclusiveLock') ,('AccessExclusiveLock')) Q(MODE) ON TRUE NATURAL
- LEFT JOIN
- (SELECT datname,
- MODE,
- count(MODE) qty
- FROM pg_locks lc
- RIGHT JOIN pg_database db ON db.oid = lc.database
- GROUP BY 1, 2) T
- WHERE NOT db.datistemplate
- ORDER BY 1, 2)
-SELECT json_object_agg(dbname, row_to_json(T2))
-FROM
- (SELECT dbname,
- sum(val) AS total,
- sum(CASE
- WHEN MODE = 'accessexclusive' THEN val
- END) AS accessexclusive,
- sum(CASE
- WHEN MODE = 'accessshare' THEN val
- END) AS accessshare,
- sum(CASE
- WHEN MODE = 'exclusive' THEN val
- END) AS EXCLUSIVE,
- sum(CASE
- WHEN MODE = 'rowexclusive' THEN val
- END) AS rowexclusive,
- sum(CASE
- WHEN MODE = 'rowshare' THEN val
- END) AS rowshare,
- sum(CASE
- WHEN MODE = 'share' THEN val
- END) AS SHARE,
- sum(CASE
- WHEN MODE = 'sharerowexclusive' THEN val
- END) AS sharerowexclusive,
- sum(CASE
- WHEN MODE = 'shareupdateexclusive' THEN val
- END) AS shareupdateexclusive
- FROM T
- GROUP BY dbname) T2`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&locksJSON)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- if len(locksJSON) == 0 {
- return nil, errors.New("cannot parse data")
- }
-
- return locksJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_locks_test.go b/src/go/plugins/postgres/handler_locks_test.go
deleted file mode 100644
index 5d076fa074c..00000000000
--- a/src/go/plugins/postgres/handler_locks_test.go
+++ /dev/null
@@ -1,74 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
- "fmt"
- "testing"
-)
-
-func TestPlugin_locksHandler(t *testing.T) {
-
- // create pool or acquire conn from old pool for test
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("Plugin.locksHandler() should return ptr to Pool for Plugin.locksHandler()"),
- &impl,
- args{context.Background(), sharedPool, keyLocks, nil, []string{}},
-
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- got, err := locksHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.locksHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if len(got.(string)) == 0 && err != errors.New("cannot parse data") {
- t.Errorf("Plugin.locksHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_oldest_xid.go b/src/go/plugins/postgres/handler_oldest_xid.go
deleted file mode 100644
index 4140fd6fde1..00000000000
--- a/src/go/plugins/postgres/handler_oldest_xid.go
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// oldestXIDHandler gets age of the oldest xid if all is OK or nil otherwise.
-func oldestXIDHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var resultXID int64
-
- query := `SELECT greatest(max(age(backend_xmin)), max(age(backend_xid)))
- FROM pg_catalog.pg_stat_activity`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&resultXID)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return resultXID, nil
-}
diff --git a/src/go/plugins/postgres/handler_oldest_xid_test.go b/src/go/plugins/postgres/handler_oldest_xid_test.go
deleted file mode 100644
index 36fe7e35714..00000000000
--- a/src/go/plugins/postgres/handler_oldest_xid_test.go
+++ /dev/null
@@ -1,71 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_oldestHandler(t *testing.T) {
-
- // create pool or acquire conn from old pool for test
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("oldestXIDHandler() should return ptr to Pool for oldestXIDHandler()"),
- &impl,
- args{context.Background(), sharedPool, keyOldestXid, nil, []string{}},
-
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := oldestXIDHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.oldestXIDHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
-
- })
- }
-
-}
diff --git a/src/go/plugins/postgres/handler_ping.go b/src/go/plugins/postgres/handler_ping.go
deleted file mode 100644
index 04018cb4da4..00000000000
--- a/src/go/plugins/postgres/handler_ping.go
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
-)
-
-const (
- pingFailed = 0
- pingOk = 1
-)
-
-// pingHandler queries 'SELECT 1' and returns pingOk if a connection is alive or pingFailed otherwise.
-func pingHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var res int
-
- row, err := conn.QueryRow(ctx, fmt.Sprintf("SELECT %d", pingOk))
- if err != nil {
- return pingFailed, nil
- }
-
- err = row.Scan(&res)
-
- if err != nil || res != pingOk {
- return pingFailed, nil
- }
-
- return pingOk, nil
-}
diff --git a/src/go/plugins/postgres/handler_ping_test.go b/src/go/plugins/postgres/handler_ping_test.go
deleted file mode 100755
index 98d70b03fe6..00000000000
--- a/src/go/plugins/postgres/handler_ping_test.go
+++ /dev/null
@@ -1,73 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "reflect"
- "testing"
-)
-
-func TestPlugin_pingHandler(t *testing.T) {
- // create pool or acquire conn from old pool for test
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- want interface{}
- wantErr bool
- }{
- {
- fmt.Sprintf("pingHandler should return %d if connection is ok", pingOk),
- &impl,
- args{context.Background(), sharedPool, keyPing, nil, []string{}},
- pingOk,
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- got, err := pingHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.pingHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("Plugin.pingHandler() = %v, want %v", got, tt.want)
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_queries.go b/src/go/plugins/postgres/handler_queries.go
deleted file mode 100644
index 6ce96cc1c63..00000000000
--- a/src/go/plugins/postgres/handler_queries.go
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "strconv"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
-)
-
-// queriesHandler executes select from pg_database command and returns JSON if all is OK or nil otherwise.
-func queriesHandler(ctx context.Context, conn PostgresClient,
- _ string, params map[string]string, _ ...string) (interface{}, error) {
- var queriesJSON string
-
- period, err := strconv.Atoi(params["TimePeriod"])
- if err != nil {
- return nil, zbxerr.ErrorInvalidParams.Wrap(
- fmt.Errorf("TimePeriod must be an integer, %s", err.Error()),
- )
- }
-
- if period < 1 {
- return nil, zbxerr.ErrorInvalidParams.Wrap(
- fmt.Errorf("TimePeriod must be greater than 0"),
- )
- }
-
- exp := `^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)`
- query := fmt.Sprintf(`WITH T AS (
- SELECT
- db.datname,
- coalesce(T.query_time_max, 0) query_time_max,
- coalesce(T.tx_time_max, 0) tx_time_max,
- coalesce(T.mro_time_max, 0) mro_time_max,
- coalesce(T.query_time_sum, 0) query_time_sum,
- coalesce(T.tx_time_sum, 0) tx_time_sum,
- coalesce(T.mro_time_sum, 0) mro_time_sum,
- coalesce(T.query_slow_count, 0) query_slow_count,
- coalesce(T.tx_slow_count, 0) tx_slow_count,
- coalesce(T.mro_slow_count, 0) mro_slow_count
- FROM
- pg_database db NATURAL
- LEFT JOIN (
- SELECT
- datname,
- extract(
- epoch
- FROM
- now()
- ) :: integer ts,
- coalesce(
- max(
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) :: integer * (
- state NOT IN (
- 'idle',
- 'idle in transaction',
- 'idle in transaction (aborted)'
- )
- AND query !~* E'%s'
- ) :: integer
- ),
- 0
- ) query_time_max,
- coalesce(
- max(
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) :: integer * (
- state NOT IN ('idle')
- AND query !~* E'%s'
- ) :: integer
- ),
- 0
- ) tx_time_max,
- coalesce(
- max(
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) :: integer * (
- state NOT IN ('idle')
- AND query ~* E'%s'
- ) :: integer
- ),
- 0
- ) mro_time_max,
- coalesce(
- sum(
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) :: integer * (
- state NOT IN (
- 'idle',
- 'idle in transaction',
- 'idle in transaction (aborted)'
- )
- AND query !~* E'%s'
- ) :: integer
- ),
- 0
- ) query_time_sum,
- coalesce(
- sum(
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) :: integer * (
- state NOT IN ('idle')
- AND query !~* E'%s'
- ) :: integer
- ),
- 0
- ) tx_time_sum,
- coalesce(
- sum(
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) :: integer * (
- state NOT IN ('idle')
- AND query ~* E'%s'
- ) :: integer
- ),
- 0
- ) mro_time_sum,
- coalesce(
- sum(
- (
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) > % d
- ) :: integer * (
- state NOT IN (
- 'idle',
- 'idle in transaction',
- 'idle in transaction (aborted)'
- )
- AND query !~* E'%s'
- ) :: integer
- ),
- 0
- ) query_slow_count,
- coalesce(
- sum(
- (
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) > % d
- ) :: integer * (
- state NOT IN ('idle')
- AND query !~* E'%s'
- ) :: integer
- ),
- 0
- ) tx_slow_count,
- coalesce(
- sum(
- (
- extract(
- 'epoch'
- FROM
- (clock_timestamp() - query_start)
- ) > % d
- ) :: integer * (
- state NOT IN ('idle')
- AND query ~* E'%s'
- ) :: integer
- ),
- 0
- ) mro_slow_count
- FROM
- pg_stat_activity
- WHERE
- pid <> pg_backend_pid()
- GROUP BY
- 1
- ) T
- WHERE
- NOT db.datistemplate
- )
- SELECT
- json_object_agg(datname, row_to_json(T))
- FROM
- T`,
- exp, exp, exp, exp, exp, exp, period, exp, period, exp, period, exp)
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&queriesJSON)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- if len(queriesJSON) == 0 {
- return nil, zbxerr.ErrorCannotParseResult
- }
-
- return queriesJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_queries_test.go b/src/go/plugins/postgres/handler_queries_test.go
deleted file mode 100644
index df8cca0f249..00000000000
--- a/src/go/plugins/postgres/handler_queries_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
- "fmt"
- "testing"
-)
-
-func TestPlugin_queriesHandler(t *testing.T) {
- // create pool or acquire conn from old pool for test
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("Plugin.queriesHandler() should return ptr to Pool for Plugin.queriesHandler()"),
- &impl,
- args{context.Background(), sharedPool, keyQueries, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- got, err := queriesHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.queriesHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if len(got.(string)) == 0 && err != errors.New("cannot parse data") {
- t.Errorf("Plugin.queriesHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_replication.go b/src/go/plugins/postgres/handler_replication.go
deleted file mode 100644
index 8bd2aaebfe1..00000000000
--- a/src/go/plugins/postgres/handler_replication.go
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "database/sql"
- "errors"
- "strconv"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// replicationHandler gets info about recovery state if all is OK or nil otherwise.
-func replicationHandler(ctx context.Context, conn PostgresClient,
- key string, _ map[string]string, _ ...string) (interface{}, error) {
- var (
- replicationResult int64
- status int
- query string
- stringResult sql.NullString
- inRecovery bool
- )
-
- switch key {
- case keyReplicationStatus:
- row, err := conn.QueryRow(ctx, `SELECT pg_is_in_recovery()`)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&inRecovery)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- if inRecovery {
- row, err = conn.QueryRow(ctx, `SELECT COUNT(*) FROM pg_stat_wal_receiver`)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&status)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
- } else {
- status = 2
- }
-
- return strconv.Itoa(status), nil
-
- case keyReplicationLagSec:
- query = `SELECT
- CASE
- WHEN NOT pg_is_in_recovery() OR pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0
- ELSE COALESCE(EXTRACT(EPOCH FROM now() - pg_last_xact_replay_timestamp())::integer, 0)
- END AS lag;`
- case keyReplicationLagB:
- row, err := conn.QueryRow(ctx, `SELECT pg_is_in_recovery()`)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&inRecovery)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- if inRecovery {
- query = `SELECT pg_catalog.pg_wal_lsn_diff (pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn());`
- row, err = conn.QueryRow(ctx, query)
-
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&replicationResult)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
- } else {
- replicationResult = 0
- }
-
- return replicationResult, nil
-
- case keyReplicationRecoveryRole:
- query = `SELECT pg_is_in_recovery()::int`
-
- case keyReplicationCount:
- query = `SELECT COUNT(DISTINCT client_addr) + COALESCE(SUM(CASE WHEN client_addr IS NULL THEN 1 ELSE 0 END), 0) FROM pg_stat_replication;`
-
- case keyReplicationProcessInfo:
- query = `SELECT json_object_agg(application_name, row_to_json(T))
- FROM (
- SELECT
- application_name,
- EXTRACT(epoch FROM COALESCE(flush_lag,'0'::interval)) AS flush_lag,
- EXTRACT(epoch FROM COALESCE(replay_lag,'0'::interval)) AS replay_lag,
- EXTRACT(epoch FROM COALESCE(write_lag, '0'::interval)) AS write_lag
- FROM pg_stat_replication
- ) T; `
- row, err := conn.QueryRow(ctx, query)
-
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&stringResult)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return stringResult.String, nil
- }
-
- row, err := conn.QueryRow(ctx, query)
-
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&replicationResult)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return replicationResult, nil
-}
diff --git a/src/go/plugins/postgres/handler_replication_process_name_discovery.go b/src/go/plugins/postgres/handler_replication_process_name_discovery.go
deleted file mode 100644
index 8fe5d3302c3..00000000000
--- a/src/go/plugins/postgres/handler_replication_process_name_discovery.go
+++ /dev/null
@@ -1,55 +0,0 @@
-/* /*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// processNameDiscoveryHandler gets names of all sender processes in pg_stat_replication
-// and returns JSON if all is OK or nil otherwise.
-func processNameDiscoveryHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var appNameJSON string
-
- query := `SELECT
- json_build_object('data',COALESCE(json_agg(json_build_object('{#APPLICATION_NAME}',application_name)), '[]'))
- FROM pg_stat_replication`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&appNameJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return appNameJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_replication_test.go b/src/go/plugins/postgres/handler_replication_test.go
deleted file mode 100644
index 004570385ce..00000000000
--- a/src/go/plugins/postgres/handler_replication_test.go
+++ /dev/null
@@ -1,106 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_replicationHandler(t *testing.T) {
- // create pool or acquire conn from old pool
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("replicationHandler should return ptr to Pool for replication.count"),
- &impl,
- args{context.Background(), sharedPool, keyReplicationCount, nil, []string{}},
- false,
- },
- {
- fmt.Sprintf("replicationHandler should return ptr to Pool for replication.status"),
- &impl,
- args{context.Background(), sharedPool, keyReplicationStatus, nil, []string{}},
- false,
- },
- {
- fmt.Sprintf("replicationHandler should return ptr to Pool for replication.lag.sec"),
- &impl,
- args{context.Background(), sharedPool, keyReplicationLagSec, nil, []string{}},
- false,
- },
- {
- fmt.Sprintf("replicationHandler should return ptr to Pool for replication.lag.b"),
- &impl,
- args{context.Background(), sharedPool, keyReplicationLagB, nil, []string{}},
- false,
- },
- {
- fmt.Sprintf("replicationHandler should return ptr to Pool for replication.recovery_role"),
- &impl,
- args{context.Background(), sharedPool, keyReplicationRecoveryRole, nil, []string{}},
- false,
- },
- {
- fmt.Sprintf("replicationHandler should return ptr to Pool for replication.master.discovery.application_name"),
- &impl,
- args{context.Background(), sharedPool, keyReplicationMasterDiscoveryAppName, nil, []string{}},
- false,
- },
- }
-
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- got, err := replicationHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.replicationHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if tt.wantErr == false {
- if tt.args.key == keyReplicationStatus || tt.args.key == keyReplicationMasterDiscoveryAppName {
- if len(got.(string)) == 0 {
- t.Errorf("Plugin.replicationTransactions() at DeepEqual error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- }
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_uptime.go b/src/go/plugins/postgres/handler_uptime.go
deleted file mode 100644
index 23f6979be5d..00000000000
--- a/src/go/plugins/postgres/handler_uptime.go
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// uptimeHandler finds difference btw current time and
-// postmaster start time and returns int64 if all is OK or nil otherwise.
-func uptimeHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var uptime float64
-
- query := `SELECT date_part('epoch', now() - pg_postmaster_start_time());`
- row, err := conn.QueryRow(ctx, query)
-
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&uptime)
-
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return uptime, nil
-}
diff --git a/src/go/plugins/postgres/handler_uptime_test.go b/src/go/plugins/postgres/handler_uptime_test.go
deleted file mode 100644
index eabc6e7c787..00000000000
--- a/src/go/plugins/postgres/handler_uptime_test.go
+++ /dev/null
@@ -1,66 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_uptimeHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("uptimeHandler should return json with data if OK"),
- &impl,
- args{context.Background(), sharedPool, keyUptime, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := uptimeHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.uptimeHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/handler_wal.go b/src/go/plugins/postgres/handler_wal.go
deleted file mode 100644
index 822234f4125..00000000000
--- a/src/go/plugins/postgres/handler_wal.go
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
-
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "github.com/jackc/pgx/v4"
-)
-
-// walHandler executes select from directory which contains wal files and returns JSON if all is OK or nil otherwise.
-func walHandler(ctx context.Context, conn PostgresClient,
- _ string, _ map[string]string, _ ...string) (interface{}, error) {
- var walJSON string
-
- query := `SELECT row_to_json(T)
- FROM (
- SELECT
- CASE
- WHEN pg_is_in_recovery() THEN 0
- ELSE pg_wal_lsn_diff(pg_current_wal_lsn(),'0/00000000')
- END AS WRITE,
- CASE
- WHEN NOT pg_is_in_recovery() THEN 0
- ELSE pg_wal_lsn_diff(pg_last_wal_receive_lsn(),'0/00000000')
- END AS RECEIVE,
- count(*)
- FROM pg_ls_waldir() AS COUNT
- ) T;`
-
- row, err := conn.QueryRow(ctx, query)
- if err != nil {
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- err = row.Scan(&walJSON)
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, zbxerr.ErrorEmptyResult.Wrap(err)
- }
-
- return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
- }
-
- return walJSON, nil
-}
diff --git a/src/go/plugins/postgres/handler_wal_test.go b/src/go/plugins/postgres/handler_wal_test.go
deleted file mode 100644
index dede50f710f..00000000000
--- a/src/go/plugins/postgres/handler_wal_test.go
+++ /dev/null
@@ -1,66 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "fmt"
- "testing"
-)
-
-func TestPlugin_walHandler(t *testing.T) {
- sharedPool, err := getConnPool()
- if err != nil {
- t.Fatal(err)
- }
-
- type args struct {
- ctx context.Context
- conn *PGConn
- key string
- params map[string]string
- extraParams []string
- }
- tests := []struct {
- name string
- p *Plugin
- args args
- wantErr bool
- }{
- {
- fmt.Sprintf("walHandler should return json with data if OK"),
- &impl,
- args{context.Background(), sharedPool, keyWal, nil, []string{}},
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := walHandler(tt.args.ctx, tt.args.conn, tt.args.key, tt.args.params, tt.args.extraParams...)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.walHandler() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
diff --git a/src/go/plugins/postgres/metrics.go b/src/go/plugins/postgres/metrics.go
deleted file mode 100644
index 3654ef90720..00000000000
--- a/src/go/plugins/postgres/metrics.go
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "errors"
- "fmt"
- "regexp"
- "strings"
-
- "git.zabbix.com/ap/plugin-support/metric"
- "git.zabbix.com/ap/plugin-support/plugin"
- "git.zabbix.com/ap/plugin-support/uri"
-)
-
-const (
- keyArchiveSize = "pgsql.archive"
- keyAutovacuum = "pgsql.autovacuum.count"
- keyBgwriter = "pgsql.bgwriter"
- keyCache = "pgsql.cache.hit"
- keyConnections = "pgsql.connections"
- keyCustomQuery = "pgsql.custom.query"
- keyDBStat = "pgsql.dbstat"
- keyDBStatSum = "pgsql.dbstat.sum"
- keyDatabaseAge = "pgsql.db.age"
- keyDatabasesBloating = "pgsql.db.bloating_tables"
- keyDatabasesDiscovery = "pgsql.db.discovery"
- keyDatabaseSize = "pgsql.db.size"
- keyLocks = "pgsql.locks"
- keyOldestXid = "pgsql.oldest.xid"
- keyPing = "pgsql.ping"
- keyQueries = "pgsql.queries"
- keyReplicationCount = "pgsql.replication.count"
- keyReplicationLagB = "pgsql.replication.lag.b"
- keyReplicationLagSec = "pgsql.replication.lag.sec"
- keyReplicationProcessInfo = "pgsql.replication.process"
- keyReplicationProcessNameDiscovery = "pgsql.replication.process.discovery"
- keyReplicationRecoveryRole = "pgsql.replication.recovery_role"
- keyReplicationStatus = "pgsql.replication.status"
- keyUptime = "pgsql.uptime"
- keyWal = "pgsql.wal.stat"
-)
-
-// handlerFunc defines an interface must be implemented by handlers.
-type handlerFunc func(ctx context.Context, conn PostgresClient, key string,
- params map[string]string, extraParams ...string) (res interface{}, err error)
-
-// getHandlerFunc returns a handlerFunc related to a given key.
-func getHandlerFunc(key string) handlerFunc {
- switch key {
- case keyDatabasesDiscovery:
- return databasesDiscoveryHandler
- case keyDatabasesBloating:
- return databasesBloatingHandler
- case keyDatabaseSize:
- return databaseSizeHandler
- case keyDatabaseAge:
- return databaseAgeHandler
- case keyArchiveSize:
- return archiveHandler
- case keyPing:
- return pingHandler
- case keyConnections:
- return connectionsHandler
- case keyWal:
- return walHandler
- case keyAutovacuum:
- return autovacuumHandler
- case keyDBStat,
- keyDBStatSum:
- return dbStatHandler
- case keyBgwriter:
- return bgwriterHandler
- case keyCustomQuery:
- return customQueryHandler
- case keyUptime:
- return uptimeHandler
- case keyCache:
- return cacheHandler
- case keyReplicationCount,
- keyReplicationStatus,
- keyReplicationLagSec,
- keyReplicationRecoveryRole,
- keyReplicationLagB,
- keyReplicationProcessInfo:
- return replicationHandler
- case keyReplicationProcessNameDiscovery:
- return processNameDiscoveryHandler
- case keyLocks:
- return locksHandler
- case keyOldestXid:
- return oldestXIDHandler
- case keyQueries:
- return queriesHandler
- default:
- return nil
- }
-}
-
-var uriDefaults = &uri.Defaults{Scheme: "tcp", Port: "5432"}
-
-var (
- minDBNameLen = 1
- maxDBNameLen = 63
- maxPassLen = 512
-)
-
-type PostgresURIValidator struct {
- Defaults *uri.Defaults
- AllowedSchemes []string
-}
-
-var reSocketPath = regexp.MustCompile(`^.*\.s\.PGSQL\.\d{1,5}$`)
-
-func (v PostgresURIValidator) Validate(value *string) error {
- if value == nil {
- return nil
- }
-
- u, err := uri.New(*value, v.Defaults)
- if err != nil {
- return err
- }
-
- isValidScheme := false
- if v.AllowedSchemes != nil {
- for _, s := range v.AllowedSchemes {
- if u.Scheme() == s {
- isValidScheme = true
- break
- }
- }
-
- if !isValidScheme {
- return fmt.Errorf("allowed schemes: %s", strings.Join(v.AllowedSchemes, ", "))
- }
- }
-
- if u.Scheme() == "unix" && !reSocketPath.MatchString(*value) {
- return errors.New(
- `socket file must satisfy the format: "/path/.s.PGSQL.nnnn" where nnnn is the server's port number`)
- }
-
- return nil
-}
-
-// Common params: [URI|Session][,User][,Password][,Database]
-var (
- paramURI = metric.NewConnParam("URI", "URI to connect or session name.").
- WithDefault(uriDefaults.Scheme + "://localhost:" + uriDefaults.Port).WithSession().
- WithValidator(PostgresURIValidator{
- Defaults: uriDefaults,
- AllowedSchemes: []string{"tcp", "postgresql", "unix"},
- })
- paramUsername = metric.NewConnParam("User", "PostgreSQL user.").WithDefault("postgres")
- paramPassword = metric.NewConnParam("Password", "User's password.").WithDefault("").
- WithValidator(metric.LenValidator{Max: &maxPassLen})
- paramDatabase = metric.NewConnParam("Database", "Database name to be used for connection.").
- WithDefault("postgres").WithValidator(metric.LenValidator{Min: &minDBNameLen, Max: &maxDBNameLen})
- paramTLSConnect = metric.NewSessionOnlyParam("TLSConnect", "DB connection encryption type.").WithDefault("")
- paramTLSCaFile = metric.NewSessionOnlyParam("TLSCAFile", "TLS ca file path.").WithDefault("")
- paramTLSCertFile = metric.NewSessionOnlyParam("TLSCertFile", "TLS cert file path.").WithDefault("")
- paramTLSKeyFile = metric.NewSessionOnlyParam("TLSKeyFile", "TLS key file path.").WithDefault("")
-)
-
-var metrics = metric.MetricSet{
- keyArchiveSize: metric.New("Returns info about size of archive files.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyAutovacuum: metric.New("Returns count of autovacuum workers.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyBgwriter: metric.New("Returns JSON for sum of each type of bgwriter statistic.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyCache: metric.New("Returns cache hit percent.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyConnections: metric.New("Returns JSON for sum of each type of connection.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyCustomQuery: metric.New("Returns result of a custom query.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase,
- metric.NewParam("QueryName", "Name of a custom query "+
- "(must be equal to a name of an SQL file without an extension).").SetRequired(),
- paramTLSConnect, paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, true),
-
- keyDBStat: metric.New("Returns JSON for sum of each type of statistic.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyDBStatSum: metric.New("Returns JSON for sum of each type of statistic for all database.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyDatabaseAge: metric.New("Returns age for specific database.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyDatabasesBloating: metric.New("Returns percent of bloating tables for each database.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyDatabasesDiscovery: metric.New("Returns JSON discovery rule with names of databases.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyDatabaseSize: metric.New("Returns size in bytes for specific database.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyLocks: metric.New("Returns collect all metrics from pg_locks.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyOldestXid: metric.New("Returns age of oldest xid.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyPing: metric.New("Tests if connection is alive or not.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyQueries: metric.New("Returns queries statistic.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase,
- metric.NewParam("TimePeriod", "Execution time limit for count of slow queries.").SetRequired(),
- paramTLSConnect, paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyReplicationCount: metric.New("Returns number of standby servers.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyReplicationLagB: metric.New("Returns replication lag with Master in byte.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyReplicationLagSec: metric.New("Returns replication lag with Master in seconds.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyReplicationProcessNameDiscovery: metric.New("Returns JSON with application name from pg_stat_replication.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyReplicationProcessInfo: metric.New("Returns flush lag, write lag and replay lag per each sender process.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyReplicationRecoveryRole: metric.New("Returns postgreSQL recovery role.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyReplicationStatus: metric.New("Returns postgreSQL replication status.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyUptime: metric.New("Returns uptime.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-
- keyWal: metric.New("Returns JSON wal by type.",
- []*metric.Param{paramURI, paramUsername, paramPassword, paramDatabase, paramTLSConnect,
- paramTLSCaFile, paramTLSCertFile, paramTLSKeyFile}, false),
-}
-
-func init() {
- plugin.RegisterMetrics(&impl, pluginName, metrics.List()...)
-}
diff --git a/src/go/plugins/postgres/postgres.go b/src/go/plugins/postgres/postgres.go
deleted file mode 100755
index c4031facccc..00000000000
--- a/src/go/plugins/postgres/postgres.go
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "context"
- "net/http"
- "net/url"
- "time"
-
- "git.zabbix.com/ap/plugin-support/uri"
- "git.zabbix.com/ap/plugin-support/zbxerr"
- "zabbix.com/pkg/tlsconfig"
-
- "github.com/omeid/go-yarn"
-
- "git.zabbix.com/ap/plugin-support/plugin"
-)
-
-const (
- pluginName = "Postgres"
- sqlExt = ".sql"
- hkInterval = 10
-)
-
-// Plugin inherits plugin.Base and store plugin-specific data.
-type Plugin struct {
- plugin.Base
- connMgr *ConnManager
- options PluginOptions
-}
-
-// impl is the pointer to the plugin implementation.
-var impl Plugin
-
-// Export implements the Exporter interface.
-func (p *Plugin) Export(key string, rawParams []string, _ plugin.ContextProvider) (result interface{}, err error) {
- params, extraParams, err := metrics[key].EvalParams(rawParams, p.options.Sessions)
- if err != nil {
- return nil, err
- }
-
- details, err := tlsconfig.CreateDetails(params["sessionName"], params["TLSConnect"],
- params["TLSCAFile"], params["TLSCertFile"], params["TLSKeyFile"], params["URI"])
- if err != nil {
- return nil, zbxerr.ErrorInvalidConfiguration.Wrap(err)
- }
-
- dbname := url.QueryEscape(params["Database"])
-
- uri, err := uri.NewWithCreds(params["URI"]+"?dbname="+dbname, params["User"], params["Password"], uriDefaults)
- if err != nil {
- return nil, err
- }
-
- handleMetric := getHandlerFunc(key)
- if handleMetric == nil {
- return nil, zbxerr.ErrorUnsupportedMetric
- }
-
- conn, err := p.connMgr.GetConnection(*uri, details)
- if err != nil {
- // Special logic of processing connection errors should be used if pgsql.ping is requested
- // because it must return pingFailed if any error occurred.
- if key == keyPing {
- return pingFailed, nil
- }
-
- p.Errf(err.Error())
-
- return nil, err
- }
-
- ctx, cancel := context.WithTimeout(conn.ctx, conn.callTimeout)
- defer cancel()
-
- result, err = handleMetric(ctx, conn, key, params, extraParams...)
-
- if err != nil {
- p.Errf(err.Error())
- }
-
- return result, err
-}
-
-// Start implements the Runner interface and performs initialization when plugin is activated.
-func (p *Plugin) Start() {
- queryStorage, err := yarn.New(http.Dir(p.options.CustomQueriesPath), "*"+sqlExt)
- if err != nil {
- p.Errf(err.Error())
- // create empty storage if error occurred
- queryStorage = yarn.NewFromMap(map[string]string{})
- }
-
- p.connMgr = NewConnManager(
- time.Duration(p.options.KeepAlive)*time.Second,
- time.Duration(p.options.Timeout)*time.Second,
- time.Duration(p.options.CallTimeout)*time.Second,
- hkInterval*time.Second,
- queryStorage,
- )
-}
-
-// Stop implements the Runner interface and frees resources when plugin is deactivated.
-func (p *Plugin) Stop() {
- p.connMgr.Destroy()
- p.connMgr = nil
-}
diff --git a/src/go/plugins/postgres/postgres_test.go b/src/go/plugins/postgres/postgres_test.go
deleted file mode 100755
index 4255bee0d2d..00000000000
--- a/src/go/plugins/postgres/postgres_test.go
+++ /dev/null
@@ -1,145 +0,0 @@
-//go:build postgres_tests
-// +build postgres_tests
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "os"
- "reflect"
- "testing"
-
- "git.zabbix.com/ap/plugin-support/log"
- "git.zabbix.com/ap/plugin-support/plugin"
- "github.com/omeid/go-yarn"
-)
-
-var testParamDatabase = map[string]string{"Database": "postgres"}
-
-// TestMain does the before and after setup
-func TestMain(m *testing.M) {
- var code int
-
- _ = log.Open(log.Console, log.Debug, "", 0)
-
- log.Infof("[TestMain] Start connecting to PostgreSQL...")
- if err := createConnection(); err != nil {
- log.Infof("failed to create connection to PostgreSQL for tests")
- os.Exit(code)
- }
- // initialize plugin
- impl.Init(pluginName)
- impl.Configure(&plugin.GlobalOptions{Timeout: 30}, nil)
-
- code = m.Run()
- if code != 0 {
- log.Critf("failed to run PostgreSQL tests")
- os.Exit(code)
- }
- log.Infof("[TestMain] Cleaning up...")
- os.Exit(code)
-}
-
-func TestPlugin_Start(t *testing.T) {
- t.Run("Connection manager must be initialized", func(t *testing.T) {
- impl.Start()
- if impl.connMgr == nil {
- t.Error("Connection manager is not initialized")
- }
- })
-}
-
-func TestPlugin_Export(t *testing.T) {
- pgAddr, pgUser, pgPwd, pgDb := getEnv()
-
- type args struct {
- key string
- params []string
- ctx plugin.ContextProvider
- }
-
- //impl.Configure(&plugin.GlobalOptions{Timeout: 30}, nil)
- impl.connMgr.queryStorage = yarn.NewFromMap(map[string]string{
- "TestQuery.sql": "SELECT $1::text AS res",
- })
-
- tests := []struct {
- name string
- p *Plugin
- args args
- wantResult interface{}
- wantErr bool
- }{
- {
- "Check PG Ping",
- &impl,
- args{keyPing, []string{pgAddr, pgUser, pgPwd}, nil},
- pingOk,
- false,
- },
- {
- "Too many parameters",
- &impl,
- args{keyPing, []string{"param1", "param2", "param3", "param4", "param5"}, nil},
- nil,
- true,
- },
- {
- "Check wal handler",
- &impl,
- args{keyWal, []string{pgAddr, pgUser, pgPwd}, nil},
- nil,
- false,
- },
- {
- "Check custom queries handler. Should return 1 as text",
- &impl,
- args{keyCustomQuery, []string{pgAddr, pgUser, pgPwd, pgDb, "TestQuery", "echo"}, nil},
- "[{\"res\":\"echo\"}]",
- false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- gotResult, err := tt.p.Export(tt.args.key, tt.args.params, tt.args.ctx)
- if (err != nil) != tt.wantErr {
- t.Errorf("Plugin.Export() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(gotResult, tt.wantResult) && tt.args.key != keyWal {
- t.Errorf("Plugin.Export() = %v, want %v", gotResult, tt.wantResult)
- }
- if tt.args.key == keyWal && len(gotResult.(string)) == 0 {
- t.Errorf("Plugin.Export() result for keyPostgresWal length is 0")
- }
- })
- }
-
-}
-
-func TestPlugin_Stop(t *testing.T) {
- t.Run("Connection manager must be deinitialized", func(t *testing.T) {
- impl.Stop()
- if impl.connMgr != nil {
- t.Error("Connection manager is not deinitialized")
- }
- })
-}
diff --git a/src/go/plugins/postgres/testpool.go b/src/go/plugins/postgres/testpool.go
deleted file mode 100644
index 79a98afca8e..00000000000
--- a/src/go/plugins/postgres/testpool.go
+++ /dev/null
@@ -1,91 +0,0 @@
-//go:build !windows
-// +build !windows
-
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-package postgres
-
-import (
- "database/sql"
- "fmt"
- "os"
- "time"
-
- "git.zabbix.com/ap/plugin-support/log"
-)
-
-var sharedConn *PGConn
-
-func getConnPool() (*PGConn, error) {
- return sharedConn, nil
-}
-
-func getEnv() (pgAddr, pgUser, pgPwd, pgDb string) {
- pgAddr = os.Getenv("PG_ADDR")
- pgUser = os.Getenv("PG_USER")
- pgPwd = os.Getenv("PG_PWD")
- pgDb = os.Getenv("PG_DB")
-
- if pgAddr == "" {
- pgAddr = "localhost:5432"
- }
- if pgUser == "" {
- pgUser = "postgres"
- }
- if pgPwd == "" {
- pgPwd = "postgres"
- }
- if pgDb == "" {
- pgDb = "postgres"
- }
-
- return
-}
-
-func createConnection() error {
- pgAddr, pgUser, pgPwd, pgDb := getEnv()
-
- connString := fmt.Sprintf("postgresql://%s:%s@%s/%s", pgUser, pgPwd, pgAddr, pgDb)
-
- newConn, err := sql.Open("pgx", connString)
- if err != nil {
- log.Critf("[createConnection] cannot create connection to Postgres: %s", err.Error())
-
- return err
- }
-
- var version int
-
- err = newConn.QueryRow(`select current_setting('server_version_num');`).Scan(&version)
- if err != nil {
- log.Critf("[createConnection] cannot get Postgres version: %s", err.Error())
-
- return err
- }
-
- sharedConn = &PGConn{
- client: newConn,
- lastTimeAccess: time.Now(),
- version: version,
- callTimeout: 30,
- }
-
- return nil
-}
diff --git a/src/libs/Makefile.am b/src/libs/Makefile.am
index a4dc59a644c..9b2cc851f83 100644
--- a/src/libs/Makefile.am
+++ b/src/libs/Makefile.am
@@ -14,6 +14,7 @@ DIST_SUBDIRS = \
zbxdb \
zbxdbcache \
zbxdbhigh \
+ zbxdbwrap \
zbxdbschema \
zbxdbupgrade \
zbxdiag \
@@ -69,6 +70,7 @@ SERVER_SUBDIRS = \
zbxdb \
zbxdbcache \
zbxdbhigh \
+ zbxdbwrap \
zbxdbschema \
zbxdbupgrade \
zbxdiag \
@@ -111,6 +113,7 @@ PROXY_SUBDIRS = \
zbxdb \
zbxdbcache \
zbxdbhigh \
+ zbxdbwrap \
zbxdbschema \
zbxdbupgrade \
zbxdiag \
@@ -180,4 +183,5 @@ SUBDIRS = \
EXTRA_DIST = \
zbxsymbols \
- zbxwin32
+ zbxwin32 \
+ zbxwinservice
diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c
index b4b40971cda..0b61db46efc 100644
--- a/src/libs/zbxcommon/misc.c
+++ b/src/libs/zbxcommon/misc.c
@@ -519,10 +519,10 @@ unsigned char get_interface_type_by_item_type(unsigned char type)
case ITEM_TYPE_EXTERNAL:
case ITEM_TYPE_SSH:
case ITEM_TYPE_TELNET:
- case ITEM_TYPE_SCRIPT:
return INTERFACE_TYPE_ANY;
case ITEM_TYPE_HTTPAGENT:
return INTERFACE_TYPE_OPT;
+ case ITEM_TYPE_SCRIPT:
default:
return INTERFACE_TYPE_UNKNOWN;
}
diff --git a/src/libs/zbxconf/cfg.c b/src/libs/zbxconf/cfg.c
index e1764f5d4a0..792da1d4982 100644
--- a/src/libs/zbxconf/cfg.c
+++ b/src/libs/zbxconf/cfg.c
@@ -25,13 +25,10 @@
extern unsigned char program_type;
-char *CONFIG_FILE = NULL;
-
char *CONFIG_LOG_TYPE_STR = NULL;
int CONFIG_LOG_TYPE = LOG_TYPE_UNDEFINED;
char *CONFIG_LOG_FILE = NULL;
int CONFIG_LOG_FILE_SIZE = 1;
-int CONFIG_ALLOW_ROOT = 0;
int CONFIG_TIMEOUT = 3;
static int __parse_cfg_file(const char *cfg_file, struct cfg_line *cfg, int level, int optional, int strict,
diff --git a/src/libs/zbxdb/db.c b/src/libs/zbxdb/db.c
index 42db53433c2..883c8586f0c 100644
--- a/src/libs/zbxdb/db.c
+++ b/src/libs/zbxdb/db.c
@@ -2594,6 +2594,9 @@ void zbx_db_version_json_create(struct zbx_json *json, struct zbx_db_version_inf
{
zbx_json_addstring(json, "compression_availability", "false", ZBX_JSON_TYPE_INT);
}
+
+ zbx_json_addint64(json, "compressed_chunks_history", info->history_compressed_chunks);
+ zbx_json_addint64(json, "compressed_chunks_trends", info->trends_compressed_chunks);
}
#endif
zbx_json_close(json);
@@ -2868,6 +2871,59 @@ out:
}
#ifdef HAVE_POSTGRESQL
+static int zbx_tsdb_table_has_compressed_chunks(const char *table_names)
+{
+ DB_RESULT result;
+ int ret;
+
+ if (1 == ZBX_DB_TSDB_V1) {
+ result = zbx_db_select("select null from timescaledb_information.compressed_chunk_stats where hypertable_name in (%s) and "
+ "compression_status='Compressed'", table_names);
+ }
+ else
+ {
+ result = zbx_db_select("select null from timescaledb_information.chunks where hypertable_name in (%s) and "
+ "is_compressed='t'", table_names);
+ }
+
+ if ((DB_RESULT)ZBX_DB_DOWN == result)
+ {
+ ret = FAIL;
+ goto out;
+ }
+
+ if (NULL != zbx_db_fetch(result))
+ ret = SUCCEED;
+ else
+ ret = FAIL;
+out:
+ DBfree_result(result);
+
+ return ret;
+}
+
+void zbx_tsdb_extract_compressed_chunk_flags(struct zbx_db_version_info_t *version_info)
+{
+#define ZBX_TSDB1_HISTORY_TABLES "'history_uint'::regclass,'history_log'::regclass,'history_str'::regclass,'history_text'::regclass,'history'::regclass"
+#define ZBX_TSDB2_HISTORY_TABLES "'history_uint','history_log','history_str','history_text','history'"
+#define ZBX_TSDB1_TRENDS_TABLES "'trends'::regclass,'trends_uint'::regclass"
+#define ZBX_TSDB2_TRENDS_TABLES "'trends','trends_uint'"
+ const char *history_tables, *trends_tables;
+
+ history_tables = (1 == ZBX_DB_TSDB_V1 ? ZBX_TSDB1_HISTORY_TABLES : ZBX_TSDB2_HISTORY_TABLES);
+ trends_tables = (1 == ZBX_DB_TSDB_V1 ? ZBX_TSDB1_TRENDS_TABLES : ZBX_TSDB2_TRENDS_TABLES);
+
+ version_info->history_compressed_chunks = (SUCCEED == zbx_tsdb_table_has_compressed_chunks(history_tables)) ?
+ 1 : 0;
+
+ version_info->trends_compressed_chunks = (SUCCEED == zbx_tsdb_table_has_compressed_chunks(trends_tables)) ?
+ 1 : 0;
+
+#undef ZBX_TSDB1_HISTORY_TABLES
+#undef ZBX_TSDB2_HISTORY_TABLES
+#undef ZBX_TSDB1_TRENDS_TABLES
+#undef ZBX_TSDB2_TRENDS_TABLES
+}
/***************************************************************************************************************
* *
* Purpose: retrieves TimescaleDB extension info, including license string and numeric version value *
@@ -2875,7 +2931,7 @@ out:
**************************************************************************************************************/
void zbx_tsdb_info_extract(struct zbx_db_version_info_t *version_info)
{
- int tsdb_ver;
+ int tsdb_ver;
if (0 != zbx_strcmp_null(version_info->extension, ZBX_DB_EXTENSION_TIMESCALEDB))
return;
@@ -2901,6 +2957,8 @@ void zbx_tsdb_info_extract(struct zbx_db_version_info_t *version_info)
if (ZBX_TIMESCALE_MIN_VERSION_WITH_LICENSE_PARAM_SUPPORT <= tsdb_ver)
version_info->ext_lic = zbx_tsdb_get_license();
+ zbx_tsdb_extract_compressed_chunk_flags(version_info);
+
zabbix_log(LOG_LEVEL_DEBUG, "TimescaleDB version: [%d], license: [%s]", tsdb_ver,
ZBX_NULL2EMPTY_STR(version_info->ext_lic));
}
@@ -3023,4 +3081,5 @@ int zbx_tsdb_get_compression_availability(void)
{
return ZBX_TIMESCALE_COMPRESSION_AVAILABLE;
}
+
#endif
diff --git a/src/libs/zbxdbcache/Makefile.am b/src/libs/zbxdbcache/Makefile.am
index 577d3ed846c..60d3f944ed4 100644
--- a/src/libs/zbxdbcache/Makefile.am
+++ b/src/libs/zbxdbcache/Makefile.am
@@ -10,6 +10,7 @@ libzbxdbcache_a_SOURCES = \
dbconfig_maintenance.c \
dbsync.c \
dbsync.h \
+ lld_macro.c \
valuecache.c \
valuecache.h \
user_macro.c \
diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c
index e5bbd267eb9..6f3ce27d541 100644
--- a/src/libs/zbxdbcache/dbcache.c
+++ b/src/libs/zbxdbcache/dbcache.c
@@ -1533,6 +1533,168 @@ static void DCsync_trends(void)
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
}
+#define ZBX_FLAGS_TRIGGER_CREATE_NOTHING 0x00
+#define ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT 0x01
+#define ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT 0x02
+#define ZBX_FLAGS_TRIGGER_CREATE_EVENT \
+ (ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT | ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT)
+
+/******************************************************************************
+ * *
+ * Purpose: 1) calculate changeset of trigger fields to be updated *
+ * 2) generate events *
+ * *
+ * Parameters: trigger - [IN] the trigger to process *
+ * diffs - [OUT] the vector with trigger changes *
+ * *
+ * Return value: SUCCEED - trigger processed successfully *
+ * FAIL - no changes *
+ * *
+ * Comments: Trigger dependency checks will be done during event processing. *
+ * *
+ * Event generation depending on trigger value/state changes: *
+ * *
+ * From \ To | OK | OK(?) | PROBLEM | PROBLEM(?) | NONE *
+ *----------------------------------------------------------------------------*
+ * OK | . | I | E | I | . *
+ * | | | | | *
+ * OK(?) | I | . | E,I | - | I *
+ * | | | | | *
+ * PROBLEM | E | I | E(m) | I | . *
+ * | | | | | *
+ * PROBLEM(?) | E,I | - | E(m),I | . | I *
+ * *
+ * Legend: *
+ * 'E' - trigger event *
+ * 'I' - internal event *
+ * '.' - nothing *
+ * '-' - should never happen *
+ * *
+ ******************************************************************************/
+static int zbx_process_trigger(struct _DC_TRIGGER *trigger, zbx_vector_ptr_t *diffs)
+{
+ const char *new_error;
+ int new_state, new_value, ret = FAIL;
+ zbx_uint64_t flags = ZBX_FLAGS_TRIGGER_DIFF_UNSET, event_flags = ZBX_FLAGS_TRIGGER_CREATE_NOTHING;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() triggerid:" ZBX_FS_UI64 " value:%d(%d) new_value:%d",
+ __func__, trigger->triggerid, trigger->value, trigger->state, trigger->new_value);
+
+ if (TRIGGER_VALUE_UNKNOWN == trigger->new_value)
+ {
+ new_state = TRIGGER_STATE_UNKNOWN;
+ new_value = trigger->value;
+ }
+ else
+ {
+ new_state = TRIGGER_STATE_NORMAL;
+ new_value = trigger->new_value;
+ }
+ new_error = (NULL == trigger->new_error ? "" : trigger->new_error);
+
+ if (trigger->state != new_state)
+ {
+ flags |= ZBX_FLAGS_TRIGGER_DIFF_UPDATE_STATE;
+ event_flags |= ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT;
+ }
+
+ if (0 != strcmp(trigger->error, new_error))
+ flags |= ZBX_FLAGS_TRIGGER_DIFF_UPDATE_ERROR;
+
+ if (TRIGGER_STATE_NORMAL == new_state)
+ {
+ if (TRIGGER_VALUE_PROBLEM == new_value)
+ {
+ if (TRIGGER_VALUE_OK == trigger->value || TRIGGER_TYPE_MULTIPLE_TRUE == trigger->type)
+ event_flags |= ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT;
+ }
+ else if (TRIGGER_VALUE_OK == new_value)
+ {
+ if (TRIGGER_VALUE_PROBLEM == trigger->value || 0 == trigger->lastchange)
+ event_flags |= ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT;
+ }
+ }
+
+ /* check if there is something to be updated */
+ if (0 == (flags & ZBX_FLAGS_TRIGGER_DIFF_UPDATE) && 0 == (event_flags & ZBX_FLAGS_TRIGGER_CREATE_EVENT))
+ goto out;
+
+ if (0 != (event_flags & ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT))
+ {
+ zbx_add_event(EVENT_SOURCE_TRIGGERS, EVENT_OBJECT_TRIGGER, trigger->triggerid,
+ &trigger->timespec, new_value, trigger->description,
+ trigger->expression, trigger->recovery_expression,
+ trigger->priority, trigger->type, &trigger->tags,
+ trigger->correlation_mode, trigger->correlation_tag, trigger->value, trigger->opdata,
+ trigger->event_name, NULL);
+ }
+
+ if (0 != (event_flags & ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT))
+ {
+ zbx_add_event(EVENT_SOURCE_INTERNAL, EVENT_OBJECT_TRIGGER, trigger->triggerid,
+ &trigger->timespec, new_state, NULL, trigger->expression,
+ trigger->recovery_expression, 0, 0, &trigger->tags, 0, NULL, 0, NULL, NULL,
+ new_error);
+ }
+
+ zbx_append_trigger_diff(diffs, trigger->triggerid, trigger->priority, flags, trigger->value, new_state,
+ trigger->timespec.sec, new_error);
+
+ ret = SUCCEED;
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s flags:" ZBX_FS_UI64, __func__, zbx_result_string(ret),
+ flags);
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Comments: helper function for zbx_process_triggers() *
+ * *
+ ******************************************************************************/
+static int zbx_trigger_topoindex_compare(const void *d1, const void *d2)
+{
+ const DC_TRIGGER *t1 = *(const DC_TRIGGER * const *)d1;
+ const DC_TRIGGER *t2 = *(const DC_TRIGGER * const *)d2;
+
+ ZBX_RETURN_IF_NOT_EQUAL(t1->topoindex, t2->topoindex);
+
+ return 0;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process triggers - calculates property changeset and generates *
+ * events *
+ * *
+ * Parameters: triggers - [IN] the triggers to process *
+ * trigger_diff - [OUT] the trigger changeset *
+ * *
+ * Comments: The trigger_diff changeset must be cleaned by the caller: *
+ * zbx_vector_ptr_clear_ext(trigger_diff, *
+ * (zbx_clean_func_t)zbx_trigger_diff_free); *
+ * *
+ ******************************************************************************/
+static void zbx_process_triggers(zbx_vector_ptr_t *triggers, zbx_vector_ptr_t *trigger_diff)
+{
+ int i;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() values_num:%d", __func__, triggers->values_num);
+
+ if (0 == triggers->values_num)
+ goto out;
+
+ zbx_vector_ptr_sort(triggers, zbx_trigger_topoindex_compare);
+
+ for (i = 0; i < triggers->values_num; i++)
+ zbx_process_trigger((struct _DC_TRIGGER *)triggers->values[i], trigger_diff);
+
+ zbx_vector_ptr_sort(trigger_diff, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
+}
+
/******************************************************************************
* *
* Purpose: re-calculate and update values of triggers related to the items *
diff --git a/src/libs/zbxdbcache/dbconfig.c b/src/libs/zbxdbcache/dbconfig.c
index 7dcd21e2082..ef9651f33e4 100644
--- a/src/libs/zbxdbcache/dbconfig.c
+++ b/src/libs/zbxdbcache/dbconfig.c
@@ -40,6 +40,7 @@
#include "zbxtime.h"
#include "zbxip.h"
#include "zbxsysinfo.h"
+#include "events.h"
int sync_in_progress = 0;
@@ -15500,6 +15501,7 @@ static void dc_reschedule_items(const zbx_hashset_t *activated_hosts)
zbx_vector_item_delay_destroy(&items);
}
+
/******************************************************************************
* *
* Purpose: reschedule httptests on hosts that were re-enabled or unassigned *
@@ -15556,7 +15558,6 @@ static void dc_reschedule_httptests(zbx_hashset_t *activated_hosts)
zbx_vector_dc_httptest_ptr_destroy(&httptests);
}
-
/******************************************************************************
* *
* Purpose: get next drule to be processed *
diff --git a/src/libs/zbxdbhigh/lld_macro.c b/src/libs/zbxdbcache/lld_macro.c
index 28a74c3c29d..28a74c3c29d 100644
--- a/src/libs/zbxdbhigh/lld_macro.c
+++ b/src/libs/zbxdbcache/lld_macro.c
diff --git a/src/libs/zbxdbhigh/Makefile.am b/src/libs/zbxdbhigh/Makefile.am
index 53ab11f9d90..147e0ba15c3 100644
--- a/src/libs/zbxdbhigh/Makefile.am
+++ b/src/libs/zbxdbhigh/Makefile.am
@@ -4,21 +4,10 @@ noinst_LIBRARIES = libzbxdbhigh.a
libzbxdbhigh_a_SOURCES = \
db.c \
- event.c \
- host.c \
item.c \
- lld_macro.c \
maintenance.c \
proxy.c \
- template_item.c \
- template.h \
trigger.c \
- trigger_dep_linking.c \
- trigger_dep_linking.h \
- trigger_linking.c \
- trigger_linking.h \
- graph_linking.c \
- graph_linking.h \
tag.c \
item_param.c \
lld_override.c \
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index b29b9bdeead..06d1afdd089 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -44,6 +44,8 @@ extern char ZBX_PG_ESCAPE_BACKSLASH;
static int connection_failure;
extern unsigned char program_type;
+static zbx_dc_get_nextid_func_t zbx_cb_nextid;
+
void DBclose(void)
{
zbx_db_close();
@@ -194,9 +196,14 @@ int DBconnect(int flag)
return err;
}
-int DBinit(char **error)
+int DBinit(zbx_dc_get_nextid_func_t cb_nextid, unsigned char program, char **error)
{
- return zbx_db_init(CONFIG_DBNAME, db_schema, error);
+ zbx_cb_nextid = cb_nextid;
+
+ if (ZBX_PROGRAM_TYPE_SERVER != program)
+ return zbx_db_init(CONFIG_DBNAME, db_schema, error);
+
+ return SUCCEED;
}
void DBdeinit(void)
@@ -723,7 +730,7 @@ zbx_uint64_t DBget_maxid_num(const char *tablename, int num)
0 == strcmp(tablename, "autoreg_host") ||
0 == strcmp(tablename, "event_suppress") ||
0 == strcmp(tablename, "trigger_queue"))
- return DCget_nextid(tablename, num);
+ return zbx_cb_nextid(tablename, num);
return DBget_nextid(tablename, num);
}
@@ -873,6 +880,14 @@ int zbx_db_check_version_info(struct zbx_db_version_info_t *info, int allow_unsu
return SUCCEED;
}
+void zbx_db_version_info_clear(struct zbx_db_version_info_t *version_info)
+{
+ zbx_free(version_info->friendly_current_version);
+ zbx_free(version_info->extension);
+ zbx_free(version_info->ext_friendly_current_version);
+ zbx_free(version_info->ext_lic);
+}
+
#ifdef HAVE_POSTGRESQL
/******************************************************************************
* *
@@ -2073,16 +2088,6 @@ const char *DBget_inventory_field(unsigned char inventory_link)
return inventory_fields[inventory_link - 1];
}
-int DBtxn_status(void)
-{
- return 0 == zbx_db_txn_error() ? SUCCEED : FAIL;
-}
-
-int DBtxn_ongoing(void)
-{
- return 0 == zbx_db_txn_level() ? FAIL : SUCCEED;
-}
-
int DBtable_exists(const char *table_name)
{
char *table_name_esc;
@@ -3519,76 +3524,6 @@ void zbx_user_free(zbx_user_t *user)
/******************************************************************************
* *
- * Purpose: initializes mock field *
- * *
- * Parameters: field - [OUT] the field data *
- * field_type - [IN] the field type in database schema *
- * field_len - [IN] the field size in database schema *
- * *
- ******************************************************************************/
-void zbx_db_mock_field_init(zbx_db_mock_field_t *field, int field_type, int field_len)
-{
- switch (field_type)
- {
- case ZBX_TYPE_CHAR:
-#if defined(HAVE_ORACLE)
- field->chars_num = field_len;
- field->bytes_num = 4000;
-#else
- field->chars_num = field_len;
- field->bytes_num = -1;
-#endif
- return;
- }
-
- THIS_SHOULD_NEVER_HAPPEN;
-
- field->chars_num = 0;
- field->bytes_num = 0;
-}
-
-/******************************************************************************
- * *
- * Purpose: 'appends' text to the field, if successful the character/byte *
- * limits are updated *
- * *
- * Parameters: field - [IN/OUT] the mock field *
- * text - [IN] the text to append *
- * *
- * Return value: SUCCEED - the field had enough space to append the text *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-int zbx_db_mock_field_append(zbx_db_mock_field_t *field, const char *text)
-{
- int bytes_num, chars_num;
-
- if (-1 != field->bytes_num)
- {
- bytes_num = strlen(text);
- if (bytes_num > field->bytes_num)
- return FAIL;
- }
- else
- bytes_num = 0;
-
- if (-1 != field->chars_num)
- {
- chars_num = zbx_strlen_utf8(text);
- if (chars_num > field->chars_num)
- return FAIL;
- }
- else
- chars_num = 0;
-
- field->bytes_num -= bytes_num;
- field->chars_num -= chars_num;
-
- return SUCCEED;
-}
-
-/******************************************************************************
- * *
* Purpose: checks instanceid value in config table and generates new *
* instance id if its empty *
* *
diff --git a/src/libs/zbxdbhigh/proxy.c b/src/libs/zbxdbhigh/proxy.c
index 0465224627f..4182e9fb9f3 100644
--- a/src/libs/zbxdbhigh/proxy.c
+++ b/src/libs/zbxdbhigh/proxy.c
@@ -17,1136 +17,11 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "proxy.h"
#include "zbxdbhigh.h"
#include "log.h"
-#include "zbxsysinfo.h"
-#include "zbxserver.h"
-#include "zbxtasks.h"
-#include "zbxdiscovery.h"
-#include "zbxalgo.h"
-#include "preproc.h"
-#include "zbxcrypto.h"
-#include "../zbxkvs/kvs.h"
-#include "zbxlld.h"
-#include "events.h"
-#include "../zbxvault/vault.h"
-#include "zbxavailability.h"
-#include "zbxcommshigh.h"
-#include "zbxnum.h"
-#include "zbxtime.h"
-#include "zbxip.h"
-#include "version.h"
#include "zbxversion.h"
-extern char *CONFIG_SERVER;
-
-/* the space reserved in json buffer to hold at least one record plus service data */
-#define ZBX_DATA_JSON_RESERVED (ZBX_HISTORY_TEXT_VALUE_LEN * 4 + ZBX_KIBIBYTE * 4)
-
-#define ZBX_DATA_JSON_RECORD_LIMIT (ZBX_MAX_RECV_DATA_SIZE - ZBX_DATA_JSON_RESERVED)
-#define ZBX_DATA_JSON_BATCH_LIMIT ((ZBX_MAX_RECV_DATA_SIZE - ZBX_DATA_JSON_RESERVED) / 2)
-
-/* the maximum number of values processed in one batch */
-#define ZBX_HISTORY_VALUES_MAX 256
-
-typedef struct
-{
- zbx_uint64_t druleid;
- zbx_vector_uint64_t dcheckids;
- zbx_vector_ptr_t ips;
-}
-zbx_drule_t;
-
-typedef struct
-{
- char ip[ZBX_INTERFACE_IP_LEN_MAX];
- zbx_vector_ptr_t services;
-}
-zbx_drule_ip_t;
-
-typedef struct
-{
- const char *field;
- const char *tag;
- zbx_json_type_t jt;
- const char *default_value;
-}
-zbx_history_field_t;
-
-typedef struct
-{
- const char *table, *lastidfield;
- zbx_history_field_t fields[ZBX_MAX_FIELDS];
-}
-zbx_history_table_t;
-
-typedef int (*zbx_client_item_validator_t)(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error);
-
-typedef struct
-{
- zbx_uint64_t hostid;
- int value;
-}
-zbx_host_rights_t;
-
-static zbx_history_table_t dht = {
- "proxy_dhistory", "dhistory_lastid",
- {
- {"clock", ZBX_PROTO_TAG_CLOCK, ZBX_JSON_TYPE_INT, NULL},
- {"druleid", ZBX_PROTO_TAG_DRULE, ZBX_JSON_TYPE_INT, NULL},
- {"dcheckid", ZBX_PROTO_TAG_DCHECK, ZBX_JSON_TYPE_INT, NULL},
- {"ip", ZBX_PROTO_TAG_IP, ZBX_JSON_TYPE_STRING, NULL},
- {"dns", ZBX_PROTO_TAG_DNS, ZBX_JSON_TYPE_STRING, NULL},
- {"port", ZBX_PROTO_TAG_PORT, ZBX_JSON_TYPE_INT, "0"},
- {"value", ZBX_PROTO_TAG_VALUE, ZBX_JSON_TYPE_STRING, ""},
- {"status", ZBX_PROTO_TAG_STATUS, ZBX_JSON_TYPE_INT, "0"},
- {NULL}
- }
-};
-
-static zbx_history_table_t areg = {
- "proxy_autoreg_host", "autoreg_host_lastid",
- {
- {"clock", ZBX_PROTO_TAG_CLOCK, ZBX_JSON_TYPE_INT, NULL},
- {"host", ZBX_PROTO_TAG_HOST, ZBX_JSON_TYPE_STRING, NULL},
- {"listen_ip", ZBX_PROTO_TAG_IP, ZBX_JSON_TYPE_STRING, ""},
- {"listen_dns", ZBX_PROTO_TAG_DNS, ZBX_JSON_TYPE_STRING, ""},
- {"listen_port", ZBX_PROTO_TAG_PORT, ZBX_JSON_TYPE_STRING, "0"},
- {"host_metadata", ZBX_PROTO_TAG_HOST_METADATA, ZBX_JSON_TYPE_STRING, ""},
- {"flags", ZBX_PROTO_TAG_FLAGS, ZBX_JSON_TYPE_STRING, "0"},
- {"tls_accepted", ZBX_PROTO_TAG_TLS_ACCEPTED, ZBX_JSON_TYPE_INT, "0"},
- {NULL}
- }
-};
-
-/******************************************************************************
- * *
- * Purpose: check proxy connection permissions (encryption configuration and *
- * if peer proxy address is allowed) *
- * *
- * Parameters: *
- * proxy - [IN] the proxy data *
- * sock - [IN] connection socket context *
- * error - [OUT] error message *
- * *
- * Return value: *
- * SUCCEED - connection permission check was successful *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-int zbx_proxy_check_permissions(const DC_PROXY *proxy, const zbx_socket_t *sock, char **error)
-{
-#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
- zbx_tls_conn_attr_t attr;
-#endif
- if ('\0' != *proxy->proxy_address && FAIL == zbx_tcp_check_allowed_peers(sock, proxy->proxy_address))
- {
- *error = zbx_strdup(*error, "connection is not allowed");
- return FAIL;
- }
-
-#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
- if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
- {
- if (SUCCEED != zbx_tls_get_attr_cert(sock, &attr))
- {
- *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
- THIS_SHOULD_NEVER_HAPPEN;
- return FAIL;
- }
- }
-#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
- else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
- {
- if (SUCCEED != zbx_tls_get_attr_psk(sock, &attr))
- {
- *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
- THIS_SHOULD_NEVER_HAPPEN;
- return FAIL;
- }
- }
-#endif
- else if (ZBX_TCP_SEC_UNENCRYPTED != sock->connection_type)
- {
- *error = zbx_strdup(*error, "internal error: invalid connection type");
- THIS_SHOULD_NEVER_HAPPEN;
- return FAIL;
- }
-#endif
- if (0 == ((unsigned int)proxy->tls_accept & sock->connection_type))
- {
- *error = zbx_dsprintf(NULL, "connection of type \"%s\" is not allowed for proxy \"%s\"",
- zbx_tcp_connection_type_name(sock->connection_type), proxy->host);
- return FAIL;
- }
-
-#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
- if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
- {
- /* simplified match, not compliant with RFC 4517, 4518 */
- if ('\0' != *proxy->tls_issuer && 0 != strcmp(proxy->tls_issuer, attr.issuer))
- {
- *error = zbx_dsprintf(*error, "proxy \"%s\" certificate issuer does not match", proxy->host);
- return FAIL;
- }
-
- /* simplified match, not compliant with RFC 4517, 4518 */
- if ('\0' != *proxy->tls_subject && 0 != strcmp(proxy->tls_subject, attr.subject))
- {
- *error = zbx_dsprintf(*error, "proxy \"%s\" certificate subject does not match", proxy->host);
- return FAIL;
- }
- }
-#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
- else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
- {
- if (strlen(proxy->tls_psk_identity) != attr.psk_identity_len ||
- 0 != memcmp(proxy->tls_psk_identity, attr.psk_identity, attr.psk_identity_len))
- {
- *error = zbx_dsprintf(*error, "proxy \"%s\" is using false PSK identity", proxy->host);
- return FAIL;
- }
- }
-#endif
-#endif
- return SUCCEED;
-}
-
-/******************************************************************************
- * *
- * Purpose: checks host connection permissions (encryption configuration) *
- * *
- * Parameters: *
- * host - [IN] the host data *
- * sock - [IN] connection socket context *
- * error - [OUT] error message *
- * *
- * Return value: *
- * SUCCEED - connection permission check was successful *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int zbx_host_check_permissions(const DC_HOST *host, const zbx_socket_t *sock, char **error)
-{
-#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
- zbx_tls_conn_attr_t attr;
-
- if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
- {
- if (SUCCEED != zbx_tls_get_attr_cert(sock, &attr))
- {
- *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
- THIS_SHOULD_NEVER_HAPPEN;
- return FAIL;
- }
- }
-#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
- else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
- {
- if (SUCCEED != zbx_tls_get_attr_psk(sock, &attr))
- {
- *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
- THIS_SHOULD_NEVER_HAPPEN;
- return FAIL;
- }
- }
-#endif
- else if (ZBX_TCP_SEC_UNENCRYPTED != sock->connection_type)
- {
- *error = zbx_strdup(*error, "internal error: invalid connection type");
- THIS_SHOULD_NEVER_HAPPEN;
- return FAIL;
- }
-#endif
- if (0 == ((unsigned int)host->tls_accept & sock->connection_type))
- {
- *error = zbx_dsprintf(NULL, "connection of type \"%s\" is not allowed for host \"%s\"",
- zbx_tcp_connection_type_name(sock->connection_type), host->host);
- return FAIL;
- }
-
-#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
- if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
- {
- /* simplified match, not compliant with RFC 4517, 4518 */
- if ('\0' != *host->tls_issuer && 0 != strcmp(host->tls_issuer, attr.issuer))
- {
- *error = zbx_dsprintf(*error, "host \"%s\" certificate issuer does not match", host->host);
- return FAIL;
- }
-
- /* simplified match, not compliant with RFC 4517, 4518 */
- if ('\0' != *host->tls_subject && 0 != strcmp(host->tls_subject, attr.subject))
- {
- *error = zbx_dsprintf(*error, "host \"%s\" certificate subject does not match", host->host);
- return FAIL;
- }
- }
-#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
- else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
- {
- if (strlen(host->tls_psk_identity) != attr.psk_identity_len ||
- 0 != memcmp(host->tls_psk_identity, attr.psk_identity, attr.psk_identity_len))
- {
- *error = zbx_dsprintf(*error, "host \"%s\" is using false PSK identity", host->host);
- return FAIL;
- }
- }
-#endif
-#endif
- return SUCCEED;
-}
-
-/******************************************************************************
- * *
- * Purpose: *
- * Extract a proxy name from JSON and find the proxy ID in configuration *
- * cache, and check access rights. The proxy must be configured in active *
- * mode. *
- * *
- * Parameters: *
- * jp - [IN] JSON with the proxy name *
- * proxy - [OUT] the proxy data *
- * error - [OUT] error message *
- * *
- * Return value: *
- * SUCCEED - proxy ID was found in database *
- * FAIL - an error occurred (e.g. an unknown proxy, the proxy is *
- * configured in passive mode or access denied) *
- * *
- ******************************************************************************/
-int get_active_proxy_from_request(const struct zbx_json_parse *jp, DC_PROXY *proxy, char **error)
-{
- char *ch_error, host[ZBX_HOSTNAME_BUF_LEN];
-
- if (SUCCEED != zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, host, sizeof(host), NULL))
- {
- *error = zbx_strdup(*error, "missing name of proxy");
- return FAIL;
- }
-
- if (SUCCEED != zbx_check_hostname(host, &ch_error))
- {
- *error = zbx_dsprintf(*error, "invalid proxy name \"%s\": %s", host, ch_error);
- zbx_free(ch_error);
- return FAIL;
- }
-
- return zbx_dc_get_active_proxy_by_name(host, proxy, error);
-}
-
-/******************************************************************************
- * *
- * Purpose: *
- * Check access rights to a passive proxy for the given connection and *
- * send a response if denied. *
- * *
- * Parameters: *
- * sock - [IN] connection socket context *
- * send_response - [IN] to send or not to send a response to server. *
- * Value: ZBX_SEND_RESPONSE or *
- * ZBX_DO_NOT_SEND_RESPONSE *
- * req - [IN] request, included into error message *
- * zbx_config_tls - [IN] configured requirements to allow access *
- * *
- * Return value: *
- * SUCCEED - access is allowed *
- * FAIL - access is denied *
- * *
- ******************************************************************************/
-int check_access_passive_proxy(zbx_socket_t *sock, int send_response, const char *req,
- const zbx_config_tls_t *zbx_config_tls)
-{
- char *msg = NULL;
-
- if (FAIL == zbx_tcp_check_allowed_peers(sock, CONFIG_SERVER))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" is not allowed: %s", req, sock->peer,
- zbx_socket_strerror());
-
- if (ZBX_SEND_RESPONSE == send_response)
- zbx_send_proxy_response(sock, FAIL, "connection is not allowed", CONFIG_TIMEOUT);
-
- return FAIL;
- }
-
- if (0 == (zbx_config_tls->accept_modes & sock->connection_type))
- {
- msg = zbx_dsprintf(NULL, "%s over connection of type \"%s\" is not allowed", req,
- zbx_tcp_connection_type_name(sock->connection_type));
-
- zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" by proxy configuration parameter \"TLSAccept\"",
- msg, sock->peer);
-
- if (ZBX_SEND_RESPONSE == send_response)
- zbx_send_proxy_response(sock, FAIL, msg, CONFIG_TIMEOUT);
-
- zbx_free(msg);
- return FAIL;
- }
-
-#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
- if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
- {
- if (SUCCEED == zbx_check_server_issuer_subject(sock, zbx_config_tls->server_cert_issuer,
- zbx_config_tls->server_cert_subject, &msg))
- {
- return SUCCEED;
- }
-
- zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" is not allowed: %s", req, sock->peer, msg);
-
- if (ZBX_SEND_RESPONSE == send_response)
- zbx_send_proxy_response(sock, FAIL, "certificate issuer or subject mismatch", CONFIG_TIMEOUT);
-
- zbx_free(msg);
- return FAIL;
- }
- else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
- {
- if (0 != (ZBX_PSK_FOR_PROXY & zbx_tls_get_psk_usage()))
- return SUCCEED;
-
- zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" is not allowed: it used PSK which is not"
- " configured for proxy communication with server", req, sock->peer);
-
- if (ZBX_SEND_RESPONSE == send_response)
- zbx_send_proxy_response(sock, FAIL, "wrong PSK used", CONFIG_TIMEOUT);
-
- return FAIL;
- }
-#endif
- return SUCCEED;
-}
-
-/******************************************************************************
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - no interface availability has been changed *
- * *
- ******************************************************************************/
-int get_interface_availability_data(struct zbx_json *json, int *ts)
-{
- int i, ret = FAIL;
- zbx_vector_ptr_t interfaces;
- zbx_interface_availability_t *ia;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- zbx_vector_ptr_create(&interfaces);
-
- if (SUCCEED != DCget_interfaces_availability(&interfaces, ts))
- goto out;
-
- zbx_json_addarray(json, ZBX_PROTO_TAG_INTERFACE_AVAILABILITY);
-
- for (i = 0; i < interfaces.values_num; i++)
- {
- ia = (zbx_interface_availability_t *)interfaces.values[i];
-
- zbx_json_addobject(json, NULL);
- zbx_json_adduint64(json, ZBX_PROTO_TAG_INTERFACE_ID, ia->interfaceid);
-
- zbx_json_adduint64(json, ZBX_PROTO_TAG_AVAILABLE, ia->agent.available);
- zbx_json_addstring(json, ZBX_PROTO_TAG_ERROR, ia->agent.error, ZBX_JSON_TYPE_STRING);
-
- zbx_json_close(json);
- }
-
- zbx_json_close(json);
-
- ret = SUCCEED;
-out:
- zbx_vector_ptr_clear_ext(&interfaces, (zbx_mem_free_func_t)zbx_interface_availability_free);
- zbx_vector_ptr_destroy(&interfaces);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: parses interfaces availability data contents and processes it *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-static int process_interfaces_availability_contents(struct zbx_json_parse *jp_data, char **error)
-{
- zbx_uint64_t interfaceid;
- struct zbx_json_parse jp_row;
- const char *p = NULL;
- char *tmp;
- size_t tmp_alloc = 129;
- zbx_interface_availability_t *ia = NULL;
- zbx_vector_availability_ptr_t interfaces;
- int ret;
-
- tmp = (char *)zbx_malloc(NULL, tmp_alloc);
-
- zbx_vector_availability_ptr_create(&interfaces);
-
- while (NULL != (p = zbx_json_next(jp_data, p))) /* iterate the interface entries */
- {
- if (SUCCEED != (ret = zbx_json_brackets_open(p, &jp_row)))
- {
- *error = zbx_strdup(*error, zbx_json_strerror());
- goto out;
- }
-
- if (SUCCEED != (ret = zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_INTERFACE_ID, &tmp, &tmp_alloc,
- NULL)))
- {
- *error = zbx_strdup(*error, zbx_json_strerror());
- goto out;
- }
-
- if (SUCCEED != (ret = zbx_is_uint64(tmp, &interfaceid)))
- {
- *error = zbx_strdup(*error, "interfaceid is not a valid numeric");
- goto out;
- }
-
- ia = (zbx_interface_availability_t *)zbx_malloc(NULL, sizeof(zbx_interface_availability_t));
- zbx_interface_availability_init(ia, interfaceid);
-
- if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_AVAILABLE, &tmp, &tmp_alloc, NULL))
- {
- ia->agent.available = atoi(tmp);
- ia->agent.flags |= ZBX_FLAGS_AGENT_STATUS_AVAILABLE;
- }
-
- if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_ERROR, &tmp, &tmp_alloc, NULL))
- {
- ia->agent.error = zbx_strdup(NULL, tmp);
- ia->agent.flags |= ZBX_FLAGS_AGENT_STATUS_ERROR;
- }
-
- if (SUCCEED != (ret = zbx_interface_availability_is_set(ia)))
- {
- zbx_free(ia);
- *error = zbx_dsprintf(*error, "no availability data for \"interfaceid\":" ZBX_FS_UI64,
- interfaceid);
- goto out;
- }
-
- zbx_vector_availability_ptr_append(&interfaces, ia);
- }
-
- if (0 < interfaces.values_num && SUCCEED == DCset_interfaces_availability(&interfaces))
- zbx_availabilities_flush(&interfaces);
-
- ret = SUCCEED;
-out:
- zbx_vector_availability_ptr_clear_ext(&interfaces, zbx_interface_availability_free);
- zbx_vector_availability_ptr_destroy(&interfaces);
-
- zbx_free(tmp);
-
- return ret;
-}
-
-static void proxy_get_lastid(const char *table_name, const char *lastidfield, zbx_uint64_t *lastid)
-{
- DB_RESULT result;
- DB_ROW row;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() field:'%s.%s'", __func__, table_name, lastidfield);
-
- result = DBselect("select nextid from ids where table_name='%s' and field_name='%s'",
- table_name, lastidfield);
-
- if (NULL == (row = DBfetch(result)))
- *lastid = 0;
- else
- ZBX_STR2UINT64(*lastid, row[0]);
- DBfree_result(result);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():" ZBX_FS_UI64, __func__, *lastid);
-}
-
-static void proxy_set_lastid(const char *table_name, const char *lastidfield, const zbx_uint64_t lastid)
-{
- DB_RESULT result;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() [%s.%s:" ZBX_FS_UI64 "]", __func__, table_name, lastidfield, lastid);
-
- result = DBselect("select 1 from ids where table_name='%s' and field_name='%s'",
- table_name, lastidfield);
-
- if (NULL == DBfetch(result))
- {
- DBexecute("insert into ids (table_name,field_name,nextid) values ('%s','%s'," ZBX_FS_UI64 ")",
- table_name, lastidfield, lastid);
- }
- else
- {
- DBexecute("update ids set nextid=" ZBX_FS_UI64 " where table_name='%s' and field_name='%s'",
- lastid, table_name, lastidfield);
- }
- DBfree_result(result);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
-}
-
-void proxy_set_hist_lastid(const zbx_uint64_t lastid)
-{
- proxy_set_lastid("proxy_history", "history_lastid", lastid);
-}
-
-void proxy_set_dhis_lastid(const zbx_uint64_t lastid)
-{
- proxy_set_lastid(dht.table, dht.lastidfield, lastid);
-}
-
-void proxy_set_areg_lastid(const zbx_uint64_t lastid)
-{
- proxy_set_lastid(areg.table, areg.lastidfield, lastid);
-}
-
-int proxy_get_delay(const zbx_uint64_t lastid)
-{
- DB_RESULT result;
- DB_ROW row;
- char *sql = NULL;
- int ts = 0;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() [lastid=" ZBX_FS_UI64 "]", __func__, lastid);
-
- sql = zbx_dsprintf(sql, "select write_clock from proxy_history where id>" ZBX_FS_UI64 " order by id asc",
- lastid);
-
- result = DBselectN(sql, 1);
- zbx_free(sql);
-
- if (NULL != (row = DBfetch(result)))
- ts = (int)time(NULL) - atoi(row[0]);
-
- DBfree_result(result);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
-
- return ts;
-}
-
-/******************************************************************************
- * *
- * Purpose: Get history data from the database. *
- * *
- ******************************************************************************/
-static void proxy_get_history_data_simple(struct zbx_json *j, const char *proto_tag, const zbx_history_table_t *ht,
- zbx_uint64_t *lastid, zbx_uint64_t *id, int *records_num, int *more)
-{
- size_t offset = 0;
- int f, records_num_last = *records_num, retries = 1;
- char sql[MAX_STRING_LEN];
- DB_RESULT result;
- DB_ROW row;
- struct timespec t_sleep = { 0, 100000000L }, t_rem;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() table:'%s'", __func__, ht->table);
-
- *more = ZBX_PROXY_DATA_DONE;
-
- offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, "select id");
-
- for (f = 0; NULL != ht->fields[f].field; f++)
- offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, ",%s", ht->fields[f].field);
-try_again:
- zbx_snprintf(sql + offset, sizeof(sql) - offset, " from %s where id>" ZBX_FS_UI64 " order by id",
- ht->table, *id);
-
- result = DBselectN(sql, ZBX_MAX_HRECORDS);
-
- while (NULL != (row = DBfetch(result)))
- {
- ZBX_STR2UINT64(*lastid, row[0]);
-
- if (1 < *lastid - *id)
- {
- /* At least one record is missing. It can happen if some DB syncer process has */
- /* started but not yet committed a transaction or a rollback occurred in a DB syncer. */
- if (0 < retries--)
- {
- DBfree_result(result);
- zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing."
- " Waiting " ZBX_FS_DBL " sec, retrying.",
- __func__, *lastid - *id - 1,
- t_sleep.tv_sec + t_sleep.tv_nsec / 1e9);
- nanosleep(&t_sleep, &t_rem);
- goto try_again;
- }
- else
- {
- zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing. No more retries.",
- __func__, *lastid - *id - 1);
- }
- }
-
- if (0 == *records_num)
- zbx_json_addarray(j, proto_tag);
-
- zbx_json_addobject(j, NULL);
-
- for (f = 0; NULL != ht->fields[f].field; f++)
- {
- if (NULL != ht->fields[f].default_value && 0 == strcmp(row[f + 1], ht->fields[f].default_value))
- continue;
-
- zbx_json_addstring(j, ht->fields[f].tag, row[f + 1], ht->fields[f].jt);
- }
-
- (*records_num)++;
-
- zbx_json_close(j);
-
- /* stop gathering data to avoid exceeding the maximum packet size */
- if (ZBX_DATA_JSON_RECORD_LIMIT < j->buffer_offset)
- {
- *more = ZBX_PROXY_DATA_MORE;
- break;
- }
-
- *id = *lastid;
- }
- DBfree_result(result);
-
- if (ZBX_MAX_HRECORDS == *records_num - records_num_last)
- *more = ZBX_PROXY_DATA_MORE;
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%d lastid:" ZBX_FS_UI64 " more:%d size:" ZBX_FS_SIZE_T,
- __func__, *records_num - records_num_last, *lastid, *more,
- (zbx_fs_size_t)j->buffer_offset);
-}
-
-typedef struct
-{
- zbx_uint64_t id;
- zbx_uint64_t itemid;
- zbx_uint64_t lastlogsize;
- size_t source_offset;
- size_t value_offset;
- int clock;
- int ns;
- int timestamp;
- int severity;
- int logeventid;
- int mtime;
- unsigned char state;
- unsigned char flags;
-}
-zbx_history_data_t;
-
-/******************************************************************************
- * *
- * Purpose: read proxy history data from the database *
- * *
- * Parameters: lastid - [IN] the id of last processed proxy *
- * history record *
- * data - [IN/OUT] the proxy history data buffer *
- * data_alloc - [IN/OUT] the size of proxy history data *
- * buffer *
- * string_buffer - [IN/OUT] the string buffer *
- * string_buffer_size - [IN/OUT] the size of string buffer *
- * more - [OUT] set to ZBX_PROXY_DATA_MORE if there *
- * might be more data to read *
- * *
- * Return value: The number of records read. *
- * *
- ******************************************************************************/
-static int proxy_get_history_data(zbx_uint64_t lastid, zbx_history_data_t **data, size_t *data_alloc,
- char **string_buffer, size_t *string_buffer_alloc, int *more)
-{
- DB_RESULT result;
- DB_ROW row;
- char *sql = NULL;
- size_t sql_alloc = 0, sql_offset = 0, data_num = 0;
- size_t string_buffer_offset = 0;
- zbx_uint64_t id;
- int retries = 1, total_retries = 10;
- struct timespec t_sleep = { 0, 100000000L }, t_rem;
- zbx_history_data_t *hd;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() lastid:" ZBX_FS_UI64, __func__, lastid);
-
-try_again:
- zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
- "select id,itemid,clock,ns,timestamp,source,severity,"
- "value,logeventid,state,lastlogsize,mtime,flags"
- " from proxy_history"
- " where id>" ZBX_FS_UI64
- " order by id",
- lastid);
-
- result = DBselectN(sql, ZBX_MAX_HRECORDS - data_num);
-
- zbx_free(sql);
-
- while (NULL != (row = DBfetch(result)))
- {
- ZBX_STR2UINT64(id, row[0]);
-
- if (1 < id - lastid)
- {
- /* At least one record is missing. It can happen if some DB syncer process has */
- /* started but not yet committed a transaction or a rollback occurred in a DB syncer. */
- if (0 < retries--)
- {
- /* limit the number of total retries to avoid being stuck */
- /* in history full of 'holes' for a long time */
- if (0 >= total_retries--)
- break;
-
- DBfree_result(result);
- zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing."
- " Waiting " ZBX_FS_DBL " sec, retrying.",
- __func__, id - lastid - 1,
- t_sleep.tv_sec + t_sleep.tv_nsec / 1e9);
- nanosleep(&t_sleep, &t_rem);
- goto try_again;
- }
- else
- {
- zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing. No more retries.",
- __func__, id - lastid - 1);
- }
- }
-
- retries = 1;
-
- if (*data_alloc == data_num)
- {
- *data_alloc *= 2;
- *data = (zbx_history_data_t *)zbx_realloc(*data, sizeof(zbx_history_data_t) * *data_alloc);
- }
-
- hd = *data + data_num++;
- hd->id = id;
- ZBX_STR2UINT64(hd->itemid, row[1]);
- ZBX_STR2UCHAR(hd->flags, row[12]);
- hd->clock = atoi(row[2]);
- hd->ns = atoi(row[3]);
-
- if (PROXY_HISTORY_FLAG_NOVALUE != (hd->flags & PROXY_HISTORY_MASK_NOVALUE))
- {
- ZBX_STR2UCHAR(hd->state, row[9]);
-
- if (0 == (hd->flags & PROXY_HISTORY_FLAG_NOVALUE))
- {
- size_t len1, len2;
-
- hd->timestamp = atoi(row[4]);
- hd->severity = atoi(row[6]);
- hd->logeventid = atoi(row[8]);
-
- len1 = strlen(row[5]) + 1;
- len2 = strlen(row[7]) + 1;
-
- if (*string_buffer_alloc < string_buffer_offset + len1 + len2)
- {
- while (*string_buffer_alloc < string_buffer_offset + len1 + len2)
- *string_buffer_alloc += ZBX_KIBIBYTE;
-
- *string_buffer = (char *)zbx_realloc(*string_buffer, *string_buffer_alloc);
- }
-
- hd->source_offset = string_buffer_offset;
- memcpy(*string_buffer + hd->source_offset, row[5], len1);
- string_buffer_offset += len1;
-
- hd->value_offset = string_buffer_offset;
- memcpy(*string_buffer + hd->value_offset, row[7], len2);
- string_buffer_offset += len2;
- }
-
- if (0 != (hd->flags & PROXY_HISTORY_FLAG_META))
- {
- ZBX_STR2UINT64(hd->lastlogsize, row[10]);
- hd->mtime = atoi(row[11]);
- }
- }
-
- lastid = id;
- }
- DBfree_result(result);
-
- if (ZBX_MAX_HRECORDS != data_num && 1 == retries)
- *more = ZBX_PROXY_DATA_DONE;
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s() data_num:" ZBX_FS_SIZE_T, __func__, data_num);
-
- return data_num;
-}
-
-/******************************************************************************
- * *
- * Purpose: add history records to output json *
- * *
- * Parameters: j - [IN] the json output buffer *
- * records_num - [IN] the total number of records added *
- * dc_items - [IN] the item configuration data *
- * errcodes - [IN] the item configuration status codes *
- * records - [IN] the records to add *
- * string_buffer - [IN] the string buffer holding string values *
- * lastid - [OUT] the id of last added record *
- * *
- * Return value: The total number of records added. *
- * *
- ******************************************************************************/
-static int proxy_add_hist_data(struct zbx_json *j, int records_num, const DC_ITEM *dc_items, const int *errcodes,
- const zbx_vector_ptr_t *records, const char *string_buffer, zbx_uint64_t *lastid)
-{
- int i;
- const zbx_history_data_t *hd;
-
- for (i = records->values_num - 1; i >= 0; i--)
- {
- hd = (const zbx_history_data_t *)records->values[i];
- *lastid = hd->id;
-
- if (SUCCEED != errcodes[i])
- continue;
-
- if (ITEM_STATUS_ACTIVE != dc_items[i].status)
- continue;
-
- if (HOST_STATUS_MONITORED != dc_items[i].host.status)
- continue;
-
- if (PROXY_HISTORY_FLAG_NOVALUE == (hd->flags & PROXY_HISTORY_MASK_NOVALUE))
- {
- if (SUCCEED != zbx_is_counted_in_item_queue(dc_items[i].type, dc_items[i].key_orig))
- continue;
- }
-
- if (0 == records_num)
- zbx_json_addarray(j, ZBX_PROTO_TAG_HISTORY_DATA);
-
- zbx_json_addobject(j, NULL);
- zbx_json_adduint64(j, ZBX_PROTO_TAG_ID, hd->id);
- zbx_json_adduint64(j, ZBX_PROTO_TAG_ITEMID, hd->itemid);
- zbx_json_adduint64(j, ZBX_PROTO_TAG_CLOCK, hd->clock);
- zbx_json_adduint64(j, ZBX_PROTO_TAG_NS, hd->ns);
-
- if (PROXY_HISTORY_FLAG_NOVALUE != (hd->flags & PROXY_HISTORY_MASK_NOVALUE))
- {
- if (ITEM_STATE_NORMAL != hd->state)
- zbx_json_adduint64(j, ZBX_PROTO_TAG_STATE, hd->state);
-
- if (0 == (hd->flags & PROXY_HISTORY_FLAG_NOVALUE))
- {
- if (0 != hd->timestamp)
- zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGTIMESTAMP, hd->timestamp);
-
- if ('\0' != string_buffer[hd->source_offset])
- {
- zbx_json_addstring(j, ZBX_PROTO_TAG_LOGSOURCE,
- string_buffer + hd->source_offset, ZBX_JSON_TYPE_STRING);
- }
-
- if (0 != hd->severity)
- zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGSEVERITY, hd->severity);
-
- if (0 != hd->logeventid)
- zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGEVENTID, hd->logeventid);
-
- zbx_json_addstring(j, ZBX_PROTO_TAG_VALUE, string_buffer + hd->value_offset,
- ZBX_JSON_TYPE_STRING);
- }
-
- if (0 != (hd->flags & PROXY_HISTORY_FLAG_META))
- {
- zbx_json_adduint64(j, ZBX_PROTO_TAG_LASTLOGSIZE, hd->lastlogsize);
- zbx_json_adduint64(j, ZBX_PROTO_TAG_MTIME, hd->mtime);
- }
- }
-
- zbx_json_close(j);
- records_num++;
-
- /* stop gathering data to avoid exceeding the maximum packet size */
- if (ZBX_DATA_JSON_RECORD_LIMIT < j->buffer_offset)
- break;
- }
-
- return records_num;
-}
-
-int proxy_get_hist_data(struct zbx_json *j, zbx_uint64_t *lastid, int *more)
-{
- int records_num = 0, data_num, i, *errcodes = NULL, items_alloc = 0;
- zbx_uint64_t id;
- zbx_hashset_t itemids_added;
- zbx_history_data_t *data;
- char *string_buffer;
- size_t data_alloc = 16, string_buffer_alloc = ZBX_KIBIBYTE;
- zbx_vector_uint64_t itemids;
- zbx_vector_ptr_t records;
- DC_ITEM *dc_items = 0;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- zbx_vector_uint64_create(&itemids);
- zbx_vector_ptr_create(&records);
- data = (zbx_history_data_t *)zbx_malloc(NULL, data_alloc * sizeof(zbx_history_data_t));
- string_buffer = (char *)zbx_malloc(NULL, string_buffer_alloc);
-
- *more = ZBX_PROXY_DATA_MORE;
- proxy_get_lastid("proxy_history", "history_lastid", &id);
-
- zbx_hashset_create(&itemids_added, data_alloc, ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
-
- /* get history data in batches by ZBX_MAX_HRECORDS records and stop if: */
- /* 1) there are no more data to read */
- /* 2) we have retrieved more than the total maximum number of records */
- /* 3) we have gathered more than half of the maximum packet size */
- while (ZBX_DATA_JSON_BATCH_LIMIT > j->buffer_offset && ZBX_MAX_HRECORDS_TOTAL > records_num &&
- 0 != (data_num = proxy_get_history_data(id, &data, &data_alloc, &string_buffer,
- &string_buffer_alloc, more)))
- {
- zbx_vector_uint64_reserve(&itemids, data_num);
- zbx_vector_ptr_reserve(&records, data_num);
-
- /* filter out duplicate novalue updates */
- for (i = data_num - 1; i >= 0; i--)
- {
- if (PROXY_HISTORY_FLAG_NOVALUE == (data[i].flags & PROXY_HISTORY_MASK_NOVALUE))
- {
- if (NULL != zbx_hashset_search(&itemids_added, &data[i].itemid))
- continue;
-
- zbx_hashset_insert(&itemids_added, &data[i].itemid, sizeof(data[i].itemid));
- }
-
- zbx_vector_ptr_append(&records, &data[i]);
- zbx_vector_uint64_append(&itemids, data[i].itemid);
- }
-
- /* append history records to json */
-
- if (itemids.values_num > items_alloc)
- {
- items_alloc = itemids.values_num;
- dc_items = (DC_ITEM *)zbx_realloc(dc_items, items_alloc * sizeof(DC_ITEM));
- errcodes = (int *)zbx_realloc(errcodes, items_alloc * sizeof(int));
- }
-
- DCconfig_get_items_by_itemids(dc_items, itemids.values, errcodes, itemids.values_num);
-
- records_num = proxy_add_hist_data(j, records_num, dc_items, errcodes, &records, string_buffer, lastid);
- DCconfig_clean_items(dc_items, errcodes, itemids.values_num);
-
- /* got less data than requested - either no more data to read or the history is full of */
- /* holes. In this case send retrieved data before attempting to read/wait for more data */
- if (ZBX_MAX_HRECORDS > data_num)
- break;
-
- zbx_vector_uint64_clear(&itemids);
- zbx_vector_ptr_clear(&records);
- zbx_hashset_clear(&itemids_added);
- id = *lastid;
- }
-
- if (0 != records_num)
- zbx_json_close(j);
-
- zbx_hashset_destroy(&itemids_added);
-
- zbx_free(dc_items);
- zbx_free(errcodes);
- zbx_free(data);
- zbx_free(string_buffer);
- zbx_vector_ptr_destroy(&records);
- zbx_vector_uint64_destroy(&itemids);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s() lastid:" ZBX_FS_UI64 " records_num:%d size:~" ZBX_FS_SIZE_T " more:%d",
- __func__, *lastid, records_num, j->buffer_offset, *more);
-
- return records_num;
-}
-
-int proxy_get_dhis_data(struct zbx_json *j, zbx_uint64_t *lastid, int *more)
-{
- int records_num = 0;
- zbx_uint64_t id;
-
- proxy_get_lastid(dht.table, dht.lastidfield, &id);
-
- /* get history data in batches by ZBX_MAX_HRECORDS records and stop if: */
- /* 1) there are no more data to read */
- /* 2) we have retrieved more than the total maximum number of records */
- /* 3) we have gathered more than half of the maximum packet size */
- while (ZBX_DATA_JSON_BATCH_LIMIT > j->buffer_offset)
- {
- proxy_get_history_data_simple(j, ZBX_PROTO_TAG_DISCOVERY_DATA, &dht, lastid, &id, &records_num, more);
-
- if (ZBX_PROXY_DATA_DONE == *more || ZBX_MAX_HRECORDS_TOTAL <= records_num)
- break;
- }
-
- if (0 != records_num)
- zbx_json_close(j);
-
- return records_num;
-}
-
-int proxy_get_areg_data(struct zbx_json *j, zbx_uint64_t *lastid, int *more)
-{
- int records_num = 0;
- zbx_uint64_t id;
-
- proxy_get_lastid(areg.table, areg.lastidfield, &id);
-
- /* get history data in batches by ZBX_MAX_HRECORDS records and stop if: */
- /* 1) there are no more data to read */
- /* 2) we have retrieved more than the total maximum number of records */
- /* 3) we have gathered more than half of the maximum packet size */
- while (ZBX_DATA_JSON_BATCH_LIMIT > j->buffer_offset)
- {
- proxy_get_history_data_simple(j, ZBX_PROTO_TAG_AUTOREGISTRATION, &areg, lastid, &id, &records_num,
- more);
-
- if (ZBX_PROXY_DATA_DONE == *more || ZBX_MAX_HRECORDS_TOTAL <= records_num)
- break;
- }
-
- if (0 != records_num)
- zbx_json_close(j);
-
- return records_num;
-}
-
-int proxy_get_host_active_availability(struct zbx_json *j)
-{
- zbx_ipc_message_t response;
- int records_num = 0;
-
- zbx_ipc_message_init(&response);
- zbx_availability_send(ZBX_IPC_AVAILMAN_ACTIVE_HOSTDATA, 0, 0, &response);
-
- if (0 != response.size)
- {
- zbx_vector_proxy_hostdata_ptr_t hostdata;
-
- zbx_vector_proxy_hostdata_ptr_create(&hostdata);
- zbx_availability_deserialize_hostdata(response.data, &hostdata);
- zbx_availability_serialize_json_hostdata(&hostdata, j);
-
- records_num = hostdata.values_num;
-
- zbx_vector_proxy_hostdata_ptr_clear_ext(&hostdata, (zbx_proxy_hostdata_ptr_free_func_t)zbx_ptr_free);
- zbx_vector_proxy_hostdata_ptr_destroy(&hostdata);
- }
-
- zbx_ipc_message_clean(&response);
-
- return records_num;
-}
-
void calc_timestamp(const char *line, int *timestamp, const char *format)
{
int hh, mm, ss, yyyy, dd, MM;
@@ -1155,6 +30,7 @@ void calc_timestamp(const char *line, int *timestamp, const char *format)
struct tm tm;
time_t t;
+
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
hh = mm = ss = yyyy = dd = MM = 0;
@@ -1217,1637 +93,6 @@ void calc_timestamp(const char *line, int *timestamp, const char *format)
/******************************************************************************
* *
- * Purpose: processes item value depending on proxy/flags settings *
- * *
- * Parameters: item - [IN] the item to process *
- * result - [IN] the item result *
- * *
- * Comments: Values gathered by server are sent to the preprocessing manager, *
- * while values received from proxy are already preprocessed and *
- * must be either directly stored to history cache or sent to lld *
- * manager. *
- * *
- ******************************************************************************/
-static void process_item_value(const DC_ITEM *item, AGENT_RESULT *result, zbx_timespec_t *ts, int *h_num,
- char *error)
-{
- if (0 == item->host.proxy_hostid)
- {
- zbx_preprocess_item_value(item->itemid, item->host.hostid, item->value_type, item->flags, result, ts,
- item->state, error);
- *h_num = 0;
- }
- else
- {
- if (0 != (ZBX_FLAG_DISCOVERY_RULE & item->flags))
- {
- zbx_lld_process_agent_result(item->itemid, item->host.hostid, result, ts, error);
- *h_num = 0;
- }
- else
- {
- dc_add_history(item->itemid, item->value_type, item->flags, result, ts, item->state, error);
- *h_num = 1;
- }
- }
-}
-
-/******************************************************************************
- * *
- * Purpose: process single value from incoming history data *
- * *
- * Parameters: item - [IN] the item to process *
- * value - [IN] the value to process *
- * hval - [OUT] indication that value was added to history *
- * *
- * Return value: SUCCEED - the value was processed successfully *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int process_history_data_value(DC_ITEM *item, zbx_agent_value_t *value, int *h_num)
-{
- if (ITEM_STATUS_ACTIVE != item->status)
- return FAIL;
-
- if (HOST_STATUS_MONITORED != item->host.status)
- return FAIL;
-
- /* update item nextcheck during maintenance */
- if (SUCCEED == in_maintenance_without_data_collection(item->host.maintenance_status,
- item->host.maintenance_type, item->type) &&
- item->host.maintenance_from <= value->ts.sec)
- {
- return SUCCEED;
- }
-
- if (NULL == value->value && ITEM_STATE_NOTSUPPORTED == value->state)
- {
- THIS_SHOULD_NEVER_HAPPEN;
- return FAIL;
- }
-
- if (ITEM_STATE_NOTSUPPORTED == value->state ||
- (NULL != value->value && 0 == strcmp(value->value, ZBX_NOTSUPPORTED)))
- {
- zabbix_log(LOG_LEVEL_DEBUG, "item [%s:%s] error: %s", item->host.host, item->key_orig, value->value);
-
- item->state = ITEM_STATE_NOTSUPPORTED;
- process_item_value(item, NULL, &value->ts, h_num, value->value);
- }
- else
- {
- AGENT_RESULT result;
-
- zbx_init_agent_result(&result);
-
- if (NULL != value->value)
- {
- if (ITEM_VALUE_TYPE_LOG == item->value_type)
- {
- zbx_log_t *log;
-
- log = (zbx_log_t *)zbx_malloc(NULL, sizeof(zbx_log_t));
- log->value = zbx_strdup(NULL, value->value);
- zbx_replace_invalid_utf8(log->value);
-
- if (0 == value->timestamp)
- {
- log->timestamp = 0;
- calc_timestamp(log->value, &log->timestamp, item->logtimefmt);
- }
- else
- log->timestamp = value->timestamp;
-
- log->logeventid = value->logeventid;
- log->severity = value->severity;
-
- if (NULL != value->source)
- {
- log->source = zbx_strdup(NULL, value->source);
- zbx_replace_invalid_utf8(log->source);
- }
- else
- log->source = NULL;
-
- SET_LOG_RESULT(&result, log);
- }
- else
- zbx_set_agent_result_type(&result, ITEM_VALUE_TYPE_TEXT, value->value);
- }
-
- if (0 != value->meta)
- zbx_set_agent_result_meta(&result, value->lastlogsize, value->mtime);
-
- if (0 != ZBX_ISSET_VALUE(&result) || 0 != ZBX_ISSET_META(&result))
- {
- item->state = ITEM_STATE_NORMAL;
- process_item_value(item, &result, &value->ts, h_num, NULL);
- }
-
- zbx_free_agent_result(&result);
- }
-
- return SUCCEED;
-}
-
-/******************************************************************************
- * *
- * Purpose: process new item values *
- * *
- * Parameters: items - [IN] the items to process *
- * values - [IN] the item values value to process *
- * errcodes - [IN/OUT] in - item configuration error code *
- * (FAIL - item/host was not found) *
- * out - value processing result *
- * (SUCCEED - processed, FAIL - error) *
- * values_num - [IN] the number of items/values to process *
- * nodata_win - [IN/OUT] proxy communication delay info *
- * *
- * Return value: the number of processed values *
- * *
- ******************************************************************************/
-int process_history_data(DC_ITEM *items, zbx_agent_value_t *values, int *errcodes, size_t values_num,
- zbx_proxy_suppress_t *nodata_win)
-{
- size_t i;
- int processed_num = 0, history_num;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- for (i = 0; i < values_num; i++)
- {
- if (SUCCEED != errcodes[i])
- continue;
-
- history_num = 0;
-
- if (SUCCEED != process_history_data_value(&items[i], &values[i], &history_num))
- {
- /* clean failed items to avoid updating their runtime data */
- DCconfig_clean_items(&items[i], &errcodes[i], 1);
- errcodes[i] = FAIL;
- continue;
- }
-
- if (0 != items[i].host.proxy_hostid && NULL != nodata_win &&
- 0 != (nodata_win->flags & ZBX_PROXY_SUPPRESS_ACTIVE) && 0 < history_num)
- {
- if (values[i].ts.sec <= nodata_win->period_end)
- {
- nodata_win->values_num++;
- }
- else
- {
- nodata_win->flags &= (~ZBX_PROXY_SUPPRESS_MORE);
- }
-
- zabbix_log(LOG_LEVEL_TRACE, "%s() flags:%d values_num:%d value_time:%d period_end:%d",
- __func__, nodata_win->flags, nodata_win->values_num, values[i].ts.sec,
- nodata_win->period_end);
- }
-
- processed_num++;
- }
-
- if (0 < processed_num)
- zbx_dc_items_update_nextcheck(items, values, errcodes, values_num);
-
- zbx_preprocessor_flush();
- dc_flush_history();
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s() processed:%d", __func__, processed_num);
-
- return processed_num;
-}
-
-/******************************************************************************
- * *
- * Purpose: frees resources allocated to store agent values *
- * *
- * Parameters: values - [IN] the values to clean *
- * values_num - [IN] the number of items in values array *
- * *
- ******************************************************************************/
-static void zbx_agent_values_clean(zbx_agent_value_t *values, size_t values_num)
-{
- size_t i;
-
- for (i = 0; i < values_num; i++)
- {
- zbx_free(values[i].value);
- zbx_free(values[i].source);
- }
-}
-
-/******************************************************************************
- * *
- * Purpose: calculates difference between server and client (proxy, active *
- * agent or sender) time and log it *
- * *
- * Parameters: level - [IN] log level *
- * jp - [IN] JSON with clock, [ns] fields *
- * ts_recv - [IN] the connection timestamp *
- * *
- ******************************************************************************/
-static void log_client_timediff(int level, struct zbx_json_parse *jp, const zbx_timespec_t *ts_recv)
-{
- char tmp[32];
- zbx_timespec_t client_timediff;
- int sec, ns;
-
- if (SUCCEED != ZBX_CHECK_LOG_LEVEL(level))
- return;
-
- if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp), NULL))
- {
- sec = atoi(tmp);
- client_timediff.sec = ts_recv->sec - sec;
-
- if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_NS, tmp, sizeof(tmp), NULL))
- {
- ns = atoi(tmp);
- client_timediff.ns = ts_recv->ns - ns;
-
- if (client_timediff.sec > 0 && client_timediff.ns < 0)
- {
- client_timediff.sec--;
- client_timediff.ns += 1000000000;
- }
- else if (client_timediff.sec < 0 && client_timediff.ns > 0)
- {
- client_timediff.sec++;
- client_timediff.ns -= 1000000000;
- }
-
- zabbix_log(level, "%s(): timestamp from json %d seconds and %d nanosecond, "
- "delta time from json %d seconds and %d nanosecond",
- __func__, sec, ns, client_timediff.sec, client_timediff.ns);
- }
- else
- {
- zabbix_log(level, "%s(): timestamp from json %d seconds, "
- "delta time from json %d seconds", __func__, sec, client_timediff.sec);
- }
- }
-}
-
-/******************************************************************************
- * *
- * Purpose: parses agent value from history data json row *
- * *
- * Parameters: jp_row - [IN] JSON with history data row *
- * unique_shift - [IN/OUT] auto increment nanoseconds to ensure *
- * unique value of timestamps *
- * av - [OUT] the agent value *
- * *
- * Return value: SUCCEED - the value was parsed successfully *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int parse_history_data_row_value(const struct zbx_json_parse *jp_row, zbx_timespec_t *unique_shift,
- zbx_agent_value_t *av)
-{
- char *tmp = NULL;
- size_t tmp_alloc = 0;
- int ret = FAIL;
-
- memset(av, 0, sizeof(zbx_agent_value_t));
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_CLOCK, &tmp, &tmp_alloc, NULL))
- {
- if (FAIL == zbx_is_uint31(tmp, &av->ts.sec))
- goto out;
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_NS, &tmp, &tmp_alloc, NULL))
- {
- if (FAIL == zbx_is_uint_n_range(tmp, tmp_alloc, &av->ts.ns, sizeof(av->ts.ns),
- 0LL, 999999999LL))
- {
- goto out;
- }
- }
- else
- {
- /* ensure unique value timestamp (clock, ns) if only clock is available */
-
- av->ts.sec += unique_shift->sec;
- av->ts.ns = unique_shift->ns++;
-
- if (unique_shift->ns > 999999999)
- {
- unique_shift->sec++;
- unique_shift->ns = 0;
- }
- }
- }
- else
- zbx_timespec(&av->ts);
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_STATE, &tmp, &tmp_alloc, NULL))
- av->state = (unsigned char)atoi(tmp);
-
- /* Unsupported item meta information must be ignored for backwards compatibility. */
- /* New agents will not send meta information for items in unsupported state. */
- if (ITEM_STATE_NOTSUPPORTED != av->state)
- {
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LASTLOGSIZE, &tmp, &tmp_alloc, NULL))
- {
- av->meta = 1; /* contains meta information */
-
- zbx_is_uint64(tmp, &av->lastlogsize);
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_MTIME, &tmp, &tmp_alloc, NULL))
- av->mtime = atoi(tmp);
- }
- }
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_VALUE, &tmp, &tmp_alloc, NULL))
- av->value = zbx_strdup(av->value, tmp);
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGTIMESTAMP, &tmp, &tmp_alloc, NULL))
- av->timestamp = atoi(tmp);
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGSOURCE, &tmp, &tmp_alloc, NULL))
- av->source = zbx_strdup(av->source, tmp);
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGSEVERITY, &tmp, &tmp_alloc, NULL))
- av->severity = atoi(tmp);
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGEVENTID, &tmp, &tmp_alloc, NULL))
- av->logeventid = atoi(tmp);
-
- if (SUCCEED != zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_ID, &tmp, &tmp_alloc, NULL) ||
- SUCCEED != zbx_is_uint64(tmp, &av->id))
- {
- av->id = 0;
- }
-
- zbx_free(tmp);
-
- ret = SUCCEED;
-out:
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: parses item identifier from history data json row *
- * *
- * Parameters: jp_row - [IN] JSON with history data row *
- * itemid - [OUT] the item identifier *
- * *
- * Return value: SUCCEED - the item identifier was parsed successfully *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int parse_history_data_row_itemid(const struct zbx_json_parse *jp_row, zbx_uint64_t *itemid)
-{
- char buffer[MAX_ID_LEN + 1];
-
- if (SUCCEED != zbx_json_value_by_name(jp_row, ZBX_PROTO_TAG_ITEMID, buffer, sizeof(buffer), NULL))
- return FAIL;
-
- if (SUCCEED != zbx_is_uint64(buffer, itemid))
- return FAIL;
-
- return SUCCEED;
-}
-/******************************************************************************
- * *
- * Purpose: parses host,key pair from history data json row *
- * *
- * Parameters: jp_row - [IN] JSON with history data row *
- * hk - [OUT] the host,key pair *
- * *
- * Return value: SUCCEED - the host,key pair was parsed successfully *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int parse_history_data_row_hostkey(const struct zbx_json_parse *jp_row, zbx_host_key_t *hk)
-{
- size_t str_alloc;
-
- str_alloc = 0;
- zbx_free(hk->host);
-
- if (SUCCEED != zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_HOST, &hk->host, &str_alloc, NULL))
- return FAIL;
-
- str_alloc = 0;
- zbx_free(hk->key);
-
- if (SUCCEED != zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_KEY, &hk->key, &str_alloc, NULL))
- {
- zbx_free(hk->host);
- return FAIL;
- }
-
- return SUCCEED;
-}
-
-/******************************************************************************
- * *
- * Purpose: parses up to ZBX_HISTORY_VALUES_MAX item values and host,key *
- * pairs from history data json *
- * *
- * Parameters: jp_data - [IN] JSON with history data array *
- * pnext - [IN/OUT] the pointer to the next item in json, *
- * NULL - no more data left *
- * values - [OUT] the item values *
- * hostkeys - [OUT] the corresponding host,key pairs *
- * values_num - [OUT] number of elements in values and hostkeys *
- * arrays *
- * parsed_num - [OUT] the number of values parsed *
- * unique_shift - [IN/OUT] auto increment nanoseconds to ensure *
- * unique value of timestamps *
- * *
- * Return value: SUCCEED - values were parsed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-static int parse_history_data(struct zbx_json_parse *jp_data, const char **pnext, zbx_agent_value_t *values,
- zbx_host_key_t *hostkeys, int *values_num, int *parsed_num, zbx_timespec_t *unique_shift)
-{
- struct zbx_json_parse jp_row;
- int ret = FAIL;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- *values_num = 0;
- *parsed_num = 0;
-
- if (NULL == *pnext)
- {
- if (NULL == (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX)
- {
- ret = SUCCEED;
- goto out;
- }
- }
-
- /* iterate the history data rows */
- do
- {
- if (FAIL == zbx_json_brackets_open(*pnext, &jp_row))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s", zbx_json_strerror());
- goto out;
- }
-
- (*parsed_num)++;
-
- if (SUCCEED != parse_history_data_row_hostkey(&jp_row, &hostkeys[*values_num]))
- continue;
-
- if (SUCCEED != parse_history_data_row_value(&jp_row, unique_shift, &values[*values_num]))
- continue;
-
- (*values_num)++;
- }
- while (NULL != (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX);
-
- ret = SUCCEED;
-out:
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s processed:%d/%d", __func__, zbx_result_string(ret),
- *values_num, *parsed_num);
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: parses up to ZBX_HISTORY_VALUES_MAX item values and item *
- * identifiers from history data json *
- * *
- * Parameters: jp_data - [IN] JSON with history data array *
- * pnext - [IN/OUT] the pointer to the next item in *
- * json, NULL - no more data left *
- * values - [OUT] the item values *
- * itemids - [OUT] the corresponding item identifiers *
- * values_num - [OUT] number of elements in values and itemids *
- * arrays *
- * parsed_num - [OUT] the number of values parsed *
- * unique_shift - [IN/OUT] auto increment nanoseconds to ensure *
- * unique value of timestamps *
- * info - [OUT] address of a pointer to the info string *
- * (should be freed by the caller) *
- * *
- * Return value: SUCCEED - values were parsed successfully *
- * FAIL - an error occurred *
- * *
- * Comments: This function is used to parse the new proxy history data *
- * protocol introduced in Zabbix v3.3. *
- * *
- ******************************************************************************/
-static int parse_history_data_by_itemids(struct zbx_json_parse *jp_data, const char **pnext,
- zbx_agent_value_t *values, zbx_uint64_t *itemids, int *values_num, int *parsed_num,
- zbx_timespec_t *unique_shift, char **error)
-{
- struct zbx_json_parse jp_row;
- int ret = FAIL;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- *values_num = 0;
- *parsed_num = 0;
-
- if (NULL == *pnext)
- {
- if (NULL == (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX)
- {
- ret = SUCCEED;
- goto out;
- }
- }
-
- /* iterate the history data rows */
- do
- {
- if (FAIL == zbx_json_brackets_open(*pnext, &jp_row))
- {
- *error = zbx_strdup(*error, zbx_json_strerror());
- goto out;
- }
-
- (*parsed_num)++;
-
- if (SUCCEED != parse_history_data_row_itemid(&jp_row, &itemids[*values_num]))
- continue;
-
- if (SUCCEED != parse_history_data_row_value(&jp_row, unique_shift, &values[*values_num]))
- continue;
-
- (*values_num)++;
- }
- while (NULL != (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX);
-
- ret = SUCCEED;
-out:
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s processed:%d/%d", __func__, zbx_result_string(ret),
- *values_num, *parsed_num);
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: validates item received from proxy *
- * *
- * Parameters: item - [IN/OUT] the item data *
- * sock - [IN] the connection socket *
- * args - [IN] the validator arguments *
- * error - unused *
- * *
- * Return value: SUCCEED - the validation was successful *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int proxy_item_validator(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error)
-{
- zbx_uint64_t *proxyid = (zbx_uint64_t *)args;
-
- ZBX_UNUSED(sock);
- ZBX_UNUSED(error);
-
- /* don't process item if its host was assigned to another proxy */
- if (item->host.proxy_hostid != *proxyid)
- return FAIL;
-
- /* don't process aggregate/calculated items coming from proxy */
- if (ITEM_TYPE_CALCULATED == item->type)
- return FAIL;
-
- return SUCCEED;
-}
-
-/******************************************************************************
- * *
- * Purpose: parses history data array and process the data *
- * *
- * *
- * Parameters: sock - [IN] socket for host permission validation *
- * validator_func - [IN] function to validate item permission *
- * validator_args - [IN] validator function arguments *
- * jp_data - [IN] JSON with history data array *
- * session - [IN] the data session *
- * nodata_win - [OUT] counter of delayed values *
- * info - [OUT] address of a pointer to the info *
- * string (should be freed by the caller) *
- * mode - [IN] item retrieve mode is used to retrieve *
- * only necessary data to reduce time *
- * spent holding read lock *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- * Comments: This function is used to parse the new proxy history data *
- * protocol introduced in Zabbix v3.3. *
- * *
- ******************************************************************************/
-static int process_history_data_by_itemids(zbx_socket_t *sock, zbx_client_item_validator_t validator_func,
- void *validator_args, struct zbx_json_parse *jp_data, zbx_session_t *session,
- zbx_proxy_suppress_t *nodata_win, char **info, unsigned int mode)
-{
- const char *pnext = NULL;
- int ret = SUCCEED, processed_num = 0, total_num = 0, values_num, read_num, i, *errcodes;
- double sec;
- DC_ITEM *items;
- char *error = NULL;
- zbx_uint64_t itemids[ZBX_HISTORY_VALUES_MAX], last_valueid = 0;
- zbx_agent_value_t values[ZBX_HISTORY_VALUES_MAX];
- zbx_timespec_t unique_shift = {0, 0};
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- items = (DC_ITEM *)zbx_malloc(NULL, sizeof(DC_ITEM) * ZBX_HISTORY_VALUES_MAX);
- errcodes = (int *)zbx_malloc(NULL, sizeof(int) * ZBX_HISTORY_VALUES_MAX);
-
- sec = zbx_time();
-
- while (SUCCEED == parse_history_data_by_itemids(jp_data, &pnext, values, itemids, &values_num, &read_num,
- &unique_shift, &error) && 0 != values_num)
- {
- DCconfig_get_items_by_itemids_partial(items, itemids, errcodes, values_num, mode);
-
- for (i = 0; i < values_num; i++)
- {
- if (SUCCEED != errcodes[i])
- continue;
-
- /* check and discard if duplicate data */
- if (NULL != session && 0 != values[i].id && values[i].id <= session->last_id)
- {
- DCconfig_clean_items(&items[i], &errcodes[i], 1);
- errcodes[i] = FAIL;
- continue;
- }
-
- if (SUCCEED != validator_func(&items[i], sock, validator_args, &error))
- {
- if (NULL != error)
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s", error);
- zbx_free(error);
- }
-
- DCconfig_clean_items(&items[i], &errcodes[i], 1);
- errcodes[i] = FAIL;
- }
- }
-
- processed_num += process_history_data(items, values, errcodes, values_num, nodata_win);
-
- total_num += read_num;
-
- last_valueid = values[values_num - 1].id;
-
- DCconfig_clean_items(items, errcodes, values_num);
- zbx_agent_values_clean(values, values_num);
-
- if (NULL == pnext)
- break;
- }
-
- if (NULL != session && 0 != last_valueid)
- {
- if (session->last_id > last_valueid)
- {
- zabbix_log(LOG_LEVEL_WARNING, "received id:" ZBX_FS_UI64 " is less than last id:"
- ZBX_FS_UI64, last_valueid, session->last_id);
- }
- else
- session->last_id = last_valueid;
- }
-
- zbx_free(errcodes);
- zbx_free(items);
-
- if (NULL == error)
- {
- ret = SUCCEED;
- *info = zbx_dsprintf(*info, "processed: %d; failed: %d; total: %d; seconds spent: " ZBX_FS_DBL,
- processed_num, total_num - processed_num, total_num, zbx_time() - sec);
- }
- else
- {
- zbx_free(*info);
- *info = error;
- }
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: validates item received from active agent *
- * *
- * Parameters: item - [IN] the item data *
- * sock - [IN] the connection socket *
- * args - [IN] the validator arguments *
- * error - [OUT] the error message *
- * *
- * Return value: SUCCEED - the validation was successful *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int agent_item_validator(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error)
-{
- zbx_host_rights_t *rights = (zbx_host_rights_t *)args;
-
- if (0 != item->host.proxy_hostid)
- return FAIL;
-
- if (ITEM_TYPE_ZABBIX_ACTIVE != item->type)
- return FAIL;
-
- if (rights->hostid != item->host.hostid)
- {
- rights->hostid = item->host.hostid;
- rights->value = zbx_host_check_permissions(&item->host, sock, error);
- }
-
- return rights->value;
-}
-
-/******************************************************************************
- * *
- * Purpose: validates item received from sender *
- * *
- * Parameters: item - [IN] the item data *
- * sock - [IN] the connection socket *
- * args - [IN] the validator arguments *
- * error - [OUT] the error message *
- * *
- * Return value: SUCCEED - the validation was successful *
- * FAIL - otherwise *
- * *
- ******************************************************************************/
-static int sender_item_validator(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error)
-{
- zbx_host_rights_t *rights;
- char key_short[VALUE_ERRMSG_MAX * ZBX_MAX_BYTES_IN_UTF8_CHAR + 1];
-
- if (0 != item->host.proxy_hostid)
- return FAIL;
-
- switch(item->type)
- {
- case ITEM_TYPE_HTTPAGENT:
- if (0 == item->allow_traps)
- {
- *error = zbx_dsprintf(*error, "cannot process HTTP agent item \"%s\" trap:"
- " trapping is not enabled", zbx_truncate_itemkey(item->key_orig,
- VALUE_ERRMSG_MAX, key_short, sizeof(key_short)));
- return FAIL;
- }
- break;
- case ITEM_TYPE_TRAPPER:
- break;
- default:
- *error = zbx_dsprintf(*error, "cannot process item \"%s\" trap:"
- " item type \"%d\" cannot be used with traps",
- zbx_truncate_itemkey(item->key_orig, VALUE_ERRMSG_MAX, key_short,
- sizeof(key_short)), item->type);
- return FAIL;
- }
-
- if ('\0' != *item->trapper_hosts) /* list of allowed hosts not empty */
- {
- char *allowed_peers;
- int ret;
-
- allowed_peers = zbx_strdup(NULL, item->trapper_hosts);
- zbx_substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, item, NULL, NULL, NULL, NULL, NULL,
- &allowed_peers, MACRO_TYPE_ALLOWED_HOSTS, NULL, 0);
- ret = zbx_tcp_check_allowed_peers(sock, allowed_peers);
- zbx_free(allowed_peers);
-
- if (FAIL == ret)
- {
- *error = zbx_dsprintf(*error, "cannot process item \"%s\" trap: %s",
- zbx_truncate_itemkey(item->key_orig, VALUE_ERRMSG_MAX, key_short,
- sizeof(key_short)), zbx_socket_strerror());
- return FAIL;
- }
- }
-
- rights = (zbx_host_rights_t *)args;
-
- if (rights->hostid != item->host.hostid)
- {
- rights->hostid = item->host.hostid;
- rights->value = zbx_host_check_permissions(&item->host, sock, error);
- }
-
- return rights->value;
-}
-
-static void process_history_data_by_keys(zbx_socket_t *sock, zbx_client_item_validator_t validator_func,
- void *validator_args, char **info, struct zbx_json_parse *jp_data, const char *token)
-{
- int values_num, read_num, processed_num = 0, total_num = 0, i;
- zbx_timespec_t unique_shift = {0, 0};
- const char *pnext = NULL;
- char *error = NULL;
- zbx_host_key_t *hostkeys;
- DC_ITEM *items;
- zbx_session_t *session = NULL;
- zbx_uint64_t last_hostid = 0;
- zbx_agent_value_t values[ZBX_HISTORY_VALUES_MAX];
- int errcodes[ZBX_HISTORY_VALUES_MAX];
- double sec;
-
- sec = zbx_time();
-
- items = (DC_ITEM *)zbx_malloc(NULL, sizeof(DC_ITEM) * ZBX_HISTORY_VALUES_MAX);
- hostkeys = (zbx_host_key_t *)zbx_malloc(NULL, sizeof(zbx_host_key_t) * ZBX_HISTORY_VALUES_MAX);
- memset(hostkeys, 0, sizeof(zbx_host_key_t) * ZBX_HISTORY_VALUES_MAX);
-
- while (SUCCEED == parse_history_data(jp_data, &pnext, values, hostkeys, &values_num, &read_num,
- &unique_shift) && 0 != values_num)
- {
- DCconfig_get_items_by_keys(items, hostkeys, errcodes, values_num);
-
- for (i = 0; i < values_num; i++)
- {
- if (SUCCEED != errcodes[i])
- {
- zabbix_log(LOG_LEVEL_DEBUG, "cannot retrieve key \"%s\" on host \"%s\" from "
- "configuration cache", hostkeys[i].key, hostkeys[i].host);
- continue;
- }
-
- if (last_hostid != items[i].host.hostid)
- {
- last_hostid = items[i].host.hostid;
-
- if (NULL != token)
- {
- session = zbx_dc_get_or_create_session(last_hostid, token,
- ZBX_SESSION_TYPE_DATA);
- }
- }
-
- /* check and discard if duplicate data */
- if (NULL != session && 0 != values[i].id && values[i].id <= session->last_id)
- {
- DCconfig_clean_items(&items[i], &errcodes[i], 1);
- errcodes[i] = FAIL;
- continue;
- }
-
- if (SUCCEED != validator_func(&items[i], sock, validator_args, &error))
- {
- if (NULL != error)
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s", error);
- zbx_free(error);
- }
- else
- {
- zabbix_log(LOG_LEVEL_DEBUG, "unknown validation error for item \"%s\"",
- (NULL == items[i].key) ? items[i].key_orig : items[i].key);
- }
-
- DCconfig_clean_items(&items[i], &errcodes[i], 1);
- errcodes[i] = FAIL;
- }
-
- if (NULL != session)
- session->last_id = values[i].id;
- }
-
- processed_num += process_history_data(items, values, errcodes, values_num, NULL);
- total_num += read_num;
-
- DCconfig_clean_items(items, errcodes, values_num);
- zbx_agent_values_clean(values, values_num);
-
- if (NULL == pnext)
- break;
- }
-
- for (i = 0; i < ZBX_HISTORY_VALUES_MAX; i++)
- {
- zbx_free(hostkeys[i].host);
- zbx_free(hostkeys[i].key);
- }
-
- zbx_free(hostkeys);
- zbx_free(items);
-
- *info = zbx_dsprintf(*info, "processed: %d; failed: %d; total: %d; seconds spent: " ZBX_FS_DBL,
- processed_num, total_num - processed_num, total_num, zbx_time() - sec);
-}
-
-/******************************************************************************
- * *
- * Purpose: process history data sent by proxy/agent/sender *
- * *
- * Parameters: sock - [IN] the connection socket *
- * jp - [IN] JSON with historical data *
- * ts - [IN] the client connection timestamp *
- * validator_func - [IN] the item validator callback function *
- * validator_args - [IN] the user arguments passed to validator *
- * function *
- * info - [OUT] address of a pointer to the info string *
- * (should be freed by the caller) *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-static int process_client_history_data(zbx_socket_t *sock, struct zbx_json_parse *jp, zbx_timespec_t *ts,
- zbx_client_item_validator_t validator_func, void *validator_args, char **info)
-{
- int ret;
- char *token = NULL;
- size_t token_alloc = 0;
- struct zbx_json_parse jp_data;
- char tmp[MAX_STRING_LEN];
- int version;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- log_client_timediff(LOG_LEVEL_DEBUG, jp, ts);
-
- if (SUCCEED != (ret = zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_DATA, &jp_data)))
- {
- *info = zbx_strdup(*info, zbx_json_strerror());
- goto out;
- }
-
- if (SUCCEED == zbx_json_value_by_name_dyn(jp, ZBX_PROTO_TAG_SESSION, &token, &token_alloc, NULL))
- {
- size_t token_len;
-
- if (ZBX_SESSION_TOKEN_SIZE != (token_len = strlen(token)))
- {
- *info = zbx_dsprintf(*info, "invalid session token length %d", (int)token_len);
- ret = FAIL;
- goto out;
- }
- }
-
- if (SUCCEED != zbx_json_value_by_name(jp, ZBX_PROTO_TAG_VERSION, tmp, sizeof(tmp), NULL) ||
- FAIL == (version = zbx_get_component_version_without_patch(tmp)))
- {
- version = ZBX_COMPONENT_VERSION(4, 2, 0);
- }
-
- if (ZBX_COMPONENT_VERSION(4, 4, 0) <= version &&
- SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, tmp, sizeof(tmp), NULL))
- {
- zbx_session_t *session;
- zbx_uint64_t hostid;
-
- if (SUCCEED != DCconfig_get_hostid_by_name(tmp, &hostid))
- {
- *info = zbx_dsprintf(*info, "unknown host '%s'", tmp);
- ret = SUCCEED;
- goto out;
- }
-
- if (NULL == token)
- session = NULL;
- else
- session = zbx_dc_get_or_create_session(hostid, token, ZBX_SESSION_TYPE_DATA);
-
- if (SUCCEED != (ret = process_history_data_by_itemids(sock, validator_func, validator_args, &jp_data,
- session, NULL, info, ZBX_ITEM_GET_DEFAULT)))
- {
- goto out;
- }
- }
- else
- process_history_data_by_keys(sock, validator_func, validator_args, info, &jp_data, token);
-out:
- zbx_free(token);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: process history data received from Zabbix active agent *
- * *
- * Parameters: sock - [IN] the connection socket *
- * jp - [IN] the JSON with history data *
- * ts - [IN] the connection timestamp *
- * info - [OUT] address of a pointer to the info string *
- * (should be freed by the caller) *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-int process_agent_history_data(zbx_socket_t *sock, struct zbx_json_parse *jp, zbx_timespec_t *ts, char **info)
-{
- zbx_host_rights_t rights = {0};
-
- return process_client_history_data(sock, jp, ts, agent_item_validator, &rights, info);
-}
-
-/******************************************************************************
- * *
- * Purpose: process history data received from Zabbix sender *
- * *
- * Parameters: sock - [IN] the connection socket *
- * jp - [IN] the JSON with history data *
- * ts - [IN] the connection timestamp *
- * info - [OUT] address of a pointer to the info string *
- * (should be freed by the caller) *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-int process_sender_history_data(zbx_socket_t *sock, struct zbx_json_parse *jp, zbx_timespec_t *ts, char **info)
-{
- zbx_host_rights_t rights = {0};
- int ret;
- zbx_dc_um_handle_t *um_handle;
-
- um_handle = zbx_dc_open_user_macros();
-
- ret = process_client_history_data(sock, jp, ts, sender_item_validator, &rights, info);
-
- zbx_dc_close_user_macros(um_handle);
-
- return ret;
-}
-
-static void zbx_drule_ip_free(zbx_drule_ip_t *ip)
-{
- zbx_vector_ptr_clear_ext(&ip->services, zbx_ptr_free);
- zbx_vector_ptr_destroy(&ip->services);
- zbx_free(ip);
-}
-
-static void zbx_drule_free(zbx_drule_t *drule)
-{
- zbx_vector_ptr_clear_ext(&drule->ips, (zbx_clean_func_t)zbx_drule_ip_free);
- zbx_vector_ptr_destroy(&drule->ips);
- zbx_vector_uint64_destroy(&drule->dcheckids);
- zbx_free(drule);
-}
-
-/******************************************************************************
- * *
- * Purpose: process services discovered on IP address *
- * *
- * Parameters: drule_ptr - [IN] discovery rule structure *
- * ip_discovered_ptr - [IN] vector of ip addresses *
- * *
- ******************************************************************************/
-static int process_services(const zbx_vector_ptr_t *services, const char *ip, zbx_uint64_t druleid,
- zbx_vector_uint64_t *dcheckids, zbx_uint64_t unique_dcheckid, int *processed_num, int ip_idx)
-{
- ZBX_DB_DHOST dhost;
- zbx_service_t *service;
- int services_num, ret = FAIL, i, dchecks = 0;
- zbx_vector_ptr_t services_old;
- ZBX_DB_DRULE drule = {.druleid = druleid, .unique_dcheckid = unique_dcheckid};
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- memset(&dhost, 0, sizeof(dhost));
-
- zbx_vector_ptr_create(&services_old);
-
- /* find host update */
- for (i = *processed_num; i < services->values_num; i++)
- {
- service = (zbx_service_t *)services->values[i];
-
- zabbix_log(LOG_LEVEL_DEBUG, "%s() druleid:" ZBX_FS_UI64 " dcheckid:" ZBX_FS_UI64 " unique_dcheckid:"
- ZBX_FS_UI64 " time:'%s %s' ip:'%s' dns:'%s' port:%hu status:%d value:'%s'",
- __func__, drule.druleid, service->dcheckid, drule.unique_dcheckid,
- zbx_date2str(service->itemtime, NULL), zbx_time2str(service->itemtime, NULL), ip, service->dns,
- service->port, service->status, service->value);
-
- if (0 == service->dcheckid)
- break;
-
- dchecks++;
- }
-
- /* stop processing current discovery rule and save proxy history until host update is available */
- if (i == services->values_num)
- {
- for (i = *processed_num; i < services->values_num; i++)
- {
- char *ip_esc, *dns_esc, *value_esc;
-
- service = (zbx_service_t *)services->values[i];
-
- ip_esc = DBdyn_escape_field("proxy_dhistory", "ip", ip);
- dns_esc = DBdyn_escape_field("proxy_dhistory", "dns", service->dns);
- value_esc = DBdyn_escape_field("proxy_dhistory", "value", service->value);
-
- DBexecute("insert into proxy_dhistory (clock,druleid,ip,port,value,status,dcheckid,dns)"
- " values (%d," ZBX_FS_UI64 ",'%s',%d,'%s',%d," ZBX_FS_UI64 ",'%s')",
- (int)service->itemtime, drule.druleid, ip_esc, service->port,
- value_esc, service->status, service->dcheckid, dns_esc);
- zbx_free(value_esc);
- zbx_free(dns_esc);
- zbx_free(ip_esc);
- }
-
- goto fail;
- }
-
- services_num = i;
-
- if (0 == *processed_num && 0 == ip_idx)
- {
- DB_RESULT result;
- DB_ROW row;
- zbx_uint64_t dcheckid;
-
- result = DBselect(
- "select dcheckid,clock,port,value,status,dns,ip"
- " from proxy_dhistory"
- " where druleid=" ZBX_FS_UI64
- " order by id",
- drule.druleid);
-
- for (i = 0; NULL != (row = DBfetch(result)); i++)
- {
- if (SUCCEED == DBis_null(row[0]))
- continue;
-
- ZBX_STR2UINT64(dcheckid, row[0]);
-
- if (0 == strcmp(ip, row[6]))
- {
- service = (zbx_service_t *)zbx_malloc(NULL, sizeof(zbx_service_t));
- service->dcheckid = dcheckid;
- service->itemtime = (time_t)atoi(row[1]);
- service->port = atoi(row[2]);
- zbx_strlcpy_utf8(service->value, row[3], ZBX_MAX_DISCOVERED_VALUE_SIZE);
- service->status = atoi(row[4]);
- zbx_strlcpy(service->dns, row[5], ZBX_INTERFACE_DNS_LEN_MAX);
- zbx_vector_ptr_append(&services_old, service);
- zbx_vector_uint64_append(dcheckids, service->dcheckid);
- dchecks++;
- }
- }
- DBfree_result(result);
-
- if (0 != i)
- {
- DBexecute("delete from proxy_dhistory"
- " where druleid=" ZBX_FS_UI64,
- drule.druleid);
- }
-
- zbx_vector_uint64_sort(dcheckids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
- zbx_vector_uint64_uniq(dcheckids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
-
- if (SUCCEED != DBlock_druleid(drule.druleid))
- {
- zabbix_log(LOG_LEVEL_DEBUG, "druleid:" ZBX_FS_UI64 " does not exist", drule.druleid);
- goto fail;
- }
-
- if (SUCCEED != DBlock_ids("dchecks", "dcheckid", dcheckids))
- {
- zabbix_log(LOG_LEVEL_DEBUG, "checks are not available for druleid:" ZBX_FS_UI64, drule.druleid);
- goto fail;
- }
- }
-
- if (0 == dchecks)
- {
- zabbix_log(LOG_LEVEL_DEBUG, "cannot process host update without services");
- goto fail;
- }
-
- for (i = 0; i < services_old.values_num; i++)
- {
- service = (zbx_service_t *)services_old.values[i];
-
- if (FAIL == zbx_vector_uint64_bsearch(dcheckids, service->dcheckid, ZBX_DEFAULT_UINT64_COMPARE_FUNC))
- {
- zabbix_log(LOG_LEVEL_DEBUG, "dcheckid:" ZBX_FS_UI64 " does not exist", service->dcheckid);
- continue;
- }
-
- zbx_discovery_update_service(&drule, service->dcheckid, &dhost, ip, service->dns, service->port,
- service->status, service->value, service->itemtime);
- }
-
- for (;*processed_num < services_num; (*processed_num)++)
- {
- service = (zbx_service_t *)services->values[*processed_num];
-
- if (FAIL == zbx_vector_uint64_bsearch(dcheckids, service->dcheckid, ZBX_DEFAULT_UINT64_COMPARE_FUNC))
- {
- zabbix_log(LOG_LEVEL_DEBUG, "dcheckid:" ZBX_FS_UI64 " does not exist", service->dcheckid);
- continue;
- }
-
- zbx_discovery_update_service(&drule, service->dcheckid, &dhost, ip, service->dns, service->port,
- service->status, service->value, service->itemtime);
- }
-
- service = (zbx_service_t *)services->values[(*processed_num)++];
- zbx_discovery_update_host(&dhost, service->status, service->itemtime);
-
- ret = SUCCEED;
-fail:
- zbx_vector_ptr_clear_ext(&services_old, zbx_ptr_free);
- zbx_vector_ptr_destroy(&services_old);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: parse discovery data contents and process it *
- * *
- * Parameters: jp_data - [IN] JSON with discovery data *
- * error - [OUT] address of a pointer to the info *
- * string (should be freed by the caller) *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-static int process_discovery_data_contents(struct zbx_json_parse *jp_data, char **error)
-{
- DB_RESULT result;
- DB_ROW row;
- zbx_uint64_t dcheckid, druleid;
- struct zbx_json_parse jp_row;
- int status, ret = SUCCEED, i, j;
- unsigned short port;
- const char *p = NULL;
- char ip[ZBX_INTERFACE_IP_LEN_MAX], tmp[MAX_STRING_LEN],
- dns[ZBX_INTERFACE_DNS_LEN_MAX], *value = NULL;
- time_t itemtime;
- size_t value_alloc = ZBX_MAX_DISCOVERED_VALUE_SIZE;
- zbx_vector_ptr_t drules;
- zbx_drule_t *drule;
- zbx_drule_ip_t *drule_ip;
- zbx_service_t *service;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- value = (char *)zbx_malloc(value, value_alloc);
-
- zbx_vector_ptr_create(&drules);
-
- while (NULL != (p = zbx_json_next(jp_data, p)))
- {
- if (FAIL == zbx_json_brackets_open(p, &jp_row))
- goto json_parse_error;
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp), NULL))
- goto json_parse_error;
-
- itemtime = atoi(tmp);
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DRULE, tmp, sizeof(tmp), NULL))
- goto json_parse_error;
-
- ZBX_STR2UINT64(druleid, tmp);
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DCHECK, tmp, sizeof(tmp), NULL))
- goto json_parse_error;
-
- if ('\0' != *tmp)
- ZBX_STR2UINT64(dcheckid, tmp);
- else
- dcheckid = 0;
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_IP, ip, sizeof(ip), NULL))
- goto json_parse_error;
-
- if (SUCCEED != zbx_is_ip(ip))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid IP address", __func__, ip);
- continue;
- }
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_PORT, tmp, sizeof(tmp), NULL))
- {
- port = 0;
- }
- else if (FAIL == zbx_is_ushort(tmp, &port))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid port", __func__, tmp);
- continue;
- }
-
- if (SUCCEED != zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_VALUE, &value, &value_alloc, NULL))
- *value = '\0';
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DNS, dns, sizeof(dns), NULL))
- {
- *dns = '\0';
- }
- else if ('\0' != *dns && FAIL == zbx_validate_hostname(dns))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid hostname", __func__, dns);
- continue;
- }
-
- if (SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_STATUS, tmp, sizeof(tmp), NULL))
- status = atoi(tmp);
- else
- status = 0;
-
- if (FAIL == (i = zbx_vector_ptr_search(&drules, &druleid, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC)))
- {
- drule = (zbx_drule_t *)zbx_malloc(NULL, sizeof(zbx_drule_t));
- drule->druleid = druleid;
- zbx_vector_ptr_create(&drule->ips);
- zbx_vector_uint64_create(&drule->dcheckids);
- zbx_vector_ptr_append(&drules, drule);
- }
- else
- drule = drules.values[i];
-
- if (FAIL == (i = zbx_vector_ptr_search(&drule->ips, ip, ZBX_DEFAULT_STR_COMPARE_FUNC)))
- {
- drule_ip = (zbx_drule_ip_t *)zbx_malloc(NULL, sizeof(zbx_drule_ip_t));
- zbx_strlcpy(drule_ip->ip, ip, ZBX_INTERFACE_IP_LEN_MAX);
- zbx_vector_ptr_create(&drule_ip->services);
- zbx_vector_ptr_append(&drule->ips, drule_ip);
- }
- else
- drule_ip = drule->ips.values[i];
-
- service = (zbx_service_t *)zbx_malloc(NULL, sizeof(zbx_service_t));
- if (0 != (service->dcheckid = dcheckid))
- zbx_vector_uint64_append(&drule->dcheckids, service->dcheckid);
- service->port = port;
- service->status = status;
- zbx_strlcpy_utf8(service->value, value, ZBX_MAX_DISCOVERED_VALUE_SIZE);
- zbx_strlcpy(service->dns, dns, ZBX_INTERFACE_DNS_LEN_MAX);
- service->itemtime = itemtime;
- zbx_vector_ptr_append(&drule_ip->services, service);
-
- continue;
-json_parse_error:
- *error = zbx_strdup(*error, zbx_json_strerror());
- ret = FAIL;
- goto json_parse_return;
- }
-
- for (i = 0; i < drules.values_num; i++)
- {
- zbx_uint64_t unique_dcheckid;
- int ret2 = SUCCEED;
-
- drule = (zbx_drule_t *)drules.values[i];
-
- DBbegin();
- result = DBselect(
- "select dcheckid"
- " from dchecks"
- " where druleid=" ZBX_FS_UI64
- " and uniq=1",
- drule->druleid);
-
- if (NULL != (row = DBfetch(result)))
- ZBX_STR2UINT64(unique_dcheckid, row[0]);
- else
- unique_dcheckid = 0;
- DBfree_result(result);
- for (j = 0; j < drule->ips.values_num && SUCCEED == ret2; j++)
- {
- int processed_num = 0;
-
- drule_ip = (zbx_drule_ip_t *)drule->ips.values[j];
-
- while (processed_num != drule_ip->services.values_num)
- {
- if (FAIL == (ret2 = process_services(&drule_ip->services, drule_ip->ip, drule->druleid,
- &drule->dcheckids, unique_dcheckid, &processed_num, j)))
- {
- break;
- }
- }
- }
-
- zbx_process_events(NULL, NULL);
- zbx_clean_events();
- DBcommit();
- }
-json_parse_return:
- zbx_free(value);
-
- zbx_vector_ptr_clear_ext(&drules, (zbx_clean_func_t)zbx_drule_free);
- zbx_vector_ptr_destroy(&drules);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: parse autoregistration data contents and process it *
- * *
- * Parameters: jp_data - [IN] JSON with autoregistration data *
- * proxy_hostid - [IN] proxy identifier from database *
- * error - [OUT] address of a pointer to the info *
- * string (should be freed by the caller) *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-static int process_autoregistration_contents(struct zbx_json_parse *jp_data, zbx_uint64_t proxy_hostid,
- char **error)
-{
- struct zbx_json_parse jp_row;
- int ret = SUCCEED;
- const char *p = NULL;
- time_t itemtime;
- char host[ZBX_HOSTNAME_BUF_LEN], ip[ZBX_INTERFACE_IP_LEN_MAX],
- dns[ZBX_INTERFACE_DNS_LEN_MAX], tmp[MAX_STRING_LEN], *host_metadata = NULL;
- unsigned short port;
- size_t host_metadata_alloc = 1; /* for at least NUL-terminating string */
- zbx_vector_ptr_t autoreg_hosts;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- if (0 == DCget_auto_registration_action_count())
- {
- zabbix_log(LOG_LEVEL_DEBUG, "cannot process auto registration contents, all autoregistration actions"
- " are disabled");
- goto out;
- }
-
- zbx_vector_ptr_create(&autoreg_hosts);
- host_metadata = (char *)zbx_malloc(host_metadata, host_metadata_alloc);
-
- while (NULL != (p = zbx_json_next(jp_data, p)))
- {
- unsigned int connection_type;
- zbx_conn_flags_t flags = ZBX_CONN_DEFAULT;
-
- if (FAIL == (ret = zbx_json_brackets_open(p, &jp_row)))
- break;
-
- if (FAIL == (ret = zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp), NULL)))
- break;
-
- itemtime = atoi(tmp);
-
- if (FAIL == (ret = zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_HOST, host, sizeof(host), NULL)))
- break;
-
- if (FAIL == zbx_check_hostname(host, NULL))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid Zabbix host name", __func__, host);
- continue;
- }
-
- if (FAIL == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_HOST_METADATA,
- &host_metadata, &host_metadata_alloc, NULL))
- {
- *host_metadata = '\0';
- }
-
- if (FAIL != zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_FLAGS, tmp, sizeof(tmp), NULL))
- {
- int flags_int;
-
- flags_int = atoi(tmp);
-
- switch (flags_int)
- {
- case ZBX_CONN_DEFAULT:
- case ZBX_CONN_IP:
- case ZBX_CONN_DNS:
- flags = (zbx_conn_flags_t)flags_int;
- break;
- default:
- flags = ZBX_CONN_DEFAULT;
- zabbix_log(LOG_LEVEL_WARNING, "wrong flags value: %d for host \"%s\":",
- flags_int, host);
- }
- }
-
- if (FAIL == (ret = zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_IP, ip, sizeof(ip), NULL)))
- {
- if (ZBX_CONN_DNS == flags)
- {
- *ip = '\0';
- ret = SUCCEED;
- }
- else
- break;
- }
- else if (SUCCEED != zbx_is_ip(ip))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid IP address", __func__, ip);
- continue;
- }
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DNS, dns, sizeof(dns), NULL))
- {
- *dns = '\0';
- }
- else if ('\0' != *dns && FAIL == zbx_validate_hostname(dns))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid hostname", __func__, dns);
- continue;
- }
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_PORT, tmp, sizeof(tmp), NULL))
- {
- port = ZBX_DEFAULT_AGENT_PORT;
- }
- else if (FAIL == zbx_is_ushort(tmp, &port))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid port", __func__, tmp);
- continue;
- }
-
- if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_TLS_ACCEPTED, tmp, sizeof(tmp), NULL))
- {
- connection_type = ZBX_TCP_SEC_UNENCRYPTED;
- }
- else if (FAIL == zbx_is_uint32(tmp, &connection_type) || (ZBX_TCP_SEC_UNENCRYPTED != connection_type &&
- ZBX_TCP_SEC_TLS_PSK != connection_type && ZBX_TCP_SEC_TLS_CERT != connection_type))
- {
- zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid value for \""
- ZBX_PROTO_TAG_TLS_ACCEPTED "\"", __func__, tmp);
- continue;
- }
-
- DBregister_host_prepare(&autoreg_hosts, host, ip, dns, port, connection_type, host_metadata, flags,
- itemtime);
- }
-
- if (0 != autoreg_hosts.values_num)
- {
- DBbegin();
- DBregister_host_flush(&autoreg_hosts, proxy_hostid);
- DBcommit();
- DCconfig_delete_autoreg_host(&autoreg_hosts);
- }
-
- zbx_free(host_metadata);
- DBregister_host_clean(&autoreg_hosts);
- zbx_vector_ptr_destroy(&autoreg_hosts);
-
- if (SUCCEED != ret)
- *error = zbx_strdup(*error, zbx_json_strerror());
-out:
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: get the number of values waiting to be sent to the server *
- * *
- * Return value: the number of history values *
- * *
- ******************************************************************************/
-int proxy_get_history_count(void)
-{
- DB_RESULT result;
- DB_ROW row;
- zbx_uint64_t id;
- int count = 0;
-
- DBconnect(ZBX_DB_CONNECT_NORMAL);
-
- proxy_get_lastid("proxy_history", "history_lastid", &id);
-
- result = DBselect(
- "select count(*)"
- " from proxy_history"
- " where id>" ZBX_FS_UI64,
- id);
-
- if (NULL != (row = DBfetch(result)))
- count = atoi(row[0]);
-
- DBfree_result(result);
-
- DBclose();
-
- return count;
-}
-
-/******************************************************************************
- * *
* Purpose: extracts protocol version from json data *
* *
* Parameters: *
@@ -2899,567 +144,3 @@ int zbx_get_proxy_protocol_version_int(const char *version_str)
return ZBX_COMPONENT_VERSION(3, 2, 0);
}
-/******************************************************************************
- * *
- * Purpose: parse tasks contents and saves the received tasks *
- * *
- * Parameters: jp_tasks - [IN] JSON with tasks data *
- * *
- ******************************************************************************/
-static void process_tasks_contents(struct zbx_json_parse *jp_tasks)
-{
- zbx_vector_ptr_t tasks;
-
- zbx_vector_ptr_create(&tasks);
-
- zbx_tm_json_deserialize_tasks(jp_tasks, &tasks);
-
- DBbegin();
- zbx_tm_save_tasks(&tasks);
- DBcommit();
-
- zbx_vector_ptr_clear_ext(&tasks, (zbx_clean_func_t)zbx_tm_task_free);
- zbx_vector_ptr_destroy(&tasks);
-}
-
-/******************************************************************************
- * *
- * Purpose: appends text to the string on a new line *
- * *
- ******************************************************************************/
-static void zbx_strcatnl_alloc(char **info, size_t *info_alloc, size_t *info_offset, const char *text)
-{
- if (0 != *info_offset)
- zbx_chrcpy_alloc(info, info_alloc, info_offset, '\n');
-
- zbx_strcpy_alloc(info, info_alloc, info_offset, text);
-}
-
-/******************************************************************************
- * *
- * Purpose: detect lost connection with proxy and calculate suppression *
- * window if possible *
- * *
- * Parameters: ts - [IN] timestamp when the proxy connection was *
- * established *
- * proxy_staus - [IN] - active or passive proxy *
- * diff - [IN/OUT] the properties to update *
- * *
- ******************************************************************************/
-static void check_proxy_nodata(zbx_timespec_t *ts, unsigned char proxy_status, zbx_proxy_diff_t *diff)
-{
- int delay;
-
- if (0 != (diff->nodata_win.flags & ZBX_PROXY_SUPPRESS_ACTIVE))
- {
- diff->nodata_win.values_num = 0; /* reset counter of new suppress values received from proxy */
- return; /* only for current packet */
- }
-
- delay = ts->sec - diff->lastaccess;
-
- if ((HOST_STATUS_PROXY_PASSIVE == proxy_status &&
- (2 * CONFIG_PROXYDATA_FREQUENCY) < delay && NET_DELAY_MAX < delay) ||
- (HOST_STATUS_PROXY_ACTIVE == proxy_status && NET_DELAY_MAX < delay))
- {
- diff->nodata_win.values_num = 0;
- diff->nodata_win.period_end = ts->sec;
- diff->flags |= ZBX_FLAGS_PROXY_DIFF_UPDATE_SUPPRESS_WIN;
- diff->nodata_win.flags |= ZBX_PROXY_SUPPRESS_ENABLE;
- }
-}
-
-/******************************************************************************
- * *
- * Purpose: detect lack of data during lost connectivity *
- * *
- * Parameters: ts - [IN] timestamp when the proxy connection was *
- * established *
- * proxy_staus - [IN] - active or passive proxy *
- * diff - [IN/OUT] the properties to update *
- * *
- ******************************************************************************/
-static void check_proxy_nodata_empty(zbx_timespec_t *ts, unsigned char proxy_status, zbx_proxy_diff_t *diff)
-{
- int delay_empty;
-
- if (0 != (diff->nodata_win.flags & ZBX_PROXY_SUPPRESS_EMPTY) && 0 != diff->nodata_win.values_num)
- diff->nodata_win.flags &= (~ZBX_PROXY_SUPPRESS_EMPTY);
-
- if (0 == (diff->nodata_win.flags & ZBX_PROXY_SUPPRESS_EMPTY) || 0 != diff->nodata_win.values_num)
- return;
-
- delay_empty = ts->sec - diff->nodata_win.period_end;
-
- if (HOST_STATUS_PROXY_PASSIVE == proxy_status ||
- (HOST_STATUS_PROXY_ACTIVE == proxy_status && NET_DELAY_MAX < delay_empty))
- {
- diff->nodata_win.period_end = 0;
- diff->nodata_win.flags = ZBX_PROXY_SUPPRESS_DISABLE;
- }
-}
-
-/******************************************************************************
- * *
- * Purpose: process 'proxy data' request *
- * *
- * Parameters: proxy - [IN] the source proxy *
- * jp - [IN] JSON with proxy data *
- * proxy_hostid - [IN] proxy identifier from database *
- * ts - [IN] timestamp when the proxy connection was *
- * established *
- * proxy_status - [IN] active or passive proxy mode *
- * more - [OUT] available data flag *
- * error - [OUT] address of a pointer to the info string *
- * (should be freed by the caller) *
- * *
- * Return value: SUCCEED - processed successfully *
- * FAIL - an error occurred *
- * *
- ******************************************************************************/
-int process_proxy_data(const DC_PROXY *proxy, struct zbx_json_parse *jp, zbx_timespec_t *ts,
- unsigned char proxy_status, int *more, char **error)
-{
- struct zbx_json_parse jp_data;
- int ret = SUCCEED, flags_old;
- char *error_step = NULL, value[MAX_STRING_LEN];
- size_t error_alloc = 0, error_offset = 0;
- zbx_proxy_diff_t proxy_diff;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
-
- proxy_diff.flags = ZBX_FLAGS_PROXY_DIFF_UNSET;
- proxy_diff.hostid = proxy->hostid;
-
- if (SUCCEED != (ret = DCget_proxy_nodata_win(proxy_diff.hostid, &proxy_diff.nodata_win,
- &proxy_diff.lastaccess)))
- {
- zabbix_log(LOG_LEVEL_WARNING, "cannot get proxy communication delay");
- ret = FAIL;
- goto out;
- }
-
- if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_MORE, value, sizeof(value), NULL))
- proxy_diff.more_data = atoi(value);
- else
- proxy_diff.more_data = ZBX_PROXY_DATA_DONE;
-
- if (NULL != more)
- *more = proxy_diff.more_data;
-
- if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_PROXY_DELAY, value, sizeof(value), NULL))
- proxy_diff.proxy_delay = atoi(value);
- else
- proxy_diff.proxy_delay = 0;
-
- proxy_diff.flags |= ZBX_FLAGS_PROXY_DIFF_UPDATE_PROXYDELAY;
- flags_old = proxy_diff.nodata_win.flags;
- check_proxy_nodata(ts, proxy_status, &proxy_diff); /* first packet can be empty for active proxy */
-
- zabbix_log(LOG_LEVEL_DEBUG, "%s() flag_win:%d/%d flag:%d proxy_status:%d period_end:%d delay:%d"
- " timestamp:%d lastaccess:%d proxy_delay:%d more:%d", __func__, proxy_diff.nodata_win.flags,
- flags_old, (int)proxy_diff.flags, proxy_status, proxy_diff.nodata_win.period_end,
- ts->sec - proxy_diff.lastaccess, ts->sec, proxy_diff.lastaccess, proxy_diff.proxy_delay,
- proxy_diff.more_data);
-
- if (ZBX_FLAGS_PROXY_DIFF_UNSET != proxy_diff.flags)
- zbx_dc_update_proxy(&proxy_diff);
-
- if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_INTERFACE_AVAILABILITY, &jp_data))
- {
- if (SUCCEED != (ret = process_interfaces_availability_contents(&jp_data, &error_step)))
- zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
- }
-
- flags_old = proxy_diff.nodata_win.flags;
-
- if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_HISTORY_DATA, &jp_data))
- {
- zbx_session_t *session = NULL;
-
- if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_SESSION, value, sizeof(value), NULL))
- {
- size_t token_len;
-
- if (ZBX_SESSION_TOKEN_SIZE != (token_len = strlen(value)))
- {
- *error = zbx_dsprintf(*error, "invalid session token length %d", (int)token_len);
- ret = FAIL;
- goto out;
- }
-
- session = zbx_dc_get_or_create_session(proxy->hostid, value, ZBX_SESSION_TYPE_DATA);
- }
-
- if (SUCCEED != (ret = process_history_data_by_itemids(NULL, proxy_item_validator,
- (void *)&proxy->hostid, &jp_data, session, &proxy_diff.nodata_win, &error_step,
- ZBX_ITEM_GET_PROCESS)))
- {
- zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
- }
- }
-
- if (0 != (proxy_diff.nodata_win.flags & ZBX_PROXY_SUPPRESS_ACTIVE))
- {
- check_proxy_nodata_empty(ts, proxy_status, &proxy_diff);
-
- if (0 < proxy_diff.nodata_win.values_num || flags_old != proxy_diff.nodata_win.flags)
- proxy_diff.flags |= ZBX_FLAGS_PROXY_DIFF_UPDATE_SUPPRESS_WIN;
-
- zabbix_log(LOG_LEVEL_DEBUG, "Result of %s() flag_win:%d/%d flag:%d values_num:%d",
- __func__, proxy_diff.nodata_win.flags, flags_old, (int)proxy_diff.flags,
- proxy_diff.nodata_win.values_num);
- }
-
- if (ZBX_FLAGS_PROXY_DIFF_UNSET != proxy_diff.flags)
- zbx_dc_update_proxy(&proxy_diff);
-
- if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_DISCOVERY_DATA, &jp_data))
- {
- if (SUCCEED != (ret = process_discovery_data_contents(&jp_data, &error_step)))
- zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
- }
-
- if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_AUTOREGISTRATION, &jp_data))
- {
- if (SUCCEED != (ret = process_autoregistration_contents(&jp_data, proxy->hostid, &error_step)))
- zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
- }
-
- if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_TASKS, &jp_data))
- process_tasks_contents(&jp_data);
-
- if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_PROXY_ACTIVE_AVAIL_DATA, &jp_data))
- {
- const char *ptr;
- zbx_vector_proxy_hostdata_ptr_t host_avails;
- struct zbx_json_parse jp_host;
- char buffer[ZBX_KIBIBYTE];
-
- zbx_vector_proxy_hostdata_ptr_create(&host_avails);
-
- for (ptr = NULL; NULL != (ptr = zbx_json_next(&jp_data, ptr));)
- {
- zbx_proxy_hostdata_t *host;
-
- if (SUCCEED != zbx_json_brackets_open(ptr, &jp_host))
- continue;
-
- if (SUCCEED == zbx_json_value_by_name(&jp_host, ZBX_PROTO_TAG_HOSTID, buffer, sizeof(buffer), NULL))
- {
- host = (zbx_proxy_hostdata_t *)zbx_malloc(NULL, sizeof(zbx_proxy_hostdata_t));
- host->hostid = atoi(buffer);
- }
- else
- continue;
-
- if (FAIL == zbx_json_value_by_name(&jp_host, ZBX_PROTO_TAG_ACTIVE_STATUS, buffer, sizeof(buffer), NULL))
- {
- zbx_free(host);
- continue;
- }
-
- host->status = atoi(buffer);
-
- zbx_vector_proxy_hostdata_ptr_append(&host_avails, host);
- }
-
- if (0 != host_avails.values_num)
- {
- unsigned char *data = NULL;
- zbx_uint32_t data_len;
- DC_HOST *hosts;
- int i, *errcodes;
- zbx_vector_uint64_t hostids;
- zbx_vector_proxy_hostdata_ptr_t proxy_host_avails;
-
- zbx_vector_uint64_create(&hostids);
-
- for (i = 0; i < host_avails.values_num; i++)
- zbx_vector_uint64_append(&hostids, host_avails.values[i]->hostid);
-
- hosts = (DC_HOST *)zbx_malloc(NULL, sizeof(DC_HOST) * host_avails.values_num);
- errcodes = (int *)zbx_malloc(NULL, sizeof(int) * host_avails.values_num);
- DCconfig_get_hosts_by_hostids(hosts, hostids.values, errcodes, hostids.values_num);
-
- zbx_vector_uint64_destroy(&hostids);
-
- zbx_vector_proxy_hostdata_ptr_create(&proxy_host_avails);
-
- for (i = 0; i < host_avails.values_num; i++)
- {
- if (SUCCEED == errcodes[i] && hosts[i].proxy_hostid == proxy->hostid)
- zbx_vector_proxy_hostdata_ptr_append(&proxy_host_avails, host_avails.values[i]);
- }
-
- zbx_free(errcodes);
- zbx_free(hosts);
-
- data_len = zbx_availability_serialize_proxy_hostdata(&data, &proxy_host_avails, proxy->hostid);
- zbx_availability_send(ZBX_IPC_AVAILMAN_PROCESS_PROXY_HOSTDATA, data, data_len, NULL);
-
- zbx_vector_proxy_hostdata_ptr_destroy(&proxy_host_avails);
- zbx_vector_proxy_hostdata_ptr_clear_ext(&host_avails, (zbx_proxy_hostdata_ptr_free_func_t)zbx_ptr_free);
- zbx_free(data);
- }
-
- zbx_vector_proxy_hostdata_ptr_destroy(&host_avails);
- }
- else
- {
- unsigned char *data = NULL;
- zbx_uint32_t data_len;
-
- data_len = zbx_availability_serialize_active_proxy_hb_update(&data, proxy->hostid);
- zbx_availability_send(ZBX_IPC_AVAILMAN_ACTIVE_PROXY_HB_UPDATE, data, data_len, NULL);
- zbx_free(data);
- }
-
-out:
- zbx_free(error_step);
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
-
- return ret;
-}
-
-/******************************************************************************
- * *
- * Purpose: flushes lastaccess changes for proxies every *
- * ZBX_PROXY_LASTACCESS_UPDATE_FREQUENCY seconds *
- * *
- ******************************************************************************/
-static void zbx_db_flush_proxy_lastaccess(void)
-{
- zbx_vector_uint64_pair_t lastaccess;
-
- zbx_vector_uint64_pair_create(&lastaccess);
-
- zbx_dc_get_proxy_lastaccess(&lastaccess);
-
- if (0 != lastaccess.values_num)
- {
- char *sql;
- size_t sql_alloc = 256, sql_offset = 0;
- int i;
-
- sql = (char *)zbx_malloc(NULL, sql_alloc);
-
- DBbegin();
- zbx_DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset);
-
- for (i = 0; i < lastaccess.values_num; i++)
- {
- zbx_uint64_pair_t *pair = &lastaccess.values[i];
-
- zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update host_rtdata"
- " set lastaccess=%d"
- " where hostid=" ZBX_FS_UI64 ";\n",
- (int)pair->second, pair->first);
-
- DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset);
- }
-
- zbx_DBend_multiple_update(&sql, &sql_alloc, &sql_offset);
-
- if (16 < sql_offset) /* in ORACLE always present begin..end; */
- DBexecute("%s", sql);
-
- DBcommit();
-
- zbx_free(sql);
- }
-
- zbx_vector_uint64_pair_destroy(&lastaccess);
-}
-
-/******************************************************************************
- * *
- * Purpose: updates proxy version and compatibility with server in database *
- * *
- * Parameters: proxy - [IN] the proxy to update version for *
- * diff - [IN] indicates changes to the proxy *
- * *
- ******************************************************************************/
-static void db_update_proxy_version(DC_PROXY *proxy, zbx_proxy_diff_t *diff)
-{
- if (0 != (diff->flags & ZBX_FLAGS_PROXY_DIFF_UPDATE_VERSION))
- {
- if (0 != proxy->version_int)
- {
- zabbix_log(LOG_LEVEL_DEBUG, "proxy \"%s\" protocol version updated from %u.%u to %u.%u",
- proxy->host,
- ZBX_COMPONENT_VERSION_MAJOR(proxy->version_int),
- ZBX_COMPONENT_VERSION_MINOR(proxy->version_int),
- ZBX_COMPONENT_VERSION_MAJOR(diff->version_int),
- ZBX_COMPONENT_VERSION_MINOR(diff->version_int));
- }
-
- if (ZBX_DB_OK > DBexecute(
- "update host_rtdata"
- " set version=%u,compatibility=%u"
- " where hostid=" ZBX_FS_UI64,
- ZBX_COMPONENT_VERSION_TO_DEC_FORMAT(diff->version_int), diff->compatibility,
- diff->hostid))
- {
- zabbix_log(LOG_LEVEL_WARNING, "Failed to update proxy version and compatibility with server for"
- " proxy '%s'.", proxy->host);
- }
- }
-}
-
-/******************************************************************************
- * *
- * Purpose: gets proxy version compatibility with server version *
- * *
- * Parameters: proxy_version - [IN] proxy_version *
- * *
- * Return value: proxy version compatibility with server version *
- * *
- ******************************************************************************/
-static zbx_proxy_compatibility_t zbx_get_proxy_compatibility(int proxy_version)
-{
-#define SERVER_VERSION ZBX_COMPONENT_VERSION(ZABBIX_VERSION_MAJOR, ZABBIX_VERSION_MINOR, 0)
-
- if (0 == proxy_version)
- return ZBX_PROXY_VERSION_UNDEFINED;
-
- proxy_version = ZBX_COMPONENT_VERSION_WITHOUT_PATCH(proxy_version);
-
- if (SERVER_VERSION == proxy_version)
- return ZBX_PROXY_VERSION_CURRENT;
-
- if (SERVER_VERSION < proxy_version)
- return ZBX_PROXY_VERSION_UNSUPPORTED;
-#if (ZABBIX_VERSION_MINOR == 0)
- if (ZABBIX_VERSION_MAJOR == 1 + ZBX_COMPONENT_VERSION_MAJOR(proxy_version))
- return ZBX_PROXY_VERSION_STATUS_OUTDATED;
-#elif (ZABBIX_VERSION_MINOR > 0)
- if (ZABBIX_VERSION_MAJOR == ZBX_COMPONENT_VERSION_MAJOR(proxy_version))
- return ZBX_PROXY_VERSION_OUTDATED;
-#endif
- return ZBX_PROXY_VERSION_UNSUPPORTED;
-
-#undef SERVER_VERSION
-}
-
-/******************************************************************************
- * *
- * Purpose: updates proxy runtime properties in cache and database. *
- * *
- * Parameters: proxy - [IN/OUT] the proxy *
- * version_str - [IN] the proxy version as string *
- * version_int - [IN] the proxy version in numeric representation *
- * lastaccess - [IN] the last proxy access time *
- * compress - [IN] 1 if proxy is using data compression, *
- * 0 otherwise *
- * flags_add - [IN] additional flags for update proxy *
- * *
- * Comments: The proxy parameter properties are also updated. *
- * *
- ******************************************************************************/
-void zbx_update_proxy_data(DC_PROXY *proxy, char *version_str, int version_int, int lastaccess, int compress,
- zbx_uint64_t flags_add)
-{
- zbx_proxy_diff_t diff;
- zbx_proxy_compatibility_t compatibility;
-
- compatibility = zbx_get_proxy_compatibility(version_int);
-
- diff.hostid = proxy->hostid;
- diff.flags = ZBX_FLAGS_PROXY_DIFF_UPDATE | flags_add;
- diff.version_str = version_str;
- diff.version_int = version_int;
- diff.compatibility = compatibility;
- diff.lastaccess = lastaccess;
- diff.compress = compress;
-
- zbx_dc_update_proxy(&diff);
-
- db_update_proxy_version(proxy, &diff);
-
- zbx_strlcpy(proxy->version_str, version_str, sizeof(proxy->version_str));
- proxy->version_int = version_int;
- proxy->compatibility = compatibility;
- proxy->auto_compress = compress;
- proxy->lastaccess = lastaccess;
-
- if (0 != (diff.flags & ZBX_FLAGS_PROXY_DIFF_UPDATE_COMPRESS))
- DBexecute("update hosts set auto_compress=%d where hostid=" ZBX_FS_UI64, diff.compress, diff.hostid);
-
- zbx_db_flush_proxy_lastaccess();
-}
-/******************************************************************************
- * *
- * Purpose: flushes last_version_error_time changes runtime *
- * variable for proxies structures *
- * *
- ******************************************************************************/
-static void zbx_update_proxy_lasterror(DC_PROXY *proxy)
-{
- zbx_proxy_diff_t diff;
-
- diff.hostid = proxy->hostid;
- diff.flags = ZBX_FLAGS_PROXY_DIFF_UPDATE_LASTERROR;
- diff.lastaccess = time(NULL);
- diff.last_version_error_time = proxy->last_version_error_time;
-
- zbx_dc_update_proxy(&diff);
-}
-/******************************************************************************
- * *
- * Purpose: check server and proxy versions and compatibility rules *
- * *
- * Parameters: *
- * proxy - [IN] the source proxy *
- * version - [IN] the version of proxy *
- * *
- * Return value: *
- * SUCCEED - no compatibility issue *
- * FAIL - compatibility check fault *
- * *
- ******************************************************************************/
-int zbx_check_protocol_version(DC_PROXY *proxy, int version)
-{
- zbx_proxy_compatibility_t compatibility;
-
- compatibility = zbx_get_proxy_compatibility(version);
-
- /* warn if another proxy version is used and proceed with compatibility rules*/
- if (ZBX_PROXY_VERSION_CURRENT != compatibility)
- {
- int now = zbx_time(), print_log = 0;
-
- if (proxy->last_version_error_time <= now)
- {
- print_log = 1;
- proxy->last_version_error_time = now + 5 * SEC_PER_MIN;
- zbx_update_proxy_lasterror(proxy);
- }
-
- if (ZBX_PROXY_VERSION_UNSUPPORTED == compatibility)
- {
- if (1 == print_log)
- {
- zabbix_log(LOG_LEVEL_WARNING, "Proxy \"%s\" version %u.%u.%u is not supported by server"
- " version %d.%d.%d.", proxy->host,
- ZBX_COMPONENT_VERSION_MAJOR(version),
- ZBX_COMPONENT_VERSION_MINOR(version),
- ZBX_COMPONENT_VERSION_PATCH(version), ZABBIX_VERSION_MAJOR,
- ZABBIX_VERSION_MINOR, ZABBIX_VERSION_PATCH);
- }
- return FAIL;
- }
- else if (ZBX_PROXY_VERSION_OUTDATED == compatibility && 1 == print_log)
- {
- zabbix_log(LOG_LEVEL_WARNING, "Proxy \"%s\" version %u.%u.%u is outdated, only data collection"
- " and remote execution is available with server version %d.%d.%d.", proxy->host,
- ZBX_COMPONENT_VERSION_MAJOR(version), ZBX_COMPONENT_VERSION_MINOR(version),
- ZBX_COMPONENT_VERSION_PATCH(version), ZABBIX_VERSION_MAJOR,
- ZABBIX_VERSION_MINOR, ZABBIX_VERSION_PATCH);
- }
- else if (ZBX_PROXY_VERSION_UNDEFINED == compatibility)
- return FAIL;
- }
-
- return SUCCEED;
-}
diff --git a/src/libs/zbxdbhigh/trigger.c b/src/libs/zbxdbhigh/trigger.c
index 0d4e42b58bf..dcb2eeb7bd7 100644
--- a/src/libs/zbxdbhigh/trigger.c
+++ b/src/libs/zbxdbhigh/trigger.c
@@ -25,121 +25,6 @@
#include "zbxserver.h"
#include "zbxnum.h"
-#define ZBX_FLAGS_TRIGGER_CREATE_NOTHING 0x00
-#define ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT 0x01
-#define ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT 0x02
-#define ZBX_FLAGS_TRIGGER_CREATE_EVENT \
- (ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT | ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT)
-
-/******************************************************************************
- * *
- * Purpose: 1) calculate changeset of trigger fields to be updated *
- * 2) generate events *
- * *
- * Parameters: trigger - [IN] the trigger to process *
- * diffs - [OUT] the vector with trigger changes *
- * *
- * Return value: SUCCEED - trigger processed successfully *
- * FAIL - no changes *
- * *
- * Comments: Trigger dependency checks will be done during event processing. *
- * *
- * Event generation depending on trigger value/state changes: *
- * *
- * From \ To | OK | OK(?) | PROBLEM | PROBLEM(?) | NONE *
- *----------------------------------------------------------------------------*
- * OK | . | I | E | I | . *
- * | | | | | *
- * OK(?) | I | . | E,I | - | I *
- * | | | | | *
- * PROBLEM | E | I | E(m) | I | . *
- * | | | | | *
- * PROBLEM(?) | E,I | - | E(m),I | . | I *
- * *
- * Legend: *
- * 'E' - trigger event *
- * 'I' - internal event *
- * '.' - nothing *
- * '-' - should never happen *
- * *
- ******************************************************************************/
-static int zbx_process_trigger(struct _DC_TRIGGER *trigger, zbx_vector_ptr_t *diffs)
-{
- const char *new_error;
- int new_state, new_value, ret = FAIL;
- zbx_uint64_t flags = ZBX_FLAGS_TRIGGER_DIFF_UNSET, event_flags = ZBX_FLAGS_TRIGGER_CREATE_NOTHING;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() triggerid:" ZBX_FS_UI64 " value:%d(%d) new_value:%d",
- __func__, trigger->triggerid, trigger->value, trigger->state, trigger->new_value);
-
- if (TRIGGER_VALUE_UNKNOWN == trigger->new_value)
- {
- new_state = TRIGGER_STATE_UNKNOWN;
- new_value = trigger->value;
- }
- else
- {
- new_state = TRIGGER_STATE_NORMAL;
- new_value = trigger->new_value;
- }
- new_error = (NULL == trigger->new_error ? "" : trigger->new_error);
-
- if (trigger->state != new_state)
- {
- flags |= ZBX_FLAGS_TRIGGER_DIFF_UPDATE_STATE;
- event_flags |= ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT;
- }
-
- if (0 != strcmp(trigger->error, new_error))
- flags |= ZBX_FLAGS_TRIGGER_DIFF_UPDATE_ERROR;
-
- if (TRIGGER_STATE_NORMAL == new_state)
- {
- if (TRIGGER_VALUE_PROBLEM == new_value)
- {
- if (TRIGGER_VALUE_OK == trigger->value || TRIGGER_TYPE_MULTIPLE_TRUE == trigger->type)
- event_flags |= ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT;
- }
- else if (TRIGGER_VALUE_OK == new_value)
- {
- if (TRIGGER_VALUE_PROBLEM == trigger->value || 0 == trigger->lastchange)
- event_flags |= ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT;
- }
- }
-
- /* check if there is something to be updated */
- if (0 == (flags & ZBX_FLAGS_TRIGGER_DIFF_UPDATE) && 0 == (event_flags & ZBX_FLAGS_TRIGGER_CREATE_EVENT))
- goto out;
-
- if (0 != (event_flags & ZBX_FLAGS_TRIGGER_CREATE_TRIGGER_EVENT))
- {
- zbx_add_event(EVENT_SOURCE_TRIGGERS, EVENT_OBJECT_TRIGGER, trigger->triggerid,
- &trigger->timespec, new_value, trigger->description,
- trigger->expression, trigger->recovery_expression,
- trigger->priority, trigger->type, &trigger->tags,
- trigger->correlation_mode, trigger->correlation_tag, trigger->value, trigger->opdata,
- trigger->event_name, NULL);
- }
-
- if (0 != (event_flags & ZBX_FLAGS_TRIGGER_CREATE_INTERNAL_EVENT))
- {
- zbx_add_event(EVENT_SOURCE_INTERNAL, EVENT_OBJECT_TRIGGER, trigger->triggerid,
- &trigger->timespec, new_state, NULL, trigger->expression,
- trigger->recovery_expression, 0, 0, &trigger->tags, 0, NULL, 0, NULL, NULL,
- new_error);
- }
-
- zbx_append_trigger_diff(diffs, trigger->triggerid, trigger->priority, flags, trigger->value, new_state,
- trigger->timespec.sec, new_error);
-
- ret = SUCCEED;
-out:
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s flags:" ZBX_FS_UI64, __func__, zbx_result_string(ret),
- flags);
-
- return ret;
-}
-
/******************************************************************************
* *
* Purpose: save the trigger changes to database *
@@ -224,53 +109,6 @@ void zbx_trigger_diff_free(zbx_trigger_diff_t *diff)
/******************************************************************************
* *
- * Comments: helper function for zbx_process_triggers() *
- * *
- ******************************************************************************/
-static int zbx_trigger_topoindex_compare(const void *d1, const void *d2)
-{
- const DC_TRIGGER *t1 = *(const DC_TRIGGER * const *)d1;
- const DC_TRIGGER *t2 = *(const DC_TRIGGER * const *)d2;
-
- ZBX_RETURN_IF_NOT_EQUAL(t1->topoindex, t2->topoindex);
-
- return 0;
-}
-
-/******************************************************************************
- * *
- * Purpose: process triggers - calculates property changeset and generates *
- * events *
- * *
- * Parameters: triggers - [IN] the triggers to process *
- * trigger_diff - [OUT] the trigger changeset *
- * *
- * Comments: The trigger_diff changeset must be cleaned by the caller: *
- * zbx_vector_ptr_clear_ext(trigger_diff, *
- * (zbx_clean_func_t)zbx_trigger_diff_free); *
- * *
- ******************************************************************************/
-void zbx_process_triggers(zbx_vector_ptr_t *triggers, zbx_vector_ptr_t *trigger_diff)
-{
- int i;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() values_num:%d", __func__, triggers->values_num);
-
- if (0 == triggers->values_num)
- goto out;
-
- zbx_vector_ptr_sort(triggers, zbx_trigger_topoindex_compare);
-
- for (i = 0; i < triggers->values_num; i++)
- zbx_process_trigger((struct _DC_TRIGGER *)triggers->values[i], trigger_diff);
-
- zbx_vector_ptr_sort(trigger_diff, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
-out:
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
-}
-
-/******************************************************************************
- * *
* Purpose: Adds a new trigger diff to trigger changeset vector *
* *
******************************************************************************/
diff --git a/src/libs/zbxdbwrap/Makefile.am b/src/libs/zbxdbwrap/Makefile.am
new file mode 100644
index 00000000000..c670b84edb0
--- /dev/null
+++ b/src/libs/zbxdbwrap/Makefile.am
@@ -0,0 +1,20 @@
+## Process this file with automake to produce Makefile.in
+
+noinst_LIBRARIES = libzbxdbwrap.a
+
+libzbxdbwrap_a_SOURCES = \
+ proxy.c \
+ event.c \
+ template_item.c \
+ template.h \
+ trigger_dep_linking.c \
+ trigger_dep_linking.h \
+ trigger_linking.c \
+ trigger_linking.h \
+ graph_linking.c \
+ graph_linking.h \
+ host.c
+
+libzbxdbwrap_a_CFLAGS = \
+ -I$(top_srcdir)/src/zabbix_server/ \
+ $(TLS_CFLAGS)
diff --git a/src/libs/zbxdbhigh/event.c b/src/libs/zbxdbwrap/event.c
index 1d1a80f418e..718cf1d8800 100644
--- a/src/libs/zbxdbhigh/event.c
+++ b/src/libs/zbxdbwrap/event.c
@@ -17,7 +17,7 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "zbxdbhigh.h"
+#include "zbxdbwrap.h"
#include "zbxnum.h"
#include "zbxexpr.h"
diff --git a/src/libs/zbxdbhigh/graph_linking.c b/src/libs/zbxdbwrap/graph_linking.c
index 133afb11433..133afb11433 100644
--- a/src/libs/zbxdbhigh/graph_linking.c
+++ b/src/libs/zbxdbwrap/graph_linking.c
diff --git a/src/libs/zbxdbhigh/graph_linking.h b/src/libs/zbxdbwrap/graph_linking.h
index ed0d6ddadbc..ed0d6ddadbc 100644
--- a/src/libs/zbxdbhigh/graph_linking.h
+++ b/src/libs/zbxdbwrap/graph_linking.h
diff --git a/src/libs/zbxdbhigh/host.c b/src/libs/zbxdbwrap/host.c
index f8b7f6b4596..92fe7972450 100644
--- a/src/libs/zbxdbhigh/host.c
+++ b/src/libs/zbxdbwrap/host.c
@@ -17,7 +17,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "zbxdbhigh.h"
+#include "template.h"
+#include "zbxdbwrap.h"
#include "log.h"
#include "dbcache.h"
@@ -68,7 +69,7 @@ static int zbx_ids_names_compare_func(const void *d1, const void *d2)
* FAIL - otherwise *
* *
******************************************************************************/
-int DBselect_ids_names(const char *sql, zbx_vector_uint64_t *ids, zbx_vector_str_t *names)
+static int DBselect_ids_names(const char *sql, zbx_vector_uint64_t *ids, zbx_vector_str_t *names)
{
int i, ret = FAIL;
DB_RESULT result;
@@ -842,6 +843,9 @@ static int validate_host(zbx_uint64_t hostid, zbx_vector_uint64_t *templateids,
type = (unsigned char)atoi(trow[0]);
type = get_interface_type_by_item_type(type);
+ if (INTERFACE_TYPE_UNKNOWN == type)
+ continue;
+
if (INTERFACE_TYPE_ANY == type)
{
for (i = 0; INTERFACE_TYPE_COUNT > i; i++)
@@ -6109,7 +6113,7 @@ zbx_uint64_t DBadd_interface(zbx_uint64_t hostid, unsigned char type, unsigned c
ip_esc = DBdyn_escape_field("interface", "ip", ip);
dns_esc = DBdyn_escape_field("interface", "dns", dns);
- interfaceid = DBget_maxid("interface");
+ interfaceid = DBget_maxid_num("interface", 1);
DBexecute("insert into interface"
" (interfaceid,hostid,main,type,useip,ip,dns,port)"
diff --git a/src/libs/zbxdbwrap/proxy.c b/src/libs/zbxdbwrap/proxy.c
new file mode 100644
index 00000000000..6a731bad5d4
--- /dev/null
+++ b/src/libs/zbxdbwrap/proxy.c
@@ -0,0 +1,3334 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2022 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 "zbxdbwrap.h"
+
+#include "zbxdbhigh.h"
+#include "log.h"
+#include "zbxsysinfo.h"
+#include "zbxserver.h"
+#include "zbxtasks.h"
+#include "zbxdiscovery.h"
+#include "zbxalgo.h"
+#include "preproc.h"
+#include "zbxcrypto.h"
+#include "zbxlld.h"
+#include "events.h"
+#include "zbxavailability.h"
+#include "zbxcommshigh.h"
+#include "zbxnum.h"
+#include "zbxtime.h"
+#include "zbxip.h"
+#include "version.h"
+#include "zbxversion.h"
+
+extern char *CONFIG_SERVER;
+
+/* the space reserved in json buffer to hold at least one record plus service data */
+#define ZBX_DATA_JSON_RESERVED (ZBX_HISTORY_TEXT_VALUE_LEN * 4 + ZBX_KIBIBYTE * 4)
+
+#define ZBX_DATA_JSON_RECORD_LIMIT (ZBX_MAX_RECV_DATA_SIZE - ZBX_DATA_JSON_RESERVED)
+#define ZBX_DATA_JSON_BATCH_LIMIT ((ZBX_MAX_RECV_DATA_SIZE - ZBX_DATA_JSON_RESERVED) / 2)
+
+/* the maximum number of values processed in one batch */
+#define ZBX_HISTORY_VALUES_MAX 256
+
+typedef struct
+{
+ zbx_uint64_t druleid;
+ zbx_vector_uint64_t dcheckids;
+ zbx_vector_ptr_t ips;
+}
+zbx_drule_t;
+
+typedef struct
+{
+ char ip[ZBX_INTERFACE_IP_LEN_MAX];
+ zbx_vector_ptr_t services;
+}
+zbx_drule_ip_t;
+
+typedef struct
+{
+ const char *field;
+ const char *tag;
+ zbx_json_type_t jt;
+ const char *default_value;
+}
+zbx_history_field_t;
+
+typedef struct
+{
+ const char *table, *lastidfield;
+ zbx_history_field_t fields[ZBX_MAX_FIELDS];
+}
+zbx_history_table_t;
+
+typedef int (*zbx_client_item_validator_t)(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error);
+
+typedef struct
+{
+ zbx_uint64_t hostid;
+ int value;
+}
+zbx_host_rights_t;
+
+static zbx_history_table_t dht = {
+ "proxy_dhistory", "dhistory_lastid",
+ {
+ {"clock", ZBX_PROTO_TAG_CLOCK, ZBX_JSON_TYPE_INT, NULL},
+ {"druleid", ZBX_PROTO_TAG_DRULE, ZBX_JSON_TYPE_INT, NULL},
+ {"dcheckid", ZBX_PROTO_TAG_DCHECK, ZBX_JSON_TYPE_INT, NULL},
+ {"ip", ZBX_PROTO_TAG_IP, ZBX_JSON_TYPE_STRING, NULL},
+ {"dns", ZBX_PROTO_TAG_DNS, ZBX_JSON_TYPE_STRING, NULL},
+ {"port", ZBX_PROTO_TAG_PORT, ZBX_JSON_TYPE_INT, "0"},
+ {"value", ZBX_PROTO_TAG_VALUE, ZBX_JSON_TYPE_STRING, ""},
+ {"status", ZBX_PROTO_TAG_STATUS, ZBX_JSON_TYPE_INT, "0"},
+ {NULL}
+ }
+};
+
+static zbx_history_table_t areg = {
+ "proxy_autoreg_host", "autoreg_host_lastid",
+ {
+ {"clock", ZBX_PROTO_TAG_CLOCK, ZBX_JSON_TYPE_INT, NULL},
+ {"host", ZBX_PROTO_TAG_HOST, ZBX_JSON_TYPE_STRING, NULL},
+ {"listen_ip", ZBX_PROTO_TAG_IP, ZBX_JSON_TYPE_STRING, ""},
+ {"listen_dns", ZBX_PROTO_TAG_DNS, ZBX_JSON_TYPE_STRING, ""},
+ {"listen_port", ZBX_PROTO_TAG_PORT, ZBX_JSON_TYPE_STRING, "0"},
+ {"host_metadata", ZBX_PROTO_TAG_HOST_METADATA, ZBX_JSON_TYPE_STRING, ""},
+ {"flags", ZBX_PROTO_TAG_FLAGS, ZBX_JSON_TYPE_STRING, "0"},
+ {"tls_accepted", ZBX_PROTO_TAG_TLS_ACCEPTED, ZBX_JSON_TYPE_INT, "0"},
+ {NULL}
+ }
+};
+
+/******************************************************************************
+ * *
+ * Purpose: check proxy connection permissions (encryption configuration and *
+ * if peer proxy address is allowed) *
+ * *
+ * Parameters: *
+ * proxy - [IN] the proxy data *
+ * sock - [IN] connection socket context *
+ * error - [OUT] error message *
+ * *
+ * Return value: *
+ * SUCCEED - connection permission check was successful *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+int zbx_proxy_check_permissions(const DC_PROXY *proxy, const zbx_socket_t *sock, char **error)
+{
+#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
+ zbx_tls_conn_attr_t attr;
+#endif
+ if ('\0' != *proxy->proxy_address && FAIL == zbx_tcp_check_allowed_peers(sock, proxy->proxy_address))
+ {
+ *error = zbx_strdup(*error, "connection is not allowed");
+ return FAIL;
+ }
+
+#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
+ if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
+ {
+ if (SUCCEED != zbx_tls_get_attr_cert(sock, &attr))
+ {
+ *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
+ THIS_SHOULD_NEVER_HAPPEN;
+ return FAIL;
+ }
+ }
+#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
+ else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
+ {
+ if (SUCCEED != zbx_tls_get_attr_psk(sock, &attr))
+ {
+ *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
+ THIS_SHOULD_NEVER_HAPPEN;
+ return FAIL;
+ }
+ }
+#endif
+ else if (ZBX_TCP_SEC_UNENCRYPTED != sock->connection_type)
+ {
+ *error = zbx_strdup(*error, "internal error: invalid connection type");
+ THIS_SHOULD_NEVER_HAPPEN;
+ return FAIL;
+ }
+#endif
+ if (0 == ((unsigned int)proxy->tls_accept & sock->connection_type))
+ {
+ *error = zbx_dsprintf(NULL, "connection of type \"%s\" is not allowed for proxy \"%s\"",
+ zbx_tcp_connection_type_name(sock->connection_type), proxy->host);
+ return FAIL;
+ }
+
+#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
+ if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
+ {
+ /* simplified match, not compliant with RFC 4517, 4518 */
+ if ('\0' != *proxy->tls_issuer && 0 != strcmp(proxy->tls_issuer, attr.issuer))
+ {
+ *error = zbx_dsprintf(*error, "proxy \"%s\" certificate issuer does not match", proxy->host);
+ return FAIL;
+ }
+
+ /* simplified match, not compliant with RFC 4517, 4518 */
+ if ('\0' != *proxy->tls_subject && 0 != strcmp(proxy->tls_subject, attr.subject))
+ {
+ *error = zbx_dsprintf(*error, "proxy \"%s\" certificate subject does not match", proxy->host);
+ return FAIL;
+ }
+ }
+#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
+ else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
+ {
+ if (strlen(proxy->tls_psk_identity) != attr.psk_identity_len ||
+ 0 != memcmp(proxy->tls_psk_identity, attr.psk_identity, attr.psk_identity_len))
+ {
+ *error = zbx_dsprintf(*error, "proxy \"%s\" is using false PSK identity", proxy->host);
+ return FAIL;
+ }
+ }
+#endif
+#endif
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: checks host connection permissions (encryption configuration) *
+ * *
+ * Parameters: *
+ * host - [IN] the host data *
+ * sock - [IN] connection socket context *
+ * error - [OUT] error message *
+ * *
+ * Return value: *
+ * SUCCEED - connection permission check was successful *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int zbx_host_check_permissions(const DC_HOST *host, const zbx_socket_t *sock, char **error)
+{
+#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
+ zbx_tls_conn_attr_t attr;
+
+ if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
+ {
+ if (SUCCEED != zbx_tls_get_attr_cert(sock, &attr))
+ {
+ *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
+ THIS_SHOULD_NEVER_HAPPEN;
+ return FAIL;
+ }
+ }
+#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
+ else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
+ {
+ if (SUCCEED != zbx_tls_get_attr_psk(sock, &attr))
+ {
+ *error = zbx_strdup(*error, "internal error: cannot get connection attributes");
+ THIS_SHOULD_NEVER_HAPPEN;
+ return FAIL;
+ }
+ }
+#endif
+ else if (ZBX_TCP_SEC_UNENCRYPTED != sock->connection_type)
+ {
+ *error = zbx_strdup(*error, "internal error: invalid connection type");
+ THIS_SHOULD_NEVER_HAPPEN;
+ return FAIL;
+ }
+#endif
+ if (0 == ((unsigned int)host->tls_accept & sock->connection_type))
+ {
+ *error = zbx_dsprintf(NULL, "connection of type \"%s\" is not allowed for host \"%s\"",
+ zbx_tcp_connection_type_name(sock->connection_type), host->host);
+ return FAIL;
+ }
+
+#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
+ if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
+ {
+ /* simplified match, not compliant with RFC 4517, 4518 */
+ if ('\0' != *host->tls_issuer && 0 != strcmp(host->tls_issuer, attr.issuer))
+ {
+ *error = zbx_dsprintf(*error, "host \"%s\" certificate issuer does not match", host->host);
+ return FAIL;
+ }
+
+ /* simplified match, not compliant with RFC 4517, 4518 */
+ if ('\0' != *host->tls_subject && 0 != strcmp(host->tls_subject, attr.subject))
+ {
+ *error = zbx_dsprintf(*error, "host \"%s\" certificate subject does not match", host->host);
+ return FAIL;
+ }
+ }
+#if defined(HAVE_GNUTLS) || (defined(HAVE_OPENSSL) && defined(HAVE_OPENSSL_WITH_PSK))
+ else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
+ {
+ if (strlen(host->tls_psk_identity) != attr.psk_identity_len ||
+ 0 != memcmp(host->tls_psk_identity, attr.psk_identity, attr.psk_identity_len))
+ {
+ *error = zbx_dsprintf(*error, "host \"%s\" is using false PSK identity", host->host);
+ return FAIL;
+ }
+ }
+#endif
+#endif
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: *
+ * Extract a proxy name from JSON and find the proxy ID in configuration *
+ * cache, and check access rights. The proxy must be configured in active *
+ * mode. *
+ * *
+ * Parameters: *
+ * jp - [IN] JSON with the proxy name *
+ * proxy - [OUT] the proxy data *
+ * error - [OUT] error message *
+ * *
+ * Return value: *
+ * SUCCEED - proxy ID was found in database *
+ * FAIL - an error occurred (e.g. an unknown proxy, the proxy is *
+ * configured in passive mode or access denied) *
+ * *
+ ******************************************************************************/
+int get_active_proxy_from_request(const struct zbx_json_parse *jp, DC_PROXY *proxy, char **error)
+{
+ char *ch_error, host[ZBX_HOSTNAME_BUF_LEN];
+
+ if (SUCCEED != zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, host, sizeof(host), NULL))
+ {
+ *error = zbx_strdup(*error, "missing name of proxy");
+ return FAIL;
+ }
+
+ if (SUCCEED != zbx_check_hostname(host, &ch_error))
+ {
+ *error = zbx_dsprintf(*error, "invalid proxy name \"%s\": %s", host, ch_error);
+ zbx_free(ch_error);
+ return FAIL;
+ }
+
+ return zbx_dc_get_active_proxy_by_name(host, proxy, error);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: *
+ * Check access rights to a passive proxy for the given connection and *
+ * send a response if denied. *
+ * *
+ * Parameters: *
+ * sock - [IN] connection socket context *
+ * send_response - [IN] to send or not to send a response to server. *
+ * Value: ZBX_SEND_RESPONSE or *
+ * ZBX_DO_NOT_SEND_RESPONSE *
+ * req - [IN] request, included into error message *
+ * zbx_config_tls - [IN] configured requirements to allow access *
+ * *
+ * Return value: *
+ * SUCCEED - access is allowed *
+ * FAIL - access is denied *
+ * *
+ ******************************************************************************/
+int check_access_passive_proxy(zbx_socket_t *sock, int send_response, const char *req,
+ const zbx_config_tls_t *zbx_config_tls)
+{
+ char *msg = NULL;
+
+ if (FAIL == zbx_tcp_check_allowed_peers(sock, CONFIG_SERVER))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" is not allowed: %s", req, sock->peer,
+ zbx_socket_strerror());
+
+ if (ZBX_SEND_RESPONSE == send_response)
+ zbx_send_proxy_response(sock, FAIL, "connection is not allowed", CONFIG_TIMEOUT);
+
+ return FAIL;
+ }
+
+ if (0 == (zbx_config_tls->accept_modes & sock->connection_type))
+ {
+ msg = zbx_dsprintf(NULL, "%s over connection of type \"%s\" is not allowed", req,
+ zbx_tcp_connection_type_name(sock->connection_type));
+
+ zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" by proxy configuration parameter \"TLSAccept\"",
+ msg, sock->peer);
+
+ if (ZBX_SEND_RESPONSE == send_response)
+ zbx_send_proxy_response(sock, FAIL, msg, CONFIG_TIMEOUT);
+
+ zbx_free(msg);
+ return FAIL;
+ }
+
+#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
+ if (ZBX_TCP_SEC_TLS_CERT == sock->connection_type)
+ {
+ if (SUCCEED == zbx_check_server_issuer_subject(sock, zbx_config_tls->server_cert_issuer,
+ zbx_config_tls->server_cert_subject, &msg))
+ {
+ return SUCCEED;
+ }
+
+ zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" is not allowed: %s", req, sock->peer, msg);
+
+ if (ZBX_SEND_RESPONSE == send_response)
+ zbx_send_proxy_response(sock, FAIL, "certificate issuer or subject mismatch", CONFIG_TIMEOUT);
+
+ zbx_free(msg);
+ return FAIL;
+ }
+ else if (ZBX_TCP_SEC_TLS_PSK == sock->connection_type)
+ {
+ if (0 != (ZBX_PSK_FOR_PROXY & zbx_tls_get_psk_usage()))
+ return SUCCEED;
+
+ zabbix_log(LOG_LEVEL_WARNING, "%s from server \"%s\" is not allowed: it used PSK which is not"
+ " configured for proxy communication with server", req, sock->peer);
+
+ if (ZBX_SEND_RESPONSE == send_response)
+ zbx_send_proxy_response(sock, FAIL, "wrong PSK used", CONFIG_TIMEOUT);
+
+ return FAIL;
+ }
+#endif
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - no interface availability has been changed *
+ * *
+ ******************************************************************************/
+int get_interface_availability_data(struct zbx_json *json, int *ts)
+{
+ int i, ret = FAIL;
+ zbx_vector_ptr_t interfaces;
+ zbx_interface_availability_t *ia;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ zbx_vector_ptr_create(&interfaces);
+
+ if (SUCCEED != DCget_interfaces_availability(&interfaces, ts))
+ goto out;
+
+ zbx_json_addarray(json, ZBX_PROTO_TAG_INTERFACE_AVAILABILITY);
+
+ for (i = 0; i < interfaces.values_num; i++)
+ {
+ ia = (zbx_interface_availability_t *)interfaces.values[i];
+
+ zbx_json_addobject(json, NULL);
+ zbx_json_adduint64(json, ZBX_PROTO_TAG_INTERFACE_ID, ia->interfaceid);
+
+ zbx_json_adduint64(json, ZBX_PROTO_TAG_AVAILABLE, ia->agent.available);
+ zbx_json_addstring(json, ZBX_PROTO_TAG_ERROR, ia->agent.error, ZBX_JSON_TYPE_STRING);
+
+ zbx_json_close(json);
+ }
+
+ zbx_json_close(json);
+
+ ret = SUCCEED;
+out:
+ zbx_vector_ptr_clear_ext(&interfaces, (zbx_mem_free_func_t)zbx_interface_availability_free);
+ zbx_vector_ptr_destroy(&interfaces);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parses interfaces availability data contents and processes it *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+static int process_interfaces_availability_contents(struct zbx_json_parse *jp_data, char **error)
+{
+ zbx_uint64_t interfaceid;
+ struct zbx_json_parse jp_row;
+ const char *p = NULL;
+ char *tmp;
+ size_t tmp_alloc = 129;
+ zbx_interface_availability_t *ia = NULL;
+ zbx_vector_availability_ptr_t interfaces;
+ int ret;
+
+ tmp = (char *)zbx_malloc(NULL, tmp_alloc);
+
+ zbx_vector_availability_ptr_create(&interfaces);
+
+ while (NULL != (p = zbx_json_next(jp_data, p))) /* iterate the interface entries */
+ {
+ if (SUCCEED != (ret = zbx_json_brackets_open(p, &jp_row)))
+ {
+ *error = zbx_strdup(*error, zbx_json_strerror());
+ goto out;
+ }
+
+ if (SUCCEED != (ret = zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_INTERFACE_ID, &tmp, &tmp_alloc,
+ NULL)))
+ {
+ *error = zbx_strdup(*error, zbx_json_strerror());
+ goto out;
+ }
+
+ if (SUCCEED != (ret = zbx_is_uint64(tmp, &interfaceid)))
+ {
+ *error = zbx_strdup(*error, "interfaceid is not a valid numeric");
+ goto out;
+ }
+
+ ia = (zbx_interface_availability_t *)zbx_malloc(NULL, sizeof(zbx_interface_availability_t));
+ zbx_interface_availability_init(ia, interfaceid);
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_AVAILABLE, &tmp, &tmp_alloc, NULL))
+ {
+ ia->agent.available = atoi(tmp);
+ ia->agent.flags |= ZBX_FLAGS_AGENT_STATUS_AVAILABLE;
+ }
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_ERROR, &tmp, &tmp_alloc, NULL))
+ {
+ ia->agent.error = zbx_strdup(NULL, tmp);
+ ia->agent.flags |= ZBX_FLAGS_AGENT_STATUS_ERROR;
+ }
+
+ if (SUCCEED != (ret = zbx_interface_availability_is_set(ia)))
+ {
+ zbx_free(ia);
+ *error = zbx_dsprintf(*error, "no availability data for \"interfaceid\":" ZBX_FS_UI64,
+ interfaceid);
+ goto out;
+ }
+
+ zbx_vector_availability_ptr_append(&interfaces, ia);
+ }
+
+ if (0 < interfaces.values_num && SUCCEED == DCset_interfaces_availability(&interfaces))
+ zbx_availabilities_flush(&interfaces);
+
+ ret = SUCCEED;
+out:
+ zbx_vector_availability_ptr_clear_ext(&interfaces, zbx_interface_availability_free);
+ zbx_vector_availability_ptr_destroy(&interfaces);
+
+ zbx_free(tmp);
+
+ return ret;
+}
+
+static void proxy_get_lastid(const char *table_name, const char *lastidfield, zbx_uint64_t *lastid)
+{
+ DB_RESULT result;
+ DB_ROW row;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() field:'%s.%s'", __func__, table_name, lastidfield);
+
+ result = DBselect("select nextid from ids where table_name='%s' and field_name='%s'",
+ table_name, lastidfield);
+
+ if (NULL == (row = DBfetch(result)))
+ *lastid = 0;
+ else
+ ZBX_STR2UINT64(*lastid, row[0]);
+ DBfree_result(result);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():" ZBX_FS_UI64, __func__, *lastid);
+}
+
+static void proxy_set_lastid(const char *table_name, const char *lastidfield, const zbx_uint64_t lastid)
+{
+ DB_RESULT result;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() [%s.%s:" ZBX_FS_UI64 "]", __func__, table_name, lastidfield, lastid);
+
+ result = DBselect("select 1 from ids where table_name='%s' and field_name='%s'",
+ table_name, lastidfield);
+
+ if (NULL == DBfetch(result))
+ {
+ DBexecute("insert into ids (table_name,field_name,nextid) values ('%s','%s'," ZBX_FS_UI64 ")",
+ table_name, lastidfield, lastid);
+ }
+ else
+ {
+ DBexecute("update ids set nextid=" ZBX_FS_UI64 " where table_name='%s' and field_name='%s'",
+ lastid, table_name, lastidfield);
+ }
+ DBfree_result(result);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
+}
+
+void proxy_set_hist_lastid(const zbx_uint64_t lastid)
+{
+ proxy_set_lastid("proxy_history", "history_lastid", lastid);
+}
+
+void proxy_set_dhis_lastid(const zbx_uint64_t lastid)
+{
+ proxy_set_lastid(dht.table, dht.lastidfield, lastid);
+}
+
+void proxy_set_areg_lastid(const zbx_uint64_t lastid)
+{
+ proxy_set_lastid(areg.table, areg.lastidfield, lastid);
+}
+
+int proxy_get_delay(const zbx_uint64_t lastid)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ char *sql = NULL;
+ int ts = 0;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() [lastid=" ZBX_FS_UI64 "]", __func__, lastid);
+
+ sql = zbx_dsprintf(sql, "select write_clock from proxy_history where id>" ZBX_FS_UI64 " order by id asc",
+ lastid);
+
+ result = DBselectN(sql, 1);
+ zbx_free(sql);
+
+ if (NULL != (row = DBfetch(result)))
+ ts = (int)time(NULL) - atoi(row[0]);
+
+ DBfree_result(result);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
+
+ return ts;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: Get history data from the database. *
+ * *
+ ******************************************************************************/
+static void proxy_get_history_data_simple(struct zbx_json *j, const char *proto_tag, const zbx_history_table_t *ht,
+ zbx_uint64_t *lastid, zbx_uint64_t *id, int *records_num, int *more)
+{
+ size_t offset = 0;
+ int f, records_num_last = *records_num, retries = 1;
+ char sql[MAX_STRING_LEN];
+ DB_RESULT result;
+ DB_ROW row;
+ struct timespec t_sleep = { 0, 100000000L }, t_rem;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() table:'%s'", __func__, ht->table);
+
+ *more = ZBX_PROXY_DATA_DONE;
+
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, "select id");
+
+ for (f = 0; NULL != ht->fields[f].field; f++)
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, ",%s", ht->fields[f].field);
+try_again:
+ zbx_snprintf(sql + offset, sizeof(sql) - offset, " from %s where id>" ZBX_FS_UI64 " order by id",
+ ht->table, *id);
+
+ result = DBselectN(sql, ZBX_MAX_HRECORDS);
+
+ while (NULL != (row = DBfetch(result)))
+ {
+ ZBX_STR2UINT64(*lastid, row[0]);
+
+ if (1 < *lastid - *id)
+ {
+ /* At least one record is missing. It can happen if some DB syncer process has */
+ /* started but not yet committed a transaction or a rollback occurred in a DB syncer. */
+ if (0 < retries--)
+ {
+ DBfree_result(result);
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing."
+ " Waiting " ZBX_FS_DBL " sec, retrying.",
+ __func__, *lastid - *id - 1,
+ t_sleep.tv_sec + t_sleep.tv_nsec / 1e9);
+ nanosleep(&t_sleep, &t_rem);
+ goto try_again;
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing. No more retries.",
+ __func__, *lastid - *id - 1);
+ }
+ }
+
+ if (0 == *records_num)
+ zbx_json_addarray(j, proto_tag);
+
+ zbx_json_addobject(j, NULL);
+
+ for (f = 0; NULL != ht->fields[f].field; f++)
+ {
+ if (NULL != ht->fields[f].default_value && 0 == strcmp(row[f + 1], ht->fields[f].default_value))
+ continue;
+
+ zbx_json_addstring(j, ht->fields[f].tag, row[f + 1], ht->fields[f].jt);
+ }
+
+ (*records_num)++;
+
+ zbx_json_close(j);
+
+ /* stop gathering data to avoid exceeding the maximum packet size */
+ if (ZBX_DATA_JSON_RECORD_LIMIT < j->buffer_offset)
+ {
+ *more = ZBX_PROXY_DATA_MORE;
+ break;
+ }
+
+ *id = *lastid;
+ }
+ DBfree_result(result);
+
+ if (ZBX_MAX_HRECORDS == *records_num - records_num_last)
+ *more = ZBX_PROXY_DATA_MORE;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%d lastid:" ZBX_FS_UI64 " more:%d size:" ZBX_FS_SIZE_T,
+ __func__, *records_num - records_num_last, *lastid, *more,
+ (zbx_fs_size_t)j->buffer_offset);
+}
+
+typedef struct
+{
+ zbx_uint64_t id;
+ zbx_uint64_t itemid;
+ zbx_uint64_t lastlogsize;
+ size_t source_offset;
+ size_t value_offset;
+ int clock;
+ int ns;
+ int timestamp;
+ int severity;
+ int logeventid;
+ int mtime;
+ unsigned char state;
+ unsigned char flags;
+}
+zbx_history_data_t;
+
+/******************************************************************************
+ * *
+ * Purpose: read proxy history data from the database *
+ * *
+ * Parameters: lastid - [IN] the id of last processed proxy *
+ * history record *
+ * data - [IN/OUT] the proxy history data buffer *
+ * data_alloc - [IN/OUT] the size of proxy history data *
+ * buffer *
+ * string_buffer - [IN/OUT] the string buffer *
+ * string_buffer_size - [IN/OUT] the size of string buffer *
+ * more - [OUT] set to ZBX_PROXY_DATA_MORE if there *
+ * might be more data to read *
+ * *
+ * Return value: The number of records read. *
+ * *
+ ******************************************************************************/
+static int proxy_get_history_data(zbx_uint64_t lastid, zbx_history_data_t **data, size_t *data_alloc,
+ char **string_buffer, size_t *string_buffer_alloc, int *more)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ char *sql = NULL;
+ size_t sql_alloc = 0, sql_offset = 0, data_num = 0;
+ size_t string_buffer_offset = 0;
+ zbx_uint64_t id;
+ int retries = 1, total_retries = 10;
+ struct timespec t_sleep = { 0, 100000000L }, t_rem;
+ zbx_history_data_t *hd;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() lastid:" ZBX_FS_UI64, __func__, lastid);
+
+try_again:
+ zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
+ "select id,itemid,clock,ns,timestamp,source,severity,"
+ "value,logeventid,state,lastlogsize,mtime,flags"
+ " from proxy_history"
+ " where id>" ZBX_FS_UI64
+ " order by id",
+ lastid);
+
+ result = DBselectN(sql, ZBX_MAX_HRECORDS - data_num);
+
+ zbx_free(sql);
+
+ while (NULL != (row = DBfetch(result)))
+ {
+ ZBX_STR2UINT64(id, row[0]);
+
+ if (1 < id - lastid)
+ {
+ /* At least one record is missing. It can happen if some DB syncer process has */
+ /* started but not yet committed a transaction or a rollback occurred in a DB syncer. */
+ if (0 < retries--)
+ {
+ /* limit the number of total retries to avoid being stuck */
+ /* in history full of 'holes' for a long time */
+ if (0 >= total_retries--)
+ break;
+
+ DBfree_result(result);
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing."
+ " Waiting " ZBX_FS_DBL " sec, retrying.",
+ __func__, id - lastid - 1,
+ t_sleep.tv_sec + t_sleep.tv_nsec / 1e9);
+ nanosleep(&t_sleep, &t_rem);
+ goto try_again;
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() " ZBX_FS_UI64 " record(s) missing. No more retries.",
+ __func__, id - lastid - 1);
+ }
+ }
+
+ retries = 1;
+
+ if (*data_alloc == data_num)
+ {
+ *data_alloc *= 2;
+ *data = (zbx_history_data_t *)zbx_realloc(*data, sizeof(zbx_history_data_t) * *data_alloc);
+ }
+
+ hd = *data + data_num++;
+ hd->id = id;
+ ZBX_STR2UINT64(hd->itemid, row[1]);
+ ZBX_STR2UCHAR(hd->flags, row[12]);
+ hd->clock = atoi(row[2]);
+ hd->ns = atoi(row[3]);
+
+ if (PROXY_HISTORY_FLAG_NOVALUE != (hd->flags & PROXY_HISTORY_MASK_NOVALUE))
+ {
+ ZBX_STR2UCHAR(hd->state, row[9]);
+
+ if (0 == (hd->flags & PROXY_HISTORY_FLAG_NOVALUE))
+ {
+ size_t len1, len2;
+
+ hd->timestamp = atoi(row[4]);
+ hd->severity = atoi(row[6]);
+ hd->logeventid = atoi(row[8]);
+
+ len1 = strlen(row[5]) + 1;
+ len2 = strlen(row[7]) + 1;
+
+ if (*string_buffer_alloc < string_buffer_offset + len1 + len2)
+ {
+ while (*string_buffer_alloc < string_buffer_offset + len1 + len2)
+ *string_buffer_alloc += ZBX_KIBIBYTE;
+
+ *string_buffer = (char *)zbx_realloc(*string_buffer, *string_buffer_alloc);
+ }
+
+ hd->source_offset = string_buffer_offset;
+ memcpy(*string_buffer + hd->source_offset, row[5], len1);
+ string_buffer_offset += len1;
+
+ hd->value_offset = string_buffer_offset;
+ memcpy(*string_buffer + hd->value_offset, row[7], len2);
+ string_buffer_offset += len2;
+ }
+
+ if (0 != (hd->flags & PROXY_HISTORY_FLAG_META))
+ {
+ ZBX_STR2UINT64(hd->lastlogsize, row[10]);
+ hd->mtime = atoi(row[11]);
+ }
+ }
+
+ lastid = id;
+ }
+ DBfree_result(result);
+
+ if (ZBX_MAX_HRECORDS != data_num && 1 == retries)
+ *more = ZBX_PROXY_DATA_DONE;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s() data_num:" ZBX_FS_SIZE_T, __func__, data_num);
+
+ return data_num;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: add history records to output json *
+ * *
+ * Parameters: j - [IN] the json output buffer *
+ * records_num - [IN] the total number of records added *
+ * dc_items - [IN] the item configuration data *
+ * errcodes - [IN] the item configuration status codes *
+ * records - [IN] the records to add *
+ * string_buffer - [IN] the string buffer holding string values *
+ * lastid - [OUT] the id of last added record *
+ * *
+ * Return value: The total number of records added. *
+ * *
+ ******************************************************************************/
+static int proxy_add_hist_data(struct zbx_json *j, int records_num, const DC_ITEM *dc_items, const int *errcodes,
+ const zbx_vector_ptr_t *records, const char *string_buffer, zbx_uint64_t *lastid)
+{
+ int i;
+ const zbx_history_data_t *hd;
+
+ for (i = records->values_num - 1; i >= 0; i--)
+ {
+ hd = (const zbx_history_data_t *)records->values[i];
+ *lastid = hd->id;
+
+ if (SUCCEED != errcodes[i])
+ continue;
+
+ if (ITEM_STATUS_ACTIVE != dc_items[i].status)
+ continue;
+
+ if (HOST_STATUS_MONITORED != dc_items[i].host.status)
+ continue;
+
+ if (PROXY_HISTORY_FLAG_NOVALUE == (hd->flags & PROXY_HISTORY_MASK_NOVALUE))
+ {
+ if (SUCCEED != zbx_is_counted_in_item_queue(dc_items[i].type, dc_items[i].key_orig))
+ continue;
+ }
+
+ if (0 == records_num)
+ zbx_json_addarray(j, ZBX_PROTO_TAG_HISTORY_DATA);
+
+ zbx_json_addobject(j, NULL);
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_ID, hd->id);
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_ITEMID, hd->itemid);
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_CLOCK, hd->clock);
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_NS, hd->ns);
+
+ if (PROXY_HISTORY_FLAG_NOVALUE != (hd->flags & PROXY_HISTORY_MASK_NOVALUE))
+ {
+ if (ITEM_STATE_NORMAL != hd->state)
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_STATE, hd->state);
+
+ if (0 == (hd->flags & PROXY_HISTORY_FLAG_NOVALUE))
+ {
+ if (0 != hd->timestamp)
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGTIMESTAMP, hd->timestamp);
+
+ if ('\0' != string_buffer[hd->source_offset])
+ {
+ zbx_json_addstring(j, ZBX_PROTO_TAG_LOGSOURCE,
+ string_buffer + hd->source_offset, ZBX_JSON_TYPE_STRING);
+ }
+
+ if (0 != hd->severity)
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGSEVERITY, hd->severity);
+
+ if (0 != hd->logeventid)
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_LOGEVENTID, hd->logeventid);
+
+ zbx_json_addstring(j, ZBX_PROTO_TAG_VALUE, string_buffer + hd->value_offset,
+ ZBX_JSON_TYPE_STRING);
+ }
+
+ if (0 != (hd->flags & PROXY_HISTORY_FLAG_META))
+ {
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_LASTLOGSIZE, hd->lastlogsize);
+ zbx_json_adduint64(j, ZBX_PROTO_TAG_MTIME, hd->mtime);
+ }
+ }
+
+ zbx_json_close(j);
+ records_num++;
+
+ /* stop gathering data to avoid exceeding the maximum packet size */
+ if (ZBX_DATA_JSON_RECORD_LIMIT < j->buffer_offset)
+ break;
+ }
+
+ return records_num;
+}
+
+int proxy_get_hist_data(struct zbx_json *j, zbx_uint64_t *lastid, int *more)
+{
+ int records_num = 0, data_num, i, *errcodes = NULL, items_alloc = 0;
+ zbx_uint64_t id;
+ zbx_hashset_t itemids_added;
+ zbx_history_data_t *data;
+ char *string_buffer;
+ size_t data_alloc = 16, string_buffer_alloc = ZBX_KIBIBYTE;
+ zbx_vector_uint64_t itemids;
+ zbx_vector_ptr_t records;
+ DC_ITEM *dc_items = 0;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ zbx_vector_uint64_create(&itemids);
+ zbx_vector_ptr_create(&records);
+ data = (zbx_history_data_t *)zbx_malloc(NULL, data_alloc * sizeof(zbx_history_data_t));
+ string_buffer = (char *)zbx_malloc(NULL, string_buffer_alloc);
+
+ *more = ZBX_PROXY_DATA_MORE;
+ proxy_get_lastid("proxy_history", "history_lastid", &id);
+
+ zbx_hashset_create(&itemids_added, data_alloc, ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
+
+ /* get history data in batches by ZBX_MAX_HRECORDS records and stop if: */
+ /* 1) there are no more data to read */
+ /* 2) we have retrieved more than the total maximum number of records */
+ /* 3) we have gathered more than half of the maximum packet size */
+ while (ZBX_DATA_JSON_BATCH_LIMIT > j->buffer_offset && ZBX_MAX_HRECORDS_TOTAL > records_num &&
+ 0 != (data_num = proxy_get_history_data(id, &data, &data_alloc, &string_buffer,
+ &string_buffer_alloc, more)))
+ {
+ zbx_vector_uint64_reserve(&itemids, data_num);
+ zbx_vector_ptr_reserve(&records, data_num);
+
+ /* filter out duplicate novalue updates */
+ for (i = data_num - 1; i >= 0; i--)
+ {
+ if (PROXY_HISTORY_FLAG_NOVALUE == (data[i].flags & PROXY_HISTORY_MASK_NOVALUE))
+ {
+ if (NULL != zbx_hashset_search(&itemids_added, &data[i].itemid))
+ continue;
+
+ zbx_hashset_insert(&itemids_added, &data[i].itemid, sizeof(data[i].itemid));
+ }
+
+ zbx_vector_ptr_append(&records, &data[i]);
+ zbx_vector_uint64_append(&itemids, data[i].itemid);
+ }
+
+ /* append history records to json */
+
+ if (itemids.values_num > items_alloc)
+ {
+ items_alloc = itemids.values_num;
+ dc_items = (DC_ITEM *)zbx_realloc(dc_items, items_alloc * sizeof(DC_ITEM));
+ errcodes = (int *)zbx_realloc(errcodes, items_alloc * sizeof(int));
+ }
+
+ DCconfig_get_items_by_itemids(dc_items, itemids.values, errcodes, itemids.values_num);
+
+ records_num = proxy_add_hist_data(j, records_num, dc_items, errcodes, &records, string_buffer, lastid);
+ DCconfig_clean_items(dc_items, errcodes, itemids.values_num);
+
+ /* got less data than requested - either no more data to read or the history is full of */
+ /* holes. In this case send retrieved data before attempting to read/wait for more data */
+ if (ZBX_MAX_HRECORDS > data_num)
+ break;
+
+ zbx_vector_uint64_clear(&itemids);
+ zbx_vector_ptr_clear(&records);
+ zbx_hashset_clear(&itemids_added);
+ id = *lastid;
+ }
+
+ if (0 != records_num)
+ zbx_json_close(j);
+
+ zbx_hashset_destroy(&itemids_added);
+
+ zbx_free(dc_items);
+ zbx_free(errcodes);
+ zbx_free(data);
+ zbx_free(string_buffer);
+ zbx_vector_ptr_destroy(&records);
+ zbx_vector_uint64_destroy(&itemids);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s() lastid:" ZBX_FS_UI64 " records_num:%d size:~" ZBX_FS_SIZE_T " more:%d",
+ __func__, *lastid, records_num, j->buffer_offset, *more);
+
+ return records_num;
+}
+
+int proxy_get_dhis_data(struct zbx_json *j, zbx_uint64_t *lastid, int *more)
+{
+ int records_num = 0;
+ zbx_uint64_t id;
+
+ proxy_get_lastid(dht.table, dht.lastidfield, &id);
+
+ /* get history data in batches by ZBX_MAX_HRECORDS records and stop if: */
+ /* 1) there are no more data to read */
+ /* 2) we have retrieved more than the total maximum number of records */
+ /* 3) we have gathered more than half of the maximum packet size */
+ while (ZBX_DATA_JSON_BATCH_LIMIT > j->buffer_offset)
+ {
+ proxy_get_history_data_simple(j, ZBX_PROTO_TAG_DISCOVERY_DATA, &dht, lastid, &id, &records_num, more);
+
+ if (ZBX_PROXY_DATA_DONE == *more || ZBX_MAX_HRECORDS_TOTAL <= records_num)
+ break;
+ }
+
+ if (0 != records_num)
+ zbx_json_close(j);
+
+ return records_num;
+}
+
+int proxy_get_areg_data(struct zbx_json *j, zbx_uint64_t *lastid, int *more)
+{
+ int records_num = 0;
+ zbx_uint64_t id;
+
+ proxy_get_lastid(areg.table, areg.lastidfield, &id);
+
+ /* get history data in batches by ZBX_MAX_HRECORDS records and stop if: */
+ /* 1) there are no more data to read */
+ /* 2) we have retrieved more than the total maximum number of records */
+ /* 3) we have gathered more than half of the maximum packet size */
+ while (ZBX_DATA_JSON_BATCH_LIMIT > j->buffer_offset)
+ {
+ proxy_get_history_data_simple(j, ZBX_PROTO_TAG_AUTOREGISTRATION, &areg, lastid, &id, &records_num,
+ more);
+
+ if (ZBX_PROXY_DATA_DONE == *more || ZBX_MAX_HRECORDS_TOTAL <= records_num)
+ break;
+ }
+
+ if (0 != records_num)
+ zbx_json_close(j);
+
+ return records_num;
+}
+
+int proxy_get_host_active_availability(struct zbx_json *j)
+{
+ zbx_ipc_message_t response;
+ int records_num = 0;
+
+ zbx_ipc_message_init(&response);
+ zbx_availability_send(ZBX_IPC_AVAILMAN_ACTIVE_HOSTDATA, 0, 0, &response);
+
+ if (0 != response.size)
+ {
+ zbx_vector_proxy_hostdata_ptr_t hostdata;
+
+ zbx_vector_proxy_hostdata_ptr_create(&hostdata);
+ zbx_availability_deserialize_hostdata(response.data, &hostdata);
+ zbx_availability_serialize_json_hostdata(&hostdata, j);
+
+ records_num = hostdata.values_num;
+
+ zbx_vector_proxy_hostdata_ptr_clear_ext(&hostdata, (zbx_proxy_hostdata_ptr_free_func_t)zbx_ptr_free);
+ zbx_vector_proxy_hostdata_ptr_destroy(&hostdata);
+ }
+
+ zbx_ipc_message_clean(&response);
+
+ return records_num;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: processes item value depending on proxy/flags settings *
+ * *
+ * Parameters: item - [IN] the item to process *
+ * result - [IN] the item result *
+ * *
+ * Comments: Values gathered by server are sent to the preprocessing manager, *
+ * while values received from proxy are already preprocessed and *
+ * must be either directly stored to history cache or sent to lld *
+ * manager. *
+ * *
+ ******************************************************************************/
+static void process_item_value(const DC_ITEM *item, AGENT_RESULT *result, zbx_timespec_t *ts, int *h_num,
+ char *error)
+{
+ if (0 == item->host.proxy_hostid)
+ {
+ zbx_preprocess_item_value(item->itemid, item->host.hostid, item->value_type, item->flags, result, ts,
+ item->state, error);
+ *h_num = 0;
+ }
+ else
+ {
+ if (0 != (ZBX_FLAG_DISCOVERY_RULE & item->flags))
+ {
+ zbx_lld_process_agent_result(item->itemid, item->host.hostid, result, ts, error);
+ *h_num = 0;
+ }
+ else
+ {
+ dc_add_history(item->itemid, item->value_type, item->flags, result, ts, item->state, error);
+ *h_num = 1;
+ }
+ }
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process single value from incoming history data *
+ * *
+ * Parameters: item - [IN] the item to process *
+ * value - [IN] the value to process *
+ * hval - [OUT] indication that value was added to history *
+ * *
+ * Return value: SUCCEED - the value was processed successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int process_history_data_value(DC_ITEM *item, zbx_agent_value_t *value, int *h_num)
+{
+ if (ITEM_STATUS_ACTIVE != item->status)
+ return FAIL;
+
+ if (HOST_STATUS_MONITORED != item->host.status)
+ return FAIL;
+
+ /* update item nextcheck during maintenance */
+ if (SUCCEED == in_maintenance_without_data_collection(item->host.maintenance_status,
+ item->host.maintenance_type, item->type) &&
+ item->host.maintenance_from <= value->ts.sec)
+ {
+ return SUCCEED;
+ }
+
+ if (NULL == value->value && ITEM_STATE_NOTSUPPORTED == value->state)
+ {
+ THIS_SHOULD_NEVER_HAPPEN;
+ return FAIL;
+ }
+
+ if (ITEM_STATE_NOTSUPPORTED == value->state ||
+ (NULL != value->value && 0 == strcmp(value->value, ZBX_NOTSUPPORTED)))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "item [%s:%s] error: %s", item->host.host, item->key_orig, value->value);
+
+ item->state = ITEM_STATE_NOTSUPPORTED;
+ process_item_value(item, NULL, &value->ts, h_num, value->value);
+ }
+ else
+ {
+ AGENT_RESULT result;
+
+ zbx_init_agent_result(&result);
+
+ if (NULL != value->value)
+ {
+ if (ITEM_VALUE_TYPE_LOG == item->value_type)
+ {
+ zbx_log_t *log;
+
+ log = (zbx_log_t *)zbx_malloc(NULL, sizeof(zbx_log_t));
+ log->value = zbx_strdup(NULL, value->value);
+ zbx_replace_invalid_utf8(log->value);
+
+ if (0 == value->timestamp)
+ {
+ log->timestamp = 0;
+ calc_timestamp(log->value, &log->timestamp, item->logtimefmt);
+ }
+ else
+ log->timestamp = value->timestamp;
+
+ log->logeventid = value->logeventid;
+ log->severity = value->severity;
+
+ if (NULL != value->source)
+ {
+ log->source = zbx_strdup(NULL, value->source);
+ zbx_replace_invalid_utf8(log->source);
+ }
+ else
+ log->source = NULL;
+
+ SET_LOG_RESULT(&result, log);
+ }
+ else
+ zbx_set_agent_result_type(&result, ITEM_VALUE_TYPE_TEXT, value->value);
+ }
+
+ if (0 != value->meta)
+ zbx_set_agent_result_meta(&result, value->lastlogsize, value->mtime);
+
+ if (0 != ZBX_ISSET_VALUE(&result) || 0 != ZBX_ISSET_META(&result))
+ {
+ item->state = ITEM_STATE_NORMAL;
+ process_item_value(item, &result, &value->ts, h_num, NULL);
+ }
+
+ zbx_free_agent_result(&result);
+ }
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process new item values *
+ * *
+ * Parameters: items - [IN] the items to process *
+ * values - [IN] the item values value to process *
+ * errcodes - [IN/OUT] in - item configuration error code *
+ * (FAIL - item/host was not found) *
+ * out - value processing result *
+ * (SUCCEED - processed, FAIL - error) *
+ * values_num - [IN] the number of items/values to process *
+ * nodata_win - [IN/OUT] proxy communication delay info *
+ * *
+ * Return value: the number of processed values *
+ * *
+ ******************************************************************************/
+int process_history_data(DC_ITEM *items, zbx_agent_value_t *values, int *errcodes, size_t values_num,
+ zbx_proxy_suppress_t *nodata_win)
+{
+ size_t i;
+ int processed_num = 0, history_num;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ for (i = 0; i < values_num; i++)
+ {
+ if (SUCCEED != errcodes[i])
+ continue;
+
+ history_num = 0;
+
+ if (SUCCEED != process_history_data_value(&items[i], &values[i], &history_num))
+ {
+ /* clean failed items to avoid updating their runtime data */
+ DCconfig_clean_items(&items[i], &errcodes[i], 1);
+ errcodes[i] = FAIL;
+ continue;
+ }
+
+ if (0 != items[i].host.proxy_hostid && NULL != nodata_win &&
+ 0 != (nodata_win->flags & ZBX_PROXY_SUPPRESS_ACTIVE) && 0 < history_num)
+ {
+ if (values[i].ts.sec <= nodata_win->period_end)
+ {
+ nodata_win->values_num++;
+ }
+ else
+ {
+ nodata_win->flags &= (~ZBX_PROXY_SUPPRESS_MORE);
+ }
+
+ zabbix_log(LOG_LEVEL_TRACE, "%s() flags:%d values_num:%d value_time:%d period_end:%d",
+ __func__, nodata_win->flags, nodata_win->values_num, values[i].ts.sec,
+ nodata_win->period_end);
+ }
+
+ processed_num++;
+ }
+
+ if (0 < processed_num)
+ zbx_dc_items_update_nextcheck(items, values, errcodes, values_num);
+
+ zbx_preprocessor_flush();
+ dc_flush_history();
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s() processed:%d", __func__, processed_num);
+
+ return processed_num;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: frees resources allocated to store agent values *
+ * *
+ * Parameters: values - [IN] the values to clean *
+ * values_num - [IN] the number of items in values array *
+ * *
+ ******************************************************************************/
+static void zbx_agent_values_clean(zbx_agent_value_t *values, size_t values_num)
+{
+ size_t i;
+
+ for (i = 0; i < values_num; i++)
+ {
+ zbx_free(values[i].value);
+ zbx_free(values[i].source);
+ }
+}
+
+/******************************************************************************
+ * *
+ * Purpose: calculates difference between server and client (proxy, active *
+ * agent or sender) time and log it *
+ * *
+ * Parameters: level - [IN] log level *
+ * jp - [IN] JSON with clock, [ns] fields *
+ * ts_recv - [IN] the connection timestamp *
+ * *
+ ******************************************************************************/
+static void log_client_timediff(int level, struct zbx_json_parse *jp, const zbx_timespec_t *ts_recv)
+{
+ char tmp[32];
+ zbx_timespec_t client_timediff;
+ int sec, ns;
+
+ if (SUCCEED != ZBX_CHECK_LOG_LEVEL(level))
+ return;
+
+ if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp), NULL))
+ {
+ sec = atoi(tmp);
+ client_timediff.sec = ts_recv->sec - sec;
+
+ if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_NS, tmp, sizeof(tmp), NULL))
+ {
+ ns = atoi(tmp);
+ client_timediff.ns = ts_recv->ns - ns;
+
+ if (client_timediff.sec > 0 && client_timediff.ns < 0)
+ {
+ client_timediff.sec--;
+ client_timediff.ns += 1000000000;
+ }
+ else if (client_timediff.sec < 0 && client_timediff.ns > 0)
+ {
+ client_timediff.sec++;
+ client_timediff.ns -= 1000000000;
+ }
+
+ zabbix_log(level, "%s(): timestamp from json %d seconds and %d nanosecond, "
+ "delta time from json %d seconds and %d nanosecond",
+ __func__, sec, ns, client_timediff.sec, client_timediff.ns);
+ }
+ else
+ {
+ zabbix_log(level, "%s(): timestamp from json %d seconds, "
+ "delta time from json %d seconds", __func__, sec, client_timediff.sec);
+ }
+ }
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parses agent value from history data json row *
+ * *
+ * Parameters: jp_row - [IN] JSON with history data row *
+ * unique_shift - [IN/OUT] auto increment nanoseconds to ensure *
+ * unique value of timestamps *
+ * av - [OUT] the agent value *
+ * *
+ * Return value: SUCCEED - the value was parsed successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int parse_history_data_row_value(const struct zbx_json_parse *jp_row, zbx_timespec_t *unique_shift,
+ zbx_agent_value_t *av)
+{
+ char *tmp = NULL;
+ size_t tmp_alloc = 0;
+ int ret = FAIL;
+
+ memset(av, 0, sizeof(zbx_agent_value_t));
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_CLOCK, &tmp, &tmp_alloc, NULL))
+ {
+ if (FAIL == zbx_is_uint31(tmp, &av->ts.sec))
+ goto out;
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_NS, &tmp, &tmp_alloc, NULL))
+ {
+ if (FAIL == zbx_is_uint_n_range(tmp, tmp_alloc, &av->ts.ns, sizeof(av->ts.ns),
+ 0LL, 999999999LL))
+ {
+ goto out;
+ }
+ }
+ else
+ {
+ /* ensure unique value timestamp (clock, ns) if only clock is available */
+
+ av->ts.sec += unique_shift->sec;
+ av->ts.ns = unique_shift->ns++;
+
+ if (unique_shift->ns > 999999999)
+ {
+ unique_shift->sec++;
+ unique_shift->ns = 0;
+ }
+ }
+ }
+ else
+ zbx_timespec(&av->ts);
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_STATE, &tmp, &tmp_alloc, NULL))
+ av->state = (unsigned char)atoi(tmp);
+
+ /* Unsupported item meta information must be ignored for backwards compatibility. */
+ /* New agents will not send meta information for items in unsupported state. */
+ if (ITEM_STATE_NOTSUPPORTED != av->state)
+ {
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LASTLOGSIZE, &tmp, &tmp_alloc, NULL))
+ {
+ av->meta = 1; /* contains meta information */
+
+ zbx_is_uint64(tmp, &av->lastlogsize);
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_MTIME, &tmp, &tmp_alloc, NULL))
+ av->mtime = atoi(tmp);
+ }
+ }
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_VALUE, &tmp, &tmp_alloc, NULL))
+ av->value = zbx_strdup(av->value, tmp);
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGTIMESTAMP, &tmp, &tmp_alloc, NULL))
+ av->timestamp = atoi(tmp);
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGSOURCE, &tmp, &tmp_alloc, NULL))
+ av->source = zbx_strdup(av->source, tmp);
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGSEVERITY, &tmp, &tmp_alloc, NULL))
+ av->severity = atoi(tmp);
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_LOGEVENTID, &tmp, &tmp_alloc, NULL))
+ av->logeventid = atoi(tmp);
+
+ if (SUCCEED != zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_ID, &tmp, &tmp_alloc, NULL) ||
+ SUCCEED != zbx_is_uint64(tmp, &av->id))
+ {
+ av->id = 0;
+ }
+
+ zbx_free(tmp);
+
+ ret = SUCCEED;
+out:
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parses item identifier from history data json row *
+ * *
+ * Parameters: jp_row - [IN] JSON with history data row *
+ * itemid - [OUT] the item identifier *
+ * *
+ * Return value: SUCCEED - the item identifier was parsed successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int parse_history_data_row_itemid(const struct zbx_json_parse *jp_row, zbx_uint64_t *itemid)
+{
+ char buffer[MAX_ID_LEN + 1];
+
+ if (SUCCEED != zbx_json_value_by_name(jp_row, ZBX_PROTO_TAG_ITEMID, buffer, sizeof(buffer), NULL))
+ return FAIL;
+
+ if (SUCCEED != zbx_is_uint64(buffer, itemid))
+ return FAIL;
+
+ return SUCCEED;
+}
+/******************************************************************************
+ * *
+ * Purpose: parses host,key pair from history data json row *
+ * *
+ * Parameters: jp_row - [IN] JSON with history data row *
+ * hk - [OUT] the host,key pair *
+ * *
+ * Return value: SUCCEED - the host,key pair was parsed successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int parse_history_data_row_hostkey(const struct zbx_json_parse *jp_row, zbx_host_key_t *hk)
+{
+ size_t str_alloc;
+
+ str_alloc = 0;
+ zbx_free(hk->host);
+
+ if (SUCCEED != zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_HOST, &hk->host, &str_alloc, NULL))
+ return FAIL;
+
+ str_alloc = 0;
+ zbx_free(hk->key);
+
+ if (SUCCEED != zbx_json_value_by_name_dyn(jp_row, ZBX_PROTO_TAG_KEY, &hk->key, &str_alloc, NULL))
+ {
+ zbx_free(hk->host);
+ return FAIL;
+ }
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parses up to ZBX_HISTORY_VALUES_MAX item values and host,key *
+ * pairs from history data json *
+ * *
+ * Parameters: jp_data - [IN] JSON with history data array *
+ * pnext - [IN/OUT] the pointer to the next item in json, *
+ * NULL - no more data left *
+ * values - [OUT] the item values *
+ * hostkeys - [OUT] the corresponding host,key pairs *
+ * values_num - [OUT] number of elements in values and hostkeys *
+ * arrays *
+ * parsed_num - [OUT] the number of values parsed *
+ * unique_shift - [IN/OUT] auto increment nanoseconds to ensure *
+ * unique value of timestamps *
+ * *
+ * Return value: SUCCEED - values were parsed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+static int parse_history_data(struct zbx_json_parse *jp_data, const char **pnext, zbx_agent_value_t *values,
+ zbx_host_key_t *hostkeys, int *values_num, int *parsed_num, zbx_timespec_t *unique_shift)
+{
+ struct zbx_json_parse jp_row;
+ int ret = FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ *values_num = 0;
+ *parsed_num = 0;
+
+ if (NULL == *pnext)
+ {
+ if (NULL == (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX)
+ {
+ ret = SUCCEED;
+ goto out;
+ }
+ }
+
+ /* iterate the history data rows */
+ do
+ {
+ if (FAIL == zbx_json_brackets_open(*pnext, &jp_row))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s", zbx_json_strerror());
+ goto out;
+ }
+
+ (*parsed_num)++;
+
+ if (SUCCEED != parse_history_data_row_hostkey(&jp_row, &hostkeys[*values_num]))
+ continue;
+
+ if (SUCCEED != parse_history_data_row_value(&jp_row, unique_shift, &values[*values_num]))
+ continue;
+
+ (*values_num)++;
+ }
+ while (NULL != (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX);
+
+ ret = SUCCEED;
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s processed:%d/%d", __func__, zbx_result_string(ret),
+ *values_num, *parsed_num);
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parses up to ZBX_HISTORY_VALUES_MAX item values and item *
+ * identifiers from history data json *
+ * *
+ * Parameters: jp_data - [IN] JSON with history data array *
+ * pnext - [IN/OUT] the pointer to the next item in *
+ * json, NULL - no more data left *
+ * values - [OUT] the item values *
+ * itemids - [OUT] the corresponding item identifiers *
+ * values_num - [OUT] number of elements in values and itemids *
+ * arrays *
+ * parsed_num - [OUT] the number of values parsed *
+ * unique_shift - [IN/OUT] auto increment nanoseconds to ensure *
+ * unique value of timestamps *
+ * info - [OUT] address of a pointer to the info string *
+ * (should be freed by the caller) *
+ * *
+ * Return value: SUCCEED - values were parsed successfully *
+ * FAIL - an error occurred *
+ * *
+ * Comments: This function is used to parse the new proxy history data *
+ * protocol introduced in Zabbix v3.3. *
+ * *
+ ******************************************************************************/
+static int parse_history_data_by_itemids(struct zbx_json_parse *jp_data, const char **pnext,
+ zbx_agent_value_t *values, zbx_uint64_t *itemids, int *values_num, int *parsed_num,
+ zbx_timespec_t *unique_shift, char **error)
+{
+ struct zbx_json_parse jp_row;
+ int ret = FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ *values_num = 0;
+ *parsed_num = 0;
+
+ if (NULL == *pnext)
+ {
+ if (NULL == (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX)
+ {
+ ret = SUCCEED;
+ goto out;
+ }
+ }
+
+ /* iterate the history data rows */
+ do
+ {
+ if (FAIL == zbx_json_brackets_open(*pnext, &jp_row))
+ {
+ *error = zbx_strdup(*error, zbx_json_strerror());
+ goto out;
+ }
+
+ (*parsed_num)++;
+
+ if (SUCCEED != parse_history_data_row_itemid(&jp_row, &itemids[*values_num]))
+ continue;
+
+ if (SUCCEED != parse_history_data_row_value(&jp_row, unique_shift, &values[*values_num]))
+ continue;
+
+ (*values_num)++;
+ }
+ while (NULL != (*pnext = zbx_json_next(jp_data, *pnext)) && *values_num < ZBX_HISTORY_VALUES_MAX);
+
+ ret = SUCCEED;
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s processed:%d/%d", __func__, zbx_result_string(ret),
+ *values_num, *parsed_num);
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: validates item received from proxy *
+ * *
+ * Parameters: item - [IN/OUT] the item data *
+ * sock - [IN] the connection socket *
+ * args - [IN] the validator arguments *
+ * error - unused *
+ * *
+ * Return value: SUCCEED - the validation was successful *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int proxy_item_validator(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error)
+{
+ zbx_uint64_t *proxyid = (zbx_uint64_t *)args;
+
+ ZBX_UNUSED(sock);
+ ZBX_UNUSED(error);
+
+ /* don't process item if its host was assigned to another proxy */
+ if (item->host.proxy_hostid != *proxyid)
+ return FAIL;
+
+ /* don't process aggregate/calculated items coming from proxy */
+ if (ITEM_TYPE_CALCULATED == item->type)
+ return FAIL;
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parses history data array and process the data *
+ * *
+ * *
+ * Parameters: sock - [IN] socket for host permission validation *
+ * validator_func - [IN] function to validate item permission *
+ * validator_args - [IN] validator function arguments *
+ * jp_data - [IN] JSON with history data array *
+ * session - [IN] the data session *
+ * nodata_win - [OUT] counter of delayed values *
+ * info - [OUT] address of a pointer to the info *
+ * string (should be freed by the caller) *
+ * mode - [IN] item retrieve mode is used to retrieve *
+ * only necessary data to reduce time *
+ * spent holding read lock *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ * Comments: This function is used to parse the new proxy history data *
+ * protocol introduced in Zabbix v3.3. *
+ * *
+ ******************************************************************************/
+static int process_history_data_by_itemids(zbx_socket_t *sock, zbx_client_item_validator_t validator_func,
+ void *validator_args, struct zbx_json_parse *jp_data, zbx_session_t *session,
+ zbx_proxy_suppress_t *nodata_win, char **info, unsigned int mode)
+{
+ const char *pnext = NULL;
+ int ret = SUCCEED, processed_num = 0, total_num = 0, values_num, read_num, i, *errcodes;
+ double sec;
+ DC_ITEM *items;
+ char *error = NULL;
+ zbx_uint64_t itemids[ZBX_HISTORY_VALUES_MAX], last_valueid = 0;
+ zbx_agent_value_t values[ZBX_HISTORY_VALUES_MAX];
+ zbx_timespec_t unique_shift = {0, 0};
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ items = (DC_ITEM *)zbx_malloc(NULL, sizeof(DC_ITEM) * ZBX_HISTORY_VALUES_MAX);
+ errcodes = (int *)zbx_malloc(NULL, sizeof(int) * ZBX_HISTORY_VALUES_MAX);
+
+ sec = zbx_time();
+
+ while (SUCCEED == parse_history_data_by_itemids(jp_data, &pnext, values, itemids, &values_num, &read_num,
+ &unique_shift, &error) && 0 != values_num)
+ {
+ DCconfig_get_items_by_itemids_partial(items, itemids, errcodes, values_num, mode);
+
+ for (i = 0; i < values_num; i++)
+ {
+ if (SUCCEED != errcodes[i])
+ continue;
+
+ /* check and discard if duplicate data */
+ if (NULL != session && 0 != values[i].id && values[i].id <= session->last_id)
+ {
+ DCconfig_clean_items(&items[i], &errcodes[i], 1);
+ errcodes[i] = FAIL;
+ continue;
+ }
+
+ if (SUCCEED != validator_func(&items[i], sock, validator_args, &error))
+ {
+ if (NULL != error)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s", error);
+ zbx_free(error);
+ }
+
+ DCconfig_clean_items(&items[i], &errcodes[i], 1);
+ errcodes[i] = FAIL;
+ }
+ }
+
+ processed_num += process_history_data(items, values, errcodes, values_num, nodata_win);
+
+ total_num += read_num;
+
+ last_valueid = values[values_num - 1].id;
+
+ DCconfig_clean_items(items, errcodes, values_num);
+ zbx_agent_values_clean(values, values_num);
+
+ if (NULL == pnext)
+ break;
+ }
+
+ if (NULL != session && 0 != last_valueid)
+ {
+ if (session->last_id > last_valueid)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "received id:" ZBX_FS_UI64 " is less than last id:"
+ ZBX_FS_UI64, last_valueid, session->last_id);
+ }
+ else
+ session->last_id = last_valueid;
+ }
+
+ zbx_free(errcodes);
+ zbx_free(items);
+
+ if (NULL == error)
+ {
+ ret = SUCCEED;
+ *info = zbx_dsprintf(*info, "processed: %d; failed: %d; total: %d; seconds spent: " ZBX_FS_DBL,
+ processed_num, total_num - processed_num, total_num, zbx_time() - sec);
+ }
+ else
+ {
+ zbx_free(*info);
+ *info = error;
+ }
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: validates item received from active agent *
+ * *
+ * Parameters: item - [IN] the item data *
+ * sock - [IN] the connection socket *
+ * args - [IN] the validator arguments *
+ * error - [OUT] the error message *
+ * *
+ * Return value: SUCCEED - the validation was successful *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int agent_item_validator(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error)
+{
+ zbx_host_rights_t *rights = (zbx_host_rights_t *)args;
+
+ if (0 != item->host.proxy_hostid)
+ return FAIL;
+
+ if (ITEM_TYPE_ZABBIX_ACTIVE != item->type)
+ return FAIL;
+
+ if (rights->hostid != item->host.hostid)
+ {
+ rights->hostid = item->host.hostid;
+ rights->value = zbx_host_check_permissions(&item->host, sock, error);
+ }
+
+ return rights->value;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: validates item received from sender *
+ * *
+ * Parameters: item - [IN] the item data *
+ * sock - [IN] the connection socket *
+ * args - [IN] the validator arguments *
+ * error - [OUT] the error message *
+ * *
+ * Return value: SUCCEED - the validation was successful *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int sender_item_validator(DC_ITEM *item, zbx_socket_t *sock, void *args, char **error)
+{
+ zbx_host_rights_t *rights;
+ char key_short[VALUE_ERRMSG_MAX * ZBX_MAX_BYTES_IN_UTF8_CHAR + 1];
+
+ if (0 != item->host.proxy_hostid)
+ return FAIL;
+
+ switch(item->type)
+ {
+ case ITEM_TYPE_HTTPAGENT:
+ if (0 == item->allow_traps)
+ {
+ *error = zbx_dsprintf(*error, "cannot process HTTP agent item \"%s\" trap:"
+ " trapping is not enabled", zbx_truncate_itemkey(item->key_orig,
+ VALUE_ERRMSG_MAX, key_short, sizeof(key_short)));
+ return FAIL;
+ }
+ break;
+ case ITEM_TYPE_TRAPPER:
+ break;
+ default:
+ *error = zbx_dsprintf(*error, "cannot process item \"%s\" trap:"
+ " item type \"%d\" cannot be used with traps",
+ zbx_truncate_itemkey(item->key_orig, VALUE_ERRMSG_MAX, key_short,
+ sizeof(key_short)), item->type);
+ return FAIL;
+ }
+
+ if ('\0' != *item->trapper_hosts) /* list of allowed hosts not empty */
+ {
+ char *allowed_peers;
+ int ret;
+
+ allowed_peers = zbx_strdup(NULL, item->trapper_hosts);
+ zbx_substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, item, NULL, NULL, NULL, NULL, NULL,
+ &allowed_peers, MACRO_TYPE_ALLOWED_HOSTS, NULL, 0);
+ ret = zbx_tcp_check_allowed_peers(sock, allowed_peers);
+ zbx_free(allowed_peers);
+
+ if (FAIL == ret)
+ {
+ *error = zbx_dsprintf(*error, "cannot process item \"%s\" trap: %s",
+ zbx_truncate_itemkey(item->key_orig, VALUE_ERRMSG_MAX, key_short,
+ sizeof(key_short)), zbx_socket_strerror());
+ return FAIL;
+ }
+ }
+
+ rights = (zbx_host_rights_t *)args;
+
+ if (rights->hostid != item->host.hostid)
+ {
+ rights->hostid = item->host.hostid;
+ rights->value = zbx_host_check_permissions(&item->host, sock, error);
+ }
+
+ return rights->value;
+}
+
+static void process_history_data_by_keys(zbx_socket_t *sock, zbx_client_item_validator_t validator_func,
+ void *validator_args, char **info, struct zbx_json_parse *jp_data, const char *token)
+{
+ int values_num, read_num, processed_num = 0, total_num = 0, i;
+ zbx_timespec_t unique_shift = {0, 0};
+ const char *pnext = NULL;
+ char *error = NULL;
+ zbx_host_key_t *hostkeys;
+ DC_ITEM *items;
+ zbx_session_t *session = NULL;
+ zbx_uint64_t last_hostid = 0;
+ zbx_agent_value_t values[ZBX_HISTORY_VALUES_MAX];
+ int errcodes[ZBX_HISTORY_VALUES_MAX];
+ double sec;
+
+ sec = zbx_time();
+
+ items = (DC_ITEM *)zbx_malloc(NULL, sizeof(DC_ITEM) * ZBX_HISTORY_VALUES_MAX);
+ hostkeys = (zbx_host_key_t *)zbx_malloc(NULL, sizeof(zbx_host_key_t) * ZBX_HISTORY_VALUES_MAX);
+ memset(hostkeys, 0, sizeof(zbx_host_key_t) * ZBX_HISTORY_VALUES_MAX);
+
+ while (SUCCEED == parse_history_data(jp_data, &pnext, values, hostkeys, &values_num, &read_num,
+ &unique_shift) && 0 != values_num)
+ {
+ DCconfig_get_items_by_keys(items, hostkeys, errcodes, values_num);
+
+ for (i = 0; i < values_num; i++)
+ {
+ if (SUCCEED != errcodes[i])
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "cannot retrieve key \"%s\" on host \"%s\" from "
+ "configuration cache", hostkeys[i].key, hostkeys[i].host);
+ continue;
+ }
+
+ if (last_hostid != items[i].host.hostid)
+ {
+ last_hostid = items[i].host.hostid;
+
+ if (NULL != token)
+ {
+ session = zbx_dc_get_or_create_session(last_hostid, token,
+ ZBX_SESSION_TYPE_DATA);
+ }
+ }
+
+ /* check and discard if duplicate data */
+ if (NULL != session && 0 != values[i].id && values[i].id <= session->last_id)
+ {
+ DCconfig_clean_items(&items[i], &errcodes[i], 1);
+ errcodes[i] = FAIL;
+ continue;
+ }
+
+ if (SUCCEED != validator_func(&items[i], sock, validator_args, &error))
+ {
+ if (NULL != error)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s", error);
+ zbx_free(error);
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "unknown validation error for item \"%s\"",
+ (NULL == items[i].key) ? items[i].key_orig : items[i].key);
+ }
+
+ DCconfig_clean_items(&items[i], &errcodes[i], 1);
+ errcodes[i] = FAIL;
+ }
+
+ if (NULL != session)
+ session->last_id = values[i].id;
+ }
+
+ processed_num += process_history_data(items, values, errcodes, values_num, NULL);
+ total_num += read_num;
+
+ DCconfig_clean_items(items, errcodes, values_num);
+ zbx_agent_values_clean(values, values_num);
+
+ if (NULL == pnext)
+ break;
+ }
+
+ for (i = 0; i < ZBX_HISTORY_VALUES_MAX; i++)
+ {
+ zbx_free(hostkeys[i].host);
+ zbx_free(hostkeys[i].key);
+ }
+
+ zbx_free(hostkeys);
+ zbx_free(items);
+
+ *info = zbx_dsprintf(*info, "processed: %d; failed: %d; total: %d; seconds spent: " ZBX_FS_DBL,
+ processed_num, total_num - processed_num, total_num, zbx_time() - sec);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process history data sent by proxy/agent/sender *
+ * *
+ * Parameters: sock - [IN] the connection socket *
+ * jp - [IN] JSON with historical data *
+ * ts - [IN] the client connection timestamp *
+ * validator_func - [IN] the item validator callback function *
+ * validator_args - [IN] the user arguments passed to validator *
+ * function *
+ * info - [OUT] address of a pointer to the info string *
+ * (should be freed by the caller) *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+static int process_client_history_data(zbx_socket_t *sock, struct zbx_json_parse *jp, zbx_timespec_t *ts,
+ zbx_client_item_validator_t validator_func, void *validator_args, char **info)
+{
+ int ret;
+ char *token = NULL;
+ size_t token_alloc = 0;
+ struct zbx_json_parse jp_data;
+ char tmp[MAX_STRING_LEN];
+ int version;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ log_client_timediff(LOG_LEVEL_DEBUG, jp, ts);
+
+ if (SUCCEED != (ret = zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_DATA, &jp_data)))
+ {
+ *info = zbx_strdup(*info, zbx_json_strerror());
+ goto out;
+ }
+
+ if (SUCCEED == zbx_json_value_by_name_dyn(jp, ZBX_PROTO_TAG_SESSION, &token, &token_alloc, NULL))
+ {
+ size_t token_len;
+
+ if (ZBX_SESSION_TOKEN_SIZE != (token_len = strlen(token)))
+ {
+ *info = zbx_dsprintf(*info, "invalid session token length %d", (int)token_len);
+ ret = FAIL;
+ goto out;
+ }
+ }
+
+ if (SUCCEED != zbx_json_value_by_name(jp, ZBX_PROTO_TAG_VERSION, tmp, sizeof(tmp), NULL) ||
+ FAIL == (version = zbx_get_component_version_without_patch(tmp)))
+ {
+ version = ZBX_COMPONENT_VERSION(4, 2, 0);
+ }
+
+ if (ZBX_COMPONENT_VERSION(4, 4, 0) <= version &&
+ SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, tmp, sizeof(tmp), NULL))
+ {
+ zbx_session_t *session;
+ zbx_uint64_t hostid;
+
+ if (SUCCEED != DCconfig_get_hostid_by_name(tmp, &hostid))
+ {
+ *info = zbx_dsprintf(*info, "unknown host '%s'", tmp);
+ ret = SUCCEED;
+ goto out;
+ }
+
+ if (NULL == token)
+ session = NULL;
+ else
+ session = zbx_dc_get_or_create_session(hostid, token, ZBX_SESSION_TYPE_DATA);
+
+ if (SUCCEED != (ret = process_history_data_by_itemids(sock, validator_func, validator_args, &jp_data,
+ session, NULL, info, ZBX_ITEM_GET_DEFAULT)))
+ {
+ goto out;
+ }
+ }
+ else
+ process_history_data_by_keys(sock, validator_func, validator_args, info, &jp_data, token);
+out:
+ zbx_free(token);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process history data received from Zabbix active agent *
+ * *
+ * Parameters: sock - [IN] the connection socket *
+ * jp - [IN] the JSON with history data *
+ * ts - [IN] the connection timestamp *
+ * info - [OUT] address of a pointer to the info string *
+ * (should be freed by the caller) *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+int process_agent_history_data(zbx_socket_t *sock, struct zbx_json_parse *jp, zbx_timespec_t *ts, char **info)
+{
+ zbx_host_rights_t rights = {0};
+
+ return process_client_history_data(sock, jp, ts, agent_item_validator, &rights, info);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process history data received from Zabbix sender *
+ * *
+ * Parameters: sock - [IN] the connection socket *
+ * jp - [IN] the JSON with history data *
+ * ts - [IN] the connection timestamp *
+ * info - [OUT] address of a pointer to the info string *
+ * (should be freed by the caller) *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+int process_sender_history_data(zbx_socket_t *sock, struct zbx_json_parse *jp, zbx_timespec_t *ts, char **info)
+{
+ zbx_host_rights_t rights = {0};
+ int ret;
+ zbx_dc_um_handle_t *um_handle;
+
+ um_handle = zbx_dc_open_user_macros();
+
+ ret = process_client_history_data(sock, jp, ts, sender_item_validator, &rights, info);
+
+ zbx_dc_close_user_macros(um_handle);
+
+ return ret;
+}
+
+static void zbx_drule_ip_free(zbx_drule_ip_t *ip)
+{
+ zbx_vector_ptr_clear_ext(&ip->services, zbx_ptr_free);
+ zbx_vector_ptr_destroy(&ip->services);
+ zbx_free(ip);
+}
+
+static void zbx_drule_free(zbx_drule_t *drule)
+{
+ zbx_vector_ptr_clear_ext(&drule->ips, (zbx_clean_func_t)zbx_drule_ip_free);
+ zbx_vector_ptr_destroy(&drule->ips);
+ zbx_vector_uint64_destroy(&drule->dcheckids);
+ zbx_free(drule);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process services discovered on IP address *
+ * *
+ * Parameters: drule_ptr - [IN] discovery rule structure *
+ * ip_discovered_ptr - [IN] vector of ip addresses *
+ * *
+ ******************************************************************************/
+static int process_services(const zbx_vector_ptr_t *services, const char *ip, zbx_uint64_t druleid,
+ zbx_vector_uint64_t *dcheckids, zbx_uint64_t unique_dcheckid, int *processed_num, int ip_idx)
+{
+ ZBX_DB_DHOST dhost;
+ zbx_service_t *service;
+ int services_num, ret = FAIL, i, dchecks = 0;
+ zbx_vector_ptr_t services_old;
+ ZBX_DB_DRULE drule = {.druleid = druleid, .unique_dcheckid = unique_dcheckid};
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ memset(&dhost, 0, sizeof(dhost));
+
+ zbx_vector_ptr_create(&services_old);
+
+ /* find host update */
+ for (i = *processed_num; i < services->values_num; i++)
+ {
+ service = (zbx_service_t *)services->values[i];
+
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() druleid:" ZBX_FS_UI64 " dcheckid:" ZBX_FS_UI64 " unique_dcheckid:"
+ ZBX_FS_UI64 " time:'%s %s' ip:'%s' dns:'%s' port:%hu status:%d value:'%s'",
+ __func__, drule.druleid, service->dcheckid, drule.unique_dcheckid,
+ zbx_date2str(service->itemtime, NULL), zbx_time2str(service->itemtime, NULL), ip, service->dns,
+ service->port, service->status, service->value);
+
+ if (0 == service->dcheckid)
+ break;
+
+ dchecks++;
+ }
+
+ /* stop processing current discovery rule and save proxy history until host update is available */
+ if (i == services->values_num)
+ {
+ for (i = *processed_num; i < services->values_num; i++)
+ {
+ char *ip_esc, *dns_esc, *value_esc;
+
+ service = (zbx_service_t *)services->values[i];
+
+ ip_esc = DBdyn_escape_field("proxy_dhistory", "ip", ip);
+ dns_esc = DBdyn_escape_field("proxy_dhistory", "dns", service->dns);
+ value_esc = DBdyn_escape_field("proxy_dhistory", "value", service->value);
+
+ DBexecute("insert into proxy_dhistory (clock,druleid,ip,port,value,status,dcheckid,dns)"
+ " values (%d," ZBX_FS_UI64 ",'%s',%d,'%s',%d," ZBX_FS_UI64 ",'%s')",
+ (int)service->itemtime, drule.druleid, ip_esc, service->port,
+ value_esc, service->status, service->dcheckid, dns_esc);
+ zbx_free(value_esc);
+ zbx_free(dns_esc);
+ zbx_free(ip_esc);
+ }
+
+ goto fail;
+ }
+
+ services_num = i;
+
+ if (0 == *processed_num && 0 == ip_idx)
+ {
+ DB_RESULT result;
+ DB_ROW row;
+ zbx_uint64_t dcheckid;
+
+ result = DBselect(
+ "select dcheckid,clock,port,value,status,dns,ip"
+ " from proxy_dhistory"
+ " where druleid=" ZBX_FS_UI64
+ " order by id",
+ drule.druleid);
+
+ for (i = 0; NULL != (row = DBfetch(result)); i++)
+ {
+ if (SUCCEED == DBis_null(row[0]))
+ continue;
+
+ ZBX_STR2UINT64(dcheckid, row[0]);
+
+ if (0 == strcmp(ip, row[6]))
+ {
+ service = (zbx_service_t *)zbx_malloc(NULL, sizeof(zbx_service_t));
+ service->dcheckid = dcheckid;
+ service->itemtime = (time_t)atoi(row[1]);
+ service->port = atoi(row[2]);
+ zbx_strlcpy_utf8(service->value, row[3], ZBX_MAX_DISCOVERED_VALUE_SIZE);
+ service->status = atoi(row[4]);
+ zbx_strlcpy(service->dns, row[5], ZBX_INTERFACE_DNS_LEN_MAX);
+ zbx_vector_ptr_append(&services_old, service);
+ zbx_vector_uint64_append(dcheckids, service->dcheckid);
+ dchecks++;
+ }
+ }
+ DBfree_result(result);
+
+ if (0 != i)
+ {
+ DBexecute("delete from proxy_dhistory"
+ " where druleid=" ZBX_FS_UI64,
+ drule.druleid);
+ }
+
+ zbx_vector_uint64_sort(dcheckids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
+ zbx_vector_uint64_uniq(dcheckids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
+
+ if (SUCCEED != DBlock_druleid(drule.druleid))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "druleid:" ZBX_FS_UI64 " does not exist", drule.druleid);
+ goto fail;
+ }
+
+ if (SUCCEED != DBlock_ids("dchecks", "dcheckid", dcheckids))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "checks are not available for druleid:" ZBX_FS_UI64, drule.druleid);
+ goto fail;
+ }
+ }
+
+ if (0 == dchecks)
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "cannot process host update without services");
+ goto fail;
+ }
+
+ for (i = 0; i < services_old.values_num; i++)
+ {
+ service = (zbx_service_t *)services_old.values[i];
+
+ if (FAIL == zbx_vector_uint64_bsearch(dcheckids, service->dcheckid, ZBX_DEFAULT_UINT64_COMPARE_FUNC))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "dcheckid:" ZBX_FS_UI64 " does not exist", service->dcheckid);
+ continue;
+ }
+
+ zbx_discovery_update_service(&drule, service->dcheckid, &dhost, ip, service->dns, service->port,
+ service->status, service->value, service->itemtime);
+ }
+
+ for (;*processed_num < services_num; (*processed_num)++)
+ {
+ service = (zbx_service_t *)services->values[*processed_num];
+
+ if (FAIL == zbx_vector_uint64_bsearch(dcheckids, service->dcheckid, ZBX_DEFAULT_UINT64_COMPARE_FUNC))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "dcheckid:" ZBX_FS_UI64 " does not exist", service->dcheckid);
+ continue;
+ }
+
+ zbx_discovery_update_service(&drule, service->dcheckid, &dhost, ip, service->dns, service->port,
+ service->status, service->value, service->itemtime);
+ }
+
+ service = (zbx_service_t *)services->values[(*processed_num)++];
+ zbx_discovery_update_host(&dhost, service->status, service->itemtime);
+
+ ret = SUCCEED;
+fail:
+ zbx_vector_ptr_clear_ext(&services_old, zbx_ptr_free);
+ zbx_vector_ptr_destroy(&services_old);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parse discovery data contents and process it *
+ * *
+ * Parameters: jp_data - [IN] JSON with discovery data *
+ * error - [OUT] address of a pointer to the info *
+ * string (should be freed by the caller) *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+static int process_discovery_data_contents(struct zbx_json_parse *jp_data, char **error)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ zbx_uint64_t dcheckid, druleid;
+ struct zbx_json_parse jp_row;
+ int status, ret = SUCCEED, i, j;
+ unsigned short port;
+ const char *p = NULL;
+ char ip[ZBX_INTERFACE_IP_LEN_MAX], tmp[MAX_STRING_LEN],
+ dns[ZBX_INTERFACE_DNS_LEN_MAX], *value = NULL;
+ time_t itemtime;
+ size_t value_alloc = ZBX_MAX_DISCOVERED_VALUE_SIZE;
+ zbx_vector_ptr_t drules;
+ zbx_drule_t *drule;
+ zbx_drule_ip_t *drule_ip;
+ zbx_service_t *service;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ value = (char *)zbx_malloc(value, value_alloc);
+
+ zbx_vector_ptr_create(&drules);
+
+ while (NULL != (p = zbx_json_next(jp_data, p)))
+ {
+ if (FAIL == zbx_json_brackets_open(p, &jp_row))
+ goto json_parse_error;
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp), NULL))
+ goto json_parse_error;
+
+ itemtime = atoi(tmp);
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DRULE, tmp, sizeof(tmp), NULL))
+ goto json_parse_error;
+
+ ZBX_STR2UINT64(druleid, tmp);
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DCHECK, tmp, sizeof(tmp), NULL))
+ goto json_parse_error;
+
+ if ('\0' != *tmp)
+ ZBX_STR2UINT64(dcheckid, tmp);
+ else
+ dcheckid = 0;
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_IP, ip, sizeof(ip), NULL))
+ goto json_parse_error;
+
+ if (SUCCEED != zbx_is_ip(ip))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid IP address", __func__, ip);
+ continue;
+ }
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_PORT, tmp, sizeof(tmp), NULL))
+ {
+ port = 0;
+ }
+ else if (FAIL == zbx_is_ushort(tmp, &port))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid port", __func__, tmp);
+ continue;
+ }
+
+ if (SUCCEED != zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_VALUE, &value, &value_alloc, NULL))
+ *value = '\0';
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DNS, dns, sizeof(dns), NULL))
+ {
+ *dns = '\0';
+ }
+ else if ('\0' != *dns && FAIL == zbx_validate_hostname(dns))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid hostname", __func__, dns);
+ continue;
+ }
+
+ if (SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_STATUS, tmp, sizeof(tmp), NULL))
+ status = atoi(tmp);
+ else
+ status = 0;
+
+ if (FAIL == (i = zbx_vector_ptr_search(&drules, &druleid, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC)))
+ {
+ drule = (zbx_drule_t *)zbx_malloc(NULL, sizeof(zbx_drule_t));
+ drule->druleid = druleid;
+ zbx_vector_ptr_create(&drule->ips);
+ zbx_vector_uint64_create(&drule->dcheckids);
+ zbx_vector_ptr_append(&drules, drule);
+ }
+ else
+ drule = drules.values[i];
+
+ if (FAIL == (i = zbx_vector_ptr_search(&drule->ips, ip, ZBX_DEFAULT_STR_COMPARE_FUNC)))
+ {
+ drule_ip = (zbx_drule_ip_t *)zbx_malloc(NULL, sizeof(zbx_drule_ip_t));
+ zbx_strlcpy(drule_ip->ip, ip, ZBX_INTERFACE_IP_LEN_MAX);
+ zbx_vector_ptr_create(&drule_ip->services);
+ zbx_vector_ptr_append(&drule->ips, drule_ip);
+ }
+ else
+ drule_ip = drule->ips.values[i];
+
+ service = (zbx_service_t *)zbx_malloc(NULL, sizeof(zbx_service_t));
+ if (0 != (service->dcheckid = dcheckid))
+ zbx_vector_uint64_append(&drule->dcheckids, service->dcheckid);
+ service->port = port;
+ service->status = status;
+ zbx_strlcpy_utf8(service->value, value, ZBX_MAX_DISCOVERED_VALUE_SIZE);
+ zbx_strlcpy(service->dns, dns, ZBX_INTERFACE_DNS_LEN_MAX);
+ service->itemtime = itemtime;
+ zbx_vector_ptr_append(&drule_ip->services, service);
+
+ continue;
+json_parse_error:
+ *error = zbx_strdup(*error, zbx_json_strerror());
+ ret = FAIL;
+ goto json_parse_return;
+ }
+
+ for (i = 0; i < drules.values_num; i++)
+ {
+ zbx_uint64_t unique_dcheckid;
+ int ret2 = SUCCEED;
+
+ drule = (zbx_drule_t *)drules.values[i];
+
+ DBbegin();
+ result = DBselect(
+ "select dcheckid"
+ " from dchecks"
+ " where druleid=" ZBX_FS_UI64
+ " and uniq=1",
+ drule->druleid);
+
+ if (NULL != (row = DBfetch(result)))
+ ZBX_STR2UINT64(unique_dcheckid, row[0]);
+ else
+ unique_dcheckid = 0;
+ DBfree_result(result);
+ for (j = 0; j < drule->ips.values_num && SUCCEED == ret2; j++)
+ {
+ int processed_num = 0;
+
+ drule_ip = (zbx_drule_ip_t *)drule->ips.values[j];
+
+ while (processed_num != drule_ip->services.values_num)
+ {
+ if (FAIL == (ret2 = process_services(&drule_ip->services, drule_ip->ip, drule->druleid,
+ &drule->dcheckids, unique_dcheckid, &processed_num, j)))
+ {
+ break;
+ }
+ }
+ }
+
+ zbx_process_events(NULL, NULL);
+ zbx_clean_events();
+ DBcommit();
+ }
+json_parse_return:
+ zbx_free(value);
+
+ zbx_vector_ptr_clear_ext(&drules, (zbx_clean_func_t)zbx_drule_free);
+ zbx_vector_ptr_destroy(&drules);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parse autoregistration data contents and process it *
+ * *
+ * Parameters: jp_data - [IN] JSON with autoregistration data *
+ * proxy_hostid - [IN] proxy identifier from database *
+ * error - [OUT] address of a pointer to the info *
+ * string (should be freed by the caller) *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+static int process_autoregistration_contents(struct zbx_json_parse *jp_data, zbx_uint64_t proxy_hostid,
+ char **error)
+{
+ struct zbx_json_parse jp_row;
+ int ret = SUCCEED;
+ const char *p = NULL;
+ time_t itemtime;
+ char host[ZBX_HOSTNAME_BUF_LEN], ip[ZBX_INTERFACE_IP_LEN_MAX],
+ dns[ZBX_INTERFACE_DNS_LEN_MAX], tmp[MAX_STRING_LEN], *host_metadata = NULL;
+ unsigned short port;
+ size_t host_metadata_alloc = 1; /* for at least NUL-terminating string */
+ zbx_vector_ptr_t autoreg_hosts;
+ zbx_conn_flags_t flags = ZBX_CONN_DEFAULT;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ if (0 == DCget_auto_registration_action_count())
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "cannot process auto registration contents, all autoregistration actions"
+ " are disabled");
+ goto out;
+ }
+
+ zbx_vector_ptr_create(&autoreg_hosts);
+ host_metadata = (char *)zbx_malloc(host_metadata, host_metadata_alloc);
+
+ while (NULL != (p = zbx_json_next(jp_data, p)))
+ {
+ unsigned int connection_type;
+
+ if (FAIL == (ret = zbx_json_brackets_open(p, &jp_row)))
+ break;
+
+ if (FAIL == (ret = zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp), NULL)))
+ break;
+
+ itemtime = atoi(tmp);
+
+ if (FAIL == (ret = zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_HOST, host, sizeof(host), NULL)))
+ break;
+
+ if (FAIL == zbx_check_hostname(host, NULL))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid Zabbix host name", __func__, host);
+ continue;
+ }
+
+ if (FAIL == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_HOST_METADATA,
+ &host_metadata, &host_metadata_alloc, NULL))
+ {
+ *host_metadata = '\0';
+ }
+
+ if (FAIL != zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_FLAGS, tmp, sizeof(tmp), NULL))
+ {
+ int flags_int;
+
+ flags_int = atoi(tmp);
+
+ switch (flags_int)
+ {
+ case ZBX_CONN_DEFAULT:
+ case ZBX_CONN_IP:
+ case ZBX_CONN_DNS:
+ flags = (zbx_conn_flags_t)flags_int;
+ break;
+ default:
+ flags = ZBX_CONN_DEFAULT;
+ zabbix_log(LOG_LEVEL_WARNING, "wrong flags value: %d for host \"%s\":",
+ flags_int, host);
+ }
+ }
+
+ if (FAIL == (ret = zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_IP, ip, sizeof(ip), NULL)))
+ {
+ if (ZBX_CONN_DNS == flags)
+ {
+ *ip = '\0';
+ ret = SUCCEED;
+ }
+ else
+ break;
+ }
+ else if (SUCCEED != zbx_is_ip(ip))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid IP address", __func__, ip);
+ continue;
+ }
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_DNS, dns, sizeof(dns), NULL))
+ {
+ *dns = '\0';
+ }
+ else if ('\0' != *dns && FAIL == zbx_validate_hostname(dns))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid hostname", __func__, dns);
+ continue;
+ }
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_PORT, tmp, sizeof(tmp), NULL))
+ {
+ port = ZBX_DEFAULT_AGENT_PORT;
+ }
+ else if (FAIL == zbx_is_ushort(tmp, &port))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid port", __func__, tmp);
+ continue;
+ }
+
+ if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_TLS_ACCEPTED, tmp, sizeof(tmp), NULL))
+ {
+ connection_type = ZBX_TCP_SEC_UNENCRYPTED;
+ }
+ else if (FAIL == zbx_is_uint32(tmp, &connection_type) || (ZBX_TCP_SEC_UNENCRYPTED != connection_type &&
+ ZBX_TCP_SEC_TLS_PSK != connection_type && ZBX_TCP_SEC_TLS_CERT != connection_type))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s(): \"%s\" is not a valid value for \""
+ ZBX_PROTO_TAG_TLS_ACCEPTED "\"", __func__, tmp);
+ continue;
+ }
+
+ DBregister_host_prepare(&autoreg_hosts, host, ip, dns, port, connection_type, host_metadata, flags,
+ itemtime);
+ }
+
+ if (0 != autoreg_hosts.values_num)
+ {
+ DBbegin();
+ DBregister_host_flush(&autoreg_hosts, proxy_hostid);
+ DBcommit();
+ DCconfig_delete_autoreg_host(&autoreg_hosts);
+ }
+
+ zbx_free(host_metadata);
+ DBregister_host_clean(&autoreg_hosts);
+ zbx_vector_ptr_destroy(&autoreg_hosts);
+
+ if (SUCCEED != ret)
+ *error = zbx_strdup(*error, zbx_json_strerror());
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: get the number of values waiting to be sent to the server *
+ * *
+ * Return value: the number of history values *
+ * *
+ ******************************************************************************/
+int proxy_get_history_count(void)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ zbx_uint64_t id;
+ int count = 0;
+
+ DBconnect(ZBX_DB_CONNECT_NORMAL);
+
+ proxy_get_lastid("proxy_history", "history_lastid", &id);
+
+ result = DBselect(
+ "select count(*)"
+ " from proxy_history"
+ " where id>" ZBX_FS_UI64,
+ id);
+
+ if (NULL != (row = DBfetch(result)))
+ count = atoi(row[0]);
+
+ DBfree_result(result);
+
+ DBclose();
+
+ return count;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parse tasks contents and saves the received tasks *
+ * *
+ * Parameters: jp_tasks - [IN] JSON with tasks data *
+ * *
+ ******************************************************************************/
+static void process_tasks_contents(struct zbx_json_parse *jp_tasks)
+{
+ zbx_vector_ptr_t tasks;
+
+ zbx_vector_ptr_create(&tasks);
+
+ zbx_tm_json_deserialize_tasks(jp_tasks, &tasks);
+
+ DBbegin();
+ zbx_tm_save_tasks(&tasks);
+ DBcommit();
+
+ zbx_vector_ptr_clear_ext(&tasks, (zbx_clean_func_t)zbx_tm_task_free);
+ zbx_vector_ptr_destroy(&tasks);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: appends text to the string on a new line *
+ * *
+ ******************************************************************************/
+static void zbx_strcatnl_alloc(char **info, size_t *info_alloc, size_t *info_offset, const char *text)
+{
+ if (0 != *info_offset)
+ zbx_chrcpy_alloc(info, info_alloc, info_offset, '\n');
+
+ zbx_strcpy_alloc(info, info_alloc, info_offset, text);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: detect lost connection with proxy and calculate suppression *
+ * window if possible *
+ * *
+ * Parameters: ts - [IN] timestamp when the proxy connection was *
+ * established *
+ * proxy_staus - [IN] - active or passive proxy *
+ * diff - [IN/OUT] the properties to update *
+ * *
+ ******************************************************************************/
+static void check_proxy_nodata(zbx_timespec_t *ts, unsigned char proxy_status, zbx_proxy_diff_t *diff)
+{
+ int delay;
+
+ if (0 != (diff->nodata_win.flags & ZBX_PROXY_SUPPRESS_ACTIVE))
+ {
+ diff->nodata_win.values_num = 0; /* reset counter of new suppress values received from proxy */
+ return; /* only for current packet */
+ }
+
+ delay = ts->sec - diff->lastaccess;
+
+ if ((HOST_STATUS_PROXY_PASSIVE == proxy_status &&
+ (2 * CONFIG_PROXYDATA_FREQUENCY) < delay && NET_DELAY_MAX < delay) ||
+ (HOST_STATUS_PROXY_ACTIVE == proxy_status && NET_DELAY_MAX < delay))
+ {
+ diff->nodata_win.values_num = 0;
+ diff->nodata_win.period_end = ts->sec;
+ diff->flags |= ZBX_FLAGS_PROXY_DIFF_UPDATE_SUPPRESS_WIN;
+ diff->nodata_win.flags |= ZBX_PROXY_SUPPRESS_ENABLE;
+ }
+}
+
+/******************************************************************************
+ * *
+ * Purpose: detect lack of data during lost connectivity *
+ * *
+ * Parameters: ts - [IN] timestamp when the proxy connection was *
+ * established *
+ * proxy_staus - [IN] - active or passive proxy *
+ * diff - [IN/OUT] the properties to update *
+ * *
+ ******************************************************************************/
+static void check_proxy_nodata_empty(zbx_timespec_t *ts, unsigned char proxy_status, zbx_proxy_diff_t *diff)
+{
+ int delay_empty;
+
+ if (0 != (diff->nodata_win.flags & ZBX_PROXY_SUPPRESS_EMPTY) && 0 != diff->nodata_win.values_num)
+ diff->nodata_win.flags &= (~ZBX_PROXY_SUPPRESS_EMPTY);
+
+ if (0 == (diff->nodata_win.flags & ZBX_PROXY_SUPPRESS_EMPTY) || 0 != diff->nodata_win.values_num)
+ return;
+
+ delay_empty = ts->sec - diff->nodata_win.period_end;
+
+ if (HOST_STATUS_PROXY_PASSIVE == proxy_status ||
+ (HOST_STATUS_PROXY_ACTIVE == proxy_status && NET_DELAY_MAX < delay_empty))
+ {
+ diff->nodata_win.period_end = 0;
+ diff->nodata_win.flags = ZBX_PROXY_SUPPRESS_DISABLE;
+ }
+}
+
+/******************************************************************************
+ * *
+ * Purpose: process 'proxy data' request *
+ * *
+ * Parameters: proxy - [IN] the source proxy *
+ * jp - [IN] JSON with proxy data *
+ * proxy_hostid - [IN] proxy identifier from database *
+ * ts - [IN] timestamp when the proxy connection was *
+ * established *
+ * proxy_status - [IN] active or passive proxy mode *
+ * more - [OUT] available data flag *
+ * error - [OUT] address of a pointer to the info string *
+ * (should be freed by the caller) *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occurred *
+ * *
+ ******************************************************************************/
+int process_proxy_data(const DC_PROXY *proxy, struct zbx_json_parse *jp, zbx_timespec_t *ts,
+ unsigned char proxy_status, int *more, char **error)
+{
+ struct zbx_json_parse jp_data;
+ int ret = SUCCEED, flags_old;
+ char *error_step = NULL, value[MAX_STRING_LEN];
+ size_t error_alloc = 0, error_offset = 0;
+ zbx_proxy_diff_t proxy_diff;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ proxy_diff.flags = ZBX_FLAGS_PROXY_DIFF_UNSET;
+ proxy_diff.hostid = proxy->hostid;
+
+ if (SUCCEED != (ret = DCget_proxy_nodata_win(proxy_diff.hostid, &proxy_diff.nodata_win,
+ &proxy_diff.lastaccess)))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "cannot get proxy communication delay");
+ ret = FAIL;
+ goto out;
+ }
+
+ if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_MORE, value, sizeof(value), NULL))
+ proxy_diff.more_data = atoi(value);
+ else
+ proxy_diff.more_data = ZBX_PROXY_DATA_DONE;
+
+ if (NULL != more)
+ *more = proxy_diff.more_data;
+
+ if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_PROXY_DELAY, value, sizeof(value), NULL))
+ proxy_diff.proxy_delay = atoi(value);
+ else
+ proxy_diff.proxy_delay = 0;
+
+ proxy_diff.flags |= ZBX_FLAGS_PROXY_DIFF_UPDATE_PROXYDELAY;
+ flags_old = proxy_diff.nodata_win.flags;
+ check_proxy_nodata(ts, proxy_status, &proxy_diff); /* first packet can be empty for active proxy */
+
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() flag_win:%d/%d flag:%d proxy_status:%d period_end:%d delay:%d"
+ " timestamp:%d lastaccess:%d proxy_delay:%d more:%d", __func__, proxy_diff.nodata_win.flags,
+ flags_old, (int)proxy_diff.flags, proxy_status, proxy_diff.nodata_win.period_end,
+ ts->sec - proxy_diff.lastaccess, ts->sec, proxy_diff.lastaccess, proxy_diff.proxy_delay,
+ proxy_diff.more_data);
+
+ if (ZBX_FLAGS_PROXY_DIFF_UNSET != proxy_diff.flags)
+ zbx_dc_update_proxy(&proxy_diff);
+
+ if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_INTERFACE_AVAILABILITY, &jp_data))
+ {
+ if (SUCCEED != (ret = process_interfaces_availability_contents(&jp_data, &error_step)))
+ zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
+ }
+
+ flags_old = proxy_diff.nodata_win.flags;
+
+ if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_HISTORY_DATA, &jp_data))
+ {
+ zbx_session_t *session = NULL;
+
+ if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_SESSION, value, sizeof(value), NULL))
+ {
+ size_t token_len;
+
+ if (ZBX_SESSION_TOKEN_SIZE != (token_len = strlen(value)))
+ {
+ *error = zbx_dsprintf(*error, "invalid session token length %d", (int)token_len);
+ ret = FAIL;
+ goto out;
+ }
+
+ session = zbx_dc_get_or_create_session(proxy->hostid, value, ZBX_SESSION_TYPE_DATA);
+ }
+
+ if (SUCCEED != (ret = process_history_data_by_itemids(NULL, proxy_item_validator,
+ (void *)&proxy->hostid, &jp_data, session, &proxy_diff.nodata_win, &error_step,
+ ZBX_ITEM_GET_PROCESS)))
+ {
+ zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
+ }
+ }
+
+ if (0 != (proxy_diff.nodata_win.flags & ZBX_PROXY_SUPPRESS_ACTIVE))
+ {
+ check_proxy_nodata_empty(ts, proxy_status, &proxy_diff);
+
+ if (0 < proxy_diff.nodata_win.values_num || flags_old != proxy_diff.nodata_win.flags)
+ proxy_diff.flags |= ZBX_FLAGS_PROXY_DIFF_UPDATE_SUPPRESS_WIN;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "Result of %s() flag_win:%d/%d flag:%d values_num:%d",
+ __func__, proxy_diff.nodata_win.flags, flags_old, (int)proxy_diff.flags,
+ proxy_diff.nodata_win.values_num);
+ }
+
+ if (ZBX_FLAGS_PROXY_DIFF_UNSET != proxy_diff.flags)
+ zbx_dc_update_proxy(&proxy_diff);
+
+ if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_DISCOVERY_DATA, &jp_data))
+ {
+ if (SUCCEED != (ret = process_discovery_data_contents(&jp_data, &error_step)))
+ zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
+ }
+
+ if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_AUTOREGISTRATION, &jp_data))
+ {
+ if (SUCCEED != (ret = process_autoregistration_contents(&jp_data, proxy->hostid, &error_step)))
+ zbx_strcatnl_alloc(error, &error_alloc, &error_offset, error_step);
+ }
+
+ if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_TASKS, &jp_data))
+ process_tasks_contents(&jp_data);
+
+ if (SUCCEED == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_PROXY_ACTIVE_AVAIL_DATA, &jp_data))
+ {
+ const char *ptr;
+ zbx_vector_proxy_hostdata_ptr_t host_avails;
+ struct zbx_json_parse jp_host;
+ char buffer[ZBX_KIBIBYTE];
+
+ zbx_vector_proxy_hostdata_ptr_create(&host_avails);
+
+ for (ptr = NULL; NULL != (ptr = zbx_json_next(&jp_data, ptr));)
+ {
+ zbx_proxy_hostdata_t *host;
+
+ if (SUCCEED != zbx_json_brackets_open(ptr, &jp_host))
+ continue;
+
+ if (SUCCEED == zbx_json_value_by_name(&jp_host, ZBX_PROTO_TAG_HOSTID, buffer, sizeof(buffer), NULL))
+ {
+ host = (zbx_proxy_hostdata_t *)zbx_malloc(NULL, sizeof(zbx_proxy_hostdata_t));
+ host->hostid = atoi(buffer);
+ }
+ else
+ continue;
+
+ if (FAIL == zbx_json_value_by_name(&jp_host, ZBX_PROTO_TAG_ACTIVE_STATUS, buffer, sizeof(buffer), NULL))
+ {
+ zbx_free(host);
+ continue;
+ }
+
+ host->status = atoi(buffer);
+
+ zbx_vector_proxy_hostdata_ptr_append(&host_avails, host);
+ }
+
+ if (0 != host_avails.values_num)
+ {
+ unsigned char *data = NULL;
+ zbx_uint32_t data_len;
+ DC_HOST *hosts;
+ int i, *errcodes;
+ zbx_vector_uint64_t hostids;
+ zbx_vector_proxy_hostdata_ptr_t proxy_host_avails;
+
+ zbx_vector_uint64_create(&hostids);
+
+ for (i = 0; i < host_avails.values_num; i++)
+ zbx_vector_uint64_append(&hostids, host_avails.values[i]->hostid);
+
+ hosts = (DC_HOST *)zbx_malloc(NULL, sizeof(DC_HOST) * host_avails.values_num);
+ errcodes = (int *)zbx_malloc(NULL, sizeof(int) * host_avails.values_num);
+ DCconfig_get_hosts_by_hostids(hosts, hostids.values, errcodes, hostids.values_num);
+
+ zbx_vector_uint64_destroy(&hostids);
+
+ zbx_vector_proxy_hostdata_ptr_create(&proxy_host_avails);
+
+ for (i = 0; i < host_avails.values_num; i++)
+ {
+ if (SUCCEED == errcodes[i] && hosts[i].proxy_hostid == proxy->hostid)
+ zbx_vector_proxy_hostdata_ptr_append(&proxy_host_avails, host_avails.values[i]);
+ }
+
+ zbx_free(errcodes);
+ zbx_free(hosts);
+
+ data_len = zbx_availability_serialize_proxy_hostdata(&data, &proxy_host_avails, proxy->hostid);
+ zbx_availability_send(ZBX_IPC_AVAILMAN_PROCESS_PROXY_HOSTDATA, data, data_len, NULL);
+
+ zbx_vector_proxy_hostdata_ptr_destroy(&proxy_host_avails);
+ zbx_vector_proxy_hostdata_ptr_clear_ext(&host_avails, (zbx_proxy_hostdata_ptr_free_func_t)zbx_ptr_free);
+ zbx_free(data);
+ }
+
+ zbx_vector_proxy_hostdata_ptr_destroy(&host_avails);
+ }
+
+out:
+ zbx_free(error_step);
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: flushes lastaccess changes for proxies every *
+ * ZBX_PROXY_LASTACCESS_UPDATE_FREQUENCY seconds *
+ * *
+ ******************************************************************************/
+static void zbx_db_flush_proxy_lastaccess(void)
+{
+ zbx_vector_uint64_pair_t lastaccess;
+
+ zbx_vector_uint64_pair_create(&lastaccess);
+
+ zbx_dc_get_proxy_lastaccess(&lastaccess);
+
+ if (0 != lastaccess.values_num)
+ {
+ char *sql;
+ size_t sql_alloc = 256, sql_offset = 0;
+ int i;
+
+ sql = (char *)zbx_malloc(NULL, sql_alloc);
+
+ DBbegin();
+ zbx_DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset);
+
+ for (i = 0; i < lastaccess.values_num; i++)
+ {
+ zbx_uint64_pair_t *pair = &lastaccess.values[i];
+
+ zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update host_rtdata"
+ " set lastaccess=%d"
+ " where hostid=" ZBX_FS_UI64 ";\n",
+ (int)pair->second, pair->first);
+
+ DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset);
+ }
+
+ zbx_DBend_multiple_update(&sql, &sql_alloc, &sql_offset);
+
+ if (16 < sql_offset) /* in ORACLE always present begin..end; */
+ DBexecute("%s", sql);
+
+ DBcommit();
+
+ zbx_free(sql);
+ }
+
+ zbx_vector_uint64_pair_destroy(&lastaccess);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: updates proxy version and compatibility with server in database *
+ * *
+ * Parameters: proxy - [IN] the proxy to update version for *
+ * diff - [IN] indicates changes to the proxy *
+ * *
+ ******************************************************************************/
+static void db_update_proxy_version(DC_PROXY *proxy, zbx_proxy_diff_t *diff)
+{
+ if (0 != (diff->flags & ZBX_FLAGS_PROXY_DIFF_UPDATE_VERSION))
+ {
+ if (0 != proxy->version_int)
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "proxy \"%s\" protocol version updated from %u.%u to %u.%u",
+ proxy->host,
+ ZBX_COMPONENT_VERSION_MAJOR(proxy->version_int),
+ ZBX_COMPONENT_VERSION_MINOR(proxy->version_int),
+ ZBX_COMPONENT_VERSION_MAJOR(diff->version_int),
+ ZBX_COMPONENT_VERSION_MINOR(diff->version_int));
+ }
+
+ if (ZBX_DB_OK > DBexecute(
+ "update host_rtdata"
+ " set version=%u,compatibility=%u"
+ " where hostid=" ZBX_FS_UI64,
+ ZBX_COMPONENT_VERSION_TO_DEC_FORMAT(diff->version_int), diff->compatibility,
+ diff->hostid))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Failed to update proxy version and compatibility with server for"
+ " proxy '%s'.", proxy->host);
+ }
+ }
+}
+
+/******************************************************************************
+ * *
+ * Purpose: gets proxy version compatibility with server version *
+ * *
+ * Parameters: proxy_version - [IN] proxy_version *
+ * *
+ * Return value: proxy version compatibility with server version *
+ * *
+ ******************************************************************************/
+static zbx_proxy_compatibility_t zbx_get_proxy_compatibility(int proxy_version)
+{
+#define SERVER_VERSION ZBX_COMPONENT_VERSION(ZABBIX_VERSION_MAJOR, ZABBIX_VERSION_MINOR, 0)
+
+ if (0 == proxy_version)
+ return ZBX_PROXY_VERSION_UNDEFINED;
+
+ proxy_version = ZBX_COMPONENT_VERSION_WITHOUT_PATCH(proxy_version);
+
+ if (SERVER_VERSION == proxy_version)
+ return ZBX_PROXY_VERSION_CURRENT;
+
+ if (SERVER_VERSION < proxy_version)
+ return ZBX_PROXY_VERSION_UNSUPPORTED;
+#if (ZABBIX_VERSION_MINOR == 0)
+ if (ZABBIX_VERSION_MAJOR == 1 + ZBX_COMPONENT_VERSION_MAJOR(proxy_version))
+ return ZBX_PROXY_VERSION_STATUS_OUTDATED;
+#elif (ZABBIX_VERSION_MINOR > 0)
+ if (ZABBIX_VERSION_MAJOR == ZBX_COMPONENT_VERSION_MAJOR(proxy_version))
+ return ZBX_PROXY_VERSION_OUTDATED;
+#endif
+ return ZBX_PROXY_VERSION_UNSUPPORTED;
+
+#undef SERVER_VERSION
+}
+
+/******************************************************************************
+ * *
+ * Purpose: updates proxy runtime properties in cache and database. *
+ * *
+ * Parameters: proxy - [IN/OUT] the proxy *
+ * version_str - [IN] the proxy version as string *
+ * version_int - [IN] the proxy version in numeric representation *
+ * lastaccess - [IN] the last proxy access time *
+ * compress - [IN] 1 if proxy is using data compression, *
+ * 0 otherwise *
+ * flags_add - [IN] additional flags for update proxy *
+ * *
+ * Comments: The proxy parameter properties are also updated. *
+ * *
+ ******************************************************************************/
+void zbx_update_proxy_data(DC_PROXY *proxy, char *version_str, int version_int, int lastaccess, int compress,
+ zbx_uint64_t flags_add)
+{
+ zbx_proxy_diff_t diff;
+ zbx_proxy_compatibility_t compatibility;
+
+ compatibility = zbx_get_proxy_compatibility(version_int);
+
+ diff.hostid = proxy->hostid;
+ diff.flags = ZBX_FLAGS_PROXY_DIFF_UPDATE | flags_add;
+ diff.version_str = version_str;
+ diff.version_int = version_int;
+ diff.compatibility = compatibility;
+ diff.lastaccess = lastaccess;
+ diff.compress = compress;
+
+ zbx_dc_update_proxy(&diff);
+
+ db_update_proxy_version(proxy, &diff);
+
+ zbx_strlcpy(proxy->version_str, version_str, sizeof(proxy->version_str));
+ proxy->version_int = version_int;
+ proxy->compatibility = compatibility;
+ proxy->auto_compress = compress;
+ proxy->lastaccess = lastaccess;
+
+ if (0 != (diff.flags & ZBX_FLAGS_PROXY_DIFF_UPDATE_COMPRESS))
+ DBexecute("update hosts set auto_compress=%d where hostid=" ZBX_FS_UI64, diff.compress, diff.hostid);
+
+ zbx_db_flush_proxy_lastaccess();
+}
+/******************************************************************************
+ * *
+ * Purpose: flushes last_version_error_time changes runtime *
+ * variable for proxies structures *
+ * *
+ ******************************************************************************/
+static void zbx_update_proxy_lasterror(DC_PROXY *proxy)
+{
+ zbx_proxy_diff_t diff;
+
+ diff.hostid = proxy->hostid;
+ diff.flags = ZBX_FLAGS_PROXY_DIFF_UPDATE_LASTERROR;
+ diff.lastaccess = time(NULL);
+ diff.last_version_error_time = proxy->last_version_error_time;
+
+ zbx_dc_update_proxy(&diff);
+}
+/******************************************************************************
+ * *
+ * Purpose: check server and proxy versions and compatibility rules *
+ * *
+ * Parameters: *
+ * proxy - [IN] the source proxy *
+ * version - [IN] the version of proxy *
+ * *
+ * Return value: *
+ * SUCCEED - no compatibility issue *
+ * FAIL - compatibility check fault *
+ * *
+ ******************************************************************************/
+int zbx_check_protocol_version(DC_PROXY *proxy, int version)
+{
+ zbx_proxy_compatibility_t compatibility;
+
+ compatibility = zbx_get_proxy_compatibility(version);
+
+ /* warn if another proxy version is used and proceed with compatibility rules*/
+ if (ZBX_PROXY_VERSION_CURRENT != compatibility)
+ {
+ int now = zbx_time(), print_log = 0;
+
+ if (proxy->last_version_error_time <= now)
+ {
+ print_log = 1;
+ proxy->last_version_error_time = now + 5 * SEC_PER_MIN;
+ zbx_update_proxy_lasterror(proxy);
+ }
+
+ if (ZBX_PROXY_VERSION_UNSUPPORTED == compatibility)
+ {
+ if (1 == print_log)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Proxy \"%s\" version %u.%u.%u is not supported by server"
+ " version %d.%d.%d.", proxy->host,
+ ZBX_COMPONENT_VERSION_MAJOR(version),
+ ZBX_COMPONENT_VERSION_MINOR(version),
+ ZBX_COMPONENT_VERSION_PATCH(version), ZABBIX_VERSION_MAJOR,
+ ZABBIX_VERSION_MINOR, ZABBIX_VERSION_PATCH);
+ }
+ return FAIL;
+ }
+ else if (ZBX_PROXY_VERSION_OUTDATED == compatibility && 1 == print_log)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Proxy \"%s\" version %u.%u.%u is outdated, only data collection"
+ " and remote execution is available with server version %d.%d.%d.", proxy->host,
+ ZBX_COMPONENT_VERSION_MAJOR(version), ZBX_COMPONENT_VERSION_MINOR(version),
+ ZBX_COMPONENT_VERSION_PATCH(version), ZABBIX_VERSION_MAJOR,
+ ZABBIX_VERSION_MINOR, ZABBIX_VERSION_PATCH);
+ }
+ else if (ZBX_PROXY_VERSION_UNDEFINED == compatibility)
+ return FAIL;
+ }
+
+ return SUCCEED;
+}
+
diff --git a/src/libs/zbxdbhigh/template.h b/src/libs/zbxdbwrap/template.h
index 9e879474143..9e879474143 100644
--- a/src/libs/zbxdbhigh/template.h
+++ b/src/libs/zbxdbwrap/template.h
diff --git a/src/libs/zbxdbhigh/template_item.c b/src/libs/zbxdbwrap/template_item.c
index 9500bb99dbb..9500bb99dbb 100644
--- a/src/libs/zbxdbhigh/template_item.c
+++ b/src/libs/zbxdbwrap/template_item.c
diff --git a/src/libs/zbxdbhigh/trigger_dep_linking.c b/src/libs/zbxdbwrap/trigger_dep_linking.c
index eeecce73a24..6bc847ed64b 100644
--- a/src/libs/zbxdbhigh/trigger_dep_linking.c
+++ b/src/libs/zbxdbwrap/trigger_dep_linking.c
@@ -18,7 +18,7 @@
**/
#include "trigger_dep_linking.h"
-#include "zbxdbhigh.h"
+#include "zbxdbwrap.h"
#include "log.h"
#include "audit/zbxaudit_trigger.h"
diff --git a/src/libs/zbxdbhigh/trigger_dep_linking.h b/src/libs/zbxdbwrap/trigger_dep_linking.h
index 1949f5fc4d7..1949f5fc4d7 100644
--- a/src/libs/zbxdbhigh/trigger_dep_linking.h
+++ b/src/libs/zbxdbwrap/trigger_dep_linking.h
diff --git a/src/libs/zbxdbhigh/trigger_linking.c b/src/libs/zbxdbwrap/trigger_linking.c
index 9f378e370a9..e5e0ab153d0 100644
--- a/src/libs/zbxdbhigh/trigger_linking.c
+++ b/src/libs/zbxdbwrap/trigger_linking.c
@@ -18,7 +18,7 @@
**/
#include "trigger_linking.h"
-#include "zbxdbhigh.h"
+#include "zbxdbwrap.h"
#include "trigger_dep_linking.h"
#include "zbxeval.h"
diff --git a/src/libs/zbxdbhigh/trigger_linking.h b/src/libs/zbxdbwrap/trigger_linking.h
index cad6cdde368..cad6cdde368 100644
--- a/src/libs/zbxdbhigh/trigger_linking.h
+++ b/src/libs/zbxdbwrap/trigger_linking.h
diff --git a/src/libs/zbxnix/dshm.c b/src/libs/zbxnix/dshm.c
index a7cd9624173..ede2b2c8d9d 100644
--- a/src/libs/zbxnix/dshm.c
+++ b/src/libs/zbxnix/dshm.c
@@ -22,8 +22,6 @@
#include "zbxcommon.h"
#include "log.h"
-extern char *CONFIG_FILE;
-
/******************************************************************************
* *
* Purpose: creates dynamic shared memory segment *
diff --git a/src/libs/zbxnum/num.c b/src/libs/zbxnum/num.c
index 9c06ffa138f..0ad81ad3315 100644
--- a/src/libs/zbxnum/num.c
+++ b/src/libs/zbxnum/num.c
@@ -294,7 +294,7 @@ int zbx_is_double(const char *str, double *value)
}
#if defined(_WINDOWS) || defined(__MINGW32__)
-int _wis_uint(const wchar_t *wide_string)
+int zbx_wis_uint(const wchar_t *wide_string)
{
const wchar_t *wide_char = wide_string;
diff --git a/src/libs/zbxrtc/rtc_client.c b/src/libs/zbxrtc/rtc_client.c
index 587c84947f9..ab9413d958a 100644
--- a/src/libs/zbxrtc/rtc_client.c
+++ b/src/libs/zbxrtc/rtc_client.c
@@ -26,6 +26,7 @@
#include "zbxjson.h"
#include "zbxself.h"
#include "log.h"
+#include "zbxthreads.h"
extern int CONFIG_TIMEOUT;
@@ -217,27 +218,28 @@ void zbx_rtc_subscribe(zbx_ipc_async_socket_t *rtc, unsigned char proc_type, int
* Purpose: wait for RTC notification *
* *
* Parameters: rtc - [IN] the RTC notification subscription socket *
+ * info - [IN] caller process info *
* cmd - [OUT] the RTC notification code *
* data - [OUT] the RTC notification data *
* timeout - [OUT] the timeout *
- * error - [OUT] error message *
* *
* Return value: SUCCEED - a notification was received or timeout occurred *
* FAIL - communication error *
* *
******************************************************************************/
-int zbx_rtc_wait(zbx_ipc_async_socket_t *rtc, zbx_uint32_t *cmd, unsigned char **data, int timeout)
+int zbx_rtc_wait(zbx_ipc_async_socket_t *rtc, const zbx_thread_info_t *info, zbx_uint32_t *cmd,
+ unsigned char **data, int timeout)
{
zbx_ipc_message_t *message;
int ret;
if (0 != timeout)
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_async_socket_recv(rtc, timeout, &message);
if (0 != timeout)
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (FAIL == ret)
return FAIL;
diff --git a/src/libs/zbxself/selfmon.c b/src/libs/zbxself/selfmon.c
index e3790981982..56b76dd267a 100644
--- a/src/libs/zbxself/selfmon.c
+++ b/src/libs/zbxself/selfmon.c
@@ -26,6 +26,8 @@
# include "zbxmutexs.h"
# include "zbxnix.h"
# include "log.h"
+# include "zbxtime.h"
+# include "zbxthreads.h"
# define MAX_HISTORY 60
@@ -124,8 +126,7 @@ extern int CONFIG_SERVICEMAN_FORKS;
extern int CONFIG_TRIGGERHOUSEKEEPER_FORKS;
extern int CONFIG_ODBCPOLLER_FORKS;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int process_num;
+extern unsigned char program_type;
/******************************************************************************
* *
@@ -311,20 +312,21 @@ void zbx_free_selfmon_collector(void)
/******************************************************************************
* *
- * Parameters: state - [IN] new process state; ZBX_PROCESS_STATE_* *
+ * Parameters: info - [IN] caller process info *
+ * state - [IN] new process state; ZBX_PROCESS_STATE_* *
* *
******************************************************************************/
-void zbx_update_selfmon_counter(unsigned char state)
+void zbx_update_selfmon_counter(const zbx_thread_info_t *info, unsigned char state)
{
zbx_stat_process_t *process;
clock_t ticks;
struct tms buf;
int i;
- if (ZBX_PROCESS_TYPE_UNKNOWN == process_type)
+ if (ZBX_PROCESS_TYPE_UNKNOWN == info->process_type)
return;
- process = &collector->process[process_type][process_num - 1];
+ process = &collector->process[info->process_type][info->process_num - 1];
if (-1 == (ticks = times(&buf)))
{
@@ -455,7 +457,7 @@ out:
* Purpose: calculate statistics for selected process *
* *
* Parameters: proc_type - [IN] type of process; ZBX_PROCESS_TYPE_* *
- * aggr_func - [IN] one of ZBX_AGGR_FUNC_* *
+ * aggr_func - [IN] one of ZBX_SELFMON_AGGR_FUNC_* *
* proc_num - [IN] process number; 1 - first process; *
* 0 - all processes *
* state - [IN] process state; ZBX_PROCESS_STATE_* *
@@ -476,13 +478,13 @@ void zbx_get_selfmon_stats(unsigned char proc_type, unsigned char aggr_func, int
switch (aggr_func)
{
- case ZBX_AGGR_FUNC_ONE:
+ case ZBX_SELFMON_AGGR_FUNC_ONE:
assert(0 < proc_num && proc_num <= process_forks);
process_forks = proc_num--;
break;
- case ZBX_AGGR_FUNC_AVG:
- case ZBX_AGGR_FUNC_MAX:
- case ZBX_AGGR_FUNC_MIN:
+ case ZBX_SELFMON_AGGR_FUNC_AVG:
+ case ZBX_SELFMON_AGGR_FUNC_MAX:
+ case ZBX_SELFMON_AGGR_FUNC_MIN:
assert(0 == proc_num && 0 < process_forks);
break;
default:
@@ -515,19 +517,19 @@ void zbx_get_selfmon_stats(unsigned char proc_type, unsigned char aggr_func, int
switch (aggr_func)
{
- case ZBX_AGGR_FUNC_ONE:
- case ZBX_AGGR_FUNC_AVG:
+ case ZBX_SELFMON_AGGR_FUNC_ONE:
+ case ZBX_SELFMON_AGGR_FUNC_AVG:
total += one_total;
counter += one_counter;
break;
- case ZBX_AGGR_FUNC_MAX:
+ case ZBX_SELFMON_AGGR_FUNC_MAX:
if (0 == proc_num || one_counter > counter)
{
counter = one_counter;
total = one_total;
}
break;
- case ZBX_AGGR_FUNC_MIN:
+ case ZBX_SELFMON_AGGR_FUNC_MIN:
if (0 == proc_num || one_counter < counter)
{
counter = one_counter;
@@ -650,17 +652,18 @@ static int sleep_remains;
* *
* Purpose: sleeping process *
* *
- * Parameters: sleeptime - [IN] required sleeptime, in seconds *
+ * Parameters: info - [IN] caller process info *
+ * sleeptime - [IN] required sleeptime, in seconds *
* *
******************************************************************************/
-void zbx_sleep_loop(int sleeptime)
+void zbx_sleep_loop(const zbx_thread_info_t *info, int sleeptime)
{
if (0 >= sleeptime)
return;
sleep_remains = sleeptime;
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
do
{
@@ -668,6 +671,41 @@ void zbx_sleep_loop(int sleeptime)
}
while (0 < --sleep_remains);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
+}
+
+ZBX_THREAD_ENTRY(zbx_selfmon_thread, args)
+{
+ zbx_thread_args_t *thread_args = (zbx_thread_args_t *)args;
+ const zbx_thread_info_t *info = &thread_args->info;
+ int process_num = info->process_num;
+ const char *program_type_str = get_program_type_string(program_type);
+ const char *process_type_str = get_process_type_string(info->process_type);
+
+ zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", program_type_str, info->server_num,
+ process_type_str, process_num);
+
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
+
+ while (ZBX_IS_RUNNING())
+ {
+ double sec = zbx_time();
+
+ zbx_update_env(sec);
+
+ zbx_setproctitle("%s [processing data]", process_type_str);
+
+ zbx_collect_selfmon_stats();
+ sec = zbx_time() - sec;
+
+ zbx_setproctitle("%s [processed data in " ZBX_FS_DBL " sec, idle 1 sec]", process_type_str, sec);
+
+ zbx_sleep_loop(info, ZBX_SELFMON_DELAY);
+ }
+
+ zbx_setproctitle("%s #%d [terminated]", process_type_str, process_num);
+
+ while (1)
+ zbx_sleep(SEC_PER_MIN);
}
#endif
diff --git a/src/libs/zbxsysinfo/agent/agent.c b/src/libs/zbxsysinfo/agent/agent.c
index cc04634700a..60f1483750c 100644
--- a/src/libs/zbxsysinfo/agent/agent.c
+++ b/src/libs/zbxsysinfo/agent/agent.c
@@ -26,25 +26,25 @@ extern ZBX_THREAD_LOCAL char *CONFIG_HOSTNAME;
extern char *CONFIG_HOST_METADATA;
extern char *CONFIG_HOST_METADATA_ITEM;
-static int AGENT_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result);
-static int AGENT_HOSTMETADATA(AGENT_REQUEST *request, AGENT_RESULT *result);
-static int AGENT_PING(AGENT_REQUEST *request, AGENT_RESULT *result);
-static int AGENT_VERSION(AGENT_REQUEST *request, AGENT_RESULT *result);
-static int AGENT_VARIANT(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int agent_hostname(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int agent_hostmetadata(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int agent_ping(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int agent_version(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int agent_variant(AGENT_REQUEST *request, AGENT_RESULT *result);
ZBX_METRIC parameters_agent[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"agent.hostname", 0, AGENT_HOSTNAME, NULL},
- {"agent.hostmetadata", 0, AGENT_HOSTMETADATA, NULL},
- {"agent.ping", 0, AGENT_PING, NULL},
- {"agent.variant", 0, AGENT_VARIANT, NULL},
- {"agent.version", 0, AGENT_VERSION, NULL},
- {"modbus.get", CF_HAVEPARAMS, MODBUS_GET, "tcp://127.0.0.1"},
+ {"agent.hostname", 0, agent_hostname, NULL},
+ {"agent.hostmetadata", 0, agent_hostmetadata, NULL},
+ {"agent.ping", 0, agent_ping, NULL},
+ {"agent.variant", 0, agent_variant, NULL},
+ {"agent.version", 0, agent_version, NULL},
+ {"modbus.get", CF_HAVEPARAMS, modbus_get, "tcp://127.0.0.1"},
{NULL}
};
-static int AGENT_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int agent_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ZBX_UNUSED(request);
@@ -62,7 +62,7 @@ static int AGENT_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int AGENT_HOSTMETADATA(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int agent_hostmetadata(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_OK;
@@ -88,7 +88,7 @@ static int AGENT_HOSTMETADATA(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-static int AGENT_PING(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int agent_ping(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ZBX_UNUSED(request);
@@ -97,7 +97,7 @@ static int AGENT_PING(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int AGENT_VERSION(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int agent_version(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ZBX_UNUSED(request);
@@ -106,7 +106,7 @@ static int AGENT_VERSION(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int AGENT_VARIANT(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int agent_variant(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ZBX_UNUSED(request);
diff --git a/src/libs/zbxsysinfo/agent/modbus.c b/src/libs/zbxsysinfo/agent/modbus.c
index cdd6d020ba2..cb44b4b96ff 100644
--- a/src/libs/zbxsysinfo/agent/modbus.c
+++ b/src/libs/zbxsysinfo/agent/modbus.c
@@ -607,7 +607,7 @@ out:
}
#endif /* HAVE_LIBMODBUS */
-int MODBUS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int modbus_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_LIBMODBUS
char *tmp, *err = NULL;
diff --git a/src/libs/zbxsysinfo/aix/aix.c b/src/libs/zbxsysinfo/aix/aix.c
index ee612691727..bfa13705573 100644
--- a/src/libs/zbxsysinfo/aix/aix.c
+++ b/src/libs/zbxsysinfo/aix/aix.c
@@ -18,43 +18,44 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/,free"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/,free"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"vfs.dev.read", CF_HAVEPARAMS, VFS_DEV_READ, "hdisk0,operations"},
- {"vfs.dev.write", CF_HAVEPARAMS, VFS_DEV_WRITE, "hdisk0,operations"},
+ {"vfs.dev.read", CF_HAVEPARAMS, vfs_dev_read, "hdisk0,operations"},
+ {"vfs.dev.write", CF_HAVEPARAMS, vfs_dev_write, "hdisk0,operations"},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "lo0,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "lo0,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "lo0,bytes"},
- {"net.if.collisions", CF_HAVEPARAMS, NET_IF_COLLISIONS, "lo0"},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, NULL},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "lo0,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "lo0,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "lo0,bytes"},
+ {"net.if.collisions", CF_HAVEPARAMS, net_if_collisions, "lo0"},
+ {"net.if.discovery", 0, net_if_discovery, NULL},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
- {"proc.mem", CF_HAVEPARAMS, PROC_MEM, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
+ {"proc.mem", CF_HAVEPARAMS, proc_mem, "inetd"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, NULL},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, NULL},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,user,avg1"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.switches", 0, system_cpu_switches, NULL},
+ {"system.cpu.intr", 0, system_cpu_intr, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,user,avg1"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
- {"system.stat", CF_HAVEPARAMS, SYSTEM_STAT, "page,fi"},
- {"system.swap.size", CF_HAVEPARAMS, SYSTEM_SWAP_SIZE, "all,free"},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"system.stat", CF_HAVEPARAMS, system_stat, "page,fi"},
+ {"system.swap.size", CF_HAVEPARAMS, system_swap_size, "all,free"},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/aix/cpu.c b/src/libs/zbxsysinfo/aix/cpu.c
index 940313474de..5383bb8ab91 100644
--- a/src/libs/zbxsysinfo/aix/cpu.c
+++ b/src/libs/zbxsysinfo/aix/cpu.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
#include "zbxnum.h"
@@ -25,7 +26,7 @@
#include <sys/dr.h>
#include "stats.h"
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_LIBPERFSTAT
char *tmp;
@@ -62,7 +63,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
#endif
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode, res;
@@ -140,7 +141,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_LIBPERFSTAT
#if !defined(SBITS)
@@ -209,7 +210,7 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
#endif
}
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_LIBPERFSTAT
perfstat_cpu_total_t ps_cpu_total;
@@ -234,7 +235,7 @@ int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
#endif
}
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ZBX_UNUSED(request);
#ifdef HAVE_LIBPERFSTAT
diff --git a/src/libs/zbxsysinfo/aix/diskio.c b/src/libs/zbxsysinfo/aix/diskio.c
index 387e1ecce51..cb58b6de495 100644
--- a/src/libs/zbxsysinfo/aix/diskio.c
+++ b/src/libs/zbxsysinfo/aix/diskio.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
#include "zbxstr.h"
@@ -89,7 +90,7 @@ static int get_perfstat_io(const char *devname, zbx_perfstat_t *zp, char **error
#endif
}
-static int VFS_DEV_READ_BYTES(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_read_bytes(const char *devname, AGENT_RESULT *result)
{
zbx_perfstat_t zp;
char *error;
@@ -105,7 +106,7 @@ static int VFS_DEV_READ_BYTES(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_READ_OPERATIONS(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_read_operations(const char *devname, AGENT_RESULT *result)
{
zbx_perfstat_t zp;
char *error;
@@ -121,7 +122,7 @@ static int VFS_DEV_READ_OPERATIONS(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_WRITE_BYTES(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_write_bytes(const char *devname, AGENT_RESULT *result)
{
zbx_perfstat_t zp;
char *error;
@@ -137,7 +138,7 @@ static int VFS_DEV_WRITE_BYTES(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_WRITE_OPERATIONS(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_write_operations(const char *devname, AGENT_RESULT *result)
{
zbx_perfstat_t zp;
char *error;
@@ -155,7 +156,7 @@ static int VFS_DEV_WRITE_OPERATIONS(const char *devname, AGENT_RESULT *result)
#define ZBX_DEV_PFX "/dev/"
-int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_read(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const char *devname, *type;
int ret;
@@ -176,9 +177,9 @@ int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
type = get_rparam(request, 1);
if (NULL == type || '\0' == *type || 0 == strcmp(type, "operations"))
- ret = VFS_DEV_READ_OPERATIONS(devname, result);
+ ret = vfs_dev_read_operations(devname, result);
else if (0 == strcmp(type, "bytes"))
- ret = VFS_DEV_READ_BYTES(devname, result);
+ ret = vfs_dev_read_bytes(devname, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
@@ -188,7 +189,7 @@ int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_write(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const char *devname, *type;
int ret;
@@ -209,9 +210,9 @@ int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
type = get_rparam(request, 1);
if (NULL == type || '\0' == *type || 0 == strcmp(type, "operations"))
- ret = VFS_DEV_WRITE_OPERATIONS(devname, result);
+ ret = vfs_dev_write_operations(devname, result);
else if (0 == strcmp(type, "bytes"))
- ret = VFS_DEV_WRITE_BYTES(devname, result);
+ ret = vfs_dev_write_bytes(devname, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
diff --git a/src/libs/zbxsysinfo/aix/diskspace.c b/src/libs/zbxsysinfo/aix/diskspace.c
index 64517ca45a1..f455a5d08e5 100644
--- a/src/libs/zbxsysinfo/aix/diskspace.c
+++ b/src/libs/zbxsysinfo/aix/diskspace.c
@@ -88,7 +88,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -104,7 +104,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -120,7 +120,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -136,7 +136,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -152,7 +152,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -168,7 +168,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -188,24 +188,24 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
static const char *zbx_get_vfs_name_by_type(int type)
@@ -234,7 +234,7 @@ static const char *zbx_get_vfs_name_by_type(int type)
return NULL != vfs_names[type] ? vfs_names[type] : "unknown";
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int rc, sz, i, ret = SYSINFO_RET_FAIL;
struct vmount *vms = NULL, *vm;
@@ -290,7 +290,7 @@ error:
return ret;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int rc, sz, i, ret = SYSINFO_RET_FAIL;
struct vmount *vms = NULL, *vm;
@@ -422,7 +422,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/aix/hostname.c b/src/libs/zbxsysinfo/aix/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/aix/hostname.c
+++ b/src/libs/zbxsysinfo/aix/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/aix/inodes.c b/src/libs/zbxsysinfo/aix/inodes.c
index 0b9ae8f4d73..46b4801e2bd 100644
--- a/src/libs/zbxsysinfo/aix/inodes.c
+++ b/src/libs/zbxsysinfo/aix/inodes.c
@@ -74,7 +74,7 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
#undef ZBX_FFREE
}
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -130,7 +130,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/aix/memory.c b/src/libs/zbxsysinfo/aix/memory.c
index b34ca838342..1e028712ca1 100644
--- a/src/libs/zbxsysinfo/aix/memory.c
+++ b/src/libs/zbxsysinfo/aix/memory.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -36,7 +37,7 @@ static perfstat_memory_total_t m;
return SYSINFO_RET_FAIL; \
}
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -46,7 +47,7 @@ static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PINNED(AGENT_RESULT *result)
+static int vm_memory_pinned(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -56,7 +57,7 @@ static int VM_MEMORY_PINNED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -66,7 +67,7 @@ static int VM_MEMORY_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -76,7 +77,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -91,7 +92,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -100,7 +101,7 @@ static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -115,7 +116,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_CACHED(AGENT_RESULT *result)
+static int vm_memory_cached(AGENT_RESULT *result)
{
ZBX_PERFSTAT_MEMORY_TOTAL();
@@ -126,7 +127,7 @@ static int VM_MEMORY_CACHED(AGENT_RESULT *result)
#endif
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_LIBPERFSTAT
int ret;
@@ -141,21 +142,21 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "pinned"))
- ret = VM_MEMORY_PINNED(result);
+ ret = vm_memory_pinned(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else if (0 == strcmp(mode, "cached"))
- ret = VM_MEMORY_CACHED(result);
+ ret = vm_memory_cached(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/aix/net.c b/src/libs/zbxsysinfo/aix/net.c
index e09a0c7ef24..d325f81b446 100644
--- a/src/libs/zbxsysinfo/aix/net.c
+++ b/src/libs/zbxsysinfo/aix/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxjson.h"
#include "log.h"
@@ -73,7 +74,7 @@ static int get_net_stat(const char *if_name, net_stat_t *ns, char **error)
#endif
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
net_stat_t ns;
@@ -108,7 +109,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
net_stat_t ns;
@@ -143,7 +144,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
net_stat_t ns;
@@ -178,7 +179,7 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *error;
net_stat_t ns;
@@ -202,7 +203,7 @@ int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if defined(HAVE_LIBPERFSTAT)
int rc, i, ret = SYSINFO_RET_FAIL;
diff --git a/src/libs/zbxsysinfo/aix/proc.c b/src/libs/zbxsysinfo/aix/proc.c
index fa8d43a96e8..b82ccfe993d 100644
--- a/src/libs/zbxsysinfo/aix/proc.c
+++ b/src/libs/zbxsysinfo/aix/proc.c
@@ -66,7 +66,7 @@ static int check_procargs(struct procentry64 *procentry, const char *proccomm)
return NULL != zbx_regexp_match(procargs, proccomm, NULL) ? SUCCEED : FAIL;
}
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define ZBX_VSIZE 0
#define ZBX_RSS 1
@@ -286,7 +286,7 @@ out:
#undef ZBX_TRSS
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *param, *procname, *proccomm;
struct passwd *usrinfo;
diff --git a/src/libs/zbxsysinfo/aix/software.c b/src/libs/zbxsysinfo/aix/software.c
index f1c84189cf3..bad121011ec 100644
--- a/src/libs/zbxsysinfo/aix/software.c
+++ b/src/libs/zbxsysinfo/aix/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/aix/swap.c b/src/libs/zbxsysinfo/aix/swap.c
index a8a4966225a..62e9baab508 100644
--- a/src/libs/zbxsysinfo/aix/swap.c
+++ b/src/libs/zbxsysinfo/aix/swap.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_LIBPERFSTAT
#define ZBX_PERFSTAT_PAGE_SHIFT 12 /* 4 KB */
diff --git a/src/libs/zbxsysinfo/aix/system.c b/src/libs/zbxsysinfo/aix/system.c
index 21ee95f65a8..ec13add9249 100644
--- a/src/libs/zbxsysinfo/aix/system.c
+++ b/src/libs/zbxsysinfo/aix/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/aix/uptime.c b/src/libs/zbxsysinfo/aix/uptime.c
index 2133ed86df5..9c46099d067 100644
--- a/src/libs/zbxsysinfo/aix/uptime.c
+++ b/src/libs/zbxsysinfo/aix/uptime.c
@@ -18,12 +18,13 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
static long hertz = 0;
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if defined(HAVE_LIBPERFSTAT)
perfstat_cpu_total_t ps_cpu_total;
diff --git a/src/libs/zbxsysinfo/aix/vmstats.c b/src/libs/zbxsysinfo/aix/vmstats.c
index 5f88231b3d4..18de482c2e4 100644
--- a/src/libs/zbxsysinfo/aix/vmstats.c
+++ b/src/libs/zbxsysinfo/aix/vmstats.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "stats.h"
-int SYSTEM_STAT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_stat(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *section, *type;
#define ZBX_MAX_WAIT_VMSTAT 2 /* maximum seconds to wait for vmstat data on the first call */
diff --git a/src/libs/zbxsysinfo/common/cpu.c b/src/libs/zbxsysinfo/common/cpu.c
index 17e9da62919..8d086131dec 100644
--- a/src/libs/zbxsysinfo/common/cpu.c
+++ b/src/libs/zbxsysinfo/common/cpu.c
@@ -39,7 +39,7 @@ static const char *get_cpu_status_string(int status)
return NULL;
}
-int SYSTEM_CPU_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_vector_uint64_pair_t cpus;
struct zbx_json json;
diff --git a/src/libs/zbxsysinfo/common/cpu.h b/src/libs/zbxsysinfo/common/cpu.h
index 2e44bfff609..53fadc0b075 100644
--- a/src/libs/zbxsysinfo/common/cpu.h
+++ b/src/libs/zbxsysinfo/common/cpu.h
@@ -22,6 +22,6 @@
#include "zbxsysinfo.h"
-int SYSTEM_CPU_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_COMMON_CPU_H */
diff --git a/src/libs/zbxsysinfo/common/dir.c b/src/libs/zbxsysinfo/common/dir.c
index 1aa33e2ed03..a207e627147 100644
--- a/src/libs/zbxsysinfo/common/dir.c
+++ b/src/libs/zbxsysinfo/common/dir.c
@@ -28,7 +28,7 @@
#include "log.h"
#if defined(_WINDOWS) || defined(__MINGW32__)
-# include "disk.h"
+# include "zbxwin32.h"
#endif
/******************************************************************************
@@ -512,7 +512,7 @@ static int link_processed(DWORD attrib, wchar_t *wpath, zbx_vector_ptr_t *descri
return FAIL;
}
-static int vfs_dir_size(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
+static int vfs_dir_size_local(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
{
char *dir = NULL;
int mode, max_depth, ret = SYSINFO_RET_FAIL;
@@ -590,7 +590,7 @@ static int vfs_dir_size(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE tim
goto err2;
}
- if (SIZE_MODE_DISK == mode && 0 == (cluster_size = get_cluster_size(item->path, &error)))
+ if (SIZE_MODE_DISK == mode && 0 == (cluster_size = zbx_get_cluster_size(item->path, &error)))
{
SET_MSG_RESULT(result, error);
list.values_num++;
@@ -689,7 +689,7 @@ err1:
return ret;
}
#else /* not _WINDOWS or __MINGW32__ */
-static int vfs_dir_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_dir_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *dir = NULL;
int mode, max_depth, ret = SYSINFO_RET_FAIL;
@@ -838,9 +838,9 @@ err1:
}
#endif
-int VFS_DIR_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dir_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_dir_size, request, result);
+ return zbx_execute_threaded_metric(vfs_dir_size_local, request, result);
}
#define EVALUATE_DIR_ENTITY() \
@@ -1050,12 +1050,12 @@ err1:
return ret;
}
-static int vfs_dir_count(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
+static int vfs_dir_count_local(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
{
return vfs_dir_info(request, result, timeout_event, 1);
}
-static int vfs_dir_get(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
+static int vfs_dir_get_local(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
{
return vfs_dir_info(request, result, timeout_event, 0);
}
@@ -1195,23 +1195,23 @@ err1:
return ret;
}
-static int vfs_dir_count(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_dir_count_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return vfs_dir_info(request, result, 1);
}
-static int vfs_dir_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_dir_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return vfs_dir_info(request, result, 0);
}
#endif
-int VFS_DIR_COUNT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dir_count(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_dir_count, request, result);
+ return zbx_execute_threaded_metric(vfs_dir_count_local, request, result);
}
-int VFS_DIR_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dir_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_dir_get, request, result);
+ return zbx_execute_threaded_metric(vfs_dir_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/common/dir.h b/src/libs/zbxsysinfo/common/dir.h
index 4edf8153565..ff2a9dcd27c 100644
--- a/src/libs/zbxsysinfo/common/dir.h
+++ b/src/libs/zbxsysinfo/common/dir.h
@@ -57,9 +57,9 @@ typedef struct
zbx_uint64_t st_ino; /* file serial number */
} zbx_file_descriptor_t;
-int VFS_DIR_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_DIR_COUNT(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_DIR_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dir_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dir_count(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dir_get(AGENT_REQUEST *request, AGENT_RESULT *result);
int zbx_etypes_to_mask(const char *etypes, AGENT_RESULT *result);
int zbx_vfs_file_info(const char *filename, struct zbx_json *j, int array, char **error);
diff --git a/src/libs/zbxsysinfo/common/dns.c b/src/libs/zbxsysinfo/common/dns.c
index 5877c074e0b..a35a0b05a6e 100644
--- a/src/libs/zbxsysinfo/common/dns.c
+++ b/src/libs/zbxsysinfo/common/dns.c
@@ -963,7 +963,7 @@ static int dns_query_is_tcp(AGENT_REQUEST *request)
return FAIL;
}
-int NET_DNS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_dns(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if !defined(_WINDOWS) && !defined(__MINGW32__)
if (SUCCEED == dns_query_is_tcp(request))
@@ -972,7 +972,7 @@ int NET_DNS(AGENT_REQUEST *request, AGENT_RESULT *result)
return dns_query_short(request, result);
}
-int NET_DNS_RECORD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_dns_record(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if !defined(_WINDOWS) && !defined(__MINGW32__)
if (SUCCEED == dns_query_is_tcp(request))
diff --git a/src/libs/zbxsysinfo/common/dns.h b/src/libs/zbxsysinfo/common/dns.h
index b61ee30d22a..805646200ed 100644
--- a/src/libs/zbxsysinfo/common/dns.h
+++ b/src/libs/zbxsysinfo/common/dns.h
@@ -90,7 +90,7 @@
#endif /* defined(HAVE_RES_QUERY) || defined(_WINDOWS) || defined(__MINGW32__) */
-int NET_DNS(AGENT_REQUEST *request, AGENT_RESULT *result);
-int NET_DNS_RECORD(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_dns(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_dns_record(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_COMMON_NET_H */
diff --git a/src/libs/zbxsysinfo/common/file.c b/src/libs/zbxsysinfo/common/file.c
index be8986bb441..d2ebda7831e 100644
--- a/src/libs/zbxsysinfo/common/file.c
+++ b/src/libs/zbxsysinfo/common/file.c
@@ -40,7 +40,7 @@
extern int CONFIG_TIMEOUT;
-int VFS_FILE_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_stat_t buf;
char *filename, *mode;
@@ -133,7 +133,7 @@ err:
return ret;
}
-int VFS_FILE_TIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_time(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_file_time_t file_time;
char *filename, *type;
@@ -178,7 +178,7 @@ err:
}
#if defined(_WINDOWS) || defined(__MINGW32__)
-static int vfs_file_exists(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_file_exists_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const char *filename;
int ret = SYSINFO_RET_FAIL, file_exists = 0, types, types_incl, types_excl;
@@ -270,7 +270,7 @@ err:
return ret;
}
#else /* not _WINDOWS or __MINGW32__ */
-static int vfs_file_exists(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_file_exists_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_stat_t buf;
const char *filename;
@@ -349,12 +349,12 @@ static int vfs_file_exists(AGENT_REQUEST *request, AGENT_RESULT *result)
}
#endif
-int VFS_FILE_EXISTS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_exists(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return vfs_file_exists(request, result);
+ return vfs_file_exists_local(request, result);
}
-int VFS_FILE_CONTENTS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_contents(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename, *tmp, encoding[32];
char read_buf[MAX_BUFFER_LEN], *utf8, *contents = NULL;
@@ -464,7 +464,7 @@ err:
return ret;
}
-int VFS_FILE_REGEXP(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_regexp(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename, *regexp, encoding[32], *output, *start_line_str, *end_line_str;
char buf[MAX_BUFFER_LEN], *utf8, *tmp, *ptr = NULL;
@@ -585,7 +585,7 @@ err:
return ret;
}
-int VFS_FILE_REGMATCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_regmatch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename, *regexp, *tmp, encoding[32];
char buf[MAX_BUFFER_LEN], *utf8, *start_line_str, *end_line_str;
@@ -760,7 +760,7 @@ err:
return ret;
}
-int VFS_FILE_MD5SUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_md5sum(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename;
@@ -967,7 +967,7 @@ err:
* Comments: computes POSIX 1003.2 checksum *
* *
******************************************************************************/
-int VFS_FILE_CKSUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_cksum(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename, *method;
int ret = SYSINFO_RET_FAIL;
@@ -1000,7 +1000,7 @@ err:
}
#if defined(_WINDOWS) || defined(__MINGW32__)
-int VFS_FILE_OWNER(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_owner(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename, *ownertype, *resulttype;
int ret = SYSINFO_RET_FAIL;
@@ -1100,7 +1100,7 @@ err:
return ret;
}
#else
-int VFS_FILE_OWNER(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_owner(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename, *ownertype, *resulttype;
int ret = SYSINFO_RET_FAIL, type;
@@ -1183,7 +1183,7 @@ err:
#endif
#if defined(_WINDOWS) || defined(__MINGW32__)
-int VFS_FILE_PERMISSIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_permissions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ZBX_UNUSED(request);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Item is not supported on Windows."));
@@ -1197,7 +1197,7 @@ static char *get_file_permissions(zbx_stat_t *st)
(S_IRWXU & st->st_mode) >> 6, (S_IRWXG & st->st_mode) >> 3, S_IRWXO & st->st_mode);
}
-int VFS_FILE_PERMISSIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_permissions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *filename;
int ret = SYSINFO_RET_FAIL;
@@ -1693,7 +1693,7 @@ err:
}
#endif
-static int vfs_file_get(const char *filename, AGENT_RESULT *result)
+static int vfs_file_get_local(const char *filename, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
char *error = NULL;
@@ -1720,7 +1720,7 @@ static int vfs_file_get(const char *filename, AGENT_RESULT *result)
#undef VFS_FILE_ADD_TIME
#undef VFS_FILE_ADD_TS
-int VFS_FILE_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_file_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const char *filename;
@@ -1738,5 +1738,5 @@ int VFS_FILE_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- return vfs_file_get(filename, result);
+ return vfs_file_get_local(filename, result);
}
diff --git a/src/libs/zbxsysinfo/common/file.h b/src/libs/zbxsysinfo/common/file.h
index c153dfd83d7..bf12e90d1c2 100644
--- a/src/libs/zbxsysinfo/common/file.h
+++ b/src/libs/zbxsysinfo/common/file.h
@@ -24,16 +24,16 @@
#define MAX_FILE_LEN (1024 * 1024)
-int VFS_FILE_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_TIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_EXISTS(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_CONTENTS(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_REGEXP(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_REGMATCH(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_MD5SUM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_CKSUM(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_OWNER(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_PERMISSIONS(AGENT_REQUEST *request, AGENT_RESULT *result);
-int VFS_FILE_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_time(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_exists(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_contents(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_regexp(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_regmatch(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_md5sum(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_cksum(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_owner(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_permissions(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_file_get(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_COMMON_FILE_H */
diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c
index a04b478ccfe..52ce41a0e51 100644
--- a/src/libs/zbxsysinfo/common/http.c
+++ b/src/libs/zbxsysinfo/common/http.c
@@ -429,7 +429,7 @@ out:
}
#endif
-int WEB_PAGE_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int web_page_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *hostname, *path_str, *port_str, *buffer = NULL, *error = NULL;
int ret;
@@ -455,7 +455,7 @@ int WEB_PAGE_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int WEB_PAGE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result)
+int web_page_perf(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *hostname, *path_str, *port_str, *error = NULL;
double start_time;
@@ -481,7 +481,7 @@ int WEB_PAGE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int WEB_PAGE_REGEXP(AGENT_REQUEST *request, AGENT_RESULT *result)
+int web_page_regexp(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *hostname, *path_str, *port_str, *buffer = NULL, *error = NULL, *regexp, *length_str;
const char *output;
diff --git a/src/libs/zbxsysinfo/common/http.h b/src/libs/zbxsysinfo/common/http.h
index 6b33b71de07..eaab51eee05 100644
--- a/src/libs/zbxsysinfo/common/http.h
+++ b/src/libs/zbxsysinfo/common/http.h
@@ -24,8 +24,8 @@
extern char *CONFIG_SOURCE_IP;
-int WEB_PAGE_GET(AGENT_REQUEST *request, AGENT_RESULT *result);
-int WEB_PAGE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result);
-int WEB_PAGE_REGEXP(AGENT_REQUEST *request, AGENT_RESULT *result);
+int web_page_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int web_page_perf(AGENT_REQUEST *request, AGENT_RESULT *result);
+int web_page_regexp(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_COMMON_HTTP_H */
diff --git a/src/libs/zbxsysinfo/common/http_metrics.c b/src/libs/zbxsysinfo/common/http_metrics.c
index 83f6e2e1163..2bf2a26be25 100644
--- a/src/libs/zbxsysinfo/common/http_metrics.c
+++ b/src/libs/zbxsysinfo/common/http_metrics.c
@@ -22,9 +22,9 @@
ZBX_METRIC parameters_common_http[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"web.page.get", CF_HAVEPARAMS, WEB_PAGE_GET, "localhost,,80"},
- {"web.page.perf", CF_HAVEPARAMS, WEB_PAGE_PERF, "localhost,,80"},
- {"web.page.regexp", CF_HAVEPARAMS, WEB_PAGE_REGEXP, "localhost,,80,OK"},
+ {"web.page.get", CF_HAVEPARAMS, web_page_get, "localhost,,80"},
+ {"web.page.perf", CF_HAVEPARAMS, web_page_perf, "localhost,,80"},
+ {"web.page.regexp", CF_HAVEPARAMS, web_page_regexp, "localhost,,80,OK"},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/common/net.c b/src/libs/zbxsysinfo/common/net.c
index 217b0f3ba9c..fa75043daa2 100644
--- a/src/libs/zbxsysinfo/common/net.c
+++ b/src/libs/zbxsysinfo/common/net.c
@@ -17,6 +17,7 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
+#include "../sysinfo.h"
#include "net.h"
#include "zbxcomms.h"
@@ -76,7 +77,7 @@ out:
return SYSINFO_RET_OK;
}
-int NET_TCP_PORT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_tcp_port(AGENT_REQUEST *request, AGENT_RESULT *result)
{
unsigned short port;
int value_int, ret;
diff --git a/src/libs/zbxsysinfo/common/net.h b/src/libs/zbxsysinfo/common/net.h
index 1074be084d2..d216caf94da 100644
--- a/src/libs/zbxsysinfo/common/net.h
+++ b/src/libs/zbxsysinfo/common/net.h
@@ -31,6 +31,6 @@ extern char *CONFIG_SOURCE_IP;
int tcp_expect(const char *host, unsigned short port, int timeout, const char *request,
int(*validate_func)(const char *), const char *sendtoclose, int *value_int);
-int NET_TCP_PORT(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_tcp_port(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_COMMON_NET_H */
diff --git a/src/libs/zbxsysinfo/common/system.c b/src/libs/zbxsysinfo/common/system.c
index 8848d736efd..40dc805201a 100644
--- a/src/libs/zbxsysinfo/common/system.c
+++ b/src/libs/zbxsysinfo/common/system.c
@@ -17,14 +17,15 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "system.h"
+#include "../sysinfo.h"
#include "zbxsysinfo_common.h"
+#include "system.h"
#include "zbxtime.h"
#if defined(_WINDOWS) || defined(__MINGW32__)
# include "zbxsysinfo.h"
-# include "perfmon.h"
+# include "zbxwin32.h"
# pragma comment(lib, "user32.lib")
#endif
@@ -33,7 +34,7 @@
* Comments: Thread-safe *
* *
******************************************************************************/
-int SYSTEM_LOCALTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_localtime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *type, buf[32];
long milliseconds;
@@ -72,7 +73,7 @@ int SYSTEM_LOCALTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_USERS_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_users_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if defined(_WINDOWS) || defined(__MINGW32__)
char counter_path[64];
@@ -82,14 +83,14 @@ int SYSTEM_USERS_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
ZBX_UNUSED(request);
zbx_snprintf(counter_path, sizeof(counter_path), "\\%u\\%u",
- (unsigned int)get_builtin_object_index(PCI_TOTAL_SESSIONS),
- (unsigned int)get_builtin_counter_index(PCI_TOTAL_SESSIONS));
+ (unsigned int)zbx_get_builtin_object_index(PCI_TOTAL_SESSIONS),
+ (unsigned int)zbx_get_builtin_counter_index(PCI_TOTAL_SESSIONS));
request_tmp.nparam = 1;
request_tmp.params = zbx_malloc(NULL, request_tmp.nparam * sizeof(char *));
request_tmp.params[0] = counter_path;
- ret = PERF_COUNTER(&request_tmp, result);
+ ret = perf_counter(&request_tmp, result);
zbx_free(request_tmp.params);
@@ -97,6 +98,6 @@ int SYSTEM_USERS_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
#else
ZBX_UNUSED(request);
- return EXECUTE_INT("who | wc -l", result);
+ return execute_int("who | wc -l", result);
#endif
}
diff --git a/src/libs/zbxsysinfo/common/system.h b/src/libs/zbxsysinfo/common/system.h
index adf87d36370..67370eb5a45 100644
--- a/src/libs/zbxsysinfo/common/system.h
+++ b/src/libs/zbxsysinfo/common/system.h
@@ -22,7 +22,7 @@
#include "module.h"
-int SYSTEM_LOCALTIME(AGENT_REQUEST *request, AGENT_RESULT *result);
-int SYSTEM_USERS_NUM(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_localtime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_users_num(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_COMMON_SYSTEM_H */
diff --git a/src/libs/zbxsysinfo/common/zabbix_stats.c b/src/libs/zbxsysinfo/common/zabbix_stats.c
index ff579f729b7..edb7ea2c636 100644
--- a/src/libs/zbxsysinfo/common/zabbix_stats.c
+++ b/src/libs/zbxsysinfo/common/zabbix_stats.c
@@ -182,7 +182,7 @@ int zbx_get_remote_zabbix_stats_queue(const char *ip, unsigned short port, const
return 0 == ZBX_ISSET_MSG(result) ? SUCCEED : FAIL;
}
-int ZABBIX_STATS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int zabbix_stats(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const char *ip_str, *port_str, *queue_str;
unsigned short port_number;
diff --git a/src/libs/zbxsysinfo/common/zabbix_stats.h b/src/libs/zbxsysinfo/common/zabbix_stats.h
index 032c0850f6b..969e96a5f91 100644
--- a/src/libs/zbxsysinfo/common/zabbix_stats.h
+++ b/src/libs/zbxsysinfo/common/zabbix_stats.h
@@ -29,6 +29,6 @@ int zbx_get_remote_zabbix_stats(const char *ip, unsigned short port, AGENT_RESUL
int zbx_get_remote_zabbix_stats_queue(const char *ip, unsigned short port, const char *from, const char *to,
AGENT_RESULT *result);
-int ZABBIX_STATS(AGENT_REQUEST *request, AGENT_RESULT *result);
+int zabbix_stats(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_COMMON_ZABBIX_STATS_H_ */
diff --git a/src/libs/zbxsysinfo/common/zbxsysinfo_common.c b/src/libs/zbxsysinfo/common/zbxsysinfo_common.c
index f772ecdbb23..3113eb78785 100644
--- a/src/libs/zbxsysinfo/common/zbxsysinfo_common.c
+++ b/src/libs/zbxsysinfo/common/zbxsysinfo_common.c
@@ -42,54 +42,54 @@
extern int CONFIG_TIMEOUT;
-static int ONLY_ACTIVE(AGENT_REQUEST *request, AGENT_RESULT *result);
-static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result);
-static int SYSTEM_RUN_LOCAL(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int only_active(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int system_run(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int system_run_no_remote(AGENT_REQUEST *request, AGENT_RESULT *result);
ZBX_METRIC parameters_common_local[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"system.run", CF_HAVEPARAMS, SYSTEM_RUN_LOCAL, "echo test"},
+ {"system.run", CF_HAVEPARAMS, system_run_no_remote, "echo test"},
{NULL}
};
ZBX_METRIC parameters_common[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"system.localtime", CF_HAVEPARAMS, SYSTEM_LOCALTIME, "utc"},
- {"system.run", CF_HAVEPARAMS, SYSTEM_RUN, "echo test"},
-
- {"vfs.file.size", CF_HAVEPARAMS, VFS_FILE_SIZE, VFS_TEST_FILE},
- {"vfs.file.time", CF_HAVEPARAMS, VFS_FILE_TIME, VFS_TEST_FILE ",modify"},
- {"vfs.file.exists", CF_HAVEPARAMS, VFS_FILE_EXISTS, VFS_TEST_FILE},
- {"vfs.file.contents", CF_HAVEPARAMS, VFS_FILE_CONTENTS, VFS_TEST_FILE},
- {"vfs.file.regexp", CF_HAVEPARAMS, VFS_FILE_REGEXP, VFS_TEST_FILE "," VFS_TEST_REGEXP},
- {"vfs.file.regmatch", CF_HAVEPARAMS, VFS_FILE_REGMATCH, VFS_TEST_FILE "," VFS_TEST_REGEXP},
- {"vfs.file.md5sum", CF_HAVEPARAMS, VFS_FILE_MD5SUM, VFS_TEST_FILE},
- {"vfs.file.cksum", CF_HAVEPARAMS, VFS_FILE_CKSUM, VFS_TEST_FILE},
- {"vfs.file.owner", CF_HAVEPARAMS, VFS_FILE_OWNER, VFS_TEST_FILE ",user,name"},
- {"vfs.file.permissions",CF_HAVEPARAMS, VFS_FILE_PERMISSIONS, VFS_TEST_FILE},
- {"vfs.file.get", CF_HAVEPARAMS, VFS_FILE_GET, VFS_TEST_FILE},
-
- {"vfs.dir.size", CF_HAVEPARAMS, VFS_DIR_SIZE, VFS_TEST_DIR},
- {"vfs.dir.count", CF_HAVEPARAMS, VFS_DIR_COUNT, VFS_TEST_DIR},
- {"vfs.dir.get", CF_HAVEPARAMS, VFS_DIR_GET, VFS_TEST_DIR},
-
- {"net.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"},
- {"net.dns.record", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"},
- {"net.tcp.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"}, /* deprecated */
- {"net.tcp.dns.query", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"}, /* deprecated */
- {"net.tcp.port", CF_HAVEPARAMS, NET_TCP_PORT, ",80"},
-
- {"system.users.num", 0, SYSTEM_USERS_NUM, NULL},
-
- {"log", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"log.count", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"logrt", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"logrt.count", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"eventlog", CF_HAVEPARAMS, ONLY_ACTIVE, "system"},
-
- {"zabbix.stats", CF_HAVEPARAMS, ZABBIX_STATS, "127.0.0.1,10051"},
+ {"system.localtime", CF_HAVEPARAMS, system_localtime, "utc"},
+ {"system.run", CF_HAVEPARAMS, system_run, "echo test"},
+
+ {"vfs.file.size", CF_HAVEPARAMS, vfs_file_size, VFS_TEST_FILE},
+ {"vfs.file.time", CF_HAVEPARAMS, vfs_file_time, VFS_TEST_FILE ",modify"},
+ {"vfs.file.exists", CF_HAVEPARAMS, vfs_file_exists, VFS_TEST_FILE},
+ {"vfs.file.contents", CF_HAVEPARAMS, vfs_file_contents, VFS_TEST_FILE},
+ {"vfs.file.regexp", CF_HAVEPARAMS, vfs_file_regexp, VFS_TEST_FILE "," VFS_TEST_REGEXP},
+ {"vfs.file.regmatch", CF_HAVEPARAMS, vfs_file_regmatch, VFS_TEST_FILE "," VFS_TEST_REGEXP},
+ {"vfs.file.md5sum", CF_HAVEPARAMS, vfs_file_md5sum, VFS_TEST_FILE},
+ {"vfs.file.cksum", CF_HAVEPARAMS, vfs_file_cksum, VFS_TEST_FILE},
+ {"vfs.file.owner", CF_HAVEPARAMS, vfs_file_owner, VFS_TEST_FILE ",user,name"},
+ {"vfs.file.permissions",CF_HAVEPARAMS, vfs_file_permissions, VFS_TEST_FILE},
+ {"vfs.file.get", CF_HAVEPARAMS, vfs_file_get, VFS_TEST_FILE},
+
+ {"vfs.dir.size", CF_HAVEPARAMS, vfs_dir_size, VFS_TEST_DIR},
+ {"vfs.dir.count", CF_HAVEPARAMS, vfs_dir_count, VFS_TEST_DIR},
+ {"vfs.dir.get", CF_HAVEPARAMS, vfs_dir_get, VFS_TEST_DIR},
+
+ {"net.dns", CF_HAVEPARAMS, net_dns, ",zabbix.com"},
+ {"net.dns.record", CF_HAVEPARAMS, net_dns_record, ",zabbix.com"},
+ {"net.tcp.dns", CF_HAVEPARAMS, net_dns, ",zabbix.com"}, /* deprecated */
+ {"net.tcp.dns.query", CF_HAVEPARAMS, net_dns_record, ",zabbix.com"}, /* deprecated */
+ {"net.tcp.port", CF_HAVEPARAMS, net_tcp_port, ",80"},
+
+ {"system.users.num", 0, system_users_num, NULL},
+
+ {"log", CF_HAVEPARAMS, only_active, "logfile"},
+ {"log.count", CF_HAVEPARAMS, only_active, "logfile"},
+ {"logrt", CF_HAVEPARAMS, only_active, "logfile"},
+ {"logrt.count", CF_HAVEPARAMS, only_active, "logfile"},
+ {"eventlog", CF_HAVEPARAMS, only_active, "system"},
+
+ {"zabbix.stats", CF_HAVEPARAMS, zabbix_stats, "127.0.0.1,10051"},
{NULL}
};
@@ -101,7 +101,7 @@ void zbx_set_user_parameter_dir(const char *path)
user_parameter_dir = path;
}
-static int ONLY_ACTIVE(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int only_active(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ZBX_UNUSED(request);
@@ -110,7 +110,7 @@ static int ONLY_ACTIVE(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
-static int execute_str(const char *command, AGENT_RESULT *result, const char* dir)
+static int execute_str_local(const char *command, AGENT_RESULT *result, const char* dir)
{
int ret = SYSINFO_RET_FAIL;
char *cmd_result = NULL, error[MAX_STRING_LEN];
@@ -136,7 +136,7 @@ out:
return ret;
}
-int EXECUTE_USER_PARAMETER(AGENT_REQUEST *request, AGENT_RESULT *result)
+int execute_user_parameter(AGENT_REQUEST *request, AGENT_RESULT *result)
{
if (1 != request->nparam)
{
@@ -144,17 +144,17 @@ int EXECUTE_USER_PARAMETER(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- return execute_str(get_rparam(request, 0), result, user_parameter_dir);
+ return execute_str_local(get_rparam(request, 0), result, user_parameter_dir);
}
-int EXECUTE_STR(const char *command, AGENT_RESULT *result)
+int execute_str(const char *command, AGENT_RESULT *result)
{
- return execute_str(command, result, NULL);
+ return execute_str_local(command, result, NULL);
}
-int EXECUTE_DBL(const char *command, AGENT_RESULT *result)
+int execute_dbl(const char *command, AGENT_RESULT *result)
{
- if (SYSINFO_RET_OK != EXECUTE_STR(command, result))
+ if (SYSINFO_RET_OK != execute_str(command, result))
return SYSINFO_RET_FAIL;
if (NULL == ZBX_GET_DBL_RESULT(result))
@@ -169,9 +169,9 @@ int EXECUTE_DBL(const char *command, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int EXECUTE_INT(const char *command, AGENT_RESULT *result)
+int execute_int(const char *command, AGENT_RESULT *result)
{
- if (SYSINFO_RET_OK != EXECUTE_STR(command, result))
+ if (SYSINFO_RET_OK != execute_str(command, result))
return SYSINFO_RET_FAIL;
if (NULL == ZBX_GET_UI64_RESULT(result))
@@ -186,7 +186,7 @@ int EXECUTE_INT(const char *command, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int system_run(AGENT_REQUEST *request, AGENT_RESULT *result, int level)
+static int system_run_local(AGENT_REQUEST *request, AGENT_RESULT *result, int level)
{
char *command, *flag;
@@ -209,7 +209,7 @@ static int system_run(AGENT_REQUEST *request, AGENT_RESULT *result, int level)
if (NULL == flag || '\0' == *flag || 0 == strcmp(flag, "wait")) /* default parameter */
{
- return EXECUTE_STR(command, result);
+ return execute_str(command, result);
}
else if (0 == strcmp(flag, "nowait"))
{
@@ -230,7 +230,7 @@ static int system_run(AGENT_REQUEST *request, AGENT_RESULT *result, int level)
return SYSINFO_RET_OK;
}
-static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int system_run(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int level;
@@ -239,10 +239,10 @@ static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result)
if (0 != CONFIG_LOG_REMOTE_COMMANDS)
level = LOG_LEVEL_WARNING;
- return system_run(request, result, level);
+ return system_run_local(request, result, level);
}
-static int SYSTEM_RUN_LOCAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int system_run_no_remote(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return system_run(request, result, LOG_LEVEL_DEBUG);
+ return system_run_local(request, result, LOG_LEVEL_DEBUG);
}
diff --git a/src/libs/zbxsysinfo/common/zbxsysinfo_common.h b/src/libs/zbxsysinfo/common/zbxsysinfo_common.h
index caa3656409b..6bd4704d146 100644
--- a/src/libs/zbxsysinfo/common/zbxsysinfo_common.h
+++ b/src/libs/zbxsysinfo/common/zbxsysinfo_common.h
@@ -25,9 +25,9 @@
extern ZBX_METRIC parameters_common[];
extern ZBX_METRIC parameters_common_local[];
-int EXECUTE_USER_PARAMETER(AGENT_REQUEST *request, AGENT_RESULT *result);
-int EXECUTE_STR(const char *command, AGENT_RESULT *result);
-int EXECUTE_DBL(const char *command, AGENT_RESULT *result);
-int EXECUTE_INT(const char *command, AGENT_RESULT *result);
+int execute_user_parameter(AGENT_REQUEST *request, AGENT_RESULT *result);
+int execute_str(const char *command, AGENT_RESULT *result);
+int execute_dbl(const char *command, AGENT_RESULT *result);
+int execute_int(const char *command, AGENT_RESULT *result);
#endif
diff --git a/src/libs/zbxsysinfo/freebsd/boottime.c b/src/libs/zbxsysinfo/freebsd/boottime.c
index eb8bec35b22..e24c80f0e75 100644
--- a/src/libs/zbxsysinfo/freebsd/boottime.c
+++ b/src/libs/zbxsysinfo/freebsd/boottime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME
size_t len;
diff --git a/src/libs/zbxsysinfo/freebsd/cpu.c b/src/libs/zbxsysinfo/freebsd/cpu.c
index 930ec2be0bf..ac0dcbaf1ce 100644
--- a/src/libs/zbxsysinfo/freebsd/cpu.c
+++ b/src/libs/zbxsysinfo/freebsd/cpu.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "stats.h"
#include "log.h"
@@ -42,7 +43,7 @@ static int get_cpu_num(int online)
return -1;
}
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int online = 0, ncpu;
@@ -74,7 +75,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode;
@@ -130,7 +131,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return get_cpustat(result, cpu_num, state, mode);
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int mode, per_cpu = 1, cpu_num;
@@ -189,7 +190,7 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result)
{
u_int v_swtch;
size_t len;
@@ -208,7 +209,7 @@ int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result)
{
u_int v_intr;
size_t len;
diff --git a/src/libs/zbxsysinfo/freebsd/diskio.c b/src/libs/zbxsysinfo/freebsd/diskio.c
index 2a73712bff7..c33207e665b 100644
--- a/src/libs/zbxsysinfo/freebsd/diskio.c
+++ b/src/libs/zbxsysinfo/freebsd/diskio.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "stats.h"
#include "diskdevices.h"
@@ -211,12 +212,12 @@ static int vfs_dev_rw(AGENT_REQUEST *request, AGENT_RESULT *result, int rw)
return SYSINFO_RET_OK;
}
-int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_read(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return vfs_dev_rw(request, result, ZBX_DEV_READ);
}
-int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_write(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return vfs_dev_rw(request, result, ZBX_DEV_WRITE);
}
diff --git a/src/libs/zbxsysinfo/freebsd/diskspace.c b/src/libs/zbxsysinfo/freebsd/diskspace.c
index 9c855243bda..90035432a77 100644
--- a/src/libs/zbxsysinfo/freebsd/diskspace.c
+++ b/src/libs/zbxsysinfo/freebsd/diskspace.c
@@ -125,7 +125,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -141,7 +141,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -157,7 +157,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -173,7 +173,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -189,7 +189,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -205,7 +205,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -225,27 +225,27 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statfs *mntbuf;
@@ -283,7 +283,7 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statfs *mntbuf;
@@ -391,7 +391,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/freebsd/freebsd.c b/src/libs/zbxsysinfo/freebsd/freebsd.c
index 3328805dc37..84be05b8e24 100644
--- a/src/libs/zbxsysinfo/freebsd/freebsd.c
+++ b/src/libs/zbxsysinfo/freebsd/freebsd.c
@@ -18,50 +18,51 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"kernel.maxfiles", 0, KERNEL_MAXFILES, NULL},
- {"kernel.maxproc", 0, KERNEL_MAXPROC, NULL},
+ {"kernel.maxfiles", 0, kernel_maxfiles, NULL},
+ {"kernel.maxproc", 0, kernel_maxproc, NULL},
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/,free"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/,free"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"vfs.dev.read", CF_HAVEPARAMS, VFS_DEV_READ, "da0,operations"},
- {"vfs.dev.write", CF_HAVEPARAMS, VFS_DEV_WRITE, "da0,operations"},
+ {"vfs.dev.read", CF_HAVEPARAMS, vfs_dev_read, "da0,operations"},
+ {"vfs.dev.write", CF_HAVEPARAMS, vfs_dev_write, "da0,operations"},
- {"net.tcp.listen", CF_HAVEPARAMS, NET_TCP_LISTEN, "80"},
- {"net.udp.listen", CF_HAVEPARAMS, NET_UDP_LISTEN, "68"},
+ {"net.tcp.listen", CF_HAVEPARAMS, net_tcp_listen, "80"},
+ {"net.udp.listen", CF_HAVEPARAMS, net_udp_listen, "68"},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "lo0,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "lo0,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "lo0,bytes"},
- {"net.if.collisions", CF_HAVEPARAMS, NET_IF_COLLISIONS, "lo0"},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, "lo0"},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "lo0,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "lo0,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "lo0,bytes"},
+ {"net.if.collisions", CF_HAVEPARAMS, net_if_collisions, "lo0"},
+ {"net.if.discovery", 0, net_if_discovery, "lo0"},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"proc.get", CF_HAVEPARAMS, PROC_GET, "inetd"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
- {"proc.mem", CF_HAVEPARAMS, PROC_MEM, "inetd"},
+ {"proc.get", CF_HAVEPARAMS, proc_get, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
+ {"proc.mem", CF_HAVEPARAMS, proc_mem, "inetd"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, NULL},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, NULL},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,user,avg1"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.switches", 0, system_cpu_switches, NULL},
+ {"system.cpu.intr", 0, system_cpu_intr, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,user,avg1"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
- {"system.swap.size", CF_HAVEPARAMS, SYSTEM_SWAP_SIZE, "all,free"},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
+ {"system.swap.size", CF_HAVEPARAMS, system_swap_size, "all,free"},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
- {"system.boottime", 0, SYSTEM_BOOTTIME, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
+ {"system.boottime", 0, system_boottime, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/freebsd/hostname.c b/src/libs/zbxsysinfo/freebsd/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/freebsd/hostname.c
+++ b/src/libs/zbxsysinfo/freebsd/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/freebsd/inodes.c b/src/libs/zbxsysinfo/freebsd/inodes.c
index d3e27b90bac..6824e7f5e5c 100644
--- a/src/libs/zbxsysinfo/freebsd/inodes.c
+++ b/src/libs/zbxsysinfo/freebsd/inodes.c
@@ -66,7 +66,7 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
#undef ZBX_FFREE
}
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -122,7 +122,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/freebsd/kernel.c b/src/libs/zbxsysinfo/freebsd/kernel.c
index 1079fc4245b..cf2f7a8e32c 100644
--- a/src/libs/zbxsysinfo/freebsd/kernel.c
+++ b/src/libs/zbxsysinfo/freebsd/kernel.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxfiles(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXFILES
int mib[2];
@@ -50,7 +51,7 @@ int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
#endif
}
-int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC
int mib[2];
diff --git a/src/libs/zbxsysinfo/freebsd/memory.c b/src/libs/zbxsysinfo/freebsd/memory.c
index 8e85fba6cf5..f03850ee0f5 100644
--- a/src/libs/zbxsysinfo/freebsd/memory.c
+++ b/src/libs/zbxsysinfo/freebsd/memory.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -33,7 +34,7 @@ static u_int pagesize = 0;
return SYSINFO_RET_FAIL; \
}
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
unsigned long totalbytes;
size_t len;
@@ -45,7 +46,7 @@ static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
+static int vm_memory_active(AGENT_RESULT *result)
{
u_int activepages;
size_t len;
@@ -57,7 +58,7 @@ static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
+static int vm_memory_inactive(AGENT_RESULT *result)
{
u_int inactivepages;
size_t len;
@@ -69,7 +70,7 @@ static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_WIRED(AGENT_RESULT *result)
+static int vm_memory_wired(AGENT_RESULT *result)
{
u_int wiredpages;
size_t len;
@@ -81,7 +82,7 @@ static int VM_MEMORY_WIRED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_CACHED(AGENT_RESULT *result)
+static int vm_memory_cached(AGENT_RESULT *result)
{
u_int cachedpages;
size_t len;
@@ -93,7 +94,7 @@ static int VM_MEMORY_CACHED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
u_int freepages;
size_t len;
@@ -105,7 +106,7 @@ static int VM_MEMORY_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
u_int activepages, wiredpages, cachedpages;
size_t len;
@@ -119,7 +120,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
u_int activepages, wiredpages, cachedpages, totalpages;
size_t len;
@@ -141,7 +142,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
u_int inactivepages, cachedpages, freepages;
size_t len;
@@ -155,7 +156,7 @@ static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
u_int inactivepages, cachedpages, freepages, totalpages;
size_t len;
@@ -177,7 +178,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
+static int vm_memory_buffers(AGENT_RESULT *result)
{
u_int bufspace;
size_t len;
@@ -189,7 +190,7 @@ static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_SHARED(AGENT_RESULT *result)
+static int vm_memory_shared(AGENT_RESULT *result)
{
struct vmtotal vm;
size_t len = sizeof(vm);
@@ -206,7 +207,7 @@ static int VM_MEMORY_SHARED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode;
int ret;
@@ -227,29 +228,29 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "active"))
- ret = VM_MEMORY_ACTIVE(result);
+ ret = vm_memory_active(result);
else if (0 == strcmp(mode, "inactive"))
- ret = VM_MEMORY_INACTIVE(result);
+ ret = vm_memory_inactive(result);
else if (0 == strcmp(mode, "wired"))
- ret = VM_MEMORY_WIRED(result);
+ ret = vm_memory_wired(result);
else if (0 == strcmp(mode, "cached"))
- ret = VM_MEMORY_CACHED(result);
+ ret = vm_memory_cached(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else if (0 == strcmp(mode, "buffers"))
- ret = VM_MEMORY_BUFFERS(result);
+ ret = vm_memory_buffers(result);
else if (0 == strcmp(mode, "shared"))
- ret = VM_MEMORY_SHARED(result);
+ ret = vm_memory_shared(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/freebsd/net.c b/src/libs/zbxsysinfo/freebsd/net.c
index 02680ea733e..d4d3dfeea40 100644
--- a/src/libs/zbxsysinfo/freebsd/net.c
+++ b/src/libs/zbxsysinfo/freebsd/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "../common/zbxsysinfo_common.h"
#include "zbxjson.h"
@@ -75,7 +76,7 @@ static int get_ifmib_general(const char *if_name, char **error)
return FAIL;
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
@@ -111,7 +112,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
@@ -145,7 +146,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
@@ -179,7 +180,7 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *port_str, command[64];
unsigned short port;
@@ -201,7 +202,7 @@ int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_snprintf(command, sizeof(command), "netstat -an | grep '^tcp.*\\.%hu[^.].*LISTEN' | wc -l", port);
- if (SYSINFO_RET_FAIL == (res = EXECUTE_INT(command, result)))
+ if (SYSINFO_RET_FAIL == (res = execute_int(command, result)))
return res;
if (1 < result->ui64)
@@ -210,7 +211,7 @@ int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
return res;
}
-int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *port_str, command[64];
unsigned short port;
@@ -232,7 +233,7 @@ int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_snprintf(command, sizeof(command), "netstat -an | grep '^udp.*\\.%hu[^.].*\\*\\.\\*' | wc -l", port);
- if (SYSINFO_RET_FAIL == (res = EXECUTE_INT(command, result)))
+ if (SYSINFO_RET_FAIL == (res = execute_int(command, result)))
return res;
if (1 < result->ui64)
@@ -241,7 +242,7 @@ int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
return res;
}
-int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *error;
@@ -264,7 +265,7 @@ int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i;
struct zbx_json j;
diff --git a/src/libs/zbxsysinfo/freebsd/proc.c b/src/libs/zbxsysinfo/freebsd/proc.c
index f313c4b90f3..fd776ee7181 100644
--- a/src/libs/zbxsysinfo/freebsd/proc.c
+++ b/src/libs/zbxsysinfo/freebsd/proc.c
@@ -227,7 +227,7 @@ static char *get_commandline(struct kinfo_proc *proc)
}
#undef ARGV_START_SIZE
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define ZBX_SIZE 1
#define ZBX_RSS 2
@@ -491,7 +491,7 @@ out:
#undef ZBX_SSIZE
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param, *args;
int proccount = 0, invalid_user = 0, zbx_proc_stat;
@@ -688,7 +688,7 @@ static char *get_state(struct kinfo_proc *proc)
return state;
}
-int PROC_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param, *args;
int count, i, mib[4], mibs, zbx_proc_mode, pagesize, invalid_user = 0;
diff --git a/src/libs/zbxsysinfo/freebsd/software.c b/src/libs/zbxsysinfo/freebsd/software.c
index 976ea09f03d..d7767b4ebb4 100644
--- a/src/libs/zbxsysinfo/freebsd/software.c
+++ b/src/libs/zbxsysinfo/freebsd/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/freebsd/swap.c b/src/libs/zbxsysinfo/freebsd/swap.c
index 85e9ee7368b..0c92ff229c2 100644
--- a/src/libs/zbxsysinfo/freebsd/swap.c
+++ b/src/libs/zbxsysinfo/freebsd/swap.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
/*
* FreeBSD 7.0 i386
diff --git a/src/libs/zbxsysinfo/freebsd/system.c b/src/libs/zbxsysinfo/freebsd/system.c
index ec3f8896f84..fa2e315c4af 100644
--- a/src/libs/zbxsysinfo/freebsd/system.c
+++ b/src/libs/zbxsysinfo/freebsd/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/freebsd/uptime.c b/src/libs/zbxsysinfo/freebsd/uptime.c
index e021c1a9d10..605e842935b 100644
--- a/src/libs/zbxsysinfo/freebsd/uptime.c
+++ b/src/libs/zbxsysinfo/freebsd/uptime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if defined(HAVE_SYSINFO_UPTIME)
struct sysinfo info;
diff --git a/src/libs/zbxsysinfo/hpux/cpu.c b/src/libs/zbxsysinfo/hpux/cpu.c
index c484c99fe60..7f6c475b953 100644
--- a/src/libs/zbxsysinfo/hpux/cpu.c
+++ b/src/libs/zbxsysinfo/hpux/cpu.c
@@ -18,12 +18,13 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "stats.h"
#include "log.h"
#include "zbxnum.h"
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *type;
struct pst_dynamic dyn;
@@ -54,7 +55,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode;
@@ -108,7 +109,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return get_cpustat(result, cpu_num, state, mode);
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
struct pst_dynamic dyn;
diff --git a/src/libs/zbxsysinfo/hpux/diskspace.c b/src/libs/zbxsysinfo/hpux/diskspace.c
index 138f8d6de94..6cc119a97d8 100644
--- a/src/libs/zbxsysinfo/hpux/diskspace.c
+++ b/src/libs/zbxsysinfo/hpux/diskspace.c
@@ -79,7 +79,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -95,7 +95,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -111,7 +111,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -127,7 +127,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -143,7 +143,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -159,7 +159,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -179,27 +179,27 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct mntent *mt;
FILE *f;
@@ -235,7 +235,7 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct mntent *mt;
FILE *f;
@@ -350,7 +350,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/hpux/hostname.c b/src/libs/zbxsysinfo/hpux/hostname.c
index 1b20aadc1e7..0aa2ce947d8 100644
--- a/src/libs/zbxsysinfo/hpux/hostname.c
+++ b/src/libs/zbxsysinfo/hpux/hostname.c
@@ -24,9 +24,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int rc;
char *hostname;
diff --git a/src/libs/zbxsysinfo/hpux/hpux.c b/src/libs/zbxsysinfo/hpux/hpux.c
index 9228fd0aff5..7ab8c7178ba 100644
--- a/src/libs/zbxsysinfo/hpux/hpux.c
+++ b/src/libs/zbxsysinfo/hpux/hpux.c
@@ -18,31 +18,32 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/,free"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/,free"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, NULL},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "lan0,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "lan0,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "lan0,bytes"},
+ {"net.if.discovery", 0, net_if_discovery, NULL},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "lan0,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "lan0,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "lan0,bytes"},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,user,avg1"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,user,avg1"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"system.uname", 0, system_uname, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/hpux/inodes.c b/src/libs/zbxsysinfo/hpux/inodes.c
index 38a3d3b8c4a..01e4358b196 100644
--- a/src/libs/zbxsysinfo/hpux/inodes.c
+++ b/src/libs/zbxsysinfo/hpux/inodes.c
@@ -19,6 +19,7 @@
#include "inodes.h"
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -65,8 +66,7 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
#undef ZBX_FFREE
}
-
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -122,7 +122,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/hpux/memory.c b/src/libs/zbxsysinfo/hpux/memory.c
index 3608ca2b521..b5ad0da96a4 100644
--- a/src/libs/zbxsysinfo/hpux/memory.c
+++ b/src/libs/zbxsysinfo/hpux/memory.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -42,7 +43,7 @@ struct pst_dynamic pdy;
return SYSINFO_RET_FAIL; \
}
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
ZBX_PSTAT_GETSTATIC();
@@ -51,7 +52,7 @@ static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
ZBX_PSTAT_GETSTATIC();
ZBX_PSTAT_GETDYNAMIC();
@@ -61,7 +62,7 @@ static int VM_MEMORY_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
+static int vm_memory_active(AGENT_RESULT *result)
{
ZBX_PSTAT_GETSTATIC();
ZBX_PSTAT_GETDYNAMIC();
@@ -71,7 +72,7 @@ static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
ZBX_PSTAT_GETSTATIC();
ZBX_PSTAT_GETDYNAMIC();
@@ -81,7 +82,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
ZBX_PSTAT_GETSTATIC();
ZBX_PSTAT_GETDYNAMIC();
@@ -97,7 +98,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
ZBX_PSTAT_GETSTATIC();
ZBX_PSTAT_GETDYNAMIC();
@@ -107,7 +108,7 @@ static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
ZBX_PSTAT_GETSTATIC();
ZBX_PSTAT_GETDYNAMIC();
@@ -123,7 +124,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
char *mode;
@@ -137,19 +138,19 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "active"))
- ret = VM_MEMORY_ACTIVE(result);
+ ret = vm_memory_active(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/hpux/net.c b/src/libs/zbxsysinfo/hpux/net.c
index 6eedf6be362..754e9a98489 100644
--- a/src/libs/zbxsysinfo/hpux/net.c
+++ b/src/libs/zbxsysinfo/hpux/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxjson.h"
@@ -154,7 +155,7 @@ end:
#endif /* HPUX_VERSION < 1131 */
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct zbx_json j;
char *if_name;
@@ -408,7 +409,7 @@ static int get_net_stat(Ext_mib_t *mib, const char *if_name)
return SUCCEED;
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
Ext_mib_t mib;
@@ -445,7 +446,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
Ext_mib_t mib;
@@ -482,7 +483,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
Ext_mib_t mib;
diff --git a/src/libs/zbxsysinfo/hpux/proc.c b/src/libs/zbxsysinfo/hpux/proc.c
index 2121a270ace..481fe442223 100644
--- a/src/libs/zbxsysinfo/hpux/proc.c
+++ b/src/libs/zbxsysinfo/hpux/proc.c
@@ -51,7 +51,7 @@ static int check_procstate(struct pst_status pst, int zbx_proc_stat)
return FAIL;
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define ZBX_BURST ((size_t)10)
char *procname, *proccomm, *param;
diff --git a/src/libs/zbxsysinfo/hpux/software.c b/src/libs/zbxsysinfo/hpux/software.c
index 976ea09f03d..d7767b4ebb4 100644
--- a/src/libs/zbxsysinfo/hpux/software.c
+++ b/src/libs/zbxsysinfo/hpux/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/hpux/system.c b/src/libs/zbxsysinfo/hpux/system.c
index 5162af0d5ba..423cfa82ec7 100644
--- a/src/libs/zbxsysinfo/hpux/system.c
+++ b/src/libs/zbxsysinfo/hpux/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/linux/boottime.c b/src/libs/zbxsysinfo/linux/boottime.c
index a42e977cacf..50b8fbe4003 100644
--- a/src/libs/zbxsysinfo/linux/boottime.c
+++ b/src/libs/zbxsysinfo/linux/boottime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
FILE *f;
char buf[MAX_STRING_LEN];
diff --git a/src/libs/zbxsysinfo/linux/cpu.c b/src/libs/zbxsysinfo/linux/cpu.c
index 0a0483d4dc4..77ef24e74df 100644
--- a/src/libs/zbxsysinfo/linux/cpu.c
+++ b/src/libs/zbxsysinfo/linux/cpu.c
@@ -18,13 +18,14 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
#include "zbxnum.h"
#include "stats.h"
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *type;
int name;
@@ -59,7 +60,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode;
@@ -127,7 +128,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return get_cpustat(result, cpu_num, state, mode);
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int mode, per_cpu = 1, cpu_num;
@@ -189,7 +190,7 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
char line[MAX_STRING_LEN];
@@ -224,7 +225,7 @@ int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
char line[MAX_STRING_LEN];
diff --git a/src/libs/zbxsysinfo/linux/diskio.c b/src/libs/zbxsysinfo/linux/diskio.c
index 873f66c6608..4464a09c8d2 100644
--- a/src/libs/zbxsysinfo/linux/diskio.c
+++ b/src/libs/zbxsysinfo/linux/diskio.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxjson.h"
#include "zbxstr.h"
@@ -285,12 +286,12 @@ static int vfs_dev_rw(AGENT_REQUEST *request, AGENT_RESULT *result, int rw)
return SYSINFO_RET_OK;
}
-int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_read(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return vfs_dev_rw(request, result, ZBX_DEV_READ);
}
-int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_write(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return vfs_dev_rw(request, result, ZBX_DEV_WRITE);
}
@@ -298,7 +299,7 @@ int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
/* SCSI device type CD/DVD-ROM. http://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type */
#define SCSI_TYPE_ROM 0x05
-int VFS_DEV_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define DEVTYPE_STR "DEVTYPE="
#define DEVTYPE_STR_LEN ZBX_CONST_STRLEN(DEVTYPE_STR)
diff --git a/src/libs/zbxsysinfo/linux/diskspace.c b/src/libs/zbxsysinfo/linux/diskspace.c
index f1318d07b60..b9fb6431efd 100644
--- a/src/libs/zbxsysinfo/linux/diskspace.c
+++ b/src/libs/zbxsysinfo/linux/diskspace.c
@@ -86,7 +86,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -126,12 +126,12 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char line[MAX_STRING_LEN], *p, *mpoint, *mtype, *mntopts;
FILE *f;
@@ -191,7 +191,7 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char line[MAX_STRING_LEN], *p, *mpoint, *mtype, *mntopts, *error;
FILE *f;
@@ -331,7 +331,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/linux/hardware.c b/src/libs/zbxsysinfo/linux/hardware.c
index e75595c452f..d8eff864d47 100644
--- a/src/libs/zbxsysinfo/linux/hardware.c
+++ b/src/libs/zbxsysinfo/linux/hardware.c
@@ -17,9 +17,10 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "hardware.h"
#include "zbxsysinfo.h"
+#include "hardware.h"
#include "../common/zbxsysinfo_common.h"
+#include "../sysinfo.h"
#include "zbxalgo.h"
#include "zbxregexp.h"
@@ -290,7 +291,7 @@ close:
return ret;
}
-int SYSTEM_HW_CHASSIS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hw_chassis(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode, buf[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
@@ -391,7 +392,7 @@ static size_t print_freq(char *buffer, size_t size, int filter, int cpu, zbx_uin
return offset;
}
-int SYSTEM_HW_CPU(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hw_cpu(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL, filter, cpu, cur_cpu = -1, offset = 0;
zbx_uint64_t maxfreq = ZBX_MAX_UINT64, curfreq = ZBX_MAX_UINT64;
@@ -515,7 +516,7 @@ int SYSTEM_HW_CPU(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int SYSTEM_HW_DEVICES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hw_devices(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *type;
@@ -528,9 +529,9 @@ int SYSTEM_HW_DEVICES(AGENT_REQUEST *request, AGENT_RESULT *result)
type = get_rparam(request, 0);
if (NULL == type || '\0' == *type || 0 == strcmp(type, "pci"))
- return EXECUTE_STR("lspci", result); /* list PCI devices by default */
+ return execute_str("lspci", result); /* list PCI devices by default */
else if (0 == strcmp(type, "usb"))
- return EXECUTE_STR("lsusb", result);
+ return execute_str("lsusb", result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
@@ -538,7 +539,7 @@ int SYSTEM_HW_DEVICES(AGENT_REQUEST *request, AGENT_RESULT *result)
}
}
-int SYSTEM_HW_MACADDR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hw_macaddr(AGENT_REQUEST *request, AGENT_RESULT *result)
{
size_t offset;
int s, i, show_names;
diff --git a/src/libs/zbxsysinfo/linux/hostname.c b/src/libs/zbxsysinfo/linux/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/linux/hostname.c
+++ b/src/libs/zbxsysinfo/linux/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/linux/inodes.c b/src/libs/zbxsysinfo/linux/inodes.c
index 791bbdb7322..0ea0c231ed9 100644
--- a/src/libs/zbxsysinfo/linux/inodes.c
+++ b/src/libs/zbxsysinfo/linux/inodes.c
@@ -87,7 +87,7 @@ while(0)
#undef get_string
}
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -143,7 +143,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/linux/kernel.c b/src/libs/zbxsysinfo/linux/kernel.c
index 334946f331c..54297a0fbed 100644
--- a/src/libs/zbxsysinfo/linux/kernel.c
+++ b/src/libs/zbxsysinfo/linux/kernel.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
static int read_uint64_from_procfs(const char *path, int first_num, zbx_uint64_t *value)
{
@@ -46,7 +47,7 @@ static int read_uint64_from_procfs(const char *path, int first_num, zbx_uint64_t
return ret;
}
-int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxfiles(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t value;
@@ -63,7 +64,7 @@ int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t value;
@@ -80,7 +81,7 @@ int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int KERNEL_OPENFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_openfiles(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t value;
diff --git a/src/libs/zbxsysinfo/linux/linux.c b/src/libs/zbxsysinfo/linux/linux.c
index d1038f05f19..540f309fa56 100644
--- a/src/libs/zbxsysinfo/linux/linux.c
+++ b/src/libs/zbxsysinfo/linux/linux.c
@@ -18,68 +18,69 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"kernel.maxfiles", 0, KERNEL_MAXFILES, NULL},
- {"kernel.maxproc", 0, KERNEL_MAXPROC, NULL},
- {"kernel.openfiles", 0, KERNEL_OPENFILES, NULL},
+ {"kernel.maxfiles", 0, kernel_maxfiles, NULL},
+ {"kernel.maxproc", 0, kernel_maxproc, NULL},
+ {"kernel.openfiles", 0, kernel_openfiles, NULL},
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/,free"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/,free"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"vfs.dev.read", CF_HAVEPARAMS, VFS_DEV_READ, "sda,operations"},
- {"vfs.dev.write", CF_HAVEPARAMS, VFS_DEV_WRITE, "sda,operations"},
- {"vfs.dev.discovery", 0, VFS_DEV_DISCOVERY, NULL},
+ {"vfs.dev.read", CF_HAVEPARAMS, vfs_dev_read, "sda,operations"},
+ {"vfs.dev.write", CF_HAVEPARAMS, vfs_dev_write, "sda,operations"},
+ {"vfs.dev.discovery", 0, vfs_dev_discovery, NULL},
- {"net.tcp.listen", CF_HAVEPARAMS, NET_TCP_LISTEN, "80"},
- {"net.udp.listen", CF_HAVEPARAMS, NET_UDP_LISTEN, "68"},
+ {"net.tcp.listen", CF_HAVEPARAMS, net_tcp_listen, "80"},
+ {"net.udp.listen", CF_HAVEPARAMS, net_udp_listen, "68"},
- {"net.tcp.socket.count",CF_HAVEPARAMS, NET_TCP_SOCKET_COUNT, ",80"},
- {"net.udp.socket.count",CF_HAVEPARAMS, NET_UDP_SOCKET_COUNT, ",68"},
+ {"net.tcp.socket.count",CF_HAVEPARAMS, net_tcp_socket_count, ",80"},
+ {"net.udp.socket.count",CF_HAVEPARAMS, net_udp_socket_count, ",68"},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "lo,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "lo,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "lo,bytes"},
- {"net.if.collisions", CF_HAVEPARAMS, NET_IF_COLLISIONS, "lo"},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, NULL},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "lo,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "lo,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "lo,bytes"},
+ {"net.if.collisions", CF_HAVEPARAMS, net_if_collisions, "lo"},
+ {"net.if.discovery", 0, net_if_discovery, NULL},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "total"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "total"},
- {"proc.cpu.util", CF_HAVEPARAMS, PROC_CPU_UTIL, "inetd"},
- {"proc.get", CF_HAVEPARAMS, PROC_GET, "inetd"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
- {"proc.mem", CF_HAVEPARAMS, PROC_MEM, "inetd"},
+ {"proc.cpu.util", CF_HAVEPARAMS, proc_cpu_util, "inetd"},
+ {"proc.get", CF_HAVEPARAMS, proc_get, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
+ {"proc.mem", CF_HAVEPARAMS, proc_mem, "inetd"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, NULL},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, NULL},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,user,avg1"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.switches", 0, system_cpu_switches, NULL},
+ {"system.cpu.intr", 0, system_cpu_intr, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,user,avg1"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"system.hw.chassis", CF_HAVEPARAMS, SYSTEM_HW_CHASSIS, NULL},
- {"system.hw.cpu", CF_HAVEPARAMS, SYSTEM_HW_CPU, NULL},
- {"system.hw.devices", CF_HAVEPARAMS, SYSTEM_HW_DEVICES, NULL},
- {"system.hw.macaddr", CF_HAVEPARAMS, SYSTEM_HW_MACADDR, NULL},
+ {"system.hw.chassis", CF_HAVEPARAMS, system_hw_chassis, NULL},
+ {"system.hw.cpu", CF_HAVEPARAMS, system_hw_cpu, NULL},
+ {"system.hw.devices", CF_HAVEPARAMS, system_hw_devices, NULL},
+ {"system.hw.macaddr", CF_HAVEPARAMS, system_hw_macaddr, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
- {"system.sw.os", CF_HAVEPARAMS, SYSTEM_SW_OS, NULL},
- {"system.sw.packages", CF_HAVEPARAMS, SYSTEM_SW_PACKAGES, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
+ {"system.sw.os", CF_HAVEPARAMS, system_sw_os, NULL},
+ {"system.sw.packages", CF_HAVEPARAMS, system_sw_packages, NULL},
- {"system.swap.size", CF_HAVEPARAMS, SYSTEM_SWAP_SIZE, "all,free"},
- {"system.swap.in", CF_HAVEPARAMS, SYSTEM_SWAP_IN, "all"},
- {"system.swap.out", CF_HAVEPARAMS, SYSTEM_SWAP_OUT, "all"},
+ {"system.swap.size", CF_HAVEPARAMS, system_swap_size, "all,free"},
+ {"system.swap.in", CF_HAVEPARAMS, system_swap_in, "all"},
+ {"system.swap.out", CF_HAVEPARAMS, system_swap_out, "all"},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
- {"system.boottime", 0, SYSTEM_BOOTTIME, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
+ {"system.boottime", 0, system_boottime, NULL},
- {"sensor", CF_HAVEPARAMS, GET_SENSOR, "w83781d-i2c-0-2d,temp1"},
+ {"sensor", CF_HAVEPARAMS, get_sensor, "w83781d-i2c-0-2d,temp1"},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/linux/memory.c b/src/libs/zbxsysinfo/linux/memory.c
index 02907b9a72d..a317c12ebdb 100644
--- a/src/libs/zbxsysinfo/linux/memory.c
+++ b/src/libs/zbxsysinfo/linux/memory.c
@@ -18,12 +18,12 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "proc.h"
-
#include "log.h"
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
struct sysinfo info;
@@ -38,7 +38,7 @@ static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
struct sysinfo info;
@@ -53,7 +53,7 @@ static int VM_MEMORY_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
+static int vm_memory_buffers(AGENT_RESULT *result)
{
struct sysinfo info;
@@ -68,7 +68,7 @@ static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
struct sysinfo info;
@@ -83,7 +83,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
struct sysinfo info;
@@ -104,7 +104,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
FILE *f;
zbx_uint64_t value;
@@ -155,7 +155,7 @@ close:
return ret;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
struct sysinfo info;
AGENT_RESULT result_tmp;
@@ -170,7 +170,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
zbx_init_agent_result(&result_tmp);
- ret = VM_MEMORY_AVAILABLE(&result_tmp);
+ ret = vm_memory_available(&result_tmp);
if (SYSINFO_RET_FAIL == ret)
{
@@ -195,7 +195,7 @@ clean:
return ret;
}
-static int VM_MEMORY_SHARED(AGENT_RESULT *result)
+static int vm_memory_shared(AGENT_RESULT *result)
{
#ifdef KERNEL_2_4
struct sysinfo info;
@@ -216,7 +216,7 @@ static int VM_MEMORY_SHARED(AGENT_RESULT *result)
#endif
}
-static int VM_MEMORY_PROC_MEMINFO(const char *meminfo_entry, AGENT_RESULT *result)
+static int vm_memory_proc_meminfo(const char *meminfo_entry, AGENT_RESULT *result)
{
FILE *f;
zbx_uint64_t value;
@@ -241,7 +241,7 @@ static int VM_MEMORY_PROC_MEMINFO(const char *meminfo_entry, AGENT_RESULT *resul
return ret;
}
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode;
int ret;
@@ -255,31 +255,31 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "buffers"))
- ret = VM_MEMORY_BUFFERS(result);
+ ret = vm_memory_buffers(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else if (0 == strcmp(mode, "shared"))
- ret = VM_MEMORY_SHARED(result);
+ ret = vm_memory_shared(result);
else if (0 == strcmp(mode, "cached"))
- ret = VM_MEMORY_PROC_MEMINFO("Cached:", result);
+ ret = vm_memory_proc_meminfo("Cached:", result);
else if (0 == strcmp(mode, "active"))
- ret = VM_MEMORY_PROC_MEMINFO("Active:", result);
+ ret = vm_memory_proc_meminfo("Active:", result);
else if (0 == strcmp(mode, "anon"))
- ret = VM_MEMORY_PROC_MEMINFO("AnonPages:", result);
+ ret = vm_memory_proc_meminfo("AnonPages:", result);
else if (0 == strcmp(mode, "inactive"))
- ret = VM_MEMORY_PROC_MEMINFO("Inactive:", result);
+ ret = vm_memory_proc_meminfo("Inactive:", result);
else if (0 == strcmp(mode, "slab"))
- ret = VM_MEMORY_PROC_MEMINFO("Slab:", result);
+ ret = vm_memory_proc_meminfo("Slab:", result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/linux/net.c b/src/libs/zbxsysinfo/linux/net.c
index 1ad3647c954..eac5d58da44 100644
--- a/src/libs/zbxsysinfo/linux/net.c
+++ b/src/libs/zbxsysinfo/linux/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxjson.h"
#include "log.h"
@@ -415,7 +416,7 @@ out:
return ret;
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
net_stat_t ns;
char *if_name, *mode, *error;
@@ -460,7 +461,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
net_stat_t ns;
char *if_name, *mode, *error;
@@ -505,7 +506,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
net_stat_t ns;
char *if_name, *mode, *error;
@@ -546,7 +547,7 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
net_stat_t ns;
char *if_name, *error;
@@ -570,7 +571,7 @@ int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char line[MAX_STRING_LEN], *p;
FILE *f;
@@ -613,7 +614,7 @@ int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char pattern[64], *port_str, *buffer = NULL;
unsigned short port;
@@ -714,7 +715,7 @@ out:
return ret;
}
-int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char pattern[64], *port_str, *buffer = NULL;
unsigned short port;
@@ -1160,12 +1161,12 @@ err:
return ret;
}
-int NET_TCP_SOCKET_COUNT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_tcp_socket_count(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return net_socket_count(NET_CONN_TYPE_TCP, request, result);
}
-int NET_UDP_SOCKET_COUNT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_udp_socket_count(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return net_socket_count(NET_CONN_TYPE_UDP, request, result);
}
diff --git a/src/libs/zbxsysinfo/linux/proc.c b/src/libs/zbxsysinfo/linux/proc.c
index b199be328e4..f2e80c49d09 100644
--- a/src/libs/zbxsysinfo/linux/proc.c
+++ b/src/libs/zbxsysinfo/linux/proc.c
@@ -502,7 +502,7 @@ static int get_total_memory(zbx_uint64_t *total_memory)
return ret;
}
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define ZBX_SIZE 0
#define ZBX_RSS 1
@@ -880,7 +880,7 @@ out:
#undef ZBX_VMPTE
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char tmp[MAX_STRING_LEN], *procname, *proccomm, *param;
DIR *dir;
@@ -1485,7 +1485,7 @@ out:
zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
}
-int PROC_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const char *procname, *username, *cmdline, *tmp;
char *errmsg = NULL;
@@ -1749,7 +1749,7 @@ static proc_data_t *proc_read_data(char *path, int zbx_proc_mode)
return proc_data;
}
-int PROC_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define SUM_PROC_VALUE(param) \
do \
diff --git a/src/libs/zbxsysinfo/linux/sensors.c b/src/libs/zbxsysinfo/linux/sensors.c
index d37e6973c4b..d1ad02f1ba5 100644
--- a/src/libs/zbxsysinfo/linux/sensors.c
+++ b/src/libs/zbxsysinfo/linux/sensors.c
@@ -400,7 +400,7 @@ out:
#endif
}
-int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_sensor(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *device, *name, *function;
int do_task, cnt = 0;
diff --git a/src/libs/zbxsysinfo/linux/software.c b/src/libs/zbxsysinfo/linux/software.c
index bcf7dd7f47b..b6e7f239680 100644
--- a/src/libs/zbxsysinfo/linux/software.c
+++ b/src/libs/zbxsysinfo/linux/software.c
@@ -17,8 +17,9 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "software.h"
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
+#include "software.h"
#include "zbxalgo.h"
#include "zbxexec.h"
@@ -31,7 +32,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
@@ -48,7 +49,7 @@ int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_SW_OS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_os(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *type, line[MAX_STRING_LEN], tmp_line[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL, line_read = FAIL;
@@ -181,7 +182,7 @@ static ZBX_PACKAGE_MANAGER package_managers[] =
{NULL}
};
-int SYSTEM_SW_PACKAGES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_packages(AGENT_REQUEST *request, AGENT_RESULT *result)
{
size_t offset = 0;
int ret = SYSINFO_RET_FAIL, show_pm, i, check_regex, check_manager;
diff --git a/src/libs/zbxsysinfo/linux/swap.c b/src/libs/zbxsysinfo/linux/swap.c
index 2608ec4a6d5..93d1691db27 100644
--- a/src/libs/zbxsysinfo/linux/swap.c
+++ b/src/libs/zbxsysinfo/linux/swap.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct sysinfo info;
char *swapdev, *mode;
@@ -260,7 +261,7 @@ static int get_swap_stat(const char *swapdev, swap_stat_t *result)
return ret;
}
-int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *swapdev, *mode;
swap_stat_t ss;
@@ -303,7 +304,7 @@ int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *swapdev, *mode;
swap_stat_t ss;
diff --git a/src/libs/zbxsysinfo/linux/system.c b/src/libs/zbxsysinfo/linux/system.c
index 21ee95f65a8..ec13add9249 100644
--- a/src/libs/zbxsysinfo/linux/system.c
+++ b/src/libs/zbxsysinfo/linux/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/linux/uptime.c b/src/libs/zbxsysinfo/linux/uptime.c
index fe49d532474..5b090b55955 100644
--- a/src/libs/zbxsysinfo/linux/uptime.c
+++ b/src/libs/zbxsysinfo/linux/uptime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct sysinfo info;
diff --git a/src/libs/zbxsysinfo/netbsd/boottime.c b/src/libs/zbxsysinfo/netbsd/boottime.c
index eb8bec35b22..e24c80f0e75 100644
--- a/src/libs/zbxsysinfo/netbsd/boottime.c
+++ b/src/libs/zbxsysinfo/netbsd/boottime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME
size_t len;
diff --git a/src/libs/zbxsysinfo/netbsd/cpu.c b/src/libs/zbxsysinfo/netbsd/cpu.c
index 646d794f1a0..6d63da340f4 100644
--- a/src/libs/zbxsysinfo/netbsd/cpu.c
+++ b/src/libs/zbxsysinfo/netbsd/cpu.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxnum.h"
#include "log.h"
@@ -42,7 +43,7 @@ static int get_cpu_num()
#endif
}
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num;
@@ -73,7 +74,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode;
@@ -127,7 +128,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return get_cpustat(result, cpu_num, state, mode);
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int mode, per_cpu = 1, cpu_num;
@@ -186,7 +187,7 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_UVMEXP2};
size_t len;
@@ -205,7 +206,7 @@ int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_UVMEXP2};
size_t len;
diff --git a/src/libs/zbxsysinfo/netbsd/diskspace.c b/src/libs/zbxsysinfo/netbsd/diskspace.c
index d762f5b0adf..0a884f4880b 100644
--- a/src/libs/zbxsysinfo/netbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/netbsd/diskspace.c
@@ -117,7 +117,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -133,7 +133,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -149,7 +149,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -165,7 +165,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -181,7 +181,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -197,7 +197,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -217,27 +217,27 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statvfs *mntbuf;
@@ -275,7 +275,7 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statvfs *mntbuf;
@@ -382,7 +382,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/netbsd/hostname.c b/src/libs/zbxsysinfo/netbsd/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/netbsd/hostname.c
+++ b/src/libs/zbxsysinfo/netbsd/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/netbsd/inodes.c b/src/libs/zbxsysinfo/netbsd/inodes.c
index 072bcd18836..01e4358b196 100644
--- a/src/libs/zbxsysinfo/netbsd/inodes.c
+++ b/src/libs/zbxsysinfo/netbsd/inodes.c
@@ -66,7 +66,7 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
#undef ZBX_FFREE
}
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -122,7 +122,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/netbsd/kernel.c b/src/libs/zbxsysinfo/netbsd/kernel.c
index 71bbfa362ca..0d992b71ef5 100644
--- a/src/libs/zbxsysinfo/netbsd/kernel.c
+++ b/src/libs/zbxsysinfo/netbsd/kernel.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxfiles(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXFILES
int mib[2];
@@ -50,7 +51,7 @@ int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
#endif
}
-int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC
int mib[2];
diff --git a/src/libs/zbxsysinfo/netbsd/memory.c b/src/libs/zbxsysinfo/netbsd/memory.c
index 12f9489097e..6bf72c4f82c 100644
--- a/src/libs/zbxsysinfo/netbsd/memory.c
+++ b/src/libs/zbxsysinfo/netbsd/memory.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -37,7 +38,7 @@ static struct uvmexp_sysctl uvm;
return SYSINFO_RET_FAIL; \
}
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -46,7 +47,7 @@ static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
+static int vm_memory_active(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -55,7 +56,7 @@ static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
+static int vm_memory_inactive(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -64,7 +65,7 @@ static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_WIRED(AGENT_RESULT *result)
+static int vm_memory_wired(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -100,7 +101,7 @@ static int VM_MEMORY_FILE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -109,7 +110,7 @@ static int VM_MEMORY_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -118,7 +119,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -133,7 +134,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
zbx_uint64_t available;
@@ -146,7 +147,7 @@ static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
zbx_uint64_t available;
@@ -165,7 +166,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
+static int vm_memory_buffers(AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_NKMEMPAGES}, pages;
@@ -176,7 +177,7 @@ static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_CACHED(AGENT_RESULT *result)
+static int vm_memory_cached(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -185,7 +186,7 @@ static int VM_MEMORY_CACHED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_SHARED(AGENT_RESULT *result)
+static int vm_memory_shared(AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_METER};
struct vmtotal vm;
@@ -197,7 +198,7 @@ static int VM_MEMORY_SHARED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode;
int ret = SYSINFO_RET_FAIL;
@@ -211,13 +212,13 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "active"))
- ret = VM_MEMORY_ACTIVE(result);
+ ret = vm_memory_active(result);
else if (0 == strcmp(mode, "inactive"))
- ret = VM_MEMORY_INACTIVE(result);
+ ret = vm_memory_inactive(result);
else if (0 == strcmp(mode, "wired"))
- ret = VM_MEMORY_WIRED(result);
+ ret = vm_memory_wired(result);
else if (0 == strcmp(mode, "anon"))
ret = VM_MEMORY_ANON(result);
else if (0 == strcmp(mode, "exec"))
@@ -225,21 +226,21 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
else if (0 == strcmp(mode, "file"))
ret = VM_MEMORY_FILE(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else if (0 == strcmp(mode, "buffers"))
- ret = VM_MEMORY_BUFFERS(result);
+ ret = vm_memory_buffers(result);
else if (0 == strcmp(mode, "cached"))
- ret = VM_MEMORY_CACHED(result);
+ ret = vm_memory_cached(result);
else if (0 == strcmp(mode, "shared"))
- ret = VM_MEMORY_SHARED(result);
+ ret = vm_memory_shared(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/netbsd/net.c b/src/libs/zbxsysinfo/netbsd/net.c
index 8621e5322c2..9e3e9c9817f 100644
--- a/src/libs/zbxsysinfo/netbsd/net.c
+++ b/src/libs/zbxsysinfo/netbsd/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxjson.h"
#include "log.h"
@@ -146,7 +147,7 @@ static int get_ifdata(const char *if_name,
#undef IFNET_ID
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
zbx_uint64_t ibytes, ipackets, ierrors, idropped;
@@ -184,7 +185,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
zbx_uint64_t obytes, opackets, oerrors;
@@ -220,7 +221,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
zbx_uint64_t tbytes, tpackets, terrors;
@@ -256,7 +257,7 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *error;
zbx_uint64_t icollisions;
@@ -281,7 +282,7 @@ int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i;
struct zbx_json j;
diff --git a/src/libs/zbxsysinfo/netbsd/netbsd.c b/src/libs/zbxsysinfo/netbsd/netbsd.c
index 88291ba7dae..3b50f402f5b 100644
--- a/src/libs/zbxsysinfo/netbsd/netbsd.c
+++ b/src/libs/zbxsysinfo/netbsd/netbsd.c
@@ -18,42 +18,43 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"kernel.maxfiles", 0, KERNEL_MAXFILES, NULL},
- {"kernel.maxproc", 0, KERNEL_MAXPROC, NULL},
-
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
-
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "lo0,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "lo0,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "lo0,bytes"},
- {"net.if.collisions", CF_HAVEPARAMS, NET_IF_COLLISIONS, "lo0"},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, "lo0"},
-
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
-
- {"proc.get", CF_HAVEPARAMS, PROC_GET, "inetd"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
- {"proc.mem", CF_HAVEPARAMS, PROC_MEM, "inetd"},
-
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, NULL},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, NULL},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,user,avg1"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
-
- {"system.uname", 0, SYSTEM_UNAME, NULL},
-
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
- {"system.boottime", 0, SYSTEM_BOOTTIME, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"kernel.maxfiles", 0, kernel_maxfiles, NULL},
+ {"kernel.maxproc", 0, kernel_maxproc, NULL},
+
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
+
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "lo0,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "lo0,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "lo0,bytes"},
+ {"net.if.collisions", CF_HAVEPARAMS, net_if_collisions, "lo0"},
+ {"net.if.discovery", 0, net_if_discovery, "lo0"},
+
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
+
+ {"proc.get", CF_HAVEPARAMS, proc_get, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
+ {"proc.mem", CF_HAVEPARAMS, proc_mem, "inetd"},
+
+ {"system.cpu.switches", 0, system_cpu_switches, NULL},
+ {"system.cpu.intr", 0, system_cpu_intr, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,user,avg1"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
+
+ {"system.uname", 0, system_uname, NULL},
+
+ {"system.uptime", 0, system_uptime, NULL},
+ {"system.boottime", 0, system_boottime, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/netbsd/proc.c b/src/libs/zbxsysinfo/netbsd/proc.c
index 464c6f3f3f4..6695fc4101f 100644
--- a/src/libs/zbxsysinfo/netbsd/proc.c
+++ b/src/libs/zbxsysinfo/netbsd/proc.c
@@ -115,7 +115,7 @@ static char *proc_argv(pid_t pid)
return argv;
}
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param, *args;
int do_task, pagesize, count, i, proccount = 0, invalid_user = 0, proc_ok, comm_ok, op, arg;
@@ -243,7 +243,7 @@ out:
return SYSINFO_RET_OK;
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param, *args;
int proccount = 0, invalid_user = 0, zbx_proc_stat;
@@ -405,7 +405,7 @@ static char *get_state(struct kinfo_proc2 *proc)
return state;
}
-int PROC_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param, *args;
int invalid_user = 0, count, i, k, zbx_proc_mode, pagesize, op, arg;
diff --git a/src/libs/zbxsysinfo/netbsd/software.c b/src/libs/zbxsysinfo/netbsd/software.c
index 976ea09f03d..d7767b4ebb4 100644
--- a/src/libs/zbxsysinfo/netbsd/software.c
+++ b/src/libs/zbxsysinfo/netbsd/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/netbsd/system.c b/src/libs/zbxsysinfo/netbsd/system.c
index ec3f8896f84..fa2e315c4af 100644
--- a/src/libs/zbxsysinfo/netbsd/system.c
+++ b/src/libs/zbxsysinfo/netbsd/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/netbsd/uptime.c b/src/libs/zbxsysinfo/netbsd/uptime.c
index e021c1a9d10..605e842935b 100644
--- a/src/libs/zbxsysinfo/netbsd/uptime.c
+++ b/src/libs/zbxsysinfo/netbsd/uptime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if defined(HAVE_SYSINFO_UPTIME)
struct sysinfo info;
diff --git a/src/libs/zbxsysinfo/openbsd/boottime.c b/src/libs/zbxsysinfo/openbsd/boottime.c
index eb8bec35b22..e24c80f0e75 100644
--- a/src/libs/zbxsysinfo/openbsd/boottime.c
+++ b/src/libs/zbxsysinfo/openbsd/boottime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME
size_t len;
diff --git a/src/libs/zbxsysinfo/openbsd/cpu.c b/src/libs/zbxsysinfo/openbsd/cpu.c
index c00429fead4..73211661a38 100644
--- a/src/libs/zbxsysinfo/openbsd/cpu.c
+++ b/src/libs/zbxsysinfo/openbsd/cpu.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
#include "zbxnum.h"
@@ -41,7 +42,7 @@ static int get_cpu_num()
#endif
}
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num;
@@ -72,7 +73,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode;
@@ -128,7 +129,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return get_cpustat(result, cpu_num, state, mode);
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int mode, per_cpu = 1, cpu_num;
@@ -187,7 +188,7 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_UVMEXP};
size_t len;
@@ -206,7 +207,7 @@ int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_UVMEXP};
size_t len;
diff --git a/src/libs/zbxsysinfo/openbsd/diskio.c b/src/libs/zbxsysinfo/openbsd/diskio.c
index 5cea1603a41..79fb2003dfb 100644
--- a/src/libs/zbxsysinfo/openbsd/diskio.c
+++ b/src/libs/zbxsysinfo/openbsd/diskio.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
#include "zbxstr.h"
@@ -97,7 +98,7 @@ static int get_disk_stats(const char *devname, zbx_uint64_t *rbytes, zbx_uint64_
return ret;
}
-static int VFS_DEV_READ_BYTES(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_read_bytes(const char *devname, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -113,7 +114,7 @@ static int VFS_DEV_READ_BYTES(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_READ_OPERATIONS(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_read_operations(const char *devname, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -129,7 +130,7 @@ static int VFS_DEV_READ_OPERATIONS(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_WRITE_BYTES(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_write_bytes(const char *devname, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -145,7 +146,7 @@ static int VFS_DEV_WRITE_BYTES(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_WRITE_OPERATIONS(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_write_operations(const char *devname, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -161,7 +162,7 @@ static int VFS_DEV_WRITE_OPERATIONS(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_read(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *devname, *mode;
int ret;
@@ -176,9 +177,9 @@ int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 1);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "operations"))
- ret = VFS_DEV_READ_OPERATIONS(devname, result);
+ ret = vfs_dev_read_operations(devname, result);
else if (0 == strcmp(mode, "bytes"))
- ret = VFS_DEV_READ_BYTES(devname, result);
+ ret = vfs_dev_read_bytes(devname, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
@@ -188,7 +189,7 @@ int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_write(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *devname, *mode;
int ret;
@@ -203,9 +204,9 @@ int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 1);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "operations"))
- ret = VFS_DEV_WRITE_OPERATIONS(devname, result);
+ ret = vfs_dev_write_operations(devname, result);
else if (0 == strcmp(mode, "bytes"))
- ret = VFS_DEV_WRITE_BYTES(devname, result);
+ ret = vfs_dev_write_bytes(devname, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
diff --git a/src/libs/zbxsysinfo/openbsd/diskspace.c b/src/libs/zbxsysinfo/openbsd/diskspace.c
index e4e00320f17..da0a8653d0e 100644
--- a/src/libs/zbxsysinfo/openbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/openbsd/diskspace.c
@@ -101,7 +101,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -117,7 +117,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -133,7 +133,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -149,7 +149,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -165,7 +165,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -181,7 +181,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -201,27 +201,27 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statfs *mntbuf;
@@ -259,7 +259,7 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statfs *mntbuf;
@@ -365,7 +365,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/openbsd/hostname.c b/src/libs/zbxsysinfo/openbsd/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/openbsd/hostname.c
+++ b/src/libs/zbxsysinfo/openbsd/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/openbsd/inodes.c b/src/libs/zbxsysinfo/openbsd/inodes.c
index 85060eace97..01e4358b196 100644
--- a/src/libs/zbxsysinfo/openbsd/inodes.c
+++ b/src/libs/zbxsysinfo/openbsd/inodes.c
@@ -19,6 +19,7 @@
#include "inodes.h"
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -65,7 +66,7 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
#undef ZBX_FFREE
}
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -121,7 +122,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/openbsd/kernel.c b/src/libs/zbxsysinfo/openbsd/kernel.c
index 71bbfa362ca..0d992b71ef5 100644
--- a/src/libs/zbxsysinfo/openbsd/kernel.c
+++ b/src/libs/zbxsysinfo/openbsd/kernel.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxfiles(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXFILES
int mib[2];
@@ -50,7 +51,7 @@ int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
#endif
}
-int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC
int mib[2];
diff --git a/src/libs/zbxsysinfo/openbsd/memory.c b/src/libs/zbxsysinfo/openbsd/memory.c
index b28ab227ec3..db0412c6312 100644
--- a/src/libs/zbxsysinfo/openbsd/memory.c
+++ b/src/libs/zbxsysinfo/openbsd/memory.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -35,7 +36,7 @@ static struct uvmexp uvm;
return SYSINFO_RET_FAIL; \
}
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -44,7 +45,7 @@ static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
+static int vm_memory_active(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -53,7 +54,7 @@ static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
+static int vm_memory_inactive(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -62,7 +63,7 @@ static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_WIRED(AGENT_RESULT *result)
+static int vm_memory_wired(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -71,7 +72,7 @@ static int VM_MEMORY_WIRED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -80,7 +81,7 @@ static int VM_MEMORY_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -89,7 +90,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -104,7 +105,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -114,7 +115,7 @@ static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -130,7 +131,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
+static int vm_memory_buffers(AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_NKMEMPAGES}, pages;
@@ -141,7 +142,7 @@ static int VM_MEMORY_BUFFERS(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_CACHED(AGENT_RESULT *result)
+static int vm_memory_cached(AGENT_RESULT *result)
{
ZBX_SYSCTL(uvm);
@@ -150,7 +151,7 @@ static int VM_MEMORY_CACHED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_SHARED(AGENT_RESULT *result)
+static int vm_memory_shared(AGENT_RESULT *result)
{
int mib[] = {CTL_VM, VM_METER};
struct vmtotal vm;
@@ -162,7 +163,7 @@ static int VM_MEMORY_SHARED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode;
int ret = SYSINFO_RET_FAIL;
@@ -176,29 +177,29 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "active"))
- ret = VM_MEMORY_ACTIVE(result);
+ ret = vm_memory_active(result);
else if (0 == strcmp(mode, "inactive"))
- ret = VM_MEMORY_INACTIVE(result);
+ ret = vm_memory_inactive(result);
else if (0 == strcmp(mode, "wired"))
- ret = VM_MEMORY_WIRED(result);
+ ret = vm_memory_wired(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else if (0 == strcmp(mode, "buffers"))
- ret = VM_MEMORY_BUFFERS(result);
+ ret = vm_memory_buffers(result);
else if (0 == strcmp(mode, "cached"))
- ret = VM_MEMORY_CACHED(result);
+ ret = vm_memory_cached(result);
else if (0 == strcmp(mode, "shared"))
- ret = VM_MEMORY_SHARED(result);
+ ret = vm_memory_shared(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/openbsd/net.c b/src/libs/zbxsysinfo/openbsd/net.c
index 50fa564da67..b3f5f5c3f5a 100644
--- a/src/libs/zbxsysinfo/openbsd/net.c
+++ b/src/libs/zbxsysinfo/openbsd/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxjson.h"
#include "log.h"
@@ -206,7 +207,7 @@ clean:
#undef IFNET_ID
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
zbx_uint64_t ibytes, ipackets, ierrors, idropped;
@@ -244,7 +245,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
zbx_uint64_t obytes, opackets, oerrors;
@@ -280,7 +281,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
zbx_uint64_t tbytes, tpackets, terrors;
@@ -316,7 +317,7 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *error;
zbx_uint64_t icollisions;
@@ -341,7 +342,7 @@ int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i;
struct zbx_json j;
diff --git a/src/libs/zbxsysinfo/openbsd/openbsd.c b/src/libs/zbxsysinfo/openbsd/openbsd.c
index 9e09aa32eaa..aa8a3d4b711 100644
--- a/src/libs/zbxsysinfo/openbsd/openbsd.c
+++ b/src/libs/zbxsysinfo/openbsd/openbsd.c
@@ -18,51 +18,52 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"kernel.maxfiles", 0, KERNEL_MAXFILES, NULL},
- {"kernel.maxproc", 0, KERNEL_MAXPROC, NULL},
+ {"kernel.maxfiles", 0, kernel_maxfiles, NULL},
+ {"kernel.maxproc", 0, kernel_maxproc, NULL},
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"vfs.dev.read", CF_HAVEPARAMS, VFS_DEV_READ, "sd0,operations"},
- {"vfs.dev.write", CF_HAVEPARAMS, VFS_DEV_WRITE, "sd0,operations"},
+ {"vfs.dev.read", CF_HAVEPARAMS, vfs_dev_read, "sd0,operations"},
+ {"vfs.dev.write", CF_HAVEPARAMS, vfs_dev_write, "sd0,operations"},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "lo0,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "lo0,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "lo0,bytes"},
- {"net.if.collisions", CF_HAVEPARAMS, NET_IF_COLLISIONS, "lo0"},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, "lo0"},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "lo0,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "lo0,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "lo0,bytes"},
+ {"net.if.collisions", CF_HAVEPARAMS, net_if_collisions, "lo0"},
+ {"net.if.discovery", 0, net_if_discovery, "lo0"},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"proc.get", CF_HAVEPARAMS, PROC_GET, "inetd"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
- {"proc.mem", CF_HAVEPARAMS, PROC_MEM, "inetd"},
+ {"proc.get", CF_HAVEPARAMS, proc_get, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
+ {"proc.mem", CF_HAVEPARAMS, proc_mem, "inetd"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, NULL},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, NULL},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,idle"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.switches", 0, system_cpu_switches, NULL},
+ {"system.cpu.intr", 0, system_cpu_intr, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,idle"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"system.swap.size", CF_HAVEPARAMS, SYSTEM_SWAP_SIZE, "all,free"},
- {"system.swap.in", CF_HAVEPARAMS, SYSTEM_SWAP_IN, "all,pages"},
- {"system.swap.out", CF_HAVEPARAMS, SYSTEM_SWAP_OUT, "all,count"},
+ {"system.swap.size", CF_HAVEPARAMS, system_swap_size, "all,free"},
+ {"system.swap.in", CF_HAVEPARAMS, system_swap_in, "all,pages"},
+ {"system.swap.out", CF_HAVEPARAMS, system_swap_out, "all,count"},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
- {"system.boottime", 0, SYSTEM_BOOTTIME, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
+ {"system.boottime", 0, system_boottime, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
- {"sensor", CF_HAVEPARAMS, GET_SENSOR, "cpu0,temp0"},
+ {"sensor", CF_HAVEPARAMS, get_sensor, "cpu0,temp0"},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/openbsd/proc.c b/src/libs/zbxsysinfo/openbsd/proc.c
index b52414c415e..f72eda437bd 100644
--- a/src/libs/zbxsysinfo/openbsd/proc.c
+++ b/src/libs/zbxsysinfo/openbsd/proc.c
@@ -203,7 +203,7 @@ static void collect_args(char **argv, int argc, char **args, size_t *args_alloc)
#undef ARGS_START_SIZE
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param;
int do_task, pagesize, count, i, proccount = 0, invalid_user = 0, proc_ok, comm_ok;
@@ -380,7 +380,7 @@ out:
return SYSINFO_RET_OK;
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param;
int proccount = 0, invalid_user = 0, zbx_proc_stat, count, i, proc_ok, stat_ok, comm_ok;
@@ -684,7 +684,7 @@ static char *get_state(struct ZBX_STRUCT_KINFO_PROC *proc)
return state;
}
-int PROC_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define SUM_PROC_VALUE(param) \
do \
diff --git a/src/libs/zbxsysinfo/openbsd/sensors.c b/src/libs/zbxsysinfo/openbsd/sensors.c
index b75d399d7db..53b83a1704e 100644
--- a/src/libs/zbxsysinfo/openbsd/sensors.c
+++ b/src/libs/zbxsysinfo/openbsd/sensors.c
@@ -127,7 +127,7 @@ static int get_device_sensors(int do_task, int *mib, const struct sensordev *sen
return SUCCEED;
}
-int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_sensor(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *device, *name, *function;
int do_task, mib[5], dev, cnt = 0;
@@ -218,7 +218,7 @@ int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result)
#else
-int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int get_sensor(AGENT_REQUEST *request, AGENT_RESULT *result)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for \"sensordev\" structure."));
diff --git a/src/libs/zbxsysinfo/openbsd/software.c b/src/libs/zbxsysinfo/openbsd/software.c
index 976ea09f03d..d7767b4ebb4 100644
--- a/src/libs/zbxsysinfo/openbsd/software.c
+++ b/src/libs/zbxsysinfo/openbsd/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/openbsd/swap.c b/src/libs/zbxsysinfo/openbsd/swap.c
index fa64fd8b208..2a1040c5276 100644
--- a/src/libs/zbxsysinfo/openbsd/swap.c
+++ b/src/libs/zbxsysinfo/openbsd/swap.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -57,7 +58,7 @@ static int get_swap_size(zbx_uint64_t *total, zbx_uint64_t *free, zbx_uint64_t *
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_TOTAL(AGENT_RESULT *result)
+static int system_swap_total(AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -73,7 +74,7 @@ static int SYSTEM_SWAP_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_FREE(AGENT_RESULT *result)
+static int system_swap_free(AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -89,7 +90,7 @@ static int SYSTEM_SWAP_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_USED(AGENT_RESULT *result)
+static int system_swap_used(AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -105,7 +106,7 @@ static int SYSTEM_SWAP_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result)
+static int system_swap_pfree(AGENT_RESULT *result)
{
double value;
char *error;
@@ -121,7 +122,7 @@ static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_PUSED(AGENT_RESULT *result)
+static int system_swap_pused(AGENT_RESULT *result)
{
double value;
char *error;
@@ -137,7 +138,7 @@ static int SYSTEM_SWAP_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *swapdev, *mode;
int ret;
@@ -159,23 +160,23 @@ int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
if (NULL == mode || *mode == '\0' || 0 == strcmp(mode, "free"))
{
- ret = SYSTEM_SWAP_FREE(result);
+ ret = system_swap_free(result);
}
else if (0 == strcmp(mode, "used"))
{
- ret = SYSTEM_SWAP_USED(result);
+ ret = system_swap_used(result);
}
else if (0 == strcmp(mode, "total"))
{
- ret = SYSTEM_SWAP_TOTAL(result);
+ ret = system_swap_total(result);
}
else if (0 == strcmp(mode, "pfree"))
{
- ret = SYSTEM_SWAP_PFREE(result);
+ ret = system_swap_pfree(result);
}
else if (0 == strcmp(mode, "pused"))
{
- ret = SYSTEM_SWAP_PUSED(result);
+ ret = system_swap_pused(result);
}
else
{
@@ -229,7 +230,7 @@ static int get_swap_io(zbx_uint64_t *icount, zbx_uint64_t *ipages, zbx_uint64_t
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret;
char *swapdev, *mode, *error;
@@ -274,7 +275,7 @@ int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int SYSTEM_SWAP_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret;
char *swapdev, *mode, *error;
diff --git a/src/libs/zbxsysinfo/openbsd/system.c b/src/libs/zbxsysinfo/openbsd/system.c
index ec3f8896f84..fa2e315c4af 100644
--- a/src/libs/zbxsysinfo/openbsd/system.c
+++ b/src/libs/zbxsysinfo/openbsd/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/openbsd/uptime.c b/src/libs/zbxsysinfo/openbsd/uptime.c
index 1eb81fa24b6..463cc8c6dc4 100644
--- a/src/libs/zbxsysinfo/openbsd/uptime.c
+++ b/src/libs/zbxsysinfo/openbsd/uptime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME
int mib[2], now;
diff --git a/src/libs/zbxsysinfo/osf/cpu.c b/src/libs/zbxsysinfo/osf/cpu.c
index a01d835c4c9..2cd469d2293 100644
--- a/src/libs/zbxsysinfo/osf/cpu.c
+++ b/src/libs/zbxsysinfo/osf/cpu.c
@@ -18,9 +18,10 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "../common/zbxsysinfo_common.h"
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int ret = SYSINFO_RET_FAIL;
@@ -52,13 +53,13 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
tmp = get_rparam(request, 1);
if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "user"))
- ret = EXECUTE_DBL("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF-3))}'", result);
+ ret = execute_dbl("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF-3))}'", result);
else if (0 == strcmp(tmp, "nice"))
- ret = EXECUTE_DBL("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF-2))}'", result);
+ ret = execute_dbl("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF-2))}'", result);
else if (0 == strcmp(tmp, "system"))
- ret = EXECUTE_DBL("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF-1))}'", result);
+ ret = execute_dbl("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF-1))}'", result);
else if (0 == strcmp(tmp, "idle"))
- ret = EXECUTE_DBL("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF))}'", result);
+ ret = execute_dbl("iostat 1 2 | tail -n 1 | awk '{printf(\"%s\",$(NF))}'", result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
@@ -68,7 +69,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int ret = SYSINFO_RET_FAIL;
@@ -91,11 +92,11 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
tmp = get_rparam(request, 1);
if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "avg1"))
- ret = EXECUTE_DBL("uptime | awk '{printf(\"%s\", $(NF))}' | sed 's/[ ,]//g'", result);
+ ret = execute_dbl("uptime | awk '{printf(\"%s\", $(NF))}' | sed 's/[ ,]//g'", result);
else if (0 == strcmp(tmp, "avg5"))
- ret = EXECUTE_DBL("uptime | awk '{printf(\"%s\", $(NF-1))}' | sed 's/[ ,]//g'", result);
+ ret = execute_dbl("uptime | awk '{printf(\"%s\", $(NF-1))}' | sed 's/[ ,]//g'", result);
else if (0 == strcmp(tmp, "avg15"))
- ret = EXECUTE_DBL("uptime | awk '{printf(\"%s\", $(NF-2))}' | sed 's/[ ,]//g'", result);
+ ret = execute_dbl("uptime | awk '{printf(\"%s\", $(NF-2))}' | sed 's/[ ,]//g'", result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
diff --git a/src/libs/zbxsysinfo/osf/diskspace.c b/src/libs/zbxsysinfo/osf/diskspace.c
index 76df1a5b190..5c24dcb0a9c 100644
--- a/src/libs/zbxsysinfo/osf/diskspace.c
+++ b/src/libs/zbxsysinfo/osf/diskspace.c
@@ -76,7 +76,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -92,7 +92,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -108,7 +108,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -124,7 +124,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -140,7 +140,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -156,7 +156,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -176,22 +176,22 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/osf/hostname.c b/src/libs/zbxsysinfo/osf/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/osf/hostname.c
+++ b/src/libs/zbxsysinfo/osf/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/osf/inodes.c b/src/libs/zbxsysinfo/osf/inodes.c
index cc9d1cc3658..81c236c737c 100644
--- a/src/libs/zbxsysinfo/osf/inodes.c
+++ b/src/libs/zbxsysinfo/osf/inodes.c
@@ -22,7 +22,7 @@
#include "log.h"
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_SYS_STATVFS_H
# define ZBX_STATFS statvfs
@@ -110,7 +110,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
#undef ZBX_FFREE
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/osf/kernel.c b/src/libs/zbxsysinfo/osf/kernel.c
index 60c4827c85a..27003f27a6c 100644
--- a/src/libs/zbxsysinfo/osf/kernel.c
+++ b/src/libs/zbxsysinfo/osf/kernel.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxfiles(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXFILES
int mib[2], len;
@@ -49,7 +50,7 @@ int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
#endif
}
-int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC
int mib[2], len;
diff --git a/src/libs/zbxsysinfo/osf/memory.c b/src/libs/zbxsysinfo/osf/memory.c
index de910b18479..10a192050cd 100644
--- a/src/libs/zbxsysinfo/osf/memory.c
+++ b/src/libs/zbxsysinfo/osf/memory.c
@@ -18,19 +18,20 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "../common/zbxsysinfo_common.h"
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
- return EXECUTE_INT("vmstat -s | awk 'BEGIN{pages=0}{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if(($2==\"inactive\"||$2==\"active\"||$2==\"wired\")&&$3==\"pages\")pages+=$1}END{printf (pages*pgsize)}'", result);
+ return execute_int("vmstat -s | awk 'BEGIN{pages=0}{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if(($2==\"inactive\"||$2==\"active\"||$2==\"wired\")&&$3==\"pages\")pages+=$1}END{printf (pages*pgsize)}'", result);
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
- return EXECUTE_INT("vmstat -s | awk '{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if($2==\"free\"&&$3==\"pages\")pages=($1)}END{printf (pages*pgsize)}'", result);
+ return execute_int("vmstat -s | awk '{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if($2==\"free\"&&$3==\"pages\")pages=($1)}END{printf (pages*pgsize)}'", result);
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
AGENT_RESULT result_tmp;
@@ -38,7 +39,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
zbx_init_agent_result(&result_tmp);
- if (SYSINFO_RET_OK != VM_MEMORY_FREE(&result_tmp))
+ if (SYSINFO_RET_OK != vm_memory_free(&result_tmp))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, result_tmp.msg));
goto clean;
@@ -46,7 +47,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
free = result_tmp.ui64;
- if (SYSINFO_RET_OK != VM_MEMORY_TOTAL(&result_tmp))
+ if (SYSINFO_RET_OK != vm_memory_total(&result_tmp))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, result_tmp.msg));
goto clean;
@@ -63,7 +64,7 @@ clean:
return ret;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
AGENT_RESULT result_tmp;
@@ -71,7 +72,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
zbx_init_agent_result(&result_tmp);
- if (SYSINFO_RET_OK != VM_MEMORY_FREE(&result_tmp))
+ if (SYSINFO_RET_OK != vm_memory_free(&result_tmp))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, result_tmp.msg));
goto clean;
@@ -79,7 +80,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
free = result_tmp.ui64;
- if (SYSINFO_RET_OK != VM_MEMORY_TOTAL(&result_tmp))
+ if (SYSINFO_RET_OK != vm_memory_total(&result_tmp))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, result_tmp.msg));
goto clean;
@@ -102,12 +103,12 @@ clean:
return ret;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
- return VM_MEMORY_FREE(result);
+ return vm_memory_free(result);
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
AGENT_RESULT result_tmp;
@@ -115,7 +116,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
zbx_init_agent_result(&result_tmp);
- if (SYSINFO_RET_OK != VM_MEMORY_FREE(&result_tmp))
+ if (SYSINFO_RET_OK != vm_memory_free(&result_tmp))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, result_tmp.msg));
goto clean;
@@ -123,7 +124,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
free = result_tmp.ui64;
- if (SYSINFO_RET_OK != VM_MEMORY_TOTAL(&result_tmp))
+ if (SYSINFO_RET_OK != vm_memory_total(&result_tmp))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, result_tmp.msg));
goto clean;
@@ -146,7 +147,7 @@ clean:
return ret;
}
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode;
int ret = SYSINFO_RET_FAIL;
@@ -160,17 +161,17 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/osf/osf.c b/src/libs/zbxsysinfo/osf/osf.c
index 428010ff03b..c7aa9675ea9 100644
--- a/src/libs/zbxsysinfo/osf/osf.c
+++ b/src/libs/zbxsysinfo/osf/osf.c
@@ -18,31 +18,32 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"kernel.maxfiles", 0, KERNEL_MAXFILES, NULL},
- {"kernel.maxproc", 0, KERNEL_MAXPROC, NULL},
+ {"kernel.maxfiles", 0, kernel_maxfiles, NULL},
+ {"kernel.maxproc", 0, kernel_maxproc, NULL},
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/,free"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/,free"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
- {"proc.mem", CF_HAVEPARAMS, PROC_MEM, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
+ {"proc.mem", CF_HAVEPARAMS, proc_mem, "inetd"},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,user,avg1"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,user,avg1"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"system.swap.size", CF_HAVEPARAMS, SYSTEM_SWAP_SIZE, "all,free"},
+ {"system.swap.size", CF_HAVEPARAMS, system_swap_size, "all,free"},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/osf/proc.c b/src/libs/zbxsysinfo/osf/proc.c
index 7d5bacaaea0..990aa82d28f 100644
--- a/src/libs/zbxsysinfo/osf/proc.c
+++ b/src/libs/zbxsysinfo/osf/proc.c
@@ -26,7 +26,7 @@
#include <sys/procfs.h>
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result)
{
DIR *dir;
int proc;
@@ -152,7 +152,7 @@ out:
return SYSINFO_RET_OK;
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
DIR *dir;
int proc;
diff --git a/src/libs/zbxsysinfo/osf/software.c b/src/libs/zbxsysinfo/osf/software.c
index 976ea09f03d..d7767b4ebb4 100644
--- a/src/libs/zbxsysinfo/osf/software.c
+++ b/src/libs/zbxsysinfo/osf/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/osf/swap.c b/src/libs/zbxsysinfo/osf/swap.c
index 11c08179bec..eb09f2bd8b9 100644
--- a/src/libs/zbxsysinfo/osf/swap.c
+++ b/src/libs/zbxsysinfo/osf/swap.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
/* Solaris. */
#if !defined(HAVE_SYSINFO_FREESWAP)
@@ -85,7 +86,7 @@ point them all to the same buffer */
#endif
#endif
-static int SYSTEM_SWAP_USED(AGENT_RESULT *result)
+static int system_swap_used(AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
@@ -126,7 +127,7 @@ static int SYSTEM_SWAP_USED(AGENT_RESULT *result)
#endif
}
-static int SYSTEM_SWAP_FREE(AGENT_RESULT *result)
+static int system_swap_free(AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_FREESWAP
struct sysinfo info;
@@ -165,7 +166,7 @@ static int SYSTEM_SWAP_FREE(AGENT_RESULT *result)
#endif
}
-static int SYSTEM_SWAP_TOTAL(AGENT_RESULT *result)
+static int system_swap_total(AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_TOTALSWAP
struct sysinfo info;
@@ -196,7 +197,7 @@ static int SYSTEM_SWAP_TOTAL(AGENT_RESULT *result)
#endif
}
-static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result)
+static int system_swap_pfree(AGENT_RESULT *result)
{
AGENT_RESULT result_tmp;
zbx_uint64_t tot_val = 0;
@@ -204,7 +205,7 @@ static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result)
zbx_init_agent_result(&result_tmp);
- if (SYSINFO_RET_OK != SYSTEM_SWAP_TOTAL(&result_tmp) || !(result_tmp.type & AR_UINT64))
+ if (SYSINFO_RET_OK != system_swap_total(&result_tmp) || !(result_tmp.type & AR_UINT64))
return SYSINFO_RET_FAIL;
tot_val = result_tmp.ui64;
@@ -215,7 +216,7 @@ static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (SYSINFO_RET_OK != SYSTEM_SWAP_FREE(&result_tmp) || !(result_tmp.type & AR_UINT64))
+ if (SYSINFO_RET_OK != system_swap_free(&result_tmp) || !(result_tmp.type & AR_UINT64))
return SYSINFO_RET_FAIL;
free_val = result_tmp.ui64;
@@ -226,7 +227,7 @@ static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_PUSED(AGENT_RESULT *result)
+static int system_swap_pused(AGENT_RESULT *result)
{
AGENT_RESULT result_tmp;
zbx_uint64_t tot_val = 0;
@@ -234,7 +235,7 @@ static int SYSTEM_SWAP_PUSED(AGENT_RESULT *result)
zbx_init_agent_result(&result_tmp);
- if (SYSINFO_RET_OK != SYSTEM_SWAP_TOTAL(&result_tmp) || !(result_tmp.type & AR_UINT64))
+ if (SYSINFO_RET_OK != system_swap_total(&result_tmp) || !(result_tmp.type & AR_UINT64))
return SYSINFO_RET_FAIL;
tot_val = result_tmp.ui64;
@@ -245,7 +246,7 @@ static int SYSTEM_SWAP_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
- if (SYSINFO_RET_OK != SYSTEM_SWAP_FREE(&result_tmp) || !(result_tmp.type & AR_UINT64))
+ if (SYSINFO_RET_OK != system_swap_free(&result_tmp) || !(result_tmp.type & AR_UINT64))
return SYSINFO_RET_FAIL;
free_val = result_tmp.ui64;
@@ -256,7 +257,7 @@ static int SYSTEM_SWAP_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *swapdev, *mode;
int ret = SYSINFO_RET_FAIL;
@@ -271,15 +272,15 @@ int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "free"))
- ret = SYSTEM_SWAP_FREE(result);
+ ret = system_swap_free(result);
else if (0 == strcmp(mode, "used"))
- ret = SYSTEM_SWAP_USED(result);
+ ret = system_swap_used(result);
else if (0 == strcmp(mode, "total"))
- ret = SYSTEM_SWAP_TOTAL(result);
+ ret = system_swap_total(result);
else if (0 == strcmp(mode, "pfree"))
- ret = SYSTEM_SWAP_PFREE(result);
+ ret = system_swap_pfree(result);
else if (0 == strcmp(mode, "pused"))
- ret = SYSTEM_SWAP_PUSED(result);
+ ret = system_swap_pused(result);
else
ret = SYSINFO_RET_FAIL;
diff --git a/src/libs/zbxsysinfo/osf/system.c b/src/libs/zbxsysinfo/osf/system.c
index ec3f8896f84..fa2e315c4af 100644
--- a/src/libs/zbxsysinfo/osf/system.c
+++ b/src/libs/zbxsysinfo/osf/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/osf/uptime.c b/src/libs/zbxsysinfo/osf/uptime.c
index 235b26513f1..afcb340447f 100644
--- a/src/libs/zbxsysinfo/osf/uptime.c
+++ b/src/libs/zbxsysinfo/osf/uptime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#if defined(HAVE_SYSINFO_UPTIME)
struct sysinfo info;
diff --git a/src/libs/zbxsysinfo/osx/boottime.c b/src/libs/zbxsysinfo/osx/boottime.c
index 0747dc77d97..c43945b74b0 100644
--- a/src/libs/zbxsysinfo/osx/boottime.c
+++ b/src/libs/zbxsysinfo/osx/boottime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_KERN, KERN_BOOTTIME};
struct timeval boottime;
diff --git a/src/libs/zbxsysinfo/osx/cpu.c b/src/libs/zbxsysinfo/osx/cpu.c
index 7424a16c60a..34c86ddf196 100644
--- a/src/libs/zbxsysinfo/osx/cpu.c
+++ b/src/libs/zbxsysinfo/osx/cpu.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -37,7 +38,7 @@ static int get_cpu_num(int online)
return cpu_num;
}
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, online = 0;
@@ -69,7 +70,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int mode, per_cpu = 1, cpu_num;
diff --git a/src/libs/zbxsysinfo/osx/diskspace.c b/src/libs/zbxsysinfo/osx/diskspace.c
index 350b0ca7c51..cbad5e1c6fe 100644
--- a/src/libs/zbxsysinfo/osx/diskspace.c
+++ b/src/libs/zbxsysinfo/osx/diskspace.c
@@ -101,7 +101,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_BSIZE
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -117,7 +117,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -133,7 +133,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -149,7 +149,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -165,7 +165,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -181,7 +181,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -201,27 +201,27 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statfs *mntbuf;
@@ -259,7 +259,7 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int i, rc;
struct statfs *mntbuf;
@@ -365,7 +365,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/osx/hostname.c b/src/libs/zbxsysinfo/osx/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/osx/hostname.c
+++ b/src/libs/zbxsysinfo/osx/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/osx/inodes.c b/src/libs/zbxsysinfo/osx/inodes.c
index 85060eace97..8bd59aeb155 100644
--- a/src/libs/zbxsysinfo/osx/inodes.c
+++ b/src/libs/zbxsysinfo/osx/inodes.c
@@ -17,8 +17,9 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "inodes.h"
#include "zbxsysinfo.h"
+#include "inodes.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -65,7 +66,7 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
#undef ZBX_FFREE
}
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -121,7 +122,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/osx/kernel.c b/src/libs/zbxsysinfo/osx/kernel.c
index c3671cd81e8..9900ee329f0 100644
--- a/src/libs/zbxsysinfo/osx/kernel.c
+++ b/src/libs/zbxsysinfo/osx/kernel.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxfiles(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_KERN, KERN_MAXFILES}, maxfiles;
size_t len = sizeof(maxfiles);
@@ -37,7 +38,7 @@ int KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_KERN, KERN_MAXPROC}, maxproc;
size_t len = sizeof(maxproc);
diff --git a/src/libs/zbxsysinfo/osx/memory.c b/src/libs/zbxsysinfo/osx/memory.c
index d06bfb5d1e1..30f93fa71e8 100644
--- a/src/libs/zbxsysinfo/osx/memory.c
+++ b/src/libs/zbxsysinfo/osx/memory.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -49,7 +50,7 @@ static zbx_uint64_t memsize;
return SYSINFO_RET_FAIL; \
}
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
ZBX_SYSCTL(memsize);
@@ -58,7 +59,7 @@ static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
+static int vm_memory_active(AGENT_RESULT *result)
{
ZBX_HOST_STATISTICS(vm);
@@ -67,7 +68,7 @@ static int VM_MEMORY_ACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
+static int vm_memory_inactive(AGENT_RESULT *result)
{
ZBX_HOST_STATISTICS(vm);
@@ -76,7 +77,7 @@ static int VM_MEMORY_INACTIVE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_WIRED(AGENT_RESULT *result)
+static int vm_memory_wired(AGENT_RESULT *result)
{
ZBX_HOST_STATISTICS(vm);
@@ -85,7 +86,7 @@ static int VM_MEMORY_WIRED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_FREE(AGENT_RESULT *result)
+static int vm_memory_free(AGENT_RESULT *result)
{
ZBX_HOST_STATISTICS(vm);
@@ -94,7 +95,7 @@ static int VM_MEMORY_FREE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
ZBX_HOST_STATISTICS(vm);
@@ -103,7 +104,7 @@ static int VM_MEMORY_USED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
zbx_uint64_t used;
@@ -124,7 +125,7 @@ static int VM_MEMORY_PUSED(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
ZBX_HOST_STATISTICS(vm);
@@ -133,7 +134,7 @@ static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
zbx_uint64_t available;
@@ -154,7 +155,7 @@ static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode;
int ret = SYSINFO_RET_FAIL;
@@ -177,23 +178,23 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "active"))
- ret = VM_MEMORY_ACTIVE(result);
+ ret = vm_memory_active(result);
else if (0 == strcmp(mode, "inactive"))
- ret = VM_MEMORY_INACTIVE(result);
+ ret = vm_memory_inactive(result);
else if (0 == strcmp(mode, "wired"))
- ret = VM_MEMORY_WIRED(result);
+ ret = vm_memory_wired(result);
else if (0 == strcmp(mode, "free"))
- ret = VM_MEMORY_FREE(result);
+ ret = vm_memory_free(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/osx/net.c b/src/libs/zbxsysinfo/osx/net.c
index 465765bb812..975c336c7b2 100644
--- a/src/libs/zbxsysinfo/osx/net.c
+++ b/src/libs/zbxsysinfo/osx/net.c
@@ -17,8 +17,9 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "../common/zbxsysinfo_common.h"
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
+#include "../common/zbxsysinfo_common.h"
#include "zbxnum.h"
#include "log.h"
@@ -76,7 +77,7 @@ static int get_ifmib_general(const char *if_name, char **error)
return SYSINFO_RET_FAIL;
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
@@ -112,7 +113,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
@@ -146,7 +147,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode, *error;
@@ -180,7 +181,7 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *port_str, command[64];
unsigned short port;
@@ -202,7 +203,7 @@ int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_snprintf(command, sizeof(command), "netstat -an | grep '^tcp.*\\.%hu[^.].*LISTEN' | wc -l", port);
- if (SYSINFO_RET_FAIL == (ret = EXECUTE_INT(command, result)))
+ if (SYSINFO_RET_FAIL == (ret = execute_int(command, result)))
return ret;
if (1 < result->ui64)
@@ -211,7 +212,7 @@ int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *port_str, command[64];
unsigned short port;
@@ -233,7 +234,7 @@ int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_snprintf(command, sizeof(command), "netstat -an | grep '^udp.*\\.%hu[^.].*\\*\\.\\*' | wc -l", port);
- if (SYSINFO_RET_FAIL == (ret = EXECUTE_INT(command, result)))
+ if (SYSINFO_RET_FAIL == (ret = execute_int(command, result)))
return ret;
if (1 < result->ui64)
@@ -242,7 +243,7 @@ int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *error;
diff --git a/src/libs/zbxsysinfo/osx/osx.c b/src/libs/zbxsysinfo/osx/osx.c
index 78258234acb..f2a1ecc9140 100644
--- a/src/libs/zbxsysinfo/osx/osx.c
+++ b/src/libs/zbxsysinfo/osx/osx.c
@@ -18,37 +18,38 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"kernel.maxfiles", 0, KERNEL_MAXFILES, NULL},
- {"kernel.maxproc", 0, KERNEL_MAXPROC, NULL},
+ {"kernel.maxfiles", 0, kernel_maxfiles, NULL},
+ {"kernel.maxproc", 0, kernel_maxproc, NULL},
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/,free"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/,free"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"net.tcp.listen", CF_HAVEPARAMS, NET_TCP_LISTEN, "80"},
- {"net.udp.listen", CF_HAVEPARAMS, NET_UDP_LISTEN, "68"},
+ {"net.tcp.listen", CF_HAVEPARAMS, net_tcp_listen, "80"},
+ {"net.udp.listen", CF_HAVEPARAMS, net_udp_listen, "68"},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "en0,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "en0,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "en0,bytes"},
- {"net.if.collisions", CF_HAVEPARAMS, NET_IF_COLLISIONS, "en0"},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "en0,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "en0,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "en0,bytes"},
+ {"net.if.collisions", CF_HAVEPARAMS, net_if_collisions, "en0"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
- {"system.boottime", 0, SYSTEM_BOOTTIME, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
+ {"system.boottime", 0, system_boottime, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/osx/software.c b/src/libs/zbxsysinfo/osx/software.c
index 976ea09f03d..d7767b4ebb4 100644
--- a/src/libs/zbxsysinfo/osx/software.c
+++ b/src/libs/zbxsysinfo/osx/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/osx/system.c b/src/libs/zbxsysinfo/osx/system.c
index ec3f8896f84..fa2e315c4af 100644
--- a/src/libs/zbxsysinfo/osx/system.c
+++ b/src/libs/zbxsysinfo/osx/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/osx/uptime.c b/src/libs/zbxsysinfo/osx/uptime.c
index bb41a04883d..4157bfbdda9 100644
--- a/src/libs/zbxsysinfo/osx/uptime.c
+++ b/src/libs/zbxsysinfo/osx/uptime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int mib[] = {CTL_KERN, KERN_BOOTTIME};
struct timeval boottime;
diff --git a/src/libs/zbxsysinfo/simple/simple.c b/src/libs/zbxsysinfo/simple/simple.c
index 7ec090656e2..c36572c8a15 100644
--- a/src/libs/zbxsysinfo/simple/simple.c
+++ b/src/libs/zbxsysinfo/simple/simple.c
@@ -17,8 +17,9 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "simple.h"
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
+#include "simple.h"
#include "../common/net.h"
#include "ntp.h"
@@ -42,10 +43,10 @@
ZBX_METRIC parameters_simple[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"net.tcp.service", CF_HAVEPARAMS, CHECK_SERVICE, "ssh,127.0.0.1,22"},
- {"net.tcp.service.perf",CF_HAVEPARAMS, CHECK_SERVICE_PERF, "ssh,127.0.0.1,22"},
- {"net.udp.service", CF_HAVEPARAMS, CHECK_SERVICE, "ntp,127.0.0.1,123"},
- {"net.udp.service.perf",CF_HAVEPARAMS, CHECK_SERVICE_PERF, "ntp,127.0.0.1,123"},
+ {"net.tcp.service", CF_HAVEPARAMS, check_service, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_HAVEPARAMS, check_service_perf, "ssh,127.0.0.1,22"},
+ {"net.udp.service", CF_HAVEPARAMS, check_service, "ntp,127.0.0.1,123"},
+ {"net.udp.service.perf",CF_HAVEPARAMS, check_service_perf, "ntp,127.0.0.1,123"},
{NULL}
};
@@ -304,7 +305,7 @@ static int validate_imap(const char *line)
return 0 == strncmp(line, "* OK", 4) ? ZBX_TCP_EXPECT_OK : ZBX_TCP_EXPECT_FAIL;
}
-int check_service(AGENT_REQUEST *request, const char *default_addr, AGENT_RESULT *result, int perf)
+int zbx_check_service_default_addr(AGENT_REQUEST *request, const char *default_addr, AGENT_RESULT *result, int perf)
{
unsigned short port = 0;
char *service, *ip_str, ip[ZBX_MAX_DNSNAME_LEN + 1], *port_str;
@@ -492,12 +493,12 @@ int check_service(AGENT_REQUEST *request, const char *default_addr, AGENT_RESULT
* The old name for these checks is check_service[*].
*/
-int CHECK_SERVICE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int check_service(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return check_service(request, "127.0.0.1", result, 0);
+ return zbx_check_service_default_addr(request, "127.0.0.1", result, 0);
}
-int CHECK_SERVICE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result)
+int check_service_perf(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return check_service(request, "127.0.0.1", result, 1);
+ return zbx_check_service_default_addr(request, "127.0.0.1", result, 1);
}
diff --git a/src/libs/zbxsysinfo/simple/simple.h b/src/libs/zbxsysinfo/simple/simple.h
index 435bc845626..5ee767c8522 100644
--- a/src/libs/zbxsysinfo/simple/simple.h
+++ b/src/libs/zbxsysinfo/simple/simple.h
@@ -25,9 +25,7 @@
extern char *CONFIG_SOURCE_IP;
extern ZBX_METRIC parameters_simple[];
-int check_service(AGENT_REQUEST *request, const char *default_addr, AGENT_RESULT *result, int perf);
-
-int CHECK_SERVICE_PERF(AGENT_REQUEST *request, AGENT_RESULT *result);
-int CHECK_SERVICE(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service_perf(AGENT_REQUEST *request, AGENT_RESULT *result);
+int check_service(AGENT_REQUEST *request, AGENT_RESULT *result);
#endif /* ZABBIX_SYSINFO_SIMPLE_H */
diff --git a/src/libs/zbxsysinfo/solaris/boottime.c b/src/libs/zbxsysinfo/solaris/boottime.c
index 20786fd3fbd..635844f21e9 100644
--- a/src/libs/zbxsysinfo/solaris/boottime.c
+++ b/src/libs/zbxsysinfo/solaris/boottime.c
@@ -19,10 +19,11 @@
#include "zbxsysinfo.h"
#include "zbx_sysinfo_kstat.h"
+#include "../sysinfo.h"
#include "log.h"
-int SYSTEM_BOOTTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
diff --git a/src/libs/zbxsysinfo/solaris/cpu.c b/src/libs/zbxsysinfo/solaris/cpu.c
index c18da58e2cc..9142da5bf08 100644
--- a/src/libs/zbxsysinfo/solaris/cpu.c
+++ b/src/libs/zbxsysinfo/solaris/cpu.c
@@ -19,12 +19,13 @@
#include "zbxsysinfo.h"
#include "zbx_sysinfo_kstat.h"
+#include "../sysinfo.h"
#include "stats.h"
#include "log.h"
#include "zbxnum.h"
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int name;
@@ -59,7 +60,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num, state, mode;
@@ -156,7 +157,7 @@ close:
}
#endif
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
double value;
@@ -247,7 +248,7 @@ int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result)
{
kstat_ctl_t *kc;
kstat_t *k;
@@ -289,7 +290,7 @@ int SYSTEM_CPU_SWITCHES(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_INTR(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result)
{
kstat_ctl_t *kc;
kstat_t *k;
diff --git a/src/libs/zbxsysinfo/solaris/diskio.c b/src/libs/zbxsysinfo/solaris/diskio.c
index 544b40360a3..1d67c3d5974 100644
--- a/src/libs/zbxsysinfo/solaris/diskio.c
+++ b/src/libs/zbxsysinfo/solaris/diskio.c
@@ -107,7 +107,7 @@ clean:
return ret;
}
-static int VFS_DEV_READ_BYTES(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_read_bytes(const char *devname, AGENT_RESULT *result)
{
zbx_kstat_t zk;
char *error;
@@ -123,7 +123,7 @@ static int VFS_DEV_READ_BYTES(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_READ_OPERATIONS(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_read_operations(const char *devname, AGENT_RESULT *result)
{
zbx_kstat_t zk;
char *error;
@@ -139,7 +139,7 @@ static int VFS_DEV_READ_OPERATIONS(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_WRITE_BYTES(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_write_bytes(const char *devname, AGENT_RESULT *result)
{
zbx_kstat_t zk;
char *error;
@@ -155,7 +155,7 @@ static int VFS_DEV_WRITE_BYTES(const char *devname, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_DEV_WRITE_OPERATIONS(const char *devname, AGENT_RESULT *result)
+static int vfs_dev_write_operations(const char *devname, AGENT_RESULT *result)
{
zbx_kstat_t zk;
char *error;
@@ -210,24 +210,24 @@ static int process_mode_function(AGENT_REQUEST *request, AGENT_RESULT *result, c
return SYSINFO_RET_FAIL;
}
-int VFS_DEV_READ(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_read(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const MODE_FUNCTION fl[] =
{
- {"bytes", VFS_DEV_READ_BYTES},
- {"operations", VFS_DEV_READ_OPERATIONS},
+ {"bytes", vfs_dev_read_bytes},
+ {"operations", vfs_dev_read_operations},
{NULL, NULL}
};
return process_mode_function(request, result, fl);
}
-int VFS_DEV_WRITE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_dev_write(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const MODE_FUNCTION fl[] =
{
- {"bytes", VFS_DEV_WRITE_BYTES},
- {"operations", VFS_DEV_WRITE_OPERATIONS},
+ {"bytes", vfs_dev_write_bytes},
+ {"operations", vfs_dev_write_operations},
{NULL, NULL}
};
diff --git a/src/libs/zbxsysinfo/solaris/diskspace.c b/src/libs/zbxsysinfo/solaris/diskspace.c
index db889b709ae..708946a9d62 100644
--- a/src/libs/zbxsysinfo/solaris/diskspace.c
+++ b/src/libs/zbxsysinfo/solaris/diskspace.c
@@ -84,7 +84,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *f
#undef ZBX_STATFS
}
-static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_used(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -100,7 +100,7 @@ static int VFS_FS_USED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_free(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -116,7 +116,7 @@ static int VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_total(const char *fs, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -132,7 +132,7 @@ static int VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pfree(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -148,7 +148,7 @@ static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int vfs_fs_pused(const char *fs, AGENT_RESULT *result)
{
double value;
char *error;
@@ -164,7 +164,7 @@ static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode;
@@ -184,27 +184,27 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */
- return VFS_FS_TOTAL(fsname, result);
+ return vfs_fs_total(fsname, result);
if (0 == strcmp(mode, "free"))
- return VFS_FS_FREE(fsname, result);
+ return vfs_fs_free(fsname, result);
if (0 == strcmp(mode, "pfree"))
- return VFS_FS_PFREE(fsname, result);
+ return vfs_fs_pfree(fsname, result);
if (0 == strcmp(mode, "used"))
- return VFS_FS_USED(fsname, result);
+ return vfs_fs_used(fsname, result);
if (0 == strcmp(mode, "pused"))
- return VFS_FS_PUSED(fsname, result);
+ return vfs_fs_pused(fsname, result);
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
return SYSINFO_RET_FAIL;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct mnttab mt;
FILE *f;
@@ -240,7 +240,7 @@ int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct mnttab mt;
FILE *f;
@@ -352,7 +352,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/solaris/hostname.c b/src/libs/zbxsysinfo/solaris/hostname.c
index f17648f076e..2a8af85d14e 100644
--- a/src/libs/zbxsysinfo/solaris/hostname.c
+++ b/src/libs/zbxsysinfo/solaris/hostname.c
@@ -28,9 +28,9 @@
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
char *hostname;
diff --git a/src/libs/zbxsysinfo/solaris/inodes.c b/src/libs/zbxsysinfo/solaris/inodes.c
index 072bcd18836..5c7cc6bac73 100644
--- a/src/libs/zbxsysinfo/solaris/inodes.c
+++ b/src/libs/zbxsysinfo/solaris/inodes.c
@@ -17,8 +17,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "inodes.h"
#include "zbxsysinfo.h"
+#include "inodes.h"
#include "../sysinfo.h"
#include "log.h"
@@ -42,7 +42,6 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
zbx_strerror(errno));
return SYSINFO_RET_FAIL;
}
-
*itotal = (zbx_uint64_t)s.f_files;
*ifree = (zbx_uint64_t)s.ZBX_FFREE;
*iused = (zbx_uint64_t)(s.f_files - s.f_ffree);
@@ -66,7 +65,7 @@ int get_fs_inode_stat(const char *fs, zbx_uint64_t *itotal, zbx_uint64_t *ifree,
#undef ZBX_FFREE
}
-static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int vfs_fs_inode_local(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *fsname, *mode, *error;
zbx_uint64_t total, free, used;
@@ -122,7 +121,7 @@ static int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_inode, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_inode_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/solaris/kernel.c b/src/libs/zbxsysinfo/solaris/kernel.c
index ac4f50fefa5..abd194bf1ed 100644
--- a/src/libs/zbxsysinfo/solaris/kernel.c
+++ b/src/libs/zbxsysinfo/solaris/kernel.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
-int KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
kstat_ctl_t *kc;
diff --git a/src/libs/zbxsysinfo/solaris/memory.c b/src/libs/zbxsysinfo/solaris/memory.c
index fca95d9758a..0349a3991b9 100644
--- a/src/libs/zbxsysinfo/solaris/memory.c
+++ b/src/libs/zbxsysinfo/solaris/memory.c
@@ -17,9 +17,10 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "log.h"
-
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
+
+#include "log.h"
#define CHECKED_SYSCONF_SYSCALL(sysconf_name) \
errno = 0; \
@@ -35,7 +36,7 @@
#include "stats.h"
#endif
-static int VM_MEMORY_TOTAL(AGENT_RESULT *result)
+static int vm_memory_total(AGENT_RESULT *result)
{
int ret;
long res_SC_PHYS_PAGES, res_SC_PAGESIZE;
@@ -54,7 +55,7 @@ out:
}
#ifndef HAVE_VMINFO_T_UPDATES
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
int ret;
zbx_uint64_t used;
@@ -76,7 +77,7 @@ out:
return ret;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
int ret;
zbx_uint64_t used, total;
@@ -104,7 +105,7 @@ out:
return ret;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
int ret;
long res_SC_AVPHYS_PAGES, res_SC_PAGESIZE;
@@ -122,7 +123,7 @@ out:
return ret;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
int ret;
zbx_uint64_t total;
@@ -151,7 +152,7 @@ out:
#else /*HAVE_VMINFO_T_UPDATES*/
-static int VM_MEMORY_USED(AGENT_RESULT *result)
+static int vm_memory_used(AGENT_RESULT *result)
{
int ret;
zbx_uint64_t freemem;
@@ -184,7 +185,7 @@ out:
return ret;
}
-static int VM_MEMORY_PUSED(AGENT_RESULT *result)
+static int vm_memory_pused(AGENT_RESULT *result)
{
int ret;
zbx_uint64_t freemem, total;
@@ -227,7 +228,7 @@ out:
return ret;
}
-static int VM_MEMORY_AVAILABLE(AGENT_RESULT *result)
+static int vm_memory_available(AGENT_RESULT *result)
{
int ret;
zbx_uint64_t freemem;
@@ -255,7 +256,7 @@ out:
return ret;
}
-static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result)
+static int vm_memory_pavailable(AGENT_RESULT *result)
{
int ret;
zbx_uint64_t total, freemem;
@@ -299,7 +300,7 @@ out:
}
#endif /*HAVE_VMINFO_T_UPDATES*/
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *mode;
int ret;
@@ -316,15 +317,15 @@ int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
mode = get_rparam(request, 0);
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
- ret = VM_MEMORY_TOTAL(result);
+ ret = vm_memory_total(result);
else if (0 == strcmp(mode, "used"))
- ret = VM_MEMORY_USED(result);
+ ret = vm_memory_used(result);
else if (0 == strcmp(mode, "pused"))
- ret = VM_MEMORY_PUSED(result);
+ ret = vm_memory_pused(result);
else if (0 == strcmp(mode, "available") || 0 == strcmp(mode, "free"))
- ret = VM_MEMORY_AVAILABLE(result);
+ ret = vm_memory_available(result);
else if (0 == strcmp(mode, "pavailable"))
- ret = VM_MEMORY_PAVAILABLE(result);
+ ret = vm_memory_pavailable(result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter."));
diff --git a/src/libs/zbxsysinfo/solaris/net.c b/src/libs/zbxsysinfo/solaris/net.c
index aed08bdbfa4..904afe619df 100644
--- a/src/libs/zbxsysinfo/solaris/net.c
+++ b/src/libs/zbxsysinfo/solaris/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "../common/zbxsysinfo_common.h"
#include "zbx_sysinfo_kstat.h"
@@ -89,7 +90,7 @@ clean:
return ret;
}
-static int NET_IF_IN_BYTES(const char *if_name, AGENT_RESULT *result)
+static int net_if_in_bytes(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -110,7 +111,7 @@ static int NET_IF_IN_BYTES(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_IN_PACKETS(const char *if_name, AGENT_RESULT *result)
+static int net_if_in_packets(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -131,7 +132,7 @@ static int NET_IF_IN_PACKETS(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_IN_ERRORS(const char *if_name, AGENT_RESULT *result)
+static int net_if_in_errors(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -147,7 +148,7 @@ static int NET_IF_IN_ERRORS(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_OUT_BYTES(const char *if_name, AGENT_RESULT *result)
+static int net_if_out_bytes(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -168,7 +169,7 @@ static int NET_IF_OUT_BYTES(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_OUT_PACKETS(const char *if_name, AGENT_RESULT *result)
+static int net_if_out_packets(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -189,7 +190,7 @@ static int NET_IF_OUT_PACKETS(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_OUT_ERRORS(const char *if_name, AGENT_RESULT *result)
+static int net_if_out_errors(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *error;
@@ -205,7 +206,7 @@ static int NET_IF_OUT_ERRORS(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_TOTAL_BYTES(const char *if_name, AGENT_RESULT *result)
+static int net_if_total_bytes(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value_in, value_out;
char *error;
@@ -228,7 +229,7 @@ static int NET_IF_TOTAL_BYTES(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_TOTAL_PACKETS(const char *if_name, AGENT_RESULT *result)
+static int net_if_total_packets(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value_in, value_out;
char *error;
@@ -251,7 +252,7 @@ static int NET_IF_TOTAL_PACKETS(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int NET_IF_TOTAL_ERRORS(const char *if_name, AGENT_RESULT *result)
+static int net_if_total_errors(const char *if_name, AGENT_RESULT *result)
{
zbx_uint64_t value_in, value_out;
char *error;
@@ -268,7 +269,7 @@ static int NET_IF_TOTAL_ERRORS(const char *if_name, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t value;
char *if_name, *error;
@@ -298,7 +299,7 @@ int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *port_str, command[64];
unsigned short port;
@@ -320,7 +321,7 @@ int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_snprintf(command, sizeof(command), "netstat -an -P tcp | grep '\\.%hu[^.].*LISTEN' | wc -l", port);
- if (SYSINFO_RET_FAIL == (res = EXECUTE_INT(command, result)))
+ if (SYSINFO_RET_FAIL == (res = execute_int(command, result)))
return res;
if (1 < result->ui64)
@@ -329,7 +330,7 @@ int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
return res;
}
-int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *port_str, command[64];
unsigned short port;
@@ -351,7 +352,7 @@ int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
zbx_snprintf(command, sizeof(command), "netstat -an -P udp | grep '\\.%hu[^.].*Idle' | wc -l", port);
- if (SYSINFO_RET_FAIL == (res = EXECUTE_INT(command, result)))
+ if (SYSINFO_RET_FAIL == (res = execute_int(command, result)))
return res;
if (1 < result->ui64)
@@ -360,7 +361,7 @@ int NET_UDP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
return res;
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
int ret;
@@ -381,11 +382,11 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bytes"))
- ret = NET_IF_IN_BYTES(if_name, result);
+ ret = net_if_in_bytes(if_name, result);
else if (0 == strcmp(mode, "packets"))
- ret = NET_IF_IN_PACKETS(if_name, result);
+ ret = net_if_in_packets(if_name, result);
else if (0 == strcmp(mode, "errors"))
- ret = NET_IF_IN_ERRORS(if_name, result);
+ ret = net_if_in_errors(if_name, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
@@ -395,7 +396,7 @@ int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
int ret;
@@ -416,11 +417,11 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bytes"))
- ret = NET_IF_OUT_BYTES(if_name, result);
+ ret = net_if_out_bytes(if_name, result);
else if (0 == strcmp(mode, "packets"))
- ret = NET_IF_OUT_PACKETS(if_name, result);
+ ret = net_if_out_packets(if_name, result);
else if (0 == strcmp(mode, "errors"))
- ret = NET_IF_OUT_ERRORS(if_name, result);
+ ret = net_if_out_errors(if_name, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
@@ -430,7 +431,7 @@ int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
int ret;
@@ -451,11 +452,11 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
}
if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bytes"))
- ret = NET_IF_TOTAL_BYTES(if_name, result);
+ ret = net_if_total_bytes(if_name, result);
else if (0 == strcmp(mode, "packets"))
- ret = NET_IF_TOTAL_PACKETS(if_name, result);
+ ret = net_if_total_packets(if_name, result);
else if (0 == strcmp(mode, "errors"))
- ret = NET_IF_TOTAL_ERRORS(if_name, result);
+ ret = net_if_total_errors(if_name, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
@@ -465,7 +466,7 @@ int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return ret;
}
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct if_nameindex *ni;
struct zbx_json j;
diff --git a/src/libs/zbxsysinfo/solaris/proc.c b/src/libs/zbxsysinfo/solaris/proc.c
index 415a89dea48..af3c70f865d 100644
--- a/src/libs/zbxsysinfo/solaris/proc.c
+++ b/src/libs/zbxsysinfo/solaris/proc.c
@@ -388,7 +388,7 @@ static int proc_match_props(const zbx_sysinfo_proc_t *proc, const struct passwd
return SUCCEED;
}
-int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param, *memtype = NULL;
DIR *dir;
@@ -553,7 +553,7 @@ out:
return SYSINFO_RET_OK;
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param, *zone_parameter;
DIR *dir;
@@ -904,7 +904,7 @@ out:
zabbix_log(LOG_LEVEL_TRACE, "End of %s()", __func__);
}
-int PROC_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
const char *procname, *username, *cmdline, *tmp, *flags;
char *errmsg = NULL;
diff --git a/src/libs/zbxsysinfo/solaris/software.c b/src/libs/zbxsysinfo/solaris/software.c
index 976ea09f03d..d7767b4ebb4 100644
--- a/src/libs/zbxsysinfo/solaris/software.c
+++ b/src/libs/zbxsysinfo/solaris/software.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/solaris/solaris.c b/src/libs/zbxsysinfo/solaris/solaris.c
index a0bbc58000a..7081d124165 100644
--- a/src/libs/zbxsysinfo/solaris/solaris.c
+++ b/src/libs/zbxsysinfo/solaris/solaris.c
@@ -18,51 +18,52 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"kernel.maxproc", 0, KERNEL_MAXPROC, NULL},
+ {"kernel.maxproc", 0, kernel_maxproc, NULL},
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "/,free"},
- {"vfs.fs.inode", CF_HAVEPARAMS, VFS_FS_INODE, "/,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "/,free"},
+ {"vfs.fs.inode", CF_HAVEPARAMS, vfs_fs_inode, "/,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"vfs.dev.read", CF_HAVEPARAMS, VFS_DEV_READ, "sd0,operations"},
- {"vfs.dev.write", CF_HAVEPARAMS, VFS_DEV_WRITE, "sd0,operations"},
+ {"vfs.dev.read", CF_HAVEPARAMS, vfs_dev_read, "sd0,operations"},
+ {"vfs.dev.write", CF_HAVEPARAMS, vfs_dev_write, "sd0,operations"},
- {"net.tcp.listen", CF_HAVEPARAMS, NET_TCP_LISTEN, "80"},
- {"net.udp.listen", CF_HAVEPARAMS, NET_UDP_LISTEN, "68"},
+ {"net.tcp.listen", CF_HAVEPARAMS, net_tcp_listen, "80"},
+ {"net.udp.listen", CF_HAVEPARAMS, net_udp_listen, "68"},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "hme0,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "hme0,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "hme0,bytes"},
- {"net.if.collisions", CF_HAVEPARAMS, NET_IF_COLLISIONS, "hme0"},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, NULL},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "hme0,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "hme0,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "hme0,bytes"},
+ {"net.if.collisions", CF_HAVEPARAMS, net_if_collisions, "hme0"},
+ {"net.if.discovery", 0, net_if_discovery, NULL},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"proc.cpu.util", CF_HAVEPARAMS, PROC_CPU_UTIL, "inetd"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "inetd"},
- {"proc.mem", CF_HAVEPARAMS, PROC_MEM, "inetd"},
+ {"proc.cpu.util", CF_HAVEPARAMS, proc_cpu_util, "inetd"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "inetd"},
+ {"proc.mem", CF_HAVEPARAMS, proc_mem, "inetd"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, NULL},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, NULL},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,idle"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.switches", 0, system_cpu_switches, NULL},
+ {"system.cpu.intr", 0, system_cpu_intr, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,idle"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"system.swap.size", CF_HAVEPARAMS, SYSTEM_SWAP_SIZE, "all,free"},
- {"system.swap.in", CF_HAVEPARAMS, SYSTEM_SWAP_IN, "all"},
- {"system.swap.out", CF_HAVEPARAMS, SYSTEM_SWAP_OUT, "all,count"},
+ {"system.swap.size", CF_HAVEPARAMS, system_swap_size, "all,free"},
+ {"system.swap.in", CF_HAVEPARAMS, system_swap_in, "all"},
+ {"system.swap.out", CF_HAVEPARAMS, system_swap_out, "all,count"},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
- {"system.boottime", 0, SYSTEM_BOOTTIME, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
+ {"system.boottime", 0, system_boottime, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/solaris/swap.c b/src/libs/zbxsysinfo/solaris/swap.c
index fa596fa8426..b623e0f7c42 100644
--- a/src/libs/zbxsysinfo/solaris/swap.c
+++ b/src/libs/zbxsysinfo/solaris/swap.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -105,7 +106,7 @@ finish:
return ret;
}
-static int SYSTEM_SWAP_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int system_swap_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t total, free1;
char *error;
@@ -121,7 +122,7 @@ static int SYSTEM_SWAP_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_USED(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int system_swap_used(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t total, free1;
char *error;
@@ -137,7 +138,7 @@ static int SYSTEM_SWAP_USED(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_FREE(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int system_swap_free(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t total, free1;
char *error;
@@ -153,7 +154,7 @@ static int SYSTEM_SWAP_FREE(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_PUSED(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int system_swap_pused(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t total, free1;
char *error;
@@ -172,7 +173,7 @@ static int SYSTEM_SWAP_PUSED(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_SWAP_PFREE(AGENT_REQUEST *request, AGENT_RESULT *result)
+static int system_swap_pfree(AGENT_REQUEST *request, AGENT_RESULT *result)
{
zbx_uint64_t total, free1;
char *error;
@@ -191,7 +192,7 @@ static int SYSTEM_SWAP_PFREE(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int ret;
@@ -213,15 +214,15 @@ int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
tmp = get_rparam(request, 1);
if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "free")) /* default parameter */
- ret = SYSTEM_SWAP_FREE(request, result);
+ ret = system_swap_free(request, result);
else if (0 == strcmp(tmp, "total"))
- ret = SYSTEM_SWAP_TOTAL(request, result);
+ ret = system_swap_total(request, result);
else if (0 == strcmp(tmp, "used"))
- ret = SYSTEM_SWAP_USED(request, result);
+ ret = system_swap_used(request, result);
else if (0 == strcmp(tmp, "pfree"))
- ret = SYSTEM_SWAP_PFREE(request, result);
+ ret = system_swap_pfree(request, result);
else if (0 == strcmp(tmp, "pused"))
- ret = SYSTEM_SWAP_PUSED(request, result);
+ ret = system_swap_pused(request, result);
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
@@ -299,7 +300,7 @@ clean:
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret;
char *tmp, *error;
@@ -339,7 +340,7 @@ int SYSTEM_SWAP_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret;
char *tmp, *error;
diff --git a/src/libs/zbxsysinfo/solaris/system.c b/src/libs/zbxsysinfo/solaris/system.c
index ec3f8896f84..fa2e315c4af 100644
--- a/src/libs/zbxsysinfo/solaris/system.c
+++ b/src/libs/zbxsysinfo/solaris/system.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -25,7 +26,7 @@
# include <sys/utsname.h>
#endif
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct utsname name;
diff --git a/src/libs/zbxsysinfo/solaris/uptime.c b/src/libs/zbxsysinfo/solaris/uptime.c
index d362919a15d..96a12e19860 100644
--- a/src/libs/zbxsysinfo/solaris/uptime.c
+++ b/src/libs/zbxsysinfo/solaris/uptime.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- if (SYSINFO_RET_OK == SYSTEM_BOOTTIME(request, result))
+ if (SYSINFO_RET_OK == system_boottime(request, result))
{
time_t now;
diff --git a/src/libs/zbxsysinfo/sysinfo.c b/src/libs/zbxsysinfo/sysinfo.c
index 167c135e0a6..d7cb9a18c75 100644
--- a/src/libs/zbxsysinfo/sysinfo.c
+++ b/src/libs/zbxsysinfo/sysinfo.c
@@ -186,7 +186,7 @@ int zbx_add_user_parameter(const char *itemkey, char *command, char *error, size
{
metric.key = get_rkey(&request);
metric.flags = flags;
- metric.function = &EXECUTE_USER_PARAMETER;
+ metric.function = &execute_user_parameter;
metric.test_param = command;
ret = zbx_add_metric(&metric, error, max_error_len);
diff --git a/src/libs/zbxsysinfo/sysinfo.h b/src/libs/zbxsysinfo/sysinfo.h
index 7c2a2a59a82..ba6474293a9 100644
--- a/src/libs/zbxsysinfo/sysinfo.h
+++ b/src/libs/zbxsysinfo/sysinfo.h
@@ -119,4 +119,77 @@ zbx_mntopt_t;
char *zbx_format_mntopt_string(zbx_mntopt_t mntopts[], int flags);
#endif
+/* external system functions */
+int get_sensor(AGENT_REQUEST *request, AGENT_RESULT *result);
+int kernel_maxfiles(AGENT_REQUEST *request, AGENT_RESULT *result);
+int kernel_maxproc(AGENT_REQUEST *request, AGENT_RESULT *result);
+int kernel_openfiles(AGENT_REQUEST *request, AGENT_RESULT *result);
+
+#ifdef ZBX_PROCSTAT_COLLECTOR
+int proc_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result);
+#endif
+
+int proc_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int proc_mem(AGENT_REQUEST *request, AGENT_RESULT *result);
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_if_collisions(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_tcp_socket_count(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_udp_listen(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_udp_socket_count(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_switches(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_intr(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_cpu_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_chassis(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_cpu(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_devices(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_hw_macaddr(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_sw_os(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_sw_packages(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_in(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_out(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result);
+int system_boottime(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dev_read(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dev_write(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_dev_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_inode(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+
+#if defined(_WINDOWS) || defined(__MINGW32__)
+int user_perf_counter(AGENT_REQUEST *request, AGENT_RESULT *result);
+int perf_counter(AGENT_REQUEST *request, AGENT_RESULT *result);
+int perf_counter_en(AGENT_REQUEST *request, AGENT_RESULT *result);
+int perf_instance_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int perf_instance_discovery_en(AGENT_REQUEST *request, AGENT_RESULT *result);
+int service_discovery(AGENT_REQUEST *request, AGENT_RESULT *result);
+int service_info(AGENT_REQUEST *request, AGENT_RESULT *result);
+int service_state(AGENT_REQUEST *request, AGENT_RESULT *result);
+int services(AGENT_REQUEST *request, AGENT_RESULT *result);
+int proc_info(AGENT_REQUEST *request, AGENT_RESULT *result);
+int net_if_list(AGENT_REQUEST *request, AGENT_RESULT *result);
+int wmi_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+int wmi_getall(AGENT_REQUEST *request, AGENT_RESULT *result);
+int vm_vmemory_size(AGENT_REQUEST *request, AGENT_RESULT *result);
+int registry_data(AGENT_REQUEST *request, AGENT_RESULT *result);
+int registry_get(AGENT_REQUEST *request, AGENT_RESULT *result);
+#endif
+
+#ifdef _AIX
+int system_stat(AGENT_REQUEST *request, AGENT_RESULT *result);
+#endif
#endif /* ZABBIX_SYSINFO_H */
diff --git a/src/libs/zbxsysinfo/unknown/hostname.c b/src/libs/zbxsysinfo/unknown/hostname.c
index 7aba9204d81..51e63192710 100644
--- a/src/libs/zbxsysinfo/unknown/hostname.c
+++ b/src/libs/zbxsysinfo/unknown/hostname.c
@@ -18,12 +18,13 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", 0, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", 0, system_hostname, NULL};
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Not supported because the system is unknown."));
diff --git a/src/libs/zbxsysinfo/win32/cpu.c b/src/libs/zbxsysinfo/win32/cpu.c
index 9a45638310a..321f824d4a7 100644
--- a/src/libs/zbxsysinfo/win32/cpu.c
+++ b/src/libs/zbxsysinfo/win32/cpu.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
@@ -209,7 +210,7 @@ finish:
return numa_node_count;
}
-int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp;
int cpu_num;
@@ -238,7 +239,7 @@ int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_util(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp, *error = NULL;
int cpu_num, interval;
@@ -301,7 +302,7 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_FAIL;
}
-int SYSTEM_CPU_LOAD(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_cpu_load(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *tmp, *error = NULL;
double value;
diff --git a/src/libs/zbxsysinfo/win32/diskspace.c b/src/libs/zbxsysinfo/win32/diskspace.c
index 80b475a96f7..40c94df7ead 100644
--- a/src/libs/zbxsysinfo/win32/diskspace.c
+++ b/src/libs/zbxsysinfo/win32/diskspace.c
@@ -95,7 +95,7 @@ static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *n
}
-static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
+static int vfs_fs_size_local(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
{
char *path, *mode;
char *error;
@@ -146,9 +146,9 @@ static int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE time
return SYSINFO_RET_OK;
}
-int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_size, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_size_local, request, result);
}
static const char *get_drive_type_string(UINT type)
@@ -334,7 +334,7 @@ out:
#undef zbx_wcsdup
}
-int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
struct zbx_json j;
int i, ret = SYSINFO_RET_FAIL;
@@ -379,7 +379,7 @@ out:
return ret;
}
-static int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
+static int vfs_fs_get_local(AGENT_REQUEST *request, AGENT_RESULT *result, HANDLE timeout_event)
{
size_t sz;
struct zbx_json j;
@@ -464,7 +464,7 @@ out:
return ret;
}
-int VFS_FS_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vfs_fs_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
- return zbx_execute_threaded_metric(vfs_fs_get, request, result);
+ return zbx_execute_threaded_metric(vfs_fs_get_local, request, result);
}
diff --git a/src/libs/zbxsysinfo/win32/hostname.c b/src/libs/zbxsysinfo/win32/hostname.c
index 7fdbe3ac9c5..dc556112178 100644
--- a/src/libs/zbxsysinfo/win32/hostname.c
+++ b/src/libs/zbxsysinfo/win32/hostname.c
@@ -18,13 +18,14 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
#include "zbxstr.h"
ZBX_METRIC parameter_hostname =
/* KEY FLAG FUNCTION TEST PARAMETERS */
- {"system.hostname", CF_HAVEPARAMS, SYSTEM_HOSTNAME, NULL};
+ {"system.hostname", CF_HAVEPARAMS, system_hostname, NULL};
static void retrieve_hostname(char *buffer, int len, char **error)
{
@@ -35,7 +36,7 @@ static void retrieve_hostname(char *buffer, int len, char **error)
}
}
-int SYSTEM_HOSTNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_hostname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
DWORD dwSize = 256;
wchar_t computerName[256];
diff --git a/src/libs/zbxsysinfo/win32/memory.c b/src/libs/zbxsysinfo/win32/memory.c
index ccd9f7dc40d..7dfbdf8c69f 100644
--- a/src/libs/zbxsysinfo/win32/memory.c
+++ b/src/libs/zbxsysinfo/win32/memory.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxsymbols.h"
-int VM_MEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_memory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
PERFORMANCE_INFORMATION pfi;
MEMORYSTATUSEX ms_ex;
diff --git a/src/libs/zbxsysinfo/win32/net.c b/src/libs/zbxsysinfo/win32/net.c
index cbe61a948cb..bdbdbdcee31 100644
--- a/src/libs/zbxsysinfo/win32/net.c
+++ b/src/libs/zbxsysinfo/win32/net.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxstr.h"
#include "zbxnum.h"
@@ -426,7 +427,7 @@ clean:
return ret;
}
-int NET_IF_IN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_in(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
zbx_ifrow_t ifrow = {NULL, NULL};
@@ -476,7 +477,7 @@ clean:
return ret;
}
-int NET_IF_OUT(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_out(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
zbx_ifrow_t ifrow = {NULL, NULL};
@@ -526,7 +527,7 @@ clean:
return ret;
}
-int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_total(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *if_name, *mode;
zbx_ifrow_t ifrow = {NULL, NULL};
@@ -578,7 +579,7 @@ clean:
return ret;
}
-int NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
DWORD dwSize, dwRetVal, i;
int ret = SYSINFO_RET_FAIL;
@@ -678,7 +679,7 @@ static char *get_if_adminstatus_string(DWORD status)
}
}
-int NET_IF_LIST(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_if_list(AGENT_REQUEST *request, AGENT_RESULT *result)
{
DWORD dwSize, dwRetVal, i, j;
char *buf = NULL;
@@ -784,7 +785,7 @@ clean:
return ret;
}
-int NET_TCP_LISTEN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int net_tcp_listen(AGENT_REQUEST *request, AGENT_RESULT *result)
{
MIB_TCPTABLE *pTcpTable = NULL;
DWORD dwSize, dwRetVal;
diff --git a/src/libs/zbxsysinfo/win32/pdhmon.c b/src/libs/zbxsysinfo/win32/pdhmon.c
index a055996b84d..2f2cdb4cdfc 100644
--- a/src/libs/zbxsysinfo/win32/pdhmon.c
+++ b/src/libs/zbxsysinfo/win32/pdhmon.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxstr.h"
#include "zbxthreads.h"
@@ -27,7 +28,7 @@
#include "perfstat.h"
-int USER_PERF_COUNTER(AGENT_REQUEST *request, AGENT_RESULT *result)
+int user_perf_counter(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int ret = SYSINFO_RET_FAIL;
char *counter, *error = NULL;
@@ -103,7 +104,7 @@ static int perf_counter_ex(const char *function, AGENT_REQUEST *request, AGENT_R
goto out;
}
- if (FAIL == check_counter_path(counterpath, PERF_COUNTER_LANG_DEFAULT == lang))
+ if (FAIL == zbx_check_counter_path(counterpath, PERF_COUNTER_LANG_DEFAULT == lang))
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid performance counter path."));
goto out;
@@ -124,12 +125,12 @@ out:
return ret;
}
-int PERF_COUNTER(AGENT_REQUEST *request, AGENT_RESULT *result)
+int perf_counter(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return perf_counter_ex(__func__, request, result, PERF_COUNTER_LANG_DEFAULT);
}
-int PERF_COUNTER_EN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int perf_counter_en(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return perf_counter_ex(__func__, request, result, PERF_COUNTER_LANG_EN);
}
@@ -254,12 +255,12 @@ err:
return ret;
}
-int PERF_INSTANCE_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int perf_instance_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return perf_instance_discovery_ex(__func__, request, result, PERF_COUNTER_LANG_DEFAULT);
}
-int PERF_INSTANCE_DISCOVERY_EN(AGENT_REQUEST *request, AGENT_RESULT *result)
+int perf_instance_discovery_en(AGENT_REQUEST *request, AGENT_RESULT *result)
{
return perf_instance_discovery_ex(__func__, request, result, PERF_COUNTER_LANG_EN);
}
diff --git a/src/libs/zbxsysinfo/win32/proc.c b/src/libs/zbxsysinfo/win32/proc.c
index c8abb62b634..ed7babb04d1 100644
--- a/src/libs/zbxsysinfo/win32/proc.c
+++ b/src/libs/zbxsysinfo/win32/proc.c
@@ -73,7 +73,10 @@ static int zbx_get_process_username(HANDLE hProcess, char *userName, char *sid)
int iUse, res = FAIL;
/* clean result; */
- *userName = *sid = '\0';
+ *userName = '\0';
+
+ if (NULL != sid)
+ *sid = '\0';
/* open the processes token */
if (0 == OpenProcessToken(hProcess, TOKEN_QUERY, &tok))
@@ -119,7 +122,7 @@ lbl_err:
return res;
}
-int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_num(AGENT_REQUEST *request, AGENT_RESULT *result)
{
HANDLE hProcessSnap, hProcess;
PROCESSENTRY32 pe32;
@@ -340,7 +343,7 @@ static int GetProcessAttribute(HANDLE hProcess, int attr, int type, int count, d
* avg - average value for all processes named <process>
* sum - sum of values for all processes named <process>
*/
-int PROC_INFO(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_info(AGENT_REQUEST *request, AGENT_RESULT *result)
{
HANDLE hProcessSnap, hProcess;
PROCESSENTRY32 pe32;
@@ -478,7 +481,7 @@ static void proc_data_free(proc_data_t *proc_data)
zbx_free(proc_data);
}
-int PROC_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int proc_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define SUM_PROC_VALUE_DBL(param) \
do \
diff --git a/src/libs/zbxsysinfo/win32/registry.c b/src/libs/zbxsysinfo/win32/registry.c
index e8436572503..83f1bb076b9 100644
--- a/src/libs/zbxsysinfo/win32/registry.c
+++ b/src/libs/zbxsysinfo/win32/registry.c
@@ -18,7 +18,9 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
+#include "zbxstr.h"
#include "base64.h"
#include "zbxjson.h"
#include "zbxalgo.h"
@@ -404,7 +406,7 @@ out:
return ret;
}
-int REGISTRY_DATA(AGENT_REQUEST *request, AGENT_RESULT *result)
+int registry_data(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *regkey, *value_name;
@@ -430,7 +432,7 @@ int REGISTRY_DATA(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int REGISTRY_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+int registry_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *pkey, *pmode, *regexp;
int mode;
diff --git a/src/libs/zbxsysinfo/win32/services.c b/src/libs/zbxsysinfo/win32/services.c
index f9a26c6ac85..05ed85f0ea4 100644
--- a/src/libs/zbxsysinfo/win32/services.c
+++ b/src/libs/zbxsysinfo/win32/services.c
@@ -18,6 +18,7 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxstr.h"
#include "log.h"
@@ -253,7 +254,7 @@ static zbx_startup_type_t get_service_startup_type(SC_HANDLE h_srv, QUERY_SERVIC
}
}
-int SERVICE_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
+int service_discovery(AGENT_REQUEST *request, AGENT_RESULT *result)
{
ENUM_SERVICE_STATUS_PROCESS *ssp = NULL;
SC_HANDLE h_mgr;
@@ -390,7 +391,7 @@ next:
return SYSINFO_RET_OK;
}
-int SERVICE_INFO(AGENT_REQUEST *request, AGENT_RESULT *result)
+int service_info(AGENT_REQUEST *request, AGENT_RESULT *result)
{
#define ZBX_SRV_PARAM_STATE 0x01
#define ZBX_SRV_PARAM_DISPLAYNAME 0x02
@@ -549,7 +550,7 @@ int SERVICE_INFO(AGENT_REQUEST *request, AGENT_RESULT *result)
#undef ZBX_NON_EXISTING_SRV
}
-int SERVICE_STATE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int service_state(AGENT_REQUEST *request, AGENT_RESULT *result)
{
SC_HANDLE mgr, service;
char *name;
@@ -698,7 +699,7 @@ static int check_service_state(SC_HANDLE h_srv, int service_state)
return FAIL;
}
-int SERVICES(AGENT_REQUEST *request, AGENT_RESULT *result)
+int services(AGENT_REQUEST *request, AGENT_RESULT *result)
{
int start_type, service_state;
char *type, *state, *exclude, *buf = NULL, *utf8;
@@ -810,17 +811,3 @@ int SERVICES(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-#undef ZBX_SRV_STARTTYPE_ALL
-#undef ZBX_SRV_STARTTYPE_AUTOMATIC
-#undef ZBX_SRV_STARTTYPE_MANUAL
-#undef ZBX_SRV_STARTTYPE_DISABLED
-
-#undef ZBX_SRV_STATE_STOPPED 0x0001
-#undef ZBX_SRV_STATE_START_PENDING 0x0002
-#undef ZBX_SRV_STATE_STOP_PENDING 0x0004
-#undef ZBX_SRV_STATE_RUNNING 0x0008
-#undef ZBX_SRV_STATE_CONTINUE_PENDING 0x0010
-#undef ZBX_SRV_STATE_PAUSE_PENDING 0x0020
-#undef ZBX_SRV_STATE_PAUSED 0x0040
-#undef ZBX_SRV_STATE_STARTED 0x007e
-#undef ZBX_SRV_STATE_ALL 0x007f
diff --git a/src/libs/zbxsysinfo/win32/software.c b/src/libs/zbxsysinfo/win32/software.c
index 9c88f065e3a..f53891c81ee 100644
--- a/src/libs/zbxsysinfo/win32/software.c
+++ b/src/libs/zbxsysinfo/win32/software.c
@@ -18,8 +18,9 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
-int SYSTEM_SW_ARCH(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_sw_arch(AGENT_REQUEST *request, AGENT_RESULT *result)
{
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
diff --git a/src/libs/zbxsysinfo/win32/swap.c b/src/libs/zbxsysinfo/win32/swap.c
index 801371d0b3d..72e3b90ccc4 100644
--- a/src/libs/zbxsysinfo/win32/swap.c
+++ b/src/libs/zbxsysinfo/win32/swap.c
@@ -18,10 +18,11 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxsymbols.h"
-int VM_VMEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int vm_vmemory_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
MEMORYSTATUSEX ms_ex;
MEMORYSTATUS ms;
@@ -72,7 +73,7 @@ int VM_VMEMORY_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_swap_size(AGENT_REQUEST *request, AGENT_RESULT *result)
{
MEMORYSTATUSEX ms_ex;
MEMORYSTATUS ms;
diff --git a/src/libs/zbxsysinfo/win32/system.c b/src/libs/zbxsysinfo/win32/system.c
index 565da5ad96c..cc35553090c 100644
--- a/src/libs/zbxsysinfo/win32/system.c
+++ b/src/libs/zbxsysinfo/win32/system.c
@@ -18,12 +18,13 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "log.h"
#include "cfg.h"
#include "zbxtime.h"
-#include "perfmon.h"
+#include "zbxwin32.h"
#pragma comment(lib, "user32.lib")
@@ -169,7 +170,7 @@ static void get_wmi_check_timeout(const char *wmi_namespace, const char *query,
*time_previous_query_finished = zbx_time();
}
-int SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uname(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *os = NULL;
size_t os_alloc = 0, os_offset = 0;
diff --git a/src/libs/zbxsysinfo/win32/uptime.c b/src/libs/zbxsysinfo/win32/uptime.c
index fca4d803b9d..d264c3c9f61 100644
--- a/src/libs/zbxsysinfo/win32/uptime.c
+++ b/src/libs/zbxsysinfo/win32/uptime.c
@@ -18,24 +18,25 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
-#include "perfmon.h"
+#include "zbxwin32.h"
-int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result)
+int system_uptime(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char counter_path[64];
AGENT_REQUEST request_tmp;
int ret;
zbx_snprintf(counter_path, sizeof(counter_path), "\\%u\\%u",
- (unsigned int)get_builtin_object_index(PCI_SYSTEM_UP_TIME),
- (unsigned int)get_builtin_counter_index(PCI_SYSTEM_UP_TIME));
+ (unsigned int)zbx_get_builtin_object_index(PCI_SYSTEM_UP_TIME),
+ (unsigned int)zbx_get_builtin_counter_index(PCI_SYSTEM_UP_TIME));
request_tmp.nparam = 1;
request_tmp.params = zbx_malloc(NULL, request_tmp.nparam * sizeof(char *));
request_tmp.params[0] = counter_path;
- ret = PERF_COUNTER(&request_tmp, result);
+ ret = perf_counter(&request_tmp, result);
zbx_free(request_tmp.params);
diff --git a/src/libs/zbxsysinfo/win32/win32.c b/src/libs/zbxsysinfo/win32/win32.c
index cd378909562..3357f46d566 100644
--- a/src/libs/zbxsysinfo/win32/win32.c
+++ b/src/libs/zbxsysinfo/win32/win32.c
@@ -18,62 +18,63 @@
**/
#include "zbxsysinfo.h"
+#include "../sysinfo.h"
#include "zbxwinservice.h"
ZBX_METRIC parameters_specific[] =
/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"vfs.fs.size", CF_HAVEPARAMS, VFS_FS_SIZE, "c:,free"},
- {"vfs.fs.discovery", 0, VFS_FS_DISCOVERY, NULL},
- {"vfs.fs.get", 0, VFS_FS_GET, NULL},
+ {"vfs.fs.size", CF_HAVEPARAMS, vfs_fs_size, "c:,free"},
+ {"vfs.fs.discovery", 0, vfs_fs_discovery, NULL},
+ {"vfs.fs.get", 0, vfs_fs_get, NULL},
- {"net.tcp.listen", CF_HAVEPARAMS, NET_TCP_LISTEN, "80"},
+ {"net.tcp.listen", CF_HAVEPARAMS, net_tcp_listen, "80"},
- {"net.if.in", CF_HAVEPARAMS, NET_IF_IN, "MS TCP Loopback interface,bytes"},
- {"net.if.out", CF_HAVEPARAMS, NET_IF_OUT, "MS TCP Loopback interface,bytes"},
- {"net.if.total", CF_HAVEPARAMS, NET_IF_TOTAL, "MS TCP Loopback interface,bytes"},
- {"net.if.discovery", 0, NET_IF_DISCOVERY, NULL},
- {"net.if.list", 0, NET_IF_LIST, NULL},
+ {"net.if.in", CF_HAVEPARAMS, net_if_in, "MS TCP Loopback interface,bytes"},
+ {"net.if.out", CF_HAVEPARAMS, net_if_out, "MS TCP Loopback interface,bytes"},
+ {"net.if.total", CF_HAVEPARAMS, net_if_total, "MS TCP Loopback interface,bytes"},
+ {"net.if.discovery", 0, net_if_discovery, NULL},
+ {"net.if.list", 0, net_if_list, NULL},
- {"vm.memory.size", CF_HAVEPARAMS, VM_MEMORY_SIZE, "free"},
+ {"vm.memory.size", CF_HAVEPARAMS, vm_memory_size, "free"},
- {"proc.get", CF_HAVEPARAMS, PROC_GET, "svchost.exe"},
- {"proc.num", CF_HAVEPARAMS, PROC_NUM, "svchost.exe"},
+ {"proc.get", CF_HAVEPARAMS, proc_get, "svchost.exe"},
+ {"proc.num", CF_HAVEPARAMS, proc_num, "svchost.exe"},
- {"system.cpu.util", CF_HAVEPARAMS, SYSTEM_CPU_UTIL, "all,system,avg1"},
- {"system.cpu.load", CF_HAVEPARAMS, SYSTEM_CPU_LOAD, "all,avg1"},
- {"system.cpu.num", CF_HAVEPARAMS, SYSTEM_CPU_NUM, "online"},
- {"system.cpu.discovery",0, SYSTEM_CPU_DISCOVERY, NULL},
+ {"system.cpu.util", CF_HAVEPARAMS, system_cpu_util, "all,system,avg1"},
+ {"system.cpu.load", CF_HAVEPARAMS, system_cpu_load, "all,avg1"},
+ {"system.cpu.num", CF_HAVEPARAMS, system_cpu_num, "online"},
+ {"system.cpu.discovery",0, system_cpu_discovery, NULL},
- {"system.sw.arch", 0, SYSTEM_SW_ARCH, NULL},
+ {"system.sw.arch", 0, system_sw_arch, NULL},
- {"system.swap.size", CF_HAVEPARAMS, SYSTEM_SWAP_SIZE, "all,free"},
- {"vm.vmemory.size", CF_HAVEPARAMS, VM_VMEMORY_SIZE, "total"},
+ {"system.swap.size", CF_HAVEPARAMS, system_swap_size, "all,free"},
+ {"vm.vmemory.size", CF_HAVEPARAMS, vm_vmemory_size, "total"},
- {"system.uptime", 0, SYSTEM_UPTIME, NULL},
+ {"system.uptime", 0, system_uptime, NULL},
- {"system.uname", 0, SYSTEM_UNAME, NULL},
+ {"system.uname", 0, system_uname, NULL},
- {"service.discovery", 0, SERVICE_DISCOVERY, NULL},
- {"service.info", CF_HAVEPARAMS, SERVICE_INFO, ZABBIX_SERVICE_NAME},
- {"service_state", CF_HAVEPARAMS, SERVICE_STATE, ZABBIX_SERVICE_NAME},
- {"services", CF_HAVEPARAMS, SERVICES, NULL},
- {"perf_counter", CF_HAVEPARAMS, PERF_COUNTER, "\\System\\Processes"},
- {"perf_counter_en", CF_HAVEPARAMS, PERF_COUNTER_EN, "\\System\\Processes"},
- {"perf_instance.discovery", CF_HAVEPARAMS, PERF_INSTANCE_DISCOVERY, "Processor"},
- {"perf_instance_en.discovery", CF_HAVEPARAMS, PERF_INSTANCE_DISCOVERY_EN, "Processor"},
- {"proc_info", CF_HAVEPARAMS, PROC_INFO, "svchost.exe"},
+ {"service.discovery", 0, service_discovery, NULL},
+ {"service.info", CF_HAVEPARAMS, service_info, ZABBIX_SERVICE_NAME},
+ {"service_state", CF_HAVEPARAMS, service_state, ZABBIX_SERVICE_NAME},
+ {"services", CF_HAVEPARAMS, services, NULL},
+ {"perf_counter", CF_HAVEPARAMS, perf_counter, "\\System\\Processes"},
+ {"perf_counter_en", CF_HAVEPARAMS, perf_counter_en, "\\System\\Processes"},
+ {"perf_instance.discovery", CF_HAVEPARAMS, perf_instance_discovery, "Processor"},
+ {"perf_instance_en.discovery", CF_HAVEPARAMS, perf_instance_discovery_en, "Processor"},
+ {"proc_info", CF_HAVEPARAMS, proc_info, "svchost.exe"},
- {"__UserPerfCounter", CF_HAVEPARAMS, USER_PERF_COUNTER, ""},
+ {"__UserPerfCounter", CF_HAVEPARAMS, user_perf_counter, ""},
- {"wmi.get", CF_HAVEPARAMS, WMI_GET,
+ {"wmi.get", CF_HAVEPARAMS, wmi_get,
"root\\cimv2,select Caption from Win32_OperatingSystem"},
- {"wmi.getall", CF_HAVEPARAMS, WMI_GETALL,
+ {"wmi.getall", CF_HAVEPARAMS, wmi_getall,
"root\\cimv2,select * from Win32_OperatingSystem"},
- {"registry.data", CF_HAVEPARAMS, REGISTRY_DATA, NULL},
- {"registry.get", CF_HAVEPARAMS, REGISTRY_GET, NULL},
+ {"registry.data", CF_HAVEPARAMS, registry_data, NULL},
+ {"registry.get", CF_HAVEPARAMS, registry_get, NULL},
{NULL}
};
diff --git a/src/libs/zbxsysinfo/win32/wmi.cpp b/src/libs/zbxsysinfo/win32/wmi.cpp
index 2c9554c8d3c..98e69bac658 100644
--- a/src/libs/zbxsysinfo/win32/wmi.cpp
+++ b/src/libs/zbxsysinfo/win32/wmi.cpp
@@ -479,7 +479,7 @@ out:
* SYSINFO_RET_FAIL - retrieving WMI value failed *
* *
******************************************************************************/
-extern "C" int WMI_GET(AGENT_REQUEST *request, AGENT_RESULT *result)
+extern "C" int wmi_get(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *wmi_namespace, *wmi_query, *error = NULL;
VARIANT *vtProp;
@@ -942,7 +942,7 @@ extern "C" int convert_wmi_json(zbx_vector_wmi_instance_t *wmi_values, char **js
* SYSINFO_RET_FAIL - retrieving WMI value failed *
* *
******************************************************************************/
-extern "C" int WMI_GETALL(AGENT_REQUEST *request, AGENT_RESULT *result)
+extern "C" int wmi_getall(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *wmi_namespace, *wmi_query, *jd = NULL, *error = NULL;
int ret = SYSINFO_RET_FAIL;
diff --git a/src/libs/zbxtime/time.c b/src/libs/zbxtime/time.c
index d961eb1d595..01efdc4ec85 100644
--- a/src/libs/zbxtime/time.c
+++ b/src/libs/zbxtime/time.c
@@ -1021,3 +1021,141 @@ char *zbx_time2str(time_t time, const char *tz)
tm->tm_sec);
return buffer;
}
+
+/******************************************************************************
+ * *
+ * Purpose: convert string from iso8601 timezone info to offset in seconds *
+ * *
+ * Parameters: zone - [IN] iso8601 timezone string *
+ * offset - [OUT] offset value *
+ * *
+ * Return value: SUCCEED - the operation has completed successfully *
+ * FAIL - the operation has failed *
+ * *
+ ******************************************************************************/
+static int zbx_iso8601_timezone(const char *zone, long int *offset)
+{
+ int m, h, sign = 0;
+ char c;
+ const char *ptr = zone;
+
+ if ('.' == *zone) /* skip milliseconds */
+ {
+ for (ptr++; 0 != isdigit(*ptr); ptr++)
+ ;
+ }
+
+ for (; ' ' == *ptr; ptr++)
+ ;
+
+ *offset = 0;
+ c = *ptr;
+
+ if ('\0' == c || 'Z' == c || 'z' == c)
+ return SUCCEED;
+ else if ('-' == c)
+ sign = -1;
+ else if ('+' == c)
+ sign = +1;
+ else
+ return FAIL;
+
+ ptr++;
+
+ if (ZBX_CONST_STRLEN("00:00") > strlen(ptr) || ':' != ptr[2])
+ return FAIL;
+
+ if (0 == isdigit(*ptr) || 23 < (h = atoi(ptr)))
+ return FAIL;
+
+ if (0 == isdigit(ptr[3]) || 59 < (m = atoi(&ptr[3])))
+ return FAIL;
+
+ *offset = sign * (m + h * 60) * 60;
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parse string from iso8601 datetime (xml base) to UTC *
+ * without millisecond, supported formats: *
+ * yyyy-mm-ddThh:mm:ss *
+ * yyyy-mm-ddThh:mm:ssZ *
+ * yyyy-mm-ddThh:mm:ss+hh:mm *
+ * yyyy-mm-ddThh:mm:ss-hh:mm *
+ * yyyy-mm-ddThh:mm:ss +hh:mm *
+ * yyyy-mm-ddThh:mm:ss -hh:mm *
+ * yyyy-mm-ddThh:mm:ss.ccc *
+ * yyyy-mm-ddThh:mm:ss.cccZ *
+ * yyyy-mm-ddThh:mm:ss.ccc+hh:mm *
+ * yyyy-mm-ddThh:mm:ss.ccc-hh:mm *
+ * yyyy-mm-ddThh:mm:ss.ccc +hh:mm *
+ * yyyy-mm-ddThh:mm:ss.ccc -hh:mm *
+ * yyyy-mm-dd hh:mm:ss *
+ * yyyy-mm-dd hh:mm:ssZ *
+ * yyyy-mm-dd hh:mm:ss+hh:mm *
+ * yyyy-mm-dd hh:mm:ss-hh:mm *
+ * yyyy-mm-dd hh:mm:ss +hh:mm *
+ * yyyy-mm-dd hh:mm:ss -hh:mm *
+ * yyyy-mm-dd hh:mm:ss.ccc *
+ * yyyy-mm-dd hh:mm:ss.cccZ *
+ * yyyy-mm-dd hh:mm:ss.ccc+hh:mm *
+ * yyyy-mm-dd hh:mm:ss.ccc-hh:mm *
+ * yyyy-mm-dd hh:mm:ss.ccc +hh:mm *
+ * yyyy-mm-dd hh:mm:ss.ccc -hh:mm *
+ * *
+ * Parameters: str - [IN] iso8601 datetime string *
+ * time - [OUT] parsed tm value *
+ * *
+ * Return value: SUCCEED - the operation has completed successfully *
+ * FAIL - the operation has failed *
+ * *
+ ******************************************************************************/
+int zbx_iso8601_utc(const char *str, time_t *time)
+{
+ long int offset;
+ struct tm tm;
+
+ if ( 0 == isdigit(*str) || ZBX_CONST_STRLEN("1234-12-12T12:12:12") > strlen(str) ||
+ ('T' != str[10] && ' ' != str[10]) ||
+ '-' != str[4] || '-' != str[7] || ':' != str[13] || ':' != str[16])
+ {
+ return FAIL;
+ }
+
+ memset(&tm, 0 , sizeof (struct tm));
+ tm.tm_year = atoi(str);
+
+ if (0 == isdigit(str[5]) || 12 < (tm.tm_mon = atoi(&str[5])))
+ return FAIL;
+
+ if (0 == isdigit(str[8]) || 31 < (tm.tm_mday = atoi(&str[8])))
+ return FAIL;
+
+ if (0 == isdigit(str[11]) || 23 < (tm.tm_hour = atoi(&str[11])))
+ return FAIL;
+
+ if (0 == isdigit(str[14]) || 59 < (tm.tm_min = atoi(&str[14])))
+ return FAIL;
+
+ if (0 == isdigit(str[17]) || 59 < (tm.tm_sec = atoi(&str[17])))
+ return FAIL;
+
+ tm.tm_isdst = 0;
+
+ if (FAIL == zbx_iso8601_timezone(&str[19], &offset))
+ return FAIL;
+
+ if (NULL != time)
+ {
+ int t;
+
+ if(FAIL == zbx_utc_time(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, &t))
+ return FAIL;
+
+ *time = t - offset;
+ }
+
+ return SUCCEED;
+}
diff --git a/src/libs/zbxwin32/disk.c b/src/libs/zbxwin32/disk.c
index 7b88dc80b68..da2bdebe1be 100644
--- a/src/libs/zbxwin32/disk.c
+++ b/src/libs/zbxwin32/disk.c
@@ -17,6 +17,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
+#include "zbxwin32.h"
+
#include "zbxstr.h"
#include "log.h"
@@ -32,7 +34,7 @@
* On error, 0 is returned. *
* *
******************************************************************************/
-zbx_uint64_t get_cluster_size(const char *path, char **error)
+zbx_uint64_t zbx_get_cluster_size(const char *path, char **error)
{
wchar_t *disk = NULL, *wpath = NULL;
unsigned long sectors_per_cluster, bytes_per_sector, path_length;
diff --git a/src/libs/zbxwin32/fatal.c b/src/libs/zbxwin32/fatal.c
index 9e040c6dca5..7c684fb9615 100644
--- a/src/libs/zbxwin32/fatal.c
+++ b/src/libs/zbxwin32/fatal.c
@@ -17,6 +17,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
+#include "zbxwin32.h"
+
#include "zbxstr.h"
#include "log.h"
@@ -25,28 +27,35 @@
#pragma comment(lib, "DbgHelp.lib")
-#define STACKWALK_MAX_NAMELEN 4096
-
-#define ZBX_LSHIFT(value, bits) (((unsigned __int64)value) << bits)
-
-extern const char *progname;
+typedef BOOL (WINAPI *SymGetLineFromAddrW64_func_t)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
+typedef BOOL (WINAPI *SymFromAddr_func_t)(HANDLE a, DWORD64 b , PDWORD64 c, PSYMBOL_INFO d);
#ifdef _M_X64
-
-#define ZBX_IMAGE_FILE_MACHINE IMAGE_FILE_MACHINE_AMD64
-
static void print_register(const char *name, unsigned __int64 value)
{
zabbix_log(LOG_LEVEL_CRIT, "%-7s = %16I64x = %20I64u = %20I64d", name, value, value, value);
}
+#else
+static void print_register(const char *name, unsigned __int32 value)
+{
+ zabbix_log(LOG_LEVEL_CRIT, "%-7s = %16lx = %20lu = %20ld", name, value, value, value);
+}
+#endif
static void print_fatal_info(CONTEXT *pctx)
{
zabbix_log(LOG_LEVEL_CRIT, "====== Fatal information: ======");
+#ifdef _M_X64
zabbix_log(LOG_LEVEL_CRIT, "Program counter: 0x%08lx", pctx->Rip);
+#else
+ zabbix_log(LOG_LEVEL_CRIT, "Program counter: 0x%04x", pctx->Eip);
+#endif
zabbix_log(LOG_LEVEL_CRIT, "=== Registers: ===");
+#define ZBX_LSHIFT(value, bits) (((unsigned __int64)value) << bits)
+
+#ifdef _M_X64
print_register("r8", pctx->R8);
print_register("r9", pctx->R9);
print_register("r10", pctx->R10);
@@ -68,24 +77,7 @@ static void print_fatal_info(CONTEXT *pctx)
print_register("rsp", pctx->Rsp);
print_register("efl", pctx->EFlags);
print_register("csgsfs", ZBX_LSHIFT(pctx->SegCs, 24) | ZBX_LSHIFT(pctx->SegGs, 16) | ZBX_LSHIFT(pctx->SegFs, 8));
-}
-
#else
-
-#define ZBX_IMAGE_FILE_MACHINE IMAGE_FILE_MACHINE_I386
-
-static void print_register(const char *name, unsigned __int32 value)
-{
- zabbix_log(LOG_LEVEL_CRIT, "%-7s = %16lx = %20lu = %20ld", name, value, value, value);
-}
-
-static void print_fatal_info(CONTEXT *pctx)
-{
- zabbix_log(LOG_LEVEL_CRIT, "====== Fatal information: ======");
-
- zabbix_log(LOG_LEVEL_CRIT, "Program counter: 0x%04x", pctx->Eip);
- zabbix_log(LOG_LEVEL_CRIT, "=== Registers: ===");
-
print_register("edi", pctx->Edi);
print_register("esi", pctx->Esi);
print_register("ebp", pctx->Ebp);
@@ -98,12 +90,12 @@ static void print_fatal_info(CONTEXT *pctx)
print_register("esp", pctx->Esp);
print_register("efl", pctx->EFlags);
print_register("csgsfs", ZBX_LSHIFT(pctx->SegCs, 24) | ZBX_LSHIFT(pctx->SegGs, 16) | ZBX_LSHIFT(pctx->SegFs, 8));
-}
-
#endif
-typedef BOOL (WINAPI *SymGetLineFromAddrW64_func_t)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
-typedef BOOL (WINAPI *SymFromAddr_func_t)(HANDLE a, DWORD64 b , PDWORD64 c, PSYMBOL_INFO d);
+#undef ZBX_LSHIFT
+}
+
+static zbx_get_progname_f get_progname_cb = NULL;
void zbx_backtrace(void)
{
@@ -154,7 +146,7 @@ static void print_backtrace(CONTEXT *pctx)
process_name = zbx_unicode_to_utf8(szProcessName);
- if (NULL != (ptr = strstr(process_name, progname)))
+ if (NULL != (ptr = strstr(process_name, get_progname_cb())))
zbx_strncpy_alloc(&process_path, &path_alloc, &path_offset, process_name, ptr - process_name);
}
@@ -181,6 +173,12 @@ static void print_backtrace(CONTEXT *pctx)
scount = s;
ctxcount = ctx;
+#ifdef _M_X64
+#define ZBX_IMAGE_FILE_MACHINE IMAGE_FILE_MACHINE_AMD64
+#else
+#define ZBX_IMAGE_FILE_MACHINE IMAGE_FILE_MACHINE_I386
+#endif
+
/* get number of frames, ctxcount may be modified during StackWalk64() calls */
while (TRUE == StackWalk64(ZBX_IMAGE_FILE_MACHINE, hProcess, hThread, &scount, &ctxcount, NULL, NULL, NULL,
NULL))
@@ -223,6 +221,8 @@ static void print_backtrace(CONTEXT *pctx)
break;
}
+#undef ZBX_IMAGE_FILE_MACHINE
+
SymCleanup(hProcess);
zbx_free(frame);
@@ -231,6 +231,11 @@ static void print_backtrace(CONTEXT *pctx)
zbx_free(pSym);
}
+void zbx_init_library_win32(zbx_get_progname_f get_progname)
+{
+ get_progname_cb = get_progname;
+}
+
int zbx_win_exception_filter(struct _EXCEPTION_POINTERS *ep)
{
zabbix_log(LOG_LEVEL_CRIT, "Unhandled exception %x detected at 0x%p. Crashing ...",
diff --git a/src/libs/zbxwin32/perfmon.c b/src/libs/zbxwin32/perfmon.c
index 661b6af2fa2..9958556ba0f 100644
--- a/src/libs/zbxwin32/perfmon.c
+++ b/src/libs/zbxwin32/perfmon.c
@@ -17,9 +17,10 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "perfmon.h"
+#include "zbxwin32.h"
#include "zbxstr.h"
+#include "zbxnum.h"
#include "stats.h"
#include "log.h"
@@ -230,7 +231,7 @@ PDH_STATUS zbx_PdhGetRawCounterValue(const char *function, const char *counterpa
* sleep 1 second to get the second raw value. *
* *
******************************************************************************/
-PDH_STATUS calculate_counter_value(const char *function, const char *counterpath,
+PDH_STATUS zbx_calculate_counter_value(const char *function, const char *counterpath,
zbx_perf_counter_lang_t lang, double *value)
{
PDH_HQUERY query;
@@ -300,7 +301,7 @@ close_query:
* installations for the same names *
* *
******************************************************************************/
-DWORD get_builtin_object_index(zbx_builtin_counter_ref_t counter_ref)
+DWORD zbx_get_builtin_object_index(zbx_builtin_counter_ref_t counter_ref)
{
return builtin_object_map[builtin_counter_map[counter_ref].object].pdhIndex;
}
@@ -316,7 +317,7 @@ DWORD get_builtin_object_index(zbx_builtin_counter_ref_t counter_ref)
* installations for the same names *
* *
******************************************************************************/
-DWORD get_builtin_counter_index(zbx_builtin_counter_ref_t counter_ref)
+DWORD zbx_get_builtin_counter_index(zbx_builtin_counter_ref_t counter_ref)
{
return builtin_counter_map[counter_ref].pdhIndex;
}
@@ -340,7 +341,7 @@ DWORD get_builtin_counter_index(zbx_builtin_counter_ref_t counter_ref)
* by the caller. *
* *
******************************************************************************/
-wchar_t *get_all_counter_names(HKEY reg_key, wchar_t *reg_value_name)
+wchar_t *zbx_get_all_counter_names(HKEY reg_key, wchar_t *reg_value_name)
{
wchar_t *buffer = NULL;
DWORD buffer_size = 0;
@@ -508,7 +509,7 @@ out:
* initialization from init_perf_collector(). *
* *
******************************************************************************/
-int init_builtin_counter_indexes(void)
+int zbx_init_builtin_counter_indexes(void)
{
int ret = SUCCEED, i;
wchar_t *counter_text, *eng_names, *counter_base;
@@ -526,7 +527,7 @@ int init_builtin_counter_indexes(void)
/* Get buffer holding a list of performance counter indexes and English counter names. */
/* L"Counter" stores names, L"Help" stores descriptions ("Help" is not used). */
- if (NULL == (counter_base = eng_names = get_all_counter_names(HKEY_PERFORMANCE_TEXT, L"Counter")))
+ if (NULL == (counter_base = eng_names = zbx_get_all_counter_names(HKEY_PERFORMANCE_TEXT, L"Counter")))
{
ret = FAIL;
goto out;
@@ -568,7 +569,7 @@ int init_builtin_counter_indexes(void)
builtin_counter_map[i].minSupported_dwMajorVersion && vi->dwMinorVersion >=
builtin_counter_map[i].minSupported_dwMinorVersion && 0 ==
wcscmp(builtin_counter_map[i].eng_name, counter_text) && SUCCEED ==
- validate_object_counter(get_builtin_object_index(i), counter_index))
+ validate_object_counter(zbx_get_builtin_object_index(i), counter_index))
{
builtin_counter_map[i].pdhIndex = counter_index;
break;
@@ -617,7 +618,7 @@ out:
* installations for the same names *
* *
******************************************************************************/
-wchar_t *get_counter_name(DWORD pdhIndex)
+wchar_t *zbx_get_counter_name(DWORD pdhIndex)
{
zbx_perf_counter_id_t *counterName;
@@ -656,7 +657,7 @@ wchar_t *get_counter_name(DWORD pdhIndex)
return counterName->name;
}
-int check_counter_path(char *counterPath, int convert_from_numeric)
+int zbx_check_counter_path(char *counterPath, int convert_from_numeric)
{
PDH_COUNTER_PATH_ELEMENTS *cpe = NULL;
PDH_STATUS status;
@@ -687,15 +688,15 @@ int check_counter_path(char *counterPath, int convert_from_numeric)
if (0 != convert_from_numeric)
{
- int is_numeric = (SUCCEED == _wis_uint(cpe->szObjectName) ? 0x01 : 0);
- is_numeric |= (SUCCEED == _wis_uint(cpe->szCounterName) ? 0x02 : 0);
+ int is_numeric = (SUCCEED == zbx_wis_uint(cpe->szObjectName) ? 0x01 : 0);
+ is_numeric |= (SUCCEED == zbx_wis_uint(cpe->szCounterName) ? 0x02 : 0);
if (0 != is_numeric)
{
if (0x01 & is_numeric)
- cpe->szObjectName = get_counter_name(_wtoi(cpe->szObjectName));
+ cpe->szObjectName = zbx_get_counter_name(_wtoi(cpe->szObjectName));
if (0x02 & is_numeric)
- cpe->szCounterName = get_counter_name(_wtoi(cpe->szCounterName));
+ cpe->szCounterName = zbx_get_counter_name(_wtoi(cpe->szCounterName));
if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__func__, cpe, counterPath))
goto clean;
diff --git a/src/libs/zbxwin32/service.c b/src/libs/zbxwinservice/service.c
index af9ce932f73..c83f3510185 100644
--- a/src/libs/zbxwin32/service.c
+++ b/src/libs/zbxwinservice/service.c
@@ -23,7 +23,6 @@
#include "cfg.h"
#include "log.h"
#include "zbxconf.h"
-#include "perfmon.h"
#define EVENTLOG_REG_PATH TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\")
@@ -117,6 +116,9 @@ static VOID WINAPI ServiceEntry(DWORD argc, wchar_t **argv)
{
wchar_t *wservice_name;
+ ZBX_UNUSED(argc);
+ ZBX_UNUSED(argv);
+
wservice_name = zbx_utf8_to_unicode(ZABBIX_SERVICE_NAME);
serviceHandle = RegisterServiceCtrlHandler(wservice_name, ServiceCtrlHandler);
zbx_free(wservice_name);
@@ -140,7 +142,7 @@ static VOID WINAPI ServiceEntry(DWORD argc, wchar_t **argv)
MAIN_ZABBIX_ENTRY(0);
}
-void service_start(int flags)
+void zbx_service_start(int flags)
{
int ret;
static SERVICE_TABLE_ENTRY serviceTable[2];
@@ -206,7 +208,8 @@ static void svc_get_fullpath(const char *path, wchar_t *fullpath, size_t max_ful
zbx_free(wpath);
}
-static void svc_get_command_line(const char *path, int multiple_agents, wchar_t *cmdLine, size_t max_cmdLine)
+static void svc_get_command_line(const char *path, int multiple_agents, wchar_t *cmdLine, size_t max_cmdLine,
+ const char *config_file)
{
wchar_t path1[MAX_PATH], path2[MAX_PATH];
@@ -217,9 +220,9 @@ static void svc_get_command_line(const char *path, int multiple_agents, wchar_t
else
StringCchPrintf(path1, MAX_PATH, path2);
- if (NULL != CONFIG_FILE)
+ if (NULL != config_file)
{
- svc_get_fullpath(CONFIG_FILE, path2, MAX_PATH);
+ svc_get_fullpath(config_file, path2, MAX_PATH);
StringCchPrintf(cmdLine, max_cmdLine, TEXT("\"%s\" %s--config \"%s\""),
path1,
(0 == multiple_agents) ? TEXT("") : TEXT("--multiple-agents "),
@@ -259,7 +262,7 @@ static int svc_install_event_source(const char *path)
return SUCCEED;
}
-int ZabbixCreateService(const char *path, int multiple_agents)
+int ZabbixCreateService(const char *path, int multiple_agents, const char *config_file)
{
SC_HANDLE mgr, service;
SERVICE_DESCRIPTION sd;
@@ -271,7 +274,7 @@ int ZabbixCreateService(const char *path, int multiple_agents)
if (FAIL == svc_OpenSCManager(&mgr))
return ret;
- svc_get_command_line(path, multiple_agents, cmdLine, MAX_PATH);
+ svc_get_command_line(path, multiple_agents, cmdLine, MAX_PATH, config_file);
wservice_name = zbx_utf8_to_unicode(ZABBIX_SERVICE_NAME);
@@ -424,7 +427,7 @@ int ZabbixStopService(void)
return ret;
}
-void set_parent_signal_handler(zbx_on_exit_t zbx_on_exit_cb_arg)
+void zbx_set_parent_signal_handler(zbx_on_exit_t zbx_on_exit_cb_arg)
{
zbx_on_exit_cb = zbx_on_exit_cb_arg;
signal(SIGINT, parent_signal_handler);
diff --git a/src/libs/zbxxml/xml.c b/src/libs/zbxxml/xml.c
index ff6a73767f4..9d614da2108 100644
--- a/src/libs/zbxxml/xml.c
+++ b/src/libs/zbxxml/xml.c
@@ -1262,12 +1262,33 @@ out:
******************************************************************************/
int zbx_xml_doc_read_num(xmlDoc *xdoc, const char *xpath, int *num)
{
+ return zbx_xml_node_read_num(xdoc, NULL, xpath, num);
+}
+
+/******************************************************************************
+ * *
+ * Purpose: retrieves numeric xpath value *
+ * *
+ * Parameters: xdoc - [IN] xml document *
+ * node - [IN] the XML node *
+ * xpath - [IN] xpath *
+ * num - [OUT] numeric value *
+ * *
+ * Return value: SUCCEED - the count was retrieved successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+int zbx_xml_node_read_num(xmlDoc *xdoc, xmlNode *node, const char *xpath, int *num)
+{
int ret = FAIL;
xmlXPathContext *xpathCtx;
xmlXPathObject *xpathObj;
xpathCtx = xmlXPathNewContext(xdoc);
+ if (NULL != node)
+ xpathCtx->node = node;
+
if (NULL == (xpathObj = xmlXPathEvalExpression((const xmlChar *)xpath, xpathCtx)))
goto out;
diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c
index 14e557f811d..55fc2c27af9 100644
--- a/src/zabbix_agent/active.c
+++ b/src/zabbix_agent/active.c
@@ -31,8 +31,6 @@
#include "zbxtime.h"
#include "zbx_rtc_constants.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern ZBX_THREAD_LOCAL char *CONFIG_HOSTNAME;
extern int CONFIG_HEARTBEAT_FREQUENCY;
@@ -1438,19 +1436,16 @@ ZBX_THREAD_ENTRY(active_checks_thread, args)
time_t nextcheck = 0, nextrefresh = 0, nextsend = 0, now, delta, lastcheck = 0,
heartbeat_nextcheck = 0;
zbx_uint32_t config_revision_local = 0;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
- assert(args);
- assert(((zbx_thread_args_t *)args)->args);
activechks_args_in = (zbx_thread_activechk_args *)((((zbx_thread_args_t *)args))->args);
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(activechks_args_in->zbx_get_program_type_cb_arg()),
server_num, get_process_type_string(process_type), process_num);
-
zbx_vector_ptr_create(&activechk_args.addrs);
zbx_addr_copy(&activechk_args.addrs, &(activechks_args_in->addrs));
@@ -1478,7 +1473,7 @@ ZBX_THREAD_ENTRY(active_checks_thread, args)
if (1 == need_update_userparam)
{
zbx_setproctitle("active checks #%d [reloading user parameters]", process_num);
- reload_user_parameters(process_type, process_num);
+ reload_user_parameters(process_type, process_num, activechks_args_in->config_file);
need_update_userparam = 0;
}
#endif
diff --git a/src/zabbix_agent/active.h b/src/zabbix_agent/active.h
index 240f2667d0e..6a75cdf33ed 100644
--- a/src/zabbix_agent/active.h
+++ b/src/zabbix_agent/active.h
@@ -48,6 +48,7 @@ typedef struct
char *hostname;
zbx_config_tls_t *zbx_config_tls;
zbx_get_program_type_f zbx_get_program_type_cb_arg;
+ char *config_file;
}
zbx_thread_activechk_args;
diff --git a/src/zabbix_agent/cpustat.c b/src/zabbix_agent/cpustat.c
index 2bdc991ed6d..4f465d8021b 100644
--- a/src/zabbix_agent/cpustat.c
+++ b/src/zabbix_agent/cpustat.c
@@ -136,11 +136,11 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
#ifdef _WINDOWS
cpe.szMachineName = NULL;
- cpe.szObjectName = get_builtin_object_name(PCI_PROCESSOR_TIME);
+ cpe.szObjectName = zbx_get_builtin_object_name(PCI_PROCESSOR_TIME);
cpe.szInstanceName = cpu;
cpe.szParentInstance = NULL;
cpe.dwInstanceIndex = (DWORD)-1;
- cpe.szCounterName = get_builtin_counter_name(PCI_PROCESSOR_TIME);
+ cpe.szCounterName = zbx_get_builtin_counter_name(PCI_PROCESSOR_TIME);
/* 64 logical CPUs (threads) is a hard limit for 32-bit Windows systems and some old 64-bit versions, */
/* such as Windows Vista. Systems with <= 64 threads will always have one processor group, which means */
@@ -190,8 +190,8 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
pcpus->count, cpu_groups);
- cpe.szObjectName = get_builtin_object_name(PCI_INFORMATION_PROCESSOR_TIME);
- cpe.szCounterName = get_builtin_counter_name(PCI_INFORMATION_PROCESSOR_TIME);
+ cpe.szObjectName = zbx_get_builtin_object_name(PCI_INFORMATION_PROCESSOR_TIME);
+ cpe.szCounterName = zbx_get_builtin_counter_name(PCI_INFORMATION_PROCESSOR_TIME);
/* This doesn't seem to be well documented but it looks like Windows treats Processor Information */
/* object differently on NUMA-enabled systems. First index for the object may either mean logical */
@@ -232,9 +232,9 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
}
}
- cpe.szObjectName = get_builtin_object_name(PCI_PROCESSOR_QUEUE_LENGTH);
+ cpe.szObjectName = zbx_get_builtin_object_name(PCI_PROCESSOR_QUEUE_LENGTH);
cpe.szInstanceName = NULL;
- cpe.szCounterName = get_builtin_counter_name(PCI_PROCESSOR_QUEUE_LENGTH);
+ cpe.szCounterName = zbx_get_builtin_counter_name(PCI_PROCESSOR_QUEUE_LENGTH);
if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__func__, &cpe, counterPath))
goto clean;
diff --git a/src/zabbix_agent/cpustat.h b/src/zabbix_agent/cpustat.h
index c4ffc5f6599..fe58eeb77f5 100644
--- a/src/zabbix_agent/cpustat.h
+++ b/src/zabbix_agent/cpustat.h
@@ -24,7 +24,7 @@
#include "zbxalgo.h"
#ifdef _WINDOWS
-# include "perfmon.h"
+# include "zbxwin32.h"
typedef struct
{
diff --git a/src/zabbix_agent/listener.c b/src/zabbix_agent/listener.c
index ad557e1180d..ed7024ceef0 100644
--- a/src/zabbix_agent/listener.c
+++ b/src/zabbix_agent/listener.c
@@ -26,9 +26,6 @@
#include "zbxtime.h"
#include "zbx_rtc_constants.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
-
#if defined(ZABBIX_SERVICE)
# include "zbxwinservice.h"
#elif defined(ZABBIX_DAEMON)
@@ -114,14 +111,11 @@ ZBX_THREAD_ENTRY(listener_thread, args)
int ret;
zbx_socket_t s;
zbx_thread_listener_args *init_child_args_in;
-
- assert(args);
- assert(((zbx_thread_args_t *)args)->args);
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
init_child_args_in = (zbx_thread_listener_args *)((((zbx_thread_args_t *)args))->args);
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(init_child_args_in->zbx_get_program_type_cb_arg()),
@@ -145,7 +139,7 @@ ZBX_THREAD_ENTRY(listener_thread, args)
if (1 == need_update_userparam)
{
zbx_setproctitle("listener #%d [reloading user parameters]", process_num);
- reload_user_parameters(process_type, process_num);
+ reload_user_parameters(process_type, process_num, init_child_args_in->config_file);
need_update_userparam = 0;
}
#endif
diff --git a/src/zabbix_agent/listener.h b/src/zabbix_agent/listener.h
index 32a87b68a4c..49aaca0ca9d 100644
--- a/src/zabbix_agent/listener.h
+++ b/src/zabbix_agent/listener.h
@@ -28,6 +28,7 @@ typedef struct
zbx_socket_t *listen_sock;
zbx_config_tls_t *zbx_config_tls;
zbx_get_program_type_f zbx_get_program_type_cb_arg;
+ char *config_file;
}
zbx_thread_listener_args;
diff --git a/src/zabbix_agent/perfstat.c b/src/zabbix_agent/perfstat.c
index bc1d23619da..3f846f94d79 100644
--- a/src/zabbix_agent/perfstat.c
+++ b/src/zabbix_agent/perfstat.c
@@ -249,8 +249,8 @@ static int set_object_names(void)
if (TRUE == refresh)
ppsd.lastrefresh_objects = time(NULL);
- if (NULL == (p_eng = names_eng = get_all_counter_names(HKEY_PERFORMANCE_TEXT, L"Counter")) ||
- NULL == (p_loc = names_loc = get_all_counter_names(HKEY_PERFORMANCE_NLSTEXT, L"Counter")))
+ if (NULL == (p_eng = names_eng = zbx_get_all_counter_names(HKEY_PERFORMANCE_TEXT, L"Counter")) ||
+ NULL == (p_loc = names_loc = zbx_get_all_counter_names(HKEY_PERFORMANCE_NLSTEXT, L"Counter")))
{
goto out;
}
@@ -448,7 +448,7 @@ int init_perf_collector(zbx_threadedness_t threadedness, char **error)
ppsd.lastrefresh_objects = 0;
ppsd.lastupdate_names = 0;
- if (SUCCEED != init_builtin_counter_indexes())
+ if (SUCCEED != zbx_init_builtin_counter_indexes())
{
*error = zbx_strdup(*error, "cannot initialize built-in counter indexes");
goto out;
@@ -680,7 +680,7 @@ out:
if (NULL != counterpath)
{
/* request counter value directly from Windows performance counters */
- PDH_STATUS pdh_status = calculate_counter_value(__func__, counterpath, perfs->lang, value);
+ PDH_STATUS pdh_status = zbx_calculate_counter_value(__func__, counterpath, perfs->lang, value);
if (PDH_NOT_IMPLEMENTED == pdh_status)
*error = zbx_strdup(*error, "Counter is not supported for this Microsoft Windows version");
@@ -756,7 +756,7 @@ out:
if (SUCCEED != ret && NULL != perfs)
{
/* request counter value directly from Windows performance counters */
- if (ERROR_SUCCESS == calculate_counter_value(__func__, counterpath, lang, value))
+ if (ERROR_SUCCESS == zbx_calculate_counter_value(__func__, counterpath, lang, value))
ret = SUCCEED;
}
diff --git a/src/zabbix_agent/perfstat.h b/src/zabbix_agent/perfstat.h
index 8b2ff9474a0..525f6af2b16 100644
--- a/src/zabbix_agent/perfstat.h
+++ b/src/zabbix_agent/perfstat.h
@@ -24,7 +24,7 @@
# error "This module is only available for Windows OS"
#endif
-#include "perfmon.h"
+#include "zbxwin32.h"
zbx_perf_counter_data_t *add_perf_counter(const char *name, const char *counterpath, int interval,
zbx_perf_counter_lang_t lang, char **error);
diff --git a/src/zabbix_agent/stats.c b/src/zabbix_agent/stats.c
index a8cf6315c09..db9736e1f71 100644
--- a/src/zabbix_agent/stats.c
+++ b/src/zabbix_agent/stats.c
@@ -34,9 +34,6 @@ extern int get_cpu_num_win32(void);
ZBX_COLLECTOR_DATA *collector = NULL;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
-
#ifndef _WINDOWS
static int shm_id;
int my_diskstat_shmid = ZBX_NONEXISTENT_SHMID;
@@ -395,11 +392,9 @@ void diskstat_shm_extend(void)
******************************************************************************/
ZBX_THREAD_ENTRY(collector_thread, args)
{
- assert(args);
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
zabbix_log(LOG_LEVEL_INFORMATION, "agent #%d started [collector]", server_num);
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index ff4d1877c13..8551c8a8136 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -18,13 +18,14 @@
**/
#include "log.h"
+#include "modbtype.h"
+#include "zbxcomms.h"
#include "zbxconf.h"
+#include "zbxexpr.h"
#include "zbxgetopt.h"
-#include "zbxcomms.h"
-#include "modbtype.h"
-#include "zbxstr.h"
#include "zbxip.h"
-#include "zbxexpr.h"
+#include "zbxstr.h"
+#include "zbxthreads.h"
static char *CONFIG_PID_FILE = NULL;
@@ -85,6 +86,7 @@ int CONFIG_HEARTBEAT_FREQUENCY = 60;
#include "stats.h"
#ifdef _WINDOWS
# include "perfstat.h"
+# include "zbxwin32.h"
#else
# include "zbxnix.h"
#endif
@@ -241,9 +243,12 @@ static unsigned char get_program_type(void)
return program_type;
}
-ZBX_THREAD_LOCAL unsigned char process_type = 255; /* ZBX_PROCESS_TYPE_UNKNOWN */
-ZBX_THREAD_LOCAL int process_num;
-ZBX_THREAD_LOCAL int server_num = 0;
+#if defined(_WINDOWS) || defined(__MINGW32__)
+static const char *get_progname(void)
+{
+ return progname;
+}
+#endif
static zbx_thread_activechk_args *config_active_args = NULL;
@@ -282,11 +287,13 @@ int CONFIG_AVAILMAN_FORKS = 0;
int CONFIG_SERVICEMAN_FORKS = 0;
int CONFIG_TRIGGERHOUSEKEEPER_FORKS = 0;
+static char *config_file = NULL;
+static int config_allow_root = 0;
+
char *opt = NULL;
#ifdef _WINDOWS
void zbx_co_uninitialize();
-int zbx_win_exception_filter(struct _EXCEPTION_POINTERS *ep);
#endif
int get_process_info_by_thread(int local_server_num, unsigned char *local_process_type, int *local_process_num);
@@ -349,8 +356,8 @@ static int parse_commandline(int argc, char **argv, ZBX_TASK_EX *t)
switch (ch)
{
case 'c':
- if (NULL == CONFIG_FILE)
- CONFIG_FILE = strdup(zbx_optarg);
+ if (NULL == config_file)
+ config_file = strdup(zbx_optarg);
break;
#ifndef _WINDOWS
case 'R':
@@ -528,13 +535,13 @@ static int parse_commandline(int argc, char **argv, ZBX_TASK_EX *t)
goto out;
}
- if (NULL == CONFIG_FILE)
- CONFIG_FILE = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
+ if (NULL == config_file)
+ config_file = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
out:
if (FAIL == ret)
{
zbx_free(TEST_METRIC);
- zbx_free(CONFIG_FILE);
+ zbx_free(config_file);
}
return ret;
@@ -738,6 +745,7 @@ static int add_serveractive_host_cb(const zbx_vector_ptr_t *addrs, zbx_vector_st
hostnames->values[i] : "");
config_active_args[forks].zbx_config_tls = zbx_config_tls;
config_active_args[forks].zbx_get_program_type_cb_arg = get_program_type;
+ config_active_args[forks].config_file = config_file;
}
return SUCCEED;
@@ -887,7 +895,7 @@ static void zbx_load_config(int requirement, ZBX_TASK_EX *task)
PARM_OPT, 0, 0},
{"LoadModule", &CONFIG_LOAD_MODULE, TYPE_MULTISTRING,
PARM_OPT, 0, 0},
- {"AllowRoot", &CONFIG_ALLOW_ROOT, TYPE_INT,
+ {"AllowRoot", &config_allow_root, TYPE_INT,
PARM_OPT, 0, 1},
{"User", &CONFIG_USER, TYPE_STRING,
PARM_OPT, 0, 0},
@@ -954,7 +962,7 @@ static void zbx_load_config(int requirement, ZBX_TASK_EX *task)
zbx_strarr_init(&CONFIG_PERF_COUNTERS);
zbx_strarr_init(&CONFIG_PERF_COUNTERS_EN);
#endif
- parse_cfg_file(CONFIG_FILE, cfg, requirement, ZBX_CFG_STRICT, ZBX_CFG_EXIT_FAILURE);
+ parse_cfg_file(config_file, cfg, requirement, ZBX_CFG_STRICT, ZBX_CFG_EXIT_FAILURE);
zbx_finalize_key_access_rules_configuration();
@@ -1032,7 +1040,7 @@ static int zbx_exec_service_task(const char *name, const ZBX_TASK_EX *t)
switch (t->task)
{
case ZBX_TASK_INSTALL_SERVICE:
- ret = ZabbixCreateService(name, t->flags & ZBX_TASK_FLAG_MULTIPLE_AGENTS);
+ ret = ZabbixCreateService(name, t->flags & ZBX_TASK_FLAG_MULTIPLE_AGENTS, config_file);
break;
case ZBX_TASK_UNINSTALL_SERVICE:
ret = ZabbixRemoveService();
@@ -1122,7 +1130,7 @@ int MAIN_ZABBIX_ENTRY(int flags)
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);
+ zabbix_log(LOG_LEVEL_INFORMATION, "using configuration file: %s", config_file);
#if !defined(_WINDOWS) && (defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL))
if (SUCCEED != zbx_coredump_disable())
@@ -1211,20 +1219,23 @@ int MAIN_ZABBIX_ENTRY(int flags)
for (i = 0; i < threads_num; i++)
{
zbx_thread_args_t *thread_args;
- zbx_thread_listener_args listener_args = {&listen_sock, zbx_config_tls, get_program_type};
+ zbx_thread_info_t *thread_info;
+ zbx_thread_listener_args listener_args = {&listen_sock, zbx_config_tls, get_program_type,
+ config_file};
thread_args = (zbx_thread_args_t *)zbx_malloc(NULL, sizeof(zbx_thread_args_t));
+ thread_info = &thread_args->info;
- if (FAIL == get_process_info_by_thread(i + 1, &thread_args->process_type, &thread_args->process_num))
+ if (FAIL == get_process_info_by_thread(i + 1, &thread_info->process_type, &thread_info->process_num))
{
THIS_SHOULD_NEVER_HAPPEN;
exit(EXIT_FAILURE);
}
- thread_args->server_num = i + 1;
+ thread_info->server_num = i + 1;
thread_args->args = NULL;
- switch (thread_args->process_type)
+ switch (thread_info->process_type)
{
case ZBX_PROCESS_TYPE_COLLECTOR:
zbx_thread_start(collector_thread, thread_args, &threads[i]);
@@ -1244,7 +1255,7 @@ int MAIN_ZABBIX_ENTRY(int flags)
}
#ifdef _WINDOWS
- set_parent_signal_handler(zbx_on_exit); /* must be called after all threads are created */
+ zbx_set_parent_signal_handler(zbx_on_exit); /* must be called after all threads are created */
/* wait for an exiting thread */
res = WaitForMultipleObjectsEx(threads_num, threads, FALSE, INFINITE, FALSE);
@@ -1335,7 +1346,11 @@ int main(int argc, char **argv)
char *error = NULL;
#ifdef _WINDOWS
int ret;
-
+#endif
+#if defined(_WINDOWS) || defined(__MINGW32__)
+ zbx_init_library_win32(&get_progname);
+#endif
+#ifdef _WINDOWS
/* Provide, so our process handles errors instead of the system itself. */
/* Attention!!! */
/* The system does not display the critical-error-handler message box. */
@@ -1487,9 +1502,9 @@ int main(int argc, char **argv)
}
#if defined(ZABBIX_SERVICE)
- service_start(t.flags);
+ zbx_service_start(t.flags);
#elif defined(ZABBIX_DAEMON)
- zbx_daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, t.flags, get_pid_file_path, zbx_on_exit);
+ zbx_daemon_start(config_allow_root, CONFIG_USER, t.flags, get_pid_file_path, zbx_on_exit);
#endif
exit(EXIT_SUCCESS);
}
diff --git a/src/zabbix_agent/zbxconf.c b/src/zabbix_agent/zbxconf.c
index 1b406cb8ad7..b36d58566a5 100644
--- a/src/zabbix_agent/zbxconf.c
+++ b/src/zabbix_agent/zbxconf.c
@@ -185,7 +185,7 @@ void load_perf_counters(const char **def_lines, const char **eng_lines)
zbx_unicode_to_utf8_static(wcounterPath, counterpath, PDH_MAX_COUNTER_PATH);
zbx_free(wcounterPath);
- if (FAIL == check_counter_path(counterpath, lang == PERF_COUNTER_LANG_DEFAULT))
+ if (FAIL == zbx_check_counter_path(counterpath, lang == PERF_COUNTER_LANG_DEFAULT))
{
error = zbx_strdup(error, "Invalid counter path.");
goto pc_fail;
@@ -224,7 +224,7 @@ void load_perf_counters(const char **def_lines, const char **eng_lines)
* Purpose: load user parameters from configuration file *
* *
******************************************************************************/
-static int load_config_user_params(void)
+static int load_config_user_params(const char *config_file)
{
struct cfg_line cfg[] =
{
@@ -235,25 +235,17 @@ static int load_config_user_params(void)
{NULL}
};
- return parse_cfg_file(CONFIG_FILE, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_NOT_STRICT, ZBX_CFG_NO_EXIT_FAILURE);
+ return parse_cfg_file(config_file, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_NOT_STRICT, ZBX_CFG_NO_EXIT_FAILURE);
}
-/******************************************************************************
- * *
- * Purpose: reload user parameters *
- * *
- * Parameters: process_type - process type *
- * process_num - process number *
- * *
- ******************************************************************************/
-void reload_user_parameters(unsigned char process_type, int process_num)
+void reload_user_parameters(unsigned char process_type, int process_num, const char *config_file)
{
char *error = NULL;
ZBX_METRIC *metrics_fallback = NULL;
zbx_strarr_init(&CONFIG_USER_PARAMETERS);
- if (FAIL == load_config_user_params())
+ if (FAIL == load_config_user_params(config_file))
{
zabbix_log(LOG_LEVEL_ERR, "cannot reload user parameters [%s #%d]: error processing configuration file",
get_process_type_string(process_type), process_num);
diff --git a/src/zabbix_agent/zbxconf.h b/src/zabbix_agent/zbxconf.h
index 4d256837bc2..7c2d14a43be 100644
--- a/src/zabbix_agent/zbxconf.h
+++ b/src/zabbix_agent/zbxconf.h
@@ -47,7 +47,7 @@ extern char *CONFIG_USER;
void load_aliases(char **lines);
int load_user_parameters(char **lines, char **err);
int load_key_access_rule(const char *value, const struct cfg_line *cfg);
-void reload_user_parameters(unsigned char process_type, int process_num);
+void reload_user_parameters(unsigned char process_type, int process_num, const char *config_file);
#ifdef _WINDOWS
void load_perf_counters(const char **def_lines, const char **eng_lines);
#endif
diff --git a/src/zabbix_java/src/com/zabbix/gateway/GeneralInformation.java b/src/zabbix_java/src/com/zabbix/gateway/GeneralInformation.java
index 89f4a89ea14..9ff9e9cab5e 100644
--- a/src/zabbix_java/src/com/zabbix/gateway/GeneralInformation.java
+++ b/src/zabbix_java/src/com/zabbix/gateway/GeneralInformation.java
@@ -22,9 +22,9 @@ package com.zabbix.gateway;
class GeneralInformation
{
static final String APPLICATION_NAME = "Zabbix Java Gateway";
- static final String REVISION_DATE = "29 September 2022";
+ static final String REVISION_DATE = "27 October 2022";
static final String REVISION = "{ZABBIX_REVISION}";
- static final String VERSION = "6.4.0beta2";
+ static final String VERSION = "6.4.0beta3";
static void printVersion()
{
diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am
index 7a2eb7edb98..6a1657afdd9 100644
--- a/src/zabbix_proxy/Makefile.am
+++ b/src/zabbix_proxy/Makefile.am
@@ -47,7 +47,6 @@ zabbix_proxy_LDADD = \
$(top_builddir)/src/libs/zbxdiscovery/libzbxdiscovery.a \
$(top_builddir)/src/libs/zbxexport/libzbxexport.a \
taskmanager/libzbxtaskmanager.a \
- $(top_builddir)/src/zabbix_server/selfmon/libzbxselfmon.a \
$(top_builddir)/src/zabbix_server/vmware/libzbxvmware.a \
$(top_builddir)/src/zabbix_server/scripts/libzbxscripts.a \
$(top_builddir)/src/zabbix_server/availability/libavailability.a \
@@ -61,6 +60,7 @@ zabbix_proxy_LDADD = \
$(top_builddir)/src/libs/zbxlog/libzbxlog.a \
$(top_builddir)/src/libs/zbxdbcache/libzbxdbcache.a \
$(top_builddir)/src/libs/zbxserver/libzbxserver.a \
+ $(top_builddir)/src/libs/zbxdbcache/libzbxdbcache.a \
stats/libzbxserver_proxy.a \
$(top_builddir)/src/libs/zbxeval/libzbxeval.a \
$(top_builddir)/src/libs/zbxserialize/libzbxserialize.a \
@@ -85,6 +85,7 @@ zabbix_proxy_LDADD = \
$(top_builddir)/src/libs/zbxicmpping/libzbxicmpping.a \
$(top_builddir)/src/libs/zbxdbupgrade/libzbxdbupgrade.a \
$(top_builddir)/src/libs/zbxdbhigh/libzbxdbhigh.a \
+ $(top_builddir)/src/libs/zbxdbwrap/libzbxdbwrap.a \
$(top_builddir)/src/libs/zbxdbschema/libzbxdbschema.a \
$(top_builddir)/src/libs/zbxdb/libzbxdb.a \
$(top_builddir)/src/libs/zbxmodules/libzbxmodules.a \
diff --git a/src/zabbix_proxy/datasender/datasender.c b/src/zabbix_proxy/datasender/datasender.c
index 8b247f0f297..d490f62b23a 100644
--- a/src/zabbix_proxy/datasender/datasender.c
+++ b/src/zabbix_proxy/datasender/datasender.c
@@ -23,7 +23,7 @@
#include "zbxdbhigh.h"
#include "log.h"
#include "zbxnix.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxself.h"
#include "zbxtasks.h"
#include "zbxcompress.h"
@@ -31,9 +31,6 @@
#include "zbxnum.h"
#include "zbxtime.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
-
extern zbx_vector_ptr_t zbx_addrs;
extern char *CONFIG_HOSTNAME;
extern char *CONFIG_SOURCE_IP;
@@ -83,7 +80,8 @@ static void get_hist_upload_state(const char *buffer, int *state)
* data and sends 'proxy data' request *
* *
******************************************************************************/
-static int proxy_data_sender(int *more, int now, int *hist_upload_state, const zbx_config_tls_t *zbx_config_tls)
+static int proxy_data_sender(int *more, int now, int *hist_upload_state, const zbx_config_tls_t *zbx_config_tls,
+ const zbx_thread_info_t *info)
{
static int data_timestamp = 0, task_timestamp = 0, upload_state = SUCCEED;
@@ -183,18 +181,18 @@ static int proxy_data_sender(int *more, int now, int *hist_upload_state, const z
reserved = j.buffer_size;
zbx_json_free(&j); /* json buffer can be large, free as fast as possible */
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
/* retry till have a connection */
if (FAIL == zbx_connect_to_server(&sock, CONFIG_SOURCE_IP, &zbx_addrs, 600, CONFIG_TIMEOUT,
CONFIG_PROXYDATA_FREQUENCY, LOG_LEVEL_WARNING, zbx_config_tls))
{
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
goto clean;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
upload_state = zbx_put_data_to_server(&sock, &buffer, buffer_size, reserved, &error);
get_hist_upload_state(sock.buffer, hist_upload_state);
@@ -291,16 +289,16 @@ ZBX_THREAD_ENTRY(datasender_thread, args)
(((zbx_thread_args_t *)args)->args);
int records = 0, hist_upload_state = ZBX_PROXY_UPLOAD_ENABLED, more;
double time_start, time_diff = 0.0, time_now;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ unsigned char process_type = info->process_type;
+ int server_num = info->server_num;
+ int process_num = info->process_num;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(datasender_args_in->zbx_get_program_type_cb_arg()),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
zbx_tls_init_child(datasender_args_in->zbx_config_tls, datasender_args_in->zbx_get_program_type_cb_arg);
@@ -322,7 +320,8 @@ ZBX_THREAD_ENTRY(datasender_thread, args)
do
{
- records += proxy_data_sender(&more, (int)time_now, &hist_upload_state, datasender_args_in->zbx_config_tls);
+ records += proxy_data_sender(&more, (int)time_now, &hist_upload_state, datasender_args_in->zbx_config_tls,
+ info);
time_now = zbx_time();
time_diff = time_now - time_start;
@@ -334,7 +333,7 @@ ZBX_THREAD_ENTRY(datasender_thread, args)
ZBX_PROXY_DATA_MORE != more ? ZBX_TASK_UPDATE_FREQUENCY : 0);
if (ZBX_PROXY_DATA_MORE != more)
- zbx_sleep_loop(ZBX_TASK_UPDATE_FREQUENCY);
+ zbx_sleep_loop(info, ZBX_TASK_UPDATE_FREQUENCY);
}
diff --git a/src/zabbix_proxy/housekeeper/housekeeper.c b/src/zabbix_proxy/housekeeper/housekeeper.c
index f1720691d7f..3573d5635f3 100644
--- a/src/zabbix_proxy/housekeeper/housekeeper.c
+++ b/src/zabbix_proxy/housekeeper/housekeeper.c
@@ -28,9 +28,7 @@
#include "zbxtime.h"
#include "zbx_rtc_constants.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
static int hk_period;
@@ -149,15 +147,15 @@ ZBX_THREAD_ENTRY(housekeeper_thread, args)
double sec, time_slept, time_now;
char sleeptext[25];
zbx_ipc_async_socket_t rtc;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ unsigned char process_type = info->process_type;
+ int server_num = info->server_num;
+ int process_num = info->process_num;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (0 == CONFIG_HOUSEKEEPING_FREQUENCY)
{
@@ -183,7 +181,7 @@ ZBX_THREAD_ENTRY(housekeeper_thread, args)
sec = zbx_time();
- while (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ while (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
switch (rtc_cmd)
{
diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c
index 698d3b62207..6ed5f3e92a8 100644
--- a/src/zabbix_proxy/proxy.c
+++ b/src/zabbix_proxy/proxy.c
@@ -17,10 +17,11 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "cfg.h"
#include "zbxdbhigh.h"
+#include "dbcache.h"
#include "zbxdbupgrade.h"
#include "log.h"
#include "zbxgetopt.h"
@@ -44,7 +45,6 @@
#include "proxyconfig/proxyconfig.h"
#include "datasender/datasender.h"
#include "taskmanager/taskmanager.h"
-#include "../zabbix_server/selfmon/selfmon.h"
#include "../zabbix_server/vmware/vmware.h"
#include "setproctitle.h"
#include "zbxcomms.h"
@@ -59,6 +59,7 @@
#include "zbxstats.h"
#include "stats/zabbix_stats.h"
#include "zbxip.h"
+#include "zbxthreads.h"
#ifdef HAVE_OPENIPMI
#include "../zabbix_server/ipmi/ipmi_manager.h"
@@ -152,10 +153,6 @@ static unsigned char get_program_type(void)
return program_type;
}
-ZBX_THREAD_LOCAL unsigned char process_type = ZBX_PROCESS_TYPE_UNKNOWN;
-ZBX_THREAD_LOCAL int process_num = 0;
-ZBX_THREAD_LOCAL int server_num = 0;
-
int CONFIG_PROXYMODE = ZBX_PROXYMODE_ACTIVE;
int CONFIG_DATASENDER_FORKS = 1;
int CONFIG_DISCOVERER_FORKS = 1;
@@ -298,6 +295,9 @@ int CONFIG_TCP_MAX_BACKLOG_SIZE = SOMAXCONN;
int CONFIG_DOUBLE_PRECISION = ZBX_DB_DBL_PRECISION_ENABLED;
+static char *config_file = NULL;
+static int config_allow_root = 0;
+
zbx_vector_ptr_t zbx_addrs;
int get_process_info_by_thread(int local_server_num, unsigned char *local_process_type, int *local_process_num);
@@ -845,7 +845,7 @@ static void zbx_load_config(ZBX_TASK_EX *task)
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,
+ {"AllowRoot", &config_allow_root, TYPE_INT,
PARM_OPT, 0, 1},
{"User", &CONFIG_USER, TYPE_STRING,
PARM_OPT, 0, 0},
@@ -907,7 +907,7 @@ static void zbx_load_config(ZBX_TASK_EX *task)
/* initialize multistrings */
zbx_strarr_init(&CONFIG_LOAD_MODULE);
- parse_cfg_file(CONFIG_FILE, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_STRICT, ZBX_CFG_EXIT_FAILURE);
+ parse_cfg_file(config_file, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_STRICT, ZBX_CFG_EXIT_FAILURE);
zbx_set_defaults();
@@ -1036,8 +1036,8 @@ int main(int argc, char **argv)
{
case 'c':
opt_c++;
- if (NULL == CONFIG_FILE)
- CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
+ if (NULL == config_file)
+ config_file = zbx_strdup(config_file, zbx_optarg);
break;
case 'R':
opt_r++;
@@ -1089,8 +1089,8 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- if (NULL == CONFIG_FILE)
- CONFIG_FILE = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
+ if (NULL == config_file)
+ config_file = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
/* required for simple checks */
zbx_init_metrics();
@@ -1118,7 +1118,7 @@ int main(int argc, char **argv)
exit(SUCCEED == ret ? EXIT_SUCCESS : EXIT_FAILURE);
}
- return zbx_daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, t.flags, get_pid_file_path, zbx_on_exit);
+ return zbx_daemon_start(config_allow_root, CONFIG_USER, t.flags, get_pid_file_path, zbx_on_exit);
}
static void zbx_check_db(void)
@@ -1142,7 +1142,7 @@ static void proxy_db_init(void)
zbx_stat_t db_stat;
#endif
- if (SUCCEED != DBinit(&error))
+ if (SUCCEED != DBinit(DCget_nextid, program_type, &error))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot initialize database: %s", error);
zbx_free(error);
@@ -1294,7 +1294,7 @@ int MAIN_ZABBIX_ENTRY(int flags)
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);
+ zabbix_log(LOG_LEVEL_INFORMATION, "using configuration file: %s", config_file);
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
if (SUCCEED != zbx_coredump_disable())
@@ -1408,16 +1408,17 @@ int MAIN_ZABBIX_ENTRY(int flags)
for (i = 0; i < threads_num; i++)
{
- if (FAIL == get_process_info_by_thread(i + 1, &thread_args.process_type, &thread_args.process_num))
+ if (FAIL == get_process_info_by_thread(i + 1, &thread_args.info.process_type,
+ &thread_args.info.process_num))
{
THIS_SHOULD_NEVER_HAPPEN;
exit(EXIT_FAILURE);
}
- thread_args.server_num = i + 1;
+ thread_args.info.server_num = i + 1;
thread_args.args = NULL;
- switch (thread_args.process_type)
+ switch (thread_args.info.process_type)
{
case ZBX_PROCESS_TYPE_CONFSYNCER:
thread_args.args = &proxyconfig_args;
@@ -1469,7 +1470,7 @@ int MAIN_ZABBIX_ENTRY(int flags)
zbx_thread_start(snmptrapper_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_SELFMON:
- zbx_thread_start(selfmon_thread, &thread_args, &threads[i]);
+ zbx_thread_start(zbx_selfmon_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_VMWARE:
zbx_thread_start(vmware_thread, &thread_args, &threads[i]);
diff --git a/src/zabbix_proxy/proxyconfig/proxyconfig.c b/src/zabbix_proxy/proxyconfig/proxyconfig.c
index 7016c60523d..0f5f4542ff3 100644
--- a/src/zabbix_proxy/proxyconfig/proxyconfig.c
+++ b/src/zabbix_proxy/proxyconfig/proxyconfig.c
@@ -21,7 +21,7 @@
#include "log.h"
#include "zbxnix.h"
-#include "dbcache.h"
+#include "zbxdbwrap.h"
#include "zbxself.h"
#include "zbxtime.h"
@@ -33,16 +33,14 @@
#define CONFIG_PROXYCONFIG_RETRY 120 /* seconds */
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern zbx_vector_ptr_t zbx_addrs;
extern char *CONFIG_HOSTNAME;
extern char *CONFIG_SOURCE_IP;
static void process_configuration_sync(size_t *data_size, zbx_synced_new_config_t *synced,
- const zbx_config_tls_t *zbx_config_tls)
+ const zbx_config_tls_t *zbx_config_tls, const zbx_thread_info_t *thread_info)
{
zbx_socket_t sock;
struct zbx_json_parse jp, jp_kvs_paths = {0};
@@ -72,16 +70,16 @@ static void process_configuration_sync(size_t *data_size, zbx_synced_new_config_
reserved = j.buffer_size;
zbx_json_free(&j);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(thread_info, ZBX_PROCESS_STATE_IDLE);
if (FAIL == zbx_connect_to_server(&sock,CONFIG_SOURCE_IP, &zbx_addrs, 600, CONFIG_TIMEOUT,
CONFIG_PROXYCONFIG_RETRY, LOG_LEVEL_WARNING, zbx_config_tls)) /* retry till have a connection */
{
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(thread_info, ZBX_PROCESS_STATE_BUSY);
goto out;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(thread_info, ZBX_PROCESS_STATE_BUSY);
if (SUCCEED != zbx_get_data_from_server(&sock, &buffer, buffer_size, reserved, &error))
{
@@ -245,15 +243,15 @@ ZBX_THREAD_ENTRY(proxyconfig_thread, args)
zbx_ipc_async_socket_t rtc;
int sleeptime;
zbx_synced_new_config_t synced = ZBX_SYNCED_NEW_CONFIG_NO;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(proxyconfig_args_in->zbx_get_program_type_cb_arg()),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
zbx_tls_init_child(proxyconfig_args_in->zbx_config_tls, proxyconfig_args_in->zbx_get_program_type_cb_arg);
#endif
@@ -277,7 +275,7 @@ ZBX_THREAD_ENTRY(proxyconfig_thread, args)
unsigned char *rtc_data;
int config_cache_reload = 0;
- while (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ while (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
if (ZBX_RTC_CONFIG_CACHE_RELOAD == rtc_cmd)
config_cache_reload = 1;
@@ -320,7 +318,7 @@ ZBX_THREAD_ENTRY(proxyconfig_thread, args)
zbx_setproctitle("%s [loading configuration]", get_process_type_string(process_type));
- process_configuration_sync(&data_size, &synced, proxyconfig_args_in->zbx_config_tls);
+ process_configuration_sync(&data_size, &synced, proxyconfig_args_in->zbx_config_tls, info);
interval = zbx_time() - sec;
zbx_setproctitle("%s [synced config " ZBX_FS_SIZE_T " bytes in " ZBX_FS_DBL " sec, idle %d sec]",
diff --git a/src/zabbix_proxy/proxyconfigwrite/proxyconfig_write.c b/src/zabbix_proxy/proxyconfigwrite/proxyconfig_write.c
index e364e87d80d..56c1dbc4ce0 100644
--- a/src/zabbix_proxy/proxyconfigwrite/proxyconfig_write.c
+++ b/src/zabbix_proxy/proxyconfigwrite/proxyconfig_write.c
@@ -19,7 +19,7 @@
#include "proxyconfig_write.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxdbhigh.h"
#include "zbxcommshigh.h"
#include "zbxrtc.h"
diff --git a/src/zabbix_proxy/rtc/rtc_proxy.c b/src/zabbix_proxy/rtc/rtc_proxy.c
index 5cad4e207e7..b3eb9bbd94c 100644
--- a/src/zabbix_proxy/rtc/rtc_proxy.c
+++ b/src/zabbix_proxy/rtc/rtc_proxy.c
@@ -19,7 +19,7 @@
#include "rtc_proxy.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbx_rtc_constants.h"
extern int CONFIG_PROXYMODE;
diff --git a/src/zabbix_proxy/stats/zabbix_stats_proxy.c b/src/zabbix_proxy/stats/zabbix_stats_proxy.c
index 2ab441acc48..5a8548ac0ac 100644
--- a/src/zabbix_proxy/stats/zabbix_stats_proxy.c
+++ b/src/zabbix_proxy/stats/zabbix_stats_proxy.c
@@ -18,7 +18,7 @@
**/
#include "zabbix_stats.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxcomms.h"
#include "zbxjson.h"
#include "zbxstr.h"
diff --git a/src/zabbix_proxy/taskmanager/taskmanager.c b/src/zabbix_proxy/taskmanager/taskmanager.c
index 20aa56c3709..3d4075af2f0 100644
--- a/src/zabbix_proxy/taskmanager/taskmanager.c
+++ b/src/zabbix_proxy/taskmanager/taskmanager.c
@@ -29,7 +29,7 @@
#include "log.h"
#include "zbxdiag.h"
#include "zbxrtc.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "dbcache.h"
#include "zbxnum.h"
#include "zbxtime.h"
@@ -40,9 +40,7 @@
extern int CONFIG_ENABLE_REMOTE_COMMANDS;
extern int CONFIG_LOG_REMOTE_COMMANDS;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_PROXYMODE;
extern char *CONFIG_HOSTNAME;
@@ -433,16 +431,16 @@ ZBX_THREAD_ENTRY(taskmanager_thread, args)
double sec1, sec2;
int tasks_num, sleeptime, nextcheck;
zbx_ipc_async_socket_t rtc;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(taskmanager_args_in->zbx_get_program_type_cb_arg()),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
zbx_tls_init_child(taskmanager_args_in->zbx_config->zbx_config_tls,
@@ -464,7 +462,7 @@ ZBX_THREAD_ENTRY(taskmanager_thread, args)
zbx_uint32_t rtc_cmd;
unsigned char *rtc_data = NULL;
- if (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ if (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
#ifdef HAVE_NETSNMP
if (ZBX_RTC_SNMP_CACHE_RELOAD == rtc_cmd)
diff --git a/src/zabbix_sender/win32/zabbix_sender.c b/src/zabbix_sender/win32/zabbix_sender.c
index 54454802903..2ee0e61b033 100644
--- a/src/zabbix_sender/win32/zabbix_sender.c
+++ b/src/zabbix_sender/win32/zabbix_sender.c
@@ -19,8 +19,10 @@
#include "zabbix_sender.h"
+#include "zbxstr.h"
#include "zbxjson.h"
#include "zbxcomms.h"
+#include "zbxcommshigh.h"
#include "cfg.h"
const char *progname = NULL;
diff --git a/src/zabbix_sender/zabbix_sender.c b/src/zabbix_sender/zabbix_sender.c
index ce419876f42..123e79d1c67 100644
--- a/src/zabbix_sender/zabbix_sender.c
+++ b/src/zabbix_sender/zabbix_sender.c
@@ -331,6 +331,8 @@ static char *ZABBIX_HOSTNAME = NULL;
static char *ZABBIX_KEY = NULL;
static char *ZABBIX_KEY_VALUE = NULL;
+static char *config_file = NULL;
+
typedef struct
{
zbx_vector_ptr_t addrs;
@@ -881,7 +883,7 @@ static void zbx_fill_from_config_file(char **dst, char *src)
}
}
-static void zbx_load_config(const char *config_file)
+static void zbx_load_config(const char *config_file_in)
{
char *cfg_source_ip = NULL, *cfg_active_hosts = NULL, *cfg_hostname = NULL, *cfg_tls_connect = NULL,
*cfg_tls_ca_file = NULL, *cfg_tls_crl_file = NULL, *cfg_tls_server_cert_issuer = NULL,
@@ -932,7 +934,7 @@ static void zbx_load_config(const char *config_file)
};
/* do not complain about unknown parameters in agent configuration file */
- parse_cfg_file(config_file, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_NOT_STRICT, ZBX_CFG_EXIT_FAILURE);
+ parse_cfg_file(config_file_in, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_NOT_STRICT, ZBX_CFG_EXIT_FAILURE);
/* get first hostname only */
if (NULL != cfg_hostname)
@@ -1011,8 +1013,8 @@ static void parse_commandline(int argc, char **argv)
switch (ch)
{
case 'c':
- if (NULL == CONFIG_FILE)
- CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
+ if (NULL == config_file)
+ config_file = zbx_strdup(config_file, zbx_optarg);
break;
case 'h':
zbx_help();
@@ -1502,8 +1504,8 @@ int main(int argc, char **argv)
parse_commandline(argc, argv);
- if (NULL != CONFIG_FILE)
- zbx_load_config(CONFIG_FILE);
+ if (NULL != config_file)
+ zbx_load_config(config_file);
#ifndef _WINDOWS
if (SUCCEED != zbx_locks_create(&error))
{
diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am
index 16c069bc236..9ed2104d3a3 100644
--- a/src/zabbix_server/Makefile.am
+++ b/src/zabbix_server/Makefile.am
@@ -15,7 +15,6 @@ SUBDIRS = \
trapper \
escalator \
proxypoller \
- selfmon \
vmware \
taskmanager \
ipmi \
@@ -72,7 +71,6 @@ zabbix_server_LDADD = \
escalator/libzbxescalator.a \
proxypoller/libzbxproxypoller.a \
proxyconfigread/libzbxproxyconfigread.a \
- selfmon/libzbxselfmon.a \
vmware/libzbxvmware.a \
taskmanager/libzbxtaskmanager.a \
odbc/libzbxodbc.a \
@@ -97,6 +95,7 @@ zabbix_server_LDADD = \
$(top_builddir)/src/libs/zbxlog/libzbxlog.a \
$(top_builddir)/src/libs/zbxdbcache/libzbxdbcache.a \
$(top_builddir)/src/libs/zbxserver/libzbxserver.a \
+ $(top_builddir)/src/libs/zbxdbcache/libzbxdbcache.a \
preprocessor/libpreprocessor.a \
$(top_builddir)/src/libs/zbxvariant/libzbxvariant.a \
$(top_builddir)/src/libs/zbxeval/libzbxeval.a \
@@ -128,6 +127,7 @@ zabbix_server_LDADD = \
$(top_builddir)/src/libs/zbxicmpping/libzbxicmpping.a \
$(top_builddir)/src/libs/zbxdbupgrade/libzbxdbupgrade.a \
$(top_builddir)/src/libs/zbxdbhigh/libzbxdbhigh.a \
+ $(top_builddir)/src/libs/zbxdbwrap/libzbxdbwrap.a \
$(top_builddir)/src/libs/zbxdbschema/libzbxdbschema.a \
$(top_builddir)/src/libs/zbxdb/libzbxdb.a \
$(top_builddir)/src/libs/zbxmodules/libzbxmodules.a \
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c
index 02880e50e0d..0fda368e4eb 100644
--- a/src/zabbix_server/actions.c
+++ b/src/zabbix_server/actions.c
@@ -26,6 +26,7 @@
#include "audit/zbxaudit.h"
#include "zbxnum.h"
#include "zbxip.h"
+#include "zbxdbwrap.h"
/******************************************************************************
* *
diff --git a/src/zabbix_server/alerter/alert_manager.c b/src/zabbix_server/alerter/alert_manager.c
index 9a40b39246b..004449a0cab 100644
--- a/src/zabbix_server/alerter/alert_manager.c
+++ b/src/zabbix_server/alerter/alert_manager.c
@@ -57,9 +57,7 @@
#define ZBX_MEDIA_CONTENT_TYPE_DEFAULT 255
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_ALERTER_FORKS;
extern char *CONFIG_ALERT_SCRIPTS_PATH;
@@ -2241,17 +2239,17 @@ ZBX_THREAD_ENTRY(alert_manager_thread, args)
time_mediatype = 0;
double time_stat, time_idle = 0, time_now, sec;
zbx_timespec_t timeout = {1, 0};
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (FAIL == am_init(&manager, &error))
{
@@ -2324,9 +2322,9 @@ ZBX_THREAD_ENTRY(alert_manager_thread, args)
time_mediatype = now;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_service_recv(&manager.ipc, &timeout, &client, &message);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
sec = zbx_time();
zbx_update_env(sec);
diff --git a/src/zabbix_server/alerter/alert_syncer.c b/src/zabbix_server/alerter/alert_syncer.c
index df66a409690..13a1baf8bfc 100644
--- a/src/zabbix_server/alerter/alert_syncer.c
+++ b/src/zabbix_server/alerter/alert_syncer.c
@@ -35,9 +35,7 @@
#define ZBX_ALERT_BATCH_SIZE 1000
#define ZBX_MEDIATYPE_CACHE_TTL SEC_PER_DAY
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_CONFSYNCER_FREQUENCY;
@@ -913,14 +911,14 @@ static void am_db_update_watchdog(zbx_am_db_t *amdb)
ZBX_THREAD_ENTRY(alert_syncer_thread, args)
{
- double sec1, sec2, time_cleanup = 0, time_watchdog = 0;
- int alerts_num, sleeptime, nextcheck, freq_watchdog, results_num;
- zbx_am_db_t amdb;
- char *error = NULL;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ double sec1, sec2, time_cleanup = 0, time_watchdog = 0;
+ int alerts_num, sleeptime, nextcheck, freq_watchdog, results_num;
+ zbx_am_db_t amdb;
+ char *error = NULL;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
@@ -944,7 +942,7 @@ ZBX_THREAD_ENTRY(alert_syncer_thread, args)
while (ZBX_IS_RUNNING())
{
- zbx_sleep_loop(sleeptime);
+ zbx_sleep_loop(info, sleeptime);
sec1 = zbx_time();
zbx_update_env(sec1);
diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c
index 01880350760..37723179f6f 100644
--- a/src/zabbix_server/alerter/alerter.c
+++ b/src/zabbix_server/alerter/alerter.c
@@ -33,9 +33,7 @@
#define ALARM_ACTION_TIMEOUT 40
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
static zbx_es_t es_engine;
@@ -291,15 +289,15 @@ ZBX_THREAD_ENTRY(alerter_thread, args)
zbx_ipc_socket_t alerter_socket;
zbx_ipc_message_t message;
double time_stat, time_idle = 0, time_now, time_read;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type));
@@ -320,7 +318,7 @@ ZBX_THREAD_ENTRY(alerter_thread, args)
zbx_setproctitle("%s #%d started", get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
while (ZBX_IS_RUNNING())
{
@@ -338,7 +336,7 @@ ZBX_THREAD_ENTRY(alerter_thread, args)
fail_num = 0;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
if (SUCCEED != zbx_ipc_socket_read(&alerter_socket, &message))
{
@@ -346,7 +344,7 @@ ZBX_THREAD_ENTRY(alerter_thread, args)
exit(EXIT_FAILURE);
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
time_read = zbx_time();
time_idle += time_read - time_now;
diff --git a/src/zabbix_server/availability/avail_manager.c b/src/zabbix_server/availability/avail_manager.c
index 4601049147f..2f9d1806c2b 100644
--- a/src/zabbix_server/availability/avail_manager.c
+++ b/src/zabbix_server/availability/avail_manager.c
@@ -27,9 +27,7 @@
#include "zbxnum.h"
#include "zbxtime.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
static sigset_t orig_mask;
typedef struct
@@ -419,18 +417,18 @@ ZBX_THREAD_ENTRY(availability_manager_thread, args)
zbx_vector_availability_ptr_t interface_availabilities;
zbx_timespec_t timeout = {ZBX_AVAILABILITY_MANAGER_DELAY, 0};
zbx_avail_active_hb_cache_t active_hb_cache;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
-
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s #%d [connecting to the database]", get_process_type_string(process_type), process_num);
@@ -473,9 +471,9 @@ ZBX_THREAD_ENTRY(availability_manager_thread, args)
processed_num = 0;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_service_recv(&service, &timeout, &client, &message);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
sec = zbx_time();
zbx_update_env(sec);
diff --git a/src/zabbix_server/dbconfig/dbconfig.c b/src/zabbix_server/dbconfig/dbconfig.c
index 8691099487f..4adf29693ec 100644
--- a/src/zabbix_server/dbconfig/dbconfig.c
+++ b/src/zabbix_server/dbconfig/dbconfig.c
@@ -29,9 +29,7 @@
#include "valuecache.h"
extern int CONFIG_CONFSYNCER_FREQUENCY;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
/******************************************************************************
* *
@@ -45,15 +43,15 @@ ZBX_THREAD_ENTRY(dbconfig_thread, args)
double sec = 0.0;
int nextcheck = 0, sleeptime, secrets_reload = 0, cache_reload = 0;
zbx_ipc_async_socket_t rtc;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_rtc_subscribe(&rtc, process_type, process_num);
@@ -79,7 +77,7 @@ ZBX_THREAD_ENTRY(dbconfig_thread, args)
sleeptime = nextcheck - (int)time(NULL);
- while (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ while (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
if (ZBX_RTC_CONFIG_CACHE_RELOAD == rtc_cmd)
{
diff --git a/src/zabbix_server/dbsyncer/dbsyncer.c b/src/zabbix_server/dbsyncer/dbsyncer.c
index 6edf51720c6..75853919921 100644
--- a/src/zabbix_server/dbsyncer/dbsyncer.c
+++ b/src/zabbix_server/dbsyncer/dbsyncer.c
@@ -27,9 +27,7 @@
#include "zbxexport.h"
extern int CONFIG_HISTSYNCER_FREQUENCY;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
static sigset_t orig_mask;
/******************************************************************************
@@ -83,21 +81,22 @@ static void db_trigger_queue_cleanup(void)
******************************************************************************/
ZBX_THREAD_ENTRY(dbsyncer_thread, args)
{
- int sleeptime = -1, total_values_num = 0, values_num, more, total_triggers_num = 0, triggers_num;
- double sec, total_sec = 0.0;
- time_t last_stat_time;
- char *stats = NULL;
- const char *process_name;
- size_t stats_alloc = 0, stats_offset = 0;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ int sleeptime = -1, total_values_num = 0, values_num, more, total_triggers_num = 0,
+ triggers_num;
+ double sec, total_sec = 0.0;
+ time_t last_stat_time;
+ char *stats = NULL;
+ const char *process_name;
+ size_t stats_alloc = 0, stats_offset = 0;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type), server_num,
(process_name = get_process_type_string(process_type)), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
@@ -181,7 +180,7 @@ ZBX_THREAD_ENTRY(dbsyncer_thread, args)
if (!ZBX_IS_RUNNING())
break;
- zbx_sleep_loop(sleeptime);
+ zbx_sleep_loop(info, sleeptime);
}
/* database APIs might not handle signals correctly and hang, block signals to avoid hanging */
diff --git a/src/zabbix_server/discoverer/discoverer.c b/src/zabbix_server/discoverer/discoverer.c
index 0a6ca298941..e78278b53b4 100644
--- a/src/zabbix_server/discoverer/discoverer.c
+++ b/src/zabbix_server/discoverer/discoverer.c
@@ -35,9 +35,7 @@
#include "zbxsysinfo.h"
#include "zbx_rtc_constants.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
#define ZBX_DISCOVERER_IPRANGE_LIMIT (1 << 16)
@@ -836,16 +834,16 @@ ZBX_THREAD_ENTRY(discoverer_thread, args)
double sec, total_sec = 0.0, old_total_sec = 0.0;
time_t last_stat_time, nextcheck = 0;
zbx_ipc_async_socket_t rtc;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(discoverer_args_in->zbx_get_program_type_cb_arg()), server_num,
get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
@@ -907,7 +905,7 @@ ZBX_THREAD_ENTRY(discoverer_thread, args)
last_stat_time = time(NULL);
}
- if (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ if (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
#ifdef HAVE_NETSNMP
if (ZBX_RTC_SNMP_CACHE_RELOAD == rtc_cmd)
diff --git a/src/zabbix_server/escalator/escalator.c b/src/zabbix_server/escalator/escalator.c
index fb2608dbac4..96ad3046ac7 100644
--- a/src/zabbix_server/escalator/escalator.c
+++ b/src/zabbix_server/escalator/escalator.c
@@ -32,6 +32,7 @@
#include "zbxnum.h"
#include "zbxtime.h"
#include "zbxexpr.h"
+#include "zbxdbwrap.h"
extern int CONFIG_ESCALATOR_FORKS;
@@ -114,9 +115,6 @@ static void zbx_tag_filter_free(zbx_tag_filter_t *tag_filter)
zbx_free(tag_filter);
}
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
-
static void add_message_alert(const ZBX_DB_EVENT *event, const ZBX_DB_EVENT *r_event, zbx_uint64_t actionid,
int esc_step, zbx_uint64_t userid, zbx_uint64_t mediatypeid, const char *subject, const char *message,
const DB_ACKNOWLEDGE *ack, const zbx_service_alarm_t *service_alarm, const ZBX_DB_SERVICE *service,
@@ -3267,6 +3265,7 @@ out:
* Parameters: now - [IN] the current time *
* nextcheck - [IN/OUT] time of the next invocation *
* escalation_source - [IN] type of escalations to be handled *
+ * process_num - [IN] process number *
* *
* Return value: the count of deleted escalations *
* *
@@ -3278,7 +3277,7 @@ out:
* *
******************************************************************************/
static int process_escalations(int now, int *nextcheck, unsigned int escalation_source,
- const char *default_timezone)
+ const char *default_timezone, int process_num)
{
int ret = 0;
DB_RESULT result;
@@ -3438,16 +3437,16 @@ ZBX_THREAD_ENTRY(escalator_thread, args)
double sec, total_sec = 0.0, old_total_sec = 0.0;
time_t last_stat_time;
zbx_config_t cfg;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(escalator_args_in->zbx_get_program_type_cb_arg()), server_num,
get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
@@ -3476,13 +3475,13 @@ ZBX_THREAD_ENTRY(escalator_thread, args)
nextcheck = time(NULL) + CONFIG_ESCALATOR_FREQUENCY;
escalations_count += process_escalations(time(NULL), &nextcheck, ZBX_ESCALATION_SOURCE_TRIGGER,
- cfg.default_timezone);
+ cfg.default_timezone, process_num);
escalations_count += process_escalations(time(NULL), &nextcheck, ZBX_ESCALATION_SOURCE_ITEM,
- cfg.default_timezone);
+ cfg.default_timezone, process_num);
escalations_count += process_escalations(time(NULL), &nextcheck, ZBX_ESCALATION_SOURCE_SERVICE,
- cfg.default_timezone);
+ cfg.default_timezone, process_num);
escalations_count += process_escalations(time(NULL), &nextcheck, ZBX_ESCALATION_SOURCE_DEFAULT,
- cfg.default_timezone);
+ cfg.default_timezone, process_num);
zbx_config_clean(&cfg);
total_sec += zbx_time() - sec;
@@ -3513,7 +3512,7 @@ ZBX_THREAD_ENTRY(escalator_thread, args)
last_stat_time = now;
}
- zbx_sleep_loop(sleeptime);
+ zbx_sleep_loop(info, sleeptime);
}
zbx_setproctitle("%s #%d [terminated]", get_process_type_string(process_type), process_num);
diff --git a/src/zabbix_server/housekeeper/housekeeper.c b/src/zabbix_server/housekeeper/housekeeper.c
index 71e48bf587c..f544edf1c8f 100644
--- a/src/zabbix_server/housekeeper/housekeeper.c
+++ b/src/zabbix_server/housekeeper/housekeeper.c
@@ -29,9 +29,12 @@
#include "history_compress.h"
#include "zbx_rtc_constants.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
+
+static struct zbx_db_version_info_t *db_version_info;
+
+#if defined(HAVE_POSTGRESQL)
+static int tsdb_version = 0;
+#endif
static int hk_period;
@@ -569,6 +572,39 @@ out:
#endif
}
+#if defined(HAVE_POSTGRESQL)
+static void hk_tsdb_check_config(void)
+{
+ if (cfg.hk.history_global == ZBX_HK_OPTION_DISABLED && cfg.hk.history_mode == ZBX_HK_OPTION_ENABLED &&
+ 1 == db_version_info->history_compressed_chunks)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Incorrect configuration. Override item history period is disabled, but "
+ "historical data is compressed. Housekeeper may skip deleting this data.");
+ }
+
+ if (cfg.hk.trends_global == ZBX_HK_OPTION_DISABLED && cfg.hk.trends_mode == ZBX_HK_OPTION_ENABLED &&
+ 1 == db_version_info->trends_compressed_chunks)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Incorrect configuration. Override item trends period is disabled, but "
+ "trends data is compressed. Housekeeper may skip deleting this data.");
+ }
+}
+
+static void hk_update_dbversion_status(void)
+{
+ struct zbx_json db_version_json;
+
+ zbx_json_initarray(&db_version_json, ZBX_JSON_STAT_BUF_LEN);
+
+ zbx_tsdb_extract_compressed_chunk_flags(db_version_info);
+
+ zbx_db_version_json_create(&db_version_json, db_version_info);
+ zbx_db_flush_version_requirements(db_version_json.buffer);
+
+ zbx_json_free(&db_version_json);
+}
+#endif
+
/******************************************************************************
* *
* Purpose: performs housekeeping for history and trends tables *
@@ -580,18 +616,28 @@ static int housekeeping_history_and_trends(int now)
{
int deleted = 0, i, rc;
zbx_hk_history_rule_t *rule;
+#if defined(HAVE_POSTGRESQL)
+ int ignore_history = 0, ignore_trends = 0;
+#endif
zabbix_log(LOG_LEVEL_DEBUG, "In %s() now:%d", __func__, now);
/* prepare delete queues for all history housekeeping rules */
hk_history_delete_queue_prepare_all(hk_history_rules, now);
+#if defined(HAVE_POSTGRESQL)
+ if (tsdb_version > 0)
+ {
+ hk_update_dbversion_status();
+ }
+#endif
+
/* Loop through the history rules. Each rule is a history table (such as history_log, trends_uint, etc) */
/* we need to clear records from */
for (rule = hk_history_rules; NULL != rule->table; rule++)
{
if (ZBX_HK_MODE_DISABLED == *rule->poption_mode)
- continue;
+ goto skip;
/* If partitioning enabled for history and/or trends then drop partitions with expired history. */
/* ZBX_HK_MODE_PARTITION is set during configuration sync based on the following: */
@@ -600,9 +646,44 @@ static int housekeeping_history_and_trends(int now)
if (ZBX_HK_MODE_PARTITION == *rule->poption_mode)
{
hk_drop_partition_for_rule(rule, now);
- continue;
+ goto skip;
}
+#if defined(HAVE_POSTGRESQL)
+ if (tsdb_version > 0)
+ {
+ if (0 == strcmp(rule->history, "history"))
+ {
+ if (1 == ignore_history)
+ goto skip;
+
+ if (1 == db_version_info->history_compressed_chunks)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Unable to perform housekeeping for history "
+ "tables due to having compressed chunks and disabled item "
+ "history period override.");
+
+ ignore_history = 1;
+ goto skip;
+ }
+ }
+ else if (0 == strcmp(rule->history, "trends"))
+ {
+ if (1 == ignore_trends)
+ goto skip;
+
+ if (1 == db_version_info->trends_compressed_chunks)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Unable to perform housekeeping for trends "
+ "tables due to having compressed chunks and disabled item "
+ "trends period override.");
+
+ ignore_trends = 1;
+ goto skip;
+ }
+ }
+ }
+#endif
/* process delete queue for the housekeeping rule */
zbx_vector_ptr_sort(&rule->delete_queue, hk_item_update_cache_compare);
@@ -616,7 +697,7 @@ static int housekeeping_history_and_trends(int now)
if (ZBX_DB_OK < rc)
deleted += rc;
}
-
+skip:
/* clear history rule delete queue so it's ready for the next housekeeping cycle */
hk_history_delete_queue_clear(rule);
}
@@ -1117,20 +1198,27 @@ static int get_housekeeping_period(double time_slept)
ZBX_THREAD_ENTRY(housekeeper_thread, args)
{
- int now, d_history_and_trends, d_cleanup, d_events, d_problems, d_sessions, d_services,
- d_audit, sleeptime, records;
- double sec, time_slept, time_now;
- char sleeptext[25];
- zbx_ipc_async_socket_t rtc;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ zbx_thread_housekeeper_args *housekeeper_args_in = (zbx_thread_housekeeper_args *)
+ (((zbx_thread_args_t *)args)->args);
+ int now, d_history_and_trends, d_cleanup, d_events, d_problems, d_sessions,
+ d_services, d_audit, sleeptime, records;
+ double sec, time_slept, time_now;
+ char sleeptext[25];
+ zbx_ipc_async_socket_t rtc;
+ unsigned char program_type;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
+
+ db_version_info = housekeeper_args_in->db_version_info;
+
+ program_type = housekeeper_args_in->zbx_get_program_type_cb_arg();
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (0 == CONFIG_HOUSEKEEPING_FREQUENCY)
{
@@ -1150,6 +1238,18 @@ ZBX_THREAD_ENTRY(housekeeper_thread, args)
zbx_rtc_subscribe(&rtc, process_type, process_num);
+#if defined(HAVE_POSTGRESQL)
+ DBconnect(ZBX_DB_CONNECT_NORMAL);
+ tsdb_version = zbx_tsdb_get_version();
+ DBclose();
+
+ if (tsdb_version > 0)
+ {
+ zbx_config_get(&cfg, ZBX_CONFIG_FLAGS_HOUSEKEEPER);
+ hk_tsdb_check_config();
+ }
+#endif
+
while (ZBX_IS_RUNNING())
{
zbx_uint32_t rtc_cmd;
@@ -1158,7 +1258,7 @@ ZBX_THREAD_ENTRY(housekeeper_thread, args)
sec = zbx_time();
- while (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ while (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
switch (rtc_cmd)
{
diff --git a/src/zabbix_server/housekeeper/housekeeper.h b/src/zabbix_server/housekeeper/housekeeper.h
index b02efa0396f..9afeb6651ac 100644
--- a/src/zabbix_server/housekeeper/housekeeper.h
+++ b/src/zabbix_server/housekeeper/housekeeper.h
@@ -25,6 +25,14 @@
extern int CONFIG_HOUSEKEEPING_FREQUENCY;
extern int CONFIG_MAX_HOUSEKEEPER_DELETE;
+typedef struct
+{
+ zbx_get_program_type_f zbx_get_program_type_cb_arg;
+ struct zbx_db_version_info_t *db_version_info;
+}
+zbx_thread_housekeeper_args;
+
+
ZBX_THREAD_ENTRY(housekeeper_thread, args);
#endif
diff --git a/src/zabbix_server/housekeeper/trigger_housekeeper.c b/src/zabbix_server/housekeeper/trigger_housekeeper.c
index d562ee54b30..c738942cb8d 100644
--- a/src/zabbix_server/housekeeper/trigger_housekeeper.c
+++ b/src/zabbix_server/housekeeper/trigger_housekeeper.c
@@ -28,9 +28,7 @@
#include "zbxtime.h"
#include "zbx_rtc_constants.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_PROBLEMHOUSEKEEPING_FREQUENCY;
@@ -92,18 +90,18 @@ static int housekeep_problems_without_triggers(void)
ZBX_THREAD_ENTRY(trigger_housekeeper_thread, args)
{
- int deleted;
- double sec;
+ int deleted;
+ double sec;
zbx_ipc_async_socket_t rtc;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type));
DBconnect(ZBX_DB_CONNECT_NORMAL);
@@ -118,7 +116,7 @@ ZBX_THREAD_ENTRY(trigger_housekeeper_thread, args)
zbx_uint32_t rtc_cmd;
unsigned char *rtc_data;
- if (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, CONFIG_PROBLEMHOUSEKEEPING_FREQUENCY) &&
+ if (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, CONFIG_PROBLEMHOUSEKEEPING_FREQUENCY) &&
0 != rtc_cmd)
{
if (ZBX_RTC_SHUTDOWN == rtc_cmd)
diff --git a/src/zabbix_server/httppoller/httppoller.c b/src/zabbix_server/httppoller/httppoller.c
index 8cbcabf2ae8..21e11a19499 100644
--- a/src/zabbix_server/httppoller/httppoller.c
+++ b/src/zabbix_server/httppoller/httppoller.c
@@ -26,9 +26,7 @@
#include "httptest.h"
#include "zbxtime.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
/******************************************************************************
* *
@@ -39,18 +37,18 @@ extern ZBX_THREAD_LOCAL int server_num, process_num;
******************************************************************************/
ZBX_THREAD_ENTRY(httppoller_thread, args)
{
- int sleeptime = -1, httptests_count = 0, old_httptests_count = 0;
- double sec, total_sec = 0.0, old_total_sec = 0.0;
- time_t last_stat_time, nextcheck = 0;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ int sleeptime = -1, httptests_count = 0, old_httptests_count = 0;
+ double sec, total_sec = 0.0, old_total_sec = 0.0;
+ time_t last_stat_time, nextcheck = 0;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
@@ -104,7 +102,7 @@ ZBX_THREAD_ENTRY(httppoller_thread, args)
last_stat_time = time(NULL);
}
- zbx_sleep_loop(sleeptime);
+ zbx_sleep_loop(info, sleeptime);
}
zbx_setproctitle("%s #%d [terminated]", get_process_type_string(process_type), process_num);
diff --git a/src/zabbix_server/ipmi/ipmi_manager.c b/src/zabbix_server/ipmi/ipmi_manager.c
index 66ac2e9f5ff..0f57b6abd7a 100644
--- a/src/zabbix_server/ipmi/ipmi_manager.c
+++ b/src/zabbix_server/ipmi/ipmi_manager.c
@@ -38,9 +38,7 @@
#define ZBX_IPMI_MANAGER_DELAY 1
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_IPMIPOLLER_FORKS;
@@ -950,20 +948,20 @@ ZBX_THREAD_ENTRY(ipmi_manager_thread, args)
int ret, nextcheck, nextcleanup, polled_num = 0, scheduled_num = 0, now;
double time_stat, time_idle = 0, time_now, sec;
zbx_timespec_t timeout = {0, 0};
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
-
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (FAIL == zbx_ipc_service_start(&ipmi_service, ZBX_IPC_SERVICE_IPMI, &error))
{
@@ -1010,9 +1008,9 @@ ZBX_THREAD_ENTRY(ipmi_manager_thread, args)
if (ZBX_IPMI_MANAGER_DELAY < timeout.sec)
timeout.sec = ZBX_IPMI_MANAGER_DELAY;
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_service_recv(&ipmi_service, &timeout, &client, &message);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
sec = zbx_time();
zbx_update_env(sec);
diff --git a/src/zabbix_server/ipmi/ipmi_poller.c b/src/zabbix_server/ipmi/ipmi_poller.c
index b0121409a09..3c8ec5edcbf 100644
--- a/src/zabbix_server/ipmi/ipmi_poller.c
+++ b/src/zabbix_server/ipmi/ipmi_poller.c
@@ -33,9 +33,7 @@
#define ZBX_IPMI_MANAGER_CLEANUP_DELAY SEC_PER_DAY
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
/******************************************************************************
* *
@@ -173,21 +171,20 @@ ZBX_THREAD_ENTRY(ipmi_poller_thread, args)
zbx_ipc_async_socket_t ipmi_socket;
int polled_num = 0;
double time_stat, time_idle = 0, time_now, time_read;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
- process_type = ((zbx_thread_args_t *)args)->process_type;
-
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
-
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (FAIL == zbx_ipc_async_socket_open(&ipmi_socket, ZBX_IPC_SERVICE_IPMI, SEC_PER_MIN, &error))
{
@@ -221,7 +218,7 @@ ZBX_THREAD_ENTRY(ipmi_poller_thread, args)
polled_num = 0;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
while (ZBX_IS_RUNNING())
{
@@ -240,7 +237,7 @@ ZBX_THREAD_ENTRY(ipmi_poller_thread, args)
zbx_perform_all_openipmi_ops(ipmi_timeout);
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (NULL == message)
break;
diff --git a/src/zabbix_server/lld/lld.c b/src/zabbix_server/lld/lld.c
index 8c2ecc771cb..3af8d4a0397 100644
--- a/src/zabbix_server/lld/lld.c
+++ b/src/zabbix_server/lld/lld.c
@@ -18,7 +18,7 @@
**/
#include "lld.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxserver.h"
#include "log.h"
diff --git a/src/zabbix_server/lld/lld.h b/src/zabbix_server/lld/lld.h
index f9ec2024da6..46720af4a23 100644
--- a/src/zabbix_server/lld/lld.h
+++ b/src/zabbix_server/lld/lld.h
@@ -260,4 +260,6 @@ typedef void (*get_object_info_f)(const void *object, zbx_uint64_t *id, int *dis
void lld_remove_lost_objects(const char *table, const char *id_name, const zbx_vector_ptr_t *objects,
int lifetime, int lastcheck, delete_ids_f cb, get_object_info_f cb_info);
+int lld_process_discovery_rule(zbx_uint64_t lld_ruleid, const char *value, char **error);
+
#endif
diff --git a/src/zabbix_server/lld/lld_graph.c b/src/zabbix_server/lld/lld_graph.c
index 9a7334a016b..b708791a720 100644
--- a/src/zabbix_server/lld/lld_graph.c
+++ b/src/zabbix_server/lld/lld_graph.c
@@ -19,6 +19,7 @@
#include "lld.h"
#include "zbxserver.h"
+#include "zbxdbwrap.h"
#include "log.h"
#include "audit/zbxaudit.h"
diff --git a/src/zabbix_server/lld/lld_host.c b/src/zabbix_server/lld/lld_host.c
index 12cfcbbf118..1e1a96c55b2 100644
--- a/src/zabbix_server/lld/lld_host.c
+++ b/src/zabbix_server/lld/lld_host.c
@@ -26,6 +26,7 @@
#include "audit/zbxaudit.h"
#include "audit/zbxaudit_host.h"
#include "zbxnum.h"
+#include "zbxdbwrap.h"
/* host macro discovery state */
#define ZBX_USERMACRO_MANUAL 0
diff --git a/src/zabbix_server/lld/lld_item.c b/src/zabbix_server/lld/lld_item.c
index d1cf75e32b7..5a88396fd9d 100644
--- a/src/zabbix_server/lld/lld_item.c
+++ b/src/zabbix_server/lld/lld_item.c
@@ -26,6 +26,7 @@
#include "zbxprometheus.h"
#include "zbxxml.h"
#include "zbxnum.h"
+#include "zbxdbwrap.h"
#include "audit/zbxaudit.h"
#include "audit/zbxaudit_item.h"
diff --git a/src/zabbix_server/lld/lld_manager.c b/src/zabbix_server/lld/lld_manager.c
index 845b6dbc596..f0c95ca399e 100644
--- a/src/zabbix_server/lld/lld_manager.c
+++ b/src/zabbix_server/lld/lld_manager.c
@@ -27,9 +27,7 @@
#include "zbxstr.h"
#include "zbxtime.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_LLDWORKER_FORKS;
@@ -567,10 +565,10 @@ ZBX_THREAD_ENTRY(lld_manager_thread, args)
zbx_uint64_t processed_num = 0;
int ret;
zbx_timespec_t timeout = {1, 0};
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
@@ -591,7 +589,7 @@ ZBX_THREAD_ENTRY(lld_manager_thread, args)
zbx_setproctitle("%s #%d started", get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
while (ZBX_IS_RUNNING())
{
@@ -609,9 +607,9 @@ ZBX_THREAD_ENTRY(lld_manager_thread, args)
processed_num = 0;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_service_recv(&lld_service, &timeout, &client, &message);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
sec = zbx_time();
zbx_update_env(sec);
diff --git a/src/zabbix_server/lld/lld_trigger.c b/src/zabbix_server/lld/lld_trigger.c
index 1aec3db991c..9f9612f5296 100644
--- a/src/zabbix_server/lld/lld_trigger.c
+++ b/src/zabbix_server/lld/lld_trigger.c
@@ -25,6 +25,7 @@
#include "audit/zbxaudit.h"
#include "audit/zbxaudit_trigger.h"
#include "zbxnum.h"
+#include "zbxdbwrap.h"
typedef struct
{
diff --git a/src/zabbix_server/lld/lld_worker.c b/src/zabbix_server/lld/lld_worker.c
index 72ec4c6b059..1efea25c6fc 100644
--- a/src/zabbix_server/lld/lld_worker.c
+++ b/src/zabbix_server/lld/lld_worker.c
@@ -18,19 +18,18 @@
**/
#include "lld_worker.h"
+#include "lld.h"
#include "zbxnix.h"
#include "log.h"
#include "zbxipcservice.h"
#include "zbxself.h"
-#include "proxy.h"
#include "../events.h"
#include "lld_protocol.h"
#include "zbxtime.h"
+#include "zbxdbwrap.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
/******************************************************************************
* *
@@ -175,10 +174,10 @@ ZBX_THREAD_ENTRY(lld_worker_thread, args)
zbx_ipc_message_t message;
double time_stat, time_idle = 0, time_now, time_read;
zbx_uint64_t processed_num = 0;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
@@ -202,7 +201,7 @@ ZBX_THREAD_ENTRY(lld_worker_thread, args)
zbx_setproctitle("%s #%d started", get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
while (ZBX_IS_RUNNING())
{
@@ -219,13 +218,13 @@ ZBX_THREAD_ENTRY(lld_worker_thread, args)
processed_num = 0;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
if (SUCCEED != zbx_ipc_socket_read(&lld_socket, &message))
{
zabbix_log(LOG_LEVEL_CRIT, "cannot read LLD manager service request");
exit(EXIT_FAILURE);
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
time_read = zbx_time();
time_idle += time_read - time_now;
diff --git a/src/zabbix_server/lld/lld_worker.h b/src/zabbix_server/lld/lld_worker.h
index 27ef4737b5a..809755ab3c1 100644
--- a/src/zabbix_server/lld/lld_worker.h
+++ b/src/zabbix_server/lld/lld_worker.h
@@ -17,8 +17,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#ifndef ZABBIX_LLD_H
-#define ZABBIX_LLD_H
+#ifndef ZABBIX_LLD_WORKER_H
+#define ZABBIX_LLD_WORKER_H
#include "zbxthreads.h"
diff --git a/src/zabbix_server/operations.c b/src/zabbix_server/operations.c
index be44b3055a6..197fd6f809b 100644
--- a/src/zabbix_server/operations.c
+++ b/src/zabbix_server/operations.c
@@ -24,6 +24,7 @@
#include "audit/zbxaudit.h"
#include "audit/zbxaudit_host.h"
#include "zbxnum.h"
+#include "zbxdbwrap.h"
typedef enum
{
diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c
index a79a86b6caf..e0228c7eaea 100644
--- a/src/zabbix_server/pinger/pinger.c
+++ b/src/zabbix_server/pinger/pinger.c
@@ -37,9 +37,7 @@
#define MAX_SIZE 65507
#define MIN_TIMEOUT 50
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
/******************************************************************************
* *
@@ -490,7 +488,7 @@ static void add_pinger_host(ZBX_FPING_HOST **hosts, int *hosts_alloc, int *hosts
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
}
-static void process_pinger_hosts(icmpitem_t *items, int items_count)
+static void process_pinger_hosts(icmpitem_t *items, int items_count, int process_num, int process_type)
{
int i, first_index = 0, ping_result;
char error[ZBX_ITEM_ERROR_LEN_MAX];
@@ -543,15 +541,15 @@ ZBX_THREAD_ENTRY(pinger_thread, args)
double sec;
static icmpitem_t *items = NULL;
static int items_alloc = 4;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (NULL == items)
items = (icmpitem_t *)zbx_malloc(items, sizeof(icmpitem_t) * items_alloc);
@@ -564,7 +562,7 @@ ZBX_THREAD_ENTRY(pinger_thread, args)
zbx_setproctitle("%s #%d [getting values]", get_process_type_string(process_type), process_num);
get_pinger_hosts(&items, &items_alloc, &items_count);
- process_pinger_hosts(items, items_count);
+ process_pinger_hosts(items, items_count, process_num, process_type);
sec = zbx_time() - sec;
itc = items_count;
@@ -576,7 +574,7 @@ ZBX_THREAD_ENTRY(pinger_thread, args)
zbx_setproctitle("%s #%d [got %d values in " ZBX_FS_DBL " sec, idle %d sec]",
get_process_type_string(process_type), process_num, itc, sec, sleeptime);
- zbx_sleep_loop(sleeptime);
+ zbx_sleep_loop(info, sleeptime);
}
zbx_setproctitle("%s #%d [terminated]", get_process_type_string(process_type), process_num);
diff --git a/src/zabbix_server/poller/checks_internal.c b/src/zabbix_server/poller/checks_internal.c
index 9d1b5feeb20..ec02e1de031 100644
--- a/src/zabbix_server/poller/checks_internal.c
+++ b/src/zabbix_server/poller/checks_internal.c
@@ -497,13 +497,13 @@ int get_value_internal(const DC_ITEM *item, AGENT_RESULT *result, const zbx_conf
unsigned short process_num = 0;
if ('\0' == *tmp || 0 == strcmp(tmp, "avg"))
- aggr_func = ZBX_AGGR_FUNC_AVG;
+ aggr_func = ZBX_SELFMON_AGGR_FUNC_AVG;
else if (0 == strcmp(tmp, "max"))
- aggr_func = ZBX_AGGR_FUNC_MAX;
+ aggr_func = ZBX_SELFMON_AGGR_FUNC_MAX;
else if (0 == strcmp(tmp, "min"))
- aggr_func = ZBX_AGGR_FUNC_MIN;
+ aggr_func = ZBX_SELFMON_AGGR_FUNC_MIN;
else if (SUCCEED == zbx_is_ushort(tmp, &process_num) && 0 < process_num)
- aggr_func = ZBX_AGGR_FUNC_ONE;
+ aggr_func = ZBX_SELFMON_AGGR_FUNC_ONE;
else
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
diff --git a/src/zabbix_server/poller/checks_simple.c b/src/zabbix_server/poller/checks_simple.c
index 10ea6280a43..38b21bd6381 100644
--- a/src/zabbix_server/poller/checks_simple.c
+++ b/src/zabbix_server/poller/checks_simple.c
@@ -57,6 +57,7 @@ static zbx_vmcheck_t vmchecks[] =
{"datastore.discovery", VMCHECK_FUNC(check_vcenter_datastore_discovery)},
{"datastore.tags.get", VMCHECK_FUNC(check_vcenter_datastore_tags_get)},
{"datastore.read", VMCHECK_FUNC(check_vcenter_datastore_read)},
+ {"datastore.perfcounter", VMCHECK_FUNC(check_vcenter_datastore_perfcounter)},
{"datastore.property", VMCHECK_FUNC(check_vcenter_datastore_property)},
{"datastore.size", VMCHECK_FUNC(check_vcenter_datastore_size)},
{"datastore.write", VMCHECK_FUNC(check_vcenter_datastore_write)},
@@ -77,6 +78,7 @@ static zbx_vmcheck_t vmchecks[] =
{"hv.datastore.list", VMCHECK_FUNC(check_vcenter_hv_datastore_list)},
{"hv.datastore.multipath", VMCHECK_FUNC(check_vcenter_hv_datastore_multipath)},
{"hv.discovery", VMCHECK_FUNC(check_vcenter_hv_discovery)},
+ {"hv.diskinfo.get", VMCHECK_FUNC(check_vcenter_hv_diskinfo_get)},
{"hv.fullname", VMCHECK_FUNC(check_vcenter_hv_fullname)},
{"hv.hw.cpu.num", VMCHECK_FUNC(check_vcenter_hv_hw_cpu_num)},
{"hv.hw.cpu.freq", VMCHECK_FUNC(check_vcenter_hv_hw_cpu_freq)},
@@ -217,12 +219,12 @@ int get_value_simple(const DC_ITEM *item, AGENT_RESULT *result, zbx_vector_ptr_t
if (0 == strcmp(request.key, "net.tcp.service") || 0 == strcmp(request.key, "net.udp.service"))
{
- if (SYSINFO_RET_OK == check_service(&request, item->interface.addr, result, 0))
+ if (SYSINFO_RET_OK == zbx_check_service_default_addr(&request, item->interface.addr, result, 0))
ret = SUCCEED;
}
else if (0 == strcmp(request.key, "net.tcp.service.perf") || 0 == strcmp(request.key, "net.udp.service.perf"))
{
- if (SYSINFO_RET_OK == check_service(&request, item->interface.addr, result, 1))
+ if (SYSINFO_RET_OK == zbx_check_service_default_addr(&request, item->interface.addr, result, 1))
ret = SUCCEED;
}
else if (SUCCEED == get_vmware_function(request.key, &vmfunc))
diff --git a/src/zabbix_server/poller/checks_simple_vmware.c b/src/zabbix_server/poller/checks_simple_vmware.c
index 03eb3548802..f2bfbe6e618 100644
--- a/src/zabbix_server/poller/checks_simple_vmware.c
+++ b/src/zabbix_server/poller/checks_simple_vmware.c
@@ -302,6 +302,18 @@ static int vmware_service_get_counter_value_by_id(zbx_vmware_service_t *service,
perfcounter = (zbx_vmware_perf_counter_t *)entity->counters.values[i];
+ if (0 != (perfcounter->state & ZBX_VMWARE_COUNTER_NOTSUPPORTED))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Performance counter not supported or data not ready."));
+ goto out;
+ }
+
+ if (0 != (ZBX_VMWARE_COUNTER_CUSTOM & perfcounter->state) &&
+ 0 != (ZBX_VMWARE_COUNTER_READY & perfcounter->state))
+ {
+ perfcounter->last_used = time(NULL);
+ }
+
if (0 == (perfcounter->state & ZBX_VMWARE_COUNTER_READY))
{
ret = SYSINFO_RET_OK;
@@ -645,18 +657,20 @@ static int custquery_read_result(zbx_vmware_cust_query_t *custom_query, AGENT_RE
}
if (0 != (custom_query->state & ZBX_VMWARE_CQ_READY))
+ {
SET_STR_RESULT(result, zbx_strdup(NULL, ZBX_NULL2EMPTY_STR(custom_query->value)));
- if (0 != (custom_query->state & ZBX_VMWARE_CQ_PAUSED))
- custom_query->state &= (unsigned char)~ZBX_VMWARE_CQ_PAUSED;
+ if (0 != (custom_query->state & ZBX_VMWARE_CQ_PAUSED))
+ custom_query->state &= (unsigned char)~ZBX_VMWARE_CQ_PAUSED;
- if (NULL != custom_query->value && '\0' != *custom_query->value &&
- 0 != (custom_query->state & ZBX_VMWARE_CQ_SEPARATE))
- {
- custom_query->state &= (unsigned char)~ZBX_VMWARE_CQ_SEPARATE;
- }
+ if (NULL != custom_query->value && '\0' != *custom_query->value &&
+ 0 != (custom_query->state & ZBX_VMWARE_CQ_SEPARATE))
+ {
+ custom_query->state &= (unsigned char)~ZBX_VMWARE_CQ_SEPARATE;
+ }
- custom_query->last_pooled = time(NULL);
+ custom_query->last_pooled = time(NULL);
+ }
return SYSINFO_RET_OK;
}
@@ -791,6 +805,12 @@ int check_vcenter_cluster_discovery(AGENT_REQUEST *request, const char *username
zbx_json_addarray(&json_data, "tags");
vmware_tags_id_json(&service->data_tags, ZBX_VMWARE_SOAP_CLUSTER, cluster->id, &json_data, NULL);
zbx_json_close(&json_data);
+ zbx_json_addarray(&json_data, "datastore_uuid");
+
+ for (j = 0; j < cluster->dss_uuid.values_num; j++)
+ zbx_json_addstring(&json_data, NULL, cluster->dss_uuid.values[j], ZBX_JSON_TYPE_STRING);
+
+ zbx_json_close(&json_data);
zbx_json_close(&json_data);
}
@@ -1407,7 +1427,7 @@ int check_vcenter_hv_discovery(AGENT_REQUEST *request, const char *username, con
AGENT_RESULT *result)
{
struct zbx_json json_data;
- const char *url, *name;
+ const char *url;
zbx_vmware_service_t *service;
int ret = SYSINFO_RET_FAIL;
zbx_vmware_hv_t *hv;
@@ -1434,6 +1454,7 @@ int check_vcenter_hv_discovery(AGENT_REQUEST *request, const char *username, con
while (NULL != (hv = (zbx_vmware_hv_t *)zbx_hashset_iter_next(&iter)))
{
int i;
+ const char *name;
zbx_vmware_cluster_t *cluster = NULL;
if (NULL == (name = hv->props[ZBX_VMWARE_HVPROP_NAME]))
@@ -1496,6 +1517,98 @@ out:
return ret;
}
+int check_vcenter_hv_diskinfo_get(AGENT_REQUEST *request, const char *username, const char *password,
+ AGENT_RESULT *result)
+{
+ struct zbx_json json_data;
+ const char *url, *uuid;
+ zbx_vmware_service_t *service;
+ int i, ret = SYSINFO_RET_FAIL;
+ zbx_vmware_hv_t *hv;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ if (2 != request->nparam)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
+ goto out;
+ }
+
+ url = get_rparam(request, 0);
+ uuid = get_rparam(request, 1);
+
+ if ('\0' == *uuid)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
+ goto out;
+ }
+
+ zbx_vmware_lock();
+
+ if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
+ goto unlock;
+
+ if (NULL == (hv = hv_get(&service->data->hvs, uuid)))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Unknown hypervisor uuid."));
+ goto unlock;
+ }
+
+ zbx_json_initarray(&json_data, ZBX_JSON_STAT_BUF_LEN);
+
+ for (i = 0; i < hv->diskinfo.values_num; i++)
+ {
+ zbx_vmware_diskinfo_t *di = hv->diskinfo.values[i];
+
+ zbx_json_addobject(&json_data, NULL);
+ zbx_json_addstring(&json_data, "instance", di->diskname,
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&json_data, "hv_uuid", hv->uuid, ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&json_data, "datastore_uuid", ZBX_NULL2EMPTY_STR(di->ds_uuid),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addraw(&json_data, "operational_state", ZBX_NULL2EMPTY_STR(di->operational_state));
+ zbx_json_addstring(&json_data, "lun_type", ZBX_NULL2EMPTY_STR(di->lun_type),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addint64(&json_data, "queue_depth", di->queue_depth);
+ zbx_json_addstring(&json_data, "model", ZBX_NULL2EMPTY_STR(di->model),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&json_data, "vendor", ZBX_NULL2EMPTY_STR(di->vendor),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&json_data, "revision", ZBX_NULL2EMPTY_STR(di->revision),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&json_data, "serial_number", ZBX_NULL2EMPTY_STR(di->serial_number),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addobject(&json_data, "vsan");
+
+ if (NULL != di->vsan)
+ {
+ zbx_json_addstring(&json_data, "ssd", ZBX_NULL2EMPTY_STR(di->vsan->ssd),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&json_data, "local_disk", ZBX_NULL2EMPTY_STR(di->vsan->local_disk),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_adduint64(&json_data, "block", di->vsan->block);
+ zbx_json_adduint64(&json_data, "block_size", di->vsan->block_size);
+ }
+
+ zbx_json_close(&json_data);
+ zbx_json_close(&json_data);
+ }
+
+ zbx_json_close(&json_data);
+
+ SET_STR_RESULT(result, zbx_strdup(NULL, json_data.buffer));
+
+ zbx_json_free(&json_data);
+
+ ret = SYSINFO_RET_OK;
+unlock:
+ zbx_vmware_unlock();
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_sysinfo_ret_string(ret));
+
+ return ret;
+}
+
int check_vcenter_hv_fullname(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result)
{
@@ -2310,17 +2423,41 @@ int check_vcenter_hv_datastore_discovery(AGENT_REQUEST *request, const char *use
for (i = 0; i < hv->dsnames.values_num; i++)
{
zbx_vmware_dsname_t *dsname = hv->dsnames.values[i];
+ zbx_vmware_datastore_t *datastore;
int j, total = 0;
+ if (NULL == (datastore = ds_get(&service->data->datastores, dsname->uuid)))
+ {
+ zbx_json_free(&json_data);
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Unknown datastore uuid."));
+ goto unlock;
+ }
+
for (j = 0; j < dsname->hvdisks.values_num; j++)
total += dsname->hvdisks.values[j].multipath_total;
zbx_json_addobject(&json_data, NULL);
zbx_json_addstring(&json_data, "{#DATASTORE}", dsname->name, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&json_data, "{#DATASTORE.UUID}", dsname->uuid, ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&json_data, "{#DATASTORE.TYPE}", ZBX_NULL2EMPTY_STR(datastore->type),
+ ZBX_JSON_TYPE_STRING);
zbx_json_adduint64(&json_data, "{#MULTIPATH.COUNT}", (unsigned int)total);
zbx_json_adduint64(&json_data, "{#MULTIPATH.PARTITION.COUNT}",
(unsigned int)dsname->hvdisks.values_num);
+ zbx_json_addarray(&json_data, "datastore_extent");
+
+ for (j = 0; j < datastore->diskextents.values_num; j++)
+ {
+ zbx_vmware_diskextent_t *ext = datastore->diskextents.values[j];
+
+ zbx_json_addobject(&json_data, NULL);
+ zbx_json_adduint64(&json_data, "partitionid", ext->partitionid);
+ zbx_json_addstring(&json_data, "instance", ext->diskname,
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_close(&json_data);
+ }
+
+ zbx_json_close(&json_data);
zbx_json_addarray(&json_data, "tags");
vmware_tags_uuid_json(&service->data_tags, dsname->uuid, &json_data, NULL);
zbx_json_close(&json_data);
@@ -2968,15 +3105,15 @@ int check_vcenter_cl_perfcounter(AGENT_REQUEST *request, const char *username, c
}
/* FAIL is returned if counter already exists */
- if (SUCCEED == zbx_vmware_service_add_perf_counter(service, "ClusterComputeResource", cluster->id,
- counterid, "*"))
+ if (SUCCEED == zbx_vmware_service_add_perf_counter(service, ZBX_VMWARE_SOAP_CLUSTER, cluster->id,
+ counterid, ZBX_VMWARE_PERF_QUERY_ALL))
{
ret = SYSINFO_RET_OK;
goto unlock;
}
/* the performance counter is already being monitored, try to get the results from statistics */
- ret = vmware_service_get_counter_value_by_id(service, "ClusterComputeResource", cluster->id, counterid,
+ ret = vmware_service_get_counter_value_by_id(service, ZBX_VMWARE_SOAP_CLUSTER, cluster->id, counterid,
instance, 1, unit, result);
unlock:
zbx_vmware_unlock();
@@ -3029,14 +3166,15 @@ int check_vcenter_hv_perfcounter(AGENT_REQUEST *request, const char *username, c
}
/* FAIL is returned if counter already exists */
- if (SUCCEED == zbx_vmware_service_add_perf_counter(service, "HostSystem", hv->id, counterid, "*"))
+ if (SUCCEED == zbx_vmware_service_add_perf_counter(service, ZBX_VMWARE_SOAP_HV, hv->id, counterid,
+ ZBX_VMWARE_PERF_QUERY_ALL))
{
ret = SYSINFO_RET_OK;
goto unlock;
}
/* the performance counter is already being monitored, try to get the results from statistics */
- ret = vmware_service_get_counter_value_by_id(service, "HostSystem", hv->id, counterid, instance, 1, unit,
+ ret = vmware_service_get_counter_value_by_id(service, ZBX_VMWARE_SOAP_HV, hv->id, counterid, instance, 1, unit,
result);
unlock:
zbx_vmware_unlock();
@@ -3277,6 +3415,67 @@ out:
return ret;
}
+int check_vcenter_datastore_perfcounter(AGENT_REQUEST *request, const char *username, const char *password,
+ AGENT_RESULT *result)
+{
+ const char *instance, *url, *uuid, *path;
+ zbx_vmware_service_t *service;
+ zbx_vmware_datastore_t *ds;
+ zbx_uint64_t counterid;
+ int unit, ret = SYSINFO_RET_FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ if (3 > request->nparam || request->nparam > 4)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters."));
+ goto out;
+ }
+
+ url = get_rparam(request, 0);
+ uuid = get_rparam(request, 1);
+ path = get_rparam(request, 2);
+ instance = get_rparam(request, 3);
+
+ if (NULL == instance)
+ instance = "";
+
+ zbx_vmware_lock();
+
+ if (NULL == (service = get_vmware_service(url, username, password, result, &ret)))
+ goto unlock;
+
+ if (NULL == (ds = ds_get(&service->data->datastores, uuid)))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Unknown datastore uuid."));
+ goto unlock;
+ }
+
+ if (FAIL == zbx_vmware_service_get_counterid(service, path, &counterid, &unit))
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Performance counter is not available."));
+ goto unlock;
+ }
+
+ /* FAIL is returned if counter already exists */
+ if (SUCCEED == zbx_vmware_service_add_perf_counter(service, ZBX_VMWARE_SOAP_DS, ds->id, counterid,
+ ZBX_VMWARE_PERF_QUERY_ALL))
+ {
+ ret = SYSINFO_RET_OK;
+ goto unlock;
+ }
+
+ /* the performance counter is already being monitored, try to get the results from statistics */
+ ret = vmware_service_get_counter_value_by_id(service, ZBX_VMWARE_SOAP_DS, ds->id, counterid, instance, 1, unit,
+ result);
+unlock:
+ zbx_vmware_unlock();
+out:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_sysinfo_ret_string(ret));
+
+ return ret;
+}
+
int check_vcenter_datastore_property(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result)
{
@@ -3408,18 +3607,23 @@ int check_vcenter_datastore_discovery(AGENT_REQUEST *request, const char *userna
for (i = 0; i < service->data->datastores.values_num; i++)
{
zbx_vmware_datastore_t *datastore = service->data->datastores.values[i];
+
zbx_json_addobject(&json_data, NULL);
zbx_json_addstring(&json_data, "{#DATASTORE}", datastore->name, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&json_data, "{#DATASTORE.UUID}", datastore->uuid, ZBX_JSON_TYPE_STRING);
- zbx_json_addobject(&json_data, "{#DATASTORE.EXTENT}");
+ zbx_json_addstring(&json_data, "{#DATASTORE.TYPE}", ZBX_NULL2EMPTY_STR(datastore->type),
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_addarray(&json_data, "datastore_extent");
for (j = 0; j < datastore->diskextents.values_num; j++)
{
- char buffer[MAX_ID_LEN];
- zbx_vmware_diskextent_t *extent = datastore->diskextents.values[j];
+ zbx_vmware_diskextent_t *ext = datastore->diskextents.values[j];
- zbx_snprintf(buffer, sizeof(buffer), ZBX_FS_UI64, extent->partitionid);
- zbx_json_addstring(&json_data, extent->diskname, buffer, ZBX_JSON_TYPE_INT);
+ zbx_json_addobject(&json_data, NULL);
+ zbx_json_adduint64(&json_data, "partitionid", ext->partitionid);
+ zbx_json_addstring(&json_data, "instance", ext->diskname,
+ ZBX_JSON_TYPE_STRING);
+ zbx_json_close(&json_data);
}
zbx_json_close(&json_data);
@@ -4107,7 +4311,7 @@ int check_vcenter_vm_discovery(AGENT_REQUEST *request, const char *username, con
else
zbx_json_addstring(&json_data, "{#VM.RPOOL.PATH}", "", ZBX_JSON_TYPE_STRING);
- zbx_json_addarray(&json_data, "vm.customattribute");
+ zbx_json_addarray(&json_data, "vm_customattribute");
for (j = 0; j < vm->custom_attrs.values_num; j++)
{
@@ -5020,14 +5224,15 @@ int check_vcenter_vm_perfcounter(AGENT_REQUEST *request, const char *username, c
}
/* FAIL is returned if counter already exists */
- if (SUCCEED == zbx_vmware_service_add_perf_counter(service, "VirtualMachine", vm->id, counterid, "*"))
+ if (SUCCEED == zbx_vmware_service_add_perf_counter(service, ZBX_VMWARE_SOAP_VM, vm->id, counterid,
+ ZBX_VMWARE_PERF_QUERY_ALL))
{
ret = SYSINFO_RET_OK;
goto unlock;
}
/* the performance counter is already being monitored, try to get the results from statistics */
- ret = vmware_service_get_counter_value_by_id(service, "VirtualMachine", vm->id, counterid, instance, 1, unit,
+ ret = vmware_service_get_counter_value_by_id(service, ZBX_VMWARE_SOAP_VM, vm->id, counterid, instance, 1, unit,
result);
unlock:
zbx_vmware_unlock();
@@ -5619,7 +5824,8 @@ static int check_vcenter_rp_common(const char *url, const char *username, const
}
/* FAIL is returned if counter already exists */
- if (SUCCEED == zbx_vmware_service_add_perf_counter(service, ZBX_VMWARE_SOAP_RESOURCEPOOL, rpid, counterid, ""))
+ if (SUCCEED == zbx_vmware_service_add_perf_counter(service, ZBX_VMWARE_SOAP_RESOURCEPOOL, rpid, counterid,
+ ZBX_VMWARE_PERF_QUERY_TOTAL))
{
ret = SYSINFO_RET_OK;
goto unlock;
@@ -5889,4 +6095,20 @@ int check_vcenter_alarms_get(AGENT_REQUEST *request, const char *username, const
#undef ALARMS_GET_START
#undef ALARMS_GET_END
+#undef ZBX_VMWARE_DATASTORE_SIZE_TOTAL
+#undef ZBX_VMWARE_DATASTORE_SIZE_FREE
+#undef ZBX_VMWARE_DATASTORE_SIZE_PFREE
+#undef ZBX_VMWARE_DATASTORE_SIZE_UNCOMMITTED
+
+#undef ZBX_DATASTORE_TOTAL
+#undef ZBX_DATASTORE_COUNTER_CAPACITY
+#undef ZBX_DATASTORE_COUNTER_USED
+#undef ZBX_DATASTORE_COUNTER_PROVISIONED
+
+#undef ZBX_DATASTORE_DIRECTION_READ
+#undef ZBX_DATASTORE_DIRECTION_WRITE
+
+#undef ZBX_IF_DIRECTION_IN
+#undef ZBX_IF_DIRECTION_OUT
+
#endif /* defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL) */
diff --git a/src/zabbix_server/poller/checks_simple_vmware.h b/src/zabbix_server/poller/checks_simple_vmware.h
index 2c493c3344e..4923196f3b5 100644
--- a/src/zabbix_server/poller/checks_simple_vmware.h
+++ b/src/zabbix_server/poller/checks_simple_vmware.h
@@ -52,6 +52,8 @@ int check_vcenter_datastore_tags_get(AGENT_REQUEST *request, const char *usernam
AGENT_RESULT *result);
int check_vcenter_datastore_read(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
+int check_vcenter_datastore_perfcounter(AGENT_REQUEST *request, const char *username, const char *password,
+ AGENT_RESULT *result);
int check_vcenter_datastore_property(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
int check_vcenter_datastore_size(AGENT_REQUEST *request, const char *username, const char *password,
@@ -100,6 +102,8 @@ int check_vcenter_hv_datastore_multipath(AGENT_REQUEST *request, const char *use
AGENT_RESULT *result);
int check_vcenter_hv_discovery(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
+int check_vcenter_hv_diskinfo_get(AGENT_REQUEST *request, const char *username, const char *password,
+ AGENT_RESULT *result);
int check_vcenter_hv_fullname(AGENT_REQUEST *request, const char *username, const char *password,
AGENT_RESULT *result);
int check_vcenter_hv_hw_cpu_num(AGENT_REQUEST *request, const char *username, const char *password,
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index ef1d28cb094..96a8b88bccf 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -48,9 +48,6 @@
#include "zbxsysinfo.h"
#include "zbx_rtc_constants.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
-
/******************************************************************************
* *
* Purpose: write interface availability changes into database *
@@ -956,20 +953,21 @@ ZBX_THREAD_ENTRY(poller_thread, args)
time_t last_stat_time;
unsigned char poller_type;
zbx_ipc_async_socket_t rtc;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
poller_type = (poller_args_in->poller_type);
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(poller_args_in->zbx_get_program_type_cb_arg()), server_num,
get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
scriptitem_es_engine_init();
@@ -1027,7 +1025,7 @@ ZBX_THREAD_ENTRY(poller_thread, args)
last_stat_time = time(NULL);
}
- if (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ if (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
#ifdef HAVE_NETSNMP
if (ZBX_RTC_SNMP_CACHE_RELOAD == rtc_cmd)
diff --git a/src/zabbix_server/preprocessor/preproc_manager.c b/src/zabbix_server/preprocessor/preproc_manager.c
index fe77732b603..2ced8c47340 100644
--- a/src/zabbix_server/preprocessor/preproc_manager.c
+++ b/src/zabbix_server/preprocessor/preproc_manager.c
@@ -29,9 +29,7 @@
#include "zbxtime.h"
#include "zbxsysinfo.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_PREPROCESSOR_FORKS;
#define ZBX_PREPROCESSING_MANAGER_DELAY 1
@@ -1959,20 +1957,20 @@ ZBX_THREAD_ENTRY(preprocessing_manager_thread, args)
int ret;
double time_stat, time_idle = 0, time_now, time_flush, sec;
zbx_timespec_t timeout = {ZBX_PREPROCESSING_MANAGER_DELAY, 0};
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
-
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (FAIL == zbx_ipc_service_start(&service, ZBX_IPC_SERVICE_PREPROCESSING, &error))
{
@@ -2005,9 +2003,9 @@ ZBX_THREAD_ENTRY(preprocessing_manager_thread, args)
manager.processed_num = 0;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_service_recv(&service, &timeout, &client, &message);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
sec = zbx_time();
zbx_update_env(sec);
diff --git a/src/zabbix_server/preprocessor/preproc_worker.c b/src/zabbix_server/preprocessor/preproc_worker.c
index c33a85c509e..30bd514e637 100644
--- a/src/zabbix_server/preprocessor/preproc_worker.c
+++ b/src/zabbix_server/preprocessor/preproc_worker.c
@@ -30,9 +30,7 @@
#include "preproc_history.h"
#include "zbxtime.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
#define ZBX_PREPROC_VALUE_PREVIEW_LEN 100
@@ -117,6 +115,88 @@ static void worker_format_result(int step, const zbx_preproc_result_t *result, c
}
}
+/* mock field to estimate how much data can be stored in characters, bytes or both, */
+/* depending on database backend */
+
+typedef struct
+{
+ int bytes_num;
+ int chars_num;
+}
+zbx_db_mock_field_t;
+
+/******************************************************************************
+ * *
+ * Purpose: initializes mock field *
+ * *
+ * Parameters: field - [OUT] the field data *
+ * field_type - [IN] the field type in database schema *
+ * field_len - [IN] the field size in database schema *
+ * *
+ ******************************************************************************/
+static void zbx_db_mock_field_init(zbx_db_mock_field_t *field, int field_type, int field_len)
+{
+ switch (field_type)
+ {
+ case ZBX_TYPE_CHAR:
+#if defined(HAVE_ORACLE)
+ field->chars_num = field_len;
+ field->bytes_num = 4000;
+#else
+ field->chars_num = field_len;
+ field->bytes_num = -1;
+#endif
+ return;
+ }
+
+ THIS_SHOULD_NEVER_HAPPEN;
+
+ field->chars_num = 0;
+ field->bytes_num = 0;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: 'appends' text to the field, if successful the character/byte *
+ * limits are updated *
+ * *
+ * Parameters: field - [IN/OUT] the mock field *
+ * text - [IN] the text to append *
+ * *
+ * Return value: SUCCEED - the field had enough space to append the text *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int zbx_db_mock_field_append(zbx_db_mock_field_t *field, const char *text)
+{
+ int bytes_num, chars_num;
+
+ if (-1 != field->bytes_num)
+ {
+ bytes_num = strlen(text);
+ if (bytes_num > field->bytes_num)
+ return FAIL;
+ }
+ else
+ bytes_num = 0;
+
+ if (-1 != field->chars_num)
+ {
+ chars_num = zbx_strlen_utf8(text);
+ if (chars_num > field->chars_num)
+ return FAIL;
+ }
+ else
+ chars_num = 0;
+
+ field->bytes_num -= bytes_num;
+ field->chars_num -= chars_num;
+
+ return SUCCEED;
+}
+
+
+
/******************************************************************************
* *
* Purpose: formats preprocessing error message *
@@ -583,10 +663,10 @@ ZBX_THREAD_ENTRY(preprocessing_worker_thread, args)
zbx_ipc_socket_t socket;
zbx_ipc_message_t message;
zbx_preproc_dep_request_t dep_request;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
@@ -607,7 +687,7 @@ ZBX_THREAD_ENTRY(preprocessing_worker_thread, args)
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
memset(&dep_request, 0, sizeof(dep_request));
zbx_variant_set_none(&dep_request.value);
@@ -616,7 +696,7 @@ ZBX_THREAD_ENTRY(preprocessing_worker_thread, args)
while (ZBX_IS_RUNNING())
{
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
if (SUCCEED != zbx_ipc_socket_read(&socket, &message))
{
@@ -624,7 +704,7 @@ ZBX_THREAD_ENTRY(preprocessing_worker_thread, args)
exit(EXIT_FAILURE);
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_update_env(zbx_time());
switch (message.code)
diff --git a/src/zabbix_server/proxyconfigread/proxyconfig_read.c b/src/zabbix_server/proxyconfigread/proxyconfig_read.c
index 4948ad076e4..a524f62e6b8 100644
--- a/src/zabbix_server/proxyconfigread/proxyconfig_read.c
+++ b/src/zabbix_server/proxyconfigread/proxyconfig_read.c
@@ -19,7 +19,7 @@
#include "proxyconfig_read.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxdbhigh.h"
#include "libs/zbxkvs/kvs.h"
#include "libs/zbxvault/vault.h"
diff --git a/src/zabbix_server/proxypoller/proxypoller.c b/src/zabbix_server/proxypoller/proxypoller.c
index 99a29adf560..d5205941948 100644
--- a/src/zabbix_server/proxypoller/proxypoller.c
+++ b/src/zabbix_server/proxypoller/proxypoller.c
@@ -19,7 +19,7 @@
#include "proxypoller.h"
#include "zbxserver.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxnix.h"
#include "zbxself.h"
@@ -37,8 +37,6 @@
#include "zbx_rtc_constants.h"
static zbx_get_program_type_f zbx_get_program_type_cb = NULL;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
static int connect_to_proxy(const DC_PROXY *proxy, zbx_socket_t *sock, int timeout)
{
@@ -645,17 +643,18 @@ ZBX_THREAD_ENTRY(proxypoller_thread, args)
double sec, total_sec = 0.0, old_total_sec = 0.0;
time_t last_stat_time;
zbx_ipc_async_socket_t rtc;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
zbx_get_program_type_cb = proxy_poller_args_in->zbx_get_program_type_cb_arg;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(zbx_get_program_type_cb()), server_num,
get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
@@ -712,7 +711,7 @@ ZBX_THREAD_ENTRY(proxypoller_thread, args)
last_stat_time = time(NULL);
}
- if (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ if (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
if (ZBX_RTC_SHUTDOWN == rtc_cmd)
break;
diff --git a/src/zabbix_server/reporter/report_manager.c b/src/zabbix_server/reporter/report_manager.c
index 4bb016ec032..5440c2f61d9 100644
--- a/src/zabbix_server/reporter/report_manager.c
+++ b/src/zabbix_server/reporter/report_manager.c
@@ -46,9 +46,7 @@
#define ZBX_REPORT_STATE_ERROR 2
#define ZBX_REPORT_STATE_SUCCESS_INFO 3
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_REPORTWRITER_FORKS;
/* report manager data */
@@ -2301,17 +2299,17 @@ ZBX_THREAD_ENTRY(report_manager_thread, args)
int ret, processed_num = 0, created_num = 0;
zbx_rm_t manager;
zbx_timespec_t timeout;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
if (FAIL == rm_init(&manager, &error))
{
@@ -2384,9 +2382,9 @@ ZBX_THREAD_ENTRY(report_manager_thread, args)
time_now = sec;
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_service_recv(&manager.ipc, &timeout, &client, &message);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
sec = zbx_time();
zbx_update_env(sec);
diff --git a/src/zabbix_server/reporter/report_writer.c b/src/zabbix_server/reporter/report_writer.c
index 671349b906f..98018356e66 100644
--- a/src/zabbix_server/reporter/report_writer.c
+++ b/src/zabbix_server/reporter/report_writer.c
@@ -27,9 +27,7 @@
#include "report_protocol.h"
#include "zbxtime.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern char *CONFIG_WEBSERVICE_URL;
@@ -415,10 +413,10 @@ ZBX_THREAD_ENTRY(report_writer_thread, args)
zbx_alerter_dispatch_t dispatch = {0};
int report_status = FAIL, started_num = 0, sent_num = 0, finished_num = 0;
double time_now, time_stat, time_wake, time_idle = 0;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zbx_setproctitle("%s #%d starting", get_process_type_string(process_type), process_num);
@@ -438,7 +436,7 @@ ZBX_THREAD_ENTRY(report_writer_thread, args)
get_program_type_string(poller_args_in->zbx_get_program_type_cb_arg()), server_num,
get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s #%d started", get_process_type_string(process_type), process_num);
@@ -462,7 +460,7 @@ ZBX_THREAD_ENTRY(report_writer_thread, args)
finished_num = 0;
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
if (SUCCEED != zbx_ipc_socket_read(&socket, &message))
{
@@ -470,7 +468,7 @@ ZBX_THREAD_ENTRY(report_writer_thread, args)
exit(EXIT_FAILURE);
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
time_wake = zbx_time();
zbx_update_env(time_wake);
diff --git a/src/zabbix_server/selfmon/Makefile.am b/src/zabbix_server/selfmon/Makefile.am
deleted file mode 100644
index f9cb126957b..00000000000
--- a/src/zabbix_server/selfmon/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-noinst_LIBRARIES = libzbxselfmon.a
-
-libzbxselfmon_a_SOURCES = \
- selfmon.c \
- selfmon.h
diff --git a/src/zabbix_server/selfmon/selfmon.c b/src/zabbix_server/selfmon/selfmon.c
deleted file mode 100644
index a2f845394e5..00000000000
--- a/src/zabbix_server/selfmon/selfmon.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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 "selfmon.h"
-
-#include "zbxnix.h"
-#include "zbxself.h"
-#include "log.h"
-#include "zbxtime.h"
-
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
-
-ZBX_THREAD_ENTRY(selfmon_thread, args)
-{
- double sec;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
-
- zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
- server_num, get_process_type_string(process_type), process_num);
-
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
-
- while (ZBX_IS_RUNNING())
- {
- sec = zbx_time();
- zbx_update_env(sec);
-
- zbx_setproctitle("%s [processing data]", get_process_type_string(process_type));
-
- zbx_collect_selfmon_stats();
- sec = zbx_time() - sec;
-
- zbx_setproctitle("%s [processed data in " ZBX_FS_DBL " sec, idle 1 sec]",
- get_process_type_string(process_type), sec);
-
- zbx_sleep_loop(ZBX_SELFMON_DELAY);
- }
-
- zbx_setproctitle("%s #%d [terminated]", get_process_type_string(process_type), process_num);
-
- while (1)
- zbx_sleep(SEC_PER_MIN);
-}
diff --git a/src/zabbix_server/selfmon/selfmon.h b/src/zabbix_server/selfmon/selfmon.h
deleted file mode 100644
index d9085295066..00000000000
--- a/src/zabbix_server/selfmon/selfmon.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2022 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.
-**/
-
-#ifndef ZABBIX_SELFMON_H
-#define ZABBIX_SELFMON_H
-
-#include "zbxthreads.h"
-
-ZBX_THREAD_ENTRY(selfmon_thread, args);
-
-#endif
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index daad512a04e..4f9227114ee 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -50,7 +50,6 @@
#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"
@@ -80,6 +79,7 @@
#include "zbxip.h"
#include "zbxsysinfo.h"
#include "zbx_rtc_constants.h"
+#include "zbxthreads.h"
#ifdef HAVE_OPENIPMI
#include "ipmi/ipmi_manager.h"
@@ -190,10 +190,6 @@ static unsigned char get_program_type(void)
return program_type;
}
-ZBX_THREAD_LOCAL unsigned char process_type = ZBX_PROCESS_TYPE_UNKNOWN;
-ZBX_THREAD_LOCAL int process_num = 0;
-ZBX_THREAD_LOCAL int server_num = 0;
-
int CONFIG_ALERTER_FORKS = 3;
int CONFIG_DISCOVERER_FORKS = 1;
int CONFIG_HOUSEKEEPER_FORKS = 1;
@@ -339,6 +335,11 @@ char *CONFIG_WEBSERVICE_URL = NULL;
int CONFIG_SERVICEMAN_SYNC_FREQUENCY = 60;
+static char *config_file = NULL;
+static int config_allow_root = 0;
+
+struct zbx_db_version_info_t db_version_info;
+
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)
@@ -888,7 +889,7 @@ static void zbx_load_config(ZBX_TASK_EX *task)
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,
+ {"AllowRoot", &config_allow_root, TYPE_INT,
PARM_OPT, 0, 1},
{"User", &CONFIG_USER, TYPE_STRING,
PARM_OPT, 0, 0},
@@ -963,7 +964,7 @@ static void zbx_load_config(ZBX_TASK_EX *task)
/* initialize multistrings */
zbx_strarr_init(&CONFIG_LOAD_MODULE);
- parse_cfg_file(CONFIG_FILE, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_STRICT, ZBX_CFG_EXIT_FAILURE);
+ parse_cfg_file(config_file, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_STRICT, ZBX_CFG_EXIT_FAILURE);
zbx_set_defaults();
CONFIG_LOG_TYPE = zbx_get_log_type(CONFIG_LOG_TYPE_STR);
@@ -1094,8 +1095,8 @@ int main(int argc, char **argv)
{
case 'c':
opt_c++;
- if (NULL == CONFIG_FILE)
- CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
+ if (NULL == config_file)
+ config_file = zbx_strdup(config_file, zbx_optarg);
break;
case 'R':
opt_r++;
@@ -1147,8 +1148,8 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- if (NULL == CONFIG_FILE)
- CONFIG_FILE = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
+ if (NULL == config_file)
+ config_file = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
/* required for simple checks */
zbx_init_metrics();
@@ -1175,14 +1176,13 @@ int main(int argc, char **argv)
exit(SUCCEED == ret ? EXIT_SUCCESS : EXIT_FAILURE);
}
- return zbx_daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, t.flags, get_pid_file_path, zbx_on_exit);
+ return zbx_daemon_start(config_allow_root, CONFIG_USER, t.flags, get_pid_file_path, zbx_on_exit);
}
static void zbx_check_db(void)
{
- struct zbx_db_version_info_t db_version_info;
- struct zbx_json db_version_json;
- int result = SUCCEED;
+ struct zbx_json db_version_json;
+ int result = SUCCEED;
memset(&db_version_info, 0, sizeof(db_version_info));
result = zbx_db_check_version_info(&db_version_info, CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS);
@@ -1217,6 +1217,12 @@ static void zbx_check_db(void)
zabbix_log(LOG_LEVEL_WARNING, "database could be upgraded to use primary keys in history tables");
}
+#if defined(HAVE_POSTGRESQL)
+ if (0 == zbx_strcmp_null(db_version_info.extension, ZBX_DB_EXTENSION_TIMESCALEDB))
+ {
+ zbx_tsdb_extract_compressed_chunk_flags(&db_version_info);
+ }
+#endif
zbx_db_version_json_create(&db_version_json, &db_version_info);
if (SUCCEED == result)
@@ -1227,13 +1233,10 @@ static void zbx_check_db(void)
}
DBclose();
- zbx_free(db_version_info.friendly_current_version);
- zbx_free(db_version_info.extension);
- zbx_free(db_version_info.ext_friendly_current_version);
- zbx_free(db_version_info.ext_lic);
- if(SUCCEED != result)
+ if (SUCCEED != result)
{
+ zbx_db_version_info_clear(&db_version_info);
exit(EXIT_FAILURE);
}
}
@@ -1283,6 +1286,7 @@ static int server_startup(zbx_socket_t *listen_sock, int *ha_stat, int *ha_failo
zbx_thread_discoverer_args discoverer_args = {zbx_config_tls, get_program_type};
zbx_thread_report_writer_args report_writer_args = {zbx_config_tls->ca_file, zbx_config_tls->cert_file,
zbx_config_tls->key_file, CONFIG_SOURCE_IP, get_program_type};
+ zbx_thread_housekeeper_args housekeeper_args = {get_program_type, &db_version_info};
if (SUCCEED != init_database_cache(&error))
{
@@ -1356,16 +1360,17 @@ static int server_startup(zbx_socket_t *listen_sock, int *ha_stat, int *ha_failo
for (i = 0; i < threads_num; i++)
{
- if (FAIL == get_process_info_by_thread(i + 1, &thread_args.process_type, &thread_args.process_num))
+ if (FAIL == get_process_info_by_thread(i + 1, &thread_args.info.process_type,
+ &thread_args.info.process_num))
{
THIS_SHOULD_NEVER_HAPPEN;
exit(EXIT_FAILURE);
}
- thread_args.server_num = i + 1;
+ thread_args.info.server_num = i + 1;
thread_args.args = NULL;
- switch (thread_args.process_type)
+ switch (thread_args.info.process_type)
{
case ZBX_PROCESS_TYPE_SERVICEMAN:
threads_flags[i] = ZBX_THREAD_PRIORITY_SECOND;
@@ -1427,6 +1432,7 @@ static int server_startup(zbx_socket_t *listen_sock, int *ha_stat, int *ha_failo
zbx_thread_start(alerter_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_HOUSEKEEPER:
+ thread_args.args = &housekeeper_args;
zbx_thread_start(housekeeper_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_TIMER:
@@ -1460,7 +1466,7 @@ static int server_startup(zbx_socket_t *listen_sock, int *ha_stat, int *ha_failo
zbx_thread_start(proxypoller_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_SELFMON:
- zbx_thread_start(selfmon_thread, &thread_args, &threads[i]);
+ zbx_thread_start(zbx_selfmon_thread, &thread_args, &threads[i]);
break;
case ZBX_PROCESS_TYPE_VMWARE:
zbx_thread_start(vmware_thread, &thread_args, &threads[i]);
@@ -1731,7 +1737,7 @@ int MAIN_ZABBIX_ENTRY(int flags)
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);
+ zabbix_log(LOG_LEVEL_INFORMATION, "using configuration file: %s", config_file);
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
if (SUCCEED != zbx_coredump_disable())
@@ -1778,6 +1784,13 @@ int MAIN_ZABBIX_ENTRY(int flags)
exit(EXIT_FAILURE);
}
+ if (SUCCEED != DBinit(DCget_nextid, program_type, &error))
+ {
+ zabbix_log(LOG_LEVEL_CRIT, "cannot initialize database: %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",
@@ -2001,6 +2014,8 @@ int MAIN_ZABBIX_ENTRY(int flags)
zbx_free(error);
}
+ zbx_db_version_info_clear(&db_version_info);
+
zbx_on_exit(ZBX_EXIT_STATUS());
return SUCCEED;
diff --git a/src/zabbix_server/service/service_manager.c b/src/zabbix_server/service/service_manager.c
index 1176eb38b01..3b578168c86 100644
--- a/src/zabbix_server/service/service_manager.c
+++ b/src/zabbix_server/service/service_manager.c
@@ -29,9 +29,7 @@
#include "zbxtime.h"
#include "zbxexpr.h"
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_SERVICEMAN_SYNC_FREQUENCY;
/* keep deleted problem eventids up to 2 hours in case problem deletion arrived before problem or before recovery */
@@ -3267,18 +3265,18 @@ ZBX_THREAD_ENTRY(service_manager_thread, args)
zbx_service_manager_t service_manager;
zbx_timespec_t timeout = {1, 0};
int service_cache_reload_requested = 0;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
/* once in STAT_INTERVAL seconds */
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
-
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s #%d [connecting to the database]", get_process_type_string(process_type), process_num);
@@ -3375,9 +3373,9 @@ ZBX_THREAD_ENTRY(service_manager_thread, args)
time_now = zbx_time();
}
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
ret = zbx_ipc_service_recv(&service, &timeout, &client, &message);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
sec = zbx_time();
zbx_update_env(sec);
diff --git a/src/zabbix_server/snmptrapper/snmptrapper.c b/src/zabbix_server/snmptrapper/snmptrapper.c
index efe668a4f51..41308f59b9b 100644
--- a/src/zabbix_server/snmptrapper/snmptrapper.c
+++ b/src/zabbix_server/snmptrapper/snmptrapper.c
@@ -19,7 +19,7 @@
#include "snmptrapper.h"
#include "zbxserver.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxself.h"
#include "zbxnix.h"
@@ -37,9 +37,7 @@ static char *buffer = NULL;
static int offset = 0;
static int force = 0;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
static void DBget_lastsize(void)
{
@@ -589,18 +587,18 @@ static int get_latest_data(void)
******************************************************************************/
ZBX_THREAD_ENTRY(snmptrapper_thread, args)
{
- double sec;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ double sec;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
zabbix_log(LOG_LEVEL_DEBUG, "In %s() trapfile:'%s'", __func__, CONFIG_SNMPTRAP_FILE);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type));
@@ -625,7 +623,7 @@ ZBX_THREAD_ENTRY(snmptrapper_thread, args)
zbx_setproctitle("%s [processed data in " ZBX_FS_DBL " sec, idle 1 sec]",
get_process_type_string(process_type), sec);
- zbx_sleep_loop(1);
+ zbx_sleep_loop(info, 1);
}
zbx_free(buffer);
diff --git a/src/zabbix_server/snmptrapper/snmptrapper.h b/src/zabbix_server/snmptrapper/snmptrapper.h
index f10775f9394..9422a825e1d 100644
--- a/src/zabbix_server/snmptrapper/snmptrapper.h
+++ b/src/zabbix_server/snmptrapper/snmptrapper.h
@@ -23,7 +23,6 @@
#include "zbxthreads.h"
extern char *CONFIG_SNMPTRAP_FILE;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
ZBX_THREAD_ENTRY(snmptrapper_thread, args);
diff --git a/src/zabbix_server/taskmanager/taskmanager.c b/src/zabbix_server/taskmanager/taskmanager.c
index 6ffd5a13300..2f3653afbb3 100644
--- a/src/zabbix_server/taskmanager/taskmanager.c
+++ b/src/zabbix_server/taskmanager/taskmanager.c
@@ -48,9 +48,7 @@
#define ZBX_TM_TEMP_SUPPRESION_ACTION_UNSUPPRESS 64
#define ZBX_TM_TEMP_SUPPRESION_INDEFINITE_TIME 0
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
/******************************************************************************
* *
@@ -1386,15 +1384,15 @@ ZBX_THREAD_ENTRY(taskmanager_thread, args)
double sec1, sec2;
int tasks_num, sleeptime, nextcheck;
zbx_ipc_async_socket_t rtc;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type));
DBconnect(ZBX_DB_CONNECT_NORMAL);
@@ -1415,7 +1413,7 @@ ZBX_THREAD_ENTRY(taskmanager_thread, args)
zbx_uint32_t rtc_cmd;
unsigned char *rtc_data = NULL;
- if (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
+ if (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, sleeptime) && 0 != rtc_cmd)
{
if (ZBX_RTC_PROXY_CONFIG_CACHE_RELOAD == rtc_cmd)
tm_reload_proxy_cache_by_names(&rtc, rtc_data);
diff --git a/src/zabbix_server/timer/timer.c b/src/zabbix_server/timer/timer.c
index 345a387236a..56e8feee12b 100644
--- a/src/zabbix_server/timer/timer.c
+++ b/src/zabbix_server/timer/timer.c
@@ -30,9 +30,7 @@
#define ZBX_EVENT_BATCH_SIZE 1000
-extern ZBX_THREAD_LOCAL unsigned char process_type;
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern int CONFIG_TIMER_FORKS;
/* addition data for event maintenance calculations to pair with zbx_event_suppress_query_t */
@@ -231,7 +229,7 @@ static void event_queries_fetch(DB_RESULT result, zbx_vector_ptr_t *event_querie
* data from database and prepare event query, event data structures *
* *
******************************************************************************/
-static void db_get_query_events(zbx_vector_ptr_t *event_queries, zbx_vector_ptr_t *event_data)
+static void db_get_query_events(zbx_vector_ptr_t *event_queries, zbx_vector_ptr_t *event_data, int process_num)
{
DB_ROW row;
DB_RESULT result;
@@ -348,9 +346,10 @@ static void db_get_query_events(zbx_vector_ptr_t *event_queries, zbx_vector_ptr_
* changes in cache *
* *
* Parameters: suppressed_num - [OUT] the number of suppressed events *
+ * process_num - [IN] process number *
* *
******************************************************************************/
-static void db_update_event_suppress_data(int *suppressed_num)
+static void db_update_event_suppress_data(int *suppressed_num, int process_num)
{
zbx_vector_ptr_t event_queries, event_data;
@@ -359,7 +358,7 @@ static void db_update_event_suppress_data(int *suppressed_num)
zbx_vector_ptr_create(&event_queries);
zbx_vector_ptr_create(&event_data);
- db_get_query_events(&event_queries, &event_data);
+ db_get_query_events(&event_queries, &event_data, process_num);
if (0 != event_queries.values_num)
{
@@ -560,19 +559,19 @@ static int update_host_maintenances(void)
******************************************************************************/
ZBX_THREAD_ENTRY(timer_thread, args)
{
- double sec;
- int maintenance_time = 0, update_time = 0, idle = 1, events_num, hosts_num, update;
- char *info = NULL;
- size_t info_alloc = 0, info_offset = 0;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ double sec;
+ int maintenance_time = 0, update_time = 0, idle = 1, events_num, hosts_num, update;
+ char *info = NULL;
+ size_t info_alloc = 0, info_offset = 0;
+ const zbx_thread_info_t *thread_info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(thread_info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s #%d [connecting to the database]", get_process_type_string(process_type), process_num);
zbx_strcpy_alloc(&info, &info_alloc, &info_offset, "started");
@@ -609,7 +608,7 @@ ZBX_THREAD_ENTRY(timer_thread, args)
if (SUCCEED == update)
{
zbx_dc_maintenance_set_update_flags();
- db_update_event_suppress_data(&events_num);
+ db_update_event_suppress_data(&events_num, process_num);
zbx_dc_maintenance_reset_update_flag(process_num);
}
else
@@ -628,7 +627,7 @@ ZBX_THREAD_ENTRY(timer_thread, args)
zbx_setproctitle("%s #%d [%s, processing maintenances]", get_process_type_string(process_type),
process_num, info);
- db_update_event_suppress_data(&events_num);
+ db_update_event_suppress_data(&events_num, process_num);
info_offset = 0;
zbx_snprintf_alloc(&info, &info_alloc, &info_offset, "suppressed %d events in " ZBX_FS_DBL
@@ -651,7 +650,7 @@ ZBX_THREAD_ENTRY(timer_thread, args)
}
if (0 != idle)
- zbx_sleep_loop(1);
+ zbx_sleep_loop(thread_info, 1);
idle = 1;
}
diff --git a/src/zabbix_server/trapper/nodecommand.c b/src/zabbix_server/trapper/nodecommand.c
index ff6e3fdcaa7..74cc01e5960 100644
--- a/src/zabbix_server/trapper/nodecommand.c
+++ b/src/zabbix_server/trapper/nodecommand.c
@@ -27,6 +27,7 @@
#include "audit/zbxaudit.h"
#include "../../libs/zbxserver/get_host_from_event.h"
#include "../../libs/zbxserver/zabbix_users.h"
+#include "zbxdbwrap.h"
/******************************************************************************
* *
diff --git a/src/zabbix_server/trapper/proxydata.c b/src/zabbix_server/trapper/proxydata.c
index e964a3ff40b..f1a02741668 100644
--- a/src/zabbix_server/trapper/proxydata.c
+++ b/src/zabbix_server/trapper/proxydata.c
@@ -18,7 +18,7 @@
**/
#include "proxydata.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "zbxdbhigh.h"
#include "log.h"
diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c
index 750dd9a500d..fe3eb584aaa 100644
--- a/src/zabbix_server/trapper/trapper.c
+++ b/src/zabbix_server/trapper/trapper.c
@@ -19,7 +19,7 @@
#include "trapper.h"
#include "zbxserver.h"
-#include "proxy.h"
+#include "zbxdbwrap.h"
#include "log.h"
#include "zbxself.h"
@@ -50,8 +50,6 @@
static zbx_get_program_type_f zbx_get_program_type_cb = NULL;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern size_t (*find_psk_in_cache)(const unsigned char *, unsigned char *, unsigned int *);
extern int CONFIG_CONFSYNCER_FORKS;
@@ -1260,21 +1258,22 @@ ZBX_THREAD_ENTRY(trapper_thread, args)
double sec = 0.0;
zbx_socket_t s;
int ret;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
#ifdef HAVE_NETSNMP
zbx_ipc_async_socket_t rtc;
#endif
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
zbx_get_program_type_cb = trapper_args_in->zbx_get_program_type_cb_arg;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]",
get_program_type_string(trapper_args_in->zbx_get_program_type_cb_arg()),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
memcpy(&s, trapper_args_in->listen_sock, sizeof(zbx_socket_t));
@@ -1301,7 +1300,7 @@ ZBX_THREAD_ENTRY(trapper_thread, args)
zbx_setproctitle("%s #%d [processed data in " ZBX_FS_DBL " sec, waiting for connection]",
get_process_type_string(process_type), process_num, sec);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
/* Trapper has to accept all types of connections it can accept with the specified configuration. */
/* Only after receiving data it is known who has sent them and one can decide to accept or discard */
@@ -1316,13 +1315,13 @@ ZBX_THREAD_ENTRY(trapper_thread, args)
/* get connection timestamp */
zbx_timespec(&ts);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
zbx_setproctitle("%s #%d [processing data]", get_process_type_string(process_type),
process_num);
#ifdef HAVE_NETSNMP
- while (SUCCEED == zbx_rtc_wait(&rtc, &rtc_cmd, &rtc_data, 0) && 0 != rtc_cmd)
+ while (SUCCEED == zbx_rtc_wait(&rtc, info, &rtc_cmd, &rtc_data, 0) && 0 != rtc_cmd)
{
if (ZBX_RTC_SNMP_CACHE_RELOAD == rtc_cmd && 0 == snmp_reload)
{
diff --git a/src/zabbix_server/vmware/vmware.c b/src/zabbix_server/vmware/vmware.c
index 7fc943ea54f..c945040cd45 100644
--- a/src/zabbix_server/vmware/vmware.c
+++ b/src/zabbix_server/vmware/vmware.c
@@ -27,7 +27,6 @@
#include "zbxmutexs.h"
#include "zbxshmem.h"
#include "zbxnix.h"
-#include "zbxself.h"
#include "zbxstr.h"
#include "zbxnum.h"
#include "zbxtime.h"
@@ -104,6 +103,7 @@ ZBX_PTR_VECTOR_IMPL(vmware_custom_attr, zbx_vmware_custom_attr_t *)
ZBX_PTR_VECTOR_IMPL(custquery_param, zbx_vmware_custquery_param_t)
ZBX_PTR_VECTOR_IMPL(vmware_dvswitch, zbx_vmware_dvswitch_t *)
ZBX_PTR_VECTOR_IMPL(vmware_alarm, zbx_vmware_alarm_t *)
+ZBX_PTR_VECTOR_IMPL(vmware_diskinfo, zbx_vmware_diskinfo_t *)
/* VMware service object name mapping for vcenter and vsphere installations */
typedef struct
@@ -153,8 +153,8 @@ typedef struct
}
zbx_vmware_cq_value_t;
-ZBX_PTR_VECTOR_DECL(cq_value, zbx_vmware_cq_value_t)
-ZBX_PTR_VECTOR_IMPL(cq_value, zbx_vmware_cq_value_t)
+ZBX_PTR_VECTOR_DECL(cq_value, zbx_vmware_cq_value_t *)
+ZBX_PTR_VECTOR_IMPL(cq_value, zbx_vmware_cq_value_t *)
/* performance data for a performance collector entity */
typedef struct
@@ -199,6 +199,7 @@ typedef struct
int enabled;
}
zbx_vmware_alarm_details_t;
+
ZBX_PTR_VECTOR_DECL(vmware_alarm_details, zbx_vmware_alarm_details_t *)
ZBX_PTR_VECTOR_IMPL(vmware_alarm_details, zbx_vmware_alarm_details_t *)
@@ -209,6 +210,21 @@ typedef struct
}
zbx_vmware_alarms_data_t;
+/* VMware performance counters available per object (information cache) */
+ZBX_VECTOR_DECL(uint16, uint16_t)
+ZBX_VECTOR_IMPL(uint16, uint16_t)
+
+typedef struct
+{
+ char *type;
+ char *id;
+ zbx_vector_uint16_t list;
+}
+zbx_vmware_perf_available_t;
+
+ZBX_PTR_VECTOR_DECL(perf_available, zbx_vmware_perf_available_t *)
+ZBX_PTR_VECTOR_IMPL(perf_available, zbx_vmware_perf_available_t *)
+
#define ZBX_HOSTINFO_NODES_DATACENTER 0x01
#define ZBX_HOSTINFO_NODES_COMPRES 0x02
#define ZBX_HOSTINFO_NODES_HOST 0x04
@@ -254,8 +270,10 @@ static zbx_uint64_t evt_req_chunk_size;
#define ZBX_XPATH_FAULT_SLOW(max_len) \
"concat(substring(" ZBX_XPATH_FAULT_FAST("faultstring")",1," ZBX_STR(max_len) ")," \
- "substring(local-name(" ZBX_XPATH_FAULT_FAST("detail") "/*[1]" \
- "),1," ZBX_STR(max_len) " * number(string-length(" ZBX_XPATH_FAULT_FAST("faultstring") ")=0)))"
+ "substring(concat(local-name(" ZBX_XPATH_FAULT_FAST("detail") "/*[1]),':'," \
+ ZBX_XPATH_FAULT_FAST("detail")"//*[local-name()='name']),1," \
+ ZBX_STR(max_len) " * number(string-length(" ZBX_XPATH_FAULT_FAST("faultstring") ")=0)" \
+ "* number(string-length(local-name(" ZBX_XPATH_FAULT_FAST("detail") "/*[1]) )>0)))"
#define ZBX_XPATH_REFRESHRATE() \
"/*/*/*/*/*[local-name()='refreshRate' and ../*[local-name()='currentSupported']='true']"
@@ -324,10 +342,6 @@ static zbx_uint64_t evt_req_chunk_size;
"/*[local-name()='val']/*[local-name()='adapter']/*[local-name()='target']" \
"/*[local-name()='lun']/*[local-name()='scsiLun']"
-#define ZBX_XPATH_HV_LUN() \
- "substring-before(substring-after(/*/*/*/*/*/*[local-name()='propSet']" \
- "[*[local-name()='val'][text()='%s']][1]/*[local-name()='name'],'\"'),'\"')"
-
#define ZBX_XPATH_HV_MULTIPATH(state) \
"count(/*/*/*/*/*/*[local-name()='propSet'][1]/*[local-name()='val']" \
"/*[local-name()='lun'][*[local-name()='lun'][text()='%s']][1]" \
@@ -374,9 +388,10 @@ static zbx_uint64_t evt_req_chunk_size;
typedef int (*nodeprocfunc_t)(void *, char **);
static int vmware_service_get_vm_snapshot(void *xml_node, char **jstr);
-static void vmware_service_cq_prop_value(const char *fn_parent, xmlDoc *xdoc, zbx_vmware_cq_value_t *cqv);
+static void vmware_service_cq_prop_value(const char *fn_parent, xmlDoc *xdoc, zbx_vector_cq_value_t *cqvs);
static char *vmware_cq_prop_soap_request(const zbx_vector_cq_value_t *cq_values, const char *soap_type,
- const char *clusterid, const size_t bsz, char *buff, zbx_vmware_cq_value_t **cq_prop);
+ const char *obj_id, zbx_vector_cq_value_t *cqvs);
+static int vmware_diskinfo_diskname_compare(const void *d1, const void *d2);
typedef struct
{
@@ -415,7 +430,7 @@ static zbx_vmware_propmap_t hv_propmap[] = {
ZBX_HVPROPMAP("runtime.connectionState"), /* ZBX_VMWARE_HVPROP_CONNECTIONSTATE */
ZBX_HVPROPMAP_EXT("hardware.systemInfo.serialNumber", NULL, 67),/* ZBX_VMWARE_HVPROP_HW_SERIALNUMBER */
ZBX_HVPROPMAP_EXT("runtime.healthSystemRuntime.hardwareStatusInfo",
- zbx_xmlnode_to_json, 0), /* ZBX_VMWARE_HVPROP_HW_SENSOR */
+ zbx_xmlnode_to_json, 0) /* ZBX_VMWARE_HVPROP_HW_SENSOR */
};
static zbx_vmware_propmap_t vm_propmap[] = {
@@ -455,6 +470,9 @@ static zbx_vmware_propmap_t vm_propmap[] = {
#define ZBX_XPATH_OBJECTS_BY_TYPE(type) \
"/*/*/*/*/*[local-name()='objects'][*[local-name()='obj'][@type='" type "']]"
+#define ZBX_XPATH_OBJS_BY_TYPE(type) \
+ "/*/*/*/*/*[local-name()='objects']/*[local-name()='obj'][@type='" type "']"
+
#define ZBX_XPATH_NAME_BY_TYPE(type) \
ZBX_XPATH_PROP_OBJECT(type) "*[local-name()='propSet'][*[local-name()='name']]" \
"/*[local-name()='val']"
@@ -679,9 +697,10 @@ int zbx_str_uint64_pair_name_compare(const void *p1, const void *p2)
* Parameters: cq_value - [IN] the custom query value data *
* *
******************************************************************************/
-static void zbx_vmware_cq_value_free(zbx_vmware_cq_value_t cq_value)
+static void zbx_vmware_cq_value_free(zbx_vmware_cq_value_t *cq_value)
{
- zbx_free(cq_value.response);
+ zbx_str_free(cq_value->response);
+ zbx_free(cq_value);
}
/******************************************************************************
@@ -864,6 +883,43 @@ static int vmware_perf_entity_compare_func(const void *d1, const void *d2)
/******************************************************************************
* *
+ * performance counter availability list support functions *
+ * *
+ ******************************************************************************/
+static int vmware_perf_available_compare(const void *d1, const void *d2)
+{
+ int ret;
+
+ const zbx_vmware_perf_available_t *e1 = *(const zbx_vmware_perf_available_t * const *)d1;
+ const zbx_vmware_perf_available_t *e2 = *(const zbx_vmware_perf_available_t * const *)d2;
+
+ if (0 == (ret = strcmp(e1->type, e2->type)))
+ ret = strcmp(e1->id, e2->id);
+
+ return ret;
+}
+
+static void vmware_perf_available_free(zbx_vmware_perf_available_t *value)
+{
+ zbx_free(value->type);
+ zbx_free(value->id);
+ zbx_vector_uint16_clear(&value->list);
+ zbx_vector_uint16_destroy(&value->list);
+ zbx_free(value);
+}
+
+static int vmware_uint16_compare(const void *d1, const void *d2)
+{
+ const uint16_t *i1 = (const uint16_t *)d1;
+ const uint16_t *i2 = (const uint16_t *)d2;
+
+ ZBX_RETURN_IF_NOT_EQUAL(*i1, *i2);
+
+ return 0;
+}
+
+/******************************************************************************
+ * *
* custom query hashset support functions *
* *
******************************************************************************/
@@ -1052,6 +1108,7 @@ static void vmware_perf_counter_shared_free(zbx_vmware_perf_counter_t *counter)
{
vmware_vector_str_uint64_pair_shared_clean(&counter->values);
zbx_vector_str_uint64_pair_destroy(&counter->values);
+ vmware_shared_strfree(counter->query_instance);
__vm_shmem_free_func(counter);
}
@@ -1103,7 +1160,10 @@ static void vmware_entities_shared_clean_stats(zbx_hashset_t *entities)
vmware_vector_str_uint64_pair_shared_clean(&counter->values);
if (0 != (counter->state & ZBX_VMWARE_COUNTER_UPDATING))
- counter->state = ZBX_VMWARE_COUNTER_READY;
+ {
+ counter->state = ZBX_VMWARE_COUNTER_READY |
+ (counter->state & ZBX_VMWARE_COUNTER_STATE_MASK);
+ }
}
vmware_shared_strfree(entity->error);
entity->error = NULL;
@@ -1120,7 +1180,6 @@ static void vmware_entities_shared_clean_stats(zbx_hashset_t *entities)
static void vmware_diskextent_shared_free(zbx_vmware_diskextent_t *diskextent)
{
vmware_shared_strfree(diskextent->diskname);
-
__vm_shmem_free_func(diskextent);
}
@@ -1136,6 +1195,7 @@ static void vmware_datastore_shared_free(zbx_vmware_datastore_t *datastore)
vmware_shared_strfree(datastore->name);
vmware_shared_strfree(datastore->id);
vmware_shared_strfree(datastore->uuid);
+ vmware_shared_strfree(datastore->type);
vmware_vector_str_uint64_pair_shared_clean(&datastore->hv_uuids_access);
zbx_vector_str_uint64_pair_destroy(&datastore->hv_uuids_access);
@@ -1360,6 +1420,34 @@ static void vmware_alarm_shared_free(zbx_vmware_alarm_t *alarm)
/******************************************************************************
* *
+ * Purpose: frees shared resources allocated to store disk info data *
+ * *
+ * Parameters: di - [IN] the disk info object *
+ * *
+ ******************************************************************************/
+static void vmware_diskinfo_shared_free(zbx_vmware_diskinfo_t *di)
+{
+ vmware_shared_strfree(di->diskname);
+ vmware_shared_strfree(di->ds_uuid);
+ vmware_shared_strfree(di->operational_state);
+ vmware_shared_strfree(di->lun_type);
+ vmware_shared_strfree(di->model);
+ vmware_shared_strfree(di->vendor);
+ vmware_shared_strfree(di->revision);
+ vmware_shared_strfree(di->serial_number);
+
+ if (NULL != di->vsan)
+ {
+ vmware_shared_strfree(di->vsan->ssd);
+ vmware_shared_strfree(di->vsan->local_disk);
+ __vm_shmem_free_func(di->vsan);
+ }
+
+ __vm_shmem_free_func(di);
+}
+
+/******************************************************************************
+ * *
* Purpose: frees shared resources allocated to store vmware hypervisor *
* *
* Parameters: hv - [IN] the vmware hypervisor *
@@ -1379,6 +1467,9 @@ static void vmware_hv_shared_clean(zbx_vmware_hv_t *hv)
zbx_vector_str_clear_ext(&hv->alarm_ids, vmware_shared_strfree);
zbx_vector_str_destroy(&hv->alarm_ids);
+ zbx_vector_vmware_diskinfo_clear_ext(&hv->diskinfo, vmware_diskinfo_shared_free);
+ zbx_vector_vmware_diskinfo_destroy(&hv->diskinfo);
+
if (NULL != hv->uuid)
vmware_shared_strfree(hv->uuid);
@@ -1421,6 +1512,9 @@ static void vmware_cluster_shared_free(zbx_vmware_cluster_t *cluster)
if (NULL != cluster->status)
vmware_shared_strfree(cluster->status);
+ zbx_vector_str_clear_ext(&cluster->dss_uuid, vmware_shared_strfree);
+ zbx_vector_str_destroy(&cluster->dss_uuid);
+
zbx_vector_str_clear_ext(&cluster->alarm_ids, vmware_shared_strfree);
zbx_vector_str_destroy(&cluster->alarm_ids);
@@ -1641,9 +1735,14 @@ static zbx_vmware_cluster_t *vmware_cluster_shared_dup(const zbx_vmware_cluster_
cluster->id = vmware_shared_strdup(src->id);
cluster->name = vmware_shared_strdup(src->name);
cluster->status = vmware_shared_strdup(src->status);
+ VMWARE_VECTOR_CREATE(&cluster->dss_uuid, str);
+ zbx_vector_str_reserve(&cluster->dss_uuid, (size_t)src->dss_uuid.values_num);
VMWARE_VECTOR_CREATE(&cluster->alarm_ids, str);
zbx_vector_str_reserve(&cluster->alarm_ids, (size_t)src->alarm_ids.values_num);
+ for (i = 0; i < src->dss_uuid.values_num; i++)
+ zbx_vector_str_append(&cluster->dss_uuid, vmware_shared_strdup(src->dss_uuid.values[i]));
+
for (i = 0; i < src->alarm_ids.values_num; i++)
zbx_vector_str_append(&cluster->alarm_ids, vmware_shared_strdup(src->alarm_ids.values[i]));
@@ -1685,8 +1784,8 @@ static zbx_vmware_diskextent_t *vmware_diskextent_shared_dup(const zbx_vmware_di
zbx_vmware_diskextent_t *diskextent;
diskextent = (zbx_vmware_diskextent_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_diskextent_t));
- diskextent->diskname = vmware_shared_strdup(src->diskname);
diskextent->partitionid = src->partitionid;
+ diskextent->diskname = vmware_shared_strdup(src->diskname);
return diskextent;
}
@@ -1709,6 +1808,7 @@ static zbx_vmware_datastore_t *vmware_datastore_shared_dup(const zbx_vmware_data
datastore->uuid = vmware_shared_strdup(src->uuid);
datastore->name = vmware_shared_strdup(src->name);
datastore->id = vmware_shared_strdup(src->id);
+ datastore->type = vmware_shared_strdup(src->type);
VMWARE_VECTOR_CREATE(&datastore->hv_uuids_access, str_uint64_pair);
zbx_vector_str_uint64_pair_reserve(&datastore->hv_uuids_access, (size_t)src->hv_uuids_access.values_num);
VMWARE_VECTOR_CREATE(&datastore->diskextents, vmware_diskextent);
@@ -1981,6 +2081,45 @@ static zbx_vmware_dsname_t *vmware_dsname_shared_dup(const zbx_vmware_dsname_t *
/******************************************************************************
* *
+ * Purpose: copies vmware hypervisor disks object into shared memory *
+ * *
+ * Parameters: src - [IN] the vmware disk info object *
+ * *
+ * Return value: a duplicated vmware disk info object *
+ * *
+ ******************************************************************************/
+static zbx_vmware_diskinfo_t *vmware_diskinfo_shared_dup(const zbx_vmware_diskinfo_t *src)
+{
+ zbx_vmware_diskinfo_t *di;
+
+ di = (zbx_vmware_diskinfo_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_diskinfo_t));
+
+ di->diskname = vmware_shared_strdup(src->diskname);
+ di->ds_uuid = vmware_shared_strdup(src->ds_uuid);
+ di->operational_state = vmware_shared_strdup(src->operational_state);
+ di->lun_type = vmware_shared_strdup(src->lun_type);
+ di->queue_depth = src->queue_depth;
+ di->model = vmware_shared_strdup(src->model);
+ di->vendor = vmware_shared_strdup(src->vendor);
+ di->revision = vmware_shared_strdup(src->revision);
+ di->serial_number = vmware_shared_strdup(src->serial_number);
+
+ if (NULL != src->vsan)
+ {
+ di->vsan = (zbx_vmware_vsandiskinfo_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_vsandiskinfo_t));
+ di->vsan->ssd = vmware_shared_strdup(src->vsan->ssd);
+ di->vsan->local_disk = vmware_shared_strdup(src->vsan->local_disk);
+ di->vsan->block = src->vsan->block;
+ di->vsan->block_size = src->vsan->block_size;
+ }
+ else
+ di->vsan = NULL;
+
+ return di;
+}
+
+/******************************************************************************
+ * *
* Purpose: copies vmware physical NIC object into shared memory *
* *
* Parameters: src - [IN] the vmware physical NIC object *
@@ -2044,10 +2183,12 @@ static void vmware_hv_shared_copy(zbx_vmware_hv_t *dst, const zbx_vmware_hv_t *s
VMWARE_VECTOR_CREATE(&dst->vms, ptr);
VMWARE_VECTOR_CREATE(&dst->pnics, vmware_pnic);
VMWARE_VECTOR_CREATE(&dst->alarm_ids, str);
+ VMWARE_VECTOR_CREATE(&dst->diskinfo, vmware_diskinfo);
zbx_vector_vmware_dsname_reserve(&dst->dsnames, (size_t)src->dsnames.values_num);
zbx_vector_ptr_reserve(&dst->vms, (size_t)src->vms.values_num);
zbx_vector_vmware_pnic_reserve(&dst->pnics, (size_t)src->pnics.values_num);
zbx_vector_str_reserve(&dst->alarm_ids, (size_t)src->alarm_ids.values_num);
+ zbx_vector_vmware_diskinfo_reserve(&dst->diskinfo, (size_t)src->diskinfo.values_num);
dst->uuid = vmware_shared_strdup(src->uuid);
dst->id = vmware_shared_strdup(src->id);
@@ -2070,6 +2211,9 @@ static void vmware_hv_shared_copy(zbx_vmware_hv_t *dst, const zbx_vmware_hv_t *s
for (i = 0; i < src->alarm_ids.values_num; i++)
zbx_vector_str_append(&dst->alarm_ids, vmware_shared_strdup(src->alarm_ids.values[i]));
+
+ for (i = 0; i < src->diskinfo.values_num; i++)
+ zbx_vector_vmware_diskinfo_append(&dst->diskinfo, vmware_diskinfo_shared_dup(src->diskinfo.values[i]));
}
/******************************************************************************
@@ -2209,6 +2353,7 @@ static void vmware_datastore_free(zbx_vmware_datastore_t *datastore)
zbx_free(datastore->name);
zbx_free(datastore->uuid);
zbx_free(datastore->id);
+ zbx_free(datastore->type);
zbx_free(datastore);
}
@@ -2365,6 +2510,34 @@ static void vmware_dsname_free(zbx_vmware_dsname_t *dsname)
/******************************************************************************
* *
+ * Purpose: frees resources allocated to store disk info data *
+ * *
+ * Parameters: di - [IN] the disk info *
+ * *
+ ******************************************************************************/
+static void vmware_diskinfo_free(zbx_vmware_diskinfo_t *di)
+{
+ zbx_free(di->diskname);
+ zbx_free(di->ds_uuid);
+ zbx_free(di->operational_state);
+ zbx_free(di->lun_type);
+ zbx_free(di->model);
+ zbx_free(di->vendor);
+ zbx_free(di->revision);
+ zbx_free(di->serial_number);
+
+ if (NULL != di->vsan)
+ {
+ zbx_free(di->vsan->ssd);
+ zbx_free(di->vsan->local_disk);
+ zbx_free(di->vsan);
+ }
+
+ zbx_free(di);
+}
+
+/******************************************************************************
+ * *
* Purpose: frees resources allocated to physical NIC data *
* *
* Parameters: nic - [IN] the pnic of hv *
@@ -2433,6 +2606,9 @@ static void vmware_hv_clean(zbx_vmware_hv_t *hv)
zbx_vector_str_clear_ext(&hv->alarm_ids, zbx_str_free);
zbx_vector_str_destroy(&hv->alarm_ids);
+ zbx_vector_vmware_diskinfo_clear_ext(&hv->diskinfo, vmware_diskinfo_free);
+ zbx_vector_vmware_diskinfo_destroy(&hv->diskinfo);
+
zbx_free(hv->uuid);
zbx_free(hv->id);
zbx_free(hv->clusterid);
@@ -2455,6 +2631,8 @@ static void vmware_cluster_free(zbx_vmware_cluster_t *cluster)
zbx_free(cluster->name);
zbx_free(cluster->id);
zbx_free(cluster->status);
+ zbx_vector_str_clear_ext(&cluster->dss_uuid, zbx_str_free);
+ zbx_vector_str_destroy(&cluster->dss_uuid);
zbx_vector_str_clear_ext(&cluster->alarm_ids, zbx_str_free);
zbx_vector_str_destroy(&cluster->alarm_ids);
zbx_free(cluster);
@@ -3465,31 +3643,27 @@ static int vmware_service_get_vm_data(zbx_vmware_service_t *service, CURL *easyh
"</ns0:RetrievePropertiesEx>" \
ZBX_POST_VSPHERE_FOOTER
- char tmp[MAX_STRING_LEN + ZBX_VMWARE_VMPROPS_NUM * 100], props[MAX_STRING_LEN], *vmid_esc;
- int i, ret = FAIL;
+ char *tmp, props[ZBX_VMWARE_VMPROPS_NUM * 150], *vmid_esc;
+ int i, ret;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() vmid:'%s'", __func__, vmid);
props[0] = '\0';
for (i = 0; i < props_num; i++)
{
- zbx_strlcat(props, "<ns0:pathSet>", sizeof(props));
- zbx_strlcat(props, propmap[i].name, sizeof(props));
- zbx_strlcat(props, "</ns0:pathSet>", sizeof(props));
+ zbx_strscat(props, "<ns0:pathSet>");
+ zbx_strscat(props, propmap[i].name);
+ zbx_strscat(props, "</ns0:pathSet>");
}
vmid_esc = zbx_xml_escape_dyn(vmid);
-
- zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_VMWARE_VM_STATUS_EX,
+ tmp = zbx_dsprintf(NULL, ZBX_POST_VMWARE_VM_STATUS_EX,
vmware_service_objects[service->type].property_collector, props, cq_prop, vmid_esc);
zbx_free(vmid_esc);
+ ret = zbx_soap_post(__func__, easyhandle, tmp, xdoc, NULL, error);
+ zbx_str_free(tmp);
- if (SUCCEED != zbx_soap_post(__func__, easyhandle, tmp, xdoc, NULL, error))
- goto out;
-
- ret = SUCCEED;
-out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
return ret;
@@ -3623,6 +3797,7 @@ static void vmware_vm_snapshot_disksize(xmlDoc *xdoc, const char *key, xmlNode *
* uniquesize - [IN/OUT] total uniquesize of all snapshots *
* count - [IN/OUT] total number of all snapshots *
* latestdate - [OUT] the date of last snapshot *
+ * oldestdate - [OUT] the date of oldest snapshot *
* json_data - [OUT] json with info about snapshot *
* *
* Return value: SUCCEED - the operation has completed successfully *
@@ -3631,7 +3806,7 @@ static void vmware_vm_snapshot_disksize(xmlDoc *xdoc, const char *key, xmlNode *
******************************************************************************/
static int vmware_vm_snapshot_collect(xmlDoc *xdoc, xmlNode *snap_node, xmlNode *layout_node,
zbx_vector_uint64_t *disks_used, zbx_uint64_t *size, zbx_uint64_t *uniquesize, zbx_uint64_t *count,
- char **latestdate, struct zbx_json *json_data)
+ char **latestdate, char **oldestdate, struct zbx_json *json_data)
{
int i, ret = FAIL;
char *value, xpath[MAX_STRING_LEN], *name, *desc, *crtime;
@@ -3706,10 +3881,13 @@ static int vmware_vm_snapshot_collect(xmlDoc *xdoc, xmlNode *snap_node, xmlNode
zbx_json_adduint64(json_data, "uniquesize", snap_usize);
zbx_json_close(json_data);
+ if (NULL != oldestdate)
+ *oldestdate = zbx_strdup(NULL, crtime);
+
if (NULL != (next_node = zbx_xml_node_get(xdoc, snap_node, ZBX_XNN("childSnapshotList"))))
{
ret = vmware_vm_snapshot_collect(xdoc, next_node, layout_node, disks_used, size, uniquesize, count,
- latestdate, json_data);
+ latestdate, NULL, json_data);
}
else
{
@@ -3747,9 +3925,10 @@ static int vmware_service_get_vm_snapshot(void *xml_node, char **jstr)
xmlDoc *xdoc = node->doc;
struct zbx_json json_data;
int ret = FAIL;
- char *latestdate = NULL;
+ char *latestdate = NULL, *oldestdate = NULL;
zbx_uint64_t count, size, uniquesize;
zbx_vector_uint64_t disks_used;
+ time_t xml_time, now = time(NULL), latest_age = 0, oldest_age = 0;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
@@ -3775,14 +3954,23 @@ static int vmware_service_get_vm_snapshot(void *xml_node, char **jstr)
uniquesize = 0;
if (FAIL == (ret = vmware_vm_snapshot_collect(xdoc, root_node, layout_node, &disks_used, &size, &uniquesize,
- &count, &latestdate, &json_data)))
+ &count, &latestdate, &oldestdate, &json_data)))
{
goto out;
}
+ if (SUCCEED == zbx_iso8601_utc(ZBX_NULL2EMPTY_STR(latestdate), &xml_time))
+ latest_age = now - xml_time;
+
+ if (SUCCEED == zbx_iso8601_utc(ZBX_NULL2EMPTY_STR(oldestdate), &xml_time))
+ oldest_age = now - xml_time;
+
zbx_json_close(&json_data);
zbx_json_adduint64(&json_data, "count", count);
zbx_json_addstring(&json_data, "latestdate", ZBX_NULL2EMPTY_STR(latestdate), ZBX_JSON_TYPE_STRING);
+ zbx_json_addint64(&json_data, "latestage", latest_age);
+ zbx_json_addstring(&json_data, "oldestdate", ZBX_NULL2EMPTY_STR(oldestdate), ZBX_JSON_TYPE_STRING);
+ zbx_json_addint64(&json_data, "oldestage", oldest_age);
zbx_json_adduint64(&json_data, "size", size);
zbx_json_adduint64(&json_data, "uniquesize", uniquesize);
zbx_json_close(&json_data);
@@ -4108,11 +4296,11 @@ static zbx_vmware_vm_t *vmware_service_create_vm(zbx_vmware_service_t *service,
zbx_vmware_alarms_data_t *alarms_data, char **error)
{
zbx_vmware_vm_t *vm;
- char *value, buff[MAX_STRING_LEN];
+ char *value, *cq_prop;
xmlDoc *details = NULL;
- zbx_vmware_cq_value_t *cqv;
+ zbx_vector_cq_value_t cqvs;
const char *uuid_xpath[3] = {NULL, ZBX_XPATH_VM_UUID(), ZBX_XPATH_VM_INSTANCE_UUID()};
- int ret = FAIL;
+ int ret;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() vmid:'%s'", __func__, id);
@@ -4122,16 +4310,20 @@ static zbx_vmware_vm_t *vmware_service_create_vm(zbx_vmware_service_t *service,
zbx_vector_ptr_create(&vm->devs);
zbx_vector_ptr_create(&vm->file_systems);
zbx_vector_vmware_custom_attr_create(&vm->custom_attrs);
+ zbx_vector_cq_value_create(&cqvs);
+ cq_prop = vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_VM, id, &cqvs);
+ ret = vmware_service_get_vm_data(service, easyhandle, id, vm_propmap, ZBX_VMWARE_VMPROPS_NUM, cq_prop,
+ &details, error);
+ zbx_str_free(cq_prop);
- if (SUCCEED != vmware_service_get_vm_data(service, easyhandle, id, vm_propmap, ZBX_VMWARE_VMPROPS_NUM,
- vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_VM, id, sizeof(buff), buff, &cqv),
- &details, error))
- {
+ if (FAIL == ret)
goto out;
- }
if (NULL == (value = zbx_xml_doc_read_value(details, uuid_xpath[service->type])))
+ {
+ ret = FAIL;
goto out;
+ }
vm->uuid = value;
vm->id = zbx_strdup(NULL, id);
@@ -4182,13 +4374,14 @@ static zbx_vmware_vm_t *vmware_service_create_vm(zbx_vmware_service_t *service,
vmware_vm_get_file_systems(vm, details);
vmware_vm_get_custom_attrs(vm, details);
- if (NULL != cqv)
- vmware_service_cq_prop_value(__func__, details, cqv);
+ if (0 != cqvs.values_num)
+ vmware_service_cq_prop_value(__func__, details, &cqvs);
zbx_vector_str_create(&vm->alarm_ids);
ret = vmware_service_get_alarms_data(__func__, service, easyhandle, details, NULL, &vm->alarm_ids, alarms_data,
error);
out:
+ zbx_vector_cq_value_destroy(&cqvs);
zbx_xml_free_doc(details);
if (SUCCEED != ret)
@@ -4254,8 +4447,6 @@ static int vmware_service_get_diskextents_list(xmlDoc *doc, zbx_vector_vmware_di
xmlXPathContext *xpathCtx;
xmlXPathObject *xpathObj;
xmlNodeSetPtr nodeset;
- char *name, *partition;
- zbx_vmware_diskextent_t *diskextent;
int i, ret = FAIL;
if (NULL == doc)
@@ -4273,19 +4464,23 @@ static int vmware_service_get_diskextents_list(xmlDoc *doc, zbx_vector_vmware_di
for (i = 0; i < nodeset->nodeNr; i++)
{
- if (NULL == (name = zbx_xml_node_read_value(doc, nodeset->nodeTab[i], ZBX_XPATH_NN("diskName"))))
+ char *value;
+ zbx_vmware_diskextent_t *diskextent;
+ xmlNode *xn = nodeset->nodeTab[i];
+
+ if (NULL == (value = zbx_xml_node_read_value(doc, xn, ZBX_XPATH_NN("diskName"))))
{
zabbix_log(LOG_LEVEL_DEBUG, "%s(): Cannot get diskName.", __func__);
continue;
}
diskextent = (zbx_vmware_diskextent_t *)zbx_malloc(NULL, sizeof(zbx_vmware_diskextent_t));
- diskextent->diskname = name;
+ diskextent->diskname = value;
- if (NULL != (partition = zbx_xml_node_read_value(doc, nodeset->nodeTab[i], ZBX_XPATH_NN("partition"))))
+ if (NULL != (value = zbx_xml_node_read_value(doc, xn, ZBX_XPATH_NN("partition"))))
{
- diskextent->partitionid = (unsigned int) atoi(partition);
- zbx_free(partition);
+ diskextent->partitionid = (unsigned int) atoi(value);
+ zbx_free(value);
}
else
diskextent->partitionid = 0;
@@ -4293,7 +4488,7 @@ static int vmware_service_get_diskextents_list(xmlDoc *doc, zbx_vector_vmware_di
zbx_vector_vmware_diskextent_append(diskextents, diskextent);
}
- zbx_vector_vmware_diskextent_sort(diskextents, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
+ zbx_vector_vmware_diskextent_sort(diskextents, ZBX_DEFAULT_STR_PTR_COMPARE_FUNC);
ret = SUCCEED;
out:
@@ -4340,15 +4535,16 @@ static zbx_vmware_datastore_t *vmware_service_create_datastore(const zbx_vmware_
"</ns0:RetrievePropertiesEx>" \
ZBX_POST_VSPHERE_FOOTER
- char tmp[MAX_STRING_LEN], buff[MAX_STRING_LEN], *uuid = NULL, *name = NULL, *path, *id_esc,
- *value, *error = NULL;
+ char *tmp, *cq_prop, *uuid = NULL, *name = NULL, *path, *id_esc, *value, *error = NULL;
+ int ret;
zbx_vmware_datastore_t *datastore = NULL;
zbx_uint64_t capacity = ZBX_MAX_UINT64, free_space = ZBX_MAX_UINT64, uncommitted = ZBX_MAX_UINT64;
xmlDoc *doc = NULL;
- zbx_vmware_cq_value_t *cqv;
+ zbx_vector_cq_value_t cqvs;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() datastore:'%s'", __func__, id);
+ zbx_vector_cq_value_create(&cqvs);
id_esc = zbx_xml_escape_dyn(id);
if (ZBX_VMWARE_TYPE_VSPHERE == service->type && NULL != service->version &&
@@ -4359,14 +4555,16 @@ static zbx_vmware_datastore_t *vmware_service_create_datastore(const zbx_vmware_
goto out;
}
- zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_DATASTORE_GET,
- vmware_service_objects[service->type].property_collector,
- vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_DS, id, sizeof(buff), buff, &cqv),
- id_esc);
- zbx_free(id_esc);
+ cq_prop = vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_DS, id, &cqvs);
+ tmp = zbx_dsprintf(NULL, ZBX_POST_DATASTORE_GET, vmware_service_objects[service->type].property_collector,
+ cq_prop, id_esc);
+ zbx_str_free(id_esc);
+ zbx_str_free(cq_prop);
+ ret = zbx_soap_post(__func__, easyhandle, tmp, &doc, NULL, &error);
+ zbx_str_free(tmp);
- if (SUCCEED != zbx_soap_post(__func__, easyhandle, tmp, &doc, NULL, &error))
+ if (FAIL == ret)
goto out;
name = zbx_xml_doc_read_value(doc, ZBX_XPATH_DATASTORE_SUMMARY("name"));
@@ -4383,7 +4581,7 @@ static zbx_vmware_datastore_t *vmware_service_create_datastore(const zbx_vmware_
if ('/' == path[len - 1])
path[len - 1] = '\0';
- for (ptr = path + len - 2; ptr > path && *ptr != '/'; ptr--)
+ for (ptr = path + len - 2; ptr > path && *ptr != '/' && *ptr != ':'; ptr--)
;
uuid = zbx_strdup(NULL, ptr + 1);
@@ -4422,6 +4620,7 @@ static zbx_vmware_datastore_t *vmware_service_create_datastore(const zbx_vmware_
datastore->name = (NULL != name) ? name : zbx_strdup(NULL, id);
datastore->uuid = uuid;
datastore->id = zbx_strdup(NULL, id);
+ datastore->type = zbx_xml_doc_read_value(doc, ZBX_XPATH_DATASTORE_SUMMARY("type"));
datastore->capacity = capacity;
datastore->free_space = free_space;
datastore->uncommitted = uncommitted;
@@ -4430,8 +4629,8 @@ static zbx_vmware_datastore_t *vmware_service_create_datastore(const zbx_vmware_
zbx_vector_vmware_diskextent_create(&datastore->diskextents);
vmware_service_get_diskextents_list(doc, &datastore->diskextents);
- if (NULL != cqv)
- vmware_service_cq_prop_value(__func__, doc, cqv);
+ if (0 != cqvs.values_num)
+ vmware_service_cq_prop_value(__func__, doc, &cqvs);
if (FAIL == vmware_service_get_alarms_data(__func__, service, easyhandle, doc, NULL, &datastore->alarm_ids,
alarms_data, &error))
@@ -4441,6 +4640,7 @@ static zbx_vmware_datastore_t *vmware_service_create_datastore(const zbx_vmware_
}
out:
zbx_xml_free_doc(doc);
+ zbx_vector_cq_value_destroy(&cqvs);
if (NULL != error)
{
@@ -4501,7 +4701,7 @@ static int vmware_service_get_hv_data(const zbx_vmware_service_t *service, CURL
"</ns0:RetrievePropertiesEx>" \
ZBX_POST_VSPHERE_FOOTER
- char tmp[MAX_STRING_LEN + ZBX_VMWARE_HVPROPS_NUM * 100], props[MAX_STRING_LEN], *hvid_esc;
+ char *tmp, props[ZBX_VMWARE_HVPROPS_NUM * 150], *hvid_esc;
int i, ret = FAIL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() guesthvid:'%s'", __func__, hvid);
@@ -4515,25 +4715,20 @@ static int vmware_service_get_hv_data(const zbx_vmware_service_t *service, CURL
if (0 != propmap[i].vc_min && propmap[i].vc_min > service->major_version * 10 + service->minor_version)
continue;
- zbx_strlcat(props, "<ns0:pathSet>", sizeof(props));
- zbx_strlcat(props, propmap[i].name, sizeof(props));
- zbx_strlcat(props, "</ns0:pathSet>", sizeof(props));
+ zbx_strscat(props, "<ns0:pathSet>");
+ zbx_strscat(props, propmap[i].name);
+ zbx_strscat(props, "</ns0:pathSet>");
}
hvid_esc = zbx_xml_escape_dyn(hvid);
-
- zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_HV_DETAILS, vmware_service_objects[service->type].property_collector,
+ tmp = zbx_dsprintf(NULL, ZBX_POST_HV_DETAILS, vmware_service_objects[service->type].property_collector,
props, cq_prop, hvid_esc);
-
zbx_free(hvid_esc);
-
zabbix_log(LOG_LEVEL_TRACE, "%s() SOAP request: %s", __func__, tmp);
- if (SUCCEED != zbx_soap_post(__func__, easyhandle, tmp, xdoc, NULL, error))
- goto out;
+ ret = zbx_soap_post(__func__, easyhandle, tmp, xdoc, NULL, error);
+ zbx_str_free(tmp);
- ret = SUCCEED;
-out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
return ret;
@@ -4764,6 +4959,389 @@ static int vmware_service_hv_get_multipath_data(const zbx_vmware_service_t *serv
/******************************************************************************
* *
+ * Purpose: find DS by canonical disk name (perf counter instance) *
+ * *
+ * Parameters: dss - [IN] all known Datastores *
+ * diskname - [IN] canonical disk name *
+ * *
+ * Return value: uuid of Datastore or NULL *
+ * *
+ ******************************************************************************/
+static char *vmware_datastores_diskname_search(const zbx_vector_vmware_datastore_t *dss, char *diskname)
+{
+ zbx_vmware_diskextent_t dx_cmp = {.diskname = diskname};
+ int i;
+
+ for (i = 0; i< dss->values_num; i++)
+ {
+ zbx_vmware_datastore_t *ds = dss->values[i];
+
+ if (FAIL == zbx_vector_vmware_diskextent_bsearch(&ds->diskextents, &dx_cmp,
+ ZBX_DEFAULT_STR_PTR_COMPARE_FUNC))
+ {
+ continue;
+ }
+
+ return zbx_strdup(NULL, ds->uuid);
+ }
+
+ return NULL;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parse the vmware hypervisor internal disks details info *
+ * *
+ * Parameters: xdoc - [IN] a reference to xml document with disks info *
+ * dss - [IN] all known Datastores *
+ * disks_info - [OUT] *
+ * *
+ * Return value: count of updated disk objects *
+ * *
+ ******************************************************************************/
+static int vmware_service_hv_disks_parse_info(xmlDoc *xdoc, const zbx_vector_vmware_datastore_t *dss,
+ zbx_vector_ptr_pair_t *disks_info)
+{
+# define SCSILUN_PROP_NUM 8
+# define ZBX_XPATH_PSET "/*/*/*/*/*/*[local-name()='propSet']"
+# define ZBX_XPATH_LUN "substring-before(substring-after(*[local-name()='name'],'\"'),'\"')"
+# define ZBX_XPATH_LUN_PR_NAME "substring-after(*[local-name()='name'],'\"].')"
+
+
+ xmlXPathContext *xpathCtx;
+ xmlXPathObject *xpathObj;
+ xmlNodeSetPtr nodeset;
+ char *lun_key = NULL, *name = NULL;
+ int i, created = 0, j = FAIL;
+
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ xpathCtx = xmlXPathNewContext(xdoc);
+
+ if (NULL == (xpathObj = xmlXPathEvalExpression((const xmlChar *)ZBX_XPATH_PSET, xpathCtx)))
+ goto clean;
+
+ if (0 != xmlXPathNodeSetIsEmpty(xpathObj->nodesetval))
+ goto clean;
+
+ nodeset = xpathObj->nodesetval;
+ zbx_vector_ptr_pair_reserve(disks_info, (size_t)(nodeset->nodeNr / SCSILUN_PROP_NUM + disks_info->values_num));
+
+ for (i = 0; i < nodeset->nodeNr; i++)
+ {
+ zbx_vmware_diskinfo_t *di;
+ xmlNode *node = nodeset->nodeTab[i];
+ zbx_ptr_pair_t pr;
+
+ zbx_str_free(lun_key);
+ zbx_str_free(name);
+
+ if (NULL == (lun_key = zbx_xml_node_read_value(xdoc, node, ZBX_XPATH_LUN)))
+ continue;
+
+ if (NULL == (name = zbx_xml_node_read_value(xdoc, node, ZBX_XPATH_LUN_PR_NAME)))
+ continue;
+
+ pr.first = lun_key;
+
+ if ((FAIL == j || 0 != strcmp(disks_info->values[j].first, lun_key)) &&
+ FAIL == (j = zbx_vector_ptr_pair_search(disks_info, pr,
+ ZBX_DEFAULT_STR_COMPARE_FUNC)))
+ {
+ lun_key = NULL;
+ pr.second = zbx_malloc(NULL, sizeof(zbx_vmware_diskinfo_t));
+ memset(pr.second, 0, sizeof(zbx_vmware_diskinfo_t));
+ zbx_vector_ptr_pair_append(disks_info, pr);
+ j = disks_info->values_num - 1;
+ created++;
+ }
+
+ di = (zbx_vmware_diskinfo_t *)disks_info->values[j].second;
+
+ if (0 == strcmp(name, "canonicalName"))
+ {
+ di->diskname = zbx_xml_node_read_value(xdoc, node, ZBX_XNN("val"));
+ di->ds_uuid = vmware_datastores_diskname_search(dss, di->diskname);
+ }
+ else if (0 == strcmp(name, "operationalState"))
+ {
+ zbx_vector_str_t values;
+ int k;
+
+ zbx_vector_str_create(&values);
+ zbx_xml_node_read_values(xdoc, node, ZBX_XNN("val") "/*", &values);
+ di->operational_state = zbx_strdcat(di->operational_state, "[");
+
+ for (k = 0; k < values.values_num; k++)
+ di->operational_state = zbx_strdcatf(di->operational_state, "\"%s\",", values.values[k]);
+
+ if (0 != values.values_num)
+ di->operational_state[strlen(di->operational_state) - 1] = '\0';
+
+ di->operational_state = zbx_strdcat(di->operational_state, "]");
+ zbx_vector_str_clear_ext(&values, zbx_str_free);
+ zbx_vector_str_destroy(&values);
+ }
+ else if (0 == strcmp(name, "lunType"))
+ {
+ di->lun_type = zbx_xml_node_read_value(xdoc, node, ZBX_XNN("val"));
+ }
+ else if (0 == strcmp(name, "queueDepth"))
+ {
+ zbx_xml_node_read_num(xdoc, node, "number(" ZBX_XNN("val") ")", &di->queue_depth);
+ }
+ else if (0 == strcmp(name, "model"))
+ {
+ di->model = zbx_xml_node_read_value(xdoc, node, ZBX_XNN("val"));
+ zbx_lrtrim(di->model, " ");
+ }
+ else if (0 == strcmp(name, "vendor"))
+ {
+ di->vendor = zbx_xml_node_read_value(xdoc, node, ZBX_XNN("val"));
+ zbx_lrtrim(di->vendor, " ");
+ }
+ else if (0 == strcmp(name, "revision"))
+ {
+ di->revision = zbx_xml_node_read_value(xdoc, node, ZBX_XNN("val"));
+ zbx_lrtrim(di->revision, " ");
+ }
+ else if (0 == strcmp(name, "serialNumber"))
+ {
+ di->serial_number = zbx_xml_node_read_value(xdoc, node, ZBX_XNN("val"));
+ zbx_lrtrim(di->serial_number, " ");
+ }
+ }
+
+ zbx_str_free(lun_key);
+ zbx_str_free(name);
+clean:
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s() created:%d", __func__, created);
+
+ return created;
+
+# undef SCSILUN_PROP_NUM
+# undef ZBX_XPATH_LUN_PR_NAME
+# undef ZBX_XPATH_PSET
+}
+
+/******************************************************************************
+ * *
+ * Purpose: parse the vmware hypervisor vsan disks details info *
+ * *
+ * Parameters: xdoc - [IN] - a reference to xml document with disks info*
+ * vsan_uuid - [IN] - uuid of vsan DS *
+ * disks_info - [IN/OUT] - collected the hv internal disks *
+ * *
+ * Return value: count of updated vsan disk objects *
+ * *
+ ******************************************************************************/
+static int vmware_service_hv_vsan_parse_info(xmlDoc *xdoc, const char *vsan_uuid,
+ zbx_vector_ptr_pair_t *disks_info)
+{
+ xmlXPathContext *xpathCtx;
+ xmlXPathObject *xpathObj;
+ xmlNodeSetPtr nodeset;
+ int i, updated_vsan = 0, j = FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ xpathCtx = xmlXPathNewContext(xdoc);
+
+ if (NULL == (xpathObj = xmlXPathEvalExpression((const xmlChar *)"//*[" ZBX_XNN("canonicalName") "]", xpathCtx)))
+ goto clean;
+
+ if (0 != xmlXPathNodeSetIsEmpty(xpathObj->nodesetval))
+ goto clean;
+
+ nodeset = xpathObj->nodesetval;
+
+ for (i = 0; i < nodeset->nodeNr; i++)
+ {
+ zbx_vmware_diskinfo_t *di, di_cmp;
+ xmlNode *mapinfo_node = nodeset->nodeTab[i];
+ zbx_ptr_pair_t pr = {.first = NULL, .second = &di_cmp};
+
+ if (NULL == (di_cmp.diskname = zbx_xml_node_read_value(xdoc, mapinfo_node, ZBX_XNN("canonicalName"))) ||
+ FAIL == (j = zbx_vector_ptr_pair_bsearch(disks_info, pr,
+ vmware_diskinfo_diskname_compare)))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() skipped internal disk: %s", __func__,
+ ZBX_NULL2EMPTY_STR(di_cmp.diskname));
+ zbx_str_free(di_cmp.diskname);
+ continue;
+ }
+
+ zbx_str_free(di_cmp.diskname);
+ di = (zbx_vmware_diskinfo_t *)disks_info->values[j].second;
+ di->vsan = zbx_malloc(NULL, sizeof(zbx_vmware_vsandiskinfo_t));
+ memset(di->vsan, 0, sizeof(zbx_vmware_vsandiskinfo_t));
+ di->vsan->ssd = zbx_xml_node_read_value(xdoc, mapinfo_node, ZBX_XNN("ssd"));
+ di->vsan->local_disk = zbx_xml_node_read_value(xdoc, mapinfo_node, ZBX_XNN("localDisk"));
+ zbx_xml_node_read_num(xdoc, mapinfo_node,
+ "number(." ZBX_XPATH_LN2("capacity", "block") ")", (int *)&di->vsan->block);
+ zbx_xml_node_read_num(xdoc, mapinfo_node,
+ "number(." ZBX_XPATH_LN2("capacity", "blockSize") ")", (int *)&di->vsan->block_size);
+
+ if (NULL == di->ds_uuid)
+ di->ds_uuid = zbx_strdup(di->ds_uuid, vsan_uuid);
+
+ updated_vsan++;
+ }
+clean:
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s() vsan disks updated:%d", __func__, updated_vsan);
+
+ return updated_vsan;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: gets the vmware hypervisor internal disks details info *
+ * *
+ * Parameters: service - [IN] the vmware service *
+ * easyhandle - [IN] the CURL handle *
+ * hv_data - [IN] the hv data with scsi topology info *
+ * hvid - [IN] the vmware hypervisor id *
+ * dss - [IN] all known Datastores *
+ * vsan_uuid - [IN] uuid of vsan Datastore *
+ * disks_info - [OUT]
+ * error - [OUT] the error message in the case of failure *
+ * *
+ * Return value: SUCCEED - the operation has completed successfully *
+ * FAIL - the operation has failed *
+ * *
+ ******************************************************************************/
+static int vmware_service_hv_disks_get_info(const zbx_vmware_service_t *service, CURL *easyhandle,
+ xmlDoc *hv_data, const char *hvid, const zbx_vector_vmware_datastore_t *dss, const char *vsan_uuid,
+ zbx_vector_ptr_pair_t *disks_info, char **error)
+{
+# define ZBX_POST_HV_DISK_INFO \
+ ZBX_POST_VSPHERE_HEADER \
+ "<ns0:RetrievePropertiesEx>" \
+ "<ns0:_this type=\"PropertyCollector\">%s</ns0:_this>" \
+ "<ns0:specSet>" \
+ "<ns0:propSet>" \
+ "<ns0:type>HostSystem</ns0:type>" \
+ "%s" \
+ "</ns0:propSet>" \
+ "<ns0:objectSet>" \
+ "<ns0:obj type=\"HostSystem\">%s</ns0:obj>" \
+ "<ns0:skip>false</ns0:skip>" \
+ "</ns0:objectSet>" \
+ "</ns0:specSet>" \
+ "<ns0:options/>" \
+ "</ns0:RetrievePropertiesEx>" \
+ ZBX_POST_VSPHERE_FOOTER
+
+# define ZBX_POST_SCSI_INFO \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].canonicalName</ns0:pathSet>" \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].operationalState</ns0:pathSet>" \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].lunType</ns0:pathSet>" \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].queueDepth</ns0:pathSet>" \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].model</ns0:pathSet>" \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].vendor</ns0:pathSet>" \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].revision</ns0:pathSet>" \
+ "<ns0:pathSet>config.storageDevice.scsiLun[\"%s\"].serialNumber</ns0:pathSet>"
+
+ zbx_vector_str_t scsi_luns;
+ xmlDoc *doc = NULL, *doc_dinfo = NULL;
+ zbx_property_collection_iter *iter = NULL;
+ char *tmp = NULL, *hvid_esc, *scsi_req = NULL, *err = NULL;
+ int i, total, updated = 0, updated_vsan = 0, ret = SUCCEED;
+ const char *pcollecter = vmware_service_objects[service->type].property_collector;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() hvid:'%s'", __func__, hvid);
+
+ zbx_vector_str_create(&scsi_luns);
+ zbx_xml_read_values(hv_data, ZBX_XPATH_HV_SCSI_TOPOLOGY, &scsi_luns);
+ total = scsi_luns.values_num;
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() count of scsiLun:%d", __func__, total);
+
+ if (0 == total)
+ goto out;
+
+ for (i = 0; i < scsi_luns.values_num; i++)
+ {
+ scsi_req = zbx_strdcatf(scsi_req , ZBX_POST_SCSI_INFO, scsi_luns.values[i], scsi_luns.values[i],
+ scsi_luns.values[i], scsi_luns.values[i], scsi_luns.values[i], scsi_luns.values[i],
+ scsi_luns.values[i], scsi_luns.values[i]);
+ }
+
+ zbx_vector_str_clear_ext(&scsi_luns, zbx_str_free);
+ hvid_esc = zbx_xml_escape_dyn(hvid);
+ tmp = zbx_dsprintf(NULL, ZBX_POST_HV_DISK_INFO, pcollecter, ZBX_NULL2EMPTY_STR(scsi_req), hvid_esc);
+ zbx_free(hvid_esc);
+ zbx_free(scsi_req);
+
+ if (SUCCEED != (ret = zbx_property_collection_init(easyhandle, tmp, pcollecter, &iter, &doc, error)))
+ goto out;
+
+ updated += vmware_service_hv_disks_parse_info(doc, dss, disks_info);
+
+ while (NULL != iter->token)
+ {
+ zbx_xml_free_doc(doc);
+ doc = NULL;
+
+ if (SUCCEED != (ret = zbx_property_collection_next(iter, &doc, error)))
+ goto out;
+
+ updated += vmware_service_hv_disks_parse_info(doc, dss, disks_info);
+ }
+
+ if (NULL == vsan_uuid)
+ goto out;
+
+ zbx_property_collection_free(iter);
+ iter = NULL;
+ zbx_vector_ptr_pair_sort(disks_info, vmware_diskinfo_diskname_compare);
+ hvid_esc = zbx_xml_escape_dyn(hvid);
+ tmp = zbx_dsprintf(NULL, ZBX_POST_HV_DISK_INFO, pcollecter ,
+ "<ns0:pathSet>config.vsanHostConfig.storageInfo.diskMapping</ns0:pathSet>", hvid_esc);
+ zbx_free(hvid_esc);
+
+ if (SUCCEED != (ret = zbx_property_collection_init(easyhandle, tmp, pcollecter, &iter, &doc_dinfo, &err)))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() cannot get vsan disk_info:%s", __func__, err);
+ zbx_str_free(err);
+ goto out;
+ }
+
+ updated_vsan += vmware_service_hv_vsan_parse_info(doc_dinfo, vsan_uuid, disks_info);
+
+ while (NULL != iter->token)
+ {
+ zbx_xml_free_doc(doc_dinfo);
+ doc_dinfo = NULL;
+
+ if (SUCCEED != (ret = zbx_property_collection_next(iter, &doc_dinfo, error)))
+ goto out;
+
+ updated_vsan += vmware_service_hv_vsan_parse_info(doc_dinfo, vsan_uuid, disks_info);
+ }
+out:
+ zbx_free(tmp);
+ zbx_xml_free_doc(doc);
+ zbx_xml_free_doc(doc_dinfo);
+ zbx_vector_str_destroy(&scsi_luns);
+ zbx_property_collection_free(iter);
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s for %d(vsan:%d) / %d", __func__, zbx_result_string(ret), updated,
+ updated_vsan, total);
+
+ return ret;
+
+# undef ZBX_POST_SCSI_INFO
+# undef ZBX_POST_HV_DISK_INFO
+}
+
+/******************************************************************************
+ * *
* Function: vmware_ds_uuid_compare *
* *
* Purpose: sorting function to sort Datastore vector by uuid *
@@ -4854,8 +5432,8 @@ static int vmware_cq_instance_id_compare(const void *d1, const void *d2)
{
int ret;
- const zbx_vmware_cq_value_t *prop1 = (const zbx_vmware_cq_value_t *)d1;
- const zbx_vmware_cq_value_t *prop2 = (const zbx_vmware_cq_value_t *)d2;
+ const zbx_vmware_cq_value_t *prop1 = *(const zbx_vmware_cq_value_t * const *)d1;
+ const zbx_vmware_cq_value_t *prop2 = *(const zbx_vmware_cq_value_t * const *)d2;
if (0 == (ret = strcmp(prop1->instance->soap_type, prop2->instance->soap_type)))
ret = strcmp(prop1->instance->id, prop2->instance->id);
@@ -4865,6 +5443,21 @@ static int vmware_cq_instance_id_compare(const void *d1, const void *d2)
/******************************************************************************
* *
+ * Purpose: sorting function to sort diskinfo vector by diskname *
+ * *
+ ******************************************************************************/
+static int vmware_diskinfo_diskname_compare(const void *d1, const void *d2)
+{
+ const zbx_ptr_pair_t *p1 = (const zbx_ptr_pair_t *)d1;
+ const zbx_ptr_pair_t *p2 = (const zbx_ptr_pair_t *)d2;
+ const zbx_vmware_diskinfo_t *di1 = (const zbx_vmware_diskinfo_t *)p1->second;
+ const zbx_vmware_diskinfo_t *di2 = (const zbx_vmware_diskinfo_t *)p2->second;
+
+ return strcmp(di1->diskname, di2->diskname);
+}
+
+/******************************************************************************
+ * *
* Purpose: populate array of values from an xml data *
* *
* Parameters: xdoc - [IN] XML document *
@@ -5257,6 +5850,7 @@ static int vmware_hv_ds_access_update(zbx_vmware_service_t *service, CURL *easyh
ZBX_POST_VSPHERE_FOOTER
char *hvid_esc, tmp[MAX_STRING_LEN];
+ const char *pcollector = vmware_service_objects[service->type].property_collector;
int ret = FAIL, updated = 0;
xmlDoc *doc = NULL;
zbx_property_collection_iter *iter = NULL;
@@ -5265,11 +5859,10 @@ static int vmware_hv_ds_access_update(zbx_vmware_service_t *service, CURL *easyh
dss->values_num);
hvid_esc = zbx_xml_escape_dyn(hv_id);
- zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_HV_DS_ACCESS, vmware_service_objects[service->type].property_collector,
- hvid_esc, hvid_esc, hvid_esc, hvid_esc);
+ zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_HV_DS_ACCESS, pcollector, hvid_esc, hvid_esc, hvid_esc, hvid_esc);
zbx_free(hvid_esc);
- if (SUCCEED != zbx_property_collection_init(easyhandle, tmp, "propertyCollector", &iter, &doc, error))
+ if (SUCCEED != zbx_property_collection_init(easyhandle, tmp, pcollector, &iter, &doc, error))
goto out;
updated += vmware_hv_ds_access_parse(doc, hv_dss, hv_uuid, hv_id, dss);
@@ -5379,6 +5972,41 @@ clean:
/******************************************************************************
* *
+ * Function: vmware_hv_vsan_uuid *
+ * *
+ * Purpose: search for Datastore uuid with type equal to 'vsan' *
+ * *
+ * Parameters: dss - [IN] the vector with all Datastores *
+ * hv_dss - [IN] the vector with all Datastores attechad to HV *
+ * *
+ * Return value: pointer to vsan DS uuid or NULL *
+ * *
+ ******************************************************************************/
+static const char *vmware_hv_vsan_uuid(zbx_vector_vmware_datastore_t *dss, zbx_vector_str_t *hv_dss)
+{
+ int i;
+
+ for (i = 0; i < hv_dss->values_num; i++)
+ {
+ int j;
+ zbx_vmware_datastore_t *ds, ds_cmp;
+
+ ds_cmp.id = hv_dss->values[i];
+
+ if (FAIL == (j = zbx_vector_vmware_datastore_bsearch(dss, &ds_cmp, vmware_ds_id_compare)))
+ continue;
+
+ ds = dss->values[j];
+
+ if ('v' == *ds->type && 0 == strcmp("vsan", ds->type)) /* only one vsan can be attached to HV */
+ return ds->uuid;
+ }
+
+ return NULL;
+}
+
+/******************************************************************************
+ * *
* Purpose: sorting function to sort Resource pool names vector by name *
* *
******************************************************************************/
@@ -5415,30 +6043,36 @@ static int vmware_service_init_hv(zbx_vmware_service_t *service, CURL *easyhandl
zbx_vector_cq_value_t *cq_values, zbx_vmware_alarms_data_t *alarms_data, zbx_vmware_hv_t *hv,
char **error)
{
- char *value, buff[MAX_STRING_LEN];
+ char *value, *cq_prop;
+ int i, j, ret;
xmlDoc *details = NULL, *multipath_data = NULL;
zbx_vector_str_t datastores, vms;
- zbx_vmware_cq_value_t *cqv;
- int i, j, ret = FAIL;
+ zbx_vector_cq_value_t cqvs;
+ zbx_vector_ptr_pair_t disks_info;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() hvid:'%s'", __func__, id);
memset(hv, 0, sizeof(zbx_vmware_hv_t));
zbx_vector_vmware_dsname_create(&hv->dsnames);
+ zbx_vector_vmware_diskinfo_create(&hv->diskinfo);
zbx_vector_ptr_create(&hv->vms);
zbx_vector_str_create(&datastores);
zbx_vector_str_create(&vms);
+ zbx_vector_ptr_pair_create(&disks_info);
+ zbx_vector_cq_value_create(&cqvs);
zbx_vector_vmware_pnic_create(&hv->pnics);
+ cq_prop = vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_HV, id, &cqvs);
+ ret = vmware_service_get_hv_data(service, easyhandle, id, hv_propmap, ZBX_VMWARE_HVPROPS_NUM, cq_prop,
+ &details, error);
+ zbx_str_free(cq_prop);
- if (SUCCEED != vmware_service_get_hv_data(service, easyhandle, id, hv_propmap, ZBX_VMWARE_HVPROPS_NUM,
- vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_HV, id, sizeof(buff), buff, &cqv),
- &details, error))
- {
+ if (FAIL == ret)
goto out;
- }
+
+ ret = FAIL;
if (NULL == (hv->props = xml_read_props(details, hv_propmap, ZBX_VMWARE_HVPROPS_NUM)))
goto out;
@@ -5451,16 +6085,21 @@ static int vmware_service_init_hv(zbx_vmware_service_t *service, CURL *easyhandl
vmware_service_get_hv_pnics_data(details, &hv->pnics);
zbx_vector_str_create(&hv->alarm_ids);
- vmware_service_get_alarms_data(__func__, service, easyhandle, details, NULL, &hv->alarm_ids, alarms_data,
- error);
+
+ if (FAIL == vmware_service_get_alarms_data(__func__, service, easyhandle, details, NULL, &hv->alarm_ids,
+ alarms_data, error))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Cannot get hv %s alarms: %s.", hv->id, *error);
+ zbx_str_free(*error);
+ }
if (NULL != (value = zbx_xml_doc_read_value(details, "//*[@type='" ZBX_VMWARE_SOAP_CLUSTER "']")))
hv->clusterid = value;
hv->ip = vmware_hv_ip_search(details);
- if (NULL != cqv)
- vmware_service_cq_prop_value(__func__, details, cqv);
+ if (0 != cqvs.values_num)
+ vmware_service_cq_prop_value(__func__, details, &cqvs);
if (SUCCEED != vmware_hv_get_parent_data(service, easyhandle, hv, error))
goto out;
@@ -5474,6 +6113,12 @@ static int vmware_service_init_hv(zbx_vmware_service_t *service, CURL *easyhandl
if (SUCCEED != vmware_service_hv_get_multipath_data(service, easyhandle, details, id, &multipath_data, error))
goto out;
+ if (SUCCEED != vmware_service_hv_disks_get_info(service, easyhandle, details, id, dss,
+ vmware_hv_vsan_uuid(dss, &datastores), &disks_info, error))
+ {
+ goto out;
+ }
+
if (SUCCEED != vmware_hv_ds_access_update(service, easyhandle, hv->uuid, hv->id, &datastores, dss, error))
goto out;
@@ -5503,17 +6148,23 @@ static int vmware_service_init_hv(zbx_vmware_service_t *service, CURL *easyhandl
{
zbx_vmware_diskextent_t *diskextent = ds->diskextents.values[j];
zbx_vmware_hvdisk_t hvdisk;
- char tmp[MAX_STRING_LEN], *lun;
+ zbx_vmware_diskinfo_t di;
+ zbx_ptr_pair_t pair_cmp = {.second = &di};
+ const char *lun;
+ char tmp[MAX_STRING_LEN];
+ int k;
- zbx_snprintf(tmp, sizeof(tmp), ZBX_XPATH_HV_LUN(), diskextent->diskname);
+ di.diskname = diskextent->diskname;
- if (NULL == (lun = zbx_xml_doc_read_value(multipath_data, tmp)))
+ if (FAIL == (k = zbx_vector_ptr_pair_bsearch(&disks_info, pair_cmp,
+ vmware_diskinfo_diskname_compare)))
{
zabbix_log(LOG_LEVEL_DEBUG, "%s(): not found diskextent: %s",
__func__, diskextent->diskname);
continue;
}
+ lun = (const char*)disks_info.values[k].first;
zbx_snprintf(tmp, sizeof(tmp), ZBX_XPATH_HV_MULTIPATH_PATHS(), lun);
if (SUCCEED != zbx_xml_doc_read_num(multipath_data, tmp, &hvdisk.multipath_total) ||
@@ -5521,7 +6172,6 @@ static int vmware_service_init_hv(zbx_vmware_service_t *service, CURL *easyhandl
{
zabbix_log(LOG_LEVEL_DEBUG, "%s(): for diskextent: %s and lun: %s"
" multipath data is not found", __func__, diskextent->diskname, lun);
- zbx_free(lun);
continue;
}
@@ -5532,7 +6182,6 @@ static int vmware_service_init_hv(zbx_vmware_service_t *service, CURL *easyhandl
hvdisk.partitionid = diskextent->partitionid;
zbx_vector_vmware_hvdisk_append(&dsname->hvdisks, hvdisk);
- zbx_free(lun);
}
zbx_vector_vmware_hvdisk_sort(&dsname->hvdisks, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
@@ -5557,7 +6206,14 @@ static int vmware_service_init_hv(zbx_vmware_service_t *service, CURL *easyhandl
zabbix_log(LOG_LEVEL_DEBUG, "Unable initialize vm %s: %s.", vms.values[i], *error);
zbx_free(*error);
}
+ }
+
+ zbx_vector_vmware_diskinfo_reserve(&hv->diskinfo, (size_t)disks_info.values_num);
+ for (i = 0; i < disks_info.values_num; i++)
+ {
+ zbx_vector_vmware_diskinfo_append(&hv->diskinfo, disks_info.values[i].second);
+ disks_info.values[i].second = NULL;
}
ret = SUCCEED;
@@ -5570,6 +6226,17 @@ out:
zbx_vector_str_clear_ext(&datastores, zbx_str_free);
zbx_vector_str_destroy(&datastores);
+ zbx_vector_cq_value_destroy(&cqvs);
+
+ for (i = 0; i < disks_info.values_num; i++)
+ {
+ zbx_str_free(disks_info.values[i].first);
+
+ if (NULL != disks_info.values[i].second)
+ vmware_diskinfo_free((zbx_vmware_diskinfo_t *)disks_info.values[i].second);
+ }
+
+ zbx_vector_ptr_pair_destroy(&disks_info);
if (SUCCEED != ret)
vmware_hv_clean(hv);
@@ -5646,7 +6313,8 @@ static int vmware_service_get_datacenters_list(const zbx_vmware_service_t *servi
nodeset->nodeTab[i], ZBX_XPATH_PROP_NAME_NODE("triggeredAlarmState")),
&datacenter->alarm_ids, alarms_data, &error))
{
- zabbix_log(LOG_LEVEL_DEBUG, "%s(): Cannot get datacenter alarms: %s.", __func__, error);
+ zabbix_log(LOG_LEVEL_DEBUG, "%s(): Cannot get datacenter %s alarms: %s.", __func__,
+ datacenter->id, error);
zbx_str_free(error);
}
@@ -5921,6 +6589,7 @@ static int vmware_service_get_hv_ds_dc_dvs_list(const zbx_vmware_service_t *serv
ZBX_XPATH_PROP_NAME_NODE("triggeredAlarmState")
char tmp[MAX_STRING_LEN * 2];
+ const char *pcollector = vmware_service_objects[service->type].property_collector;
int ret = FAIL;
xmlDoc *doc = NULL;
xmlNode *vc_alarms;
@@ -5928,21 +6597,18 @@ static int vmware_service_get_hv_ds_dc_dvs_list(const zbx_vmware_service_t *serv
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
- zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_VCENTER_HV_DS_LIST,
- vmware_service_objects[service->type].property_collector,
+ zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_VCENTER_HV_DS_LIST, pcollector,
vmware_service_objects[service->type].root_folder);
- if (SUCCEED != zbx_property_collection_init(easyhandle, tmp, "propertyCollector", &iter, &doc, error))
- {
+ if (SUCCEED != zbx_property_collection_init(easyhandle, tmp, pcollector, &iter, &doc, error))
goto out;
- }
if (ZBX_VMWARE_TYPE_VCENTER == service->type)
- zbx_xml_read_values(doc, "//*[@type='HostSystem']", hvs);
+ zbx_xml_read_values(doc, ZBX_XPATH_OBJS_BY_TYPE(ZBX_VMWARE_SOAP_HV) , hvs);
else
zbx_vector_str_append(hvs, zbx_strdup(NULL, "ha-host"));
- zbx_xml_read_values(doc, "//*[@type='Datastore']", dss);
+ zbx_xml_read_values(doc, ZBX_XPATH_OBJS_BY_TYPE(ZBX_VMWARE_SOAP_DS), dss);
vmware_service_get_datacenters_list(service, easyhandle, doc, alarms_data, datacenters);
vmware_service_get_dvswitch_list(doc, dvswitches);
zbx_snprintf(tmp, sizeof(tmp), ZBX_XPATH_GET_ROOT_ALARMS(ZBX_VMWARE_SOAP_FOLDER, "%s"),
@@ -5963,9 +6629,9 @@ static int vmware_service_get_hv_ds_dc_dvs_list(const zbx_vmware_service_t *serv
goto out;
if (ZBX_VMWARE_TYPE_VCENTER == service->type)
- zbx_xml_read_values(doc, "//*[@type='HostSystem']", hvs);
+ zbx_xml_read_values(doc, ZBX_XPATH_OBJS_BY_TYPE(ZBX_VMWARE_SOAP_HV), hvs);
- zbx_xml_read_values(doc, "//*[@type='Datastore']", dss);
+ zbx_xml_read_values(doc, ZBX_XPATH_OBJS_BY_TYPE(ZBX_VMWARE_SOAP_DS), dss);
vmware_service_get_datacenters_list(service, easyhandle, doc, alarms_data, datacenters);
vmware_service_get_dvswitch_list(doc, dvswitches);
@@ -6251,7 +6917,8 @@ static int vmware_service_put_event_data(zbx_vector_ptr_t *events, zbx_id_xmlnod
{
zbx_vmware_event_t *event = NULL;
char *message, *time_str, *ip;
- int timestamp = 0, nodes_det = 0;
+ int nodes_det = 0;
+ time_t timestamp = 0;
unsigned int i;
zbx_uint64_t sz;
static event_hostinfo_node_t host_nodes[] =
@@ -6319,21 +6986,11 @@ static int vmware_service_put_event_data(zbx_vector_ptr_t *events, zbx_id_xmlnod
}
else
{
- int year, mon, mday, hour, min, sec, t;
-
- /* 2013-06-04T14:19:23.406298Z */
- if (6 != sscanf(time_str, "%d-%d-%dT%d:%d:%d.%*s", &year, &mon, &mday, &hour, &min, &sec))
+ if (FAIL == zbx_iso8601_utc(time_str, &timestamp)) /* 2013-06-04T14:19:23.406298Z */
{
- zabbix_log(LOG_LEVEL_TRACE, "unexpected format of createdTime '%s' for event"
- " key '" ZBX_FS_UI64 "'", time_str, xml_event.id);
- }
- else if (SUCCEED != zbx_utc_time(year, mon, mday, hour, min, sec, &t))
- {
- zabbix_log(LOG_LEVEL_TRACE, "cannot convert createdTime '%s' for event key '"
+ zabbix_log(LOG_LEVEL_TRACE, "unexpected format of createdTime '%s' for event key '"
ZBX_FS_UI64 "'", time_str, xml_event.id);
}
- else
- timestamp = t;
zbx_free(time_str);
}
@@ -6886,16 +7543,19 @@ out:
* *
* Parameters: easyhandle - [IN] the CURL handle *
* clusterid - [IN] the cluster id *
+ * datastores - [IN] all available Datastores *
* cq_values - [IN/OUT] the vector with custom query entries *
* status - [OUT] a pointer to the output variable *
+ * dss - [OUT] a list of DS available for cluster *
* error - [OUT] the error message in the case of failure *
* *
* Return value: SUCCEED - the operation has completed successfully *
* FAIL - the operation has failed *
* *
******************************************************************************/
-static int vmware_service_get_cluster_status(CURL *easyhandle, const char *clusterid,
- zbx_vector_cq_value_t *cq_values, char **status, char **error)
+static int vmware_service_get_cluster_state(CURL *easyhandle, const char *clusterid,
+ const zbx_vector_vmware_datastore_t *datastores, zbx_vector_cq_value_t *cq_values, char **status,
+ zbx_vector_str_t *dss, char **error)
{
# define ZBX_POST_VMWARE_CLUSTER_STATUS \
ZBX_POST_VSPHERE_HEADER \
@@ -6906,6 +7566,7 @@ static int vmware_service_get_cluster_status(CURL *easyhandle, const char *clust
"<ns0:type>ClusterComputeResource</ns0:type>" \
"<ns0:all>false</ns0:all>" \
"<ns0:pathSet>summary.overallStatus</ns0:pathSet>" \
+ "<ns0:pathSet>datastore</ns0:pathSet>" \
"%s" \
"</ns0:propSet>" \
"<ns0:objectSet>" \
@@ -6916,32 +7577,56 @@ static int vmware_service_get_cluster_status(CURL *easyhandle, const char *clust
"</ns0:RetrievePropertiesEx>" \
ZBX_POST_VSPHERE_FOOTER
- char tmp[MAX_STRING_LEN], *clusterid_esc, buff[MAX_STRING_LEN];
- int ret = FAIL;
+ char *tmp, *clusterid_esc, *cq_prop;
+ int i, ret = FAIL;
xmlDoc *doc = NULL;
- zbx_vmware_cq_value_t *cqv;
-
+ zbx_vector_cq_value_t cqvs;
+ zbx_vector_str_t ids;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() clusterid:'%s'", __func__, clusterid);
+ zbx_vector_str_create(&ids);
+ zbx_vector_cq_value_create(&cqvs);
clusterid_esc = zbx_xml_escape_dyn(clusterid);
+ cq_prop = vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_CLUSTER, clusterid, &cqvs);
- zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_VMWARE_CLUSTER_STATUS,
- vmware_cq_prop_soap_request(cq_values, ZBX_VMWARE_SOAP_CLUSTER, clusterid, sizeof(buff), buff,
- &cqv), clusterid_esc);
+ tmp = zbx_dsprintf(NULL, ZBX_POST_VMWARE_CLUSTER_STATUS, cq_prop, clusterid_esc);
- zbx_free(clusterid_esc);
+ zbx_str_free(cq_prop);
+ zbx_str_free(clusterid_esc);
+ ret = zbx_soap_post(__func__, easyhandle, tmp, &doc, NULL, error);
+ zbx_str_free(tmp);
- if (SUCCEED != zbx_soap_post(__func__, easyhandle, tmp, &doc, NULL, error))
+ if (FAIL == ret)
goto out;
*status = zbx_xml_doc_read_value(doc, ZBX_XPATH_PROP_NAME("summary.overallStatus"));
- if (NULL != cqv)
- vmware_service_cq_prop_value(__func__, doc, cqv);
+ if (0 != cqvs.values_num)
+ vmware_service_cq_prop_value(__func__, doc, &cqvs);
- ret = SUCCEED;
+ zbx_xml_read_values(doc, ZBX_XPATH_PROP_NAME("datastore") "/*", &ids);
+
+ for (i = 0; i < ids.values_num; i++)
+ {
+ int j;
+ zbx_vmware_datastore_t ds_cmp;
+
+ ds_cmp.id = ids.values[i];
+
+ if (FAIL == (j = zbx_vector_vmware_datastore_bsearch(datastores, &ds_cmp, vmware_ds_id_compare)))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "%s(): Datastore \"%s\" not found on cluster \"%s\".", __func__,
+ ds_cmp.id, clusterid);
+ continue;
+ }
+
+ zbx_vector_str_append(dss, zbx_strdup(NULL, datastores->values[j]->uuid));
+ }
out:
+ zbx_vector_cq_value_destroy(&cqvs);
+ zbx_vector_str_clear_ext(&ids, zbx_str_free);
+ zbx_vector_str_destroy(&ids);
zbx_xml_free_doc(doc);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
@@ -6956,6 +7641,7 @@ out:
* *
* Parameters: service - [IN] the vmware service *
* easyhandle - [IN] the CURL handle *
+ * datastores - [IN] all available Datastores *
* cq_values - [IN/OUT] the vector with custom query entries *
* clusters - [OUT] a pointer to the resulting clusters *
* vector *
@@ -6969,38 +7655,39 @@ out:
* *
******************************************************************************/
static int vmware_service_get_clusters_and_resourcepools(zbx_vmware_service_t *service, CURL *easyhandle,
- zbx_vector_cq_value_t *cq_values, zbx_vector_ptr_t *clusters,
- zbx_vector_vmware_resourcepool_t *resourcepools, zbx_vmware_alarms_data_t *alarms_data, char **error)
+ const zbx_vector_vmware_datastore_t *datastores, zbx_vector_cq_value_t *cq_values,
+ zbx_vector_ptr_t *clusters, zbx_vector_vmware_resourcepool_t *resourcepools,
+ zbx_vmware_alarms_data_t *alarms_data, char **error)
{
char xpath[MAX_STRING_LEN];
int i, ret = FAIL;
xmlDoc *cluster_data = NULL;
- zbx_vector_str_t ids, rpools_all, rpools_uniq;
+ zbx_vector_str_t ids, rpools_all, rpools_uniq, dss;
zbx_vmware_cluster_t *cluster;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
zbx_vector_str_create(&ids);
+ zbx_vector_str_create(&dss);
if (SUCCEED != vmware_service_get_cluster_data(easyhandle, &cluster_data, error))
goto out;
- zbx_xml_read_values(cluster_data, "/*/*/*/*/*[local-name()='objects']/*[local-name()='obj']"
- "[@type='" ZBX_VMWARE_SOAP_CLUSTER "']", &ids);
+ zbx_xml_read_values(cluster_data, ZBX_XPATH_OBJS_BY_TYPE(ZBX_VMWARE_SOAP_CLUSTER), &ids);
zbx_vector_ptr_reserve(clusters, (size_t)(ids.values_num + clusters->values_alloc));
for (i = 0; i < ids.values_num; i++)
{
char *status, *name;
- zbx_snprintf(xpath, sizeof(xpath), "/*/*/*/*/*[local-name()='objects'][*[local-name()='obj']"
- "[@type='" ZBX_VMWARE_SOAP_CLUSTER "'][.='%s']]/" ZBX_XPATH_PROP_NAME_NODE("name"),
- ids.values[i]);
+ zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_PROP_OBJECT_ID(ZBX_VMWARE_SOAP_CLUSTER, "[text()='%s']")
+ "/" ZBX_XPATH_PROP_NAME_NODE("name"), ids.values[i]);
if (NULL == (name = zbx_xml_doc_read_value(cluster_data, xpath)))
continue;
- if (SUCCEED != vmware_service_get_cluster_status(easyhandle, ids.values[i], cq_values, &status, error))
+ if (SUCCEED != vmware_service_get_cluster_state(easyhandle, ids.values[i], datastores, cq_values,
+ &status, &dss, error))
{
zbx_free(name);
goto out;
@@ -7010,6 +7697,9 @@ static int vmware_service_get_clusters_and_resourcepools(zbx_vmware_service_t *s
cluster->id = zbx_strdup(NULL, ids.values[i]);
cluster->name = name;
cluster->status = status;
+ zbx_vector_str_create(&cluster->dss_uuid);
+ zbx_vector_str_append_array(&cluster->dss_uuid, dss.values, dss.values_num);
+ zbx_vector_str_clear(&dss);
zbx_vector_str_create(&cluster->alarm_ids);
if (FAIL == vmware_service_get_alarms_data(__func__, service, easyhandle, cluster_data, NULL,
@@ -7062,6 +7752,7 @@ out:
zbx_xml_free_doc(cluster_data);
zbx_vector_str_clear_ext(&ids, zbx_str_free);
zbx_vector_str_destroy(&ids);
+ zbx_vector_str_destroy(&dss);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s found cl:%d rp:%d", __func__, zbx_result_string(ret),
clusters->values_num, resourcepools->values_num);
@@ -7173,15 +7864,18 @@ out:
* Parameters: counters - [IN/OUT] the vector the created performance *
* counter object should be added to *
* counterid - [IN] the performance counter id *
+ * state - [IN] the performance counter first state *
* *
******************************************************************************/
-static void vmware_counters_add_new(zbx_vector_ptr_t *counters, zbx_uint64_t counterid)
+static void vmware_counters_add_new(zbx_vector_ptr_t *counters, zbx_uint64_t counterid, unsigned char state)
{
zbx_vmware_perf_counter_t *counter;
counter = (zbx_vmware_perf_counter_t *)__vm_shmem_malloc_func(NULL, sizeof(zbx_vmware_perf_counter_t));
counter->counterid = counterid;
- counter->state = ZBX_VMWARE_COUNTER_NEW;
+ counter->state = state;
+ counter->last_used = 0;
+ counter->query_instance = NULL;
zbx_vector_str_uint64_pair_create_ext(&counter->values, __vm_shmem_malloc_func, __vm_shmem_realloc_func,
__vm_shmem_free_func);
@@ -7207,9 +7901,7 @@ static void vmware_counters_add_new(zbx_vector_ptr_t *counters, zbx_uint64_t cou
******************************************************************************/
static int vmware_service_initialize(zbx_vmware_service_t *service, CURL *easyhandle, char **error)
{
-# define UNPARSED_SERVICE_MAJOR_VERSION_DELIM "."
-
- char *version_without_major, *version = NULL, *fullname = NULL;
+ char *version_without_major, *version_update, *version = NULL, *fullname = NULL;
zbx_vector_ptr_t counters;
int ret = FAIL;
@@ -7268,14 +7960,15 @@ static int vmware_service_initialize(zbx_vmware_service_t *service, CURL *easyha
/* version should have the "x.y.z" format, but there is also an "x.y Un" format in nature */
/* according to https://www.vmware.com/support/policies/version.html */
- if (NULL == (version_without_major = strstr(version, UNPARSED_SERVICE_MAJOR_VERSION_DELIM)))
+ if (NULL == (version_without_major = strchr(version, '.')) ||
+ NULL == (version_update = strpbrk(++version_without_major, ".U")))
{
*error = zbx_dsprintf(*error, "Invalid version: %s.", version);
goto unlock;
}
- service->minor_version = (unsigned short)atoi(
- strlen(UNPARSED_SERVICE_MAJOR_VERSION_DELIM) + version_without_major);
+ service->minor_version = (unsigned short)atoi(version_without_major);
+ service->update_version = (unsigned short)atoi(++version_update);
ret = SUCCEED;
unlock:
@@ -7308,7 +8001,7 @@ out:
* *
******************************************************************************/
static void vmware_service_add_perf_entity(zbx_vmware_service_t *service, const char *type, const char *id,
- const char **counters, const char *instance, int now)
+ const char **counters, const char *instance, time_t now)
{
zbx_vmware_perf_entity_t entity, *pentity;
zbx_uint64_t counterid;
@@ -7329,7 +8022,7 @@ static void vmware_service_add_perf_entity(zbx_vmware_service_t *service, const
for (i = 0; NULL != counters[i]; i++)
{
if (SUCCEED == zbx_vmware_service_get_counterid(service, counters[i], &counterid, NULL))
- vmware_counters_add_new(&pentity->counters, counterid);
+ vmware_counters_add_new(&pentity->counters, counterid, ZBX_VMWARE_COUNTER_NEW);
else
zabbix_log(LOG_LEVEL_DEBUG, "cannot find performance counter %s", counters[i]);
}
@@ -7403,14 +8096,14 @@ static void vmware_service_update_perf_entities(zbx_vmware_service_t *service)
zbx_hashset_iter_reset(&service->data->hvs, &iter);
while (NULL != (hv = (zbx_vmware_hv_t *)zbx_hashset_iter_next(&iter)))
{
- vmware_service_add_perf_entity(service, ZBX_VMWARE_SOAP_HV, hv->id, hv_perfcounters, "*",
- service->lastcheck);
+ vmware_service_add_perf_entity(service, ZBX_VMWARE_SOAP_HV, hv->id, hv_perfcounters,
+ ZBX_VMWARE_PERF_QUERY_ALL, service->lastcheck);
for (i = 0; i < hv->vms.values_num; i++)
{
vm = (zbx_vmware_vm_t *)hv->vms.values[i];
- vmware_service_add_perf_entity(service, ZBX_VMWARE_SOAP_VM, vm->id, vm_perfcounters, "*",
- service->lastcheck);
+ vmware_service_add_perf_entity(service, ZBX_VMWARE_SOAP_VM, vm->id, vm_perfcounters,
+ ZBX_VMWARE_PERF_QUERY_ALL, service->lastcheck);
zabbix_log(LOG_LEVEL_TRACE, "%s() for type: VirtualMachine hv id: %s hv uuid: %s linked vm id:"
" %s vm uuid: %s", __func__, hv->id, hv->uuid, vm->id, vm->uuid);
}
@@ -7421,8 +8114,8 @@ static void vmware_service_update_perf_entities(zbx_vmware_service_t *service)
for (i = 0; i < service->data->datastores.values_num; i++)
{
zbx_vmware_datastore_t *ds = service->data->datastores.values[i];
- vmware_service_add_perf_entity(service, ZBX_VMWARE_SOAP_DS, ds->id, ds_perfcounters, "",
- service->lastcheck);
+ vmware_service_add_perf_entity(service, ZBX_VMWARE_SOAP_DS, ds->id, ds_perfcounters,
+ ZBX_VMWARE_PERF_QUERY_TOTAL, service->lastcheck);
zabbix_log(LOG_LEVEL_TRACE, "%s() for type: Datastore id: %s name: %s uuid: %s", __func__,
ds->id, ds->name, ds->uuid);
}
@@ -7445,18 +8138,18 @@ static void vmware_service_copy_cust_query_response(zbx_vector_cq_value_t *cq_va
for (i = 0; i < cq_values->values_num; i++)
{
- if (ZBX_VMWARE_CQV_ERROR == cq_values->values[i].status)
+ if (ZBX_VMWARE_CQV_ERROR == cq_values->values[i]->status)
{
- vmware_shared_strfree(cq_values->values[i].instance->error);
- cq_values->values[i].instance->error = vmware_shared_strdup(cq_values->values[i].response);
- cq_values->values[i].instance->state = ZBX_VMWARE_CQ_ERROR | ZBX_VMWARE_CQ_SEPARATE;
+ vmware_shared_strfree(cq_values->values[i]->instance->error);
+ cq_values->values[i]->instance->error = vmware_shared_strdup(cq_values->values[i]->response);
+ cq_values->values[i]->instance->state = ZBX_VMWARE_CQ_ERROR | ZBX_VMWARE_CQ_SEPARATE;
}
- else if (ZBX_VMWARE_CQV_VALUE == cq_values->values[i].status)
+ else if (ZBX_VMWARE_CQV_VALUE == cq_values->values[i]->status)
{
- vmware_shared_strfree(cq_values->values[i].instance->value);
- cq_values->values[i].instance->value = vmware_shared_strdup(cq_values->values[i].response);
- cq_values->values[i].instance->state = (unsigned char)(ZBX_VMWARE_CQ_READY |
- (cq_values->values[i].instance->state & ZBX_VMWARE_CQ_SEPARATE));
+ vmware_shared_strfree(cq_values->values[i]->instance->value);
+ cq_values->values[i]->instance->value = vmware_shared_strdup(cq_values->values[i]->response);
+ cq_values->values[i]->instance->state = (unsigned char)(ZBX_VMWARE_CQ_READY |
+ (cq_values->values[i]->instance->state & ZBX_VMWARE_CQ_SEPARATE));
}
}
}
@@ -7478,16 +8171,18 @@ static void vmware_service_cust_query_prep(zbx_hashset_t *cust_queries, const zb
zbx_vmware_cust_query_t *instance;
time_t now = time(NULL);
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() cust_queries:%d", __func__, cust_queries->num_data);
+
zbx_hashset_iter_reset(cust_queries, &iter);
while (NULL != (instance = (zbx_vmware_cust_query_t *)zbx_hashset_iter_next(&iter)))
{
- zbx_vmware_cq_value_t cqv = {NULL, ZBX_VMWARE_CQV_EMPTY, NULL};
+ zbx_vmware_cq_value_t *cqv;
if (instance->query_type != type)
continue;
- if (ZBX_VMWARE_CQ_NEW != instance->state && now - instance->last_pooled > SEC_PER_DAY)
+ if (0 == (instance->state & ZBX_VMWARE_CQ_NEW) && now - instance->last_pooled > SEC_PER_DAY)
{
vmware_shared_cust_query_clean(instance);
zbx_hashset_iter_remove(&iter);
@@ -7497,16 +8192,21 @@ static void vmware_service_cust_query_prep(zbx_hashset_t *cust_queries, const zb
if (0 != (instance->state & ZBX_VMWARE_CQ_PAUSED))
continue;
- if (ZBX_VMWARE_CQ_NEW != instance->state &&
+ if (0 == (instance->state & ZBX_VMWARE_CQ_NEW) &&
now - instance->last_pooled > 2 * ZBX_VMWARE_CACHE_UPDATE_PERIOD)
{
instance->state |= ZBX_VMWARE_CQ_PAUSED;
continue;
}
- cqv.instance = instance;
+ cqv = (zbx_vmware_cq_value_t *)zbx_malloc(NULL, sizeof(zbx_vmware_cq_value_t));
+ cqv->status = ZBX_VMWARE_CQV_EMPTY;
+ cqv->instance = instance;
+ cqv->response = NULL;
zbx_vector_cq_value_append(cq_values, cqv);
}
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s() cq_values:%d", __func__, cq_values->values_num);
}
/******************************************************************************
@@ -7537,7 +8237,7 @@ static void vmware_service_dvswitch_load(CURL *easyhandle, zbx_vector_cq_value_t
for (i = 0; i < cq_values->values_num; i++)
{
- zbx_vmware_cq_value_t *cqv = &cq_values->values[i];
+ zbx_vmware_cq_value_t *cqv = cq_values->values[i];
xmlNode *node;
criteria[0] = '\0';
@@ -7603,36 +8303,47 @@ static void vmware_service_dvswitch_load(CURL *easyhandle, zbx_vector_cq_value_t
* *
* Parameters: fn_parent - [IN] parent function name *
* xdoc - [IN] the xml document *
- * cqv - [IN/OUT] the custom query entry *
+ * cqvs - [IN/OUT] the custom query entries *
* *
******************************************************************************/
-static void vmware_service_cq_prop_value(const char *fn_parent, xmlDoc *xdoc, zbx_vmware_cq_value_t *cqv)
+static void vmware_service_cq_prop_value(const char *fn_parent, xmlDoc *xdoc, zbx_vector_cq_value_t *cqvs)
{
- char xpath[MAX_STRING_LEN];
- xmlNode *node;
-
- zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_PROP_NAME("%s"), cqv->instance->key);
+ int i;
- if (NULL == (node = zbx_xml_doc_get(xdoc, xpath)))
+ for (i = 0; i < cqvs->values_num; i++)
{
- cqv->response = NULL;
- cqv->status = ZBX_VMWARE_CQV_VALUE;
- }
- else if (NULL != node->xmlChildrenNode && XML_TEXT_NODE == node->xmlChildrenNode->type)
- {
- cqv->response = zbx_xml_node_read_value(xdoc, node, ".");
- cqv->status = ZBX_VMWARE_CQV_VALUE;
- }
- else
- {
- cqv->response = zbx_strdup(NULL, "only scalar values can be returned.");
- cqv->status = ZBX_VMWARE_CQV_ERROR;
- }
+ char xpath[MAX_STRING_LEN];
+ xmlNode *node;
+ zbx_vmware_cq_value_t *cqv = cqvs->values[i];
- zabbix_log(LOG_LEVEL_DEBUG, "%s() %s id:%s key:%s response length:%d node type:%d", fn_parent,
- ZBX_VMWARE_CQV_ERROR == cqv->status ? "FAIL" : "SUCCEED", cqv->instance->id,
- cqv->instance->key, NULL == cqv->response ? -1 : (int)strlen(cqv->response),
- NULL != node && NULL != node->xmlChildrenNode ? (int)node->xmlChildrenNode->type : -1);
+ zbx_snprintf(xpath, sizeof(xpath), ZBX_XPATH_PROP_NAME("%s"), cqv->instance->key);
+
+ if (NULL == (node = zbx_xml_doc_get(xdoc, xpath)))
+ {
+ cqv->response = NULL;
+ cqv->status = ZBX_VMWARE_CQV_VALUE;
+ }
+ else if ('\0' != *cqv->instance->mode && 0 == strcmp(cqv->instance->mode, "json"))
+ {
+ zbx_xmlnode_to_json(node, &cqv->response);
+ cqv->status = ZBX_VMWARE_CQV_VALUE;
+ }
+ else if (NULL != node->xmlChildrenNode && XML_TEXT_NODE == node->xmlChildrenNode->type)
+ {
+ cqv->response = zbx_xml_node_read_value(xdoc, node, ".");
+ cqv->status = ZBX_VMWARE_CQV_VALUE;
+ }
+ else
+ {
+ cqv->response = zbx_strdup(NULL, "only scalar values can be returned.");
+ cqv->status = ZBX_VMWARE_CQV_ERROR;
+ }
+
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() %s id:%s key:%s response length:%d node type:%d", fn_parent,
+ ZBX_VMWARE_CQV_ERROR == cqv->status ? "FAIL" : "SUCCEED", cqv->instance->id,
+ cqv->instance->key, NULL == cqv->response ? -1 : (int)strlen(cqv->response),
+ NULL != node && NULL != node->xmlChildrenNode ? (int)node->xmlChildrenNode->type : -1);
+ }
}
/******************************************************************************
@@ -7640,16 +8351,17 @@ static void vmware_service_cq_prop_value(const char *fn_parent, xmlDoc *xdoc, zb
* Purpose: load vmware object property info from VC *
* *
* Parameters: easyhandle - [IN] the CURL handle *
+ * collector - [IN] the name of vmware property collector *
* cq_values - [IN/OUT] the vector with custom query entries *
* and responses *
* *
******************************************************************************/
-static void vmware_service_props_load(CURL *easyhandle, zbx_vector_cq_value_t *cq_values)
+static void vmware_service_props_load(CURL *easyhandle, const char *collector, zbx_vector_cq_value_t *cq_values)
{
# define ZBX_POST_OBJ_PROP \
ZBX_POST_VSPHERE_HEADER \
"<ns0:RetrievePropertiesEx>" \
- "<ns0:_this type=\"PropertyCollector\">propertyCollector</ns0:_this>" \
+ "<ns0:_this type=\"PropertyCollector\">%s</ns0:_this>" \
"<ns0:specSet>" \
"<ns0:propSet>" \
"<ns0:type>%s</ns0:type>" \
@@ -7664,22 +8376,26 @@ static void vmware_service_props_load(CURL *easyhandle, zbx_vector_cq_value_t *c
"</ns0:RetrievePropertiesEx>" \
ZBX_POST_VSPHERE_FOOTER
- int i, total = 0, count = 0;
- xmlDoc *doc = NULL;
+ int i, total = 0, count = 0;
+ xmlDoc *doc = NULL;
+ zbx_vector_cq_value_t cq_resp;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() props total:%d", __func__, cq_values->values_num);
+ zbx_vector_cq_value_create(&cq_resp);
+ zbx_vector_cq_value_append(&cq_resp, NULL);
+
for (i = 0; i < cq_values->values_num; i++)
{
char *error = NULL, tmp[MAX_STRING_LEN];
- zbx_vmware_cq_value_t *cqv = &cq_values->values[i];
+ zbx_vmware_cq_value_t *cqv = cq_values->values[i];
if (0 == (cqv->instance->state & ZBX_VMWARE_CQ_SEPARATE))
continue;
zbx_xml_free_doc(doc);
- zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_OBJ_PROP, cqv->instance->soap_type, cqv->instance->key,
- cqv->instance->soap_type, cqv->instance->id);
+ zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_OBJ_PROP, collector, cqv->instance->soap_type,
+ cqv->instance->key, cqv->instance->soap_type, cqv->instance->id);
total++;
if (SUCCEED != zbx_soap_post(__func__, easyhandle, tmp, &doc, NULL, &error))
@@ -7690,12 +8406,14 @@ static void vmware_service_props_load(CURL *easyhandle, zbx_vector_cq_value_t *c
continue;
}
- vmware_service_cq_prop_value(__func__, doc, cqv);
+ cq_resp.values[0] = cqv;
+ vmware_service_cq_prop_value(__func__, doc, &cq_resp);
count++;
}
zbx_xml_free_doc(doc);
+ zbx_vector_cq_value_destroy(&cq_resp);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s() count: %d / %d", __func__, count, total);
# undef ZBX_POST_OBJ_PROP
@@ -7707,37 +8425,81 @@ static void vmware_service_props_load(CURL *easyhandle, zbx_vector_cq_value_t *c
* *
* Parameters: cq_values - [IN] the vector with custom query entries *
* soap_type - [IN] soap type of hv, vm etc *
- * clusterid - [IN] cluster id *
- * bsz - [IN] buffer size *
- * buff - [IN/OUT] - buffer for soap query *
- * cq_prop - [OUT] - custom query entry *
+ * obj_id - [IN] vmware instance id (hv, vm etc) *
+ * cqvs - [OUT] - custom query entry *
* *
* Return value: pointer to string with soap sub query *
* *
******************************************************************************/
static char *vmware_cq_prop_soap_request(const zbx_vector_cq_value_t *cq_values, const char *soap_type,
- const char *clusterid, const size_t bsz, char *buff, zbx_vmware_cq_value_t **cq_prop)
+ const char *obj_id, zbx_vector_cq_value_t *cqvs)
{
- int i;
- zbx_vmware_cust_query_t instance = {.soap_type = (char *)soap_type, .id = (char *)clusterid};
- zbx_vmware_cq_value_t *cq, cmp = {.instance = &instance};
-
- *buff = '\0';
- *cq_prop = NULL;
+ int i;
+ char *buff = zbx_strdup(NULL, "");
- if (FAIL == (i = zbx_vector_cq_value_bsearch(cq_values, cmp, vmware_cq_instance_id_compare)))
- return buff;
+ for (i = 0; i < cq_values->values_num; i++)
+ {
+ zbx_vmware_cq_value_t *cq = cq_values->values[i];
+ char tmp[MAX_STRING_LEN / 4];
- cq = &cq_values->values[i];
+ if (0 != cqvs->values_num && 0 != strcmp(cq->instance->id, obj_id))
+ break;
- if (0 != (cq->instance->state & ZBX_VMWARE_CQ_SEPARATE))
- return buff;
+ if (0 != (cq->instance->state & ZBX_VMWARE_CQ_SEPARATE) || 0 != strcmp(cq->instance->id, obj_id) ||
+ 0 != strcmp(cq->instance->soap_type, soap_type))
+ {
+ continue;
+ }
- zbx_snprintf(buff, bsz, "<ns0:pathSet>%s</ns0:pathSet>", cq->instance->key);
- *cq_prop = cq;
+ zbx_snprintf(tmp, sizeof(tmp), "<ns0:pathSet>%s</ns0:pathSet>", cq->instance->key);
+ buff = zbx_strdcat(buff, tmp);
+ zbx_vector_cq_value_append(cqvs, cq);
+ }
return buff;
}
+
+/******************************************************************************
+ * *
+ * Purpose: set CURL headers for soap request *
+ * *
+ * Parameters: easyhandle - [IN] prepared cURL connection handle *
+ * vc_version - [IN] major version of vc *
+ * headers - [IN/OUT] the CURL headers *
+ * error - [OUT] the error message in the case of failure *
+ * *
+ * Return value: SUCCEED - the headers were set successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int vmware_curl_set_header(CURL *easyhandle, int vc_version, struct curl_slist **headers, char **error)
+{
+ char soapver[MAX_STRING_LEN / 32];
+ CURLoption opt;
+ CURLcode err;
+
+ if (0 != vc_version && 6 > vc_version)
+ return SUCCEED;
+ else if (6 > vc_version)
+ zbx_strlcpy(soapver, ZBX_XML_HEADER1_V4, sizeof(soapver));
+ else
+ zbx_strlcpy(soapver, ZBX_XML_HEADER1_V6, sizeof(soapver));
+
+ curl_slist_free_all(*headers);
+ *headers = NULL;
+ *headers = curl_slist_append(*headers, soapver);
+ *headers = curl_slist_append(*headers, ZBX_XML_HEADER2);
+ *headers = curl_slist_append(*headers, ZBX_XML_HEADER3);
+
+ if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_HTTPHEADER, *headers)))
+ {
+ *error = zbx_dsprintf(*error, "Cannot set cURL option %d: %s.", (int)opt, curl_easy_strerror(err));
+ return FAIL;
+ }
+
+ return SUCCEED;
+}
+
/******************************************************************************
* *
* Purpose: updates object with a new data from vmware service *
@@ -7748,8 +8510,6 @@ static char *vmware_cq_prop_soap_request(const zbx_vector_cq_value_t *cq_values,
int zbx_vmware_service_update(zbx_vmware_service_t *service)
{
CURL *easyhandle = NULL;
- CURLoption opt;
- CURLcode err;
struct curl_slist *headers = NULL;
zbx_vmware_data_t *data;
zbx_vector_str_t hvs, dss;
@@ -7760,7 +8520,7 @@ int zbx_vmware_service_update(zbx_vmware_service_t *service)
ZBX_HTTPPAGE page; /* 347K/87K */
unsigned char evt_pause = 0, evt_skip_old;
zbx_uint64_t evt_last_key, events_sz = 0;
- char msg[MAX_STRING_LEN / 8], soapver[MAX_STRING_LEN / 32];
+ char msg[MAX_STRING_LEN / 8];
zabbix_log(LOG_LEVEL_DEBUG, "In %s() '%s'@'%s'", __func__, service->username, service->url);
@@ -7794,11 +8554,6 @@ int zbx_vmware_service_update(zbx_vmware_service_t *service)
zbx_vector_cq_value_sort(&prop_query_values, vmware_cq_instance_id_compare);
- if (6 > service->major_version)
- zbx_strlcpy(soapver, ZBX_XML_HEADER1_V4, sizeof(soapver));
- else
- zbx_strlcpy(soapver, ZBX_XML_HEADER1_V6, sizeof(soapver));
-
if (NULL == (easyhandle = curl_easy_init()))
{
zabbix_log(LOG_LEVEL_WARNING, "Cannot initialize cURL library");
@@ -7807,15 +8562,9 @@ int zbx_vmware_service_update(zbx_vmware_service_t *service)
page.alloc = ZBX_INIT_UPD_XML_SIZE;
page.data = (char *)zbx_malloc(NULL, page.alloc);
- headers = curl_slist_append(headers, soapver);
- headers = curl_slist_append(headers, ZBX_XML_HEADER2);
- headers = curl_slist_append(headers, ZBX_XML_HEADER3);
- if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_HTTPHEADER, headers)))
- {
- zabbix_log(LOG_LEVEL_WARNING, "Cannot set cURL option %d: %s.", (int)opt, curl_easy_strerror(err));
+ if (SUCCEED != vmware_curl_set_header(easyhandle, service->major_version, &headers, &data->error))
goto clean;
- }
if (SUCCEED != vmware_service_authenticate(service, easyhandle, &page, &data->error))
goto clean;
@@ -7823,6 +8572,10 @@ int zbx_vmware_service_update(zbx_vmware_service_t *service)
if (SUCCEED != vmware_service_initialize(service, easyhandle, &data->error))
goto clean;
+ /* update headers after VC version detection */
+ if (SUCCEED != vmware_curl_set_header(easyhandle, service->major_version, &headers, &data->error))
+ goto clean;
+
if (NULL != service->data && 0 != service->data->events.values_num && 0 == evt_skip_old &&
((const zbx_vmware_event_t *)service->data->events.values[0])->key > evt_last_key)
{
@@ -7835,13 +8588,6 @@ int zbx_vmware_service_update(zbx_vmware_service_t *service)
goto clean;
}
- if (ZBX_VMWARE_TYPE_VCENTER == service->type &&
- SUCCEED != vmware_service_get_clusters_and_resourcepools(service, easyhandle,
- &prop_query_values, &data->clusters, &data->resourcepools, &alarms_data, &data->error))
- {
- goto clean;
- }
-
zbx_vector_vmware_datastore_reserve(&data->datastores, (size_t)(dss.values_num + data->datastores.values_alloc));
for (i = 0; i < dss.values_num; i++)
@@ -7857,6 +8603,13 @@ int zbx_vmware_service_update(zbx_vmware_service_t *service)
zbx_vector_vmware_datastore_sort(&data->datastores, vmware_ds_id_compare);
+ if (ZBX_VMWARE_TYPE_VCENTER == service->type &&
+ SUCCEED != vmware_service_get_clusters_and_resourcepools(service, easyhandle, &data->datastores,
+ &prop_query_values, &data->clusters, &data->resourcepools, &alarms_data, &data->error))
+ {
+ goto clean;
+ }
+
if (SUCCEED != zbx_hashset_reserve(&data->hvs, hvs.values_num))
{
THIS_SHOULD_NEVER_HAPPEN;
@@ -7898,7 +8651,8 @@ int zbx_vmware_service_update(zbx_vmware_service_t *service)
zbx_vector_vmware_datastore_sort(&data->datastores, vmware_ds_uuid_compare);
vmware_service_dvswitch_load(easyhandle, &dvs_query_values);
- vmware_service_props_load(easyhandle, &prop_query_values);
+ vmware_service_props_load(easyhandle, vmware_service_objects[service->type].property_collector,
+ &prop_query_values);
zbx_vector_vmware_alarm_sort(&data->alarms, ZBX_DEFAULT_STR_PTR_COMPARE_FUNC);
if (0 == service->eventlog.req_sz && 0 == evt_pause)
@@ -8194,7 +8948,7 @@ static void vmware_service_parse_perf_data(zbx_vector_ptr_t *perfdata, xmlDoc *x
for (i = 0; i < nodeset->nodeNr; i++)
{
- zbx_vmware_perf_data_t *data;
+ zbx_vmware_perf_data_t *data;
int ret = FAIL;
data = (zbx_vmware_perf_data_t *)zbx_malloc(NULL, sizeof(zbx_vmware_perf_data_t));
@@ -8357,7 +9111,7 @@ static void vmware_service_retrieve_perf_counters(zbx_vmware_service_t *service,
char st_str[ZBX_XML_DATETIME];
/* add startTime for entity performance counter request for decrease XML data load */
- st_raw = zbx_time() - SEC_PER_HOUR;
+ st_raw = time(NULL) - SEC_PER_HOUR;
gmtime_r(&st_raw, &st);
strftime(st_str, sizeof(st_str), "%Y-%m-%dT%TZ", &st);
zbx_snprintf_alloc(&tmp, &tmp_alloc, &tmp_offset, "<ns0:startTime>%s</ns0:startTime>",
@@ -8372,10 +9126,17 @@ static void vmware_service_retrieve_perf_counters(zbx_vmware_service_t *service,
counter = (zbx_vmware_perf_counter_t *)entity->counters.values[j];
+ if (0 != (counter->state & ZBX_VMWARE_COUNTER_CUSTOM) &&
+ 0 == (counter->state & ZBX_VMWARE_COUNTER_ACCEPTABLE))
+ {
+ continue;
+ }
+
zbx_snprintf_alloc(&tmp, &tmp_alloc, &tmp_offset,
"<ns0:metricId><ns0:counterId>" ZBX_FS_UI64
"</ns0:counterId><ns0:instance>%s</ns0:instance></ns0:metricId>",
- counter->counterid, entity->query_instance);
+ counter->counterid, NULL == counter->query_instance ?
+ entity->query_instance : counter->query_instance);
counter->state |= ZBX_VMWARE_COUNTER_UPDATING;
@@ -8435,6 +9196,213 @@ static void vmware_service_retrieve_perf_counters(zbx_vmware_service_t *service,
/******************************************************************************
* *
+ * Purpose: remove unused performance counters *
+ * *
+ * Parameters: counters - [IN] the list of perf counters *
+ * *
+ * Return value: SUCCEED - the performance entity is empty (can be deleted) *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int vmware_perf_counters_expired_remove(zbx_vector_ptr_t *counters)
+{
+ int i;
+ time_t now = time(NULL);
+
+ for (i = counters->values_num - 1; i >= 0 ; i--)
+ {
+ zbx_vmware_perf_counter_t *counter = (zbx_vmware_perf_counter_t *)counters->values[i];
+
+ if (0 == (counter->state & ZBX_VMWARE_COUNTER_CUSTOM))
+ continue;
+
+ if (0 == counter->last_used ||
+ (0 != (counter->state & ZBX_VMWARE_COUNTER_NOTSUPPORTED) &&
+ now - SEC_PER_HOUR * 2 < counter->last_used) ||
+ (0 == (counter->state & ZBX_VMWARE_COUNTER_NOTSUPPORTED) &&
+ now - SEC_PER_DAY < counter->last_used))
+ {
+ continue;
+ }
+
+ vmware_perf_counter_shared_free(counter);
+ zbx_vector_ptr_remove(counters, i);
+ }
+
+ return 0 == counters->values_num ? SUCCEED : FAIL;
+}
+
+/******************************************************************************
+ * *
+ * Purpose: update cache with lists of available perf counter for entity *
+ * *
+ * Parameters: service - [IN] the vmware service *
+ * easyhandle - [IN] prepared cURL connection handle *
+ * type - [IN] vmware object type (vm, hv etc) *
+ * id - [IN] vmware object id (vm, hv etc) *
+ * refresh - [IN] vmware refresh interval for perf counter *
+ * begin_time - [IN] vmware begin time for perf counters list *
+ * perf_available - [IN/OUT] list of available counter per object *
+ * perf - [IN/OUT] the list of perf entities *
+ * error - [OUT] the error message in the case of failure*
+ * *
+ * Return value: SUCCEED - the operation has completed successfully *
+ * FAIL - the operation has failed *
+ ******************************************************************************/
+static int vmware_perf_available_update(zbx_vmware_service_t *service, CURL *easyhandle, const char *type,
+ const char *id, const int refresh, const char *begin_time, zbx_vector_perf_available_t *perf_available,
+ zbx_vmware_perf_available_t **perf, char **error)
+{
+# define ZBX_POST_VMWARE_GET_AVAIL_PERF \
+ ZBX_POST_VSPHERE_HEADER \
+ "<ns0:QueryAvailablePerfMetric>" \
+ "<ns0:_this type=\"PerformanceManager\">%s</ns0:_this>" \
+ "<ns0:entity type=\"%s\">%s</ns0:entity>" \
+ "<ns0:beginTime>%s</ns0:beginTime>" \
+ "%s" \
+ "</ns0:QueryAvailablePerfMetric>" \
+ ZBX_POST_VSPHERE_FOOTER
+
+ int i, ret;
+ char tmp[MAX_STRING_LEN], interval[MAX_STRING_LEN / 32];
+ xmlDoc *doc = NULL;
+ zbx_vector_str_t counters;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() type:%s id:%s begin_time:%s interval:%d", __func__, type, id,
+ begin_time, refresh);
+
+ zbx_vector_str_create(&counters);
+
+ if (ZBX_VMWARE_PERF_INTERVAL_NONE == refresh)
+ *interval = '\0';
+ else
+ zbx_snprintf(interval, sizeof(interval), "<ns0:intervalId>%d</ns0:intervalId>", refresh);
+
+ zbx_snprintf(tmp, sizeof(tmp), ZBX_POST_VMWARE_GET_AVAIL_PERF,
+ vmware_service_objects[service->type].performance_manager, type, id, begin_time, interval);
+
+ if (SUCCEED != (ret = zbx_soap_post(__func__, easyhandle, tmp, &doc, NULL, error)))
+ goto out;
+
+ if (FAIL == zbx_xml_read_values(doc, "/" ZBX_XPATH_LN2("returnval", "counterId"), &counters))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() empty list for type:%s id:%s interval:%d begin time:%s", __func__,
+ type, id, refresh, begin_time);
+ }
+
+ *perf = (zbx_vmware_perf_available_t *)zbx_malloc(NULL, sizeof(zbx_vmware_perf_available_t));
+ (*perf)->type = zbx_strdup(NULL, type);
+ (*perf)->id = zbx_strdup(NULL, id);
+ zbx_vector_uint16_create(&(*perf)->list);
+
+ for (i = 0; i < counters.values_num; i++)
+ {
+ zbx_vector_uint16_append(&(*perf)->list, (uint16_t)atoi(counters.values[i]));
+ }
+
+ zbx_vector_uint16_sort(&(*perf)->list, vmware_uint16_compare);
+ zbx_vector_uint16_uniq(&(*perf)->list, vmware_uint16_compare);
+ zbx_vector_perf_available_append(perf_available, *perf);
+ zbx_vector_perf_available_sort(perf_available, vmware_perf_available_compare);
+out:
+ zbx_vector_str_clear_ext(&counters, zbx_str_free);
+ zbx_vector_str_destroy(&counters);
+ zbx_xml_free_doc(doc);
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+
+ return ret;
+
+# undef ZBX_POST_VMWARE_GET_AVAIL_PERF
+}
+
+/******************************************************************************
+ * *
+ * Purpose: setting flag ZBX_VMWARE_COUNTER_ACCEPTABLE for new perf counters *
+ * *
+ * Parameters: service - [IN] the vmware service *
+ * easyhandle - [IN] prepared cURL connection handle *
+ * perf_available - [IN/OUT] list of available counter per object *
+ * entities - [IN/OUT] the list of perf entities *
+ * *
+ ******************************************************************************/
+static void vmware_perf_counters_availability_check(zbx_vmware_service_t *service, CURL *easyhandle,
+ zbx_vector_perf_available_t *perf_available, zbx_vector_ptr_t *entities)
+{
+ int i;
+ char begin_time[ZBX_XML_DATETIME];
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() entities:%d perf_available:%d", __func__,
+ entities->values_num, perf_available->values_num);
+
+ *begin_time = '\0';
+
+ for (i = 0; i < entities->values_num ; i++)
+ {
+ int j;
+ zbx_vmware_perf_entity_t *entity;
+
+ entity = (zbx_vmware_perf_entity_t *)entities->values[i];
+
+ for (j = 0; j < entity->counters.values_num; j++)
+ {
+ int k;
+ char *err = NULL;
+ zbx_vmware_perf_counter_t *counter;
+ zbx_vmware_perf_available_t *perf, perf_cmp = {.type = entity->type, .id = entity->id};
+
+ counter = (zbx_vmware_perf_counter_t *)entity->counters.values[j];
+
+ if (0 == (counter->state & ZBX_VMWARE_COUNTER_CUSTOM) ||
+ 0 != (counter->state & ZBX_VMWARE_COUNTER_ACCEPTABLE))
+ {
+ continue;
+ }
+
+ if ('\0' == *begin_time)
+ {
+ time_t st_raw;
+ struct tm st;
+
+ st_raw = time(NULL) - SEC_PER_HOUR;
+ gmtime_r(&st_raw, &st);
+ strftime(begin_time, sizeof(begin_time), "%Y-%m-%dT%TZ", &st);
+ }
+
+ if (FAIL != (k = zbx_vector_perf_available_bsearch(
+ perf_available, &perf_cmp, vmware_perf_available_compare)))
+ {
+ perf = perf_available->values[k];
+ }
+ else if (FAIL == vmware_perf_available_update(service, easyhandle, entity->type,
+ entity->id, entity->refresh, begin_time, perf_available, &perf, &err))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "%s() cache update error: %s", __func__, err);
+ zbx_str_free(err);
+ return;
+ }
+
+ if (FAIL == zbx_vector_uint16_bsearch(&perf->list, (uint16_t)counter->counterid,
+ vmware_uint16_compare))
+ {
+ counter->state |= ZBX_VMWARE_COUNTER_NOTSUPPORTED;
+ }
+ else
+ {
+ counter->state |= ZBX_VMWARE_COUNTER_ACCEPTABLE;
+ }
+
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() type:%s id:%s counterid:" ZBX_FS_UI64 " state:%X %s",
+ __func__, entity->type, entity->id, counter->counterid, counter->state,
+ 0 == (counter->state & ZBX_VMWARE_COUNTER_ACCEPTABLE) ?
+ "NOTSUPPORTED" : "ACCEPTABLE");
+ }
+ }
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
+}
+
+/******************************************************************************
+ * *
* Purpose: updates vmware statistics data *
* *
* Parameters: service - [IN] the vmware service *
@@ -8454,6 +9422,7 @@ int zbx_vmware_service_update_perf(zbx_vmware_service_t *service)
zbx_vmware_perf_entity_t *entity;
zbx_hashset_iter_t iter;
zbx_vector_ptr_t perfdata;
+ zbx_vector_perf_available_t perf_available;
static ZBX_HTTPPAGE page; /* 173K */
zabbix_log(LOG_LEVEL_DEBUG, "In %s() '%s'@'%s'", __func__, service->username, service->url);
@@ -8461,6 +9430,7 @@ int zbx_vmware_service_update_perf(zbx_vmware_service_t *service)
zbx_vector_ptr_create(&entities);
zbx_vector_ptr_create(&hist_entities);
zbx_vector_ptr_create(&perfdata);
+ zbx_vector_perf_available_create(&perf_available);
page.alloc = 0;
if (NULL == (easyhandle = curl_easy_init()))
@@ -8492,7 +9462,8 @@ int zbx_vmware_service_update_perf(zbx_vmware_service_t *service)
while (NULL != (entity = (zbx_vmware_perf_entity_t *)zbx_hashset_iter_next(&iter)))
{
/* remove old entities */
- if (0 != entity->last_seen && entity->last_seen < service->lastcheck)
+ if ((0 != entity->last_seen && entity->last_seen < service->lastcheck) ||
+ SUCCEED == vmware_perf_counters_expired_remove(&entity->counters))
{
vmware_shared_perf_entity_clean(entity);
zbx_hashset_iter_remove(&iter);
@@ -8529,6 +9500,34 @@ int zbx_vmware_service_update_perf(zbx_vmware_service_t *service)
zbx_vmware_lock();
+ /* checking the availability of custom performance counters */
+ zbx_hashset_iter_reset(&service->entities, &iter);
+ while (NULL != (entity = (zbx_vmware_perf_entity_t *)zbx_hashset_iter_next(&iter)))
+ {
+ for (i = 0; i < entity->counters.values_num; i++)
+ {
+ zbx_vmware_perf_counter_t *counter;
+
+ counter = (zbx_vmware_perf_counter_t *)entity->counters.values[i];
+
+ if (0 == (counter->state & ZBX_VMWARE_COUNTER_CUSTOM) || 0 != (counter->state &
+ (ZBX_VMWARE_COUNTER_ACCEPTABLE | ZBX_VMWARE_COUNTER_NOTSUPPORTED)))
+ {
+ continue;
+ }
+
+ zbx_vector_ptr_append(&entities, entity);
+ break;
+ }
+ }
+
+ zbx_vmware_unlock();
+
+ vmware_perf_counters_availability_check(service, easyhandle, &perf_available, &entities);
+ zbx_vector_ptr_clear(&entities);
+
+ zbx_vmware_lock();
+
zbx_hashset_iter_reset(&service->entities, &iter);
while (NULL != (entity = (zbx_vmware_perf_entity_t *)zbx_hashset_iter_next(&iter)))
{
@@ -8539,6 +9538,30 @@ int zbx_vmware_service_update_perf(zbx_vmware_service_t *service)
continue;
}
+ /* pre-check acceptable counters */
+ for (i = 0; i < entity->counters.values_num; i++)
+ {
+ zbx_vmware_perf_counter_t *counter;
+
+ counter = (zbx_vmware_perf_counter_t *)entity->counters.values[i];
+
+ if (0 != (counter->state & ZBX_VMWARE_COUNTER_CUSTOM) &&
+ 0 == (counter->state & ZBX_VMWARE_COUNTER_ACCEPTABLE))
+ {
+ continue;
+ }
+
+ break;
+ }
+
+ if (i == entity->counters.values_num)
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "skipping performance entity with type:%s id:%s: "
+ "unsupported counters", entity->type, entity->id);
+ continue;
+ }
+
+
if (ZBX_VMWARE_PERF_INTERVAL_NONE == entity->refresh)
zbx_vector_ptr_append(&hist_entities, entity);
else
@@ -8582,6 +9605,9 @@ out:
zbx_vmware_unlock();
+ zbx_vector_perf_available_clear_ext(&perf_available, vmware_perf_available_free);
+ zbx_vector_perf_available_destroy(&perf_available);
+
zbx_vector_ptr_clear_ext(&perfdata, (zbx_mem_free_func_t)vmware_free_perfdata);
zbx_vector_ptr_destroy(&perfdata);
@@ -8775,7 +9801,8 @@ int zbx_vmware_service_add_perf_counter(zbx_vmware_service_t *service, const cha
zbx_uint64_t counterid, const char *instance)
{
zbx_vmware_perf_entity_t *pentity, entity;
- int ret = FAIL;
+ zbx_vmware_perf_counter_t *counter;
+ int i, ret = FAIL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() type:%s id:%s counterid:" ZBX_FS_UI64, __func__, type, id,
counterid);
@@ -8794,15 +9821,23 @@ int zbx_vmware_service_add_perf_counter(zbx_vmware_service_t *service, const cha
sizeof(zbx_vmware_perf_entity_t));
}
- if (FAIL == zbx_vector_ptr_search(&pentity->counters, &counterid, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC))
+ if (FAIL == (i = zbx_vector_ptr_search(&pentity->counters, &counterid, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC)))
{
- vmware_counters_add_new(&pentity->counters, counterid);
+ vmware_counters_add_new(&pentity->counters, counterid,
+ ZBX_VMWARE_COUNTER_NEW | ZBX_VMWARE_COUNTER_CUSTOM);
+ counter = (zbx_vmware_perf_counter_t *)pentity->counters.values[pentity->counters.values_num - 1];
zbx_vector_ptr_sort(&pentity->counters, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
ret = SUCCEED;
}
+ else
+ counter = (zbx_vmware_perf_counter_t *)pentity->counters.values[i];
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
+ if (*ZBX_VMWARE_PERF_QUERY_ALL != *pentity->query_instance)
+ counter->query_instance = vmware_shared_strdup(instance);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s counter state:%X", __func__, zbx_result_string(ret),
+ counter->state);
return ret;
}
diff --git a/src/zabbix_server/vmware/vmware.h b/src/zabbix_server/vmware/vmware.h
index 8a7962c6c99..15adb060d09 100644
--- a/src/zabbix_server/vmware/vmware.h
+++ b/src/zabbix_server/vmware/vmware.h
@@ -31,11 +31,6 @@
#define ZBX_VMWARE_STATE_MASK 0x0FF
-/* the vmware performance counter state */
-#define ZBX_VMWARE_COUNTER_NEW 0x00
-#define ZBX_VMWARE_COUNTER_READY 0x01
-#define ZBX_VMWARE_COUNTER_UPDATING 0x10
-
#define ZBX_VMWARE_EVENT_KEY_UNINITIALIZED __UINT64_C(0xffffffffffffffff)
typedef struct
@@ -48,6 +43,8 @@ zbx_str_uint64_pair_t;
ZBX_PTR_VECTOR_DECL(str_uint64_pair, zbx_str_uint64_pair_t)
int zbx_str_uint64_pair_name_compare(const void *p1, const void *p2);
+#define UC(v) ((unsigned char)v)
+
/* performance counter data */
typedef struct
{
@@ -59,8 +56,22 @@ typedef struct
/* pair->value - value */
zbx_vector_str_uint64_pair_t values;
- /* the counter state, see ZBX_VMAWRE_COUNTER_* defines */
+#define ZBX_VMWARE_COUNTER_NEW UC(0x00)
+#define ZBX_VMWARE_COUNTER_READY UC(0x01)
+#define ZBX_VMWARE_COUNTER_UPDATING UC(0x02)
+#define ZBX_VMWARE_COUNTER_CUSTOM UC(0x10)
+#define ZBX_VMWARE_COUNTER_ACCEPTABLE UC(0x20)
+#define ZBX_VMWARE_COUNTER_NOTSUPPORTED UC(0x40)
+
+#define ZBX_VMWARE_COUNTER_STATE_MASK 0xF0
+ /* the vmware performance counter state */
unsigned char state;
+
+ /* time of last attempt of poller to use data */
+ time_t last_used;
+
+ /* alternate query instance (for the case when 'entity' query is TOTAL) */
+ char *query_instance;
}
zbx_vmware_perf_counter_t;
@@ -73,15 +84,19 @@ typedef struct
/* entity id */
char *id;
+#define ZBX_VMWARE_PERF_INTERVAL_UNKNOWN 0
+#define ZBX_VMWARE_PERF_INTERVAL_NONE -1
/* the performance counter refresh rate */
int refresh;
/* timestamp when the entity was queried last time */
- int last_seen;
+ time_t last_seen;
/* the performance counters to monitor */
zbx_vector_ptr_t counters;
+#define ZBX_VMWARE_PERF_QUERY_ALL "*"
+#define ZBX_VMWARE_PERF_QUERY_TOTAL ""
/* the performance counter query instance name */
char *query_instance;
@@ -92,8 +107,34 @@ zbx_vmware_perf_entity_t;
typedef struct
{
- zbx_uint64_t partitionid;
+ char *ssd;
+ char *local_disk;
+ unsigned int block_size;
+ unsigned int block;
+}
+zbx_vmware_vsandiskinfo_t;
+
+typedef struct
+{
+ char *diskname;
+ char *ds_uuid;
+ char *operational_state;
+ char *lun_type;
+ int queue_depth;
+ char *model;
+ char *vendor;
+ char *revision;
+ char *serial_number;
+ zbx_vmware_vsandiskinfo_t *vsan;
+}
+zbx_vmware_diskinfo_t;
+
+ZBX_PTR_VECTOR_DECL(vmware_diskinfo, zbx_vmware_diskinfo_t *)
+
+typedef struct
+{
char *diskname;
+ zbx_uint64_t partitionid;
}
zbx_vmware_diskextent_t;
@@ -113,6 +154,7 @@ typedef struct
char *uuid;
char *name;
char *id;
+ char *type;
zbx_uint64_t capacity;
zbx_uint64_t free_space;
zbx_uint64_t uncommitted;
@@ -266,6 +308,7 @@ typedef struct
zbx_vector_ptr_t vms;
zbx_vector_vmware_pnic_t pnics;
zbx_vector_str_t alarm_ids;
+ zbx_vector_vmware_diskinfo_t diskinfo;
}
zbx_vmware_hv_t;
@@ -283,6 +326,7 @@ typedef struct
char *id;
char *name;
char *status;
+ zbx_vector_str_t dss_uuid;
zbx_vector_str_t alarm_ids;
}
zbx_vmware_cluster_t;
@@ -381,11 +425,11 @@ typedef struct
/* the result of query */
char *value;
-#define ZBX_VMWARE_CQ_NEW 0
-#define ZBX_VMWARE_CQ_READY 1
-#define ZBX_VMWARE_CQ_ERROR 2
-#define ZBX_VMWARE_CQ_PAUSED 4
-#define ZBX_VMWARE_CQ_SEPARATE 8
+#define ZBX_VMWARE_CQ_NEW UC(0x01)
+#define ZBX_VMWARE_CQ_READY UC(0x02)
+#define ZBX_VMWARE_CQ_ERROR UC(0x04)
+#define ZBX_VMWARE_CQ_PAUSED UC(0x08)
+#define ZBX_VMWARE_CQ_SEPARATE UC(0x10)
/* the state of query */
unsigned char state;
@@ -443,10 +487,10 @@ typedef struct
/* the service state - see ZBX_VMWARE_STATE_* defines */
int state;
- int lastcheck;
+ time_t lastcheck;
/* The last vmware service access time. If a service is not accessed for a day it is removed */
- int lastaccess;
+ time_t lastaccess;
/* the vmware service instance version */
char *version;
@@ -454,6 +498,7 @@ typedef struct
/* the vmware service instance version numeric */
unsigned short major_version;
unsigned short minor_version;
+ unsigned short update_version;
/* the vmware service instance fullname */
char *fullname;
@@ -481,9 +526,6 @@ typedef struct
}
zbx_vmware_service_t;
-#define ZBX_VMWARE_PERF_INTERVAL_UNKNOWN 0
-#define ZBX_VMWARE_PERF_INTERVAL_NONE -1
-
/* the vmware collector data */
typedef struct
{
@@ -496,7 +538,7 @@ zbx_vmware_t;
typedef struct
{
- int nextcheck;
+ time_t nextcheck;
#define ZBX_VMWARE_UPDATE_CONF 1
#define ZBX_VMWARE_UPDATE_PERFCOUNTERS 2
#define ZBX_VMWARE_UPDATE_REST_TAGS 3
@@ -546,7 +588,7 @@ int zbx_vmware_service_add_perf_counter(zbx_vmware_service_t *service, const cha
zbx_vmware_perf_entity_t *zbx_vmware_service_get_perf_entity(zbx_vmware_service_t *service, const char *type,
const char *id);
-zbx_vmware_cust_query_t *zbx_vmware_service_add_cust_query(zbx_vmware_service_t *service, const char *type,
+zbx_vmware_cust_query_t *zbx_vmware_service_add_cust_query(zbx_vmware_service_t *service, const char *soap_type,
const char *id, const char *key, zbx_vmware_custom_query_type_t query_type, const char *mode,
zbx_vector_custquery_param_t *query_params);
zbx_vmware_cust_query_t *zbx_vmware_service_get_cust_query(zbx_vmware_service_t *service, const char *type,
diff --git a/src/zabbix_server/vmware/vmware_manager.c b/src/zabbix_server/vmware/vmware_manager.c
index 7b2d5663e19..8bbde550873 100644
--- a/src/zabbix_server/vmware/vmware_manager.c
+++ b/src/zabbix_server/vmware/vmware_manager.c
@@ -32,8 +32,6 @@ extern int CONFIG_VMWARE_PERF_FREQUENCY;
#define ZBX_VMWARE_SERVICE_TTL SEC_PER_HOUR
extern unsigned char program_type;
-extern ZBX_THREAD_LOCAL unsigned char process_type;
-extern ZBX_THREAD_LOCAL int server_num, process_num;
extern zbx_vmware_t *vmware;
/******************************************************************************
@@ -70,7 +68,7 @@ static const char *vmware_job_type_string(zbx_vmware_job_t *job)
* Return value: job for object or NULL *
* *
******************************************************************************/
-static zbx_vmware_job_t *vmware_job_get(zbx_vmware_t *vmw, int time_now)
+static zbx_vmware_job_t *vmware_job_get(zbx_vmware_t *vmw, time_t time_now)
{
zbx_binary_heap_elem_t *elem;
zbx_vmware_job_t *job = NULL;
@@ -152,7 +150,7 @@ out:
* time_now - [IN] the current time *
* *
******************************************************************************/
-static void vmware_job_schedule(zbx_vmware_t *vmw, zbx_vmware_job_t *job, int time_now)
+static void vmware_job_schedule(zbx_vmware_t *vmw, zbx_vmware_job_t *job, time_t time_now)
{
zbx_binary_heap_elem_t elem_new = {0, job};
@@ -190,17 +188,17 @@ static void vmware_job_schedule(zbx_vmware_t *vmw, zbx_vmware_job_t *job, int ti
ZBX_THREAD_ENTRY(vmware_thread, args)
{
#if defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL)
- int services_updated = 0, services_removed = 0;
- double time_now, time_stat, time_idle = 0;
-
- process_type = ((zbx_thread_args_t *)args)->process_type;
- server_num = ((zbx_thread_args_t *)args)->server_num;
- process_num = ((zbx_thread_args_t *)args)->process_num;
+ int services_updated = 0, services_removed = 0;
+ double time_now, time_stat, time_idle = 0;
+ const zbx_thread_info_t *info = &((zbx_thread_args_t *)args)->info;
+ int server_num = ((zbx_thread_args_t *)args)->info.server_num;
+ int process_num = ((zbx_thread_args_t *)args)->info.process_num;
+ unsigned char process_type = ((zbx_thread_args_t *)args)->info.process_type;
zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
server_num, get_process_type_string(process_type), process_num);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
#define JOB_TIMEOUT 1
#define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */
@@ -237,15 +235,15 @@ ZBX_THREAD_ENTRY(vmware_thread, args)
}
services_updated += vmware_job_exec(job);
- vmware_job_schedule(vmware, job, (int)time_now);
+ vmware_job_schedule(vmware, job, (time_t)time_now);
}
if (zbx_time() - time_now <= JOB_TIMEOUT)
{
time_idle += JOB_TIMEOUT;
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);
- zbx_sleep_loop(JOB_TIMEOUT);
- zbx_update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_IDLE);
+ zbx_sleep_loop(info, JOB_TIMEOUT);
+ zbx_update_selfmon_counter(info, ZBX_PROCESS_STATE_BUSY);
}
}
diff --git a/src/zabbix_server/vmware/vmware_rest.c b/src/zabbix_server/vmware/vmware_rest.c
index 60aaee54b03..19665791ae5 100644
--- a/src/zabbix_server/vmware/vmware_rest.c
+++ b/src/zabbix_server/vmware/vmware_rest.c
@@ -32,7 +32,6 @@ typedef struct
size_t alloc;
size_t offset;
char *url;
-
}
ZBX_HTTPPAGE;
@@ -239,6 +238,7 @@ static void vmware_entry_tags_init(zbx_vmware_data_t *data, zbx_vector_vmware_en
* Purpose: cURL handle prepare *
* *
* Parameters: url - [IN] the vmware service url *
+ * is_new_api - [IN] flag to use new api version syntax *
* easyhandle - [OUT] cURL handle *
* page - [OUT] the response buffer for cURL *
* headers - [OUT] the request headers for cURL *
@@ -247,8 +247,8 @@ static void vmware_entry_tags_init(zbx_vmware_data_t *data, zbx_vector_vmware_en
* Return value: SUCCEED if the cURL prepared, FAIL otherwise *
* *
******************************************************************************/
-static int vmware_curl_init(const char *url, CURL **easyhandle, ZBX_HTTPPAGE *page, struct curl_slist **headers,
- char **error)
+static int vmware_curl_init(const char *url, unsigned char is_new_api, CURL **easyhandle, ZBX_HTTPPAGE *page,
+ struct curl_slist **headers, char **error)
{
# define INIT_PERF_REST_SIZE 2 * ZBX_KIBIBYTE
# define ZBX_XML_HEADER1 "Accept: application/json, text/plain, */*"
@@ -281,7 +281,14 @@ static int vmware_curl_init(const char *url, CURL **easyhandle, ZBX_HTTPPAGE *pa
goto out;
}
- memcpy(&page->url[url_sz - ZBX_CONST_STRLEN("api")], "api", ZBX_CONST_STRLEN("api"));
+ if (0 == is_new_api)
+ {
+ page->url = zbx_dsprintf(page->url, "%.*s%s", (int)(url_sz - ZBX_CONST_STRLEN("sdk")), page->url,
+ "rest/com/vmware");
+ }
+ else
+ memcpy(&page->url[url_sz - ZBX_CONST_STRLEN("api")], "api", ZBX_CONST_STRLEN("api"));
+
*headers = curl_slist_append(*headers, ZBX_XML_HEADER1);
*headers = curl_slist_append(*headers, ZBX_XML_HEADER2);
@@ -368,6 +375,28 @@ static int vmware_rest_response_open(const char *data, struct zbx_json_parse *jp
return FAIL;
}
+ if (SUCCEED == zbx_json_value_by_name(jp, "majorErrorCode", err, sizeof(err), NULL))
+ {
+ char err_msg[VMWARE_SHORT_STR_LEN];
+ const char *p = NULL;
+ struct zbx_json_parse jp_row;
+
+ zbx_json_value_by_name(jp, "name", err, sizeof(err), NULL);
+
+ if (SUCCEED != zbx_json_brackets_by_name(jp, "localizableMessages", &jp_data) ||
+ NULL == (p = zbx_json_next(&jp_data, p)) ||
+ SUCCEED != zbx_json_brackets_open(p, &jp_row) ||
+ SUCCEED != zbx_json_value_by_name(&jp_row, "defaultMessage", err_msg, sizeof(err_msg),
+ NULL))
+ {
+ err_msg[0] = '\0';
+ }
+
+ *error = zbx_dsprintf(*error, "%s:%s", err, err_msg);
+
+ return FAIL;
+ }
+
return SUCCEED;
}
@@ -376,6 +405,7 @@ static int vmware_rest_response_open(const char *data, struct zbx_json_parse *jp
* Purpose: authenticate rest service *
* *
* Parameters: service - [IN] the vmware service *
+ * is_new_api - [IN] flag to use new api version syntax *
* easyhandle - [IN/OUT] cURL handle *
* headers - [IN/OUT] the request headers for cURL *
* page - [IN/OUT] the response buffer for cURL *
@@ -384,8 +414,8 @@ static int vmware_rest_response_open(const char *data, struct zbx_json_parse *jp
* Return value: SUCCEED if the rest authenticated, FAIL otherwise *
* *
******************************************************************************/
-static int vmware_service_rest_authenticate(const zbx_vmware_service_t *service, CURL *easyhandle,
- struct curl_slist **headers, ZBX_HTTPPAGE *page, char **error)
+static int vmware_service_rest_authenticate(const zbx_vmware_service_t *service, unsigned char is_new_api,
+ CURL *easyhandle, struct curl_slist **headers, ZBX_HTTPPAGE *page, char **error)
{
int ret = FAIL;
char tmp[MAX_STRING_LEN];
@@ -394,7 +424,7 @@ static int vmware_service_rest_authenticate(const zbx_vmware_service_t *service,
zabbix_log(LOG_LEVEL_DEBUG, "In %s() '%s'@'%s'", __func__, service->username, service->url);
- zbx_snprintf(tmp, sizeof(tmp),"%s/session", page->url);
+ zbx_snprintf(tmp, sizeof(tmp), 0 != is_new_api ? "%s/session" : "%s/cis/session", page->url);
if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_POST, 1L)) ||
CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_URL, tmp)) ||
@@ -413,15 +443,44 @@ static int vmware_service_rest_authenticate(const zbx_vmware_service_t *service,
goto out;
}
- if ('"' != page->data[0] && FAIL == vmware_rest_response_open(page->data, NULL, error))
+ if (0 == page->offset)
{
- *error = zbx_dsprintf(*error, "Authentication fail, %s.", *error);
+ *error = zbx_strdup(*error, "Cannot authenticate, received empty response.");
goto out;
}
- zbx_ltrim(page->data, "\"");
- zbx_rtrim(page->data, "\"");
- zbx_snprintf(tmp, sizeof(tmp),"vmware-api-session-id: %s", page->data);
+ if (0 == is_new_api)
+ {
+ char token[MAX_STRING_LEN];
+ struct zbx_json_parse jp;
+
+ if (FAIL == vmware_rest_response_open(page->data, &jp, error))
+ {
+ *error = zbx_dsprintf(*error, "Cannot authenticate: %s.", *error);
+ goto out;
+ }
+
+ if (SUCCEED != zbx_json_value_by_name(&jp, "value", token, sizeof(token), NULL))
+ {
+ *error = zbx_dsprintf(*error, "Cannot authenticate, cannot read vmware response: %s.",
+ zbx_json_strerror());
+ goto out;
+ }
+
+ zbx_snprintf(tmp, sizeof(tmp),"vmware-api-session-id: %s", token);
+ }
+ else
+ {
+ if ('"' != page->data[0] && FAIL == vmware_rest_response_open(page->data, NULL, error))
+ {
+ *error = zbx_dsprintf(*error, "Authentication fail, %s.", *error);
+ goto out;
+ }
+
+ zbx_lrtrim(page->data, "\"");
+ zbx_snprintf(tmp, sizeof(tmp),"vmware-api-session-id: %s", page->data);
+ }
+
*headers = curl_slist_append(*headers, tmp);
if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_HTTPHEADER, *headers)))
@@ -451,7 +510,8 @@ static void vmware_service_rest_logout(CURL *easyhandle, ZBX_HTTPPAGE *page)
zbx_snprintf(tmp, sizeof(tmp),"%s/session", page->url);
if (CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_URL, tmp)) ||
- CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_CUSTOMREQUEST, "DELETE")))
+ CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_CUSTOMREQUEST, "DELETE")) ||
+ CURLE_OK != (err = curl_easy_setopt(easyhandle, opt = CURLOPT_POST, 0L)))
{
zabbix_log(LOG_LEVEL_DEBUG, "%s() cannot set cURL option %d: %s.",
__func__, (int)opt, curl_easy_strerror(err));
@@ -510,6 +570,8 @@ static int vmware_http_request(const char *fn_parent, CURL *easyhandle, const ch
*error = zbx_strdup(*error, curl_easy_strerror(err));
return FAIL;
}
+ else if (0 == page->offset)
+ *page->data = '\0';
if (NULL != fn_parent)
zabbix_log(LOG_LEVEL_TRACE, "%s() REST response: %s", fn_parent, page->data);
@@ -575,7 +637,17 @@ static int vmware_rest_post(const char *fn_parent, CURL *easyhandle, const char
return FAIL;
}
- return vmware_http_request(fn_parent, easyhandle, url_suffix, jp, error);
+ if (SUCCEED != vmware_http_request(fn_parent, easyhandle, url_suffix, jp, error))
+ return FAIL;
+
+ if (CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, NULL)))
+ {
+ *error = zbx_dsprintf(*error, "Cannot set cURL option %d: %s.", CURLOPT_POSTFIELDS,
+ curl_easy_strerror(err));
+ return FAIL;
+ }
+
+ return SUCCEED;
}
/******************************************************************************
@@ -584,31 +656,46 @@ static int vmware_rest_post(const char *fn_parent, CURL *easyhandle, const char
* *
* Parameters: obj_id - [IN] the parent function name for Log records *
* easyhandle - [IN] the CURL handle *
+ * is_new_api - [IN] flag to use new api version syntax *
* ids - [OUT] the vector with tags id *
* error - [OUT] the error message in the case of failure *
* *
* Return value: SUCCEED if the receive list of tags id, FAIL otherwise *
* *
******************************************************************************/
-static int vmware_tags_linked_id(const zbx_vmware_obj_id_t *obj_id, CURL *easyhandle, zbx_vector_str_t *ids,
- char **error)
+static int vmware_tags_linked_id(const zbx_vmware_obj_id_t *obj_id, CURL *easyhandle, unsigned char is_new_api,
+ zbx_vector_str_t *ids, char **error)
{
- int ret = FAIL;
+ int ret;
char tmp[MAX_STRING_LEN];
- const char *p = NULL;
+ const char *url, *p = NULL;
struct zbx_json_parse jp;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() obj_id:%s", __func__, obj_id->id);
zbx_snprintf(tmp, sizeof(tmp),"{\"object_id\":{\"id\":\"%s\",\"type\":\"%s\"}}", obj_id->id, obj_id->type);
- if (SUCCEED == (ret = vmware_rest_post(__func__, easyhandle,
- "/cis/tagging/tag-association?action=list-attached-tags", tmp, &jp, error)))
+ if (0 != is_new_api)
+ url = "/cis/tagging/tag-association?action=list-attached-tags";
+ else
+ url = "/cis/tagging/tag-association?~action=list-attached-tags";
+
+ if (SUCCEED == (ret = vmware_rest_post(__func__, easyhandle, url, tmp, &jp, error)))
{
- while (NULL != (p = zbx_json_next_value(&jp, p, tmp, sizeof(tmp), NULL)))
+ struct zbx_json_parse jp_step;
+
+ if (0 == is_new_api)
+ {
+ if (SUCCEED != (ret = zbx_json_brackets_by_name(&jp, "value", &jp_step)))
+ goto out;
+ }
+ else
+ jp_step = jp;
+
+ while (NULL != (p = zbx_json_next_value(&jp_step, p, tmp, sizeof(tmp), NULL)))
zbx_vector_str_append(ids, zbx_strdup(NULL, tmp));
}
-
+out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s() ids:%d", __func__, ids->values_num);
return ret;
@@ -620,6 +707,7 @@ static int vmware_tags_linked_id(const zbx_vmware_obj_id_t *obj_id, CURL *easyha
* *
* Parameters: tag_id - [IN] the tag id *
* easyhandle - [IN] the CURL handle *
+ * is_new_api - [IN] flag to use new api version syntax *
* tags - [OUT] the vector with tags info *
* categories - [OUT] the vector with categories info *
* error - [OUT] the error message in the case of failure *
@@ -627,36 +715,45 @@ static int vmware_tags_linked_id(const zbx_vmware_obj_id_t *obj_id, CURL *easyha
* Return value: SUCCEED if the receive tag details, FAIL otherwise *
* *
******************************************************************************/
-static int vmware_vectors_update(const char *tag_id, CURL *easyhandle, zbx_vector_vmware_tag_t *tags,
- zbx_vector_vmware_key_value_t *categories, char **error)
+static int vmware_vectors_update(const char *tag_id, CURL *easyhandle, unsigned char is_new_api,
+ zbx_vector_vmware_tag_t *tags, zbx_vector_vmware_key_value_t *categories, char **error)
{
- struct zbx_json_parse jp;
+ struct zbx_json_parse jp, jp_data;
int i;
char cid[VMWARE_SHORT_STR_LEN], name[MAX_STRING_LEN], desc[MAX_STRING_LEN];
+ const char *url_tag, *url_cat;
zbx_vmware_key_value_t cat_cmp;
zbx_vmware_tag_t *tag;
zabbix_log(LOG_LEVEL_DEBUG, "%s() tag_id:%s", __func__, tag_id);
- if (FAIL == vmware_rest_get(__func__, easyhandle, "/cis/tagging/tag/", tag_id, &jp, error))
- return FAIL;
-
- if (FAIL == zbx_json_value_by_name(&jp, "name", name, sizeof(name), NULL))
+ if (0 == is_new_api)
{
- *error = zbx_dsprintf(*error, "Cannot read vmware response: %s", zbx_json_strerror());
- return FAIL;
+ url_tag = "/cis/tagging/tag/id:";
+ url_cat = "/cis/tagging/category/id:";
}
-
- if (FAIL == zbx_json_value_by_name(&jp, "description", desc, sizeof(desc), NULL))
+ else
{
- *error = zbx_dsprintf(*error, "Cannot read vmware response: %s", zbx_json_strerror());
+ url_tag = "/cis/tagging/tag/";
+ url_cat = "/cis/tagging/category/";
+ }
+
+ if (FAIL == vmware_rest_get(__func__, easyhandle, url_tag, tag_id, &jp_data, error))
return FAIL;
+
+ if (0 == is_new_api)
+ {
+ if (SUCCEED != zbx_json_brackets_by_name(&jp_data, "value", &jp))
+ goto json_err;
}
+ else
+ jp = jp_data;
- if (FAIL == zbx_json_value_by_name(&jp, "category_id", cid, sizeof(cid), NULL))
+ if (FAIL == zbx_json_value_by_name(&jp, "name", name, sizeof(name), NULL) ||
+ FAIL == zbx_json_value_by_name(&jp, "description", desc, sizeof(desc), NULL) ||
+ FAIL == zbx_json_value_by_name(&jp, "category_id", cid, sizeof(cid), NULL))
{
- *error = zbx_dsprintf(*error, "Cannot read vmware response: %s", zbx_json_strerror());
- return FAIL;
+ goto json_err;
}
cat_cmp.key = cid;
@@ -666,14 +763,19 @@ static int vmware_vectors_update(const char *tag_id, CURL *easyhandle, zbx_vecto
zbx_vmware_key_value_t category;
char value[MAX_STRING_LEN];
- if (FAIL == vmware_rest_get(__func__, easyhandle, "/cis/tagging/category/", cid, &jp, error))
+ if (FAIL == vmware_rest_get(__func__, easyhandle, url_cat, cid, &jp_data, error))
return FAIL;
- if (FAIL == zbx_json_value_by_name(&jp, "name", value, sizeof(value), NULL))
+ if (0 == is_new_api)
{
- *error = zbx_dsprintf(*error, "Cannot read vmware response: %s", zbx_json_strerror());
- return FAIL;
+ if (SUCCEED != zbx_json_brackets_by_name(&jp_data, "value", &jp))
+ goto json_err;
}
+ else
+ jp = jp_data;
+
+ if (FAIL == zbx_json_value_by_name(&jp, "name", value, sizeof(value), NULL))
+ goto json_err;
category.key = zbx_strdup(NULL, cid);
category.value = zbx_strdup(NULL, value);
@@ -706,13 +808,17 @@ static int vmware_vectors_update(const char *tag_id, CURL *easyhandle, zbx_vecto
tags->values[i]->name, tags->values[i]->description, tags->values[i]->category);
return i;
+json_err:
+ *error = zbx_dsprintf(*error, "Cannot read vmware response: %s", zbx_json_strerror());
+ return FAIL;
}
/******************************************************************************
* *
* Purpose: create vector with tags details *
* *
- * Parameters: entity_tags - [IN/OUT] the tag entity *
+ * Parameters: is_new_api - [IN] flag to use new api version syntax *
+ * entity_tags - [IN/OUT] the tag entity *
* tags - [IN/OUT] the vector with tags info *
* categories - [IN/OUT] the vector with categories info *
* easyhandle - [IN/OUT] the CURL handle *
@@ -720,8 +826,8 @@ static int vmware_vectors_update(const char *tag_id, CURL *easyhandle, zbx_vecto
* Return value: SUCCEED if the create tags vector, FAIL otherwise *
* *
******************************************************************************/
-static int vmware_tags_get(zbx_vmware_entity_tags_t *entity_tags, zbx_vector_vmware_tag_t *tags,
- zbx_vector_vmware_key_value_t *categories, CURL *easyhandle)
+static int vmware_tags_get(unsigned char is_new_api, zbx_vmware_entity_tags_t *entity_tags,
+ zbx_vector_vmware_tag_t *tags, zbx_vector_vmware_key_value_t *categories, CURL *easyhandle)
{
int i, found_tags = 0;
zbx_vector_str_t tag_ids;
@@ -730,7 +836,7 @@ static int vmware_tags_get(zbx_vmware_entity_tags_t *entity_tags, zbx_vector_vmw
zbx_vector_str_create(&tag_ids);
- if (FAIL == vmware_tags_linked_id(entity_tags->obj_id, easyhandle, &tag_ids, &entity_tags->error))
+ if (FAIL == vmware_tags_linked_id(entity_tags->obj_id, easyhandle, is_new_api, &tag_ids, &entity_tags->error))
goto out;
for (i = 0; i < tag_ids.values_num; i++)
@@ -739,8 +845,8 @@ static int vmware_tags_get(zbx_vmware_entity_tags_t *entity_tags, zbx_vector_vmw
zbx_vmware_tag_t *tag, cmp = {.id = tag_ids.values[i]};
if (FAIL == (j = zbx_vector_vmware_tag_bsearch(tags, &cmp, zbx_vmware_tag_id_compare)) &&
- FAIL == (j = vmware_vectors_update(tag_ids.values[i], easyhandle, tags, categories,
- &entity_tags->error)))
+ FAIL == (j = vmware_vectors_update(tag_ids.values[i], easyhandle, is_new_api, tags,
+ categories, &entity_tags->error)))
{
zabbix_log(LOG_LEVEL_DEBUG, "%s() problem with tag_id:%s error:%s", __func__, tag_ids.values[i],
entity_tags->error);
@@ -774,42 +880,49 @@ out:
******************************************************************************/
int zbx_vmware_service_update_tags(zbx_vmware_service_t *service)
{
- int i, found_tags = 0, ret = FAIL;
+ int i, version, found_tags = 0, ret = FAIL;
+ char *error = NULL;
+ unsigned char is_new_api;
zbx_vector_vmware_entity_tags_t entity_tags;
- zbx_vector_vmware_tag_t tags;
+ zbx_vector_vmware_tag_t tags;
zbx_vector_vmware_key_value_t categories;
CURL *easyhandle = NULL;
struct curl_slist *headers = NULL;
ZBX_HTTPPAGE page = {.data = NULL, .url = NULL};
- char *error = NULL;
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() vc version:%s", __func__, service->version);
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
+
+ zbx_vector_vmware_entity_tags_create(&entity_tags);
+
+ zbx_vmware_lock();
+ version = service->major_version * 100 + service->minor_version * 10 + service->update_version;
- if (65 > service->major_version * 10 + service->minor_version)
+ if (650 > version)
{
+ zbx_vmware_unlock();
error = zbx_strdup(error, "Tags are supported since vmware version 6.5.");
goto out;
}
- zbx_vector_vmware_tag_create(&tags);
- zbx_vector_vmware_key_value_create(&categories);
- zbx_vector_vmware_entity_tags_create(&entity_tags);
-
- zbx_vmware_lock();
vmware_entry_tags_init(service->data, &entity_tags);
zbx_vmware_unlock();
+ zabbix_log(LOG_LEVEL_DEBUG, "%s() vc version:%d", __func__, version);
+
+ zbx_vector_vmware_tag_create(&tags);
+ zbx_vector_vmware_key_value_create(&categories);
+ is_new_api = (702 <= version) ? 1 : 0;
+
if (0 != entity_tags.values_num && (
- SUCCEED != vmware_curl_init(service->url, &easyhandle, &page, &headers, &error) ||
- SUCCEED != vmware_service_rest_authenticate(service, easyhandle, &headers, &page, &error)))
+ SUCCEED != vmware_curl_init(service->url, is_new_api, &easyhandle, &page, &headers, &error) ||
+ SUCCEED != vmware_service_rest_authenticate(service, is_new_api, easyhandle, &headers, &page,
+ &error)))
{
goto clean;
}
for (i = 0; i < entity_tags.values_num; i++)
- {
- found_tags += vmware_tags_get(entity_tags.values[i], &tags, &categories, easyhandle);
- }
+ found_tags += vmware_tags_get(is_new_api, entity_tags.values[i], &tags, &categories, easyhandle);
if (NULL != headers)
vmware_service_rest_logout(easyhandle, &page);
@@ -820,15 +933,16 @@ int zbx_vmware_service_update_tags(zbx_vmware_service_t *service)
clean:
zbx_vector_vmware_tag_clear_ext(&tags, vmware_tag_free);
zbx_vector_vmware_key_value_clear_ext(&categories, vmware_key_value_free);
- zbx_vector_vmware_entity_tags_clear_ext(&entity_tags, vmware_entity_tags_free);
zbx_vector_vmware_tag_destroy(&tags);
zbx_vector_vmware_key_value_destroy(&categories);
- zbx_vector_vmware_entity_tags_destroy(&entity_tags);
curl_slist_free_all(headers);
curl_easy_cleanup(easyhandle);
zbx_free(page.data);
zbx_free(page.url);
out:
+ zbx_vector_vmware_entity_tags_clear_ext(&entity_tags, vmware_entity_tags_free);
+ zbx_vector_vmware_entity_tags_destroy(&entity_tags);
+
if (FAIL == ret)
{
zbx_vmware_shared_tags_error_set(error, &service->data_tags);