From: Florian G. <re...@us...> - 2007-06-12 15:11:18
|
Update of /cvsroot/perfparse/_perfparse/cgi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1174/cgi Modified Files: perfgant.c Log Message: make raw_plugin report work with new db schema Index: perfgant.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/cgi/perfgant.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** perfgant.c 6 Jun 2007 13:26:43 -0000 1.5 --- perfgant.c 12 Jun 2007 15:11:09 -0000 1.6 *************** *** 57,63 **** /* CGI in */ - char *sHost; - char *sService; - char *sFrom, *sTo; int iServiceId; --- 57,60 ---- *************** *** 81,85 **** void drawGant(); void drawHeadings(); - time_t getTime(char *sSQLDate); void drawBox(time_t t0, time_t t1, int iState); int getY(time_t t); --- 78,81 ---- *************** *** 103,106 **** --- 99,104 ---- CONFIG_ITEM_ID_DB_DATABASE, CONFIG_ITEM_ID_DB_HOST, + CONFIG_ITEM_ID_DB_PORT, + CONFIG_ITEM_ID_DB_SOCKET, CONFIG_ITEM_ID_DEFAULT_USER_PERMISSIONS_POLICY, CONFIG_ITEM_ID_DEFAULT_USER_PERMISSIONS_HOST_GROUP, *************** *** 219,223 **** g_string_printf(s_SQL, "SELECT ctime, txt_data, nagios_status FROM perfdata_service_raw WHERE service_id = %d", iServiceId); #endif ! g_string_append_printf(s_SQL, " AND ctime BETWEEN %d AND %d", tFrom, tTo); g_string_append_printf(s_SQL, " ORDER BY ctime"); query(s_SQL->str); --- 217,221 ---- g_string_printf(s_SQL, "SELECT ctime, txt_data, nagios_status FROM perfdata_service_raw WHERE service_id = %d", iServiceId); #endif ! g_string_append_printf(s_SQL, " AND ctime BETWEEN %d AND %d", (int) tFrom, (int) tTo); g_string_append_printf(s_SQL, " ORDER BY ctime"); query(s_SQL->str); *************** *** 234,238 **** iState = iData(2); } else { ! iState = 0; if (strstr(sData(1), "Connection refused")) iState = 2; else if (strstr(sData(1), "OK")) iState = 0; --- 232,236 ---- iState = iData(2); } else { ! iState = 3; // if we dont know, we set it to unknown if (strstr(sData(1), "Connection refused")) iState = 2; else if (strstr(sData(1), "OK")) iState = 0; *************** *** 245,251 **** else if (strstr(sData(1), "UNKNOWN")) iState = 3; } #ifdef USE_DB_MYSQL ! t1 = (time_t)iData(3); #elif defined USE_DB_POSTGRESQL t1 = tData(0); --- 243,250 ---- else if (strstr(sData(1), "UNKNOWN")) iState = 3; } + #ifdef USE_DB_MYSQL ! t1 = (time_t)iData(0); #elif defined USE_DB_POSTGRESQL t1 = tData(0); *************** *** 411,439 **** void getCGI() { ! char s[20]; getCGIDBVars(); /* Graph details */ - sHost = strdup(scgi("host")); - sService = strdup(scgi("service")); iServiceId = atoi(scgi("service_id")); ! sFrom = strdup(scgi("from")); ! sTo = strdup(scgi("to")); ! tFrom = getTime(sFrom); ! tTo = getTime(sTo); ! ! strcpy(s, sFrom); ! s[10] = 0; ! sprintf(s, "%s 00:00:00", s); ! tFromMidnight = getTime(s); ! strcpy(s, sTo); ! s[10] = 0; ! sprintf(s, "%s 23:59:59", s); ! tToMidnight = getTime(s) + 1; iDays = (int)(tToMidnight - tFromMidnight) / DAY1; --- 410,436 ---- void getCGI() { ! struct tm *t; getCGIDBVars(); /* Graph details */ iServiceId = atoi(scgi("service_id")); ! // use unix timestamps now ! tFrom = atoi(scgi("from")); ! tTo = atoi(scgi("to")); ! t=localtime(&tFrom); ! t->tm_sec=0; ! t->tm_min=0; ! t->tm_hour=0; ! tFromMidnight = mktime(t); ! t=localtime(&tTo); ! t->tm_sec=59; ! t->tm_min=59; ! t->tm_hour=23; ! tToMidnight = mktime(t)+1; iDays = (int)(tToMidnight - tFromMidnight) / DAY1; *************** *** 441,445 **** #ifdef DEBUG ! fprintf(f, "\"%s\" -> \"%s\" = %ld hours = %d days.\n", sFrom, sTo, (tToMidnight - tFromMidnight) / 3600, iDays); #endif --- 438,442 ---- #ifdef DEBUG ! fprintf(f, "\"%s\" -> \"%s\" = %ld hours = %d days.\n", ctime(tFrom), ctime(tTo), (tToMidnight - tFromMidnight) / 3600, iDays); #endif *************** *** 464,537 **** - time_t getTime(char *sSQLDate) - /* format "YY-MM-DD hh:mm:ss" */ - { - struct tm recTime; - static int iOffset = -1; - time_t tOut; - char s[5]; - - if (strlen(sSQLDate) < 18) { - int i; - for (i = strlen(sSQLDate) + 1; i < 19; i++) sSQLDate[i] = 0; - } - - // Year: - s[0] = sSQLDate[0]; - s[1] = sSQLDate[1]; - s[2] = sSQLDate[2]; - s[3] = sSQLDate[3]; - s[4] = 0; - iYear = atoi(s); - recTime.tm_year = iYear - 1900; - - // Month: - s[0] = sSQLDate[5]; - s[1] = sSQLDate[6]; - s[2] = 0; - iMonth = atoi(s); - recTime.tm_mon = iMonth - 1; - - // Month Day: - s[0] = sSQLDate[8]; - s[1] = sSQLDate[9]; - s[2] = 0; - iDay = atoi(s); - recTime.tm_mday = iDay; - - // Hours: - s[0] = sSQLDate[11]; - s[1] = sSQLDate[12]; - s[2] = 0; - recTime.tm_hour = atoi(s); - - // Minuts: - s[0] = sSQLDate[14]; - s[1] = sSQLDate[15]; - s[2] = 0; - recTime.tm_min = atoi(s); - - // Seconds: - s[0] = sSQLDate[17]; - s[1] = sSQLDate[18]; - s[2] = 0; - recTime.tm_sec = atoi(s); - recTime.tm_isdst = 0; - - tOut = mktime(&recTime); - - if (iOffset == -1) { - struct tm *r; - r = localtime(&tOut); - r->tm_isdst = 0; - iOffset = (int)mktime(r) - tOut; - } - - return tOut - iOffset; - - } - - - /*************************************** * --- 461,464 ---- |