diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index ad49b49638..9236d28cb0 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,12 @@ +2011-03-01 Ramon Novoa + + * win32/modules/pandora_module.h, + win32/modules/pandora_module_factory.cc, + win32/modules/pandora_module.cc, + unix/pandora_agent, + shellscript/linux/pandora_agent: Set the module min, max and + post_process in the XML data file. + 2011-02-14 Ramon Novoa * embedded/INSTALL: Added instructions to cross-compile for diff --git a/pandora_agents/shellscript/linux/pandora_agent b/pandora_agents/shellscript/linux/pandora_agent index ba9ca3e6d4..25aa28920a 100755 --- a/pandora_agents/shellscript/linux/pandora_agent +++ b/pandora_agents/shellscript/linux/pandora_agent @@ -618,7 +618,7 @@ do if [ ! -z "`echo $a | grep -e '^module_postprocess'`" ] then pprocess=`echo $a | cut -d" " -f2-` - echo "" >> $DATA2 + echo "" >> $DATA2 fi # If module ends, and execute for this module is enabled diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 4cbf031866..a076a0f406 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -311,9 +311,9 @@ sub read_config (;$) { 'interval' => 1, 'timeout' => 0, 'counter' => 0, - 'max' => 0, - 'min' => 0, - 'postprocess' => 0, + 'max' => undef, + 'min' => undef, + 'post_process' => undef, 'save' => '', 'conditions' => [], 'cron' => '', @@ -353,10 +353,12 @@ sub read_config (;$) { } elsif ($line =~ /^\s*module_freepercentdisk\s+(.*)$/) { $module->{'func'} = \&module_freepercentdisk; $module->{'params'} = $1; - } elsif ($line =~ /^\s*module_max\s+(\d+)\s*$/) { - $module->{'max'} = $1; - } elsif ($line =~ /^\s*module_min\s+(\d+)\s*$/) { + } elsif ($line =~ /^\s*module_max\s+(.*)\s*$/) { $module->{'max'} = $1; + } elsif ($line =~ /^\s*module_min\s+(.*)\s*$/) { + $module->{'min'} = $1; + } elsif ($line =~ /^\s*module_post_process\s+(.*)\s*$/) { + $module->{'post_process'} = $1; } elsif ($line =~ /^\s*module_interval\s+(\d+)\s*$/) { $module->{'interval'} = $1; @@ -1211,9 +1213,17 @@ sub write_module_xml ($@) { " {'description'} . "]]>\n" . " " . $module->{'type'} . "\n"; - if ($module->{'interval'} > 1) { - $Xml .= " " . $module->{'interval'} . "\n"; - } + # Interval + $Xml .= " " . $module->{'interval'} . "\n" if ($module->{'interval'} > 1); + + # Min + $Xml .= " " . $module->{'min'} . "\n" if (defined ($module->{'min'})); + + # Max + $Xml .= " " . $module->{'max'} . "\n" if (defined ($module->{'max'})); + + # Post process + $Xml .= " " . $module->{'post_process'} . "\n" if (defined ($module->{'post_process'})); # Data list if ($#data > 0) { diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index 3cdf8fabc4..0dcee764dc 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -43,7 +43,10 @@ Pandora_Module::Pandora_Module (string name) { this->module_timeout = 15000; this->max = 0; this->min = 0; + this->post_process = ""; this->has_limits = false; + this->has_min = false; + this->has_max = false; this->async = false; this->data_list = NULL; this->inventory_list = NULL; @@ -418,7 +421,7 @@ Pandora_Module::run () { */ string Pandora_Module::getXml () { - ostringstream module_interval; + ostringstream module_interval, min, max; string module_xml, data_clean, interval_str; Pandora_Data *data; @@ -435,17 +438,44 @@ Pandora_Module::getXml () { module_xml += "]]>\n\tmodule_type_str; module_xml += "]]>\n"; + + /* Description */ if (this->module_description != "") { module_xml += "\tmodule_description; module_xml += "]]>\n"; } + + /* Interval */ if (this->module_interval > 1) { module_interval << this->module_interval; module_xml += "\t\n"; } + + /* Min */ + if (this->has_min) { + min << this->min; + module_xml += "\t\n"; + } + + /* Max */ + if (this->has_max) { + max << this->max; + module_xml += "\t\n"; + } + + /* Post process */ + if (this->post_process != "") { + module_xml += "\tpost_process; + module_xml += "]]>\n"; + } /* Write module data */ if (this->data_list && this->data_list->size () > 1) { @@ -505,6 +535,7 @@ Pandora_Module::getXml () { void Pandora_Module::setMax (int value) { this->has_limits = true; + this->has_max = true; this->max = value; } @@ -518,9 +549,20 @@ Pandora_Module::setMax (int value) { void Pandora_Module::setMin (int value) { this->has_limits = true; + this->has_min = true; this->min = value; } +/** + * Set the post process value for the module. + * + * @param value Post process value . + */ +void +Pandora_Module::setPostProcess (string value) { + this->post_process = value; +} + /** * Set the async flag to the module. * diff --git a/pandora_agents/win32/modules/pandora_module.h b/pandora_agents/win32/modules/pandora_module.h index b79e5ce522..536407a0d5 100644 --- a/pandora_agents/win32/modules/pandora_module.h +++ b/pandora_agents/win32/modules/pandora_module.h @@ -158,7 +158,8 @@ namespace Pandora_Modules { int module_timeout; int executions; int max, min; - bool has_limits; + string post_process; + bool has_limits, has_min, has_max; Module_Type module_type; string module_kind_str; Module_Kind module_kind; @@ -242,6 +243,7 @@ namespace Pandora_Modules { void setDescription (string description); void setMax (int value); void setMin (int value); + void setPostProcess (string value); void setAsync (bool async); void setSave (string save); diff --git a/pandora_agents/win32/modules/pandora_module_factory.cc b/pandora_agents/win32/modules/pandora_module_factory.cc index ee3362274e..5229e5b43a 100644 --- a/pandora_agents/win32/modules/pandora_module_factory.cc +++ b/pandora_agents/win32/modules/pandora_module_factory.cc @@ -58,6 +58,7 @@ using namespace Pandora_Strutils; #define TOKEN_ODBC ("module_odbc ") #define TOKEN_MAX ("module_max ") #define TOKEN_MIN ("module_min ") +#define TOKEN_POST_PROCESS ("module_post_process ") #define TOKEN_DESCRIPTION ("module_description ") #define TOKEN_ODBC_QUERY ("module_odbc_query ") #define TOKEN_LOGEVENT ("module_logevent") @@ -127,7 +128,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { string module_perfcounter, module_tcpcheck; string module_port, module_timeout, module_regexp; string module_plugin, module_save, module_condition; - string module_crontab, module_cron_interval; + string module_crontab, module_cron_interval, module_post_process; Pandora_Module *module; bool numeric; Module_Type type; @@ -170,6 +171,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { module_condition = ""; module_crontab = ""; module_cron_interval = ""; + module_post_process = ""; stringtok (tokens, definition, "\n"); @@ -225,6 +227,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { if (module_min == "") { module_min = parseLine (line, TOKEN_MIN); } + if (module_post_process == "") { + module_post_process = parseLine (line, TOKEN_POST_PROCESS); + } if (module_description == "") { module_description = parseLine (line, TOKEN_DESCRIPTION); } @@ -509,5 +514,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { } } + if (module_post_process != "") { + module->setPostProcess (module_post_process); + } + return module; }