/****************************************************************************** * * * Function: DMget_config_data * * * * Purpose: get configuration changes to required node * * * * Parameters: * * * * Return value: SUCCESS - processed successfully * * FAIL - an error occurred * * * * Author: Alexander Vladishev * * * * Comments: * * * ******************************************************************************/ char *DMget_config_data(int nodeid, unsigned char dest_nodetype) { const char *__function_name = "DMget_config_data"; char *ptbls = NULL; /* list of processed tables */ size_t ptbls_alloc = ZBX_KIBIBYTE, ptbls_offset = 0; char *data = NULL; size_t data_alloc = ZBX_KIBIBYTE, data_offset = 0; int t; zabbix_log(LOG_LEVEL_DEBUG, "In %s() node:%d dest_nodetype:%s", __function_name, nodeid, zbx_nodetype_string(dest_nodetype)); ptbls = zbx_malloc(ptbls, ptbls_alloc); data = zbx_malloc(data, data_alloc); *ptbls = '\0'; zbx_snprintf_alloc(&data, &data_alloc, &data_offset, "Data%c%d%c%d", ZBX_DM_DELIMITER, CONFIG_NODEID, ZBX_DM_DELIMITER, nodeid); for (t = 0; NULL != tables[t].table; t++) { if (0 == (tables[t].flags & ZBX_SYNC)) continue; DMget_table_data(nodeid, dest_nodetype, &tables[t], &data, &data_alloc, &data_offset, &ptbls, &ptbls_alloc, &ptbls_offset); } zbx_free(ptbls); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return data; }
/****************************************************************************** * * * Function: node_sync * * * * Purpose: process configuration changes received from a node * * * * Parameters: * * * * Return value: SUCCEED - processed successfully * * FAIL - an error occurred * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ int node_sync(char *data, int *sender_nodeid, int *nodeid) { const char *r; char *lf; int datalen, res = SUCCEED; unsigned char sender_nodetype; datalen = strlen(data); zabbix_log(LOG_LEVEL_DEBUG, "In node_sync() len:%d", datalen); tmp = zbx_malloc(tmp, tmp_alloc); if (NULL != (lf = strchr(data, '\n'))) *lf = '\0'; r = data; zbx_get_next_field(&r, &tmp, &tmp_alloc, ZBX_DM_DELIMITER); /* Data */ zbx_get_next_field(&r, &tmp, &tmp_alloc, ZBX_DM_DELIMITER); *sender_nodeid = atoi(tmp); sender_nodetype = (*sender_nodeid == CONFIG_MASTER_NODEID) ? ZBX_NODE_MASTER : ZBX_NODE_SLAVE; zbx_get_next_field(&r, &tmp, &tmp_alloc, ZBX_DM_DELIMITER); *nodeid = atoi(tmp); if (0 != *sender_nodeid && 0 != *nodeid) { if (CONFIG_MASTER_NODEID != *sender_nodeid && FAIL == is_direct_slave_node(*sender_nodeid)) { zabbix_log(LOG_LEVEL_ERR, "NODE %d: Received configuration changes from unknown node %d", CONFIG_NODEID, *sender_nodeid); res = FAIL; goto quit; } if (CONFIG_MASTER_NODEID != *sender_nodeid && CONFIG_NODEID == *nodeid) { zabbix_log(LOG_LEVEL_ERR, "NODE %d: Received configuration changes for this node from a non-master node %d", CONFIG_NODEID, *sender_nodeid); res = FAIL; goto quit; } if (CONFIG_NODEID != *nodeid && FAIL == is_slave_node(CONFIG_NODEID, *nodeid)) { zabbix_log(LOG_LEVEL_ERR, "NODE %d: Received configuration changes for unknown node %d", CONFIG_NODEID, *nodeid); res = FAIL; goto quit; } zabbix_log(LOG_LEVEL_WARNING, "NODE %d: Received configuration changes from %s node %d for node %d datalen %d", CONFIG_NODEID, zbx_nodetype_string(sender_nodetype), *sender_nodeid, *nodeid, datalen); DBexecute("delete from node_cksum where nodeid=%d and cksumtype=%d", *nodeid, NODE_CKSUM_TYPE_NEW); if (lf != NULL) { *lf++ = '\n'; data = lf; buf = zbx_malloc(buf, buf_alloc); process_updated_records(*nodeid, data); process_deleted_records(*nodeid, data); process_checksum(*nodeid, data, sender_nodetype); zbx_free(buf); } } quit: zbx_free(tmp); return res; }