From: Florian G. <re...@us...> - 2007-04-01 22:39:46
|
Update of /cvsroot/perfparse/_perfparse/db_tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11501/db_tools Modified Files: convert.c Log Message: work on conversion Index: convert.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/db_tools/convert.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** convert.c 29 Mar 2007 22:44:23 -0000 1.23 --- convert.c 1 Apr 2007 22:39:44 -0000 1.24 *************** *** 70,74 **** 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; --- 70,73 ---- *************** *** 94,99 **** 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])); --- 93,120 ---- GString *gsNDBSql; gsNDBSql = g_string_new (""); ! g_string_printf(gsNDBSql, "select policy_id from perfdata_delete_policy where policy_name='%s'",policy_name); ! query_result_new=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); ! } ! } ! } ! ! int get_groupId_from_name(const char *group_name, MYSQL *p_db_mysql_new) { ! int *pGid; ! int Gid; ! ! if((pGid=g_hash_table_lookup(groupsCache,group_name))) { ! Gid=*pGid; ! return(Gid); ! } else { ! MYSQL_RES *query_result_new = NULL; ! MYSQL_ROW result_row_new; ! GString *gsNDBSql; ! gsNDBSql = g_string_new (""); ! g_string_printf(gsNDBSql, "select group_id from perfdata_groups where group_name='%s'",group_name); ! query_result_new=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])); *************** *** 104,107 **** --- 125,152 ---- } + int get_hostId_from_name(const char *host_name, MYSQL *p_db_mysql_new) { + int *pHid; + int Hid; + + if((pHid=g_hash_table_lookup(hostsCache,host_name))) { + Hid=*pHid; + return(Hid); + } else { + MYSQL_RES *query_result_new = NULL; + MYSQL_ROW result_row_new; + GString *gsNDBSql; + gsNDBSql = g_string_new (""); + g_string_printf(gsNDBSql, "select host_id from perfdata_host where host_name='%s'",host_name); + query_result_new=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 install_database (void) *************** *** 176,179 **** --- 221,225 ---- GString *gsNDBSql = g_string_new (""); + GString *gsNDBSql2 = g_string_new (""); GString *gsODBSql = g_string_new (""); *************** *** 431,450 **** 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); } printw(_("\ndone\n")); refresh(); --- 477,528 ---- i++; int iRawPolicyId=-1,iBinPolicyId=-1; + int iRawPolicyInd=-1,iBinPolicyInd=-1; + int Hid=-1,Gid=-1; + move(y,x); piODBlengths=mysql_fetch_lengths(query_result_old); + printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); + g_string_printf(gsNDBSql, "insert ignore into perfdata_host(host_name,is_deleted"); + g_string_printf(gsNDBSql2," values('%s',%s",result_row_old[0],result_row_old[8]); // 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); ! g_string_append_printf(gsNDBSql,",raw_delete_policy_id"); ! g_string_append_printf(gsNDBSql2,",%d",iRawPolicyId); ! } else { ! if(result_row_old[2]!=NULL) { ! iRawPolicyInd=atoi(result_row_old[2])*86400; ! g_string_append_printf(gsNDBSql,",raw_delete_individual"); ! g_string_append_printf(gsNDBSql2,",%d",iRawPolicyInd); ! } } ! ! if(strncmp(result_row_old[7],"user",4)!=0) { iBinPolicyId=get_policyId_from_name(result_row_old[6],&db_mysql_new); + g_string_append_printf(gsNDBSql,",bin_delete_policy_id"); + g_string_append_printf(gsNDBSql2,",%d",iBinPolicyId); + } else { + if(result_row_old[5]!=NULL) { + iBinPolicyInd=atoi(result_row_old[5])*86400; + g_string_append_printf(gsNDBSql,",bin_delete_individual"); + g_string_append_printf(gsNDBSql2,",%d",iBinPolicyInd); + } } ! g_string_append_printf(gsNDBSql2,")"); ! g_string_append_printf(gsNDBSql,")%s",gsNDBSql2->str); ! ! // printw("debug: Sql Statement: %s\n",gsNDBSql->str);refresh(); //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); ! // get host_id and group_id (cached) for filling perfdata_host_groups table ! if(result_row_old[1]!=NULL) { // NULL means no group ! Hid=get_hostId_from_name(result_row_old[0],&db_mysql_new); ! Gid=get_groupId_from_name(result_row_old[1],&db_mysql_new); ! // printw("debug: Hid=%d, Gid=%d\n",Hid,Gid); refresh(); ! g_string_printf(gsNDBSql, "insert ignore into perfdata_host_groups(group_id,host_id) values(%d,%d)",\ ! Gid,Hid); ! dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); ! } } printw(_("\ndone\n")); refresh(); *************** *** 664,669 **** if (mysql_query(p_tmp_db_mysql, sql)) { ! printw(_("A error occured executing the sql command %s. The error message is: %s"), sql, mysql_error(p_tmp_db_mysql)); exit(EXIT_FAILURE); } --- 742,748 ---- if (mysql_query(p_tmp_db_mysql, sql)) { ! printw(_("\nA error occured executing the sql command: %s\nThe error message is: %s\n"), sql, mysql_error(p_tmp_db_mysql)); + refresh(); exit(EXIT_FAILURE); } |