diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index 8593820048..fbb4d69c0e 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,15 @@ +2006-12-01 Esteban Sanchez + + * 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 * pandora_windows_service.cpp: Fixed a bug when copying the data file diff --git a/pandora_agents/win32/bin/PandoraAgent.exe b/pandora_agents/win32/bin/PandoraAgent.exe index ddc1d8c18b..edce4ac624 100755 Binary files a/pandora_agents/win32/bin/PandoraAgent.exe and b/pandora_agents/win32/bin/PandoraAgent.exe differ diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index 0d11e28499..a9e0f51d6a 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -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 # ================= diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index f3b8b8e555..6b084628fd 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -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; } diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index 83f7e18d9b..aa3db3475f 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -43,6 +43,7 @@ namespace Pandora { string agent_name; TiXmlElement *getXmlHeader (); + void copyDataFile (string filename); void pandora_run (); void pandora_init ();