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>
* bin/PandoraAgent.exe: Updated to last commit.

View File

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

View File

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