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:
Esteban Sanchez 2006-12-01 16:29:27 +00:00
parent 6de3233c38
commit a5d9ed8fd1
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> 2006-12-01 Esteban Sanchez <estebans@artica.es>
* pandora_windows_service.cpp: Fixed a bug when copying the data file * 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" temporal "C:\windows\temp"
interval 10 interval 10
agent_name localhost agent_name localhost
pandora_debug 1 #debug 1
# Module Definition # Module Definition
# ================= # =================

View File

@ -156,17 +156,94 @@ Pandora_Windows_Service::getXmlHeader () {
return agent; 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 void
Pandora_Windows_Service::pandora_run () { Pandora_Windows_Service::pandora_run () {
TiXmlDocument *doc; TiXmlDocument *doc;
TiXmlElement *local_xml, *agent; TiXmlElement *local_xml, *agent;
string xml_filename, remote_host; string xml_filename, random_integer;
string remote_filepath, random_integer; string tmp_filename, tmp_filepath, interval;
string tmp_filename, tmp_filepath, interval;
string pubkey_file, privkey_file;
bool saved; bool saved;
pandoraDebug ("Run begin"); pandoraLog ("Run begin");
agent = getXmlHeader (); agent = getXmlHeader ();
@ -214,85 +291,25 @@ Pandora_Windows_Service::pandora_run () {
saved = doc->SaveFile(); saved = doc->SaveFile();
delete doc; delete doc;
delete agent; delete agent;
if (!saved) { if (!saved) {
pandoraLog ("Error when saving the XML in %s", pandoraLog ("Error when saving the XML in %s",
tmp_filepath.c_str ()); tmp_filepath.c_str ());
return; 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) { if (getPandoraDebug () == false) {
try { this->copyDataFile (tmp_filename);
try {
Pandora_File::removeFile (tmp_filepath); Pandora_File::removeFile (tmp_filepath);
} catch (Pandora_File::Delete_Error e) { } 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; return;
} }

View File

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