Source
xxxxxxxxxx
/*
** 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/>.
**/
/******************************************************************************
* *
* Purpose: expands user macros in IPMI port value and converts result to *
* unsigned short value *
* *
* Parameters: hostid - [IN] *
* port_orig - [IN] original port value *
* port - [OUT] resulting port value *
* error - [OUT] *
* *
* Return value: SUCCEED - value was converted successfully *
* FAIL - otherwise *
* *
******************************************************************************/
int zbx_ipmi_port_expand_macros(zbx_uint64_t hostid, const char *port_orig, unsigned short *port, char **error)
{
char *tmp = zbx_strdup(NULL, port_orig);
int ret = SUCCEED;
zbx_substitute_simple_macros(NULL, NULL, NULL, NULL, &hostid, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&tmp, ZBX_MACRO_TYPE_COMMON, NULL, 0);
if (FAIL == zbx_is_ushort(tmp, port) || 0 == *port)
{
*error = zbx_dsprintf(*error, "Invalid port value \"%s\"", port_orig);
ret = FAIL;
}
zbx_free(tmp);
return ret;
}
/******************************************************************************
* *
* Purpose: executes IPMI command *
* *
* Parameters: host - [IN] target host *
* command - [IN] command to execute *
* error - [OUT] error message buffer *
* max_error_len - [IN] size of error message buffer *
* *
* Return value: SUCCEED - command was executed successfully *
* FAIL - otherwise *
* *
******************************************************************************/
int zbx_ipmi_execute_command(const zbx_dc_host_t *host, const char *command, char *error, size_t max_error_len)
{
zbx_ipc_socket_t ipmi_socket;
zbx_ipc_message_t message;
char *errmsg = NULL, sensor[ZBX_ITEM_IPMI_SENSOR_LEN_MAX], *value = NULL;
zbx_uint32_t data_len;
unsigned char *data = NULL;
int ret = FAIL, op;
zbx_dc_interface_t interface;
zbx_timespec_t ts;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() host:\"%s\" command:%s", __func__, host->host, command);
if (SUCCEED != zbx_parse_ipmi_command(command, sensor, &op, error, max_error_len))