** Copyright (C) 2001-2025 Zabbix SIA
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
** 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 Affero General Public License for more details.
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
"golang.zabbix.com/sdk/log"
"golang.zabbix.com/sdk/zbxerr"
type cephResponse struct {
Outs string `json:"outs"`
Outb string `json:"outb"`
HasFailed bool `json:"has_failed"`
Message string `json:"message"`
// request makes an http request to Ceph RESTful API Module with a given command and extra parameters.
func request(ctx context.Context, client *http.Client, uri, cmd string, args map[string]string) ([]byte, error) {
params := map[string]string{
requestBody, err := json.Marshal(params)
return nil, zbxerr.ErrorCannotMarshalJSON.Wrap(err)
req, err := http.NewRequestWithContext(ctx, "POST", uri+"/request?wait=1", bytes.NewBuffer(requestBody))
return nil, zbxerr.New(err.Error())
req.Header.Set("Content-Type", "application/json")
req.Header.Add("User-Agent", "zbx_monitor")
res, err := client.Do(req)
return nil, zbxerr.ErrorCannotFetchData.Wrap(err)
err = json.NewDecoder(res.Body).Decode(&resp)
return nil, zbxerr.ErrorCannotUnmarshalJSON.Wrap(err)
if len(resp.Failed) == 0 {
return nil, zbxerr.ErrorCannotParseResult
return nil, zbxerr.New(resp.Failed[0].Outs)
if len(resp.Message) > 0 {
return nil, zbxerr.New(resp.Message)
log.Debugf("Response = %+v", resp)
if len(resp.Finished) == 0 {
return nil, zbxerr.ErrorEmptyResult