2013-01-17 Ramon Novoa <rnovoa@artica.es>

* 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
This commit is contained in:
Ramon Novoa 2013-01-17 14:33:54 +00:00
parent 7af1adc734
commit 6e1d816b47
5 changed files with 60 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2013-01-17 Ramon Novoa <rnovoa@artica.es>
* 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 <rnovoa@artica.es> 2012-12-12 Ramon Novoa <rnovoa@artica.es>
* modules/pandora_module_logevent.cc: Changed the flags of * modules/pandora_module_logevent.cc: Changed the flags of

View File

@ -209,6 +209,8 @@ Pandora_Module::parseModuleTypeFromString (string type) {
return TYPE_ASYNC_PROC; return TYPE_ASYNC_PROC;
} else if (type == module_async_string_str) { } else if (type == module_async_string_str) {
return TYPE_ASYNC_STRING; return TYPE_ASYNC_STRING;
} else if (type == module_log_str) {
return TYPE_LOG;
} else { } else {
return TYPE_0; return TYPE_0;
} }
@ -351,7 +353,7 @@ Pandora_Module::getDataOutput (Pandora_Data *data) {
double value; double value;
if (this->module_type == TYPE_GENERIC_DATA_STRING || 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 (); return data->getValue ();
} }
@ -508,6 +510,48 @@ Pandora_Module::getXml () {
return ""; return "";
} }
/* Log module */
if (this->module_type == TYPE_LOG) {
module_xml = "<log_module>\n\t<source><![CDATA[";
module_xml += this->module_name;
module_xml += "]]></source>\n\t<data><![CDATA[";
if (this->data_list && this->data_list->size () > 1) {
list<Pandora_Data *>::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 += "]]></data></log_module>";
/* Clean up */
this->cleanDataList ();
pandoraDebug ("%s getXML end", module_name.c_str ());
return module_xml;
}
/* Compose the module XML */ /* Compose the module XML */
module_xml = "<module>\n\t<name><![CDATA["; module_xml = "<module>\n\t<name><![CDATA[";
module_xml += this->module_name; module_xml += this->module_name;

View File

@ -49,7 +49,8 @@ namespace Pandora_Modules {
TYPE_GENERIC_DATA_STRING, /**< The value is a string */ TYPE_GENERIC_DATA_STRING, /**< The value is a string */
TYPE_ASYNC_DATA, /**< Asynchronous generic_data */ TYPE_ASYNC_DATA, /**< Asynchronous generic_data */
TYPE_ASYNC_PROC, /**< Asynchronous generic_proc */ TYPE_ASYNC_PROC, /**< Asynchronous generic_proc */
TYPE_ASYNC_STRING /**< Asynchronous generic_data_string */ TYPE_ASYNC_STRING, /**< Asynchronous generic_data_string */
TYPE_LOG /**< Log data */
} Module_Type; } Module_Type;
const string module_generic_data_str = "generic_data"; const string module_generic_data_str = "generic_data";
@ -59,6 +60,7 @@ namespace Pandora_Modules {
const string module_async_data_str = "async_data"; const string module_async_data_str = "async_data";
const string module_async_proc_str = "async_proc"; const string module_async_proc_str = "async_proc";
const string module_async_string_str = "async_string"; const string module_async_string_str = "async_string";
const string module_log_str = "log";
/** /**
* Defines the kind of the module. * Defines the kind of the module.

View File

@ -752,6 +752,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
break; break;
case TYPE_GENERIC_DATA_STRING: case TYPE_GENERIC_DATA_STRING:
case TYPE_ASYNC_STRING: case TYPE_ASYNC_STRING:
case TYPE_LOG:
module->setType (module_type); module->setType (module_type);
numeric = false; numeric = false;

View File

@ -122,13 +122,15 @@ Pandora_Module_Regexp::run () {
if (regexec (&this->regexp, line.c_str (), 0, NULL, 0) == 0) { if (regexec (&this->regexp, line.c_str (), 0, NULL, 0) == 0) {
if (type == TYPE_GENERIC_DATA_STRING || type == TYPE_ASYNC_STRING) { if (type == TYPE_GENERIC_DATA_STRING || type == TYPE_ASYNC_STRING) {
this->setOutput (line); this->setOutput (line);
} } else if (type == TYPE_LOG) {
this->setOutput (line + '\n');
}
count++; count++;
} }
} }
// Set output according to the module type // 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 // Already set
} }
else if (type == TYPE_GENERIC_PROC || type == TYPE_ASYNC_PROC) { else if (type == TYPE_GENERIC_PROC || type == TYPE_ASYNC_PROC) {