From: Florian G. <re...@us...> - 2006-09-14 21:05:19
|
Update of /cvsroot/perfparse/_perfparse/cgi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7500/cgi Modified Files: perfchart.c Log Message: changes queries in perfchart Index: perfchart.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/cgi/perfchart.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** perfchart.c 24 Aug 2006 15:27:35 -0000 1.5 --- perfchart.c 14 Sep 2006 21:05:16 -0000 1.6 *************** *** 60,66 **** /* CGI in */ ! char sHost[76] = ""; ! char sService[76] = ""; ! char sMetric[76] = ""; char sFrom[30], sTo[30]; char sTimeRange[2]; --- 60,67 ---- /* CGI in */ ! char sHost[76]; ! char sService[76]; ! char sMetric[76]; ! int sMetricId = FALSE; char sFrom[30], sTo[30]; char sTimeRange[2]; *************** *** 194,198 **** printf("Expires: Sun, 02 Jan 2000 01:01:01 GMT\n"); ! printf("content-type: image/png\n\n"); setlocale(LC_ALL, ""); --- 195,200 ---- printf("Expires: Sun, 02 Jan 2000 01:01:01 GMT\n"); ! printf("content-type: image/png\n"); ! printf("Content-Disposition: inline; filename=perfchart.png\n\n"); setlocale(LC_ALL, ""); *************** *** 335,349 **** #endif #ifdef USE_DB_MYSQL ! g_string_printf(s_SQL, "SELECT UNIX_TIMESTAMP(ctime), value, warn, critical FROM perfdata_service_bin WHERE host_name = '%s'", ! sql_escape(sHost,PERCENT_ESCAPE_CHAR)); #elif defined USE_DB_POSTGRESQL ! g_string_printf(s_SQL, "SELECT ctime, value, warn, critical FROM perfdata_service_bin WHERE host_name = '%s'", ! sql_escape(sHost,PERCENT_ESCAPE_CHAR)); #endif - g_string_append_printf(s_SQL, " AND service_description = '%s'", - sql_escape(sService,PERCENT_ESCAPE_CHAR)); - g_string_append_printf(s_SQL, " AND metric = '%s'", - sql_escape(sMetric,PERCENT_ESCAPE_CHAR)); g_string_append_printf(s_SQL, " AND ctime BETWEEN '%s' AND '%s' ORDER BY ctime", sFrom, sTo); --- 337,368 ---- #endif + // get sHost sService and sMetric from sMetricId + g_string_printf(s_SQL, "SELECT h.host_name,s.service_description,m.metric FROM perfdata_host h, perfdata_service s, perfdata_service_metric m WHERE "); + g_string_append_printf(s_SQL, "h.host_id=s.host_id AND s.service_id=m.service_id AND m.metric_id=%d",sMetricId); + #ifdef USE_DB_MYSQL + if (mysql_query(&db_mysql, s_SQL->str)) + print_sql_failure_image(__FILE__,__LINE__, s_SQL->str, mysql_error(&db_mysql)); + query_result = mysql_use_result(&db_mysql); + while ((result_row = mysql_fetch_row(query_result))) { + #elif defined USE_DB_POSTGRESQL + /* pgsql untested here*/ + query_result = PQexec(db_postgresql, s_SQL->str); + if(PQresultStatus(query_result) == PGRES_BAD_RESPONSE || PQresultStatus(query_result) == PGRES_FATAL_ERROR) + print_sql_failure_image(__FILE__,__LINE__, s_SQL->str, PQresultErrorMessage(query_result)); + numberOfRows = rows(); + for (currentRow = 0; currentRow<numberOfRows; currentRow++){ + #endif + strncpy(sHost,sData(0),76); + strncpy(sService,sData(1),76); + strncpy(sMetric,sData(2),76); + } + #ifdef USE_DB_MYSQL ! g_string_printf(s_SQL, "SELECT UNIX_TIMESTAMP(ctime), value, warn, critical FROM perfdata_service_bin WHERE metric_id = %d", ! sMetricId); #elif defined USE_DB_POSTGRESQL ! g_string_printf(s_SQL, "SELECT ctime, value, warn, critical FROM perfdata_service_bin WHERE metric_id = '%s'", ! sMetricId); #endif g_string_append_printf(s_SQL, " AND ctime BETWEEN '%s' AND '%s' ORDER BY ctime", sFrom, sTo); *************** *** 1511,1517 **** /* Graph details */ ! strncpy(sHost, scgi("host"),76); ! strncpy(sService, scgi("service"),76); ! strncpy(sMetric, scgi("metric"),76); if ((s = scgi("max"))[0] > ' ') { --- 1530,1534 ---- /* Graph details */ ! sMetricId=atoi(scgi("metric_id")); if ((s = scgi("max"))[0] > ' ') { |