2006-12-01 Esteban Sanchez <estebans@artica.es>

* pandora_windows_service.[cc,h]: Added copyDataFile() method to
        class, it will copy the data file to the remote host. Now the data
        file is not copied when the debug flag is active. Changed some debug
        output to log output and changed one log message.

        * bin/pandora_agent.conf: Updated debug flag option to new format and
        commented.

        * bin/PandoraAgent.exe: Updated to new commit.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@293 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2006-12-01 16:29:27 +00:00
parent ce89120378
commit a80ea03248
5 changed files with 105 additions and 75 deletions

View File

@ -1,3 +1,15 @@
2006-12-01 Esteban Sanchez <estebans@artica.es>
* pandora_windows_service.[cc,h]: Added copyDataFile() method to
class, it will copy the data file to the remote host. Now the data
file is not copied when the debug flag is active. Changed some debug
output to log output and changed one log message.
* bin/pandora_agent.conf: Updated debug flag option to new format and
commented.
* bin/PandoraAgent.exe: Updated to new commit.
2006-12-01 Esteban Sanchez <estebans@artica.es>
* pandora_windows_service.cpp: Fixed a bug when copying the data file

View File

@ -18,7 +18,7 @@ server_path /var/spool/pandora/data_in
temporal "C:\windows\temp"
interval 10
agent_name localhost
pandora_debug 1
#debug 1
# Module Definition
# =================

View File

@ -156,17 +156,94 @@ Pandora_Windows_Service::getXmlHeader () {
return agent;
}
void
Pandora_Windows_Service::copyDataFile (string filename)
{
string remote_host, remote_filepath;
string tmp_dir, filepath;
string pubkey_file, privkey_file;
tmp_dir = conf->getValue ("temporal");
if (tmp_dir[tmp_dir.length () - 1] != '\\') {
tmp_dir += "\\";
}
filepath = tmp_dir + filename;
remote_host = conf->getValue ("server_ip");
ssh_client = new SSH::Pandora_Ssh_Client ();
pandoraDebug ("Connecting with %s", remote_host.c_str ());
try {
pubkey_file = Pandora::getPandoraInstallDir ();
pubkey_file += "key\\id_dsa.pub";
privkey_file = Pandora::getPandoraInstallDir ();
privkey_file += "key\\id_dsa";
ssh_client->connectWithPublicKey (remote_host.c_str (), 22, "pandora",
pubkey_file, privkey_file, "");
} catch (SSH::Authentication_Failed e) {
delete ssh_client;
pandoraLog ("Pandora Agent: Authentication Failed when connecting to %s",
remote_host.c_str ());
if (getPandoraDebug () == false) {
try {
Pandora_File::removeFile (filepath);
} catch (Pandora_File::Delete_Error e) {
}
}
return;
} catch (Pandora_Exception e) {
delete ssh_client;
pandoraLog ("Pandora Agent: Failed when copying to %s",
remote_host.c_str ());
if (getPandoraDebug () == false) {
try {
Pandora_File::removeFile (filepath);
} catch (Pandora_File::Delete_Error e) {
}
}
return;
}
remote_filepath = conf->getValue ("server_path");
if (remote_filepath[remote_filepath.length () - 1] != '/') {
remote_filepath += "/";
}
pandoraDebug ("Remote copying XML %s on server %s at %s%s",
filepath.c_str (), remote_host.c_str (),
remote_filepath.c_str (), filename.c_str ());
try {
ssh_client->scpFileFilename (remote_filepath + filename,
filepath);
} catch (Pandora_Exception e) {
pandoraLog ("Unable to copy at %s%s", remote_filepath.c_str (),
filename.c_str ());
ssh_client->disconnect();
delete ssh_client;
if (getPandoraDebug () == false) {
try {
Pandora_File::removeFile (filepath);
} catch (Pandora_File::Delete_Error e) {
}
}
return;
}
ssh_client->disconnect();
delete ssh_client;
}
void
Pandora_Windows_Service::pandora_run () {
TiXmlDocument *doc;
TiXmlElement *local_xml, *agent;
string xml_filename, remote_host;
string remote_filepath, random_integer;
string tmp_filename, tmp_filepath, interval;
string pubkey_file, privkey_file;
string xml_filename, random_integer;
string tmp_filename, tmp_filepath, interval;
bool saved;
pandoraDebug ("Run begin");
pandoraLog ("Run begin");
agent = getXmlHeader ();
@ -214,85 +291,25 @@ Pandora_Windows_Service::pandora_run () {
saved = doc->SaveFile();
delete doc;
delete agent;
if (!saved) {
pandoraLog ("Error when saving the XML in %s",
tmp_filepath.c_str ());
return;
}
remote_host = conf->getValue ("server_ip");
ssh_client = new SSH::Pandora_Ssh_Client ();
pandoraDebug ("Connecting with %s", remote_host.c_str ());
try {
pubkey_file = Pandora::getPandoraInstallDir ();
pubkey_file += "key\\id_dsa.pub";
privkey_file = Pandora::getPandoraInstallDir ();
privkey_file += "key\\id_dsa";
ssh_client->connectWithPublicKey (remote_host.c_str (), 22, "pandora",
pubkey_file, privkey_file, "");
} catch (SSH::Authentication_Failed e) {
delete ssh_client;
pandoraLog ("Pandora Agent: Authentication Failed when connecting to %s",
remote_host.c_str ());
if (getPandoraDebug () == false) {
try {
Pandora_File::removeFile (tmp_filepath);
} catch (Pandora_File::Delete_Error e) {
}
}
return;
} catch (Pandora_Exception e) {
delete ssh_client;
pandoraLog ("Pandora Agent: Failed when copying to %s",
remote_host.c_str ());
if (getPandoraDebug () == false) {
try {
Pandora_File::removeFile (tmp_filepath);
} catch (Pandora_File::Delete_Error e) {
}
}
return;
}
remote_filepath = conf->getValue ("server_path");
if (remote_filepath[remote_filepath.length () - 1] != '/') {
remote_filepath += "/";
}
pandoraDebug ("Remote copying XML %s on server %s at %s%s",
tmp_filepath.c_str (), remote_host.c_str (),
remote_filepath.c_str (), tmp_filename.c_str ());
try {
ssh_client->scpFileFilename (remote_filepath + tmp_filename,
tmp_filepath);
} catch (Pandora_Exception e) {
pandoraLog ("Unable to copy at %s%s", remote_filepath.c_str (),
tmp_filename.c_str ());
ssh_client->disconnect();
delete ssh_client;
if (getPandoraDebug () == false) {
try {
Pandora_File::removeFile (tmp_filepath);
} catch (Pandora_File::Delete_Error e) {
}
}
return;
}
ssh_client->disconnect();
delete ssh_client;
if (getPandoraDebug () == false) {
try {
this->copyDataFile (tmp_filename);
try {
Pandora_File::removeFile (tmp_filepath);
} catch (Pandora_File::Delete_Error e) {
}
}
pandoraDebug ("Execution number %d", execution_number);
/* Get the interval value (in minutes) */
interval = conf->getValue ("interval");
pandoraLog ("Next execution on %s mins", interval.c_str ());
return;
}

View File

@ -43,6 +43,7 @@ namespace Pandora {
string agent_name;
TiXmlElement *getXmlHeader ();
void copyDataFile (string filename);
void pandora_run ();
void pandora_init ();