}
}
-#define HTTPERROR_400 return http_issue_error( client_socket, "400 Invalid Request", "This server only understands GET." )
-#define HTTPERROR_400_PARAM return http_issue_error( client_socket, "400 Invalid Request", "Invalid parameter" )
-#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, "400 Invalid Request", "This server only delivers compact results." )
-#define HTTPERROR_403_IP return http_issue_error( client_socket, "403 Access Denied", "Your ip address is not allowed to administrate this server." )
-#define HTTPERROR_404 return http_issue_error( client_socket, "404 Not Found", "No such file or directory." )
-#define HTTPERROR_500 return http_issue_error( client_socket, "500 Internal Server Error", "A server error has occured. Please retry later." )
-ssize_t http_issue_error( const int64 client_socket, const char *title, const char *message ) {
+#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 )
+#define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM )
+#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT )
+#define HTTPERROR_403_IP return http_issue_error( client_socket, CODE_HTTPERROR_403_IP )
+#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 )
+#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 )
+ssize_t http_issue_error( const int64 client_socket, int code ) {
+ char *error_code[] = { "400 Invalid Request", "400 Invalid Request", "400 Invalid Request",
+ "403 Access Denied", "404 Not Found", "500 Internal Server Error" };
+ char *title = error_code[code];
+
size_t reply_size = sprintf( static_outbuf,
"HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n<title>%s</title>\n",
- title, strlen(message)+strlen(title)+16-4,title+4);
+ title, 2*strlen(title)+16-4,title+4);
#ifdef _DEBUG_HTTPERROR
fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request );
#endif
+ stats_issue_event( EVENT_FAILED, 1, code );
http_senddata( client_socket, static_outbuf, reply_size);
return -2;
}
mode = TASK_STATS_SLASH24S;
else if( !byte_diff(data,4,"tpbs"))
mode = TASK_STATS_TPB;
+ else if( !byte_diff(data,4,"herr"))
+ mode = TASK_STATS_HTTPERRORS;
else
HTTPERROR_400_PARAM;
break;
break;
#endif
case 5: /* stats ? */
- if( byte_diff(data,5,"stats")) HTTPERROR_404;
+ if( byte_diff( data, 5, "stats") ) HTTPERROR_404;
reply_size = http_handle_stats( client_socket, c, recv_header, recv_length );
break;
default:
static unsigned long long ot_full_scrape_count = 0;
static unsigned long long ot_full_scrape_request_count = 0;
static unsigned long long ot_full_scrape_size = 0;
+static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT];
static time_t ot_start_time;
);
}
+static size_t stats_httperrors_txt ( char * reply ) {
+ return sprintf( reply, "400 ... %llu\n400 PAR %llu\n400 COM %llu\n403 IP %llu\n404 INV %llu\n500 SRV %llu\n",
+ ot_failed_request_counts[0], ot_failed_request_counts[1], ot_failed_request_counts[2],
+ ot_failed_request_counts[3], ot_failed_request_counts[4], ot_failed_request_counts[5]);
+}
+
size_t return_stats_for_tracker( char *reply, int mode, int format ) {
format = format;
switch( mode ) {
return stats_top5_txt( reply );
case TASK_STATS_FULLSCRAPE:
return stats_fullscrapes_mrtg( reply );
+ case TASK_STATS_HTTPERRORS:
+ return stats_httperrors_txt( reply );
default:
return 0;
}
LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE GZIP\n", (unsigned int)(g_now - ot_start_time), ip[0], ip[1], ip[2], ip[3] );
ot_full_scrape_request_count++;
}
- break;
+ break;
+ case EVENT_FAILED:
+ ot_failed_request_counts[event_data]++;
+ break;
case EVENT_SYNC_IN_REQUEST:
case EVENT_SYNC_IN:
case EVENT_SYNC_OUT_REQUEST: