** 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 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.
"golang.zabbix.com/sdk/errs"
"golang.zabbix.com/sdk/zbxerr"
func tablespacesHandler(ctx context.Context, conn OraClient, params map[string]string,
_ ...string) (interface{}, error) {
query, args, err := getTablespacesQuery(params)
return nil, errs.Wrap(err, "failed to retrieve tablespace query")
row, err := conn.QueryRow(ctx, query, args...)
return nil, errs.WrapConst(err, zbxerr.ErrorCannotFetchData)
err = row.Scan(&tablespaces)
return nil, errs.WrapConst(err, zbxerr.ErrorCannotFetchData)
// Add leading zeros for floats: ".03" -> "0.03".
// Oracle JSON functions are not RFC 4627 compliant.
// There should be a better way to do that, but I haven't come up with it ¯\_(ツ)_/¯
tablespaces = strings.ReplaceAll(tablespaces, "\":.", "\":0.")
func getTablespacesQuery(params map[string]string) (string, []any, error) {
ts := params["Tablespace"]
return getFullQuery(), nil, nil
ts, t, err = prepValues(ts, t)
return "", nil, errs.WrapConst(err, zbxerr.ErrorInvalidParams)
return getPermQueryPart(), []any{ts}, nil
return getTempQueryPart(), []any{ts}, nil
return "", nil, errs.Wrapf(zbxerr.ErrorInvalidParams, "incorrect table-space type %s", t)
func prepValues(ts, t string) (outTableSpace string, outType string, err error) {