示例#1
0
文件: history.c 项目: rennhak/zabbix
/******************************************************************************
 *                                                                            *
 * Function: get_history_lastid:                                              *
 *                                                                            *
 * Purpose: get last history id from master node                              *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              * 
 *                                                                            *
 * Author: Aleksander Vladishev                                               *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int get_history_lastid(int master_nodeid, int nodeid, ZBX_TABLE *table, zbx_uint64_t *lastid)
{
	zbx_sock_t	sock;
	char		data[MAX_STRING_LEN], *answer;
	int		res = FAIL;

	zabbix_log(LOG_LEVEL_DEBUG, "In get_history_lastid()");

	if (SUCCEED == connect_to_node(master_nodeid, &sock)) {
		zbx_snprintf(data, sizeof(data), "ZBX_GET_HISTORY_LAST_ID%c%d%c%d\n%s%c%s",
			ZBX_DM_DELIMITER, CONFIG_NODEID,
			ZBX_DM_DELIMITER, nodeid,
			table->table, ZBX_DM_DELIMITER, table->recid);

		if (FAIL == send_data_to_node(master_nodeid, &sock, data))
			goto disconnect;

		if (FAIL == recv_data_from_node(master_nodeid, &sock, &answer))
			goto disconnect;

		if (0 == strncmp(answer, "FAIL", 4)) {
			zabbix_log( LOG_LEVEL_ERR, "NODE %d: get_history_lastid() FAIL from node %d for node %d",
				CONFIG_NODEID,
				master_nodeid,
				nodeid);
			goto disconnect;
		}

		ZBX_STR2UINT64(*lastid, answer);
		res = SUCCEED;
disconnect:
		disconnect_node(&sock);
	}
	return res;
}
示例#2
0
/******************************************************************************
 *                                                                            *
 * Function: send_to_node                                                     *
 *                                                                            *
 * Purpose: send configuration changes to required node                       *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value: SUCCESS - processed successfully                             *
 *               FAIL - an error occurred                                     *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int send_to_node(const char *name, int dest_nodeid, int nodeid, char *data)
{
	int		ret = FAIL;
	zbx_sock_t	sock;
	char		*answer;

	zabbix_log(LOG_LEVEL_WARNING, "NODE %d: Sending %s of node %d to node %d datalen " ZBX_FS_SIZE_T,
			CONFIG_NODEID, name, nodeid, dest_nodeid, (zbx_fs_size_t)strlen(data));

	if (FAIL == connect_to_node(dest_nodeid, &sock))
		return FAIL;

	if (FAIL == send_data_to_node(dest_nodeid, &sock, data))
		goto disconnect;

	if (FAIL == recv_data_from_node(dest_nodeid, &sock, &answer))
		goto disconnect;

	if (0 == strcmp(answer, "OK"))
	{
		zabbix_log( LOG_LEVEL_DEBUG, "OK");
		ret = SUCCEED;
	}
	else
	{
		zabbix_log( LOG_LEVEL_WARNING, "NOT OK");
	}
disconnect:
	disconnect_node(&sock);

	return ret;
}
示例#3
0
/******************************************************************************
 *                                                                            *
 * Function: process_nodes                                                    *
 *                                                                            *
 * Purpose: calculates checksums of config data                               *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
void process_nodes()
{
	DB_RESULT	result;
	DB_ROW		row;
	int		nodeid;
	int		master_nodeid;
	char		*data, *answer;
	zbx_sock_t	sock;
	int		res;
	int		sender_nodeid;

	master_nodeid = CONFIG_MASTER_NODEID;
	if (0 == master_nodeid)
		return;

	result = DBselect("select nodeid from nodes");
	while (NULL != (row=DBfetch(result))) {
		nodeid = atoi(row[0]);
		if (SUCCEED == is_master_node(CONFIG_NODEID, nodeid))
			continue;

		node_sync_lock(nodeid);

/*		DBbegin();*/

		res = calculate_checksums(nodeid, NULL, 0);
		if (SUCCEED == res && NULL != (data = get_config_data(nodeid, ZBX_NODE_MASTER))) {
			zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Sending configuration changes to master node %d for node %d datalen %d",
				CONFIG_NODEID,
				master_nodeid,
				nodeid,
				strlen(data));
			if (SUCCEED == (res = connect_to_node(master_nodeid, &sock))) {
				if (SUCCEED == res)
					res = send_data_to_node(master_nodeid, &sock, data);
				if (SUCCEED == res)
					res = recv_data_from_node(master_nodeid, &sock, &answer);
				if (SUCCEED == res && 0 == strncmp(answer, "Data", 4)) {
					res = update_checksums(nodeid, ZBX_NODE_MASTER, SUCCEED, NULL, 0, NULL);
					if (SUCCEED == res)
						res = node_sync(answer, &sender_nodeid, &nodeid);
					send_data_to_node(master_nodeid, &sock, SUCCEED == res ? "OK" : "FAIL");
				}
				disconnect_node(&sock);
			}
			zbx_free(data);
		}

/*		DBcommit();*/

		node_sync_unlock(nodeid);
	}
	DBfree_result(result);
}
示例#4
0
GList*
g_list_remove_link (GList *list, GList *link)
{
    if (list == link)
        list = list->next;

    disconnect_node (link);
    link->next = NULL;
    link->prev = NULL;

    return list;
}
示例#5
0
GList*
g_list_remove (GList *list, gconstpointer data)
{
    GList *current = g_list_find (list, data);
    if (!current)
        return list;

    if (current == list)
        list = list->next;
    g_list_free_1 (disconnect_node (current));

    return list;
}
示例#6
0
文件: history.c 项目: rennhak/zabbix
/******************************************************************************
 *                                                                            *
 * Function: get_trends_lastid:                                               *
 *                                                                            *
 * Purpose: get last history lastid and lastclock from master node            *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              * 
 *                                                                            *
 * Author: Aleksander Vladishev                                               *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int get_trends_lastid(int master_nodeid, int nodeid, ZBX_TABLE *table, zbx_uint64_t *lastid, int *lastclock)
{
	zbx_sock_t	sock;
	char		data[MAX_STRING_LEN], *answer, *ptr;
	int		res = FAIL;

	zabbix_log(LOG_LEVEL_DEBUG, "In get_trends_lastclock()");

	if (SUCCEED == connect_to_node(master_nodeid, &sock)) {
		zbx_snprintf(data, sizeof(data), "ZBX_GET_TRENDS_LAST_ID%c%d%c%d\n%s",
			ZBX_DM_DELIMITER, CONFIG_NODEID,
			ZBX_DM_DELIMITER, nodeid,
			table->table);

		if (FAIL == send_data_to_node(master_nodeid, &sock, data))
			goto disconnect;

		if (FAIL == recv_data_from_node(master_nodeid, &sock, &answer))
			goto disconnect;

		if (0 == strncmp(answer, "FAIL", 4)) {
			zabbix_log( LOG_LEVEL_ERR, "NODE %d: get_trends_lastid() FAIL from node %d for node %d",
				CONFIG_NODEID,
				master_nodeid,
				nodeid);
			goto disconnect;
		}

		if (NULL != (ptr = strchr(answer, ZBX_DM_DELIMITER))) {
			*ptr++ = '\0';

			ZBX_STR2UINT64(*lastid, answer);
			*lastclock = atoi(ptr);

			res = SUCCEED;
		}
disconnect:
		disconnect_node(&sock);
	}
	return res;
}