From 6e1d816b478a8d96d30b583ef7dc4ab54ce35f9b Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 17 Jan 2013 14:33:54 +0000 Subject: [PATCH] 2013-01-17 Ramon Novoa * modules/pandora_module.cc, modules/pandora_module.h, modules/pandora_module_factory.cc, modules/pandora_module_regexp.cc: Added support for log modules. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7497 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/win32/ChangeLog | 7 +++ .../win32/modules/pandora_module.cc | 46 ++++++++++++++++++- pandora_agents/win32/modules/pandora_module.h | 4 +- .../win32/modules/pandora_module_factory.cc | 1 + .../win32/modules/pandora_module_regexp.cc | 6 ++- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index 2c2d4d9de2..eff1272ae3 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,10 @@ +2013-01-17 Ramon Novoa + + * modules/pandora_module.cc, + modules/pandora_module.h, + modules/pandora_module_factory.cc, + modules/pandora_module_regexp.cc: Added support for log modules. + 2012-12-12 Ramon Novoa * modules/pandora_module_logevent.cc: Changed the flags of diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index 43f15a1f4f..355b0785fc 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -209,6 +209,8 @@ Pandora_Module::parseModuleTypeFromString (string type) { return TYPE_ASYNC_PROC; } else if (type == module_async_string_str) { return TYPE_ASYNC_STRING; + } else if (type == module_log_str) { + return TYPE_LOG; } else { return TYPE_0; } @@ -351,7 +353,7 @@ Pandora_Module::getDataOutput (Pandora_Data *data) { double value; if (this->module_type == TYPE_GENERIC_DATA_STRING || - this->module_type == TYPE_ASYNC_STRING) { + this->module_type == TYPE_ASYNC_STRING || this->module_type == TYPE_LOG) { return data->getValue (); } @@ -507,6 +509,48 @@ Pandora_Module::getXml () { if (!this->has_output || this->data_list == NULL) { return ""; } + + /* Log module */ + if (this->module_type == TYPE_LOG) { + module_xml = "\n\tmodule_name; + module_xml += "]]>\n\tdata_list && this->data_list->size () > 1) { + list::iterator iter; + + iter = this->data_list->begin (); + for (iter = this->data_list->begin (); + iter != this->data_list->end (); + iter++) { + data = *iter; + + try { + data_clean = strreplace (this->getDataOutput (data), + "%", "%%" ); + } catch (Output_Error e) { + continue; + } + + module_xml += data_clean; + } + } else { + data = data_list->front (); + try { + data_clean = strreplace (this->getDataOutput (data), "%", "%%" ); + module_xml += data_clean; + + } catch (Output_Error e) { + } + } + module_xml += "]]>"; + + /* Clean up */ + this->cleanDataList (); + + pandoraDebug ("%s getXML end", module_name.c_str ()); + return module_xml; + } /* Compose the module XML */ module_xml = "\n\tsetType (module_type); numeric = false; diff --git a/pandora_agents/win32/modules/pandora_module_regexp.cc b/pandora_agents/win32/modules/pandora_module_regexp.cc index 2b5778cca4..da3511fe28 100755 --- a/pandora_agents/win32/modules/pandora_module_regexp.cc +++ b/pandora_agents/win32/modules/pandora_module_regexp.cc @@ -122,13 +122,15 @@ Pandora_Module_Regexp::run () { if (regexec (&this->regexp, line.c_str (), 0, NULL, 0) == 0) { if (type == TYPE_GENERIC_DATA_STRING || type == TYPE_ASYNC_STRING) { this->setOutput (line); - } + } else if (type == TYPE_LOG) { + this->setOutput (line + '\n'); + } count++; } } // Set output according to the module type - if (type == TYPE_GENERIC_DATA_STRING || type == TYPE_ASYNC_STRING) { + if (type == TYPE_GENERIC_DATA_STRING || type == TYPE_ASYNC_STRING || type == TYPE_LOG) { // Already set } else if (type == TYPE_GENERIC_PROC || type == TYPE_ASYNC_PROC) {