From: Florian G. <re...@us...> - 2007-04-14 00:35:06
|
Update of /cvsroot/perfparse/_perfparse/db_tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18924/db_tools Modified Files: convert.c Log Message: convert perfdata_service_metric table Index: convert.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/db_tools/convert.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** convert.c 11 Apr 2007 13:43:40 -0000 1.29 --- convert.c 14 Apr 2007 00:34:59 -0000 1.30 *************** *** 39,43 **** #include <gettext.h> #include <sys/types.h> - #include <regex.h> #include <ncurses.h> --- 39,42 ---- *************** *** 48,52 **** // debug ! // #define DEBUG void checkTables (); --- 47,51 ---- // debug ! #define DEBUG void checkTables (); *************** *** 59,62 **** --- 58,64 ---- void init_caches(void); int get_policyId_from_name(const char *policy_name, MYSQL *db_mysql_new); + int get_groupId_from_name(const char *group_name, MYSQL *db_mysql_new); + int get_hostId_from_name(const char *host_name, MYSQL *db_mysql_new); + int get_serviceId_from_desc(const char *host_name,const char *service_desc,MYSQL *db_mysql_new); void end_curses(void); void exit_curses(int endval); *************** *** 66,69 **** --- 68,72 ---- GHashTable *groupsCache=NULL; GHashTable *hostsCache=NULL; + GHashTable *servicesCache=NULL; void init_caches(void) { *************** *** 71,74 **** --- 74,78 ---- groupsCache=g_hash_table_new(g_str_hash,g_str_equal); hostsCache=g_hash_table_new(g_str_hash,g_str_equal); + servicesCache=g_hash_table_new(g_str_hash,g_str_equal); } *************** *** 182,185 **** --- 186,236 ---- + int get_serviceId_from_desc(const char *host_name, const char *service_desc, MYSQL *p_db_mysql_new) { + int *pSid; + int Hid,Sid; + + // use combined string for querying cache + GString *gsCombined=g_string_new(""); + g_string_printf(gsCombined,"%s : %s",host_name,service_desc); + + if((Hid=get_hostId_from_name(host_name,p_db_mysql_new))==FALSE) { + return(FALSE); + } + + if((pSid=g_hash_table_lookup(servicesCache,gsCombined->str))) { + Sid=*pSid; + #ifdef DEBUG + printw("\nServiceId Cache Hit: %s -> %d\n",gsCombined->str,Sid);refresh(); + #endif + return(Sid); + } else { + MYSQL_RES *query_result_new = NULL; + MYSQL_ROW result_row_new; + GString *gsNDBSql; + gsNDBSql = g_string_new (""); + g_string_printf(gsNDBSql, "select service_id from perfdata_service where " + "host_id=%d and service_description='%s'", + Hid,service_desc); + 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))) { + Sid=atoi(result_row_new[0]); + } else { + Sid=FALSE; + } + // cleanup + g_string_free(gsNDBSql,TRUE); + dbtool_freeResult(query_result_new); + // save result in cache + pSid=malloc(sizeof(int)); + *pSid=Sid; + g_hash_table_insert(servicesCache,(gpointer) gsCombined->str,pSid); + #ifdef DEBUG + printw("\nServiceId Cache Miss: %s -> %d\n",gsCombined->str,Sid);refresh(); + #endif + g_string_free(gsCombined,TRUE); + return(Sid); + } + } + void *************** *** 574,578 **** refresh(); ! g_string_printf(gsODBSql, "select host_name,service_description,last_perfdata_raw,raw_delete_policy,raw_delete_policy_name,raw_delete_policy_type,is_deleted from perfdata_service"); query_result_old=dbtool_mysql_query(gsODBSql->str, &db_mysql_old,query_result_old); iODBnumrows=dbtool_rows(query_result_old); --- 625,633 ---- refresh(); ! g_string_printf(gsODBSql, "select host_name,service_description," ! "last_perfdata_raw,raw_delete_policy," ! "raw_delete_policy_name," ! "raw_delete_policy_type,is_deleted " ! "from perfdata_service"); query_result_old=dbtool_mysql_query(gsODBSql->str, &db_mysql_old,query_result_old); iODBnumrows=dbtool_rows(query_result_old); *************** *** 593,597 **** printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); Hid=get_hostId_from_name(result_row_old[0],&db_mysql_new); ! g_string_printf(gsNDBSql, "insert ignore into perfdata_service(host_id,service_description,is_deleted"); g_string_printf(gsNDBSql2," values(%d,'%s',%s",Hid,result_row_old[1],result_row_old[6]); // get raw delete policy id if template --- 648,653 ---- printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); Hid=get_hostId_from_name(result_row_old[0],&db_mysql_new); ! g_string_printf(gsNDBSql, "insert ignore into perfdata_service(host_id," ! "service_description,is_deleted"); g_string_printf(gsNDBSql2," values(%d,'%s',%s",Hid,result_row_old[1],result_row_old[6]); // get raw delete policy id if template *************** *** 614,620 **** --- 670,735 ---- dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); } + //Todo: Handle last_perfdata row somewhere? Or does it "rapair itself automatically"? printw(_("\ndone\n")); refresh(); + + // Step 5 + iStep++; + printw(_("(Step %d of %d)\n"),iStep,iNumSteps); + printw(_("Copying data of perfdata_service_metric table.\n")); + refresh(); + + g_string_printf(gsODBSql, "select host_name,service_description,metric," + "unit,notes,value_max,value_min," + "last_perfdata_bin,bin_delete_policy," + "bin_delete_policy_name," + "bin_delete_policy_type,is_deleted " + "from perfdata_service_metric"); + 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 iBinPolicyId=-1; + int iBinPolicyInd=-1; + int Sid=-1; + + move(y,x); + piODBlengths=mysql_fetch_lengths(query_result_old); + + printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); + Sid=get_serviceId_from_desc(result_row_old[0],result_row_old[1],&db_mysql_new); + g_string_printf(gsNDBSql, "insert ignore into perfdata_service_metric" + "(service_id,metric,unit,notes,value_max," + "value_min,is_deleted"); + g_string_printf(gsNDBSql2," values(%d,'%s','%s','%s',%s,%s,%s", + Sid,result_row_old[2],result_row_old[3],result_row_old[4], + result_row_old[5],result_row_old[6],result_row_old[11]); + // get bin delete policy id if template + if(strncmp(result_row_old[10],"template",4)==0) { + iBinPolicyId=get_policyId_from_name(result_row_old[9],&db_mysql_new); + g_string_append_printf(gsNDBSql,",bin_delete_policy_id"); + g_string_append_printf(gsNDBSql2,",%d",iBinPolicyId); + } else { + if(result_row_old[8]!=NULL) { + iBinPolicyInd=atoi(result_row_old[8])*86400; + g_string_append_printf(gsNDBSql,",bin_delete_policy_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(); + dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); + } + printw(_("\ndone\n")); refresh(); + //TODO: End comment versioncheck *************** *** 860,862 **** } - --- 975,976 ---- |