** Copyright (C) 2001-2023 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.
"git.zabbix.com/ap/plugin-support/zbxerr"
func newClient(socketPath string, timeout int) *client {
transport := &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", socketPath)
client.client = http.Client{
Timeout: time.Duration(timeout) * time.Second,
func (cli *client) Query(queryPath string) ([]byte, error) {
resp, err := cli.client.Get("http://" + path.Join(dockerVersion, queryPath))
return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
body, err := ioutil.ReadAll(resp.Body)
return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
if resp.StatusCode != http.StatusOK {
if err = json.Unmarshal(body, &apiErr); err != nil {
return nil, zbxerr.ErrorCannotUnmarshalJSON.Wrap(err)
return nil, zbxerr.New(apiErr.Message)