2006-07-05 Esteban Sanchez <esteban@steve-o.org>

* pandora.[cc,h]: Program name and display name of the application.
        Added pandora_version variable and getPandoraAgentVersion()

        * pandora_windows_service.[cc,h]: Added checking of debug flag when
        reading the configuration file. Get the agent name from the machine if
        it was not defined in the configuration file. Date format on
        getXmlHeader() corrected. Style correction.

        * bin/README.txt: Fixed a error.

        * bin/PandoraAgent.tar.gz: Updated to the new commit.

        * windows/pandora_wmi.cc: The errors are now shown using pandoraLog().

        * modules/pandora_module.cc, modules/pandora_module_exec.cc,
        ChangeLog: Style correction.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@91 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2006-07-05 14:02:05 +00:00
parent 2666fe27b4
commit 38b25f1170
10 changed files with 124 additions and 58 deletions

View File

@ -1,54 +1,82 @@
2006-07-05 Esteban Sanchez <esteban@steve-o.org> 2006-07-05 Esteban Sanchez <esteban@steve-o.org>
* pandora.[cc,h]: Program name and display name of the application.
Added pandora_version variable and getPandoraAgentVersion()
* pandora_windows_service.[cc,h]: Added checking of debug flag when
reading the configuration file. Get the agent name from the machine if
it was not defined in the configuration file. Date format on
getXmlHeader() corrected. Style correction.
* bin/README.txt: Fixed a error.
* bin/PandoraAgent.tar.gz: Updated to the new commit.
* windows/pandora_wmi.cc: The errors are now shown using pandoraLog().
* modules/pandora_module.cc, modules/pandora_module_exec.cc,
ChangeLog: Style correction.
2006-07-05 Esteban Sanchez <esteban@steve-o.org>
* bin/README.txt: Added to repository. * bin/README.txt: Added to repository.
* pandora.h: Service name renamed. * pandora.h: Service name renamed.
2006-07-05 Esteban Sanchez <esteban@steve-o.org> 2006-07-05 Esteban Sanchez <esteban@steve-o.org>
* windows/pandora_wmi.cc: Removed unnecessary debug. Check the service state on isRunningService () * windows/pandora_wmi.cc: Removed unnecessary debug. Check the service
state on isRunningService ()
* pandora_agent_conf.cc, modules/pandora_module_factory.cc: Removed unnecessary debug. * pandora_agent_conf.cc, modules/pandora_module_factory.cc: Removed
unnecessary debug.
* bin/PandoraAgent.tar.gz: Added to repository. * bin/PandoraAgent.tar.gz: Added to repository.
* ssh/pandora_ssh_client.cc: Debug converted into log. * ssh/pandora_ssh_client.cc: Debug converted into log.
* pandora_windows_service.cc: Get the interval value (in minutes) and set it to the service. * pandora_windows_service.cc: Get the interval value (in minutes)
Check if the XML of the module is NULL before adding it to the file. Added log output on error. and set it to the service. Check if the XML of the module is NULL
Delete temporal file before finishing the run. before adding it to the file. Added log output on error. Delete
temporal file before finishing the run.
* pandora_windows_service.h: Macro modified. * pandora_windows_service.h: Macro modified.
* modules/pandora_module.h, modules/pandora_module.cc: Added new exception, raised when the interval * modules/pandora_module.h, modules/pandora_module.cc: Added new
is not fulfilled. Added code to the run funtion of the Pandora_Module class, to check the execution exception, raised when the interval is not fulfilled. Added code to
the run funtion of the Pandora_Module class, to check the execution
interval. interval.
* modules/pandora_module_proc.cc, modules/pandora_module_exec.cc, modules/pandora_module_service.cc: * modules/pandora_module_proc.cc, modules/pandora_module_exec.cc,
Call to the run() base class function before running the specific code. modules/pandora_module_service.cc: Call to the run() base class
function before running the specific code.
* modules/pandora_module_list.cc: Removed use of namespace and use a explicit specification. * modules/pandora_module_list.cc: Removed use of namespace and use a
explicit specification.
2006-07-04 Esteban Sanchez <esteban@steve-o.org> 2006-07-04 Esteban Sanchez <esteban@steve-o.org>
* windows/pandora_wmi.*, windows/pandora_windows_info.*, windows/wmi/disphelper.*, * windows/pandora_wmi.*, windows/pandora_windows_info.*,
misc/pandora_file.*, ssh/*, ssh/libssh2/*, modules/pandora_module_service.*, windows/wmi/disphelper.*, misc/pandora_file.*, ssh/*, ssh/libssh2/*,
modules/pandora_module_proc.*: Added to repository modules/pandora_module_service.*, modules/pandora_module_proc.*: Added
to repository.
* pandora_windows_service.cc, pandora_windows_service.h: getXMLHeader renamed to getXmlHeader * pandora_windows_service.cc, pandora_windows_service.h: getXMLHeader
and modified its behavior. Updated to the Pandora XML specification. Add SSH and XML generation renamed to getXmlHeader and modified its behavior. Updated to the
Pandora XML specification. Add SSH and XML generation
functionallity. functionallity.
* modules/pandora_module_exec.cc: Added the execution to a job to prevent zombies process. Update * modules/pandora_module_exec.cc: Added the execution to a job to
the execution command. prevent zombies process. Update the execution command.
* modules/pandora_module_factory.cc: Added Pandora_Module_Proc and Pandora_Module_Service. Added * modules/pandora_module_factory.cc: Added Pandora_Module_Proc and
the interval parameter. Pandora_Module_Service. Added the interval parameter.
* modules/pandora_module_list.cc: Added support to Pandora_Module_Proc and Pandora_Module_Service. * modules/pandora_module_list.cc: Added support to Pandora_Module_Proc
and Pandora_Module_Service.
* modules/pandora_module.h: Added new types of modules. Added execution times and module description * modules/pandora_module.h: Added new types of modules. Added
to the Pandora_Module class. Added support to Pandora_Module_Proc and Pandora_Module_Service. Added execution times and module description to the Pandora_Module class.
Added support to Pandora_Module_Proc and Pandora_Module_Service. Added
getXml, setInterval and setDescription functions. getXml, setInterval and setDescription functions.
* pandora.h: Commentary fixed. * pandora.h: Commentary fixed.

View File

@ -72,8 +72,8 @@ about the execution flow of the Agent.
server_path /opt/pandora/data_in/ server_path /opt/pandora/data_in/
# Local path to the temporal directory # Local path to the temporal directory
temporal "C:\temp files" temporal "C:\temp files"
# Interval between executions (in minutes) # Interval between executions (in seconds)
interval 5 interval 60
# Name of the agent # Name of the agent
agent_name antiriad agent_name antiriad
# End of pandora_agent.conf example # End of pandora_agent.conf example

View File

@ -138,10 +138,14 @@ Pandora_Module::getXml () {
try { try {
data = this->getOutput (); data = this->getOutput ();
} catch (Output_Error e) { } catch (Output_Error e) {
pandoraLog ("Output error"); pandoraLog ("Output error on module %s",
this->module_name.c_str ());
return NULL; return NULL;
} catch (Interval_Error e) { } catch (Interval_Error e) {
pandoraLog ("The returned value was not in the interval"); pandoraLog ("The returned value was not in the interval on module %s",
this->module_name.c_str ());
return NULL; return NULL;
} }

View File

@ -105,7 +105,8 @@ Pandora_Module_Exec::run () {
unsigned long read, avail; unsigned long read, avail;
if (! AssignProcessToJobObject (job, pi.hProcess)) { if (! AssignProcessToJobObject (job, pi.hProcess)) {
pandoraLog ("Assign bad %d", GetLastError ()); pandoraLog ("Could not assigned proccess to job (error %d)",
GetLastError ());
} }
ResumeThread (pi.hThread); ResumeThread (pi.hThread);
@ -116,7 +117,7 @@ Pandora_Module_Exec::run () {
GetExitCodeProcess (pi.hProcess, &retval); GetExitCodeProcess (pi.hProcess, &retval);
if (retval != 0) { if (retval != 0) {
if (! TerminateJobObject (job, 0)) { if (! TerminateJobObject (job, 0)) {
pandoraLog ("TerminateJobObject failed. Err: %d", pandoraLog ("TerminateJobObject failed. (error %d)",
GetLastError ()); GetLastError ());
} }

View File

@ -30,9 +30,12 @@ using namespace Pandora;
using namespace Pandora_Strutils; using namespace Pandora_Strutils;
#define PATH_SIZE _MAX_PATH+1 #define PATH_SIZE _MAX_PATH+1
#define PANDORA_VERSION ("1.2Beta")
string pandora_path; string pandora_path;
string pandora_dir; string pandora_dir;
bool pandora_debug; bool pandora_debug;
string pandora_version = PANDORA_VERSION;
void void
Key_Value::parseLine (string str) { Key_Value::parseLine (string str) {
@ -160,3 +163,7 @@ Pandora::setPandoraDebug (bool dbg) {
pandora_debug = dbg; pandora_debug = dbg;
} }
string
Pandora::getPandoraAgentVersion () {
return pandora_version;
}

View File

@ -42,8 +42,8 @@ namespace Pandora {
}; };
static const HKEY hkey = HKEY_LOCAL_MACHINE; static const HKEY hkey = HKEY_LOCAL_MACHINE;
const char * const name = "PandoraService"; const char * const name = "PandoraAgent";
const char * const display_name = "Pandora service"; const char * const display_name = "Pandora agent";
const char * const description = "The Pandora Agent service"; const char * const description = "The Pandora Agent service";
void setPandoraInstallDir (string dir); void setPandoraInstallDir (string dir);
@ -51,6 +51,7 @@ namespace Pandora {
void setPandoraInstallPath (string path); void setPandoraInstallPath (string path);
string getPandoraInstallPath (); string getPandoraInstallPath ();
void setPandoraDebug (bool dbg); void setPandoraDebug (bool dbg);
string getPandoraAgentVersion ();
void pandoraDebug (char *format, ...); void pandoraDebug (char *format, ...);
void pandoraLog (char *format, ...); void pandoraLog (char *format, ...);

View File

@ -36,6 +36,8 @@ using namespace Pandora;
using namespace Pandora_Modules; using namespace Pandora_Modules;
using namespace Pandora_Strutils; using namespace Pandora_Strutils;
string enabled_values[] = {"enabled", "1", "on", "yes", "si", "", "ok", ""};
Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name, Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name,
const char * svc_display_name, const char * svc_display_name,
const char * svc_description) const char * svc_description)
@ -52,18 +54,35 @@ Pandora_Windows_Service::~Pandora_Windows_Service () {
if (this->conf != NULL) { if (this->conf != NULL) {
delete this->conf; delete this->conf;
} }
if (this->modules != NULL) { if (this->modules != NULL) {
delete this->modules; delete this->modules;
} }
} }
bool
is_enabled (string value) {
int i = 0;
if (value == "") {
return false;
}
while (enabled_values[i] != "") {
if (enabled_values[i] == value) {
return true;
}
i++;
}
return false;
}
void void
Pandora_Windows_Service::pandora_init () { Pandora_Windows_Service::pandora_init () {
int interval_ms = 60000; int interval_ms = 60000;
string conf_file, interval; string conf_file, interval, debug;
setPandoraDebug (true); setPandoraDebug (true);
pandoraDebug ("Init begin");
conf_file = Pandora::getPandoraInstallDir (); conf_file = Pandora::getPandoraInstallDir ();
conf_file += "pandora_agent.conf"; conf_file += "pandora_agent.conf";
@ -73,6 +92,9 @@ Pandora_Windows_Service::pandora_init () {
/* Get the interval value (in minutes) and set it to the service */ /* Get the interval value (in minutes) and set it to the service */
interval = conf->getValue ("interval"); interval = conf->getValue ("interval");
debug = conf->getValue ("pandora_debug");
setPandoraDebug (is_enabled (debug));
if (interval != "") { if (interval != "") {
try { try {
interval_ms = strtoint (interval) interval_ms = strtoint (interval)
@ -96,16 +118,17 @@ Pandora_Windows_Service::getXmlHeader () {
agent = new TiXmlElement ("agent_data"); agent = new TiXmlElement ("agent_data");
/* TODO: Get the name of the machine if there is no agent_name*/
value = conf->getValue ("agent_name"); value = conf->getValue ("agent_name");
agent->SetAttribute ("agent_name", value); agent->SetAttribute ("agent_name", value);
if (value == "") {
value = Pandora_Windows_Info::getSystemName ();
}
/* TODO: Get the real version of the agent */ agent->SetAttribute ("version", getPandoraAgentVersion ());
agent->SetAttribute ("version", "1.2Beta");
GetSystemTime(&st); GetSystemTime(&st);
sprintf (timestamp, "%d/%d/%d %d:%d:%d", st.wDay, st.wMonth, sprintf (timestamp, "%d-%d-%d %d:%d:%d", st.wYear, st.wMonth, st.wDay,
st.wYear, st.wHour, st.wMinute, st.wSecond); st.wHour, st.wMinute, st.wSecond);
agent->SetAttribute ("timestamp", timestamp); agent->SetAttribute ("timestamp", timestamp);
value = conf->getValue ("interval"); value = conf->getValue ("interval");
@ -205,7 +228,8 @@ Pandora_Windows_Service::pandora_run () {
return; return;
} catch (Pandora_Exception e) { } catch (Pandora_Exception e) {
delete ssh_client; delete ssh_client;
pandoraLog ("Pandora Agent: Failed when copying to %s", remote_host.c_str ()); pandoraLog ("Pandora Agent: Failed when copying to %s",
remote_host.c_str ());
try { try {
Pandora_File::removeFile (tmp_filepath); Pandora_File::removeFile (tmp_filepath);
} catch (Pandora_File::Delete_Error e) { } catch (Pandora_File::Delete_Error e) {

View File

@ -36,6 +36,7 @@ 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;
TiXmlElement * getXmlHeader (); TiXmlElement * getXmlHeader ();

View File

@ -79,7 +79,7 @@ Pandora_Wmi::isProcessRunning (string process_name) {
} }
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
cerr << "Fatal error details:" << endl << errstr << endl; pandoraLog ("isProcessRunning error. %s", errstr.c_str ());
} }
return result; return result;
@ -126,7 +126,7 @@ Pandora_Wmi::isServiceRunning (string service_name) {
} }
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
cerr << "Fatal error details:" << endl << errstr << endl; pandoraLog ("isServiceRunning error. %s", errstr.c_str ());
} }
return 0; return 0;
@ -160,7 +160,7 @@ Pandora_Wmi::getOSName () {
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
cerr << "Fatal error details:" << endl << errstr << endl; pandoraLog ("getOSName error. %s", errstr.c_str ());
} }
return ret; return ret;
@ -194,7 +194,7 @@ Pandora_Wmi::getOSVersion () {
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
cerr << "Fatal error details:" << endl << errstr << endl; pandoraLog ("getOSVersion error. %s", errstr.c_str ());
} }
return ret; return ret;
@ -228,7 +228,7 @@ Pandora_Wmi::getOSBuild () {
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
cerr << "Fatal error details:" << endl << errstr << endl; pandoraLog ("getOSBuild error. %s", errstr.c_str ());
} }
return ret; return ret;
@ -262,7 +262,7 @@ Pandora_Wmi::getSystemName () {
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
cerr << "Fatal error details:" << endl << errstr << endl; pandoraLog ("getSystemName error. %s", errstr.c_str ());
} }
return ret; return ret;