/****************************************************************************** * * * 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); }
/****************************************************************************** * * * Function: is_master_node * * * * Purpose: * * * * Parameters: * * * * Return value: SUCCEED - master_nodeid is a master node of current_nodeid * * FAIL - otherwise * * * * Author: Alexander Vladishev * * * * Comments: * * * ******************************************************************************/ int is_master_node(int current_nodeid, int master_nodeid) { DB_RESULT result; DB_ROW row; int res = FAIL; result = DBselect("select masterid from nodes where nodeid=%d", current_nodeid); if (NULL != (row = DBfetch(result))) { current_nodeid = atoi(row[0]); if (current_nodeid == master_nodeid) res = SUCCEED; else if (0 != current_nodeid) res = is_master_node(current_nodeid, master_nodeid); } DBfree_result(result); return res; }
/****************************************************************************** * * * Function: main_historysender * * * * Purpose: periodically sends historical data to master node * * * * Parameters: * * * * Return value: * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ void main_historysender() { DB_RESULT result; DB_ROW row; int master_nodeid, nodeid; zabbix_log(LOG_LEVEL_DEBUG, "In main_historysender()"); master_nodeid = CONFIG_MASTER_NODEID; if (0 == master_nodeid) return; result = DBselect("select nodeid from nodes"); while ((row = DBfetch(result))) { nodeid = atoi(row[0]); if (SUCCEED == is_master_node(CONFIG_NODEID, nodeid)) continue; process_history_tables(master_nodeid, nodeid); } DBfree_result(result); }