From: Florian G. <re...@us...> - 2007-03-29 22:44:25
|
Update of /cvsroot/perfparse/_perfparse/db_tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3706/db_tools Modified Files: convert.c Log Message: more conversion Index: convert.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/db_tools/convert.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** convert.c 26 Mar 2007 22:26:45 -0000 1.22 --- convert.c 29 Mar 2007 22:44:23 -0000 1.23 *************** *** 67,70 **** --- 67,106 ---- char *read_string_from_line(char *buf, size_t length, const char* defaultval); int read_int_from_line(int defaultval); + void init_caches(void); + int get_policyId_from_name(const char *policy_name, MYSQL *db_mysql_new); + + + // global caches. Translates names to id (e.g. host_name to host_id) + GHashTable *policiesCache=NULL; + GHashTable *groupsCache=NULL; + GHashTable *hostsCache=NULL; + + void init_caches(void) { + policiesCache=g_hash_table_new(g_str_hash,g_str_equal); + groupsCache=g_hash_table_new(g_str_hash,g_str_equal); + hostsCache=g_hash_table_new(g_str_hash,g_str_equal); + } + + int get_policyId_from_name(const char *policy_name, MYSQL *p_db_mysql_new) { + int *pPid; + int Pid; + + if((pPid=g_hash_table_lookup(policiesCache,policy_name))) { + Pid=*pPid; + return(Pid); + } else { + MYSQL_RES *query_result_new = NULL; + MYSQL_ROW result_row_new; + GString *gsNDBSql; + gsNDBSql = g_string_new (""); + g_string_printf(gsNDBSql, "select policy_id from perfdata_delete_policy where policy_name='%s')",policy_name); + dbtool_mysql_query(gsNDBSql->str, p_db_mysql_new, query_result_new); + if((result_row_new=mysql_fetch_row(query_result_new))) { + return(atoi(result_row_new[0])); + } else { + return(FALSE); + } + } + } void *************** *** 150,153 **** --- 186,192 ---- // ncurses variables int iNCrows, iNCcols; + + // init cache tables + init_caches(); // init ncurses *************** *** 354,366 **** iStep++; printw(_("(Step %d of %d)\n"),iStep,iNumSteps); ! printw(_("Copying data of perfdata_host table.\n")); refresh(); ! g_string_printf(gsODBSql, "select * from perfdata_host"); query_result_old=dbtool_mysql_query(gsODBSql->str, &db_mysql_old,query_result_old); - if((iODBnumFields=mysql_num_fields(query_result_old))!=10) { - printw(_("Original perfdata_host table modified! Bailing out")); - exit(EXIT_FAILURE); - } iODBnumrows=dbtool_rows(query_result_old); printw("Affected rows: %d\n",iODBnumrows); --- 393,401 ---- iStep++; printw(_("(Step %d of %d)\n"),iStep,iNumSteps); ! printw(_("Copying data of perfdata_delete_policy table.\n")); refresh(); ! g_string_printf(gsODBSql, "select policy_name,delete_policy from perfdata_delete_policy"); query_result_old=dbtool_mysql_query(gsODBSql->str, &db_mysql_old,query_result_old); iODBnumrows=dbtool_rows(query_result_old); printw("Affected rows: %d\n",iODBnumrows); *************** *** 372,375 **** --- 407,448 ---- piODBlengths=mysql_fetch_lengths(query_result_old); printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); + g_string_printf(gsNDBSql, \ + "insert ignore into perfdata_delete_policy(policy_name,delete_policy_seconds) values ('%.*s',%d)",\ + (int) piODBlengths[0],result_row_old[0],atoi(result_row_old[1])*86400); // convert days to seconds + dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); + } + printw(_("\ndone\n")); refresh(); + + // Step 3 + iStep++; + printw(_("(Step %d of %d)\n"),iStep,iNumSteps); + printw(_("Copying data of perfdata_host table.\n")); + refresh(); + + g_string_printf(gsODBSql, "select host_name,group_name,raw_delete_policy,raw_delete_policy_name,raw_delete_policy_type,bin_delete_policy,bin_delete_policy_name,bin_delete_policy_type,is_deleted from perfdata_host"); + query_result_old=dbtool_mysql_query(gsODBSql->str, &db_mysql_old,query_result_old); + iODBnumrows=dbtool_rows(query_result_old); + printw("Affected rows: %d\n",iODBnumrows);refresh(); + getyx(stdscr,y,x); + i=0; + + + while ((result_row_old=mysql_fetch_row(query_result_old))) { + i++; + int iRawPolicyId=-1,iBinPolicyId=-1; + move(y,x); + piODBlengths=mysql_fetch_lengths(query_result_old); + printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); + // get raw delete policy id if template + if(strncmp(result_row_old[4],"user",4)!=0) { + iRawPolicyId=get_policyId_from_name(result_row_old[3],&db_mysql_new); + // debug + // printw("Raw Policy Id: %d",iRawPolicyId); + } + if(strncmp(result_row_old[7],"user",4)!=0) { + iBinPolicyId=get_policyId_from_name(result_row_old[6],&db_mysql_new); + } + + g_string_printf(gsNDBSql, "insert into perfdata_host"); //g_string_printf(gsNDBSql, ""); // todo: copy policies, host info and popuplate perfdata_host_groups //dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); *************** *** 526,530 **** } ! printf (_("Conversions complete.\n")); } --- 599,603 ---- } ! printw (_("Conversions complete.\n")); } |