From 6bc02a1f2271e2a4b46322584b8d45704029b161 Mon Sep 17 00:00:00 2001 From: arjen Date: Sat, 27 Oct 2007 08:46:21 +0000 Subject: [PATCH] Select a specific host from a logfile, in case syslogd acts as a log server for multiple systems. This adds a new parameter (logile/fromhost) to the configuration file. --- src/gcm_input/logrunner.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gcm_input/logrunner.cpp b/src/gcm_input/logrunner.cpp index 2e610dd..2de9902 100644 --- a/src/gcm_input/logrunner.cpp +++ b/src/gcm_input/logrunner.cpp @@ -2,7 +2,7 @@ * logrunner.c * (c) Peter Roozemaal, feb 2003 * - * $Id: logrunner.cpp,v 1.3 2007-05-06 08:35:16 arjen Exp $ + * $Id: logrunner.cpp,v 1.4 2007-10-27 08:46:21 arjen Exp $ * * 1) compile, * 2) Add 'logfile' elements to the gnucomo configuration file @@ -58,6 +58,8 @@ static const char* const usage = class LogFile { String name; String type; + String fromhost; + int fd; ino_t inode; off_t position; @@ -67,10 +69,11 @@ class LogFile { void copy_data(); public: - LogFile(String n, String t) + LogFile(String n, String t, String fh) { name = n; type = t; + fromhost = fh; inode = 0; position = 0; fd = -1; @@ -78,10 +81,12 @@ public: LogFile(const LogFile &lf) { - name = lf.name; - type = lf.type; - fd = lf.fd; - inode = lf.inode; + name = lf.name; + type = lf.type; + fromhost = lf.fromhost; + + fd = lf.fd; + inode = lf.inode; position = lf.position; filter = lf.filter; } @@ -289,10 +294,16 @@ void LogFile::copy_data() String logline(line); - // Apply filters to this log entry + // See if have to select the host and apply filters to this log entry - std::list::iterator f = filter.begin(); bool filtered_out = false; + + if (fromhost && (fromhost.in(logline) == -1 || fromhost.in(logline) > 20)) + { + filtered_out = true; + } + + std::list::iterator f = filter.begin(); while (f != filter.end()) { if (logline == *f) @@ -416,6 +427,7 @@ void read_config(gnucomo_config cfg) String logfilename; String logfiletype; + String fromhost; int l = 0; @@ -424,9 +436,10 @@ void read_config(gnucomo_config cfg) { std::cerr << "Configuration for logfile " << logfilename << "\n"; logfiletype = cfg.find_parameter("logfile", "type", l); - std::cerr << "LogFile " << logfilename << " of type " << logfiletype << "\n"; + fromhost = cfg.find_parameter("logfile", "fromhost", l); + std::cerr << "LogFile " << logfilename << " of type " << logfiletype << " from host " << fromhost << "\n"; - LogFile lf(logfilename, logfiletype); + LogFile lf(logfilename, logfiletype, fromhost); int f = 0; String exp = cfg.find_parameter("logfile", "filter", l, f); -- 2.11.0