2009-02-09 Esteban Sanchez <estebans@artica.es>

* main.cc: Added a new parameter --process to run the agent as a
        single process instead of a service.

        * pandora_windows_service.h: Interval property is now public so it can
        be readed if it's running as a single process.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1432 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2009-02-09 10:26:07 +00:00
parent ef32f64adf
commit 19ebb674a5
3 changed files with 116 additions and 95 deletions

View File

@ -1,3 +1,11 @@
2009-02-09 Esteban Sanchez <estebans@artica.es>
* main.cc: Added a new parameter --process to run the agent as a
single process instead of a service.
* pandora_windows_service.h: Interval property is now public so it can
be readed if it's running as a single process.
2008-12-03 Esteban Sanchez <estebans@artica.es> 2008-12-03 Esteban Sanchez <estebans@artica.es>
* bin/PandoraAgent.exe: Updated to last commit. * bin/PandoraAgent.exe: Updated to last commit.

View File

@ -29,6 +29,7 @@
#define SSH_TEST_CMDLINE_PARAM "--test-ssh" #define SSH_TEST_CMDLINE_PARAM "--test-ssh"
#define FTP_TEST_CMDLINE_PARAM "--test-ftp" #define FTP_TEST_CMDLINE_PARAM "--test-ftp"
#define HELP_CMDLINE_PARAM "--help" #define HELP_CMDLINE_PARAM "--help"
#define PROCESS_CMDLINE_PARAM "--process"
int int
main (int argc, char *argv[]) { main (int argc, char *argv[]) {
@ -36,6 +37,7 @@ main (int argc, char *argv[]) {
char buffer[PATH_SIZE]; char buffer[PATH_SIZE];
string aux; string aux;
unsigned int pos; unsigned int pos;
bool process = false;
service = Pandora_Windows_Service::getInstance (); service = Pandora_Windows_Service::getInstance ();
service->setValues (Pandora::name, Pandora::display_name, service->setValues (Pandora::name, Pandora::display_name,
@ -91,8 +93,7 @@ main (int argc, char *argv[]) {
} }
return 0; return 0;
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
/* Help parameter */ /* Help parameter */
cout << "Pandora agent for Windows. "; cout << "Pandora agent for Windows. ";
cout << "Version " << getPandoraAgentVersion () << endl; cout << "Version " << getPandoraAgentVersion () << endl;
@ -108,6 +109,8 @@ main (int argc, char *argv[]) {
cout << ": Test the FTP Pandora Agent configuration." << endl; cout << ": Test the FTP Pandora Agent configuration." << endl;
return 0; return 0;
} else if (_stricmp(argv[i], PROCESS_CMDLINE_PARAM) == 0) {
process = true;
} else { } else {
/* No parameter recognized */ /* No parameter recognized */
cout << "Pandora agent for Windows. "; cout << "Pandora agent for Windows. ";
@ -123,9 +126,18 @@ main (int argc, char *argv[]) {
return 1; return 1;
} }
} }
service->run (); if (process) {
cout << "Pandora agent is now running" << endl;
service->pandora_init ();
while (1) {
service->pandora_run ();
Sleep (service->interval / 1000);
}
} else {
service->run ();
}
delete service; delete service;
return 0; return 0;
} }

View File

@ -1,90 +1,91 @@
/* Pandora agent service for Win32. /* Pandora agent service for Win32.
Copyright (C) 2006 Artica ST. Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez. Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option) the Free Software Foundation; either version 2, or (at your option)
any later version. any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#ifndef __PANDORA_WINDOWS_SERVICE_H__ #ifndef __PANDORA_WINDOWS_SERVICE_H__
#define __PANDORA_WINDOWS_SERVICE_H__ #define __PANDORA_WINDOWS_SERVICE_H__
#include <list> #include <list>
#include "windows_service.h" #include "windows_service.h"
#include "tinyxml/tinyxml.h" #include "tinyxml/tinyxml.h"
#include "pandora_agent_conf.h" #include "pandora_agent_conf.h"
#include "modules/pandora_module_list.h" #include "modules/pandora_module_list.h"
#include "ssh/pandora_ssh_client.h" #include "ssh/pandora_ssh_client.h"
using namespace std; using namespace std;
using namespace Pandora_Modules; using namespace Pandora_Modules;
namespace Pandora { namespace Pandora {
/** /**
* Class to implement the Pandora Windows service. * Class to implement the Pandora Windows service.
*/ */
class Pandora_Windows_Service : public Windows_Service { class Pandora_Windows_Service : public Windows_Service {
private: private:
Pandora_Agent_Conf *conf; Pandora_Agent_Conf *conf;
Pandora_Module_List *modules; Pandora_Module_List *modules;
long execution_number; long execution_number;
string agent_name; string agent_name;
long interval; long elapsed_transfer_time;
long elapsed_transfer_time; long transfer_interval;
long transfer_interval; bool started;
bool started;
TiXmlElement *getXmlHeader ();
TiXmlElement *getXmlHeader (); int copyDataFile (string filename);
int copyDataFile (string filename); int copyTentacleDataFile (string host,
int copyTentacleDataFile (string host, string filename,
string filename, string port,
string port, string ssl,
string ssl, string pass,
string pass, string opts);
string opts); int copyScpDataFile (string host,
int copyScpDataFile (string host, string remote_path,
string remote_path, string filename);
string filename); int copyFtpDataFile (string host,
int copyFtpDataFile (string host, string remote_path,
string remote_path, string filename,
string filename, string password);
string password); int copyLocalDataFile (string remote_path,
int copyLocalDataFile (string remote_path, string filename);
string filename); void recvDataFile (string filename);
void recvDataFile (string filename); void recvTentacleDataFile (string host,
void recvTentacleDataFile (string host, string filename);
string filename); void checkConfig ();
void checkConfig ();
Pandora_Windows_Service ();
Pandora_Windows_Service (); public:
public: void pandora_run ();
void pandora_run (); void pandora_init ();
void pandora_init ();
public: long interval;
static Pandora_Windows_Service *getInstance (); public:
static Pandora_Windows_Service *getInstance ();
~Pandora_Windows_Service ();
~Pandora_Windows_Service ();
void setValues (const char *svc_name,
const char *svc_display_name, void setValues (const char *svc_name,
const char *svc_description); const char *svc_display_name,
const char *svc_description);
void start ();
int sendXml (Pandora_Module_List *modules); void start ();
Pandora_Agent_Conf *getConf (); int sendXml (Pandora_Module_List *modules);
}; Pandora_Agent_Conf *getConf ();
} };
}
#endif
#endif