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"
|
2016-09-29 12:50:04 +02:00
|
|
|
#include "misc/sha256.h"
|
2006-07-04 16:07:08 +02:00
|
|
|
#include "windows/pandora_windows_info.h"
|
2008-12-11 11:20:07 +01:00
|
|
|
#include "udp_server/udp_server.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>
|
2010-07-21 12:03:20 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <pandora_agent_conf.h>
|
2011-07-11 17:49:29 +02:00
|
|
|
#include <fstream>
|
2011-07-28 19:34:51 +02:00
|
|
|
#include <unistd.h>
|
2016-09-29 12:50:04 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2006-06-20 19:05:19 +02:00
|
|
|
|
2012-11-21 18:13:05 +01:00
|
|
|
#define BUFSIZE 4096
|
|
|
|
|
2006-06-20 19:05:19 +02:00
|
|
|
using namespace std;
|
|
|
|
using namespace Pandora;
|
2020-01-29 13:00:17 +01:00
|
|
|
using namespace Pandora_File;
|
2006-06-20 19:05:19 +02:00
|
|
|
using namespace Pandora_Modules;
|
2006-07-04 16:07:08 +02:00
|
|
|
using namespace Pandora_Strutils;
|
2008-12-11 11:20:07 +01:00
|
|
|
|
2008-11-28 11:51:03 +01:00
|
|
|
Pandora_Windows_Service::Pandora_Windows_Service ()
|
2008-12-11 11:20:07 +01:00
|
|
|
: Windows_Service (NULL, NULL, NULL) {
|
2008-11-28 11:51:03 +01:00
|
|
|
this->setInitFunction ((void (Windows_Service::*) ())
|
|
|
|
&Pandora_Windows_Service::pandora_init);
|
|
|
|
this->setRunFunction ((void (Windows_Service::*) ())
|
2008-12-11 11:20:07 +01:00
|
|
|
&Pandora_Windows_Service::pandora_run);
|
|
|
|
this->started = false;
|
|
|
|
}
|
2006-07-05 16:02:05 +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
|
|
|
/**
|
2008-11-28 11:51:03 +01:00
|
|
|
* Set Pandora service Windows properties.
|
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
|
|
|
*
|
|
|
|
* @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.
|
2008-12-11 11:20:07 +01:00
|
|
|
*/
|
2008-11-28 11:51:03 +01:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::setValues (const char * svc_name,
|
|
|
|
const char * svc_display_name,
|
|
|
|
const char * svc_description) {
|
|
|
|
this->service_name = (char *) svc_name;
|
|
|
|
this->service_display_name = (char *) svc_display_name;
|
|
|
|
this->service_description = (char *) svc_description;
|
2008-07-09 14:46:22 +02:00
|
|
|
execution_number = 0;
|
|
|
|
this->modules = NULL;
|
2017-05-18 11:55:44 +02:00
|
|
|
this->broker_modules = NULL;
|
2008-07-09 14:46:22 +02:00
|
|
|
this->conf = NULL;
|
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 = 60000;
|
2012-01-03 18:23:23 +01:00
|
|
|
this->timestamp = 0;
|
|
|
|
this->run_time = 0;
|
2009-09-22 Ramon Novoa <rnovoa@artica.es>
* debug_new.h, fast_mutex.h,
debug_new.cpp, static_assert.h: Added to repository. Wu Yongwei's
memory leak detection tool (part of Nvwa). Only compiled when
debugging is enabled.
* bin/util/tentacle_client.exe: Added to repository. Tentacle client
needed to build the installer.
* installer/pandora_2.0.mpi: moved to installer/pandora.mpi. Updated.
The installer can now be built directly from the installer
subdirectory.
* configure.in, Makefile.am, autogen.sh: Created a proper
configure.in and Makefile.am. The agent can now be cross-compiled
from Linux :-D
* bin/pandora_agent.conf: Fixed. A local configuration had been
uploaded.
* pandora_windows_service.h,pandora_windows_service.cc,
udp_server/udp_server.cc, udp_server/udp_server.h: Properly shutdown
the UDP server.
* modules/pandora_module_regexp.cc,
modules/pandora_module_inventory.cc,
modules/pandora_module_factory.cc,
modules/pandora_module.cc, pandora_strutils.cc,
pandora.h, pandora.cc: Fixed a couple of memory leaks. Small changes
to avoid compile warnings when cross-compiling from Linux.
* windows_service.cc: Removed the interactive service flag to avoid
'black windows'.
* main.cc: Include the memory leak detection tool if debugging is
enabled.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1966 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-09-22 13:48:25 +02:00
|
|
|
this->udp_server = NULL;
|
2011-11-03 20:13:57 +01:00
|
|
|
this->tentacle_proxy = false;
|
2012-01-03 18:23:23 +01:00
|
|
|
this->intensive_interval = 60000;
|
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 () {
|
2011-07-28 19:34:51 +02:00
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
if (this->conf != NULL) {
|
2011-08-19 13:58:22 +02:00
|
|
|
if(conf->getValue("proxy_mode") != "") {
|
|
|
|
killTentacleProxy();
|
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
delete this->conf;
|
|
|
|
}
|
2006-07-05 16:02:05 +02:00
|
|
|
|
2009-09-22 Ramon Novoa <rnovoa@artica.es>
* debug_new.h, fast_mutex.h,
debug_new.cpp, static_assert.h: Added to repository. Wu Yongwei's
memory leak detection tool (part of Nvwa). Only compiled when
debugging is enabled.
* bin/util/tentacle_client.exe: Added to repository. Tentacle client
needed to build the installer.
* installer/pandora_2.0.mpi: moved to installer/pandora.mpi. Updated.
The installer can now be built directly from the installer
subdirectory.
* configure.in, Makefile.am, autogen.sh: Created a proper
configure.in and Makefile.am. The agent can now be cross-compiled
from Linux :-D
* bin/pandora_agent.conf: Fixed. A local configuration had been
uploaded.
* pandora_windows_service.h,pandora_windows_service.cc,
udp_server/udp_server.cc, udp_server/udp_server.h: Properly shutdown
the UDP server.
* modules/pandora_module_regexp.cc,
modules/pandora_module_inventory.cc,
modules/pandora_module_factory.cc,
modules/pandora_module.cc, pandora_strutils.cc,
pandora.h, pandora.cc: Fixed a couple of memory leaks. Small changes
to avoid compile warnings when cross-compiling from Linux.
* windows_service.cc: Removed the interactive service flag to avoid
'black windows'.
* main.cc: Include the memory leak detection tool if debugging is
enabled.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1966 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-09-22 13:48:25 +02:00
|
|
|
if (this->udp_server != NULL) {
|
|
|
|
((UDP_Server *)udp_server)->stop ();
|
|
|
|
delete (UDP_Server *)udp_server;
|
|
|
|
}
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
if (this->modules != NULL) {
|
|
|
|
delete this->modules;
|
|
|
|
}
|
2017-05-18 11:55:44 +02:00
|
|
|
|
|
|
|
if (this->broker_modules != NULL) {
|
|
|
|
delete this->broker_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
|
|
|
}
|
2008-12-11 11:20:07 +01:00
|
|
|
|
|
|
|
Pandora_Windows_Service *
|
|
|
|
Pandora_Windows_Service::getInstance () {
|
|
|
|
static Pandora_Windows_Service *service = NULL;
|
|
|
|
|
|
|
|
if (service != NULL)
|
|
|
|
return service;
|
|
|
|
|
|
|
|
service = new Pandora_Windows_Service ();
|
|
|
|
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::start () {
|
|
|
|
this->started = true;
|
2006-07-05 16:02:05 +02:00
|
|
|
}
|
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::pandora_init_broker (string file_conf) {
|
2011-07-14 10:58:18 +02:00
|
|
|
string interval, debug, transfer_interval, util_dir, path, env, name_agent;
|
2011-07-11 17:49:29 +02:00
|
|
|
string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr;
|
|
|
|
int pos;
|
|
|
|
|
2011-07-14 10:58:18 +02:00
|
|
|
name_agent = "PANDORA_AGENT=" + checkAgentName(file_conf);
|
|
|
|
putenv(name_agent.c_str());
|
2011-07-11 17:49:29 +02:00
|
|
|
|
|
|
|
this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
|
|
|
|
this->conf->setFile (file_conf);
|
2017-05-18 11:55:44 +02:00
|
|
|
if (this->broker_modules != NULL) {
|
|
|
|
delete this->broker_modules;
|
2011-11-03 20:13:57 +01:00
|
|
|
}
|
2017-05-18 11:55:44 +02:00
|
|
|
this->broker_modules = new Pandora_Module_List (file_conf);
|
2011-07-11 17:49:29 +02:00
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
pandoraDebug ("Pandora broker agent started");
|
2011-07-11 17:49:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Pandora_Windows_Service::count_broker_agents(){
|
|
|
|
string buffer;
|
|
|
|
string filename;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2011-07-11 17:49:29 +02:00
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
filename = Pandora::getPandoraInstallDir ();
|
|
|
|
filename += "pandora_agent.conf";
|
|
|
|
ifstream file (filename.c_str ());
|
|
|
|
|
|
|
|
/* Read and set the file */
|
|
|
|
while (!file.eof ()) {
|
|
|
|
/* Set the value from each line */
|
|
|
|
getline (file, buffer);
|
|
|
|
|
|
|
|
/* Ignore blank or commented lines */
|
|
|
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
|
|
|
/*Check if is a broker_agent*/
|
|
|
|
pos = buffer.find("broker_agent");
|
|
|
|
if (pos != string::npos){
|
|
|
|
num += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close ();
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::check_broker_agents(string *all_conf){
|
|
|
|
string buffer, filename;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2011-07-11 17:49:29 +02:00
|
|
|
int pos_file = 0;
|
|
|
|
|
|
|
|
filename = Pandora::getPandoraInstallDir ();
|
|
|
|
filename += "pandora_agent.conf";
|
|
|
|
|
|
|
|
ifstream file (filename.c_str ());
|
|
|
|
|
|
|
|
while (!file.eof ()) {
|
|
|
|
/* Set the value from each line */
|
|
|
|
getline (file, buffer);
|
|
|
|
|
|
|
|
/* Ignore blank or commented lines */
|
|
|
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
|
|
|
/*Check if is a broker_agent*/
|
|
|
|
pos = buffer.find("broker_agent");
|
|
|
|
if (pos != string::npos){
|
|
|
|
string name_broker, path_broker;
|
|
|
|
|
|
|
|
name_broker = buffer.substr(pos+13);
|
|
|
|
path_broker = Pandora::getPandoraInstallDir () + name_broker + ".conf";
|
|
|
|
all_conf[pos_file] = path_broker;
|
|
|
|
pos_file += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 19:05:19 +02:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::pandora_init () {
|
2017-05-18 11:55:44 +02:00
|
|
|
pandora_init(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::pandora_init (bool reload_modules) {
|
2015-09-22 18:35:19 +02:00
|
|
|
string conf_file, interval, debug, disable_logfile, intensive_interval, util_dir, path, env;
|
2008-12-11 11:20:07 +01:00
|
|
|
string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr;
|
2017-05-18 11:55:44 +02:00
|
|
|
string agent_name, agent_name_cmd, agent_alias, agent_alias_cmd, pandora_agent;
|
2011-07-28 19:34:51 +02:00
|
|
|
string proxy_mode, server_ip;
|
2011-12-13 15:37:32 +01:00
|
|
|
string *all_conf;
|
2011-07-11 17:49:29 +02:00
|
|
|
int pos, num;
|
2011-11-22 13:44:47 +01:00
|
|
|
static unsigned char first_run = 1;
|
2011-07-14 10:58:18 +02:00
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
conf_file = Pandora::getPandoraInstallDir ();
|
|
|
|
conf_file += "pandora_agent.conf";
|
2011-07-14 10:58:18 +02:00
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
num = count_broker_agents();
|
2011-12-13 15:37:32 +01:00
|
|
|
all_conf = new string[num];
|
2011-07-11 17:49:29 +02:00
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
|
2011-07-11 17:49:29 +02:00
|
|
|
this->conf->setFile (all_conf);
|
2017-05-18 11:55:44 +02:00
|
|
|
if (this->modules != NULL && reload_modules) {
|
2011-11-03 20:13:57 +01:00
|
|
|
delete this->modules;
|
|
|
|
}
|
2011-07-14 10:58:18 +02:00
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
/* Get the interval value (in seconds) and set it to the service */
|
|
|
|
interval = conf->getValue ("interval");
|
2012-01-03 18:23:23 +01:00
|
|
|
intensive_interval = conf->getValue ("intensive_interval");
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
if (interval != "") {
|
2006-07-05 10:46:51 +02:00
|
|
|
try {
|
2007-08-23 18:22:56 +02:00
|
|
|
/* miliseconds */
|
2012-01-03 18:23:23 +01:00
|
|
|
this->interval_sec = strtoint (interval);
|
|
|
|
this->interval = this->interval_sec * 1000;
|
2006-07-05 10:46:51 +02:00
|
|
|
} catch (Invalid_Conversion e) {
|
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
|
2020-01-29 13:00:17 +01:00
|
|
|
/* Set up the secondary buffer. */
|
|
|
|
if (conf->getValue ("secondary_mode") == "always") {
|
|
|
|
string secondary_temporal = conf->getValue("temporal");
|
|
|
|
if (secondary_temporal[secondary_temporal.length () - 1] != '\\') {
|
|
|
|
secondary_temporal += "\\";
|
|
|
|
}
|
|
|
|
secondary_temporal += SECONDARY_DIR;
|
|
|
|
if (!dirExists(secondary_temporal) && mkdir (secondary_temporal.c_str()) != 0) {
|
|
|
|
pandoraLog ("Pandora_Windows_Service::pandora_init: Can not create directory %s", secondary_temporal.c_str());
|
|
|
|
}
|
|
|
|
conf->setValue("secondary_temporal", secondary_temporal);
|
|
|
|
}
|
|
|
|
else if (conf->getValue ("secondary_mode") == "on_error") {
|
|
|
|
conf->setValue("secondary_temporal", conf->getValue("temporal"));
|
|
|
|
}
|
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
// Set the intensive interval
|
|
|
|
if (intensive_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
|
|
|
try {
|
|
|
|
/* miliseconds */
|
2012-01-03 18:23:23 +01:00
|
|
|
this->intensive_interval = strtoint (intensive_interval) * 1000;
|
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
|
|
|
} catch (Invalid_Conversion e) {
|
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
} else {
|
|
|
|
this->intensive_interval = this->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
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
|
|
|
|
this->setSleepTime (this->intensive_interval);
|
|
|
|
|
|
|
|
// Read modules
|
2017-05-18 11:55:44 +02:00
|
|
|
if (reload_modules) {
|
|
|
|
this->modules = new Pandora_Module_List (conf_file);
|
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
delete []all_conf;
|
2017-04-17 12:50:46 +02:00
|
|
|
|
|
|
|
// Get the agent alias.
|
|
|
|
agent_alias = conf->getValue ("agent_alias");
|
|
|
|
if (agent_alias == "") {
|
|
|
|
agent_alias_cmd = conf->getValue ("agent_alias_cmd");
|
|
|
|
if (agent_alias_cmd != "") {
|
|
|
|
agent_alias_cmd = "cmd.exe /c \"" + agent_alias_cmd + "\"";
|
|
|
|
static string temp_agent_alias = getAgentNameFromCmdExec(agent_alias_cmd);
|
|
|
|
|
|
|
|
// Delete new line and carriage return.
|
|
|
|
pos = temp_agent_alias.find("\n");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
temp_agent_alias.erase(pos, temp_agent_alias.size () - pos);
|
|
|
|
}
|
|
|
|
pos = temp_agent_alias.find("\r");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
temp_agent_alias.erase(pos, temp_agent_alias.size () - pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove leading and trailing white spaces.
|
|
|
|
temp_agent_alias = trim(temp_agent_alias);
|
|
|
|
if (temp_agent_alias != "") {
|
|
|
|
agent_alias = temp_agent_alias;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent_alias = Pandora_Windows_Info::getSystemName ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->conf->setValue("agent_alias", agent_alias);
|
|
|
|
|
2016-09-29 12:50:04 +02:00
|
|
|
// Get the agent name.
|
|
|
|
agent_name = conf->getValue ("agent_name");
|
|
|
|
if (agent_name == "") {
|
|
|
|
agent_name_cmd = conf->getValue ("agent_name_cmd");
|
|
|
|
|
|
|
|
// Random name.
|
|
|
|
if (agent_name_cmd == "__rand__") {
|
|
|
|
agent_name = generateAgentName();
|
|
|
|
this->conf->setValue("agent_name", agent_name);
|
|
|
|
conf->updateFile("agent_name", agent_name); // Write random names to disk!
|
|
|
|
}
|
|
|
|
// Name from command.
|
|
|
|
else if (agent_name_cmd != "") {
|
|
|
|
agent_name_cmd = "cmd.exe /c \"" + agent_name_cmd + "\"";
|
|
|
|
static string temp_agent_name = getAgentNameFromCmdExec(agent_name_cmd);
|
|
|
|
|
|
|
|
// Delete new line and carriage return.
|
|
|
|
pos = temp_agent_name.find("\n");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
temp_agent_name.erase(pos, temp_agent_name.size () - pos);
|
|
|
|
}
|
|
|
|
pos = temp_agent_name.find("\r");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
temp_agent_name.erase(pos, temp_agent_name.size () - pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove leading and trailing white spaces.
|
|
|
|
temp_agent_name = trim(temp_agent_name);
|
|
|
|
if (temp_agent_name != "") {
|
|
|
|
agent_name = temp_agent_name;
|
|
|
|
this->conf->setValue("agent_name", agent_name);
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
}
|
2016-09-29 12:50:04 +02:00
|
|
|
|
|
|
|
// Fall back to the hostname if agent_name is still empty.
|
|
|
|
if (agent_name == "") {
|
|
|
|
agent_name = Pandora_Windows_Info::getSystemName ();
|
|
|
|
this->conf->setValue("agent_name", agent_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
pandora_agent = "PANDORA_AGENT=" + agent_name;
|
|
|
|
putenv(pandora_agent.c_str());
|
2011-07-28 19:34:51 +02:00
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
debug = conf->getValue ("debug");
|
|
|
|
setPandoraDebug (is_enabled (debug));
|
2015-09-22 18:35:19 +02:00
|
|
|
|
|
|
|
disable_logfile = conf->getValue ("disable_logfile");
|
|
|
|
setPandoraLogDisable (is_enabled(disable_logfile));
|
2012-01-03 18:23:23 +01:00
|
|
|
|
2011-11-22 13:44:47 +01:00
|
|
|
if (first_run == 1) {
|
|
|
|
first_run = 0;
|
|
|
|
|
|
|
|
// Add the util subdirectory to the PATH
|
|
|
|
util_dir = Pandora::getPandoraInstallDir ();
|
|
|
|
util_dir += "util";
|
|
|
|
path = getenv ("PATH");
|
|
|
|
env = "PATH=" + path + ";" + util_dir;
|
|
|
|
putenv (env.c_str ());
|
|
|
|
|
|
|
|
// Set the seed for rand
|
|
|
|
srand ((unsigned) time (0));
|
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
pandoraLog ("Pandora agent started");
|
|
|
|
}
|
2015-02-04 15:59:39 +01:00
|
|
|
|
|
|
|
/*Check if proxy mode is set*/
|
|
|
|
proxy_mode = conf->getValue ("proxy_mode");
|
|
|
|
if (proxy_mode != "" && this->tentacle_proxy == false) {
|
|
|
|
launchTentacleProxy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Launch UDP Server */
|
|
|
|
udp_server_enabled = conf->getValue ("udp_server");
|
|
|
|
if (udp_server_enabled.compare ("1") == 0 && this->udp_server == NULL) {
|
|
|
|
udp_server_port = conf->getValue ("udp_server_port");
|
|
|
|
udp_server_addr = conf->getValue ("udp_server_address");
|
|
|
|
udp_server_auth_addr = conf->getValue ("udp_server_auth_address");
|
|
|
|
this->udp_server = new UDP_Server (this, udp_server_addr, udp_server_auth_addr, atoi (udp_server_port.c_str ()));
|
|
|
|
((UDP_Server *)this->udp_server)->start ();
|
|
|
|
}
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2011-07-28 19:34:51 +02:00
|
|
|
int
|
|
|
|
Pandora_Windows_Service::killTentacleProxy() {
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
|
|
|
string kill_cmd;
|
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
if (this->tentacle_proxy == false) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-28 19:34:51 +02:00
|
|
|
kill_cmd = "taskkill.exe /F /IM tentacle_server.exe";
|
|
|
|
|
|
|
|
ZeroMemory (&si, sizeof (si));
|
|
|
|
ZeroMemory (&pi, sizeof (pi));
|
|
|
|
if (CreateProcess (NULL , (CHAR *)kill_cmd.c_str (), NULL, NULL, FALSE,
|
|
|
|
CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
this->tentacle_proxy = false;
|
2011-07-28 19:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-11-03 20:13:57 +01:00
|
|
|
Pandora_Windows_Service::launchTentacleProxy() {
|
2015-03-30 11:29:44 +02:00
|
|
|
string server_ip, server_port, proxy_max_connections, proxy_timeout, server_ssl;
|
2020-09-23 12:04:55 +02:00
|
|
|
string proxy_cmd, proxy_address, proxy_port;
|
2011-07-28 19:34:51 +02:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
|
|
|
/*Check if server proxy is localhost*/
|
|
|
|
server_ip = conf->getValue("server_ip");
|
|
|
|
|
|
|
|
if (server_ip != "localhost") {
|
2015-03-30 11:29:44 +02:00
|
|
|
|
2011-07-28 19:34:51 +02:00
|
|
|
proxy_max_connections = conf->getValue("proxy_max_connection");
|
|
|
|
|
|
|
|
if (proxy_max_connections == "") {
|
|
|
|
proxy_max_connections = "10";
|
|
|
|
}
|
|
|
|
|
|
|
|
proxy_timeout = conf->getValue("proxy_timeout");
|
|
|
|
|
|
|
|
if (proxy_timeout == "") {
|
|
|
|
proxy_timeout = "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
server_port = conf->getValue("server_port");
|
|
|
|
|
|
|
|
if (server_port == "") {
|
|
|
|
server_port = "41121";
|
|
|
|
}
|
2015-03-30 11:29:44 +02:00
|
|
|
|
|
|
|
server_ssl = conf->getValue("server_ssl");
|
|
|
|
|
|
|
|
if (server_ssl == "1") {
|
|
|
|
proxy_cmd = "tentacle_server.exe -C";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
proxy_cmd = "tentacle_server.exe";
|
|
|
|
}
|
|
|
|
|
2020-09-23 12:04:55 +02:00
|
|
|
// Proxy address.
|
|
|
|
proxy_address = conf->getValue("proxy_address");
|
|
|
|
if (proxy_address == "") {
|
|
|
|
proxy_address = "0.0.0.0";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proxy port.
|
|
|
|
proxy_port = conf->getValue("proxy_port");
|
|
|
|
if (proxy_port == "") {
|
|
|
|
proxy_port = "41121";
|
|
|
|
}
|
|
|
|
|
|
|
|
proxy_cmd += " -b " + server_ip + " -g " + server_port + " -c " + proxy_max_connections + " -t " + proxy_timeout + " -a " + proxy_address + " -p " + proxy_port;
|
2015-03-30 11:29:44 +02:00
|
|
|
|
2011-07-28 19:34:51 +02:00
|
|
|
ZeroMemory (&si, sizeof (si));
|
|
|
|
ZeroMemory (&pi, sizeof (pi));
|
|
|
|
if (CreateProcess (NULL , (CHAR *)proxy_cmd.c_str (), NULL, NULL, FALSE,
|
|
|
|
CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) {
|
2011-07-29 11:19:50 +02:00
|
|
|
pandoraLog("There was a problem lauching Tentacle Proxy");
|
2011-07-28 19:34:51 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2011-07-29 11:19:50 +02:00
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
this->tentacle_proxy = true;
|
2011-07-29 11:19:50 +02:00
|
|
|
pandoraLog("Proxy mode enabled");
|
2011-07-28 19:34:51 +02:00
|
|
|
} else {
|
|
|
|
pandoraLog ("[error] You can not proxy to localhost");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
string
|
2006-07-04 16:07:08 +02:00
|
|
|
Pandora_Windows_Service::getXmlHeader () {
|
2008-07-09 14:46:22 +02:00
|
|
|
char timestamp[20];
|
2016-09-29 12:50:04 +02:00
|
|
|
string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd, agent_alias;
|
2016-06-03 11:58:13 +02:00
|
|
|
string custom_id, url_address, latitude, longitude, altitude, position_description, gis_exec, gis_result, agent_mode;
|
2016-12-13 14:28:25 +01:00
|
|
|
string group_password, group_id, ehorus_conf;
|
2008-07-31 12:31:58 +02:00
|
|
|
time_t ctime;
|
|
|
|
struct tm *ctime_tm = NULL;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
// Get agent name
|
|
|
|
agent_name = conf->getValue ("agent_name");
|
2011-09-01 16:37:57 +02:00
|
|
|
|
2016-09-29 12:50:04 +02:00
|
|
|
// Get agent alias
|
2017-04-10 11:27:34 +02:00
|
|
|
agent_alias = conf->getValue ("agent_alias");
|
2014-11-16 04:04:00 +01:00
|
|
|
|
2011-09-01 16:37:57 +02:00
|
|
|
// Get parent agent name
|
|
|
|
parent_agent_name = conf->getValue ("parent_agent_name");
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
// Get timestamp
|
2008-07-31 12:31:58 +02:00
|
|
|
ctime = time(0);
|
2008-11-28 11:51:03 +01:00
|
|
|
ctime_tm = localtime(&ctime);
|
2009-10-15 16:30:38 +02:00
|
|
|
value = conf->getValue ("autotime");
|
2010-07-06 13:47:43 +02:00
|
|
|
timestamp[0] = '\0';
|
2009-10-15 16:30:38 +02:00
|
|
|
if (value != "1") {
|
|
|
|
sprintf (timestamp, "%d-%02d-%02d %02d:%02d:%02d", ctime_tm->tm_year + 1900,
|
|
|
|
ctime_tm->tm_mon + 1, ctime_tm->tm_mday, ctime_tm->tm_hour,
|
|
|
|
ctime_tm->tm_min, ctime_tm->tm_sec);
|
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
// Get OS name and version
|
|
|
|
os_name = Pandora_Windows_Info::getOSName ();
|
|
|
|
os_version = os_name + Pandora_Windows_Info::getOSVersion ();
|
2009-10-15 16:30:38 +02:00
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
// Get encoding
|
|
|
|
encoding = conf->getValue ("encoding");
|
|
|
|
if (encoding == "") {
|
|
|
|
encoding = "ISO-8859-1";
|
|
|
|
}
|
|
|
|
|
2010-07-06 13:47:43 +02:00
|
|
|
xml = "<?xml version=\"1.0\" encoding=\"" + encoding + "\" ?>\n" +
|
|
|
|
"<agent_data agent_name=\"" + agent_name +
|
2016-09-29 12:50:04 +02:00
|
|
|
"\" agent_alias=\"" + agent_alias +
|
2010-07-06 13:47:43 +02:00
|
|
|
"\" description=\"" + conf->getValue ("description") +
|
|
|
|
"\" version=\"" + getPandoraAgentVersion ();
|
|
|
|
|
|
|
|
/* Skip the timestamp if autotime was enabled */
|
|
|
|
if (timestamp[0] != '\0') {
|
|
|
|
xml += "\" timestamp=\"";
|
|
|
|
xml += timestamp;
|
|
|
|
}
|
2011-08-18 11:41:37 +02:00
|
|
|
|
|
|
|
// Get agent address
|
|
|
|
address = conf->getValue ("address");
|
|
|
|
if (address != "") {
|
|
|
|
if(address == "auto") {
|
|
|
|
address = Pandora_Windows_Info::getSystemAddress ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(address != "") {
|
|
|
|
xml += "\" address=\"";
|
|
|
|
xml += address;
|
|
|
|
}
|
|
|
|
}
|
2012-11-19 16:57:56 +01:00
|
|
|
|
|
|
|
// Get Custom ID
|
|
|
|
custom_id = conf->getValue ("custom_id");
|
|
|
|
if (custom_id != "") {
|
|
|
|
xml += "\" custom_id=\"";
|
|
|
|
xml += custom_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get Url Address
|
|
|
|
url_address = conf->getValue ("url_address");
|
|
|
|
if (url_address != "") {
|
|
|
|
xml += "\" url_address=\"";
|
|
|
|
xml += url_address;
|
|
|
|
}
|
2016-11-25 12:41:27 +01:00
|
|
|
|
2016-12-07 15:51:21 +01:00
|
|
|
// Get group password
|
2016-11-25 12:41:27 +01:00
|
|
|
group_password = conf->getValue ("group_password");
|
|
|
|
if (group_password != "") {
|
|
|
|
xml += "\" group_password=\"";
|
|
|
|
xml += group_password;
|
|
|
|
}
|
2016-12-13 14:28:25 +01:00
|
|
|
|
|
|
|
// Get Group ID
|
|
|
|
group_id = conf->getValue ("group_id");
|
|
|
|
if (group_id != "") {
|
|
|
|
xml += "\" group_id=\"";
|
|
|
|
xml += group_id;
|
|
|
|
}
|
2012-11-19 16:57:56 +01:00
|
|
|
|
|
|
|
// Get Coordinates
|
2012-11-21 18:13:05 +01:00
|
|
|
gis_exec = conf->getValue ("gis_exec");
|
|
|
|
|
|
|
|
if(gis_exec != "") {
|
2014-11-16 04:04:00 +01:00
|
|
|
gis_result = getCoordinatesFromCmdExec(gis_exec);
|
2013-04-11 13:33:52 +02:00
|
|
|
if(gis_result != "") {
|
|
|
|
// Delete carriage return if is provided
|
|
|
|
pos = gis_result.find("\n");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
gis_result.erase(pos, gis_result.size () - pos);
|
|
|
|
}
|
|
|
|
pos = gis_result.find("\r");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
gis_result.erase(pos, gis_result.size () - pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the result as "latitude,longitude,altitude"
|
2014-11-16 04:04:00 +01:00
|
|
|
pandoraDebug ("getCoordinatesFromCmdExec: Parsing coordinates %s", gis_result.c_str ());
|
2013-04-11 13:33:52 +02:00
|
|
|
pos = gis_result.find(",");
|
|
|
|
if (pos != string::npos && pos != 0) {
|
|
|
|
latitude = gis_result;
|
|
|
|
gis_result = gis_result.substr(pos+1);
|
|
|
|
latitude.erase(pos, latitude.size () - pos);
|
|
|
|
pos = gis_result.find(",");
|
|
|
|
if(pos != string::npos && pos != 0) {
|
|
|
|
longitude = gis_result;
|
|
|
|
altitude = gis_result.substr(pos+1);
|
|
|
|
longitude.erase(pos, longitude.size () - pos);
|
|
|
|
}
|
2012-11-21 18:13:05 +01:00
|
|
|
xml += "\" latitude=\"";
|
|
|
|
xml += latitude;
|
|
|
|
xml += "\" longitude=\"";
|
|
|
|
xml += longitude;
|
|
|
|
xml += "\" altitude=\"";
|
|
|
|
xml += altitude;
|
2013-04-11 13:33:52 +02:00
|
|
|
}
|
|
|
|
}
|
2012-11-21 18:13:05 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
latitude = conf->getValue ("latitude");
|
|
|
|
longitude = conf->getValue ("longitude");
|
|
|
|
if(latitude != "" && longitude != "") {
|
|
|
|
xml += "\" latitude=\"";
|
|
|
|
xml += latitude;
|
|
|
|
xml += "\" longitude=\"";
|
|
|
|
xml += longitude;
|
|
|
|
|
|
|
|
altitude = conf->getValue ("altitude");
|
|
|
|
if(altitude != "") {
|
|
|
|
xml += "\" altitude=\"";
|
|
|
|
xml += altitude;
|
|
|
|
}
|
|
|
|
|
|
|
|
position_description = conf->getValue ("position_description");
|
|
|
|
position_description = "";
|
|
|
|
if(position_description != "") {
|
|
|
|
xml += "\" position_description=\"";
|
|
|
|
xml += position_description;
|
|
|
|
}
|
2012-11-19 16:57:56 +01:00
|
|
|
}
|
|
|
|
}
|
2016-06-03 11:58:13 +02:00
|
|
|
|
|
|
|
// Get agent mode
|
|
|
|
agent_mode = conf->getValue ("agent_mode");
|
|
|
|
// Convert the type string to lowercase
|
|
|
|
for (int i = 0; i < agent_mode.length(); i++) {
|
|
|
|
agent_mode[i] = tolower(agent_mode[i]);
|
|
|
|
}
|
|
|
|
if (!agent_mode.compare("no-learn") || !agent_mode.compare("nolearn")) {
|
|
|
|
agent_mode = "0";
|
|
|
|
} else if (!agent_mode.compare("autodisable")) {
|
|
|
|
agent_mode = "2";
|
|
|
|
} else {
|
|
|
|
agent_mode = "1";
|
|
|
|
}
|
2010-07-06 13:47:43 +02:00
|
|
|
|
|
|
|
xml += "\" interval=\"" + conf->getValue ("interval") +
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
"\" os_name=\"" + os_name +
|
|
|
|
"\" os_version=\"" + os_version +
|
2011-09-01 16:37:57 +02:00
|
|
|
"\" group=\"" + conf->getValue ("group") +
|
2016-06-03 11:58:13 +02:00
|
|
|
"\" parent_agent_name=\"" + conf->getValue ("parent_agent_name") +
|
2018-04-05 11:02:19 +02:00
|
|
|
"\" secondary_groups=\"" + conf->getValue ("secondary_groups") +
|
2016-06-03 11:58:13 +02:00
|
|
|
"\" agent_mode=\"" + agent_mode +
|
|
|
|
"\">\n";
|
2010-07-06 13:47:43 +02:00
|
|
|
return xml;
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2012-11-21 18:13:05 +01:00
|
|
|
string
|
2015-03-04 12:23:05 +01:00
|
|
|
Pandora_Windows_Service::getValueFromCmdExec (string cmd_exec, int timeout)
|
2012-11-21 18:13:05 +01:00
|
|
|
{
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
|
|
|
DWORD retval, dwRet;
|
|
|
|
SECURITY_ATTRIBUTES attributes;
|
|
|
|
HANDLE out, new_stdout, out_read, job;
|
|
|
|
string working_dir;
|
|
|
|
string output = "";
|
|
|
|
|
2013-04-11 13:33:52 +02:00
|
|
|
/* Set the bInheritHandle flag so pipe handles are inherited. */
|
|
|
|
attributes.nLength = sizeof (SECURITY_ATTRIBUTES);
|
|
|
|
attributes.bInheritHandle = TRUE;
|
|
|
|
attributes.lpSecurityDescriptor = NULL;
|
|
|
|
|
|
|
|
/* Create a job to kill the child tree if it become zombie */
|
|
|
|
/* CAUTION: In order to compile this, WINVER should be defined to 0x0500.
|
|
|
|
This may need no change, since it was redefined by the
|
|
|
|
program, but if needed, the macro is defined
|
|
|
|
in <windef.h> */
|
|
|
|
|
|
|
|
job = CreateJobObject (&attributes, NULL);
|
|
|
|
|
|
|
|
if (job == NULL) {
|
2015-03-04 17:44:59 +01:00
|
|
|
pandoraLog ("getValueFromCmdExec: CreateJobObject failed. Err: %d", GetLastError ());
|
2013-04-11 13:33:52 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the handle to the current STDOUT. */
|
|
|
|
out = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
2015-03-04 17:44:59 +01:00
|
|
|
pandoraLog ("getValueFromCmdExec: CreatePipe failed. Err: %d", GetLastError ());
|
2013-04-11 13:33:52 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure the read handle to the pipe for STDOUT is not inherited */
|
|
|
|
SetHandleInformation (out_read, HANDLE_FLAG_INHERIT, 0);
|
|
|
|
|
2012-11-21 18:13:05 +01:00
|
|
|
|
|
|
|
ZeroMemory (&si, sizeof (si));
|
2013-04-11 13:33:52 +02:00
|
|
|
GetStartupInfo (&si);
|
|
|
|
|
|
|
|
si.cb = sizeof (si);
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
si.hStdError = new_stdout;
|
|
|
|
si.hStdOutput = new_stdout;
|
|
|
|
|
|
|
|
/* Set up members of the PROCESS_INFORMATION structure. */
|
2012-11-21 18:13:05 +01:00
|
|
|
ZeroMemory (&pi, sizeof (pi));
|
|
|
|
|
2014-11-16 04:04:00 +01:00
|
|
|
pandoraDebug ("Executing cmd_exec: %s", cmd_exec.c_str ());
|
2012-11-21 18:13:05 +01:00
|
|
|
|
|
|
|
/* Create the child process. */
|
2014-11-16 04:04:00 +01:00
|
|
|
if (CreateProcess (NULL , (CHAR *)cmd_exec.c_str (), NULL, NULL, TRUE,
|
2012-11-21 18:13:05 +01:00
|
|
|
CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) {
|
2015-03-04 17:44:59 +01:00
|
|
|
pandoraLog ("getValueFromCmdExec: %s CreateProcess failed. Err: %d",
|
2014-11-16 04:04:00 +01:00
|
|
|
cmd_exec.c_str (), GetLastError ());
|
2012-11-21 18:13:05 +01:00
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
char buffer[BUFSIZE + 1];
|
|
|
|
unsigned long read, avail;
|
|
|
|
|
|
|
|
if (! AssignProcessToJobObject (job, pi.hProcess)) {
|
2015-03-04 17:44:59 +01:00
|
|
|
pandoraLog ("getValueFromCmdExec: could not assign proccess to job (error %d)",
|
2012-11-21 18:13:05 +01:00
|
|
|
GetLastError ());
|
|
|
|
}
|
|
|
|
ResumeThread (pi.hThread);
|
|
|
|
|
|
|
|
/*string output;*/
|
|
|
|
int tickbase = GetTickCount();
|
|
|
|
while ( (dwRet = WaitForSingleObject (pi.hProcess, 500)) != WAIT_ABANDONED ) {
|
|
|
|
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
|
|
|
if (avail > 0) {
|
|
|
|
ReadFile (out_read, buffer, BUFSIZE, &read, NULL);
|
|
|
|
buffer[read] = '\0';
|
|
|
|
output += (char *) buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dwRet == WAIT_OBJECT_0) {
|
|
|
|
break;
|
|
|
|
} else if(timeout < GetTickCount() - tickbase) {
|
|
|
|
/* STILL_ACTIVE */
|
|
|
|
TerminateProcess(pi.hThread, STILL_ACTIVE);
|
2015-03-04 17:44:59 +01:00
|
|
|
pandoraLog ("getValueFromCmdExec: %s timed out (retcode: %d)", cmd_exec.c_str (), STILL_ACTIVE);
|
2012-11-21 18:13:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-11 13:33:52 +02:00
|
|
|
|
2012-11-21 18:13:05 +01:00
|
|
|
GetExitCodeProcess (pi.hProcess, &retval);
|
|
|
|
|
|
|
|
if (retval != 0) {
|
|
|
|
if (! TerminateJobObject (job, 0)) {
|
2015-03-04 17:44:59 +01:00
|
|
|
pandoraLog ("getValueFromCmdExec: TerminateJobObject failed. (error %d)",
|
2012-11-21 18:13:05 +01:00
|
|
|
GetLastError ());
|
|
|
|
}
|
|
|
|
if (retval != STILL_ACTIVE) {
|
2015-03-04 17:44:59 +01:00
|
|
|
pandoraLog ("getValueFromCmdExec: %s did not executed well (retcode: %d)",
|
2014-11-16 04:04:00 +01:00
|
|
|
cmd_exec.c_str (), retval);
|
2012-11-21 18:13:05 +01:00
|
|
|
}
|
|
|
|
/* Close job, process and thread handles. */
|
|
|
|
CloseHandle (job);
|
|
|
|
CloseHandle (pi.hProcess);
|
|
|
|
CloseHandle (pi.hThread);
|
|
|
|
CloseHandle (new_stdout);
|
|
|
|
CloseHandle (out_read);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close job, process and thread handles. */
|
|
|
|
CloseHandle (job);
|
|
|
|
CloseHandle (pi.hProcess);
|
|
|
|
CloseHandle (pi.hThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle (new_stdout);
|
|
|
|
CloseHandle (out_read);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-03-04 12:23:05 +01:00
|
|
|
string
|
|
|
|
Pandora_Windows_Service::getAgentNameFromCmdExec (string cmd_exec)
|
|
|
|
{
|
2015-03-04 17:43:39 +01:00
|
|
|
return getValueFromCmdExec(cmd_exec, 60000);
|
2015-03-04 12:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
Pandora_Windows_Service::getCoordinatesFromCmdExec (string cmd_exec)
|
|
|
|
{
|
|
|
|
return getValueFromCmdExec(cmd_exec, 500);
|
|
|
|
}
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int
|
2008-03-14 14:41:31 +01:00
|
|
|
Pandora_Windows_Service::copyTentacleDataFile (string host,
|
2008-12-11 12:57:03 +01:00
|
|
|
string filename,
|
|
|
|
string port,
|
|
|
|
string ssl,
|
|
|
|
string pass,
|
2015-06-03 09:03:27 +02:00
|
|
|
string opts,
|
|
|
|
int timeout)
|
2008-03-14 14:41:31 +01:00
|
|
|
{
|
2010-05-13 17:39:52 +02:00
|
|
|
DWORD rc;
|
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 var, filepath;
|
2009-02-24 19:50:16 +01:00
|
|
|
string tentacle_cmd, working_dir;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
2008-03-14 14:41:31 +01:00
|
|
|
var = conf->getValue ("temporal");
|
|
|
|
if (var[var.length () - 1] != '\\') {
|
|
|
|
var += "\\";
|
|
|
|
}
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
filepath = var + filename;
|
|
|
|
|
2008-03-14 14:41:31 +01:00
|
|
|
/* Build the command to launch the Tentacle client */
|
|
|
|
tentacle_cmd = "tentacle_client.exe -a " + host;
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-12-11 12:57:03 +01:00
|
|
|
if (port != "") {
|
|
|
|
tentacle_cmd += " -p " + port;
|
2008-03-14 14:41:31 +01:00
|
|
|
}
|
|
|
|
|
2008-12-11 12:57:03 +01:00
|
|
|
if (ssl == "1") {
|
2008-03-14 14:41:31 +01:00
|
|
|
tentacle_cmd += " -c";
|
|
|
|
}
|
|
|
|
|
2008-12-11 12:57:03 +01:00
|
|
|
if (pass != "") {
|
|
|
|
tentacle_cmd += " -x " + pass;
|
2008-03-14 14:41:31 +01:00
|
|
|
}
|
|
|
|
|
2008-12-11 12:57:03 +01:00
|
|
|
if (opts != "") {
|
|
|
|
tentacle_cmd += " " + opts;
|
2008-03-14 14:41:31 +01:00
|
|
|
}
|
|
|
|
|
2009-09-24 18:29:25 +02:00
|
|
|
tentacle_cmd += " \"" + filepath + "\"";
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-03-14 14:41:31 +01:00
|
|
|
/* Copy the file */
|
|
|
|
pandoraDebug ("Remote copying XML %s on server %s",
|
2008-07-09 14:46:22 +02:00
|
|
|
filepath.c_str (), host.c_str ());
|
2008-03-14 14:41:31 +01:00
|
|
|
pandoraDebug ("Command %s", tentacle_cmd.c_str());
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2009-02-24 19:50:16 +01:00
|
|
|
ZeroMemory (&si, sizeof (si));
|
|
|
|
ZeroMemory (&pi, sizeof (pi));
|
2010-05-13 17:39:52 +02:00
|
|
|
if (CreateProcess (NULL , (CHAR *)tentacle_cmd.c_str (), NULL, NULL, FALSE,
|
|
|
|
CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-04-11 13:33:52 +02:00
|
|
|
|
|
|
|
/* close thread handle, because it won't be used */
|
|
|
|
CloseHandle (pi.hThread);
|
2012-02-07 17:33:01 +01:00
|
|
|
|
|
|
|
/* Timeout */
|
2015-06-03 09:03:27 +02:00
|
|
|
if (timeout <= 0) {
|
|
|
|
timeout = 30;
|
|
|
|
}
|
|
|
|
/* Convert to milliseconds */
|
|
|
|
timeout *= 1000;
|
2012-02-07 17:33:01 +01:00
|
|
|
|
2015-06-03 09:03:27 +02:00
|
|
|
if (WaitForSingleObject(pi.hProcess, timeout) == WAIT_TIMEOUT) {
|
2013-04-11 13:33:52 +02:00
|
|
|
TerminateProcess(pi.hProcess, STILL_ACTIVE);
|
2012-02-07 17:33:01 +01:00
|
|
|
CloseHandle (pi.hProcess);
|
2015-06-03 09:03:27 +02:00
|
|
|
pandoraLog ("Pandora Agent: Failed when copying to %s (tentacle timeout)", host.c_str ());
|
2012-02-07 17:33:01 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2010-05-13 17:39:52 +02:00
|
|
|
|
2012-02-07 17:33:01 +01:00
|
|
|
/* Get the return code of the tentacle client*/
|
2015-06-03 09:03:27 +02:00
|
|
|
GetExitCodeProcess (pi.hProcess, &rc);
|
2010-05-13 17:39:52 +02:00
|
|
|
if (rc != 0) {
|
2010-07-02 16:25:53 +02:00
|
|
|
CloseHandle (pi.hProcess);
|
2015-06-03 09:03:27 +02:00
|
|
|
pandoraLog ("Pandora Agent: Failed when copying to %s",
|
|
|
|
host.c_str ());
|
2010-05-13 17:39:52 +02:00
|
|
|
return -1;
|
2009-02-09 18:47:24 +01:00
|
|
|
}
|
2009-02-24 19:50:16 +01:00
|
|
|
|
2010-07-02 16:25:53 +02:00
|
|
|
CloseHandle (pi.hProcess);
|
2010-05-13 17:39:52 +02:00
|
|
|
return 0;
|
2008-03-14 14:41:31 +01:00
|
|
|
}
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int
|
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
|
|
|
{
|
2015-06-03 09:03:27 +02:00
|
|
|
/* TODO: timeout implementation */
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int rc = 0;
|
2007-08-07 16:28:14 +02:00
|
|
|
SSH::Pandora_Ssh_Client ssh_client;
|
2010-07-07 17:14:18 +02:00
|
|
|
string tmp_dir, filepath,port_str;
|
2007-08-07 16:28:14 +02:00
|
|
|
string pubkey_file, privkey_file;
|
2010-07-07 17:14:18 +02:00
|
|
|
int port;
|
2006-07-04 16:07:08 +02:00
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
tmp_dir = conf->getValue ("temporal");
|
2008-07-09 14:46:22 +02:00
|
|
|
if (tmp_dir[tmp_dir.length () - 1] != '\\') {
|
|
|
|
tmp_dir += "\\";
|
|
|
|
}
|
|
|
|
filepath = tmp_dir + filename;
|
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
pandoraDebug ("Connecting with %s", host.c_str ());
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
pubkey_file = Pandora::getPandoraInstallDir ();
|
|
|
|
pubkey_file += "key\\id_dsa.pub";
|
|
|
|
privkey_file = Pandora::getPandoraInstallDir ();
|
|
|
|
privkey_file += "key\\id_dsa";
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2010-07-07 17:14:18 +02:00
|
|
|
port_str = conf->getValue ("server_port");
|
|
|
|
if (port_str.length () == 0) {
|
|
|
|
port = SSH_DEFAULT_PORT;
|
|
|
|
} else {
|
|
|
|
port = strtoint(port_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ssh_client.connectWithPublicKey (host.c_str (), port, "pandora",
|
2007-08-07 16:28:14 +02:00
|
|
|
pubkey_file, privkey_file, "");
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
if (rc == AUTHENTICATION_FAILED) {
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraLog ("Pandora Agent: Authentication Failed "
|
2007-08-07 16:28:14 +02:00
|
|
|
"when connecting to %s",
|
2008-07-09 14:46:22 +02:00
|
|
|
host.c_str ());
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
|
|
|
} else if (rc == PANDORA_EXCEPTION) {
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraLog ("Pandora Agent: Failed when copying to %s",
|
|
|
|
host.c_str ());
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
2008-07-09 14:46:22 +02:00
|
|
|
}
|
2007-08-07 16:28:14 +02:00
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraDebug ("Remote copying XML %s on server %s at %s%s",
|
|
|
|
filepath.c_str (), host.c_str (),
|
|
|
|
remote_path.c_str (), filename.c_str ());
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
|
|
|
|
rc = ssh_client.scpFileFilename (remote_path + filename,
|
2008-07-09 14:46:22 +02:00
|
|
|
filepath);
|
2010-11-17 20:22:04 +01:00
|
|
|
if (rc == PANDORA_EXCEPTION) {
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraLog ("Unable to copy at %s%s", remote_path.c_str (),
|
|
|
|
filename.c_str ());
|
|
|
|
ssh_client.disconnect();
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
2008-07-09 14:46:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ssh_client.disconnect();
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
2007-08-07 16:28:14 +02:00
|
|
|
}
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int
|
2007-08-07 16:28:14 +02:00
|
|
|
Pandora_Windows_Service::copyFtpDataFile (string host,
|
|
|
|
string remote_path,
|
2008-12-11 12:57:03 +01:00
|
|
|
string filename,
|
2015-06-03 09:03:27 +02:00
|
|
|
string password,
|
|
|
|
int timeout)
|
2007-08-07 16:28:14 +02:00
|
|
|
{
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int rc = 0;
|
2007-08-07 16:28:14 +02:00
|
|
|
FTP::Pandora_Ftp_Client ftp_client;
|
2010-07-07 17:14:18 +02:00
|
|
|
string filepath, port_str;
|
|
|
|
int port;
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
filepath = conf->getValue ("temporal");
|
2008-07-09 14:46:22 +02:00
|
|
|
if (filepath[filepath.length () - 1] != '\\') {
|
|
|
|
filepath += "\\";
|
|
|
|
}
|
|
|
|
filepath += filename;
|
2007-08-07 16:28:14 +02:00
|
|
|
|
2010-07-07 17:14:18 +02:00
|
|
|
port_str = conf->getValue ("server_port");
|
|
|
|
if (port_str.length () == 0) {
|
|
|
|
port = FTP_DEFAULT_PORT;
|
|
|
|
} else {
|
|
|
|
port = strtoint(port_str);
|
|
|
|
}
|
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
ftp_client.connect (host,
|
2010-07-07 17:14:18 +02:00
|
|
|
port,
|
2007-08-07 16:28:14 +02:00
|
|
|
"pandora",
|
|
|
|
password);
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
rc = ftp_client.ftpFileFilename (remote_path + filename,
|
2015-06-03 09:03:27 +02:00
|
|
|
filepath, timeout);
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
if (rc == UNKNOWN_HOST) {
|
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 ();
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
|
|
|
} else if (rc == AUTHENTICATION_FAILED) {
|
2007-08-07 16:28:14 +02:00
|
|
|
pandoraLog ("Pandora Agent: Authentication Failed "
|
|
|
|
"when connecting to %s (%s)",
|
2008-07-09 14:46:22 +02:00
|
|
|
host.c_str (), ftp_client.getError ().c_str ());
|
2007-08-29 16:30:09 +02:00
|
|
|
ftp_client.disconnect ();
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
|
|
|
} else if (rc == FTP_EXCEPTION) {
|
2007-08-07 16:28:14 +02:00
|
|
|
pandoraLog ("Pandora Agent: Failed when copying to %s (%s)",
|
2008-07-09 14:46:22 +02:00
|
|
|
host.c_str (), ftp_client.getError ().c_str ());
|
2007-08-29 16:30:09 +02:00
|
|
|
ftp_client.disconnect ();
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
2007-08-07 16:28:14 +02:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
ftp_client.disconnect ();
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return rc;
|
2007-08-07 16:28:14 +02:00
|
|
|
}
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int
|
2020-01-29 13:00:17 +01:00
|
|
|
Pandora_Windows_Service::copyDataFile (string filename, bool secondary_buffer)
|
2007-08-07 16:28:14 +02:00
|
|
|
{
|
2015-06-03 09:03:27 +02:00
|
|
|
int rc = 0, timeout;
|
2008-12-11 12:57:03 +01:00
|
|
|
unsigned char copy_to_secondary = 0;
|
2007-08-07 16:28:14 +02:00
|
|
|
string mode, host, remote_path;
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2007-08-07 16:28:14 +02:00
|
|
|
mode = conf->getValue ("transfer_mode");
|
|
|
|
host = conf->getValue ("server_ip");
|
|
|
|
remote_path = conf->getValue ("server_path");
|
2015-06-03 09:03:27 +02:00
|
|
|
timeout = atoi (conf->getValue ("transfer_timeout").c_str ());
|
|
|
|
if (timeout == 0) {
|
|
|
|
timeout = 30;
|
|
|
|
}
|
|
|
|
|
2008-12-24 14:57:45 +01:00
|
|
|
// Fix remote path
|
|
|
|
if (mode != "local" && remote_path[remote_path.length () - 1] != '/') {
|
2008-07-09 14:46:22 +02:00
|
|
|
remote_path += "/";
|
2008-12-24 14:57:45 +01:00
|
|
|
} else if (mode == "local" && remote_path[remote_path.length () - 1] != '\\') {
|
|
|
|
remote_path += "\\";
|
2008-07-09 14:46:22 +02:00
|
|
|
}
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
if (mode == "ftp") {
|
2015-06-03 09:03:27 +02:00
|
|
|
rc = copyFtpDataFile (host, remote_path, filename, conf->getValue ("server_pwd"), timeout);
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
} else if (mode == "tentacle" || mode == "") {
|
|
|
|
rc = copyTentacleDataFile (host, filename, conf->getValue ("server_port"),
|
2008-12-11 12:57:03 +01:00
|
|
|
conf->getValue ("server_ssl"), conf->getValue ("server_pwd"),
|
2015-06-03 09:03:27 +02:00
|
|
|
conf->getValue ("server_opts"), timeout);
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
} else if (mode == "ssh") {
|
|
|
|
rc =copyScpDataFile (host, remote_path, filename);
|
|
|
|
} else if (mode == "local") {
|
|
|
|
rc = copyLocalDataFile (remote_path, filename);
|
|
|
|
} else {
|
|
|
|
rc = PANDORA_EXCEPTION;
|
|
|
|
pandoraLog ("Invalid transfer mode: %s."
|
|
|
|
"Please recheck transfer_mode option "
|
|
|
|
"in configuration file.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == 0) {
|
2007-08-23 18:22:56 +02:00
|
|
|
pandoraDebug ("Successfuly copied XML file to server.");
|
2008-12-11 12:57:03 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 13:00:17 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Pandora_Windows_Service::copyToSecondary (string filename, bool secondary_buffer)
|
|
|
|
{
|
|
|
|
int rc = 0, timeout;
|
|
|
|
unsigned char copy_to_secondary = 0;
|
|
|
|
string mode, host, remote_path;
|
2008-12-11 12:57:03 +01:00
|
|
|
|
2010-11-05 15:07:42 +01:00
|
|
|
// Read secondary server configuration
|
|
|
|
mode = conf->getValue ("secondary_transfer_mode");
|
|
|
|
host = conf->getValue ("secondary_server_ip");
|
|
|
|
remote_path = conf->getValue ("secondary_server_path");
|
2015-06-03 09:03:27 +02:00
|
|
|
timeout = atoi (conf->getValue ("secondary_transfer_timeout").c_str ());
|
|
|
|
if (timeout == 0) {
|
|
|
|
timeout = 30;
|
|
|
|
}
|
2010-11-05 15:07:42 +01:00
|
|
|
|
2020-01-29 13:00:17 +01:00
|
|
|
// Adjust the path for the secondary buffer.
|
|
|
|
if (secondary_buffer) {
|
|
|
|
filename.insert(0, "\\");
|
|
|
|
filename.insert(0, SECONDARY_DIR);
|
|
|
|
}
|
|
|
|
|
2010-11-05 15:07:42 +01:00
|
|
|
// Fix remote path
|
|
|
|
if (mode != "local" && remote_path[remote_path.length () - 1] != '/') {
|
|
|
|
remote_path += "/";
|
|
|
|
} else if (mode == "local" && remote_path[remote_path.length () - 1] != '\\') {
|
|
|
|
remote_path += "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the file to the secondary server
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
if (mode == "ftp") {
|
2015-06-03 09:03:27 +02:00
|
|
|
rc = copyFtpDataFile (host, remote_path, filename, conf->getValue ("secondary_server_pwd"), timeout);
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
} else if (mode == "tentacle" || mode == "") {
|
|
|
|
rc = copyTentacleDataFile (host, filename, conf->getValue ("secondary_server_port"),
|
2008-12-11 12:57:03 +01:00
|
|
|
conf->getValue ("secondary_server_ssl"), conf->getValue ("secondary_server_pwd"),
|
2015-06-03 09:03:27 +02:00
|
|
|
conf->getValue ("secondary_server_opts"), timeout);
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
} else if (mode == "ssh") {
|
|
|
|
rc = copyScpDataFile (host, remote_path, filename);
|
|
|
|
} else {
|
|
|
|
rc = PANDORA_EXCEPTION;
|
|
|
|
pandoraLog ("Invalid transfer mode: %s."
|
2020-01-29 13:00:17 +01:00
|
|
|
"Please recheck secondary_transfer_mode option "
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
"in configuration file.");
|
|
|
|
}
|
2008-12-11 12:57:03 +01:00
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
if (rc == 0) {
|
2008-12-11 12:57:03 +01:00
|
|
|
pandoraDebug ("Successfuly copied XML file to secondary server.");
|
2007-08-07 16:28:14 +02:00
|
|
|
}
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
|
|
|
|
return rc;
|
2006-12-01 17:29:27 +01:00
|
|
|
}
|
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::recvTentacleDataFile (string host,
|
2015-06-03 09:03:27 +02:00
|
|
|
string filename,
|
|
|
|
int timeout)
|
2008-06-10 11:50:29 +02:00
|
|
|
{
|
2015-06-03 09:03:27 +02:00
|
|
|
DWORD rc;
|
2008-06-10 11:50:29 +02:00
|
|
|
string var;
|
|
|
|
string tentacle_cmd;
|
2015-06-03 09:03:27 +02:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
2008-06-10 11:50:29 +02:00
|
|
|
|
|
|
|
/* 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;
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
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",
|
2008-07-09 14:46:22 +02:00
|
|
|
filename.c_str (), host.c_str ());
|
2008-06-10 11:50:29 +02:00
|
|
|
pandoraDebug ("Command %s", tentacle_cmd.c_str());
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2015-06-03 09:03:27 +02:00
|
|
|
ZeroMemory (&si, sizeof (si));
|
|
|
|
ZeroMemory (&pi, sizeof (pi));
|
|
|
|
if (CreateProcess (NULL , (CHAR *)tentacle_cmd.c_str (), NULL, NULL, FALSE,
|
|
|
|
CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) {
|
2015-09-08 15:41:14 +02:00
|
|
|
throw Pandora_Exception ();
|
2015-06-03 09:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* close thread handle, because it won't be used */
|
|
|
|
CloseHandle (pi.hThread);
|
|
|
|
|
|
|
|
/* Timeout */
|
|
|
|
if (timeout <= 0) {
|
|
|
|
timeout = 30;
|
|
|
|
}
|
|
|
|
/* Convert to milliseconds */
|
|
|
|
timeout *= 1000;
|
|
|
|
|
|
|
|
if (WaitForSingleObject(pi.hProcess, timeout) == WAIT_TIMEOUT) {
|
|
|
|
TerminateProcess(pi.hProcess, STILL_ACTIVE);
|
|
|
|
CloseHandle (pi.hProcess);
|
|
|
|
pandoraLog ("Unable to receive file %s (tentacle timeout)", filename.c_str ());
|
2015-09-08 15:41:14 +02:00
|
|
|
throw Pandora_Exception ();
|
2015-06-03 09:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the return code of the tentacle client*/
|
|
|
|
GetExitCodeProcess (pi.hProcess, &rc);
|
|
|
|
if (rc != 0) {
|
|
|
|
CloseHandle (pi.hProcess);
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraLog ("Unable to receive file %s", filename.c_str ());
|
2015-09-08 15:41:14 +02:00
|
|
|
throw Pandora_Exception ();
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-03 09:03:27 +02:00
|
|
|
CloseHandle (pi.hProcess);
|
2008-06-10 11:50:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::recvDataFile (string filename) {
|
|
|
|
string mode, host, remote_path;
|
2015-06-03 09:03:27 +02:00
|
|
|
int timeout;
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
mode = conf->getValue ("transfer_mode");
|
|
|
|
host = conf->getValue ("server_ip");
|
|
|
|
remote_path = conf->getValue ("server_path");
|
2015-06-03 09:03:27 +02:00
|
|
|
timeout = atoi (conf->getValue ("transfer_timeout").c_str ());
|
2008-06-10 11:50:29 +02:00
|
|
|
if (remote_path[remote_path.length () - 1] != '/') {
|
|
|
|
remote_path += "/";
|
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
try {
|
|
|
|
if (mode == "tentacle") {
|
2015-06-03 09:03:27 +02:00
|
|
|
recvTentacleDataFile (host, filename, timeout);
|
2008-06-10 11:50:29 +02:00
|
|
|
} else {
|
2010-07-07 17:14:18 +02:00
|
|
|
pandoraLog ("Transfer mode %s does not support file retrieval.", mode.c_str () );
|
2008-06-10 11:50:29 +02:00
|
|
|
throw Pandora_Exception ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Pandora_Exception e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int
|
2008-12-24 14:57:45 +01:00
|
|
|
Pandora_Windows_Service::copyLocalDataFile (string remote_path,
|
|
|
|
string filename)
|
|
|
|
{
|
|
|
|
string local_path, local_file, remote_file;
|
|
|
|
local_path = conf->getValue ("temporal");
|
|
|
|
if (local_path[local_path.length () - 1] != '\\') {
|
|
|
|
local_path += "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
local_file = local_path + filename;
|
|
|
|
remote_file = remote_path + filename;
|
|
|
|
if (!CopyFile (local_file.c_str (), remote_file.c_str (), TRUE)) {
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return PANDORA_EXCEPTION;
|
2008-12-24 14:57:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-16 13:43:07 +02:00
|
|
|
int
|
|
|
|
Pandora_Windows_Service::unzipCollection(string zip_path, string dest_dir) {
|
|
|
|
string unzip_cmd, dest_cmd;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
|
|
|
mode_t mode;
|
|
|
|
DWORD rc;
|
|
|
|
|
|
|
|
/*Delete dest directory*/
|
|
|
|
Pandora_File::removeDir(dest_dir);
|
|
|
|
|
|
|
|
/* Build the command to create destination diectory*/
|
|
|
|
rc = mkdir (dest_dir.c_str());
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
pandoraLog ("Pandora_Windows_Service::unzipCollection: Can not create dir %s", dest_dir.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the command to launch the Tentacle client */
|
|
|
|
unzip_cmd = "unzip.exe \"" + zip_path + "\" -d \"" + dest_dir + "\"";
|
|
|
|
|
|
|
|
ZeroMemory (&si, sizeof (si));
|
|
|
|
ZeroMemory (&pi, sizeof (pi));
|
|
|
|
if (CreateProcess (NULL , (CHAR *)unzip_cmd.c_str (), NULL, NULL, FALSE,
|
|
|
|
CREATE_NO_WINDOW, NULL, NULL, &si, &pi) == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the return code of the tentacle client*/
|
|
|
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
|
|
GetExitCodeProcess (pi.hProcess, &rc);
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
CloseHandle (pi.hProcess);
|
|
|
|
pandoraLog ("Pandora_Windows_Service::unzipCollection: Can not unzip file %s", zip_path.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle (pi.hProcess);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-21 12:03:20 +02:00
|
|
|
/*
|
|
|
|
* Check the disk for collections installed
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::purgeDiskCollections () {
|
|
|
|
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dir_content;
|
|
|
|
struct stat file;
|
|
|
|
string tmp, filepath;
|
|
|
|
|
2014-10-17 16:39:30 +02:00
|
|
|
/*Do not delete collections if there is a broker agent*/
|
2014-11-16 04:04:00 +01:00
|
|
|
if (conf->isBrokerEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-21 12:03:20 +02:00
|
|
|
filepath = Pandora::getPandoraInstallDir() +"collections\\";
|
|
|
|
/*Open the directory*/
|
|
|
|
dir = opendir (filepath.c_str ());
|
|
|
|
|
|
|
|
/*Read the directory looking for files and folders*/
|
|
|
|
dir_content = readdir(dir);
|
|
|
|
|
|
|
|
while (dir_content != NULL) {
|
|
|
|
|
|
|
|
stat(tmp.c_str(),&file);
|
|
|
|
|
|
|
|
/*If is a folder, check for . and .. */
|
|
|
|
if ( (strcmp(dir_content->d_name,".") != 0) && (strcmp(dir_content->d_name,"..") != 0) ) {
|
|
|
|
/*If the file is not in collection list, delete the file*/
|
|
|
|
if(! conf->isInCollectionList(dir_content->d_name) ) {
|
|
|
|
tmp = filepath+dir_content->d_name;
|
|
|
|
Pandora_File::removeDir(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Next item*/
|
|
|
|
dir_content = readdir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Close dir oppened*/
|
|
|
|
closedir(dir);
|
|
|
|
}
|
2010-07-16 13:43:07 +02:00
|
|
|
|
2010-07-21 12:03:20 +02:00
|
|
|
/*
|
|
|
|
* Check collections to sync it between server and agent
|
|
|
|
*/
|
2010-07-16 13:43:07 +02:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::checkCollections () {
|
|
|
|
|
|
|
|
int flag, i;
|
|
|
|
char *coll_md5 = NULL, *server_coll_md5 = NULL;
|
2013-04-11 13:33:52 +02:00
|
|
|
string collection_name, collections_dir, collection_path, collection_md5, tmp;
|
2010-07-16 13:43:07 +02:00
|
|
|
string collection_zip, install_dir, temp_dir, dest_dir, path, env;
|
|
|
|
|
|
|
|
/*Get collections directory*/
|
|
|
|
install_dir = Pandora::getPandoraInstallDir ();
|
|
|
|
collections_dir = install_dir+"collections\\";
|
|
|
|
|
|
|
|
/* Get temporal directory */
|
|
|
|
temp_dir = conf->getValue ("temporal");
|
|
|
|
if (temp_dir[temp_dir.length () - 1] != '\\') {
|
|
|
|
temp_dir += "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Set iterator in the firs collection*/
|
|
|
|
conf->goFirstCollection();
|
2010-07-20 18:38:29 +02:00
|
|
|
|
2010-07-16 13:43:07 +02:00
|
|
|
while (! conf->isLastCollection()) {
|
|
|
|
|
2010-07-20 18:38:29 +02:00
|
|
|
collection_name = conf->getCurrentCollectionName();
|
|
|
|
|
|
|
|
if(! conf->getCurrentCollectionVerify() ) {
|
2013-04-11 13:33:52 +02:00
|
|
|
int found;
|
|
|
|
|
|
|
|
/*Add the collection directory to the path (if not exists in %path%)*/
|
|
|
|
collection_path = collections_dir + collection_name;
|
2010-07-20 18:38:29 +02:00
|
|
|
path = getenv ("PATH");
|
|
|
|
|
2013-04-11 13:33:52 +02:00
|
|
|
/* check if the path is just included in the middle of %path% */
|
|
|
|
tmp = collection_path + ";"; /* Added a separator */
|
|
|
|
if(path.find(tmp) == string::npos) {
|
|
|
|
|
|
|
|
/* check if the path is the last entry of %path% */
|
|
|
|
if( ((found = path.rfind(collection_path)) != string::npos)
|
|
|
|
&& ((found + collection_path.length()) == path.length()) )
|
|
|
|
{
|
|
|
|
/* included already (at the tail of %path%) */
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* it's new ! */
|
|
|
|
env = "PATH=" + path + ";" + collection_path;
|
|
|
|
putenv (env.c_str ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
conf->setCurrentCollectionVerify();
|
2010-07-20 18:38:29 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 13:43:07 +02:00
|
|
|
collection_zip = collection_name+".zip";
|
|
|
|
collection_md5 = collection_name + ".md5";
|
|
|
|
tmp = collections_dir+collection_md5;
|
|
|
|
|
|
|
|
/*Reading local collection md5*/
|
|
|
|
try {
|
|
|
|
if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) {
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollection: Invalid local md5", tmp.c_str());
|
2010-07-16 13:43:07 +02:00
|
|
|
if (coll_md5 != NULL) {
|
|
|
|
delete[] coll_md5;
|
|
|
|
}
|
2010-07-20 18:38:29 +02:00
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-16 13:43:07 +02:00
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
/*Getting new md5*/
|
|
|
|
try {
|
|
|
|
/*Downloading md5 file*/
|
|
|
|
recvDataFile (collection_md5);
|
|
|
|
|
|
|
|
/*Reading new md5 file*/
|
|
|
|
tmp = temp_dir + collection_md5;
|
|
|
|
|
|
|
|
if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) {
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str());
|
2010-07-16 13:43:07 +02:00
|
|
|
if (coll_md5 != NULL) {
|
|
|
|
delete[] coll_md5;
|
2010-07-20 18:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-16 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
|
|
|
|
/* Save new md5 file */
|
|
|
|
tmp = collections_dir + collection_md5;
|
|
|
|
Pandora_File::writeBinFile (tmp, coll_md5, 32);
|
|
|
|
|
|
|
|
} catch(...) {
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_md5.c_str());
|
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-16 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Getting new zipped collection*/
|
|
|
|
try {
|
|
|
|
/*Downloading zipped collection*/
|
|
|
|
recvDataFile (collection_zip);
|
|
|
|
|
|
|
|
/*Uncompress zipped collection*/
|
|
|
|
tmp = temp_dir + collection_zip;
|
|
|
|
dest_dir = collections_dir + collection_name;
|
|
|
|
|
2010-07-20 18:38:29 +02:00
|
|
|
try {
|
|
|
|
unzipCollection(tmp,dest_dir);
|
|
|
|
} catch (...) {
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pandora_File::removeFile (tmp);
|
2010-07-16 13:43:07 +02:00
|
|
|
} catch (...) {
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str());
|
|
|
|
|
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-16 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Reading server collection md5*/
|
|
|
|
try {
|
|
|
|
|
|
|
|
recvDataFile(collection_md5);
|
|
|
|
tmp = temp_dir+collection_md5;
|
|
|
|
if (Pandora_File::readBinFile (tmp, &server_coll_md5) < 32) {
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str());
|
2010-07-16 13:43:07 +02:00
|
|
|
if (server_coll_md5 != NULL) {
|
|
|
|
delete[] server_coll_md5;
|
|
|
|
}
|
2010-07-20 18:38:29 +02:00
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-16 13:43:07 +02:00
|
|
|
}
|
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
|
|
|
|
} catch (...) {
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_md5.c_str());
|
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-16 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Check both md5*/
|
|
|
|
flag = 0;
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
if (coll_md5[i] != server_coll_md5[i]) {
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*If the two md5 are equals, exit*/
|
|
|
|
if (flag == 0) {
|
2010-07-20 18:38:29 +02:00
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-16 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollections: Collection %s has changed", collection_md5.c_str ());
|
2010-07-16 13:43:07 +02:00
|
|
|
|
|
|
|
/*Getting new zipped collection*/
|
|
|
|
try {
|
|
|
|
/*Downloading zipped collection*/
|
|
|
|
recvDataFile (collection_zip);
|
|
|
|
|
|
|
|
/*Uncompress zipped collection*/
|
|
|
|
tmp = temp_dir + collection_zip;
|
|
|
|
dest_dir = collections_dir + collection_name;
|
2010-07-14 19:16:08 +02:00
|
|
|
|
|
|
|
try {
|
2010-07-20 18:38:29 +02:00
|
|
|
unzipCollection(tmp,dest_dir);
|
2010-07-14 19:16:08 +02:00
|
|
|
} catch (...) {
|
2010-07-20 18:38:29 +02:00
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-14 19:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Pandora_File::removeFile (tmp);
|
2010-07-20 18:38:29 +02:00
|
|
|
|
2010-07-14 19:16:08 +02:00
|
|
|
} catch (...) {
|
2010-07-20 18:38:29 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str());
|
2010-07-14 19:16:08 +02:00
|
|
|
|
2010-07-20 18:38:29 +02:00
|
|
|
/*Go to next collection*/
|
|
|
|
conf->goNextCollection();
|
|
|
|
continue;
|
2010-07-14 19:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save new md5 file */
|
2010-07-20 18:38:29 +02:00
|
|
|
tmp = collections_dir + collection_md5;
|
2010-07-14 19:16:08 +02:00
|
|
|
Pandora_File::writeBinFile (tmp, server_coll_md5, 32);
|
|
|
|
|
|
|
|
/*Free coll_md5*/
|
|
|
|
if (coll_md5 != NULL) {
|
|
|
|
delete[] coll_md5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Free server_coll_md5*/
|
|
|
|
if (server_coll_md5 != NULL) {
|
|
|
|
delete[] server_coll_md5;
|
|
|
|
}
|
2010-07-20 18:38:29 +02:00
|
|
|
|
|
|
|
/*Go to next collection*/
|
2010-07-14 19:16:08 +02:00
|
|
|
conf->goNextCollection();
|
|
|
|
}
|
2010-07-21 12:03:20 +02:00
|
|
|
purgeDiskCollections ();
|
2010-07-14 19:16:08 +02:00
|
|
|
}
|
|
|
|
|
2011-07-14 10:58:18 +02:00
|
|
|
string
|
|
|
|
Pandora_Windows_Service::checkAgentName(string filename){
|
|
|
|
string name_agent = "";
|
|
|
|
string buffer;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2011-07-14 10:58:18 +02:00
|
|
|
ifstream file (filename.c_str ());
|
|
|
|
|
|
|
|
while (!file.eof ()) {
|
|
|
|
getline (file, buffer);
|
|
|
|
/* Ignore blank or commented lines */
|
|
|
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
|
|
|
/*Check agent_name*/
|
|
|
|
pos = buffer.find("agent_name");
|
|
|
|
if (pos != string::npos){
|
|
|
|
name_agent = buffer.substr(pos+11);
|
|
|
|
return name_agent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
return name_agent;
|
|
|
|
}
|
2011-11-03 20:13:57 +01:00
|
|
|
int
|
2011-07-11 17:49:29 +02:00
|
|
|
Pandora_Windows_Service::checkConfig (string file) {
|
2014-11-16 04:04:00 +01:00
|
|
|
int i, conf_size, pos;
|
2008-06-10 11:50:29 +02:00
|
|
|
char *conf_str = NULL, *remote_conf_str = NULL, *remote_conf_md5 = NULL;
|
2008-07-09 14:46:22 +02:00
|
|
|
char agent_md5[33], conf_md5[33], flag;
|
2011-07-11 17:49:29 +02:00
|
|
|
string agent_name, conf_tmp_file, md5_tmp_file, temp_dir, tmp;
|
2008-06-10 11:50:29 +02:00
|
|
|
|
|
|
|
tmp = conf->getValue ("remote_config");
|
|
|
|
if (tmp != "1") {
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Remote configuration disabled");
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get temporal directory */
|
|
|
|
temp_dir = conf->getValue ("temporal");
|
|
|
|
if (temp_dir[temp_dir.length () - 1] != '\\') {
|
|
|
|
temp_dir += "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get agent name */
|
2017-04-10 11:26:29 +02:00
|
|
|
agent_name = conf->getValue ("agent_name");
|
2014-11-16 04:04:00 +01:00
|
|
|
|
|
|
|
|
2010-06-30 17:40:25 +02:00
|
|
|
/* Error getting agent name */
|
2015-02-09 13:37:32 +01:00
|
|
|
if (agent_name.empty ()) {
|
2010-06-30 17:40:25 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error getting agent name");
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2010-06-30 17:40:25 +02:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2014-11-16 04:04:00 +01:00
|
|
|
Pandora_File::md5 (agent_name.c_str(), agent_name.size(), agent_md5);
|
2008-06-10 11:50:29 +02:00
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
/* Calculate md5 hashes */
|
2008-06-10 11:50:29 +02:00
|
|
|
try {
|
2011-07-11 17:49:29 +02:00
|
|
|
conf_size = Pandora_File::readBinFile (file, &conf_str);
|
2008-06-10 11:50:29 +02:00
|
|
|
Pandora_File::md5 (conf_str, conf_size, conf_md5);
|
|
|
|
} catch (...) {
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error calculating configuration md5");
|
|
|
|
if (conf_str != NULL) {
|
|
|
|
delete[] conf_str;
|
|
|
|
}
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Compose file names from the agent name hash */
|
2008-07-09 14:46:22 +02:00
|
|
|
conf_tmp_file = agent_md5;
|
|
|
|
conf_tmp_file += ".conf";
|
|
|
|
md5_tmp_file = agent_md5;
|
|
|
|
md5_tmp_file += ".md5";
|
2008-06-10 11:50:29 +02:00
|
|
|
|
|
|
|
/* 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);
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
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");
|
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
delete[] conf_str;
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
delete[] conf_str;
|
|
|
|
conf_str = NULL;
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
/* 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());
|
2008-07-09 14:46:22 +02:00
|
|
|
if (remote_conf_md5 != NULL) {
|
|
|
|
delete[] remote_conf_md5;
|
|
|
|
}
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2008-07-09 14:46:22 +02:00
|
|
|
}
|
2008-06-10 11:50:29 +02:00
|
|
|
Pandora_File::removeFile (tmp);
|
|
|
|
} catch (...) {
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error checking remote configuration md5", tmp.c_str());
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for configuration changes */
|
|
|
|
flag = 0;
|
|
|
|
for (i = 0; i < 32; i++) {
|
2008-07-09 14:46:22 +02:00
|
|
|
if (remote_conf_md5[i] != conf_md5[i]) {
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
delete[] remote_conf_md5;
|
|
|
|
|
|
|
|
/* Configuration has not changed */
|
|
|
|
if (flag == 0) {
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2010-06-30 17:40:25 +02:00
|
|
|
pandoraLog("Pandora_Windows_Service::checkConfig: Configuration for agent %s has changed", agent_name.c_str ());
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
/* 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 */
|
2011-07-11 17:49:29 +02:00
|
|
|
Pandora_File::writeBinFile (file, conf_str, conf_size);
|
2008-11-28 11:51:03 +01:00
|
|
|
} catch (...) {
|
2008-06-10 11:50:29 +02:00
|
|
|
pandoraDebug("Pandora_Windows_Service::checkConfig: Error retrieving configuration file from server");
|
2008-07-09 14:46:22 +02:00
|
|
|
if (conf_str != NULL) {
|
|
|
|
delete[] conf_str;
|
|
|
|
}
|
2011-11-03 20:13:57 +01:00
|
|
|
return 0;
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-06-10 11:50:29 +02:00
|
|
|
delete[] conf_str;
|
|
|
|
|
|
|
|
/* Reload configuration */
|
2011-11-03 20:13:57 +01:00
|
|
|
return 1;
|
2008-06-10 11:50:29 +02:00
|
|
|
}
|
2008-12-11 11:20:07 +01:00
|
|
|
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
int
|
2008-11-28 11:51:03 +01:00
|
|
|
Pandora_Windows_Service::sendXml (Pandora_Module_List *modules) {
|
2020-01-29 13:00:17 +01:00
|
|
|
int rc = 0, rc_sec = 0, xml_buffer;
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
string data_xml;
|
2008-11-28 11:51:03 +01:00
|
|
|
string xml_filename, random_integer;
|
|
|
|
string tmp_filename, tmp_filepath;
|
2020-01-29 13:00:17 +01:00
|
|
|
string secondary_filename, secondary_filepath;
|
2008-11-28 11:51:03 +01:00
|
|
|
string encoding;
|
2016-12-07 15:51:21 +01:00
|
|
|
string ehorus_conf, eh_key;
|
2008-12-11 11:20:07 +01:00
|
|
|
static HANDLE mutex = 0;
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
ULARGE_INTEGER free_bytes;
|
|
|
|
double min_free_bytes = 0;
|
|
|
|
Pandora_Agent_Conf *conf = NULL;
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
FILE *conf_fh = NULL;
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
|
|
|
|
conf = this->getConf ();
|
|
|
|
min_free_bytes = 1024 * atoi (conf->getValue ("temporal_min_size").c_str ());
|
2009-11-19 01:40:26 +01:00
|
|
|
xml_buffer = atoi (conf->getValue ("xml_buffer").c_str ());
|
2008-12-11 11:20:07 +01:00
|
|
|
|
|
|
|
if (mutex == 0) {
|
|
|
|
mutex = CreateMutex (NULL, FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for the mutex to be opened */
|
|
|
|
WaitForSingleObject (mutex, INFINITE);
|
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
data_xml = getXmlHeader ();
|
2008-11-28 11:51:03 +01:00
|
|
|
|
2016-12-07 15:51:21 +01:00
|
|
|
/* Get the eHorus key. */
|
|
|
|
ehorus_conf = conf->getValue ("ehorus_conf");
|
|
|
|
if (ehorus_conf != "") {
|
|
|
|
eh_key = getEHKey(ehorus_conf);
|
|
|
|
}
|
|
|
|
|
2012-11-20 13:29:00 +01:00
|
|
|
/* Write custom fields */
|
|
|
|
int c = 1;
|
2012-11-21 18:13:05 +01:00
|
|
|
|
|
|
|
char token_name_token[21]; // enough to hold all numbers up to 64-bits
|
|
|
|
char token_value_token[21]; // enough to hold all numbers up to 64-bits
|
|
|
|
sprintf(token_name_token, "custom_field%d_name", c);
|
|
|
|
sprintf(token_value_token, "custom_field%d_value", c);
|
|
|
|
string token_name = conf->getValue (token_name_token);
|
|
|
|
string token_value = conf->getValue (token_value_token);
|
2016-12-07 15:51:21 +01:00
|
|
|
|
|
|
|
if((token_name != "" && token_value != "") || eh_key != "") {
|
2012-11-20 13:29:00 +01:00
|
|
|
data_xml += "<custom_fields>\n";
|
|
|
|
while(token_name != "" && token_value != "") {
|
|
|
|
data_xml += " <field>\n";
|
|
|
|
data_xml += " <name><![CDATA["+ token_name +"]]></name>\n";
|
|
|
|
data_xml += " <value><![CDATA["+ token_value +"]]></value>\n";
|
|
|
|
data_xml += " </field>\n";
|
|
|
|
|
|
|
|
c++;
|
2012-11-21 18:13:05 +01:00
|
|
|
sprintf(token_name_token, "custom_field%d_name", c);
|
|
|
|
sprintf(token_value_token, "custom_field%d_value", c);
|
|
|
|
token_name = conf->getValue (token_name_token);
|
|
|
|
token_value = conf->getValue (token_value_token);
|
2012-11-20 13:29:00 +01:00
|
|
|
}
|
2016-12-07 15:51:21 +01:00
|
|
|
|
|
|
|
/* Add the eHorus key as a custom field. */
|
|
|
|
if (eh_key != "") {
|
|
|
|
data_xml += " <field>\n";
|
|
|
|
data_xml += " <name>eHorusID</name>\n";
|
|
|
|
data_xml += " <value><![CDATA["+ eh_key +"]]></value>\n";
|
|
|
|
data_xml += " </field>\n";
|
|
|
|
}
|
|
|
|
|
2012-11-20 13:29:00 +01:00
|
|
|
data_xml += "</custom_fields>\n";
|
|
|
|
}
|
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
/* Write module data */
|
2008-11-28 11:51:03 +01:00
|
|
|
if (modules != NULL) {
|
|
|
|
modules->goFirst ();
|
|
|
|
|
|
|
|
while (! modules->isLast ()) {
|
|
|
|
Pandora_Module *module;
|
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
module = modules->getCurrentValue ();
|
|
|
|
data_xml += module->getXml ();
|
2008-11-28 11:51:03 +01:00
|
|
|
modules->goNext ();
|
|
|
|
}
|
2008-12-11 11:20:07 +01:00
|
|
|
}
|
2008-11-28 11:51:03 +01:00
|
|
|
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
/* Close the XML header */
|
|
|
|
data_xml += "</agent_data>";
|
|
|
|
|
2008-11-28 11:51:03 +01:00
|
|
|
/* Generate temporal filename */
|
|
|
|
random_integer = inttostr (rand());
|
|
|
|
tmp_filename = conf->getValue ("agent_name");
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Copy the XML to temporal file */
|
|
|
|
pandoraDebug ("Copying XML on %s", tmp_filepath.c_str ());
|
2013-04-15 19:12:25 +02:00
|
|
|
conf_fh = fopen (tmp_filepath.c_str (), "wb");
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
if (conf_fh == NULL) {
|
2008-11-28 11:51:03 +01:00
|
|
|
pandoraLog ("Error when saving the XML in %s",
|
2008-12-11 11:20:07 +01:00
|
|
|
tmp_filepath.c_str ());
|
2008-12-01 14:40:19 +01:00
|
|
|
ReleaseMutex (mutex);
|
2009-01-20 Ramon Novoa <rnovoa@artica.es>
* win32/ftp/pandora_ftp_client.cc,
win32/ftp/pandora_ftp_client.h,
win32/windows/pandora_wmi.cc,
win32/pandora_windows_service.h,
win32/pandora.h,
win32/udp_server/udp_server.cc,
win32/misc/pandora_file.cc,
win32/misc/pandora_file.h,
win32/ssh/pandora_ssh_client.cc,
win32/ssh/pandora_ssh_client.h,
win32/pandora_windows_service.cc: Removed some exceptions that made
the agent crash when the watchdog thread was running.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 23:21:31 +01:00
|
|
|
return PANDORA_EXCEPTION;
|
2008-11-28 11:51:03 +01:00
|
|
|
}
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
fprintf (conf_fh, "%s", data_xml.c_str ());
|
|
|
|
fclose (conf_fh);
|
2008-11-28 11:51:03 +01:00
|
|
|
|
2015-10-06 16:09:46 +02:00
|
|
|
/* Allways reports to Data Server*/
|
|
|
|
rc = this->copyDataFile (tmp_filename);
|
2020-01-29 13:00:17 +01:00
|
|
|
if (rc != 0 && conf->getValue("secondary_mode") == "on_error") {
|
|
|
|
rc = this->copyToSecondary (tmp_filename, false);
|
|
|
|
} else if (conf->getValue("secondary_mode") == "always") {
|
|
|
|
rc_sec = this->copyToSecondary (tmp_filename, false);
|
|
|
|
|
|
|
|
/* Secondary buffer. */
|
|
|
|
if (rc_sec != 0 && xml_buffer == 1 && (GetDiskFreeSpaceEx (conf->getValue ("secondary_temporal").c_str (), &free_bytes, NULL, NULL) != 0 && free_bytes.QuadPart >= min_free_bytes)) {
|
|
|
|
secondary_filepath = conf->getValue ("secondary_temporal") + "\\" + tmp_filename;
|
|
|
|
CopyFile (tmp_filepath.c_str(), secondary_filepath.c_str(), false);
|
|
|
|
}
|
|
|
|
}
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
|
2020-01-29 13:00:17 +01:00
|
|
|
/* Primary buffer. Delete the file if successfully copied, buffer disabled or not enough space available. */
|
2015-10-06 16:09:46 +02:00
|
|
|
if (rc == 0 || xml_buffer == 0 || (GetDiskFreeSpaceEx (tmp_filepath.c_str (), &free_bytes, NULL, NULL) != 0 && free_bytes.QuadPart < min_free_bytes)) {
|
|
|
|
/* Rename the file if debug mode is enabled*/
|
|
|
|
if (getPandoraDebug ()) {
|
|
|
|
string tmp_filepath_sent = tmp_filepath;
|
|
|
|
tmp_filepath_sent.append("sent");
|
|
|
|
CopyFile (tmp_filepath.c_str(), tmp_filepath_sent.c_str(), false);
|
2009-11-19 01:40:26 +01:00
|
|
|
}
|
2015-10-06 16:09:46 +02:00
|
|
|
Pandora_File::removeFile (tmp_filepath);
|
|
|
|
}
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
|
2015-10-06 16:09:46 +02:00
|
|
|
/* Send any buffered data files */
|
|
|
|
if (xml_buffer == 1) {
|
2020-01-29 13:00:17 +01:00
|
|
|
this->sendBufferedXml (conf->getValue ("temporal"), &Pandora_Windows_Service::copyDataFile, false);
|
|
|
|
if (conf->getValue ("secondary_mode") == "always") {
|
|
|
|
this->sendBufferedXml (conf->getValue ("secondary_temporal"), &Pandora_Windows_Service::copyToSecondary, true);
|
|
|
|
} else {
|
|
|
|
this->sendBufferedXml (conf->getValue ("temporal"), &Pandora_Windows_Service::copyToSecondary, false);
|
|
|
|
}
|
2008-12-11 11:20:07 +01:00
|
|
|
}
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
|
2008-12-11 11:20:07 +01:00
|
|
|
ReleaseMutex (mutex);
|
|
|
|
}
|
2008-06-10 11:50:29 +02:00
|
|
|
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
void
|
2020-01-29 13:00:17 +01:00
|
|
|
Pandora_Windows_Service::sendBufferedXml (string path, copy_func_p copy_func, bool secondary_buffer) {
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
string base_path = path, file_path;
|
|
|
|
WIN32_FIND_DATA file_data;
|
|
|
|
HANDLE find;
|
|
|
|
|
2020-01-29 13:00:17 +01:00
|
|
|
/* Nothing to do. */
|
|
|
|
if (path == "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
if (base_path[base_path.length () - 1] != '\\') {
|
|
|
|
base_path += "\\";
|
|
|
|
}
|
|
|
|
file_path = base_path + "*.data";
|
|
|
|
|
|
|
|
/* Search for buffered data files */
|
|
|
|
find = FindFirstFile(file_path.c_str (), &file_data);
|
|
|
|
if (find == INVALID_HANDLE_VALUE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send data files as long as there are no errors */
|
2020-01-29 13:00:17 +01:00
|
|
|
if ((this->*copy_func) (file_data.cFileName, secondary_buffer) != 0) {
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
FindClose(find);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-06 16:09:46 +02:00
|
|
|
|
|
|
|
if (getPandoraDebug ()){
|
|
|
|
string file_data_path = base_path + file_data.cFileName;
|
|
|
|
string file_data_sent = file_data_path;
|
|
|
|
file_data_sent.append("sent");
|
|
|
|
CopyFile (file_data_path.c_str(), file_data_sent.c_str(), false);
|
|
|
|
}
|
|
|
|
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
Pandora_File::removeFile (base_path + file_data.cFileName);
|
|
|
|
|
|
|
|
while (FindNextFile(find, &file_data) != 0) {
|
2020-01-29 13:00:17 +01:00
|
|
|
if ((this->*copy_func) (file_data.cFileName, secondary_buffer) != 0) {
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
FindClose(find);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-06 16:09:46 +02:00
|
|
|
if (getPandoraDebug ()){
|
|
|
|
string file_data_path = base_path + file_data.cFileName;
|
|
|
|
string file_data_sent = file_data_path;
|
|
|
|
file_data_sent.append("sent");
|
|
|
|
CopyFile (file_data_path.c_str(), file_data_sent.c_str(), false);
|
|
|
|
}
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
Pandora_File::removeFile (base_path + file_data.cFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
FindClose(find);
|
|
|
|
}
|
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
void
|
2019-09-24 19:13:55 +02:00
|
|
|
Pandora_Windows_Service::pandora_run_broker (string config, long executions) {
|
2008-12-24 13:33:41 +01:00
|
|
|
Pandora_Agent_Conf *conf = NULL;
|
|
|
|
string server_addr;
|
2012-01-03 18:23:23 +01:00
|
|
|
unsigned char data_flag = 0;
|
|
|
|
unsigned char intensive_match;
|
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
pandoraDebug ("Run begin");
|
|
|
|
|
|
|
|
conf = this->getConf ();
|
|
|
|
|
|
|
|
/* Check for configuration changes */
|
|
|
|
if (getPandoraDebug () == false) {
|
2011-11-03 20:13:57 +01:00
|
|
|
if (this->checkConfig (config) == 1) {
|
|
|
|
pandora_init_broker (config);
|
|
|
|
}
|
2011-07-11 17:49:29 +02:00
|
|
|
this->checkCollections ();
|
|
|
|
}
|
|
|
|
|
|
|
|
server_addr = conf->getValue ("server_ip");
|
|
|
|
|
2018-09-24 13:13:12 +02:00
|
|
|
if (this->broker_modules != NULL && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
|
2017-05-18 11:55:44 +02:00
|
|
|
this->broker_modules->goFirst ();
|
2011-07-11 17:49:29 +02:00
|
|
|
|
2017-05-18 11:55:44 +02:00
|
|
|
while (! this->broker_modules->isLast ()) {
|
2011-07-11 17:49:29 +02:00
|
|
|
Pandora_Module *module;
|
|
|
|
|
2017-05-18 11:55:44 +02:00
|
|
|
module = this->broker_modules->getCurrentValue ();
|
2019-09-24 19:13:55 +02:00
|
|
|
|
|
|
|
/* Keep executions matching main agent */
|
|
|
|
module->setExecutions(executions);
|
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
/* Check preconditions */
|
|
|
|
if (module->evaluatePreconditions () == 0) {
|
|
|
|
pandoraDebug ("Preconditions not matched for module %s", module->getName ().c_str ());
|
|
|
|
module->setNoOutput ();
|
2017-05-18 11:55:44 +02:00
|
|
|
this->broker_modules->goNext ();
|
2012-01-03 18:23:23 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-11 17:49:29 +02:00
|
|
|
|
2018-02-21 15:57:46 +01:00
|
|
|
/* Check cron */
|
|
|
|
if (!module->checkCron (module->getInterval () * atoi (conf->getValue ("interval").c_str()))) {
|
2012-01-03 18:23:23 +01:00
|
|
|
pandoraDebug ("Cron not matched for module %s", module->getName ().c_str ());
|
2011-12-12 18:11:06 +01:00
|
|
|
module->setNoOutput ();
|
2017-05-18 11:55:44 +02:00
|
|
|
this->broker_modules->goNext ();
|
2011-12-12 18:11:06 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-09-26 19:25:53 +02:00
|
|
|
|
2017-05-18 11:55:44 +02:00
|
|
|
/* Check async */
|
|
|
|
if (module->getAsync()) {
|
|
|
|
pandoraDebug ("Forbidden async module %s in broker agents", module->getName ().c_str ());
|
|
|
|
module->setNoOutput ();
|
|
|
|
this->broker_modules->goNext ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
pandoraDebug ("Run %s", module->getName ().c_str ());
|
2012-01-03 18:23:23 +01:00
|
|
|
module->run ();
|
|
|
|
if (! module->hasOutput ()) {
|
|
|
|
module->setNoOutput ();
|
2017-05-18 11:55:44 +02:00
|
|
|
this->broker_modules->goNext ();
|
2012-01-03 18:23:23 +01:00
|
|
|
continue;
|
2011-07-11 17:49:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save module data to an environment variable */
|
|
|
|
if (!module->getSave().empty ()) {
|
|
|
|
module->exportDataOutput ();
|
|
|
|
}
|
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
/* Evaluate intensive conditions */
|
2019-11-22 13:59:22 +01:00
|
|
|
if (module->isIntensive()) {
|
|
|
|
intensive_match = module->evaluateIntensiveConditions ();
|
|
|
|
if (intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
|
|
|
|
module->setNoOutput ();
|
|
|
|
this->broker_modules->goNext ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (module->getTimestamp () + module->getInterval () * this->interval_sec <= this->run_time) {
|
|
|
|
module->setTimestamp (this->run_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
module->setIntensiveMatch (intensive_match);
|
2012-01-03 18:23:23 +01:00
|
|
|
}
|
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
/* Evaluate module conditions */
|
|
|
|
module->evaluateConditions ();
|
2012-01-03 18:23:23 +01:00
|
|
|
|
|
|
|
/* At least one module has data */
|
|
|
|
data_flag = 1;
|
2011-07-11 17:49:29 +02:00
|
|
|
|
2017-05-18 11:55:44 +02:00
|
|
|
this->broker_modules->goNext ();
|
2011-07-11 17:49:29 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
|
2018-09-24 13:13:12 +02:00
|
|
|
if ((data_flag == 1 || this->timestamp + this->interval_sec <= this->run_time) && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
|
2011-09-26 19:25:53 +02:00
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
// Send the XML
|
|
|
|
if (!server_addr.empty ()) {
|
2017-05-18 11:55:44 +02:00
|
|
|
this->sendXml (this->broker_modules);
|
2012-01-03 18:23:23 +01:00
|
|
|
}
|
2011-09-15 17:30:13 +02:00
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora_Windows_Service::pandora_run () {
|
2014-11-16 04:04:00 +01:00
|
|
|
pandora_run (0);
|
|
|
|
}
|
|
|
|
|
2013-04-11 17:39:28 +02:00
|
|
|
void
|
|
|
|
Pandora_Windows_Service::pandora_run (int forced_run) {
|
2011-07-11 17:49:29 +02:00
|
|
|
Pandora_Agent_Conf *conf = NULL;
|
2011-12-13 15:37:32 +01:00
|
|
|
string server_addr, conf_file, *all_conf;
|
2012-01-03 18:23:23 +01:00
|
|
|
int startup_delay = 0;
|
|
|
|
int i, num;
|
2013-04-04 10:06:38 +02:00
|
|
|
static bool startup = true;
|
2012-01-03 18:23:23 +01:00
|
|
|
unsigned char data_flag = 0;
|
|
|
|
unsigned char intensive_match;
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraDebug ("Run begin");
|
2011-09-26 19:25:53 +02:00
|
|
|
|
2009-05-25 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc, windows/pandora_wmi.h: Added functions for the
new modules. Removed old logevent functions.
* pandora_windows_service.h, pandora_windows_service.cc: Added support
for data file buffering and startup delay.
* modules/pandora_module_logevent.cc, modules/pandora_module_logevent.h:
Rewritten to retrieve event log data using the PDH interface instead
of WMI (was too slow).
* modules/pandora_module_tcpcheck.cc, modules/pandora_module_tcpcheck.h,
modules/pandora_module_regexp.cc, modules/pandora_module_regexp.h,
modules/pandora_module_perfcounter.cc,
modules/pandora_module_perfcounter.h,
modules/pandora_module_freedisk_percent.cc,
modules/pandora_module_freedisk_percent.h,
modules/pandora_module_freememory_percent.cc,
modules/pandora_module_freememory_percent.h: Added to repository.
New modules, see http://openideas.info/wiki/.
* modules/pandora_module.h, modules/pandora_module.cc,
modules/pandora_module_factory.cc, modules/pandora_module_list.cc:
Added support for the new modules.
* bin/pandora_agent.conf: Included configuration examples for the new
modules.
* PandoraAgent.dev: Updated to compile the new modules.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-25 19:50:27 +02:00
|
|
|
conf = this->getConf ();
|
2012-01-03 18:23:23 +01:00
|
|
|
|
2013-04-04 10:06:38 +02:00
|
|
|
/* process only once at startup */
|
|
|
|
if (startup) {
|
|
|
|
startup = false;
|
2010-11-05 15:07:42 +01:00
|
|
|
/* Sleep if a startup delay was specified */
|
|
|
|
startup_delay = atoi (conf->getValue ("startup_delay").c_str ()) * 1000;
|
2013-04-04 10:06:38 +02:00
|
|
|
if (startup_delay > 0) {
|
2012-01-03 18:23:23 +01:00
|
|
|
pandoraLog ("Delaying startup %d miliseconds", startup_delay);
|
|
|
|
Sleep (startup_delay);
|
|
|
|
}
|
2013-04-04 10:06:38 +02:00
|
|
|
setIterationBaseTicks(GetTickCount());
|
|
|
|
}
|
2010-11-05 15:07:42 +01:00
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
/* Set the run time */
|
|
|
|
this->run_time = time (NULL);
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
/* Check for configuration changes */
|
2009-11-26 18:15:06 +01:00
|
|
|
if (getPandoraDebug () == false) {
|
2011-07-11 17:49:29 +02:00
|
|
|
conf_file = Pandora::getPandoraInstallDir ();
|
|
|
|
conf_file += "pandora_agent.conf";
|
2011-07-14 10:58:18 +02:00
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
if (this->checkConfig (conf_file) == 1) {
|
|
|
|
this->pandora_init ();
|
|
|
|
}
|
2010-07-14 19:16:08 +02:00
|
|
|
this->checkCollections ();
|
2009-11-19 01:40:26 +01:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2008-12-24 13:33:41 +01:00
|
|
|
server_addr = conf->getValue ("server_ip");
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
execution_number++;
|
|
|
|
|
2018-09-24 13:13:12 +02:00
|
|
|
if (this->modules != NULL && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
|
2008-07-09 14:46:22 +02:00
|
|
|
this->modules->goFirst ();
|
|
|
|
|
|
|
|
while (! this->modules->isLast ()) {
|
|
|
|
Pandora_Module *module;
|
|
|
|
|
|
|
|
module = this->modules->getCurrentValue ();
|
2011-09-26 19:25:53 +02:00
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
/* Check preconditions */
|
|
|
|
if (module->evaluatePreconditions () == 0) {
|
|
|
|
pandoraDebug ("Preconditions not matched for module %s", module->getName ().c_str ());
|
2011-12-12 18:11:06 +01:00
|
|
|
module->setNoOutput ();
|
|
|
|
this->modules->goNext ();
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-21 13:06:47 +02:00
|
|
|
|
2018-02-21 15:57:46 +01:00
|
|
|
/* Check cron */
|
|
|
|
if (!module->checkCron (module->getInterval () * atoi (conf->getValue ("interval").c_str()))) {
|
2012-01-03 18:23:23 +01:00
|
|
|
pandoraDebug ("Cron not matched for module %s", module->getName ().c_str ());
|
|
|
|
module->setNoOutput ();
|
|
|
|
this->modules->goNext ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
pandoraDebug ("Run %s", module->getName ().c_str ());
|
2012-01-03 18:23:23 +01:00
|
|
|
module->run ();
|
|
|
|
if (! module->hasOutput ()) {
|
|
|
|
module->setNoOutput ();
|
|
|
|
this->modules->goNext ();
|
|
|
|
continue;
|
2010-07-12 18:31:07 +02:00
|
|
|
}
|
2010-06-30 17:40:25 +02:00
|
|
|
|
|
|
|
/* Save module data to an environment variable */
|
|
|
|
if (!module->getSave().empty ()) {
|
|
|
|
module->exportDataOutput ();
|
|
|
|
}
|
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
/* Evaluate intensive conditions */
|
2019-11-22 13:59:22 +01:00
|
|
|
if (module->isIntensive()) {
|
|
|
|
intensive_match = module->evaluateIntensiveConditions ();
|
|
|
|
if (forced_run != 1 && intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
|
|
|
|
module->setNoOutput ();
|
|
|
|
this->modules->goNext ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (module->getTimestamp () + module->getInterval () * this->interval_sec <= this->run_time) {
|
|
|
|
module->setTimestamp (this->run_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
module->setIntensiveMatch (intensive_match);
|
2012-01-03 18:23:23 +01:00
|
|
|
}
|
|
|
|
|
2010-07-02 16:25:53 +02:00
|
|
|
/* Evaluate module conditions */
|
|
|
|
module->evaluateConditions ();
|
2012-01-03 18:23:23 +01:00
|
|
|
|
|
|
|
/* At least one module has data */
|
|
|
|
data_flag = 1;
|
2010-07-02 16:25:53 +02:00
|
|
|
|
2008-07-09 14:46:22 +02: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
|
|
|
|
2018-09-24 13:13:12 +02:00
|
|
|
if ((forced_run == 1 || data_flag == 1 || this->timestamp + this->interval_sec <= this->run_time) && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
|
2012-01-03 18:23:23 +01:00
|
|
|
|
|
|
|
// Send the XML
|
2008-12-24 13:33:41 +01:00
|
|
|
if (!server_addr.empty ()) {
|
|
|
|
this->sendXml (this->modules);
|
|
|
|
}
|
2006-10-06 13:25:36 +02:00
|
|
|
}
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2006-12-01 17:29:27 +01:00
|
|
|
/* Get the interval value (in minutes) */
|
2012-01-03 18:23:23 +01:00
|
|
|
pandoraDebug ("Next execution on %d seconds", this->interval_sec);
|
2008-07-09 14:46:22 +02:00
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
/* Load and execute brokers */
|
2011-07-11 17:49:29 +02:00
|
|
|
num = count_broker_agents();
|
2011-12-13 15:37:32 +01:00
|
|
|
all_conf = new string [num];
|
2011-07-11 17:49:29 +02:00
|
|
|
check_broker_agents(all_conf);
|
|
|
|
for (i=0;i<num;i++){
|
|
|
|
pandora_init_broker(all_conf[i]);
|
2019-09-24 19:13:55 +02:00
|
|
|
pandora_run_broker(all_conf[i], execution_number);
|
2013-04-11 13:33:52 +02:00
|
|
|
}
|
2011-12-13 15:37:32 +01:00
|
|
|
delete []all_conf;
|
2013-04-11 13:33:52 +02:00
|
|
|
|
2011-11-03 20:13:57 +01:00
|
|
|
/* Reload the original configuration */
|
|
|
|
if (num != 0) {
|
2017-05-18 11:55:44 +02:00
|
|
|
pandora_init (false);
|
2011-07-11 17:49:29 +02:00
|
|
|
}
|
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
/* Reset time reference if necessary */
|
|
|
|
if (this->timestamp + this->interval_sec <= this->run_time) {
|
|
|
|
this->timestamp = this->run_time;
|
|
|
|
}
|
|
|
|
|
2008-07-09 14:46:22 +02:00
|
|
|
return;
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
2008-12-11 11:20:07 +01:00
|
|
|
|
|
|
|
Pandora_Agent_Conf *
|
|
|
|
Pandora_Windows_Service::getConf () {
|
|
|
|
return this->conf;
|
|
|
|
}
|
2012-01-03 18:23:23 +01:00
|
|
|
|
2016-12-07 15:51:21 +01:00
|
|
|
string
|
|
|
|
Pandora_Windows_Service::getEHKey (string ehorus_conf) {
|
|
|
|
string buffer, eh_key;
|
|
|
|
std::ifstream ifs(ehorus_conf.c_str());
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
if (! ifs.is_open ()) {
|
|
|
|
pandoraDebug ("Error opening eHorus configuration file %s", ehorus_conf.c_str ());
|
|
|
|
return eh_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for the eHorus key. */
|
|
|
|
while (ifs.good ()) {
|
|
|
|
getline (ifs, buffer);
|
|
|
|
|
|
|
|
/* Skip comments. */
|
|
|
|
if (buffer.empty() || buffer.at(0) == '#') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = buffer.find("eh_key");
|
|
|
|
if (pos != string::npos){
|
|
|
|
eh_key = buffer.substr(pos + 7); /* pos + strlen("eh_key ") */
|
|
|
|
eh_key = trim(eh_key);
|
|
|
|
return eh_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return eh_key;
|
|
|
|
}
|
|
|
|
|
2012-01-03 18:23:23 +01:00
|
|
|
long
|
|
|
|
Pandora_Windows_Service::getInterval () {
|
|
|
|
return this->interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
Pandora_Windows_Service::getIntensiveInterval () {
|
|
|
|
return this->intensive_interval;
|
|
|
|
}
|
|
|
|
|
2016-09-29 12:50:04 +02:00
|
|
|
string
|
|
|
|
Pandora_Windows_Service::generateAgentName () {
|
|
|
|
stringstream data;
|
|
|
|
char digest[SHA256_HEX_LENGTH + 1];
|
|
|
|
|
|
|
|
std::srand(std::time(0));
|
|
|
|
data << this->conf->getValue("agent_alias") <<
|
|
|
|
this->conf->getValue("server_ip") <<
|
|
|
|
time(NULL) <<
|
|
|
|
std::rand();
|
|
|
|
|
|
|
|
sha256(data.str().c_str(), digest);
|
|
|
|
return std::string(digest);
|
|
|
|
}
|