/****************************************************************************** * * * Function: filter_evaluate_or * * * * Purpose: check if the lld data passes filter evaluation by or rule * * * * Parameters: filter - [IN] the lld filter * * jp_row - [IN] the lld data row * * * * Return value: SUCCEED - the lld data passed filter evaluation * * FAIL - otherwise * * * ******************************************************************************/ static int filter_evaluate_or(lld_filter_t *filter, struct zbx_json_parse *jp_row) { const char *__function_name = "filter_evaluate_or"; int i, ret = SUCCEED; char *value = NULL; size_t value_alloc = 0; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); for (i = 0; i < filter->conditions.values_num; i++) { lld_condition_t *condition = (lld_condition_t *)filter->conditions.values[i]; if (SUCCEED == (ret = zbx_json_value_by_name_dyn(jp_row, condition->macro, &value, &value_alloc))) { ret = (ZBX_REGEXP_MATCH == regexp_match_ex(&condition->regexps, value, condition->regexp, ZBX_CASE_SENSITIVE) ? SUCCEED : FAIL); } /* if any of conditions are true the evaluation returns true */ if (SUCCEED == ret) break; } zbx_free(value); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: get_value_db * * * * Purpose: retrieve data from database * * * * Parameters: item - item we are interested in * * * * Return value: SUCCEED - data successfully retrieved and stored in result * * NOTSUPPORTED - requested item is not supported * * * * Author: Eugene Grigorjev * * * ******************************************************************************/ int get_value_db(DC_ITEM *item, AGENT_RESULT *result) { const char *__function_name = "get_value_db"; AGENT_REQUEST request; int ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "In %s() key_orig:'%s'", __function_name, item->key_orig); init_request(&request); if (SUCCEED == parse_item_key(item->key, &request)) { if (0 == strcmp(request.key, "db.odbc.select")) ret = db_odbc_select(item, &request, result); else if (0 == strcmp(request.key, "db.odbc.discovery")) ret = db_odbc_discovery(item, &request, result); else SET_MSG_RESULT(result, zbx_strdup(NULL, "Unsupported item key for this item type.")); } else SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid item parameter format.")); free_request(&request); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
static void read_ipmi_control(zbx_ipmi_host_t *h, zbx_ipmi_control_t *c) { const char *__function_name = "read_ipmi_control"; int ret; struct timeval tv; zabbix_log(LOG_LEVEL_DEBUG, "In %s() control:'%s@[%s]:%d'", __function_name, c->c_name, h->ip, h->port); if (0 == ipmi_control_is_readable(c->control)) { h->err = zbx_dsprintf(h->err, "control is not readable"); h->ret = NOTSUPPORTED; goto out; } h->ret = SUCCEED; h->done = 0; if (0 != (ret = ipmi_control_get_val(c->control, got_control_reading, h))) { h->err = zbx_dsprintf(h->err, "Cannot read control %s. ipmi_control_get_val() return error: 0x%x", c->c_name, ret); h->ret = NOTSUPPORTED; goto out; } tv.tv_sec = 10; tv.tv_usec = 0; while (0 == h->done) os_hnd->perform_one_op(os_hnd, &tv); out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(h->ret)); }
static int check_script_permissions(zbx_uint64_t groupid, zbx_uint64_t hostid, char *error, size_t max_error_len) { const char *__function_name = "check_script_permissions"; DB_RESULT result; int ret = SUCCEED; zabbix_log(LOG_LEVEL_DEBUG, "In %s() groupid:" ZBX_FS_UI64 " hostid:" ZBX_FS_UI64, __function_name, groupid, hostid); if (0 == groupid) goto exit; result = DBselect( "select hostid" " from hosts_groups" " where hostid=" ZBX_FS_UI64 " and groupid=" ZBX_FS_UI64, hostid, groupid); if (NULL == DBfetch(result)) { zbx_strlcpy(error, "Insufficient permissions. Host is not in an allowed host group.", max_error_len); ret = FAIL; } DBfree_result(result); exit: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
int telnet_test_login(ZBX_SOCKET socket_fd) { const char *__function_name = "telnet_test_login"; char buf[MAX_BUFFER_LEN]; size_t sz, offset; int rc, ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); sz = sizeof(buf); offset = 0; while (ZBX_TCP_ERROR != (rc = telnet_read(socket_fd, buf, &sz, &offset))) { if (':' == telnet_lastchar(buf, offset)) break; } convert_telnet_to_unix_eol(buf, &offset); zabbix_log(LOG_LEVEL_DEBUG, "%s() login prompt:'%.*s'", __function_name, offset, buf); if (ZBX_TCP_ERROR != rc) ret = SUCCEED; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/* * Example: telnet.run["ls /"] */ static int telnet_run(DC_ITEM *item, AGENT_RESULT *result, const char *encoding) { const char *__function_name = "telnet_run"; zbx_sock_t s; int ret = NOTSUPPORTED, flags; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (FAIL == zbx_tcp_connect(&s, CONFIG_SOURCE_IP, item->interface.addr, item->interface.port, 0)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "cannot connect to TELNET server: %s", zbx_tcp_strerror())); goto close; } flags = fcntl(s.socket, F_GETFL); if (0 == (flags & O_NONBLOCK)) fcntl(s.socket, F_SETFL, flags | O_NONBLOCK); if (FAIL == telnet_login(s.socket, item->username, item->password, result)) goto tcp_close; if (FAIL == telnet_execute(s.socket, item->params, result, encoding)) goto tcp_close; ret = SUCCEED; tcp_close: zbx_tcp_close(&s); close: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/* finalize eventlog6 and free the handles */ int finalize_eventlog6(EVT_HANDLE *render_context, EVT_HANDLE *query) { const char *__function_name = "finalize_eventlog6"; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (NULL != *query) { EvtClose(*query); *query = NULL; } if (NULL != *render_context) { EvtClose(*render_context); *render_context = NULL; } ret = SUCCEED; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: zbx_send_response * * * * Purpose: send json SUCCEED or FAIL to socket along with an info message * * * * Parameters: sock - [IN] socket descriptor * * result - [IN] SUCCEED or FAIL * * info - [IN] info message * * timeout - [IN] timeout for this operation * * * * Return value: SUCCEED - data successfully transmited * * NETWORK_ERROR - network related error occurred * * * * Author: Alexander Vladishev, Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ int zbx_send_response_ext(zbx_socket_t *sock, int result, const char *info, int protocol, int timeout) { const char *__function_name = "zbx_send_response"; struct zbx_json json; const char *resp; int ret = SUCCEED; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN); resp = SUCCEED == result ? ZBX_PROTO_VALUE_SUCCESS : ZBX_PROTO_VALUE_FAILED; zbx_json_addstring(&json, ZBX_PROTO_TAG_RESPONSE, resp, ZBX_JSON_TYPE_STRING); if (NULL != info && '\0' != *info) zbx_json_addstring(&json, ZBX_PROTO_TAG_INFO, info, ZBX_JSON_TYPE_STRING); zabbix_log(LOG_LEVEL_DEBUG, "%s() '%s'", __function_name, json.buffer); if (FAIL == (ret = zbx_tcp_send_ext(sock, json.buffer, strlen(json.buffer), protocol, timeout))) { zabbix_log(LOG_LEVEL_DEBUG, "Error sending result back: %s", zbx_socket_strerror()); ret = NETWORK_ERROR; } zbx_json_free(&json); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: put_data_to_server * * * * Purpose: send data from server * * * * Parameters: * * * * Return value: SUCCESS - processed succesfully * * FAIL - an error occured * * * * Author: Alksander Vladishev * * * * Comments: * * * ******************************************************************************/ int put_data_to_server(zbx_sock_t *sock, struct zbx_json *j) { struct zbx_json_parse jp; int ret = FAIL; char *answer, value[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In put_data_to_server() [datalen:%zd]", j->buffer_size); if (FAIL == send_data_to_server(sock, j->buffer)) goto exit; if (FAIL == recv_data_from_server(sock, &answer)) goto exit; if (FAIL == zbx_json_open(answer, &jp)) goto exit; if (FAIL == zbx_json_value_by_name(&jp, ZBX_PROTO_TAG_RESPONSE, value, sizeof(value))) goto exit; if (0 != strcmp(value, ZBX_PROTO_VALUE_SUCCESS)) goto exit; ret = SUCCEED; exit: zabbix_log(LOG_LEVEL_DEBUG, "End of put_data_to_server():%s", zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: zbx_proc_get_processes * * * * Purpose: get system processes * * * * Parameters: processes - [OUT] the system processes * * flags - [IN] the flags specifying the process properties * * that must be returned * * * * Return value: SUCCEED - the system processes were retrieved successfully * * FAIL - failed to open /proc directory * * * ******************************************************************************/ int zbx_proc_get_processes(zbx_vector_ptr_t *processes, unsigned int flags) { const char *__function_name = "zbx_proc_get_processes"; DIR *dir; struct dirent *entries; int ret = FAIL, pid; zbx_sysinfo_proc_t *proc; zabbix_log(LOG_LEVEL_TRACE, "In %s()", __function_name); if (NULL == (dir = opendir("/proc"))) goto out; while (NULL != (entries = readdir(dir))) { /* skip entries not containing pids */ if (FAIL == is_uint32(entries->d_name, &pid)) continue; if (NULL == (proc = proc_create(pid, flags))) continue; zbx_vector_ptr_append(processes, proc); } closedir(dir); ret = SUCCEED; out: zabbix_log(LOG_LEVEL_TRACE, "End of %s(): %s, processes:%d", __function_name, zbx_result_string(ret), processes->values_num); return ret; }
/****************************************************************************** * * * Function: get_perf_counter_value * * * * Purpose: gets average value of the specified performance counter interval * * * * Parameters: counter - [IN] the performance counter * * interval - [IN] the data collection interval in seconds * * value - [OUT] the calculated value * * error - [OUT] the error message * * * * Returns: SUCCEED - the value was retrieved successfully * * FAIL - otherwise * * * ******************************************************************************/ int get_perf_counter_value(PERF_COUNTER_DATA *counter, int interval, double *value, char **error) { const char *__function_name = "get_perf_counter_value"; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s() path:%s interval:%d", __function_name, counter->counterpath, interval); LOCK_PERFCOUNTERS; if (SUCCEED != perf_collector_started()) { *error = zbx_strdup(*error, "Performance collector is not started."); goto out; } if (PERF_COUNTER_ACTIVE != counter->status) { *error = zbx_strdup(*error, "Performance counter is not ready."); goto out; } *value = compute_average_value(counter, interval); ret = SUCCEED; out: UNLOCK_PERFCOUNTERS; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
static int close_inactive_host(zbx_ipmi_host_t *h) { const char *__function_name = "close_inactive_host"; char domain_name[11]; /* max int length */ struct timeval tv; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s(): %s", __function_name, h->ip); zbx_snprintf(domain_name, sizeof(domain_name), "%d", h->domain_id); ipmi_domain_iterate_domains(domains_iterate_cb, domain_name); h->done = 0; domain_close_ok = 0; ipmi_domain_pointer_cb(domain_id_ptr, domain_close_cb, h); if (1 == domain_close_ok) { tv.tv_sec = 10; tv.tv_usec = 0; while (0 == h->done) os_hnd->perform_one_op(os_hnd, &tv); free_ipmi_connection(h); ret = SUCCEED; } zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
int init_ipmi_handler(void) { const char *__function_name = "init_ipmi_handler"; int res, ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (NULL == (os_hnd = ipmi_posix_setup_os_handler())) { zabbix_log(LOG_LEVEL_WARNING, "unable to allocate IPMI handler"); goto out; } os_hnd->set_log_handler(os_hnd, my_vlog); if (0 != (res = ipmi_init(os_hnd))) { zabbix_log(LOG_LEVEL_WARNING, "unable to initialize the OpenIPMI library." " ipmi_init() return error: 0x%x", res); goto out; } ret = SUCCEED; out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: check_action_condition * * * * Purpose: check if event matches single condition * * * * Parameters: event - event to check * * condition - condition for matching * * * * Return value: SUCCEED - matches, FAIL - otherwise * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) { const char *__function_name = "check_action_condition"; int ret; zabbix_log(LOG_LEVEL_DEBUG, "In %s() actionid:" ZBX_FS_UI64 " conditionid:" ZBX_FS_UI64 " cond.value:'%s'", __function_name, condition->actionid, condition->conditionid, condition->value); switch (event->source) { case EVENT_SOURCE_TRIGGERS: ret = check_trigger_condition(event, condition); break; case EVENT_SOURCE_DISCOVERY: ret = check_discovery_condition(event, condition); break; case EVENT_SOURCE_AUTO_REGISTRATION: ret = check_auto_registration_condition(event, condition); break; default: zabbix_log(LOG_LEVEL_ERR, "Unsupported event source [%d] for condition id [" ZBX_FS_UI64 "]", event->source, condition->conditionid); ret = FAIL; } zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: get_data_from_server * * * * Purpose: get configuration and other data from server * * * * Parameters: * * * * Return value: SUCCESS - processed successfully * * FAIL - an error occurred * * * * Author: Alexander Vladishev * * * * Comments: * * * ******************************************************************************/ int get_data_from_server(zbx_sock_t *sock, const char *request) { const char *__function_name = "get_data_from_server"; int ret = FAIL; struct zbx_json j; zabbix_log(LOG_LEVEL_DEBUG, "In %s() request:'%s'", __function_name, request); zbx_json_init(&j, 128); zbx_json_addstring(&j, "request", request, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&j, "host", CONFIG_HOSTNAME, ZBX_JSON_TYPE_STRING); if (FAIL == send_data_to_server(sock, j.buffer)) goto exit; if (FAIL == recv_data_from_server(sock)) goto exit; ret = SUCCEED; exit: zbx_json_free(&j); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: check_response * * * * Purpose: Check whether JSON response is SUCCEED * * * * Parameters: JSON response from Zabbix trapper * * * * Return value: SUCCEED - processed successfully * * FAIL - an error occurred * * * * Author: Alexei Vladishev * * * * Comments: zabbix_sender has almost the same function! * * * ******************************************************************************/ static int check_response(char *response) { const char *__function_name = "check_response"; struct zbx_json_parse jp; char value[MAX_STRING_LEN]; char info[MAX_STRING_LEN]; int ret = SUCCEED; zabbix_log(LOG_LEVEL_DEBUG, "In %s() response:'%s'", __function_name, response); ret = zbx_json_open(response, &jp); if (SUCCEED == ret) ret = zbx_json_value_by_name(&jp, ZBX_PROTO_TAG_RESPONSE, value, sizeof(value)); if (SUCCEED == ret && 0 != strcmp(value, ZBX_PROTO_VALUE_SUCCESS)) ret = FAIL; if (SUCCEED == ret && SUCCEED == zbx_json_value_by_name(&jp, ZBX_PROTO_TAG_INFO, info, sizeof(info))) zabbix_log(LOG_LEVEL_DEBUG, "info from server: '%s'", info); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: put_data_to_server * * * * Purpose: send data to server * * * * Parameters: * * * * Return value: SUCCESS - processed successfully * * FAIL - an error occurred * * * * Author: Alexander Vladishev * * * * Comments: * * * ******************************************************************************/ int put_data_to_server(zbx_sock_t *sock, struct zbx_json *j, char **error) { const char *__function_name = "put_data_to_server"; char *info = NULL, *err = NULL; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s() datalen:" ZBX_FS_SIZE_T, __function_name, (zbx_fs_size_t)j->buffer_size); if (SUCCEED != send_data_to_server(sock, j->buffer)) goto out; if (SUCCEED != zbx_recv_response(sock, &info, 0, &err)) { *error = zbx_dsprintf(*error, "error:\"%s\", info:\"%s\"", ZBX_NULL2EMPTY_STR(err), ZBX_NULL2EMPTY_STR(info)); goto out; } ret = SUCCEED; out: zbx_free(info); zbx_free(err); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
static int cache_get_snmp_index(DC_ITEM *item, char *oid, char *value, int *index) { const char *__function_name = "cache_get_snmp_index"; int i, res = FAIL; zbx_snmp_index_t s; assert(index); *index = 0; zabbix_log(LOG_LEVEL_DEBUG, "In %s() oid:'%s' value:'%s'", __function_name, oid, value); if (NULL == snmpidx) goto end; s.hostid = item->host.hostid; s.port = item->interface.port; s.oid = oid; s.value = value; if (snmpidx_count > (i = get_snmpidx_nearestindex(&s)) && 0 == zbx_snmp_index_compare(&s, &snmpidx[i])) { *index = snmpidx[i].index; res = SUCCEED; } end: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s index:%d", __function_name, zbx_result_string(res), *index); return res; }
/* get handles of eventlog */ static int zbx_get_handle_eventlog6(const wchar_t *wsource, zbx_uint64_t *lastlogsize, EVT_HANDLE *query) { const char *__function_name = "zbx_get_handle_eventlog6"; wchar_t *event_query = NULL; DWORD status = 0; char *tmp_str = NULL; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s(), previous lastlogsize:" ZBX_FS_UI64, __function_name, *lastlogsize); /* start building the query */ tmp_str = zbx_dsprintf(NULL, "Event/System[EventRecordID>" ZBX_FS_UI64 "]", *lastlogsize); event_query = zbx_utf8_to_unicode(tmp_str); /* create massive query for an event on a local computer*/ *query = EvtQuery(NULL, wsource, event_query, EvtQueryChannelPath); if (NULL == *query) { if (ERROR_EVT_CHANNEL_NOT_FOUND == (status = GetLastError())) zabbix_log(LOG_LEVEL_WARNING, "EvtQuery channel missed:%s", strerror_from_system(status)); else zabbix_log(LOG_LEVEL_WARNING, "EvtQuery failed:%s", strerror_from_system(status)); goto out; } ret = SUCCEED; out: zbx_free(tmp_str); zbx_free(event_query); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
int USER_PERF_COUNTER(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; char *counter, *error = NULL; double value; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__); if (1 != request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters.")); goto out; } if (NULL == (counter = get_rparam(request, 0)) || '\0' == *counter) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); goto out; } if (SUCCEED != get_perf_counter_value_by_name(counter, &value, &error)) { SET_MSG_RESULT(result, error != NULL ? error : zbx_strdup(NULL, "Cannot obtain performance information from collector.")); goto out; } SET_DBL_RESULT(result, value); ret = SYSINFO_RET_OK; out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret)); return ret; }
static int DBget_script_by_scriptid(zbx_uint64_t scriptid, zbx_script_t *script, zbx_uint64_t *groupid) { const char *__function_name = "DBget_script_by_scriptid"; DB_RESULT result; DB_ROW row; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); result = DBselect( "select type,execute_on,command,groupid" " from scripts" " where scriptid=" ZBX_FS_UI64, scriptid); if (NULL != (row = DBfetch(result))) { script->type = (unsigned char)atoi(row[0]); script->execute_on = (unsigned char)atoi(row[1]); script->command = zbx_strdup(script->command, row[2]); ZBX_DBROW2UINT64(*groupid, row[3]); ret = SUCCEED; } DBfree_result(result); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
int PERF_COUNTER(AGENT_REQUEST *request, AGENT_RESULT *result) { char counterpath[PDH_MAX_COUNTER_PATH], *tmp, *error = NULL; int interval, ret = SYSINFO_RET_FAIL; double value; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__); if (2 < request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); goto out; } tmp = get_rparam(request, 0); if (NULL == tmp || '\0' == *tmp) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); goto out; } strscpy(counterpath, tmp); if (NULL == (tmp = get_rparam(request, 1)) || '\0' == *tmp) { interval = 1; } else if (FAIL == is_uint31(tmp, &interval)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); goto out; } if (1 > interval || MAX_COLLECTOR_PERIOD < interval) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Interval out of range.")); goto out; } if (FAIL == check_counter_path(counterpath)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid performance counter path.")); goto out; } if (SUCCEED != get_perf_counter_value_by_path(counterpath, interval, &value, &error)) { SET_MSG_RESULT(result, error != NULL ? error : zbx_strdup(NULL, "Cannot obtain performance information from collector.")); goto out; } ret = SYSINFO_RET_OK; SET_DBL_RESULT(result, value); out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret)); return ret; }
static int zbx_execute_script_on_agent(DC_HOST *host, const char *command, char **result, char *error, size_t max_error_len) { const char *__function_name = "zbx_execute_script_on_agent"; int ret; AGENT_RESULT agent_result; char *param, *port = NULL; DC_ITEM item; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); *error = '\0'; memset(&item, 0, sizeof(item)); memcpy(&item.host, host, sizeof(item.host)); if (SUCCEED != (ret = DCconfig_get_interface_by_type(&item.interface, host->hostid, INTERFACE_TYPE_AGENT))) { zbx_snprintf(error, max_error_len, "Whatap agent interface is not defined for host [%s]", host->host); goto fail; } port = zbx_strdup(port, item.interface.port_orig); substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL, &port, MACRO_TYPE_COMMON, NULL, 0); if (SUCCEED != (ret = is_ushort(port, &item.interface.port))) { zbx_snprintf(error, max_error_len, "Invalid port number [%s]", item.interface.port_orig); goto fail; } param = zbx_dyn_escape_string(command, "\""); item.key = zbx_dsprintf(item.key, "system.run[\"%s\",\"%s\"]", param, NULL == result ? "nowait" : "wait"); item.value_type = ITEM_VALUE_TYPE_TEXT; zbx_free(param); init_result(&agent_result); alarm(CONFIG_TIMEOUT); if (SUCCEED != (ret = get_value_agent(&item, &agent_result))) { if (ISSET_MSG(&agent_result)) zbx_strlcpy(error, agent_result.msg, max_error_len); ret = FAIL; } else if (NULL != result && ISSET_TEXT(&agent_result)) *result = zbx_strdup(*result, agent_result.text); alarm(0); free_result(&agent_result); zbx_free(item.key); fail: zbx_free(port); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
int init_perf_collector(int multithreaded) { const char *__function_name = "init_perf_collector"; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (0 != multithreaded) { if (ZBX_MUTEX_ERROR == zbx_mutex_create_force(&perfstat_access, ZBX_MUTEX_PERFSTAT)) { zbx_error("cannot create mutex for performance counters"); exit(EXIT_FAILURE); } } if (ERROR_SUCCESS != zbx_PdhOpenQuery(__function_name, &ppsd.pdh_query)) goto out; ppsd.nextcheck = time(NULL) + UNSUPPORTED_REFRESH_PERIOD; ret = SUCCEED; out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: recv_discovery_data * * * * Author: Alexander Vladishev * * * ******************************************************************************/ void recv_discovery_data(zbx_sock_t *sock, struct zbx_json_parse *jp) { const char *__function_name = "recv_discovery_data"; int ret; zbx_uint64_t proxy_hostid; char host[HOST_HOST_LEN_MAX], *error = NULL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (SUCCEED != (ret = get_active_proxy_id(jp, &proxy_hostid, host, &error))) { zabbix_log(LOG_LEVEL_WARNING, "discovery data from active proxy on \"%s\" failed: %s", get_ip_by_socket(sock), error); goto out; } process_dhis_data(jp); out: zbx_send_response(sock, ret, error, CONFIG_TIMEOUT); zbx_free(error); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); }
/****************************************************************************** * * * Function: lld_triggers_equal * * * * Return value: returns SUCCEED if descriptions and expressions of * * the triggers are identical; FAIL - otherwise * * * ******************************************************************************/ static int lld_triggers_equal(zbx_lld_trigger_t *trigger, zbx_lld_trigger_t *trigger_b) { const char *__function_name = "lld_triggers_equal"; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (0 == strcmp(trigger->description, trigger_b->description)) { char *expression, *expression_b; expression = lld_expression_expand(trigger->expression, &trigger->functions); expression_b = lld_expression_expand(trigger_b->expression, &trigger_b->functions); if (0 == strcmp(expression, expression_b)) ret = SUCCEED; zbx_free(expression); zbx_free(expression_b); } zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/* callback function invoked from OpenIPMI */ static void got_control_setting(ipmi_control_t *control, int err, void *cb_data) { const char *__function_name = "got_control_setting"; zbx_ipmi_host_t *h = cb_data; zbx_ipmi_control_t *c; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (0 != err) { zabbix_log(LOG_LEVEL_DEBUG, "%s() fail: %s", __function_name, zbx_strerror(err)); h->err = zbx_dsprintf(h->err, "error 0x%x while set control", err); h->ret = NETWORK_ERROR; h->done = 1; return; } c = get_ipmi_control(h, control); if (NULL == c) { THIS_SHOULD_NEVER_HAPPEN; h->err = zbx_dsprintf(h->err, "fatal error"); h->ret = NOTSUPPORTED; h->done = 1; return; } zabbix_log(LOG_LEVEL_DEBUG, "set value completed for control %s@[%s]:%d", c->c_name, h->ip, h->port); h->done = 1; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(h->ret)); }
/****************************************************************************** * * * Function: register_module * * * * Purpose: Add module to the list of loaded modules (dynamic libraries). * * It skips a module if it is already registered. * * * * Parameters: module - library handler * * * * Return value: SUCCEED - if module is successfully registered * * FAIL - if module is already registered * * * ******************************************************************************/ static int register_module(void *module) { const char *__function_name = "register_module"; int i = 0, ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (NULL == modules) { modules = zbx_malloc(modules, sizeof(void *)); modules[0] = NULL; } while (NULL != modules[i]) { if (module == modules[i]) /* a module is already registered */ goto out; i++; } modules = zbx_realloc(modules, (i + 2) * sizeof(void *)); modules[i] = module; modules[i + 1] = NULL; ret = SUCCEED; out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/* callback function invoked from OpenIPMI */ static void setup_done(ipmi_domain_t *domain, int err, unsigned int conn_num, unsigned int port_num, int still_connected, void *cb_data) { const char *__function_name = "setup_done"; int ret; zbx_ipmi_host_t *h = cb_data; zabbix_log(LOG_LEVEL_DEBUG, "In %s() phost:%p host:'[%s]:%d'", __function_name, h, h->ip, h->port); if (0 != err) { zabbix_log(LOG_LEVEL_DEBUG, "%s() fail: %s", __function_name, zbx_strerror(err)); h->err = zbx_dsprintf(h->err, "cannot connect to IPMI host: %s", zbx_strerror(err)); h->ret = NETWORK_ERROR; if (0 != (ret = ipmi_domain_close(domain, domain_closed, h))) zabbix_log(LOG_LEVEL_DEBUG, "cannot close IPMI domain: [0x%x]", ret); goto out; } if (0 != (ret = ipmi_domain_add_entity_update_handler(domain, entity_change, h))) zabbix_log(LOG_LEVEL_DEBUG, "ipmi_domain_add_entity_update_handler() return error: [0x%x]", ret); out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(h->ret)); }
/****************************************************************************** * * * Function: get_data_from_proxy * * * * Purpose: get historical data from proxy * * * * Parameters: * * * * Return value: SUCCESS - processed successfully * * FAIL - an error occurred * * * * Author: Alexander Vladishev * * * * Comments: * * * ******************************************************************************/ static int get_data_from_proxy(DC_PROXY *proxy, const char *request, char **data) { const char *__function_name = "get_data_from_proxy"; zbx_socket_t s; struct zbx_json j; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s() request:'%s'", __function_name, request); zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); zbx_json_addstring(&j, "request", request, ZBX_JSON_TYPE_STRING); if (SUCCEED == (ret = connect_to_proxy(proxy, &s, CONFIG_TRAPPER_TIMEOUT))) { if (SUCCEED == (ret = send_data_to_proxy(proxy, &s, j.buffer))) if (SUCCEED == (ret = recv_data_from_proxy(proxy, &s))) if (SUCCEED == (ret = zbx_send_response(&s, SUCCEED, NULL, 0))) *data = zbx_strdup(*data, s.buffer); disconnect_proxy(&s); } zbx_json_free(&j); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }