2011-12-12 Ramon Novoa <rnovoa@artica.es>

* windows/pandora_wmi.cc: Removed some debugging messages.

	* modules/pandora_module.h,
	  modules/pandora_module.cc,
	  pandora_windows_service.cc: Fixed pre-conditions (were not working
	  properly).

	* modules/pandora_module_regexp.cc: Improved file status detection and
	  small fixes.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5247 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2011-12-12 17:11:06 +00:00
parent 596ae320d7
commit d3d14d51c8
6 changed files with 71 additions and 58 deletions

View File

@ -1,3 +1,15 @@
2011-12-12 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc: Removed some debugging messages.
* modules/pandora_module.h,
modules/pandora_module.cc,
pandora_windows_service.cc: Fixed pre-conditions (were not working
properly).
* modules/pandora_module_regexp.cc: Improved file status detection and
small fixes.
2011-12-09 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc: Added a debug message.

View File

@ -406,6 +406,14 @@ Pandora_Module::setOutput (string output, SYSTEMTIME *system_time) {
this->data_list->push_back (data);
}
/**
* Set no output for the module.
*/
void
Pandora_Module::setNoOutput () {
this->has_output = false;
}
/**
* Run the module and generates the output.
*
@ -956,8 +964,7 @@ Pandora_Module::evaluatePreconditions () {
in <windef.h> */
job = CreateJobObject (&attributes, this->module_name.c_str ());
if (job == NULL) {
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
this->has_output = false;
pandoraLog ("evaluatePreconditions: CreateJobObject failed. Err: %d", GetLastError ());
return 0;
}
@ -965,8 +972,7 @@ Pandora_Module::evaluatePreconditions () {
out = GetStdHandle (STD_OUTPUT_HANDLE);
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
pandoraLog ("CreatePipe failed. Err: %d", GetLastError ());
this->has_output = false;
pandoraLog ("evaluatePreconditions: CreatePipe failed. Err: %d", GetLastError ());
return 0;
}
@ -985,7 +991,7 @@ Pandora_Module::evaluatePreconditions () {
/* Set up members of the PROCESS_INFORMATION structure. */
ZeroMemory (&pi, sizeof (pi));
pandoraDebug ("Executing: %s", precond->command.c_str ());
pandoraDebug ("Executing pre-condition: %s", precond->command.c_str ());
/* Set the working directory of the process. It's "utils" directory
to find the GNU W32 tools */
@ -995,18 +1001,17 @@ Pandora_Module::evaluatePreconditions () {
if (! CreateProcess (NULL, (CHAR *) precond->command.c_str (), NULL,
NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL,
working_dir.c_str (), &si, &pi)) {
pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d",
pandoraLog ("evaluatePreconditions: %s CreateProcess failed. Err: %d",
this->module_name.c_str (), GetLastError ());
this->has_output = false;
} else {
char buffer[BUFSIZE + 1];
unsigned long read, avail;
if (! AssignProcessToJobObject (job, pi.hProcess)) {
pandoraLog ("Could not assigned proccess to job (error %d)",
pandoraLog ("evaluatePreconditions: could not assign proccess to job (error %d)",
GetLastError ());
}
ResumeThread (pi.hThread);
ResumeThread (pi.hThread);
/*string output;*/
int tickbase = GetTickCount();
@ -1025,7 +1030,7 @@ Pandora_Module::evaluatePreconditions () {
} else if(this->getTimeout() < GetTickCount() - tickbase) {
/* STILL_ACTIVE */
TerminateProcess(pi.hThread, STILL_ACTIVE);
pandoraLog ("Pandora_Module_Exec: %s timed out (retcode: %d)", this->module_name.c_str (), STILL_ACTIVE);
pandoraLog ("evaluatePreconditions: %s timed out (retcode: %d)", this->module_name.c_str (), STILL_ACTIVE);
break;
}
}
@ -1034,21 +1039,21 @@ Pandora_Module::evaluatePreconditions () {
if (retval != 0) {
if (! TerminateJobObject (job, 0)) {
pandoraLog ("TerminateJobObject failed. (error %d)",
pandoraLog ("evaluatePreconditions: TerminateJobObject failed. (error %d)",
GetLastError ());
}
if (retval != STILL_ACTIVE) {
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
pandoraLog ("evaluatePreconditions: %s did not executed well (retcode: %d)",
this->module_name.c_str (), retval);
}
this->has_output = false;
/* Close job, process and thread handles. */
CloseHandle (job);
CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);
CloseHandle (new_stdout);
CloseHandle (out_read);
return 0;
}
if (!output.empty()) {
this->setOutput (output);
} else {
this->setOutput ("");
}
/* Close job, process and thread handles. */
CloseHandle (job);
@ -1058,7 +1063,7 @@ Pandora_Module::evaluatePreconditions () {
CloseHandle (new_stdout);
CloseHandle (out_read);
if ((precond->operation == ">" && float_output > precond->value_1) ||
(precond->operation == "<" && float_output < precond->value_1) ||
(precond->operation == "=" && float_output == precond->value_1) ||

View File

@ -246,7 +246,7 @@ namespace Pandora_Modules {
virtual void setOutput (string output);
virtual void setOutput (string output,
SYSTEMTIME *system_time);
virtual void setNoOutput ();
string getName () const;
string getDescription () const;

View File

@ -49,8 +49,10 @@ Pandora_Module_Regexp::Pandora_Module_Regexp (string name, string source, string
// Open the file and skip to the end
this->file.open (source.c_str ());
if (this->file.is_open () && no_seek_eof == 0) {
this->file.seekg (0, ios_base::end);
if (this->file.is_open ()) {
if (no_seek_eof == 0) {
this->file.seekg (0, ios_base::end);
}
} else {
pandoraLog ("Error opening file %s", source.c_str ());
}
@ -66,7 +68,9 @@ Pandora_Module_Regexp::Pandora_Module_Regexp (string name, string source, string
*/
Pandora_Module_Regexp::~Pandora_Module_Regexp () {
regfree (&this->regexp);
this->file.close();
if (this->file.is_open ()) {
this->file.close();
}
}
void
@ -101,6 +105,11 @@ Pandora_Module_Regexp::run () {
this->size = file_stat.st_size;
}
// Check again, in case an open or a restart failed
if (! file.is_open () || ! file.good ()) {
return;
}
// Read new lines
count = 0;
while (! file.eof ()) {
@ -145,7 +154,9 @@ Pandora_Module_Regexp::run () {
*/
void
Pandora_Module_Regexp::restart (unsigned char no_seek_eof) {
this->file.close ();
if (this->file.is_open ()) {
this->file.close ();
}
this->file.open (this->source.c_str ());
if (this->file.is_open ()) {
if (no_seek_eof == 0) {

View File

@ -1425,8 +1425,11 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
module = this->modules->getCurrentValue ();
exe = module->evaluatePreconditions ();
if (exe == 0) return;
if (exe == 0) {
module->setNoOutput ();
this->modules->goNext ();
continue;
}
pandoraDebug ("Run %s", module->getName ().c_str ());
if (module->checkCron () == 1) {
@ -1503,8 +1506,11 @@ Pandora_Windows_Service::pandora_run () {
module = this->modules->getCurrentValue ();
exe = module->evaluatePreconditions ();
if (exe == 0) return;
if (exe == 0) {
module->setNoOutput ();
this->modules->goNext ();
continue;
}
pandoraDebug ("Run %s", module->getName ().c_str ());
if (module->checkCron () == 1) {

View File

@ -701,9 +701,7 @@ Pandora_Wmi::getCdRomInfo (list<string> &rows) {
if (wmi_svc == NULL) {
pandoraLog("Error getting wmi_svc\n");
}
else {
pandoraLog("wmi_svc is ok\n");
}
dhCheck (dhGetValue (L"%o", &cd_info, wmi_svc,
L".ExecQuery(%S)",
L"SELECT Name, Description, Drive FROM Win32_CDROMDrive "));
@ -761,9 +759,7 @@ Pandora_Wmi::getVideoInfo (list<string> &rows){
if (wmi_svc == NULL) {
pandoraLog("Error getting wmi_svc\n");
}
else {
pandoraLog("wmi_svc is ok\n");
}
dhCheck (dhGetValue (L"%o", &video_info, wmi_svc,
L".ExecQuery(%S)",
L"SELECT Caption, AdapterRAM, VideoProcessor FROM Win32_VideoController "));
@ -783,7 +779,6 @@ Pandora_Wmi::getVideoInfo (list<string> &rows){
double ram_in_mb = atof(adapter_RAM) / 1048576;
ostringstream converter;
converter << ram_in_mb;
pandoraDebug("f:%f s:%s\n",ram_in_mb,adapter_RAM);
ret += " " + converter.str() + " MBytes";
}
ret += inventory_field_separator;
@ -824,9 +819,7 @@ Pandora_Wmi::getHDsInfo (list<string> &rows) {
if (wmi_svc == NULL) {
pandoraLog("Error getting wmi_svc\n");
}
else {
pandoraLog("wmi_svc is ok\n");
}
dhCheck (dhGetValue (L"%o", &hd_info, wmi_svc,
L".ExecQuery(%S)",
L"SELECT Model, Size, SystemName FROM Win32_DiskDrive "));
@ -846,12 +839,9 @@ Pandora_Wmi::getHDsInfo (list<string> &rows) {
double fsize = atof(size) / 1073741824;
ostringstream converter;
converter << fsize;
pandoraDebug("f:%f s:%s\n",fsize,size);
ret += converter.str() + " GBs";
}
else {
pandoraDebug("Size unknown\n");
}
ret += inventory_field_separator;
dhFreeString (size);
dhGetValue (L"%s", &system_name, hd_info_item,
@ -890,9 +880,7 @@ Pandora_Wmi::getCPUsInfo (list<string> &rows){
if (wmi_svc == NULL) {
pandoraLog("Error getting wmi_svc\n");
}
else {
pandoraLog("wmi_svc is ok\n");
}
dhCheck (dhGetValue (L"%o", &cpu_info, wmi_svc,
L".ExecQuery(%S)",
L"SELECT Name, MaxClockSpeed, Description FROM Win32_Processor "));
@ -946,7 +934,6 @@ getIPs(VARIANT *ip_array){
ret += "";
}
int num_ips = V_ARRAY(ip_array)->rgsabound[0].cElements;
pandoraDebug("Num IPs: %d\n",num_ips);
for (i = 0;i < num_ips;i++) {
if ((i > 0) && (i < num_ips - 1 ))
{
@ -954,7 +941,6 @@ getIPs(VARIANT *ip_array){
}
if (V_VT(&pvArray[i]) == VT_BSTR) {
LPSTR szStringA;
pandoraDebug("String[%u] (original): %S\n", i, V_BSTR(&pvArray[i]));
ret += Pandora_Strutils::strUnicodeToAnsi( V_BSTR(&pvArray[i]));
}
}
@ -982,9 +968,7 @@ Pandora_Wmi::getNICsInfo (list<string> &rows) {
if (wmi_svc == NULL) {
pandoraLog("Error getting wmi_svc\n");
}
else {
pandoraLog("wmi_svc is ok\n");
}
dhCheck (dhGetValue (L"%o", &nic_info, wmi_svc,
L".ExecQuery(%S)",
L"SELECT Caption, MACAddress, IPAddress FROM Win32_NetworkAdapterConfiguration "));
@ -1040,9 +1024,7 @@ Pandora_Wmi::getPatchInfo (list<string> &rows) {
if (wmi_svc == NULL) {
pandoraLog("Error getting wmi_svc\n");
}
else {
pandoraLog("wmi_svc is ok\n");
}
dhCheck (dhGetValue (L"%o", &patch_info, wmi_svc,
L".ExecQuery(%S)",
L"SELECT HotFixID, Description, FixComments FROM Win32_QuickFixEngineering "));
@ -1097,9 +1079,7 @@ Pandora_Wmi::getRAMInfo (list<string> &rows) {
if (wmi_svc == NULL) {
pandoraLog("Error getting wmi_svc\n");
}
else {
pandoraLog("wmi_svc is ok\n");
}
dhCheck (dhGetValue (L"%o", &ram_info, wmi_svc,
L".ExecQuery(%S)",
L"SELECT Tag, Capacity, Name FROM Win32_PhysicalMemory "));
@ -1119,7 +1099,6 @@ Pandora_Wmi::getRAMInfo (list<string> &rows) {
double fcapacity = atof(capacity) / 1048576;
ostringstream converter;
converter << fcapacity;
pandoraDebug("f:%f s:%s\n",fcapacity,capacity);
ret += converter.str() + " MBs";
}
else {