2006-06-20 19:05:19 +02:00
|
|
|
/* Pandora agents service for Win32.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Artica ST.
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
Written by Esteban Sanchez, Ramon Novoa.
|
2006-06-20 19:05:19 +02:00
|
|
|
|
|
|
|
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_windows_service.h"
|
|
|
|
#include "pandora.h"
|
2006-07-04 16:07:08 +02:00
|
|
|
#include "pandora_strutils.h"
|
2006-06-20 19:05:19 +02:00
|
|
|
#include "windows_service.h"
|
|
|
|
#include "modules/pandora_module_factory.h"
|
2006-07-04 16:07:08 +02:00
|
|
|
#include "ssh/pandora_ssh_client.h"
|
2007-08-07 16:28:14 +02:00
|
|
|
#include "ftp/pandora_ftp_client.h"
|
2006-07-04 16:07:08 +02:00
|
|
|
#include "misc/pandora_file.h"
|
|
|
|
#include "windows/pandora_windows_info.h"
|
2006-06-20 19:05:19 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <ctime>
|
2008-06-10 11:50:29 +02:00
|
|
|
#include <direct.h>
|
2006-06-20 19:05:19 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Pandora;
|
|
|
|
using namespace Pandora_Modules;
|
2006-07-04 16:07:08 +02:00
|
|
|
using namespace Pandora_Strutils;
|
2006-06-20 19:05:19 +02:00
|
|
|
|
2006-07-05 16:02:05 +02:00
|
|
|
string enabled_values[] = {"enabled", "1", "on", "yes", "si", "sí", "ok", ""};
|
|
|
|
|
2006-08-15 Esteban Sanchez <estebans@artica.es>
* autogen.sh, configure.in, Makefile.am, Doxyfile.in: Added to
repository. They are used to generate documentation, not to compile.
* main.cc: Added some comments. Style correction.
* pandora.[cc,h]: Added documentation comments. Changed visibility of
some attributes.
* pandora_agent_conf.[cc,h]: Added to Pandora namespace. Added
documentation comments.
* pandora_windows_service.[cc,h], pandora_strutils.[cc,h],
windows/pandora_windows_infp.[cc,h], ssh/pandora_ssh_test.[cc,h]:
Added documentation comments.
* ssh/pandora_ssh_client.[cc,h]:Added documentation comments. Removed
old method to connect with user and password. Style correction.
* misc/pandora_file.[cc,h]: Added documentation comments. Renamed some
parameters.
* modules/pandora_module.[cc,h]: Added documentation comments. Put a
name to the enumerators. Added a new class to agroupate all exceptions
produced by Pandora_Module child class objects. Changed visibility of
some attributes. Added some new methods and renamed others.
* modules/pandora_module_cpuusage.[cc,h],
modules/pandora_module_exec.[cc,h],
modules/pandora_module_freememory.[cc,h],
modules/pandora_module_freedisk.[cc,h], modules/pandora_module_proc.[cc,h],
modules/pandora_module_service.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes.
* modules/pandora_module_list.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes. Added
to Pandora_Modules namespace.
* windows/pandora_windows_wmi.[cc,h]: Added documentation comments.
Renamed Pandora_Wmi_Error to Pandora_Wmi_Exception.
* windows_service.[cc,h]: Added documentation comments. Changed
visibility of some attributes. Style correction.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@150 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2006-08-25 15:02:03 +02:00
|
|
|
/**
|
|
|
|
* Creates a new Pandora_Windows_Service.
|
|
|
|
*
|
|
|
|
* @param svc_name Internal service name
|
|
|
|
* @param svc_display_name Service name that will appear in the
|
|
|
|
* Windows service administration tool.
|
|
|
|
* @param svc_description Long description of the service.
|
|
|
|
*/
|
2006-06-20 19:05:19 +02:00
|
|
|
Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name,
|
2006-08-15 Esteban Sanchez <estebans@artica.es>
* autogen.sh, configure.in, Makefile.am, Doxyfile.in: Added to
repository. They are used to generate documentation, not to compile.
* main.cc: Added some comments. Style correction.
* pandora.[cc,h]: Added documentation comments. Changed visibility of
some attributes.
* pandora_agent_conf.[cc,h]: Added to Pandora namespace. Added
documentation comments.
* pandora_windows_service.[cc,h], pandora_strutils.[cc,h],
windows/pandora_windows_infp.[cc,h], ssh/pandora_ssh_test.[cc,h]:
Added documentation comments.
* ssh/pandora_ssh_client.[cc,h]:Added documentation comments. Removed
old method to connect with user and password. Style correction.
* misc/pandora_file.[cc,h]: Added documentation comments. Renamed some
parameters.
* modules/pandora_module.[cc,h]: Added documentation comments. Put a
name to the enumerators. Added a new class to agroupate all exceptions
produced by Pandora_Module child class objects. Changed visibility of
some attributes. Added some new methods and renamed others.
* modules/pandora_module_cpuusage.[cc,h],
modules/pandora_module_exec.[cc,h],
modules/pandora_module_freememory.[cc,h],
modules/pandora_module_freedisk.[cc,h], modules/pandora_module_proc.[cc,h],
modules/pandora_module_service.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes.
* modules/pandora_module_list.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes. Added
to Pandora_Modules namespace.
* windows/pandora_windows_wmi.[cc,h]: Added documentation comments.
Renamed Pandora_Wmi_Error to Pandora_Wmi_Exception.
* windows_service.[cc,h]: Added documentation comments. Changed
visibility of some attributes. Style correction.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@150 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2006-08-25 15:02:03 +02:00
|
|
|
const char * svc_display_name,
|
|
|
|
const char * svc_description)
|
2006-07-04 16:07:08 +02:00
|
|
|
: Windows_Service (svc_name, svc_display_name, svc_description) {
|
2006-06-20 19:05:19 +02:00
|
|
|
|
2006-08-15 Esteban Sanchez <estebans@artica.es>
* autogen.sh, configure.in, Makefile.am, Doxyfile.in: Added to
repository. They are used to generate documentation, not to compile.
* main.cc: Added some comments. Style correction.
* pandora.[cc,h]: Added documentation comments. Changed visibility of
some attributes.
* pandora_agent_conf.[cc,h]: Added to Pandora namespace. Added
documentation comments.
* pandora_windows_service.[cc,h], pandora_strutils.[cc,h],
windows/pandora_windows_infp.[cc,h], ssh/pandora_ssh_test.[cc,h]:
Added documentation comments.
* ssh/pandora_ssh_client.[cc,h]:Added documentation comments. Removed
old method to connect with user and password. Style correction.
* misc/pandora_file.[cc,h]: Added documentation comments. Renamed some
parameters.
* modules/pandora_module.[cc,h]: Added documentation comments. Put a
name to the enumerators. Added a new class to agroupate all exceptions
produced by Pandora_Module child class objects. Changed visibility of
some attributes. Added some new methods and renamed others.
* modules/pandora_module_cpuusage.[cc,h],
modules/pandora_module_exec.[cc,h],
modules/pandora_module_freememory.[cc,h],
modules/pandora_module_freedisk.[cc,h], modules/pandora_module_proc.[cc,h],
modules/pandora_module_service.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes.
* modules/pandora_module_list.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes. Added
to Pandora_Modules namespace.
* windows/pandora_windows_wmi.[cc,h]: Added documentation comments.
Renamed Pandora_Wmi_Error to Pandora_Wmi_Exception.
* windows_service.[cc,h]: Added documentation comments. Changed
visibility of some attributes. Style correction.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@150 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2006-08-25 15:02:03 +02:00
|
|
|
this->setInitFunction ((void (Windows_Service::*) ())
|
|
|
|
&Pandora_Windows_Service::pandora_init);
|
|
|
|
this->setRunFunction ((void (Windows_Service::*) ())
|
|
|
|
&Pandora_Windows_Service::pandora_run);
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
|
|
|
|
execution_number = 0;
|
|
|
|
this->modules = NULL;
|
|
|
|
this->conf = NULL;
|
|
|
|
this->interval = 60000;
|
|
|
|
this->transfer_interval = this->interval;
|
|
|
|
this->elapsed_transfer_time = 0;
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2006-08-15 Esteban Sanchez <estebans@artica.es>
* autogen.sh, configure.in, Makefile.am, Doxyfile.in: Added to
repository. They are used to generate documentation, not to compile.
* main.cc: Added some comments. Style correction.
* pandora.[cc,h]: Added documentation comments. Changed visibility of
some attributes.
* pandora_agent_conf.[cc,h]: Added to Pandora namespace. Added
documentation comments.
* pandora_windows_service.[cc,h], pandora_strutils.[cc,h],
windows/pandora_windows_infp.[cc,h], ssh/pandora_ssh_test.[cc,h]:
Added documentation comments.
* ssh/pandora_ssh_client.[cc,h]:Added documentation comments. Removed
old method to connect with user and password. Style correction.
* misc/pandora_file.[cc,h]: Added documentation comments. Renamed some
parameters.
* modules/pandora_module.[cc,h]: Added documentation comments. Put a
name to the enumerators. Added a new class to agroupate all exceptions
produced by Pandora_Module child class objects. Changed visibility of
some attributes. Added some new methods and renamed others.
* modules/pandora_module_cpuusage.[cc,h],
modules/pandora_module_exec.[cc,h],
modules/pandora_module_freememory.[cc,h],
modules/pandora_module_freedisk.[cc,h], modules/pandora_module_proc.[cc,h],
modules/pandora_module_service.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes.
* modules/pandora_module_list.[cc,h]: Added documentation comments.
Some changes to adapt the objects to the Pandora_Module changes. Added
to Pandora_Modules namespace.
* windows/pandora_windows_wmi.[cc,h]: Added documentation comments.
Renamed Pandora_Wmi_Error to Pandora_Wmi_Exception.
* windows_service.[cc,h]: Added documentation comments. Changed
visibility of some attributes. Style correction.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@150 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2006-08-25 15:02:03 +02:00
|
|
|
/**
|
|
|
|
* Destroys a Pandora_Windows_Service object.
|
|
|
|
*/
|
2006-06-20 19:05:19 +02:00
|
|
|
Pandora_Windows_Service::~Pandora_Windows_Service () {
|
|
|
|
if (this->conf != NULL) {
|
|
|
|
delete this->conf;
|
|
|
|
}
|
2006-07-05 16:02:05 +02:00
|
|
|
|
2006-06-20 19:05:19 +02:00
|
|
|
if (this->modules != NULL) {
|
|
|
|
delete this->modules;
|
|
|
|
}
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
pandoraLog ("Pandora agent stopped");
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2006-07-05 16:02:05 +02:00
|
|
|
bool
|
|
|
|
is_enabled (string value) {
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (value == "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (enabled_values[i] != "") {
|
|
|
|
if (enabled_values[i] == value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-06-20 19:05:19 +02:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::pandora_init () {
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
string conf_file, interval, debug, transfer_interval;
|
2006-06-20 19:05:19 +02:00
|
|
|
|
|
|
|
setPandoraDebug (true);
|
|
|
|
|
|
|
|
conf_file = Pandora::getPandoraInstallDir ();
|
|
|
|
conf_file += "pandora_agent.conf";
|
2007-08-07 16:28:14 +02:00
|
|
|
|
2008-04-02 18:01:35 +02:00
|
|
|
this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
|
|
|
|
this->conf->setFile (conf_file);
|
2006-06-20 19:05:19 +02:00
|
|
|
this->modules = new Pandora_Module_List (conf_file);
|
2006-07-05 10:46:51 +02:00
|
|
|
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
/* Get the interval value (in seconds) and set it to the service */
|
2006-07-05 10:46:51 +02:00
|
|
|
interval = conf->getValue ("interval");
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
transfer_interval = conf->getValue ("transfer_interval");
|
|
|
|
|
2006-11-21 12:32:03 +01:00
|
|
|
debug = conf->getValue ("debug");
|
2006-07-05 16:02:05 +02:00
|
|
|
setPandoraDebug (is_enabled (debug));
|
|
|
|
|
2006-07-05 10:46:51 +02:00
|
|
|
if (interval != "") {
|
|
|
|
try {
|
2007-08-23 18:22:56 +02:00
|
|
|
/* miliseconds */
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
this->interval = strtoint (interval) * 1000;
|
2006-07-05 10:46:51 +02:00
|
|
|
} catch (Invalid_Conversion e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 19:05:19 +02:00
|
|
|
srand ((unsigned) time (0));
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
this->setSleepTime (this->interval);
|
2006-06-20 19:05:19 +02:00
|
|
|
|
2007-08-23 18:22:56 +02:00
|
|
|
pandoraLog ("Pandora agent started");
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2006-07-04 16:07:08 +02:00
|
|
|
TiXmlElement *
|
|
|
|
Pandora_Windows_Service::getXmlHeader () {
|
2006-06-20 19:05:19 +02:00
|
|
|
TiXmlElement *agent;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
char timestamp[20];
|
2006-07-04 16:07:08 +02:00
|
|
|
string value;
|
2006-06-20 19:05:19 +02:00
|
|
|
|
2006-07-04 16:07:08 +02:00
|
|
|
agent = new TiXmlElement ("agent_data");
|
|
|
|
|
|
|
|
value = conf->getValue ("agent_name");
|
2006-07-05 16:02:05 +02:00
|
|
|
if (value == "") {
|
|
|
|
value = Pandora_Windows_Info::getSystemName ();
|
|
|
|
}
|
2006-12-05 13:37:36 +01:00
|
|
|
agent->SetAttribute ("agent_name", value);
|
2006-07-05 16:02:05 +02:00
|
|
|
|
|
|
|
agent->SetAttribute ("version", getPandoraAgentVersion ());
|
2006-07-04 16:07:08 +02:00
|
|
|
|
2006-06-20 19:05:19 +02:00
|
|
|
GetSystemTime(&st);
|
2007-09-06 17:21:13 +02:00
|
|
|
sprintf (timestamp, "%d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay,
|
2006-07-05 16:02:05 +02:00
|
|
|
st.wHour, st.wMinute, st.wSecond);
|
2007-09-06 17:21:13 +02:00
|
|
|
|
2006-07-04 16:07:08 +02:00
|
|
|
agent->SetAttribute ("timestamp", timestamp);
|
|
|
|
|
|
|
|
value = conf->getValue ("interval");
|
|
|
|
agent->SetAttribute ("interval", value);
|
|
|
|
|
|
|
|
value = Pandora_Windows_Info::getOSName ();
|
|
|
|
agent->SetAttribute ("os", value);
|
|
|
|
|
|
|
|
value = Pandora_Windows_Info::getOSVersion ();
|
|
|
|
agent->SetAttribute ("os_version", value);
|
|
|
|
|
|
|
|
return agent;
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2008-03-14 14:41:31 +01:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::copyTentacleDataFile (string host,
|
|
|
|
string filename)
|
|
|
|
{
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
int rc;
|
|
|
|
string var, filepath;
|
|
|
|
string tentacle_cmd;
|
2008-03-14 14:41:31 +01:00
|
|
|
|
|
|
|
var = conf->getValue ("temporal");
|
|
|
|
if (var[var.length () - 1] != '\\') {
|
|
|
|
var += "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
filepath = var + filename;
|
|
|
|
|
|
|
|
/* Build the command to launch the Tentacle client */
|
|
|
|
tentacle_cmd = "tentacle_client.exe -a " + host;
|
|
|
|
|
|
|
|
var = conf->getValue ("server_port");
|
|
|
|
if (var != "") {
|
|
|
|
tentacle_cmd += " -p " + var;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = conf->getValue ("server_ssl");
|
|
|
|
if (var == "1") {
|
|
|
|
tentacle_cmd += " -c";
|
|
|
|
}
|
|
|
|
|
|
|
|
var = conf->getValue ("server_pwd");
|
|
|
|
if (var != "") {
|
|
|
|
tentacle_cmd += " -x " + var;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = conf->getValue ("server_opts");
|
|
|
|
if (var != "") {
|
|
|
|
tentacle_cmd += " " + var;
|
|
|
|
}
|
|
|
|
|
|
|
|
tentacle_cmd += " " + filepath;
|
|
|
|
|
|
|
|
/* Copy the file */
|
|
|
|
pandoraDebug ("Remote copying XML %s on server %s",
|
|
|
|
filepath.c_str (), host.c_str ());
|
|
|
|
pandoraDebug ("Command %s", tentacle_cmd.c_str());
|
|
|
|
|
|
|
|
rc = system (tentacle_cmd.c_str());
|
|
|
|
switch (rc) {
|
|
|
|
|
|
|
|
/* system() error */
|
|
|
|
case -1:
|
|
|
|
pandoraLog ("Unable to copy %s", filename.c_str ());
|
|
|
|
throw Pandora_Exception ();
|
|
|
|
|
|
|
|
/* tentacle_client.exe returned OK */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* tentacle_client.exe error */
|
|
|
|
default:
|
|
|
|
pandoraLog ("Tentacle client was unable to copy %s",
|
|
|
|
filename.c_str ());
|
|
|
|
throw Pandora_Exception ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-20 19:05:19 +02:00
|
|
|
void
|
2007-08-07 16:28:14 +02:00
|
|
|
Pandora_Windows_Service::copyScpDataFile (string host,
|
|
|
|
string remote_path,
|
|
|
|
string filename)
|
2006-12-01 17:29:27 +01:00
|
|
|
{
|
2007-08-07 16:28:14 +02:00
|
|
|
SSH::Pandora_Ssh_Client ssh_client;
|
|
|
|
string tmp_dir, filepath;
|
|
|
|
string pubkey_file, privkey_file;
|
2006-07-04 16:07:08 +02:00
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
tmp_dir = conf->getValue ("temporal");
|
|
|
|
if (tmp_dir[tmp_dir.length () - 1] != '\\') {
|
|
|
|
tmp_dir += "\\";
|
2006-07-04 16:07:08 +02:00
|
|
|
}
|
2006-12-01 17:29:27 +01:00
|
|
|
filepath = tmp_dir + filename;
|
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
pandoraDebug ("Connecting with %s", host.c_str ());
|
2006-07-04 16:07:08 +02:00
|
|
|
|
|
|
|
try {
|
2007-08-07 16:28:14 +02:00
|
|
|
pubkey_file = Pandora::getPandoraInstallDir ();
|
|
|
|
pubkey_file += "key\\id_dsa.pub";
|
|
|
|
privkey_file = Pandora::getPandoraInstallDir ();
|
2006-07-04 16:07:08 +02:00
|
|
|
privkey_file += "key\\id_dsa";
|
2006-07-05 10:46:51 +02:00
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
ssh_client.connectWithPublicKey (host.c_str (), 22, "pandora",
|
|
|
|
pubkey_file, privkey_file, "");
|
2006-07-04 16:07:08 +02:00
|
|
|
} catch (SSH::Authentication_Failed e) {
|
2007-08-07 16:28:14 +02:00
|
|
|
pandoraLog ("Pandora Agent: Authentication Failed "
|
|
|
|
"when connecting to %s",
|
|
|
|
host.c_str ());
|
|
|
|
throw e;
|
2006-07-04 16:07:08 +02:00
|
|
|
} catch (Pandora_Exception e) {
|
2006-07-05 16:02:05 +02:00
|
|
|
pandoraLog ("Pandora Agent: Failed when copying to %s",
|
2007-08-07 16:28:14 +02:00
|
|
|
host.c_str ());
|
|
|
|
throw e;
|
2006-07-04 16:07:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pandoraDebug ("Remote copying XML %s on server %s at %s%s",
|
2007-08-07 16:28:14 +02:00
|
|
|
filepath.c_str (), host.c_str (),
|
|
|
|
remote_path.c_str (), filename.c_str ());
|
2006-07-04 16:07:08 +02:00
|
|
|
try {
|
2007-08-07 16:28:14 +02:00
|
|
|
ssh_client.scpFileFilename (remote_path + filename,
|
|
|
|
filepath);
|
2006-07-04 16:07:08 +02:00
|
|
|
} catch (Pandora_Exception e) {
|
2007-08-07 16:28:14 +02:00
|
|
|
pandoraLog ("Unable to copy at %s%s", remote_path.c_str (),
|
2006-12-01 17:29:27 +01:00
|
|
|
filename.c_str ());
|
2007-08-07 16:28:14 +02:00
|
|
|
ssh_client.disconnect();
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssh_client.disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::copyFtpDataFile (string host,
|
|
|
|
string remote_path,
|
|
|
|
string filename)
|
|
|
|
{
|
|
|
|
FTP::Pandora_Ftp_Client ftp_client;
|
|
|
|
string filepath;
|
|
|
|
string password;
|
|
|
|
|
|
|
|
filepath = conf->getValue ("temporal");
|
|
|
|
if (filepath[filepath.length () - 1] != '\\') {
|
|
|
|
filepath += "\\";
|
|
|
|
}
|
|
|
|
filepath += filename;
|
|
|
|
|
2008-03-25 18:00:32 +01:00
|
|
|
password = conf->getValue ("server_pwd");
|
2007-08-07 16:28:14 +02:00
|
|
|
|
|
|
|
ftp_client.connect (host,
|
|
|
|
22,
|
|
|
|
"pandora",
|
|
|
|
password);
|
|
|
|
|
|
|
|
try {
|
|
|
|
ftp_client.ftpFileFilename (remote_path + filename,
|
|
|
|
filepath);
|
|
|
|
} catch (FTP::Unknown_Host e) {
|
2007-08-29 16:30:09 +02:00
|
|
|
pandoraLog ("Pandora Agent: Failed when copying to %s (%s)",
|
|
|
|
host.c_str (), ftp_client.getError ().c_str ());
|
|
|
|
ftp_client.disconnect ();
|
2007-08-07 16:28:14 +02:00
|
|
|
throw e;
|
|
|
|
} catch (FTP::Authentication_Failed e) {
|
|
|
|
pandoraLog ("Pandora Agent: Authentication Failed "
|
|
|
|
"when connecting to %s (%s)",
|
2007-09-05 18:22:26 +02:00
|
|
|
host.c_str (), ftp_client.getError ().c_str ());
|
2007-08-29 16:30:09 +02:00
|
|
|
ftp_client.disconnect ();
|
2007-08-07 16:28:14 +02:00
|
|
|
throw e;
|
|
|
|
} catch (FTP::FTP_Exception e) {
|
|
|
|
pandoraLog ("Pandora Agent: Failed when copying to %s (%s)",
|
|
|
|
host.c_str (), ftp_client.getError ().c_str ());
|
2007-08-29 16:30:09 +02:00
|
|
|
ftp_client.disconnect ();
|
2007-08-07 16:28:14 +02:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
ftp_client.disconnect ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::copyDataFile (string filename)
|
|
|
|
{
|
|
|
|
string mode, host, remote_path;
|
|
|
|
|
|
|
|
mode = conf->getValue ("transfer_mode");
|
|
|
|
host = conf->getValue ("server_ip");
|
|
|
|
remote_path = conf->getValue ("server_path");
|
|
|
|
if (remote_path[remote_path.length () - 1] != '/') {
|
|
|
|
remote_path += "/";
|
2006-07-04 16:07:08 +02:00
|
|
|
}
|
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
try {
|
|
|
|
if (mode == "ftp") {
|
|
|
|
copyFtpDataFile (host, remote_path, filename);
|
2008-03-14 14:41:31 +01:00
|
|
|
} else if (mode == "tentacle") {
|
|
|
|
copyTentacleDataFile (host, filename);
|
2007-08-07 16:28:14 +02:00
|
|
|
} else if (mode == "ssh" || mode == "") {
|
|
|
|
copyScpDataFile (host, remote_path, filename);
|
|
|
|
} else {
|
|
|
|
pandoraLog ("Invalid transfer mode: %s."
|
2007-08-29 16:30:09 +02:00
|
|
|
"Please recheck transfer_mode option "
|
2007-08-07 16:28:14 +02:00
|
|
|
"in configuration file.");
|
|
|
|
}
|
|
|
|
|
2007-08-23 18:22:56 +02:00
|
|
|
pandoraDebug ("Successfuly copied XML file to server.");
|
2007-08-07 16:28:14 +02:00
|
|
|
} catch (Pandora_Exception e) {
|
|
|
|
}
|
2006-12-01 17:29:27 +01:00
|
|
|
}
|
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::recvTentacleDataFile (string host,
|
|
|
|
string filename)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
string var;
|
|
|
|
string tentacle_cmd;
|
|
|
|
|
|
|
|
/* Change directory to "temporal" */
|
|
|
|
var = conf->getValue ("temporal");
|
|
|
|
if (_chdir(var.c_str()) != 0) {
|
|
|
|
pandoraDebug ("Error changing directory to %s", var.c_str());
|
|
|
|
throw Pandora_Exception ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the command to launch the Tentacle client */
|
|
|
|
tentacle_cmd = "tentacle_client.exe -g -a " + host;
|
|
|
|
|
|
|
|
var = conf->getValue ("server_port");
|
|
|
|
if (var != "") {
|
|
|
|
tentacle_cmd += " -p " + var;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = conf->getValue ("server_ssl");
|
|
|
|
if (var == "1") {
|
|
|
|
tentacle_cmd += " -c";
|
|
|
|
}
|
|
|
|
|
|
|
|
var = conf->getValue ("server_pwd");
|
|
|
|
if (var != "") {
|
|
|
|
tentacle_cmd += " -x " + var;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = conf->getValue ("server_opts");
|
|
|
|
if (var != "") {
|
|
|
|
tentacle_cmd += " " + var;
|
|
|
|
}
|
|
|
|
|
|
|
|
tentacle_cmd += " " + filename;
|
|
|
|
|
|
|
|
/* Copy the file */
|
|
|
|
pandoraDebug ("Requesting file %s from server %s",
|
|
|
|
filename.c_str (), host.c_str ());
|
|
|
|
pandoraDebug ("Command %s", tentacle_cmd.c_str());
|
|
|
|
|
|
|
|
rc = system (tentacle_cmd.c_str());
|
|
|
|
switch (rc) {
|
|
|
|
|
|
|
|
/* system() error */
|
|
|
|
case -1:
|
|
|
|
pandoraLog ("Unable to receive file %s", filename.c_str ());
|
|
|
|
throw Pandora_Exception ();
|
|
|
|
|
|
|
|
/* tentacle_client.exe returned OK */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* tentacle_client.exe error */
|
|
|
|
default:
|
|
|
|
pandoraLog ("Tentacle client was unable to receive file %s",
|
|
|
|
filename.c_str ());
|
|
|
|
throw Pandora_Exception ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::recvDataFile (string filename) {
|
|
|
|
string mode, host, remote_path;
|
|
|
|
|
|
|
|
mode = conf->getValue ("transfer_mode");
|
|
|
|
host = conf->getValue ("server_ip");
|
|
|
|
remote_path = conf->getValue ("server_path");
|
|
|
|
if (remote_path[remote_path.length () - 1] != '/') {
|
|
|
|
remote_path += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (mode == "tentacle") {
|
|
|
|
recvTentacleDataFile (host, filename);
|
|
|
|
} else {
|
|
|
|
pandoraLog ("Transfer mode %s does not support file retrieval.");
|
|
|
|
throw Pandora_Exception ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Pandora_Exception e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::checkConfig () {
|
|
|
|
int i, conf_size;
|
|
|
|
char *conf_str = NULL, *remote_conf_str = NULL, *remote_conf_md5 = NULL;
|
|
|
|
char agent_md5[33], conf_md5[33], flag;
|
|
|
|
string conf_file, conf_tmp_file, md5_tmp_file, temp_dir, tmp;
|
|
|
|
|
|
|
|
tmp = conf->getValue ("remote_config");
|
|
|
|
if (tmp != "1") {
|
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Remote configuration disabled");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get temporal directory */
|
|
|
|
temp_dir = conf->getValue ("temporal");
|
|
|
|
if (temp_dir[temp_dir.length () - 1] != '\\') {
|
|
|
|
temp_dir += "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get base install directory */
|
|
|
|
conf_file = Pandora::getPandoraInstallDir ();
|
|
|
|
conf_file += "pandora_agent.conf";
|
|
|
|
|
|
|
|
/* Get agent name */
|
|
|
|
tmp = conf->getValue ("agent_name");
|
|
|
|
if (tmp == "") {
|
|
|
|
tmp = Pandora_Windows_Info::getSystemName ();
|
|
|
|
}
|
|
|
|
|
|
|
|
Pandora_File::md5 (tmp.c_str(), tmp.size(), agent_md5);
|
|
|
|
|
|
|
|
/* Calculate md5 hashes */
|
|
|
|
try {
|
|
|
|
conf_size = Pandora_File::readBinFile (conf_file, &conf_str);
|
|
|
|
Pandora_File::md5 (conf_str, conf_size, conf_md5);
|
|
|
|
} catch (...) {
|
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error calculating configuration md5");
|
|
|
|
if (conf_str != NULL) {
|
|
|
|
delete[] conf_str;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compose file names from the agent name hash */
|
|
|
|
conf_tmp_file = agent_md5;
|
|
|
|
conf_tmp_file += ".conf";
|
|
|
|
md5_tmp_file = agent_md5;
|
|
|
|
md5_tmp_file += ".md5";
|
|
|
|
|
|
|
|
/* Get md5 file from server */
|
|
|
|
try {
|
|
|
|
recvDataFile (md5_tmp_file);
|
|
|
|
} catch (...) {
|
|
|
|
/* Not found, upload the configuration */
|
|
|
|
try {
|
|
|
|
tmp = temp_dir;
|
|
|
|
tmp += conf_tmp_file;
|
|
|
|
Pandora_File::writeBinFile (tmp, conf_str, conf_size);
|
|
|
|
copyDataFile (conf_tmp_file);
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
|
|
|
|
tmp = temp_dir;
|
|
|
|
tmp += md5_tmp_file;
|
|
|
|
Pandora_File::writeBinFile (tmp, conf_md5, 32);
|
|
|
|
copyDataFile (md5_tmp_file);
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
} catch (...) {
|
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error uploading configuration to server");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] conf_str;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] conf_str;
|
|
|
|
conf_str = NULL;
|
|
|
|
|
|
|
|
/* Read remote configuration file md5 */
|
|
|
|
try {
|
|
|
|
tmp = temp_dir;
|
|
|
|
tmp += md5_tmp_file;
|
|
|
|
if (Pandora_File::readBinFile (tmp, &remote_conf_md5) < 32) {
|
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Invalid remote md5", tmp.c_str());
|
|
|
|
if (remote_conf_md5 != NULL) {
|
|
|
|
delete[] remote_conf_md5;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
} catch (...) {
|
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error checking remote configuration md5", tmp.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for configuration changes */
|
|
|
|
flag = 0;
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
if (remote_conf_md5[i] != conf_md5[i]) {
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] remote_conf_md5;
|
|
|
|
|
|
|
|
/* Configuration has not changed */
|
|
|
|
if (flag == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pandoraLog("Pandora_Windows_Service::checkConfig: Configuration has changed");
|
|
|
|
|
|
|
|
/* Get configuration file from server */
|
|
|
|
try {
|
|
|
|
recvDataFile (conf_tmp_file);
|
|
|
|
tmp = temp_dir;
|
|
|
|
tmp += conf_tmp_file;
|
|
|
|
conf_size = Pandora_File::readBinFile (tmp, &conf_str);
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
/* Save new configuration */
|
|
|
|
Pandora_File::writeBinFile (conf_file, conf_str, conf_size);
|
|
|
|
} catch (...) {
|
|
|
|
pandoraDebug("Pandora_Windows_Service::checkConfig: Error retrieving configuration file from server");
|
|
|
|
if (conf_str != NULL) {
|
|
|
|
delete[] conf_str;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] conf_str;
|
|
|
|
|
|
|
|
/* Reload configuration */
|
|
|
|
this->pandora_init ();
|
|
|
|
}
|
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::pandora_run () {
|
|
|
|
TiXmlDocument *doc;
|
|
|
|
TiXmlElement *local_xml, *agent;
|
|
|
|
string xml_filename, random_integer;
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
string tmp_filename, tmp_filepath;
|
2006-12-01 17:29:27 +01:00
|
|
|
bool saved;
|
|
|
|
|
2007-08-23 18:22:56 +02:00
|
|
|
pandoraDebug ("Run begin");
|
2006-12-01 17:29:27 +01:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
/* Check for configuration changes */
|
|
|
|
this->checkConfig ();
|
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
execution_number++;
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
if (this->modules != NULL) {
|
|
|
|
this->modules->goFirst ();
|
|
|
|
|
|
|
|
while (! this->modules->isLast ()) {
|
|
|
|
Pandora_Module *module;
|
|
|
|
|
|
|
|
module = this->modules->getCurrentValue ();
|
|
|
|
|
|
|
|
pandoraDebug ("Run %s", module->getName ().c_str ());
|
|
|
|
module->run ();
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
this->modules->goNext ();
|
|
|
|
}
|
|
|
|
}
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
|
|
|
|
this->elapsed_transfer_time += interval;
|
2008-06-11 16:58:53 +02:00
|
|
|
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
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";
|
2006-12-01 17:29:27 +01:00
|
|
|
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
xml_filename = conf->getValue ("temporal");
|
|
|
|
if (xml_filename[xml_filename.length () - 1] != '\\') {
|
|
|
|
xml_filename += "\\";
|
|
|
|
}
|
|
|
|
tmp_filepath = xml_filename + tmp_filename;
|
|
|
|
|
|
|
|
/* 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;
|
2006-12-01 17:29:27 +01:00
|
|
|
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
if (!saved) {
|
|
|
|
pandoraLog ("Error when saving the XML in %s",
|
|
|
|
tmp_filepath.c_str ());
|
|
|
|
return;
|
|
|
|
}
|
2006-12-01 17:29:27 +01:00
|
|
|
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
/* Only send if debug is not activated */
|
|
|
|
if (getPandoraDebug () == false) {
|
|
|
|
this->copyDataFile (tmp_filename);
|
2006-12-01 17:29:27 +01:00
|
|
|
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
try {
|
|
|
|
Pandora_File::removeFile (tmp_filepath);
|
|
|
|
} catch (Pandora_File::Delete_Error e) {
|
|
|
|
}
|
|
|
|
}
|
2006-10-06 13:25:36 +02:00
|
|
|
}
|
2006-12-01 17:29:27 +01:00
|
|
|
|
|
|
|
/* Get the interval value (in minutes) */
|
2008-04-09 Esteban Sanchez <estebans@artica.es>
* 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.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@803 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-04-09 17:48:06 +02:00
|
|
|
pandoraDebug ("Next execution on %d seconds", this->interval / 1000);
|
2006-06-20 19:05:19 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|