diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index 59290e17dd..d9f53f2932 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,35 @@ +2008-04-09 Esteban Sanchez + + * modules/pandora_data.[cc,h]: Added to repository. Implements a + Pandora_Data object, which holds a value and the timestamp when it + was created. + + * modules/pandora_module.[cc,h]: It holds now a list of Pandora_Data + objects. The XML is generated based on the size of this list. Output + property has became obsolete and child modules must use setOutput(). + + * modules/pandora_module_cpuusage.cc, + modules/pandora_module_exec.cc, + modules/pandora_module_freedisk.cc, + modules/pandora_module_freememory.cc, + modules/pandora_module_odbc.cc, modules/pandora_module_proc.cc, + modules/pandora_module_service.cc: Updated to new Pandora_Module + parent class. + + * modules/pandora_module_list.cc: Deleted debug output. + + * pandora.cc: Now uses SYSTEMTIME instead of old time_t. + + * pandora_windows_service.[cc,h]: Added Ramon Novoa to authors. Added + a new configuration token transfer_interval which sets the interval + where the data file will be sent to the server. If the current + interval token is lower than this transfer interval, the data will be + added into a data_list XML tag. + + * PandoraAgent.dev: Added new files. + + * bin/PandoraAgent.exe: Updated to last commit. + 2008-04-02 Esteban Sanchez * pandora_agent_conf.[cc,h]: Object adapted to be a singleton so it diff --git a/pandora_agents/win32/PandoraAgent.dev b/pandora_agents/win32/PandoraAgent.dev index b591dda2c4..1be1cecfb4 100644 --- a/pandora_agents/win32/PandoraAgent.dev +++ b/pandora_agents/win32/PandoraAgent.dev @@ -1,7 +1,7 @@ [Project] FileName=PandoraAgent.dev Name=PandoraAgent -UnitCount=71 +UnitCount=73 Type=1 Ver=1 ObjFiles= @@ -757,3 +757,23 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit72] +FileName=modules\pandora_data.h +CompileCpp=1 +Folder=Modules +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit73] +FileName=modules\pandora_data.cc +CompileCpp=1 +Folder=Modules +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/pandora_agents/win32/bin/PandoraAgent.exe b/pandora_agents/win32/bin/PandoraAgent.exe index 4d9b1c96e4..05e36536a1 100755 Binary files a/pandora_agents/win32/bin/PandoraAgent.exe and b/pandora_agents/win32/bin/PandoraAgent.exe differ diff --git a/pandora_agents/win32/modules/pandora_data.cc b/pandora_agents/win32/modules/pandora_data.cc new file mode 100644 index 0000000000..df22d55fcc --- /dev/null +++ b/pandora_agents/win32/modules/pandora_data.cc @@ -0,0 +1,89 @@ +/* Pandora data class to represent a value and a timestamp. + + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "pandora_data.h" + +using namespace Pandora; + +/** + * Pandora_Data constructor. + * + * Set all attributes + * + * @param value Data value. + * @param timestamp Timeestamp value. + */ +Pandora_Data::Pandora_Data (string value) { + this->value = value; + GetSystemTime (&(this->timestamp)); +} + +/** + * Pandora_Data default constructor + * + * Set all parameters to blank + */ +Pandora_Data::Pandora_Data () { + this->value = ""; + GetSystemTime (&(this->timestamp)); +} + +/** + * Destructor of Pandora_Data. + */ +Pandora_Data::~Pandora_Data () { +} + +/** + * Get value property of Pandora_Data object + * + * @return Value property. + */ +string +Pandora_Data::getValue () const { + return this->value; +} + +/** + * Get timestamp property of Pandora_Data object in a human readable format. + * + * @return Timestamp formatted. + */ +string +Pandora_Data::getTimestamp () const { + char strtime[20]; + string retval; + + sprintf (strtime, "%d-%02d-%02d %02d:%02d:%02d", this->timestamp.wYear, this->timestamp.wMonth, this->timestamp.wDay, + this->timestamp.wHour, this->timestamp.wMinute, this->timestamp.wSecond); + retval = strtime; + return retval; +} + +/** + * Set value property of Pandora_Data object + * + * @param value Value to set. + */ +void +Pandora_Data::setValue (string value) { + this->value = value; +} + diff --git a/pandora_agents/win32/modules/pandora_data.h b/pandora_agents/win32/modules/pandora_data.h new file mode 100644 index 0000000000..153f62e46b --- /dev/null +++ b/pandora_agents/win32/modules/pandora_data.h @@ -0,0 +1,50 @@ +/* Pandora data class to represent a value and a timestamp. + + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#ifndef __PANDORA_DATA_H__ +#define __PANDORA_DATA_H__ + +#include +#include + +using namespace std; + +namespace Pandora { + /** + * Class to implement the Pandora Windows service. + */ + class Pandora_Data { + private: + string value; + SYSTEMTIME timestamp; + public: + Pandora_Data (); + Pandora_Data (string value); + ~Pandora_Data (); + + string getValue () const; + string getTimestamp () const; + void setValue (string value); + }; +} + +#endif + diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index 63d4a71f45..2c3eb06596 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -37,10 +37,10 @@ Pandora_Module::Pandora_Module (string name) { this->module_name = name; this->executions = 0; this->module_interval = 1; - this->output = ""; this->max = 0; this->min = 0; this->has_limits = false; + this->data_list = NULL; } /** @@ -49,6 +49,28 @@ Pandora_Module::Pandora_Module (string name) { * Should be redefined by child classes. */ Pandora_Module::~Pandora_Module () { + this->cleanDataList (); +} + + +void +Pandora_Module::cleanDataList () { + Pandora_Data *data; + list::iterator iter; + + if (this->data_list) { + if (this->data_list->size () > 0) { + iter = this->data_list->begin (); + for (iter = this->data_list->begin (); + iter != this->data_list->end (); + iter++) { + data = *iter; + delete data; + } + } + delete this->data_list; + this->data_list = NULL; + } } /** @@ -174,31 +196,51 @@ Pandora_Module::getModuleType () const { * the interval range. */ string -Pandora_Module::getOutput () const { - switch (this->module_type) { - case TYPE_GENERIC_DATA: - case TYPE_GENERIC_DATA_INC: - case TYPE_GENERIC_PROC: - int value; - - try { - value = Pandora_Strutils::strtoint (this->output); - } catch (Pandora_Strutils::Invalid_Conversion e) { - throw Output_Error (); - } - - if (this->has_limits) { - if (value >= this->max || value <= this->min) { - throw Value_Error (); - } - } - - return Pandora_Strutils::inttostr (value); - default: - return this->output; - } +Pandora_Module::getDataOutput (Pandora_Data *data) { + int value; + + if (this->module_type == TYPE_GENERIC_DATA_STRING) { + return data->getValue (); + } + + try { + value = Pandora_Strutils::strtoint (data->getValue ()); + } catch (Pandora_Strutils::Invalid_Conversion e) { + pandoraLog ("Output error on module %s", + this->module_name.c_str ()); + throw Output_Error (); + } + + if (this->has_limits) { + if (value >= this->max || value <= this->min) { + pandoraLog ("The returned value was not in the interval on module %s", + this->module_name.c_str ()); + throw Value_Error (); + } + } + + return Pandora_Strutils::inttostr (value); } +/** + * Set the output of the module. + * + * If the function is called more than once before calling getXML, the + * output will be accumulated and added to a tag. + * + * @param output Output to add. + */ +void +Pandora_Module::setOutput (string output) { + Pandora_Data *data; + + if (this->data_list == NULL) + this->data_list = new list (); + data = new Pandora_Data (output); + this->data_list->push_back (data); +} + + /** * Run the module and generates the output. * @@ -211,9 +253,6 @@ Pandora_Module::getOutput () const { */ void Pandora_Module::run () { - - this->output = ""; - /* Check the interval */ if (this->executions % this->module_interval != 0) { pandoraDebug ("%s: Interval is not fulfilled", @@ -248,29 +287,18 @@ Pandora_Module::run () { */ TiXmlElement * Pandora_Module::getXml () { - string data; TiXmlElement *root; TiXmlElement *element; + TiXmlElement *data_list_element; + TiXmlElement *data_element; TiXmlText *text; - string item_str, data_str, desc_str; + string item_clean, data_clean, desc_clean; + Pandora_Data *data; + pandoraDebug ("%s getXML begin", module_name.c_str ()); - if (!this->has_output) { - return NULL; - } - - try { - data = this->getOutput (); - } catch (Output_Error e) { - pandoraLog ("Output error on module %s", - this->module_name.c_str ()); - - return NULL; - } catch (Value_Error e) { - pandoraLog ("The returned value was not in the interval on module %s", - this->module_name.c_str ()); - + if (!this->has_output || (this->data_list && this->data_list->size () < 1)) { return NULL; } @@ -289,22 +317,57 @@ Pandora_Module::getXml () { root->InsertEndChild (*element); delete element; delete text; - - element = new TiXmlElement ("data"); - data_str = strreplace (data, "%", "%%" ); - text = new TiXmlText (data_str); - element->InsertEndChild (*text); - root->InsertEndChild (*element); - delete text; - delete element; - + + if (this->data_list && this->data_list->size () > 1) { + list::iterator iter; + + data_list_element = new TiXmlElement ("data_list"); + + iter = this->data_list->begin (); + for (iter = this->data_list->begin (); + iter != this->data_list->end (); + iter++) { + data = *iter; + data_element = new TiXmlElement ("data"); + element = new TiXmlElement ("value"); + data_clean = strreplace (this->getDataOutput (data), "%", "%%" ); + text = new TiXmlText (data_clean); + element->InsertEndChild (*text); + data_element->InsertEndChild (*element); + delete text; + delete element; + + element = new TiXmlElement ("timestamp"); + text = new TiXmlText (data->getTimestamp ()); + element->InsertEndChild (*text); + data_element->InsertEndChild (*element); + delete text; + delete element; + + data_list_element->InsertEndChild (*data_element); + } + + root->InsertEndChild (*data_list_element); + delete data_list_element; + } else { + data = data_list->front (); + element = new TiXmlElement ("data"); + data_clean = strreplace (this->getDataOutput (data), "%", "%%" ); + text = new TiXmlText (data_clean); + element->InsertEndChild (*text); + root->InsertEndChild (*element); + delete text; + delete element; + } + element = new TiXmlElement ("description"); text = new TiXmlText (this->module_description); element->InsertEndChild (*text); root->InsertEndChild (*element); delete text; delete element; - + + this->cleanDataList (); pandoraDebug ("%s getXML end", module_name.c_str ()); return root; } diff --git a/pandora_agents/win32/modules/pandora_module.h b/pandora_agents/win32/modules/pandora_module.h index 88519a1854..1f23ce975c 100644 --- a/pandora_agents/win32/modules/pandora_module.h +++ b/pandora_agents/win32/modules/pandora_module.h @@ -22,10 +22,13 @@ #define __PANDORA_MODULE_H__ #include "../pandora.h" +#include "pandora_data.h" #include "../tinyxml/tinyxml.h" #include #include +using namespace Pandora; + /** * Definition of Pandora modules. */ @@ -69,13 +72,13 @@ namespace Pandora_Modules { MODULE_ODBC /**< The module performs a SQL query via ODBC */ } Module_Kind; - const string module_exec_str = "module_exec"; - const string module_proc_str = "module_proc"; - const string module_service_str = "module_service"; - const string module_freedisk_str = "module_freedisk"; - const string module_freememory_str = "module_freememory"; - const string module_cpuusage_str = "module_cpuusage"; - const string module_odbc_str = "module_odbc"; + const string module_exec_str = "module_exec"; + const string module_proc_str = "module_proc"; + const string module_service_str = "module_service"; + const string module_freedisk_str = "module_freedisk"; + const string module_freememory_str = "module_freememory"; + const string module_cpuusage_str = "module_cpuusage"; + const string module_odbc_str = "module_odbc"; /** * Pandora module super-class exception. @@ -104,19 +107,19 @@ namespace Pandora_Modules { */ class Pandora_Module { private: - int module_interval; - int executions; - int max, min; - bool has_limits; - string module_type_str; - Module_Type module_type; - string module_kind_str; - Module_Kind module_kind; + int module_interval; + int executions; + int max, min; + bool has_limits; + string module_type_str; + Module_Type module_type; + string module_kind_str; + Module_Kind module_kind; + list *data_list; + + string getDataOutput (Pandora_Data *data); + void cleanDataList (); protected: - /** - * Module output generated at execution. - */ - string output; /** * Indicates if the module generated output in * his last execution. @@ -146,7 +149,7 @@ namespace Pandora_Modules { virtual void run (); - virtual string getOutput () const; + virtual void setOutput (string output); string getName () const; string getDescription () const; diff --git a/pandora_agents/win32/modules/pandora_module_cpuusage.cc b/pandora_agents/win32/modules/pandora_module_cpuusage.cc index e72f7f3cbd..a6c91ae0a7 100644 --- a/pandora_agents/win32/modules/pandora_module_cpuusage.cc +++ b/pandora_agents/win32/modules/pandora_module_cpuusage.cc @@ -54,7 +54,7 @@ Pandora_Module_Cpuusage::run () { try { res = Pandora_Wmi::getCpuUsagePercentage (this->cpu_id); - this->output = inttostr (res); + this->setOutput (inttostr (res)); } catch (Pandora_Wmi::Pandora_Wmi_Exception e) { this->has_output = false; } diff --git a/pandora_agents/win32/modules/pandora_module_exec.cc b/pandora_agents/win32/modules/pandora_module_exec.cc index c3e0cbf2e2..bde84b1b10 100644 --- a/pandora_agents/win32/modules/pandora_module_exec.cc +++ b/pandora_agents/win32/modules/pandora_module_exec.cc @@ -140,12 +140,14 @@ Pandora_Module_Exec::run () { PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL); /* Read from the stdout */ if (read != 0) { + string output; do { ReadFile (out_read, buffer, BUFSIZE, &read, NULL); buffer[read] = '\0'; - this->output += (char *) buffer; + output += (char *) buffer; } while (read >= BUFSIZE); + this->setOutput (output); } /* Close job, process and thread handles. */ diff --git a/pandora_agents/win32/modules/pandora_module_freedisk.cc b/pandora_agents/win32/modules/pandora_module_freedisk.cc index 825066cf71..7bd2d9f9cf 100644 --- a/pandora_agents/win32/modules/pandora_module_freedisk.cc +++ b/pandora_agents/win32/modules/pandora_module_freedisk.cc @@ -59,7 +59,7 @@ Pandora_Module_Freedisk::run () { try { res = Pandora_Wmi::getDiskFreeSpace (this->disk_id); - this->output = longtostr (res); + this->setOutput (longtostr (res)); } catch (Pandora_Wmi::Pandora_Wmi_Exception e) { this->has_output = false; } diff --git a/pandora_agents/win32/modules/pandora_module_freememory.cc b/pandora_agents/win32/modules/pandora_module_freememory.cc index d8992adc2b..be7aaacf01 100644 --- a/pandora_agents/win32/modules/pandora_module_freememory.cc +++ b/pandora_agents/win32/modules/pandora_module_freememory.cc @@ -51,7 +51,7 @@ Pandora_Module_Freememory::run () { try { res = Pandora_Wmi::getFreememory (); - this->output = longtostr (res); + this->setOutput (longtostr (res)); } catch (Pandora_Wmi::Pandora_Wmi_Exception e) { this->has_output = false; } diff --git a/pandora_agents/win32/modules/pandora_module_list.cc b/pandora_agents/win32/modules/pandora_module_list.cc index d7c95dba28..567a0daa55 100644 --- a/pandora_agents/win32/modules/pandora_module_list.cc +++ b/pandora_agents/win32/modules/pandora_module_list.cc @@ -156,10 +156,8 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition) case MODULE_ODBC: module_odbc = (Pandora_Module_Odbc *) module; modules->push_back (module_odbc); - cout << "ASDS" << endl; break; default: - cout << "NONE" << endl; break; } } diff --git a/pandora_agents/win32/modules/pandora_module_odbc.cc b/pandora_agents/win32/modules/pandora_module_odbc.cc index 30dfe26641..550570a973 100755 --- a/pandora_agents/win32/modules/pandora_module_odbc.cc +++ b/pandora_agents/win32/modules/pandora_module_odbc.cc @@ -154,13 +154,16 @@ Pandora_Module_Odbc::doQuery () { if (results->next ()) { if (this->getTypeInt () == TYPE_GENERIC_DATA_STRING) { + string output; for (int i = 1; i <= columns; i++) { - this->output += results->getString (i); + output += results->getString (i); if (i + 1 <= columns) - this->output += " | "; + output += " | "; } + + this->setOutput (output); } else { - this->output = longtostr (results->getLong (1)); + this->setOutput (longtostr (results->getLong (1))); } } } diff --git a/pandora_agents/win32/modules/pandora_module_proc.cc b/pandora_agents/win32/modules/pandora_module_proc.cc index e2d06b87ad..48431cf621 100644 --- a/pandora_agents/win32/modules/pandora_module_proc.cc +++ b/pandora_agents/win32/modules/pandora_module_proc.cc @@ -56,5 +56,5 @@ Pandora_Module_Proc::run () { res = Pandora_Wmi::isProcessRunning (this->process_name); - this->output = inttostr (res); + this->setOutput (inttostr (res)); } diff --git a/pandora_agents/win32/modules/pandora_module_service.cc b/pandora_agents/win32/modules/pandora_module_service.cc index 881d84be95..1d1034f081 100644 --- a/pandora_agents/win32/modules/pandora_module_service.cc +++ b/pandora_agents/win32/modules/pandora_module_service.cc @@ -57,5 +57,5 @@ Pandora_Module_Service::run () { } res = Pandora_Wmi::isServiceRunning (this->service_name); - this->output = inttostr (res); + this->setOutput (inttostr (res)); } diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 6ca117900b..3a3b62fd71 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -101,12 +101,11 @@ pandoraWriteLog (string filename, string line) { char str_time[25]; FILE *file; string filepath; - time_t now; - struct tm *gmtime; + SYSTEMTIME st; - now = time (0); - gmtime = localtime (&now); - strftime (str_time, 25, "%m-%d-%y %H:%M:%S: ", gmtime); + GetSystemTime(&st); + sprintf (str_time, "%d-%02d-%02d %02d:%02d:%02d ", st.wYear, st.wMonth, st.wDay, + st.wHour, st.wMinute, st.wSecond); buffer = (char *) str_time; buffer += line; diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 9b5f4a6a43..9a4e5bc2f3 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -1,7 +1,7 @@ /* Pandora agents service for Win32. Copyright (C) 2006 Artica ST. - Written by Esteban Sanchez. + Written by Esteban Sanchez, Ramon Novoa. 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 @@ -56,9 +56,13 @@ Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name, &Pandora_Windows_Service::pandora_init); this->setRunFunction ((void (Windows_Service::*) ()) &Pandora_Windows_Service::pandora_run); - execution_number = 0; - this->modules = NULL; - this->conf = NULL; + + execution_number = 0; + this->modules = NULL; + this->conf = NULL; + this->interval = 60000; + this->transfer_interval = this->interval; + this->elapsed_transfer_time = 0; } /** @@ -72,7 +76,7 @@ Pandora_Windows_Service::~Pandora_Windows_Service () { if (this->modules != NULL) { delete this->modules; } - pandoraLog ("Pandora agent stopped"); + pandoraLog ("Pandora agent stopped"); } bool @@ -94,8 +98,7 @@ is_enabled (string value) { void Pandora_Windows_Service::pandora_init () { - int interval_ms = 60000; - string conf_file, interval, debug; + string conf_file, interval, debug, transfer_interval; setPandoraDebug (true); @@ -106,22 +109,35 @@ Pandora_Windows_Service::pandora_init () { this->conf->setFile (conf_file); this->modules = new Pandora_Module_List (conf_file); - /* Get the interval value (in minutes) and set it to the service */ + /* Get the interval value (in seconds) and set it to the service */ interval = conf->getValue ("interval"); - + transfer_interval = conf->getValue ("transfer_interval"); + debug = conf->getValue ("debug"); setPandoraDebug (is_enabled (debug)); if (interval != "") { try { /* miliseconds */ - interval_ms = strtoint (interval) * 1000; + this->interval = strtoint (interval) * 1000; } catch (Invalid_Conversion e) { } } + if (transfer_interval == "") { + this->transfer_interval = this->interval; + } else { + try { + /* miliseconds */ + this->transfer_interval = strtoint (transfer_interval) * 1000; + } catch (Invalid_Conversion e) { + this->transfer_interval = this->interval; + } + } + cout << "trans: " << this->transfer_interval << endl; + srand ((unsigned) time (0)); - this->setSleepTime (interval_ms); + this->setSleepTime (this->interval); pandoraLog ("Pandora agent started"); } @@ -165,10 +181,10 @@ void Pandora_Windows_Service::copyTentacleDataFile (string host, string filename) { - int rc; - string var, filepath; - string pubkey_file, privkey_file; - string tentacle_cmd; + int rc; + string var, filepath; + string pubkey_file, privkey_file; + string tentacle_cmd; var = conf->getValue ("temporal"); if (var[var.length () - 1] != '\\') { @@ -363,76 +379,93 @@ Pandora_Windows_Service::pandora_run () { TiXmlDocument *doc; TiXmlElement *local_xml, *agent; string xml_filename, random_integer; - string tmp_filename, tmp_filepath, interval; + string tmp_filename, tmp_filepath; bool saved; pandoraDebug ("Run begin"); - agent = getXmlHeader (); - execution_number++; - + if (this->modules != NULL) { this->modules->goFirst (); while (! this->modules->isLast ()) { Pandora_Module *module; - string result; module = this->modules->getCurrentValue (); pandoraDebug ("Run %s", module->getName ().c_str ()); module->run (); - - local_xml = module->getXml (); - if (local_xml != NULL) { - agent->InsertEndChild (*local_xml); - - delete local_xml; - } + this->modules->goNext (); } } - - random_integer = inttostr (rand()); - tmp_filename = conf->getValue ("agent_name"); - if (tmp_filename == "") { - tmp_filename = Pandora_Windows_Info::getSystemName (); - } - tmp_filename += "." + random_integer + ".data"; + + this->elapsed_transfer_time += interval; + cout << "interval time: " << interval << " transfer time:" << this->transfer_interval << " time passed: " << this->elapsed_transfer_time << endl; + if (this->elapsed_transfer_time >= this->transfer_interval) { + agent = getXmlHeader (); + + if (this->modules != NULL) { + this->modules->goFirst (); + + while (! this->modules->isLast ()) { + Pandora_Module *module; + + module = this->modules->getCurrentValue (); + + local_xml = module->getXml (); + if (local_xml != NULL) { + agent->InsertEndChild (*local_xml); + + delete local_xml; + } + this->modules->goNext (); + } + } + + this->elapsed_transfer_time = 0; + /* Generate temporal filename */ + random_integer = inttostr (rand()); + tmp_filename = conf->getValue ("agent_name"); + if (tmp_filename == "") { + tmp_filename = Pandora_Windows_Info::getSystemName (); + } + tmp_filename += "." + random_integer + ".data"; - xml_filename = conf->getValue ("temporal"); - if (xml_filename[xml_filename.length () - 1] != '\\') { - xml_filename += "\\"; - } - tmp_filepath = xml_filename + tmp_filename; + xml_filename = conf->getValue ("temporal"); + if (xml_filename[xml_filename.length () - 1] != '\\') { + xml_filename += "\\"; + } + tmp_filepath = xml_filename + tmp_filename; - /* Copy the XML to a temporal file */ - pandoraDebug ("Copying XML on %s", tmp_filepath.c_str ()); - doc = new TiXmlDocument (tmp_filepath); - doc->InsertEndChild (*agent); - saved = doc->SaveFile(); - delete doc; - delete agent; + /* Copy the XML to temporal file */ + pandoraDebug ("Copying XML on %s", tmp_filepath.c_str ()); + doc = new TiXmlDocument (tmp_filepath); + doc->InsertEndChild (*agent); + saved = doc->SaveFile(); + delete doc; + delete agent; - if (!saved) { - pandoraLog ("Error when saving the XML in %s", - tmp_filepath.c_str ()); - return; - } + if (!saved) { + pandoraLog ("Error when saving the XML in %s", + tmp_filepath.c_str ()); + return; + } - if (getPandoraDebug () == false) { - this->copyDataFile (tmp_filename); + /* Only send if debug is not activated */ + if (getPandoraDebug () == false) { + this->copyDataFile (tmp_filename); - try { - Pandora_File::removeFile (tmp_filepath); - } catch (Pandora_File::Delete_Error e) { - } + try { + Pandora_File::removeFile (tmp_filepath); + } catch (Pandora_File::Delete_Error e) { + } + } } /* Get the interval value (in minutes) */ - interval = conf->getValue ("interval"); - pandoraDebug ("Next execution on %s seconds", interval.c_str ()); + pandoraDebug ("Next execution on %d seconds", this->interval / 1000); return; } diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index 75c068b7f3..994d729a97 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -29,6 +29,7 @@ #include "ssh/pandora_ssh_client.h" using namespace std; +using namespace Pandora_Modules; namespace Pandora { /** @@ -36,10 +37,13 @@ namespace Pandora { */ class Pandora_Windows_Service : public Windows_Service { private: - Pandora_Agent_Conf *conf; - Pandora_Modules::Pandora_Module_List *modules; - long execution_number; - string agent_name; + Pandora_Agent_Conf *conf; + Pandora_Module_List *modules; + long execution_number; + string agent_name; + long interval; + long elapsed_transfer_time; + long transfer_interval; TiXmlElement *getXmlHeader (); void copyDataFile (string filename); @@ -51,7 +55,7 @@ namespace Pandora { void copyFtpDataFile (string host, string remote_path, string filename); - + public: void pandora_run (); void pandora_init (); public: