From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 18 Sep 2007 18:46:36 -0000 Subject: [Cluster-devel] conga/ricci/modules/log LogParser.cpp LogParse ... Message-ID: <20070918184636.29707.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: rmccabe at sourceware.org 2007-09-18 18:46:35 Modified files: ricci/modules/log: LogParser.cpp LogParser.h LoggingModule.cpp LoggingModule.h main.cpp Log message: Cleanup and minor optimization Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/log/LogParser.cpp.diff?cvsroot=cluster&r1=1.10&r2=1.11 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/log/LogParser.h.diff?cvsroot=cluster&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/log/LoggingModule.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/log/LoggingModule.h.diff?cvsroot=cluster&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/log/main.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5 --- conga/ricci/modules/log/LogParser.cpp 2007/09/11 02:45:28 1.10 +++ conga/ricci/modules/log/LogParser.cpp 2007/09/18 18:46:35 1.11 @@ -1,431 +1,470 @@ /* - Copyright Red Hat, Inc. 2006 - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, - MA 02139, USA. +** Copyright Red Hat, Inc. 2006-2007 +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License version 2 as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; see the file COPYING. If not, write to the +** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +** MA 02139, USA. */ /* * Author: Stanko Kupcevic */ - #include "LogParser.h" #include "utils.h" #include "Mutex.h" +#include +#include #include -#include #include +#include #include -#include #include - #include using namespace std; +static const char *cluster[] = { + "cluster", + "modclusterd", + "dlm", + "gulm", + "lock_gulmd", + "lock_gulmd_main", + "lock_gulmd_core", + "lock_gulmd_LT", + "lock_gulmd_LTPX", + "cman", + "cman_tool", + "ccs", + "ccs_tool", + "ccsd", + "fence", + "fenced", + "clvmd", + "gfs", + "gfs2", + "openais", + "groupd", + "qdiskd", + "dlm_controld", + "gfs_controld", + "clurgmgrd", + "rgmanager" +}; +static const char *cluster_service_manager[] = { + "clurgmgrd", + "rgmanager" +}; -static const char* cluster[] = {"cluster", - "modclusterd", - "dlm", - "gulm", - "lock_gulmd", - "lock_gulmd_main", - "lock_gulmd_core", - "lock_gulmd_LT", - "lock_gulmd_LTPX", - "cman", - "cman_tool", - "ccs", - "ccs_tool", - "ccsd", - "fence", - "fenced", - "clvmd", - "gfs", - "gfs2", - "openais", - "groupd", - "qdiskd", - "dlm_controld", - "gfs_controld", - "clurgmgrd", - "rgmanager"}; - -static const char* cluster_service_manager[] = {"clurgmgrd", - "rgmanager"}; - -static const char* LVS[] = {"ipvs", - "ipvsadm", - "piranha", - "piranha-gui"}; - -static const char* storage[] = {"gfs", - "gfs2", - "lvm", - "clvm", - "clvmd", - "end_request", - "buffer", - "scsi", - "md", - "raid0", - "raid1", - "raid4", - "raid5", - "cdrom", - "ext2", - "ext3", - "ext3-fs", - "swap", - "mount", - "automount"}; - -static const char* selinux[] = {"selinux", - "security", - "pam", - "audit"}; - - - +static const char *LVS[] = { + "ipvs", + "ipvsadm", + "piranha", + "piranha-gui" +}; +static const char *storage[] = { + "gfs", + "gfs2", + "lvm", + "clvm", + "clvmd", + "end_request", + "buffer", + "scsi", + "md", + "raid0", + "raid1", + "raid4", + "raid5", + "cdrom", + "ext2", + "ext3", + "ext3-fs", + "swap", + "mount", + "automount" +}; +static const char *selinux[] = { + "selinux", + "security", + "pam", + "audit" +}; class tag_set { public: - tag_set(const String& name, - const set& elements) : - name(name), - elements(elements) {} - - String name; - set elements; - set match; + tag_set(const String& name, const set& elements) : + name(name), + elements(elements) {} + + String name; + set elements; + set match; }; - static const vector& get_sets() { - static vector sets; - static Mutex mutex; - static bool init = false; - - MutexLocker l(mutex); - if (!init) { - init = true; - tag_set clu("cluster", - set(cluster, - cluster + sizeof(cluster)/sizeof(char*))); - clu.match.insert("fence_"); - sets.push_back(clu); - - sets.push_back(tag_set("cluster service manager", - set(cluster_service_manager, - cluster_service_manager + sizeof(cluster_service_manager)/sizeof(char*)))); - - sets.push_back(tag_set("lvs", - set(LVS, - LVS + sizeof(LVS)/sizeof(char*)))); - - sets.push_back(tag_set("storage", - set(storage, - storage + sizeof(storage)/sizeof(char*)))); - - tag_set SEL("selinux", - set(selinux, - selinux + sizeof(selinux)/sizeof(char*))); - SEL.match.insert("pam_"); - sets.push_back(SEL); - } - return sets; -} + static vector sets; + static Mutex mutex; + static bool init = false; + + MutexLocker l(mutex); + if (!init) { + init = true; + tag_set clu("cluster", + set(cluster, cluster + arr_elem(cluster))); + clu.match.insert("fence_"); + sets.push_back(clu); + + sets.push_back(tag_set("cluster service manager", + set(cluster_service_manager, + cluster_service_manager + arr_elem(cluster_service_manager)))); + + sets.push_back(tag_set("lvs", set(LVS, LVS + arr_elem(LVS)))); + + sets.push_back(tag_set("storage", + set(storage, storage + arr_elem(storage)))); + + tag_set SEL("selinux", + set(selinux, selinux + arr_elem(selinux))); + SEL.match.insert("pam_"); + sets.push_back(SEL); + } + return sets; +} static time_t parse_time(const String& time_rep) { - struct tm tm; - if (!strptime(time_rep.c_str(), "%b %d %T %Y", &tm)) - throw String("invalid log entry format"); - return mktime(&tm); + struct tm tm; + if (!strptime(time_rep.c_str(), "%b %d %T %Y", &tm)) + throw String("invalid log entry format"); + return mktime(&tm); } - set& -get_files(const String& path_, - set& files, - time_t age_time) +get_files(const String& path_, set& files, time_t age_time) { - String path = utils::rstrip(utils::strip(path_), "/"); - if (path.empty() || path.find_first_of(" ; & $ ` ? > < ' \" ; | \\ * \n \t") != path.npos) - return files; - if (path[0] != '/') - return files; - - struct stat st; - if (stat(path.c_str(), &st)) - // throw String("unable to stat ") + path; - return files; - if (S_ISREG(st.st_mode)) { - if (st.st_mtime >= age_time) - files.insert(path); - - // get rotated logs - for (int i=0; i<25; i++) - get_files(path + "." + utils::to_string(i), files, age_time); - - return files; - } else if (S_ISDIR(st.st_mode)) - ; // process directory - else - return files; - - DIR* d = opendir(path.c_str()); - if (d == NULL) - throw String("unable to open directory ") + path; - try { - while (true) { - struct dirent* ent = readdir(d); - if (ent == NULL) { - closedir(d); - return files; - } - String kid_path = ent->d_name; - if (kid_path == "." || kid_path == "..") - continue; - kid_path = path + "/" + kid_path; - get_files(kid_path, files, age_time); - } - } catch ( ... ) { - closedir(d); - throw; - } -} - + String path = utils::rstrip(utils::strip(path_), "/"); + if (path.empty() || + path.find_first_of(" ; & $ ` ? > < ' \" ; | \\ * \n \t") != path.npos) + { + return files; + } + if (path[0] != '/') + return files; + struct stat st; + if (stat(path.c_str(), &st)) + return files; + + if (S_ISREG(st.st_mode)) { + if (st.st_mtime >= age_time) + files.insert(path); + + // get rotated logs + for (int i = 0 ; i < 25 ; i++) + get_files(path + "." + utils::to_string(i), files, age_time); + + return files; + } else if (S_ISDIR(st.st_mode)) + ; // process directory + else + return files; + + DIR *d = opendir(path.c_str()); + if (d == NULL) { + throw String("unable to open directory ") + + path + ":" + String(strerror(errno)); + } + try { + while (true) { + struct dirent *ent = readdir(d); + if (ent == NULL) { + closedir(d); + return files; + } + + String kid_path = ent->d_name; + if (kid_path == "." || kid_path == "..") + continue; + + kid_path = path + "/" + kid_path; + get_files(kid_path, files, age_time); + } + } catch ( ... ) { + closedir(d); + throw; + } +} LogEntry::LogEntry(const String& entry) { - vector words = utils::split(entry); - if (words.size() < 6) - throw String("invalid log entry format"); - if (words[4] == "last" && - words[5] == "message") - throw String("LogEntry: last message repetition"); - if (words[5] == "printk:" && - entry.find("suppressed") != entry.npos) - throw String("LogEntry: printk repetition"); - - // get current year (not present in log files) - char buff[100]; - time_t current_time = ::time(0); - struct tm tm; - localtime_r(¤t_time, &tm); - if (strftime(buff, sizeof(buff), "%Y", &tm) != 4) - throw String("failed to get current year"); - String year(buff, 4); - String time_rep = words[0] + " " + words[1] + " " + words[2] + " " + year; - age = (long long) difftime(current_time, parse_time(time_rep)); - if (age < 0) { - // beginning of the year fix, since year is not present in log files - // FIXME: works only for log files shorter than 2 years - year = utils::to_string(utils::to_long(year) - 1); - time_rep = words[0] + " " + words[1] + " " + words[2] + " " + year; - age = (long long) difftime(current_time, parse_time(time_rep)); - } - if (age < 0) - throw String("error in LogEntry() - negative age"); - - // domain & pid - String d = utils::rstrip(utils::to_lower(words[4]), ":"); - String::size_type i = d.find("["); - domain = d.substr(0, i); - tags.insert(domain); - if (i != d.npos) { - pid = utils::strip(d.substr(i)); - pid = utils::lstrip(pid, "["); - pid = utils::rstrip(pid, "]"); - tags.insert(pid); - } - vector::size_type idx = 5; - if (domain == "kernel") { - domain = utils::rstrip(utils::to_lower(words[5]), ":"); - tags.insert(domain); - if (words[5][words[5].size()-1] == ':') - idx = 6; - } - - // message - for ( ; idx::size_type j=4; j<6; j++) { - String t(utils::strip(utils::to_lower(words[j]))); - if (t.empty()) - continue; - if (t[t.size()-1] != ':') - continue; - t = utils::rstrip(t, ":"); - tags.insert(t); - if ((i = t.find("(")) != t.npos) { - tags.insert(utils::strip(t.substr(0, i))); - String tmp_tag = utils::strip(t.substr(i)); - tmp_tag = tmp_tag.substr(0, tmp_tag.find(")")); - tmp_tag = utils::lstrip(tmp_tag, "("); - tmp_tag = utils::rstrip(tmp_tag, ")"); - tags.insert(tmp_tag); - } - if ((i = t.find("[")) != t.npos) { - tags.insert(utils::strip(t.substr(0, i))); - String tmp_tag = utils::strip(t.substr(i)); - tmp_tag = tmp_tag.substr(0, tmp_tag.find("]")); - tmp_tag = utils::lstrip(tmp_tag, "["); - tmp_tag = utils::rstrip(tmp_tag, "]"); - tags.insert(tmp_tag); - } - } - - // tags (from tag sets) - vector sets = get_sets(); - set tags_c(tags); - for (set::const_iterator iter = tags_c.begin(); - iter != tags_c.end(); - iter++) - for (vector::const_iterator ts_iter = sets.begin(); - ts_iter != sets.end(); - ts_iter++) { - if (ts_iter->elements.find(*iter) != ts_iter->elements.end()) - tags.insert(ts_iter->name); - for (set::const_iterator m_iter = ts_iter->match.begin(); - m_iter != ts_iter->match.end(); - m_iter++) - if (iter->find(*m_iter) == 0) - tags.insert(ts_iter->name); - } - if (tags.find("") != tags.end()) - tags.erase(""); + vector words = utils::split(entry); + if (words.size() < 6) + throw String("invalid log entry format"); + + if (words[4] == "last" && + words[5] == "message") + { + throw String("LogEntry: last message repetition"); + } + + if (words[5] == "printk:" && + entry.find("suppressed") != entry.npos) + { + throw String("LogEntry: printk repetition"); + } + + // get current year (not present in log files) + char buff[64]; + time_t current_time = ::time(NULL); + struct tm tm; + + localtime_r(¤t_time, &tm); + if (strftime(buff, sizeof(buff), "%Y", &tm) != 4) + throw String("failed to get current year"); + String year(buff, 4); + String time_rep = words[0] + " " + words[1] + " " + words[2] + " " + year; + age = (long long) difftime(current_time, parse_time(time_rep)); + + if (age < 0) { + // beginning of the year fix, since year is not present in log files + // FIXME: works only for log files shorter than 2 years + year = utils::to_string(utils::to_long(year) - 1); + time_rep = words[0] + " " + words[1] + " " + words[2] + " " + year; + age = (long long) difftime(current_time, parse_time(time_rep)); + } + + if (age < 0) + throw String("error in LogEntry() - negative age"); + + // domain & pid + String d = utils::rstrip(utils::to_lower(words[4]), ":"); + String::size_type i = d.find("["); + domain = d.substr(0, i); + tags.insert(domain); + + if (i != d.npos) { + pid = utils::strip(d.substr(i)); + pid = utils::lstrip(pid, "["); + pid = utils::rstrip(pid, "]"); + tags.insert(pid); + } + + vector::size_type idx = 5; + if (domain == "kernel") { + domain = utils::rstrip(utils::to_lower(words[5]), ":"); + tags.insert(domain); + + if (words[5][words[5].size() - 1] == ':') + idx = 6; + } + + // message + for ( ; idx < words.size() ; idx++) + msg += words[idx] + " "; + msg = utils::strip(msg); + + // tags (misc) + for (vector::size_type j = 4 ; j < 6 ; j++) { + String t(utils::strip(utils::to_lower(words[j]))); + + if (t.empty()) + continue; + + if (t[t.size() - 1] != ':') + continue; + + t = utils::rstrip(t, ":"); + tags.insert(t); + + if ((i = t.find("(")) != t.npos) { + tags.insert(utils::strip(t.substr(0, i))); + String tmp_tag = utils::strip(t.substr(i)); + tmp_tag = tmp_tag.substr(0, tmp_tag.find(")")); + tmp_tag = utils::lstrip(tmp_tag, "("); + tmp_tag = utils::rstrip(tmp_tag, ")"); + tags.insert(tmp_tag); + } + + if ((i = t.find("[")) != t.npos) { + tags.insert(utils::strip(t.substr(0, i))); + String tmp_tag = utils::strip(t.substr(i)); + tmp_tag = tmp_tag.substr(0, tmp_tag.find("]")); + tmp_tag = utils::lstrip(tmp_tag, "["); + tmp_tag = utils::rstrip(tmp_tag, "]"); + tags.insert(tmp_tag); + } + } + + // tags (from tag sets) + vector sets = get_sets(); + set tags_c(tags); + + for (set::const_iterator + iter = tags_c.begin() ; + iter != tags_c.end() ; + iter++) + { + for (vector::const_iterator + ts_iter = sets.begin() ; + ts_iter != sets.end() ; + ts_iter++) + { + if (ts_iter->elements.find(*iter) != ts_iter->elements.end()) + tags.insert(ts_iter->name); + + for (set::const_iterator + m_iter = ts_iter->match.begin() ; + m_iter != ts_iter->match.end() ; + m_iter++) + { + if (iter->find(*m_iter) == 0) + tags.insert(ts_iter->name); + } + } + } + + if (tags.find("") != tags.end()) + tags.erase(""); } String LogEntry::compare_str() const { - String b(utils::to_string(age)); - b += domain + pid + msg; - return b; + String b(utils::to_string(age)); + b += domain + pid + msg; + return b; } bool LogEntry::operator < (const LogEntry& obj) const { - return compare_str() < obj.compare_str(); + return compare_str() < obj.compare_str(); } XMLObject LogEntry::xml() const { - XMLObject x("logentry"); - x.set_attr("domain", domain); - x.set_attr("pid", pid); - x.set_attr("age", utils::to_string(age)); - x.set_attr("msg", msg); - - for (set::const_iterator iter = matched_tags.begin(); - iter != matched_tags.end(); - iter++) { - XMLObject t("match"); - t.set_attr("tag", *iter); - x.add_child(t); - } + XMLObject x("logentry"); + x.set_attr("domain", domain); + x.set_attr("pid", pid); + x.set_attr("age", utils::to_string(age)); + x.set_attr("msg", msg); + + for (set::const_iterator + iter = matched_tags.begin() ; + iter != matched_tags.end() ; + iter++) + { + XMLObject t("match"); + t.set_attr("tag", *iter); + x.add_child(t); + } - return x; + return x; } - - - - - - set -LogParser::get_entries(long long age, - const std::list& domains, - const list& paths) +LogParser::get_entries( long long age, + const std::list& domains, + const list& paths) { - set ret; - time_t age_time = time(NULL); + set ret; + time_t age_time = time(NULL); + + if ((long long) age_time - age < 0) + age_time = 0; + else + age_time -= age; + + + // set of requested tags + set req_tags(domains.begin(), domains.end()); + + // get log paths + set files; + + for (list::const_iterator + iter = paths.begin() ; + iter != paths.end() ; + iter++) + { + get_files(*iter, files, age_time); + } - if ((long long) age_time - age < 0) - age_time = 0; - else - age_time -= age; - - - // set of requested tags - set req_tags(domains.begin(), domains.end()); - - // get log paths - set files; - for (list::const_iterator iter = paths.begin(); - iter != paths.end(); - iter++) - get_files(*iter, files, age_time); - if (files.empty()) { - get_files("/var/log/messages", files, age_time); - get_files("/var/log/syslog", files, age_time); - } - - // process log files - for (set::const_iterator iter = files.begin(); - iter != files.end(); - iter++) { - ifstream log(iter->c_str()); - if (!log.is_open()) - throw String("failed to open ") + *iter; - while (log.good()) { - char buff[1024]; - log.getline(buff, sizeof(buff)); - try { - LogEntry e(buff); - if (e.age > age) - continue; - if (req_tags.empty()) - ret.insert(e); - else { - bool add = false; - for (set::const_iterator t_iter = req_tags.begin(); - t_iter != req_tags.end(); - t_iter++) - if (e.tags.find(*t_iter) != e.tags.end()) { - add = true; - e.matched_tags.insert(*t_iter); - } - if (add) - ret.insert(e); - } - } catch ( ... ) {} - } - } + if (files.empty()) { + get_files("/var/log/messages", files, age_time); + get_files("/var/log/syslog", files, age_time); + } + + // process log files + for (set::const_iterator + iter = files.begin() ; + iter != files.end() ; + iter++) + { + ifstream log(iter->c_str()); + if (!log.is_open()) + throw String("failed to open ") + *iter; + + while (log.good()) { + char buff[4096]; + + try { + log.getline(buff, sizeof(buff)); + LogEntry e(buff); + + /* + ** Since the log entries' times ascend chronologically, we + ** can bail if we hit an entry that's older than the max age. + */ + if (e.age > age) + break; + + if (req_tags.empty()) + ret.insert(e); + else { + bool add = false; + for (set::const_iterator + t_iter = req_tags.begin() ; + t_iter != req_tags.end() ; + t_iter++) + { + if (e.tags.find(*t_iter) != e.tags.end()) { + add = true; + e.matched_tags.insert(*t_iter); + } + + if (add) + ret.insert(e); + } + } + } catch ( ... ) {} + } + } - return ret; + return ret; } --- conga/ricci/modules/log/LogParser.h 2007/09/11 02:45:28 1.4 +++ conga/ricci/modules/log/LogParser.h 2007/09/18 18:46:35 1.5 @@ -1,28 +1,27 @@ /* - Copyright Red Hat, Inc. 2006 - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, - MA 02139, USA. +** Copyright Red Hat, Inc. 2006-2007 +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License version 2 as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; see the file COPYING. If not, write to the +** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +** MA 02139, USA. */ + /* * Author: Stanko Kupcevic */ - -#ifndef LogParser_h -#define LogParser_h +#ifndef __CONGA_MODLOG_LOGPARSER_H +#define __CONGA_MODLOG_LOGPARSER_H #include "XML.h" @@ -30,42 +29,33 @@ #include #include - class LogEntry { - public: - LogEntry(const String& entry); - - long long age; - String domain; - String msg; - String pid; - - std::set tags; - std::set matched_tags; + public: + LogEntry(const String& entry); - XMLObject xml() const; + long long age; + String domain; + String msg; + String pid; - bool operator < (const LogEntry&) const; + std::set tags; + std::set matched_tags; - private: + XMLObject xml() const; - String compare_str() const; + bool operator < (const LogEntry&) const; + private: + String compare_str() const; }; - - class LogParser { - public: - - std::set get_entries(long long age, - const std::list& tags, - const std::list& paths); - - + public: + std::set get_entries( long long age, + const std::list& tags, + const std::list& paths); }; - -#endif // LogParser_h +#endif --- conga/ricci/modules/log/LoggingModule.cpp 2007/09/11 02:45:28 1.4 +++ conga/ricci/modules/log/LoggingModule.cpp 2007/09/18 18:46:35 1.5 @@ -1,136 +1,142 @@ /* - Copyright Red Hat, Inc. 2006 - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, - MA 02139, USA. +** Copyright Red Hat, Inc. 2006-2007 +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License version 2 as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; see the file COPYING. If not, write to the +** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +** MA 02139, USA. */ + /* * Author: Stanko Kupcevic */ - #include "LoggingModule.h" #include "LogParser.h" #include "utils.h" - using namespace std; - static VarMap get(const VarMap& args); static ApiFcnMap build_fcn_map(); - LoggingModule::LoggingModule() : - Module(build_fcn_map()) + Module(build_fcn_map()) {} LoggingModule::~LoggingModule() {} - ApiFcnMap build_fcn_map() { - FcnMap api_1_0; - api_1_0["get"] = get; + FcnMap api_1_0; + api_1_0["get"] = get; - ApiFcnMap api_fcn_map; - api_fcn_map["1.0"] = api_1_0; + ApiFcnMap api_fcn_map; + api_fcn_map["1.0"] = api_1_0; - return api_fcn_map; + return api_fcn_map; } - VarMap get(const VarMap& args) { - long long age; - list tags; - list paths; - bool intersection = false; - try { - VarMap::const_iterator iter = args.find("age"); - if (iter == args.end()) - throw APIerror("missing age variable"); - age = iter->second.get_int(); - - iter = args.find("tags"); - if (iter != args.end()) - tags = iter->second.get_list_str(); - - iter = args.find("paths"); - if (iter != args.end()) - paths = iter->second.get_list_str(); - - iter = args.find("intersection"); - if (iter != args.end()) - intersection = iter->second.get_bool(); - } catch ( String e ) { - throw APIerror(e); - } - - // clean up - - list t; - for (list::const_iterator iter = tags.begin(); - iter != tags.end(); - iter++) { - String s(utils::strip(utils::to_lower(*iter))); - if (s.size()) - t.push_back(s); - } - tags.swap(t); t.clear(); - for (list::const_iterator iter = paths.begin(); - iter != paths.end(); - iter++) { - String s(utils::strip(*iter)); - if (s.size()) - t.push_back(s); - } - paths.swap(t); - - // command - - set entries = LogParser().get_entries(age, - tags, - paths); - // union or intersection? - if (intersection) { - // LogParser::get returns union - set intersect; - for (set::const_iterator iter = entries.begin(); - iter != entries.end(); - iter++) - if (iter->matched_tags.size() == tags.size()) - intersect.insert(*iter); - entries.swap(intersect); - } - - // response - - list result_list; - for (set::const_iterator iter = entries.begin(); - iter != entries.end(); - iter++) - result_list.push_back(iter->xml()); - - Variable var("log_entries", result_list); - - VarMap ret; - ret.insert(pair(var.name(), var)); - return ret; + long long age; + list tags; + list paths; + bool intersection = false; + + try { + VarMap::const_iterator iter = args.find("age"); + if (iter == args.end()) + throw APIerror("missing age variable"); + age = iter->second.get_int(); + + iter = args.find("tags"); + if (iter != args.end()) + tags = iter->second.get_list_str(); + + iter = args.find("paths"); + if (iter != args.end()) + paths = iter->second.get_list_str(); + + iter = args.find("intersection"); + if (iter != args.end()) + intersection = iter->second.get_bool(); + } catch ( String e ) { + throw APIerror(e); + } + + // clean up + + list t; + for (list::const_iterator + iter = tags.begin() ; + iter != tags.end() ; + iter++) + { + String s(utils::strip(utils::to_lower(*iter))); + if (s.size()) + t.push_back(s); + } + + tags.swap(t); + t.clear(); + + for (list::const_iterator + iter = paths.begin() ; + iter != paths.end() ; + iter++) + { + String s(utils::strip(*iter)); + if (s.size()) + t.push_back(s); + } + paths.swap(t); + + // command + set entries = LogParser().get_entries(age, tags, paths); + + // union or intersection? + if (intersection) { + // LogParser::get returns union + set intersect; + + for (set::const_iterator + iter = entries.begin() ; + iter != entries.end() ; + iter++) + { + if (iter->matched_tags.size() == tags.size()) + intersect.insert(*iter); + } + entries.swap(intersect); + } + + // response + list result_list; + for (set::const_iterator + iter = entries.begin() ; + iter != entries.end() ; + iter++) + { + result_list.push_back(iter->xml()); + } + + Variable var("log_entries", result_list); + + VarMap ret; + ret.insert(pair(var.name(), var)); + return ret; } --- conga/ricci/modules/log/LoggingModule.h 2007/09/11 02:45:28 1.2 +++ conga/ricci/modules/log/LoggingModule.h 2007/09/18 18:46:35 1.3 @@ -1,41 +1,37 @@ /* - Copyright Red Hat, Inc. 2006 - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, - MA 02139, USA. +** Copyright Red Hat, Inc. 2006-2007 +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License version 2 as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; see the file COPYING. If not, write to the +** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +** MA 02139, USA. */ + /* * Author: Stanko Kupcevic */ - -#ifndef LoggingModule_h -#define LoggingModule_h +#ifndef __CONGA_MODLOG_LOGGINGMODLE_H +#define __CONGA_MODLOG_LOGGINGMODLE_H #include "Module.h" - class LoggingModule : public Module { - public: - LoggingModule(); - virtual ~LoggingModule(); - - private: + public: + LoggingModule(); + virtual ~LoggingModule(); + private: }; - -#endif // LoggingModule_h +#endif --- conga/ricci/modules/log/main.cpp 2007/09/11 02:45:28 1.4 +++ conga/ricci/modules/log/main.cpp 2007/09/18 18:46:35 1.5 @@ -1,21 +1,21 @@ /* - Copyright Red Hat, Inc. 2005 - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, - MA 02139, USA. +** Copyright Red Hat, Inc. 2006-2007 +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License version 2 as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; see the file COPYING. If not, write to the +** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +** MA 02139, USA. */ + /* * Author: Stanko Kupcevic */ @@ -24,18 +24,17 @@ #include "LoggingModule.h" #include + using namespace std; int -main(int argc, char** argv) +main(int argc, char **argv) { - try { - LoggingModule m; - return stdin_out_module_driver(m, - argc, - argv); - } catch (String e) { - cerr << e << endl; - return 1; - } + try { + LoggingModule m; + return stdin_out_module_driver(m, argc, argv); + } catch (String e) { + cerr << e << endl; + return 1; + } }