commit b8f34988880620fb676512484d0e128c99b3c675
parent c2a98f06eaa77ef9a63c79daa94b5021ebd17a3b
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Sun, 21 Jun 2015 23:52:48 +0200
Counting HTTP status codes occurrences
Diffstat:
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -13,6 +13,7 @@ Currently implemented features :
- Counting bandwidth used
- Counting log file size
- GeoIP lookups (IPv4 only for now)
+- Counting HTTP status codes occurences
## Dependencies
diff --git a/src/logswan.c b/src/logswan.c
@@ -51,6 +51,9 @@ struct sockaddr_in6 ipv6;
int isIPv4, isIPv6;
+int httpStatus[512];
+int statusCode;
+
struct stat logFileSize;
FILE *logFile;
@@ -108,6 +111,15 @@ int main (int argc, char *argv[]) {
countries[GeoIP_id_by_addr(geoip, parsedLine.remoteHost)]++;
}
+ /* Count HTTP status codes occurences */
+ if (parsedLine.statusCode) { /* Do not feed NULL tokens to strtol */
+ statusCode = strtol(parsedLine.statusCode, &endptr, 10);
+
+ if (statusCode < 512) {
+ httpStatus[statusCode] += 1;
+ }
+ }
+
/* Increment bandwidth usage */
if (parsedLine.objectSize) { /* Do not feed NULL tokens to strtol */
bandwidth += strtol(parsedLine.objectSize, &endptr, 10);