2006-07-05 Esteban Sanchez <esteban@steve-o.org>
* 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. * bin/PandoraAgent.tar.gz: Added to repository. * 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. Check if the XML of the module is NULL before adding it to the file. Added log output on error. Delete temporal file before finishing the run. * pandora_windows_service.h: Macro modified. * modules/pandora_module.h, modules/pandora_module.cc: Added new exception, raised when the interval is not fulfilled. Added code to the run funtion of the Pandora_Module class, to check the execution interval. * modules/pandora_module_proc.cc, modules/pandora_module_exec.cc, 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. * Changelog: Renamed to ChangeLog. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@85 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
f78dd46a7b
commit
e6c81809f4
|
@ -1,3 +1,30 @@
|
|||
2006-07-05 Esteban Sanchez <esteban@steve-o.org>
|
||||
|
||||
* 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.
|
||||
|
||||
* bin/PandoraAgent.tar.gz: Added to repository.
|
||||
|
||||
* 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.
|
||||
Check if the XML of the module is NULL before adding it to the file. Added log output on error.
|
||||
Delete temporal file before finishing the run.
|
||||
|
||||
* pandora_windows_service.h: Macro modified.
|
||||
|
||||
* modules/pandora_module.h, modules/pandora_module.cc: Added new exception, raised when the interval
|
||||
is not fulfilled. Added code to the run funtion of the Pandora_Module class, to check the execution
|
||||
interval.
|
||||
|
||||
* modules/pandora_module_proc.cc, modules/pandora_module_exec.cc, 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.
|
||||
|
||||
* Changelog: Renamed to ChangeLog.
|
||||
|
||||
2006-07-04 Esteban Sanchez <esteban@steve-o.org>
|
||||
|
||||
* windows/pandora_wmi.*, windows/pandora_windows_info.*, windows/wmi/disphelper.*,
|
||||
|
|
Binary file not shown.
|
@ -60,7 +60,7 @@ main (int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
service->run ();
|
||||
|
||||
|
||||
delete service;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,22 @@ Pandora_Module::getOutput () const {
|
|||
|
||||
void
|
||||
Pandora_Module::run () {
|
||||
|
||||
|
||||
this->output = "";
|
||||
|
||||
/* Check the interval */
|
||||
if (this->executions % this->module_interval != 0) {
|
||||
pandoraDebug ("%s: Interval is not fulfilled",
|
||||
this->module_name.c_str ());
|
||||
this->executions++;
|
||||
has_output = false;
|
||||
throw Interval_Not_Fulfilled ();
|
||||
}
|
||||
|
||||
/* Increment the executions after check. This is done to execute the
|
||||
first time */
|
||||
this->executions++;
|
||||
has_output = true;
|
||||
}
|
||||
|
||||
TiXmlElement *
|
||||
|
@ -116,6 +131,10 @@ Pandora_Module::getXml () {
|
|||
|
||||
pandoraDebug ("%s getXML begin", module_name.c_str ());
|
||||
|
||||
if (!this->has_output) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
try {
|
||||
data = this->getOutput ();
|
||||
} catch (Output_Error e) {
|
||||
|
@ -187,6 +206,5 @@ Pandora_Module::setInterval (int interval) {
|
|||
|
||||
void
|
||||
Pandora_Module::setDescription (string description) {
|
||||
pandoraDebug ("Set description to: %s", description.c_str ());
|
||||
this->module_description = description;
|
||||
}
|
||||
|
|
|
@ -52,8 +52,9 @@ namespace Pandora_Modules {
|
|||
const string module_proc_str = "module_proc";
|
||||
const string module_service_str = "module_service";
|
||||
|
||||
class Output_Error : public Pandora::Pandora_Exception { };
|
||||
class Interval_Error : public Pandora::Pandora_Exception { };
|
||||
class Output_Error : public Pandora::Pandora_Exception { };
|
||||
class Interval_Error : public Pandora::Pandora_Exception { };
|
||||
class Interval_Not_Fulfilled : public Pandora::Pandora_Exception { };
|
||||
|
||||
class Pandora_Module {
|
||||
protected:
|
||||
|
@ -68,6 +69,7 @@ namespace Pandora_Modules {
|
|||
string output;
|
||||
int max, min;
|
||||
bool has_limits;
|
||||
bool has_output;
|
||||
public:
|
||||
Pandora_Module (string name);
|
||||
virtual ~Pandora_Module ();
|
||||
|
|
|
@ -45,19 +45,12 @@ Pandora_Module_Exec::run () {
|
|||
HANDLE out, new_stdout, out_read, job;
|
||||
string working_dir;
|
||||
|
||||
this->output = "";
|
||||
|
||||
/* Check the interval */
|
||||
if (this->executions % this->module_interval != 0) {
|
||||
pandoraDebug ("Interval is not fulfilled");
|
||||
this->executions++;
|
||||
try {
|
||||
Pandora_Module::run ();
|
||||
} catch (Interval_Not_Fulfilled e) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Increment the executions after check. This is done to execute the
|
||||
first time */
|
||||
this->executions++;
|
||||
|
||||
/* Set the bInheritHandle flag so pipe handles are inherited. */
|
||||
attributes.nLength = sizeof (SECURITY_ATTRIBUTES);
|
||||
attributes.bInheritHandle = TRUE;
|
||||
|
@ -133,7 +126,6 @@ Pandora_Module_Exec::run () {
|
|||
|
||||
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
||||
/* Read from the stdout */
|
||||
|
||||
if (read != 0) {
|
||||
do {
|
||||
ReadFile (out_read, buffer, BUFSIZE, &read,
|
||||
|
|
|
@ -125,7 +125,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
} else {
|
||||
return NULL;
|
||||
}
|
||||
pandoraDebug ("Description %s", module_description.c_str ());
|
||||
|
||||
if (module_description != "") {
|
||||
module->setDescription (module_description);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
using namespace std;
|
||||
using namespace Pandora;
|
||||
using namespace Pandora_Module_Factory;
|
||||
|
||||
Pandora_Module_List::Pandora_Module_List (string filename) {
|
||||
ifstream file (filename.c_str ());
|
||||
|
@ -90,7 +89,7 @@ Pandora_Module_List::parseModuleDefinition (string definition) {
|
|||
Pandora_Module_Proc *module_proc;
|
||||
Pandora_Module_Service *module_service;
|
||||
|
||||
module = getModuleFromDefinition (definition);
|
||||
module = Pandora_Module_Factory::getModuleFromDefinition (definition);
|
||||
|
||||
if (module != NULL) {
|
||||
switch (module->getModuleKind ()) {
|
||||
|
|
|
@ -30,7 +30,8 @@ using namespace Pandora_Strutils;
|
|||
|
||||
Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
|
||||
this->process_name = process_name;
|
||||
transform (process_name.begin (), process_name.end (),
|
||||
this->process_name.begin (), (int (*) (int)) tolower);
|
||||
|
||||
|
@ -40,10 +41,15 @@ Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
|
|||
|
||||
void
|
||||
Pandora_Module_Proc::run () {
|
||||
pandoraDebug ("MODULE_PROC RUN");
|
||||
|
||||
int res;
|
||||
|
||||
int res = Pandora_Wmi::isProcessRunning (this->process_name);
|
||||
pandoraDebug ("res: %d", res);
|
||||
output = "1";
|
||||
try {
|
||||
Pandora_Module::run ();
|
||||
} catch (Interval_Not_Fulfilled e) {
|
||||
return;
|
||||
}
|
||||
|
||||
res = Pandora_Wmi::isProcessRunning (this->process_name);
|
||||
|
||||
output = inttostr (res);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,9 @@ using namespace Pandora_Strutils;
|
|||
|
||||
Pandora_Module_Service::Pandora_Module_Service (string name, string service_name)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
|
||||
this->service_name = service_name;
|
||||
|
||||
transform (service_name.begin (), service_name.end (),
|
||||
this->service_name.begin (), (int (*) (int)) tolower);
|
||||
|
||||
|
@ -41,7 +43,14 @@ Pandora_Module_Service::Pandora_Module_Service (string name, string service_name
|
|||
|
||||
void
|
||||
Pandora_Module_Service::run () {
|
||||
pandoraDebug ("MODULE_SERVICE RUN");
|
||||
int res;
|
||||
|
||||
try {
|
||||
Pandora_Module::run ();
|
||||
} catch (Interval_Not_Fulfilled e) {
|
||||
return;
|
||||
}
|
||||
|
||||
output = inttostr (Pandora_Wmi::isServiceRunning (this->service_name));
|
||||
res = Pandora_Wmi::isServiceRunning (this->service_name);
|
||||
output = inttostr (res);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ Pandora_Agent_Conf::Pandora_Agent_Conf (string filename) {
|
|||
this->key_values = new list<Key_Value> ();
|
||||
|
||||
if (!file.is_open ()) {
|
||||
pandoraDebug ("No hay conf");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ Pandora_Windows_Service::~Pandora_Windows_Service () {
|
|||
|
||||
void
|
||||
Pandora_Windows_Service::pandora_init () {
|
||||
int interval_ms = 10000;
|
||||
string conf_file;
|
||||
int interval_ms = 60000;
|
||||
string conf_file, interval;
|
||||
|
||||
setPandoraDebug (true);
|
||||
pandoraDebug ("Init begin");
|
||||
|
@ -69,7 +69,18 @@ Pandora_Windows_Service::pandora_init () {
|
|||
conf_file += "pandora_agent.conf";
|
||||
this->conf = new Pandora_Agent_Conf (conf_file);
|
||||
this->modules = new Pandora_Module_List (conf_file);
|
||||
|
||||
/* Get the interval value (in minutes) and set it to the service */
|
||||
interval = conf->getValue ("interval");
|
||||
|
||||
if (interval != "") {
|
||||
try {
|
||||
interval_ms = strtoint (interval)
|
||||
* 1000 /* miliseconds */;
|
||||
} catch (Invalid_Conversion e) {
|
||||
}
|
||||
}
|
||||
|
||||
srand ((unsigned) time (0));
|
||||
this->setSleepTime (interval_ms);
|
||||
|
||||
|
@ -138,9 +149,11 @@ Pandora_Windows_Service::pandora_run () {
|
|||
module->run ();
|
||||
|
||||
local_xml = module->getXml ();
|
||||
agent->InsertEndChild (*local_xml);
|
||||
|
||||
delete local_xml;
|
||||
if (local_xml != NULL) {
|
||||
agent->InsertEndChild (*local_xml);
|
||||
|
||||
delete local_xml;
|
||||
}
|
||||
this->modules->goNext ();
|
||||
}
|
||||
}
|
||||
|
@ -178,8 +191,7 @@ Pandora_Windows_Service::pandora_run () {
|
|||
pubkey_file += "key\\id_dsa.pub";
|
||||
privkey_file = Pandora::getPandoraInstallDir ();
|
||||
privkey_file += "key\\id_dsa";
|
||||
pandoraDebug ("Pub: %s Priv: %s", pubkey_file.c_str (),
|
||||
privkey_file.c_str ());
|
||||
|
||||
ssh_client->connectWithPublicKey (remote_host.c_str (), 22, "babel",
|
||||
pubkey_file, privkey_file, "");
|
||||
} catch (SSH::Authentication_Failed e) {
|
||||
|
@ -213,6 +225,8 @@ Pandora_Windows_Service::pandora_run () {
|
|||
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;
|
||||
try {
|
||||
|
@ -223,7 +237,13 @@ Pandora_Windows_Service::pandora_run () {
|
|||
}
|
||||
|
||||
ssh_client->disconnect();
|
||||
delete ssh_client;
|
||||
|
||||
try {
|
||||
Pandora_File::removeFile (tmp_filepath);
|
||||
} catch (Pandora_File::Delete_Error e) {
|
||||
}
|
||||
|
||||
pandoraDebug ("Execution number %d", execution_number);
|
||||
|
||||
return;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#ifndef __PANDORA_WINDOWS_SERVICE_H__
|
||||
#define __PANDORA_WINDOWS_SERVICE_CLIENT_H__
|
||||
#define __PANDORA_WINDOWS_SERVICE_H__
|
||||
|
||||
#include <list>
|
||||
#include "windows_service.h"
|
||||
|
@ -38,7 +38,7 @@ private:
|
|||
long execution_number;
|
||||
|
||||
TiXmlElement * getXmlHeader ();
|
||||
|
||||
|
||||
void pandora_run ();
|
||||
void pandora_init ();
|
||||
public:
|
||||
|
|
|
@ -227,7 +227,7 @@ Pandora_Ssh_Client::scpFileFilename (const string remote_filename, const string
|
|||
Scp_Failed *e;
|
||||
errmsg = (char *) malloc (sizeof (char) * 1000);
|
||||
libssh2_session_last_error (session, &errmsg, &errmsg_len, 1);
|
||||
pandoraDebug ("Error %d on SCP %s", sent, errmsg);
|
||||
pandoraLog ("Error %d on SCP %s", sent, errmsg);
|
||||
e = new Scp_Failed (errmsg);
|
||||
|
||||
libssh2_channel_close (scp_channel);
|
||||
|
|
|
@ -73,8 +73,7 @@ Pandora_Wmi::isProcessRunning (string process_name) {
|
|||
name = fix.name;
|
||||
transform (name.begin (), name.end (), name.begin (),
|
||||
(int (*) (int)) tolower);
|
||||
pandoraDebug ("name %s", name.c_str ());
|
||||
|
||||
|
||||
if (process_name == name) {
|
||||
result++;
|
||||
}
|
||||
|
@ -91,7 +90,6 @@ Pandora_Wmi::isServiceRunning (string service_name) {
|
|||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
string name, state;
|
||||
int result = 0;
|
||||
|
||||
dhToggleExceptions (TRUE);
|
||||
|
||||
|
@ -114,20 +112,24 @@ Pandora_Wmi::isServiceRunning (string service_name) {
|
|||
name = fix.name;
|
||||
transform (name.begin (), name.end (), name.begin (),
|
||||
(int (*) (int)) tolower);
|
||||
pandoraDebug ("name %s", name.c_str ());
|
||||
|
||||
if (service_name == name) {
|
||||
dhGetValue (L"%s", &fix.state, quickfix,
|
||||
L".State");
|
||||
state = fix.state;
|
||||
pandoraDebug ("state %s", state.c_str ());
|
||||
|
||||
if (state == "Running") {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
cerr << "Fatal error details:" << endl << errstr << endl;
|
||||
}
|
||||
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
|
||||
string
|
||||
|
|
Loading…
Reference in New Issue