.......PS. [ZBX-8488] ported r47705 and a part of r47979 from ZBX-8476 branch