mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
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:
parent
596ae320d7
commit
d3d14d51c8
@ -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>
|
2011-12-09 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* windows/pandora_wmi.cc: Added a debug message.
|
* windows/pandora_wmi.cc: Added a debug message.
|
||||||
|
@ -406,6 +406,14 @@ Pandora_Module::setOutput (string output, SYSTEMTIME *system_time) {
|
|||||||
this->data_list->push_back (data);
|
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.
|
* Run the module and generates the output.
|
||||||
*
|
*
|
||||||
@ -956,8 +964,7 @@ Pandora_Module::evaluatePreconditions () {
|
|||||||
in <windef.h> */
|
in <windef.h> */
|
||||||
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
||||||
if (job == NULL) {
|
if (job == NULL) {
|
||||||
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
|
pandoraLog ("evaluatePreconditions: CreateJobObject failed. Err: %d", GetLastError ());
|
||||||
this->has_output = false;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -965,8 +972,7 @@ Pandora_Module::evaluatePreconditions () {
|
|||||||
out = GetStdHandle (STD_OUTPUT_HANDLE);
|
out = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||||
|
|
||||||
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
||||||
pandoraLog ("CreatePipe failed. Err: %d", GetLastError ());
|
pandoraLog ("evaluatePreconditions: CreatePipe failed. Err: %d", GetLastError ());
|
||||||
this->has_output = false;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -985,7 +991,7 @@ Pandora_Module::evaluatePreconditions () {
|
|||||||
|
|
||||||
/* Set up members of the PROCESS_INFORMATION structure. */
|
/* Set up members of the PROCESS_INFORMATION structure. */
|
||||||
ZeroMemory (&pi, sizeof (pi));
|
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
|
/* Set the working directory of the process. It's "utils" directory
|
||||||
to find the GNU W32 tools */
|
to find the GNU W32 tools */
|
||||||
@ -995,18 +1001,17 @@ Pandora_Module::evaluatePreconditions () {
|
|||||||
if (! CreateProcess (NULL, (CHAR *) precond->command.c_str (), NULL,
|
if (! CreateProcess (NULL, (CHAR *) precond->command.c_str (), NULL,
|
||||||
NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL,
|
NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL,
|
||||||
working_dir.c_str (), &si, &pi)) {
|
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->module_name.c_str (), GetLastError ());
|
||||||
this->has_output = false;
|
|
||||||
} else {
|
} else {
|
||||||
char buffer[BUFSIZE + 1];
|
char buffer[BUFSIZE + 1];
|
||||||
unsigned long read, avail;
|
unsigned long read, avail;
|
||||||
|
|
||||||
if (! AssignProcessToJobObject (job, pi.hProcess)) {
|
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 ());
|
GetLastError ());
|
||||||
}
|
}
|
||||||
ResumeThread (pi.hThread);
|
ResumeThread (pi.hThread);
|
||||||
|
|
||||||
/*string output;*/
|
/*string output;*/
|
||||||
int tickbase = GetTickCount();
|
int tickbase = GetTickCount();
|
||||||
@ -1025,7 +1030,7 @@ Pandora_Module::evaluatePreconditions () {
|
|||||||
} else if(this->getTimeout() < GetTickCount() - tickbase) {
|
} else if(this->getTimeout() < GetTickCount() - tickbase) {
|
||||||
/* STILL_ACTIVE */
|
/* STILL_ACTIVE */
|
||||||
TerminateProcess(pi.hThread, 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1034,22 +1039,22 @@ Pandora_Module::evaluatePreconditions () {
|
|||||||
|
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
if (! TerminateJobObject (job, 0)) {
|
if (! TerminateJobObject (job, 0)) {
|
||||||
pandoraLog ("TerminateJobObject failed. (error %d)",
|
pandoraLog ("evaluatePreconditions: TerminateJobObject failed. (error %d)",
|
||||||
GetLastError ());
|
GetLastError ());
|
||||||
}
|
}
|
||||||
if (retval != STILL_ACTIVE) {
|
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->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. */
|
/* Close job, process and thread handles. */
|
||||||
CloseHandle (job);
|
CloseHandle (job);
|
||||||
CloseHandle (pi.hProcess);
|
CloseHandle (pi.hProcess);
|
||||||
|
@ -246,7 +246,7 @@ namespace Pandora_Modules {
|
|||||||
virtual void setOutput (string output);
|
virtual void setOutput (string output);
|
||||||
virtual void setOutput (string output,
|
virtual void setOutput (string output,
|
||||||
SYSTEMTIME *system_time);
|
SYSTEMTIME *system_time);
|
||||||
|
virtual void setNoOutput ();
|
||||||
|
|
||||||
string getName () const;
|
string getName () const;
|
||||||
string getDescription () const;
|
string getDescription () const;
|
||||||
|
@ -49,8 +49,10 @@ Pandora_Module_Regexp::Pandora_Module_Regexp (string name, string source, string
|
|||||||
|
|
||||||
// Open the file and skip to the end
|
// Open the file and skip to the end
|
||||||
this->file.open (source.c_str ());
|
this->file.open (source.c_str ());
|
||||||
if (this->file.is_open () && no_seek_eof == 0) {
|
if (this->file.is_open ()) {
|
||||||
this->file.seekg (0, ios_base::end);
|
if (no_seek_eof == 0) {
|
||||||
|
this->file.seekg (0, ios_base::end);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pandoraLog ("Error opening file %s", source.c_str ());
|
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 () {
|
Pandora_Module_Regexp::~Pandora_Module_Regexp () {
|
||||||
regfree (&this->regexp);
|
regfree (&this->regexp);
|
||||||
this->file.close();
|
if (this->file.is_open ()) {
|
||||||
|
this->file.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -101,6 +105,11 @@ Pandora_Module_Regexp::run () {
|
|||||||
this->size = file_stat.st_size;
|
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
|
// Read new lines
|
||||||
count = 0;
|
count = 0;
|
||||||
while (! file.eof ()) {
|
while (! file.eof ()) {
|
||||||
@ -145,7 +154,9 @@ Pandora_Module_Regexp::run () {
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Module_Regexp::restart (unsigned char no_seek_eof) {
|
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 ());
|
this->file.open (this->source.c_str ());
|
||||||
if (this->file.is_open ()) {
|
if (this->file.is_open ()) {
|
||||||
if (no_seek_eof == 0) {
|
if (no_seek_eof == 0) {
|
||||||
|
@ -1425,8 +1425,11 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
|||||||
module = this->modules->getCurrentValue ();
|
module = this->modules->getCurrentValue ();
|
||||||
|
|
||||||
exe = module->evaluatePreconditions ();
|
exe = module->evaluatePreconditions ();
|
||||||
|
if (exe == 0) {
|
||||||
if (exe == 0) return;
|
module->setNoOutput ();
|
||||||
|
this->modules->goNext ();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
pandoraDebug ("Run %s", module->getName ().c_str ());
|
pandoraDebug ("Run %s", module->getName ().c_str ());
|
||||||
if (module->checkCron () == 1) {
|
if (module->checkCron () == 1) {
|
||||||
@ -1503,8 +1506,11 @@ Pandora_Windows_Service::pandora_run () {
|
|||||||
module = this->modules->getCurrentValue ();
|
module = this->modules->getCurrentValue ();
|
||||||
|
|
||||||
exe = module->evaluatePreconditions ();
|
exe = module->evaluatePreconditions ();
|
||||||
|
if (exe == 0) {
|
||||||
if (exe == 0) return;
|
module->setNoOutput ();
|
||||||
|
this->modules->goNext ();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
pandoraDebug ("Run %s", module->getName ().c_str ());
|
pandoraDebug ("Run %s", module->getName ().c_str ());
|
||||||
if (module->checkCron () == 1) {
|
if (module->checkCron () == 1) {
|
||||||
|
@ -701,9 +701,7 @@ Pandora_Wmi::getCdRomInfo (list<string> &rows) {
|
|||||||
if (wmi_svc == NULL) {
|
if (wmi_svc == NULL) {
|
||||||
pandoraLog("Error getting wmi_svc\n");
|
pandoraLog("Error getting wmi_svc\n");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraLog("wmi_svc is ok\n");
|
|
||||||
}
|
|
||||||
dhCheck (dhGetValue (L"%o", &cd_info, wmi_svc,
|
dhCheck (dhGetValue (L"%o", &cd_info, wmi_svc,
|
||||||
L".ExecQuery(%S)",
|
L".ExecQuery(%S)",
|
||||||
L"SELECT Name, Description, Drive FROM Win32_CDROMDrive "));
|
L"SELECT Name, Description, Drive FROM Win32_CDROMDrive "));
|
||||||
@ -761,9 +759,7 @@ Pandora_Wmi::getVideoInfo (list<string> &rows){
|
|||||||
if (wmi_svc == NULL) {
|
if (wmi_svc == NULL) {
|
||||||
pandoraLog("Error getting wmi_svc\n");
|
pandoraLog("Error getting wmi_svc\n");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraLog("wmi_svc is ok\n");
|
|
||||||
}
|
|
||||||
dhCheck (dhGetValue (L"%o", &video_info, wmi_svc,
|
dhCheck (dhGetValue (L"%o", &video_info, wmi_svc,
|
||||||
L".ExecQuery(%S)",
|
L".ExecQuery(%S)",
|
||||||
L"SELECT Caption, AdapterRAM, VideoProcessor FROM Win32_VideoController "));
|
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;
|
double ram_in_mb = atof(adapter_RAM) / 1048576;
|
||||||
ostringstream converter;
|
ostringstream converter;
|
||||||
converter << ram_in_mb;
|
converter << ram_in_mb;
|
||||||
pandoraDebug("f:%f s:%s\n",ram_in_mb,adapter_RAM);
|
|
||||||
ret += " " + converter.str() + " MBytes";
|
ret += " " + converter.str() + " MBytes";
|
||||||
}
|
}
|
||||||
ret += inventory_field_separator;
|
ret += inventory_field_separator;
|
||||||
@ -824,9 +819,7 @@ Pandora_Wmi::getHDsInfo (list<string> &rows) {
|
|||||||
if (wmi_svc == NULL) {
|
if (wmi_svc == NULL) {
|
||||||
pandoraLog("Error getting wmi_svc\n");
|
pandoraLog("Error getting wmi_svc\n");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraLog("wmi_svc is ok\n");
|
|
||||||
}
|
|
||||||
dhCheck (dhGetValue (L"%o", &hd_info, wmi_svc,
|
dhCheck (dhGetValue (L"%o", &hd_info, wmi_svc,
|
||||||
L".ExecQuery(%S)",
|
L".ExecQuery(%S)",
|
||||||
L"SELECT Model, Size, SystemName FROM Win32_DiskDrive "));
|
L"SELECT Model, Size, SystemName FROM Win32_DiskDrive "));
|
||||||
@ -846,12 +839,9 @@ Pandora_Wmi::getHDsInfo (list<string> &rows) {
|
|||||||
double fsize = atof(size) / 1073741824;
|
double fsize = atof(size) / 1073741824;
|
||||||
ostringstream converter;
|
ostringstream converter;
|
||||||
converter << fsize;
|
converter << fsize;
|
||||||
pandoraDebug("f:%f s:%s\n",fsize,size);
|
|
||||||
ret += converter.str() + " GBs";
|
ret += converter.str() + " GBs";
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraDebug("Size unknown\n");
|
|
||||||
}
|
|
||||||
ret += inventory_field_separator;
|
ret += inventory_field_separator;
|
||||||
dhFreeString (size);
|
dhFreeString (size);
|
||||||
dhGetValue (L"%s", &system_name, hd_info_item,
|
dhGetValue (L"%s", &system_name, hd_info_item,
|
||||||
@ -890,9 +880,7 @@ Pandora_Wmi::getCPUsInfo (list<string> &rows){
|
|||||||
if (wmi_svc == NULL) {
|
if (wmi_svc == NULL) {
|
||||||
pandoraLog("Error getting wmi_svc\n");
|
pandoraLog("Error getting wmi_svc\n");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraLog("wmi_svc is ok\n");
|
|
||||||
}
|
|
||||||
dhCheck (dhGetValue (L"%o", &cpu_info, wmi_svc,
|
dhCheck (dhGetValue (L"%o", &cpu_info, wmi_svc,
|
||||||
L".ExecQuery(%S)",
|
L".ExecQuery(%S)",
|
||||||
L"SELECT Name, MaxClockSpeed, Description FROM Win32_Processor "));
|
L"SELECT Name, MaxClockSpeed, Description FROM Win32_Processor "));
|
||||||
@ -946,7 +934,6 @@ getIPs(VARIANT *ip_array){
|
|||||||
ret += "";
|
ret += "";
|
||||||
}
|
}
|
||||||
int num_ips = V_ARRAY(ip_array)->rgsabound[0].cElements;
|
int num_ips = V_ARRAY(ip_array)->rgsabound[0].cElements;
|
||||||
pandoraDebug("Num IPs: %d\n",num_ips);
|
|
||||||
for (i = 0;i < num_ips;i++) {
|
for (i = 0;i < num_ips;i++) {
|
||||||
if ((i > 0) && (i < num_ips - 1 ))
|
if ((i > 0) && (i < num_ips - 1 ))
|
||||||
{
|
{
|
||||||
@ -954,7 +941,6 @@ getIPs(VARIANT *ip_array){
|
|||||||
}
|
}
|
||||||
if (V_VT(&pvArray[i]) == VT_BSTR) {
|
if (V_VT(&pvArray[i]) == VT_BSTR) {
|
||||||
LPSTR szStringA;
|
LPSTR szStringA;
|
||||||
pandoraDebug("String[%u] (original): %S\n", i, V_BSTR(&pvArray[i]));
|
|
||||||
ret += Pandora_Strutils::strUnicodeToAnsi( 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) {
|
if (wmi_svc == NULL) {
|
||||||
pandoraLog("Error getting wmi_svc\n");
|
pandoraLog("Error getting wmi_svc\n");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraLog("wmi_svc is ok\n");
|
|
||||||
}
|
|
||||||
dhCheck (dhGetValue (L"%o", &nic_info, wmi_svc,
|
dhCheck (dhGetValue (L"%o", &nic_info, wmi_svc,
|
||||||
L".ExecQuery(%S)",
|
L".ExecQuery(%S)",
|
||||||
L"SELECT Caption, MACAddress, IPAddress FROM Win32_NetworkAdapterConfiguration "));
|
L"SELECT Caption, MACAddress, IPAddress FROM Win32_NetworkAdapterConfiguration "));
|
||||||
@ -1040,9 +1024,7 @@ Pandora_Wmi::getPatchInfo (list<string> &rows) {
|
|||||||
if (wmi_svc == NULL) {
|
if (wmi_svc == NULL) {
|
||||||
pandoraLog("Error getting wmi_svc\n");
|
pandoraLog("Error getting wmi_svc\n");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraLog("wmi_svc is ok\n");
|
|
||||||
}
|
|
||||||
dhCheck (dhGetValue (L"%o", &patch_info, wmi_svc,
|
dhCheck (dhGetValue (L"%o", &patch_info, wmi_svc,
|
||||||
L".ExecQuery(%S)",
|
L".ExecQuery(%S)",
|
||||||
L"SELECT HotFixID, Description, FixComments FROM Win32_QuickFixEngineering "));
|
L"SELECT HotFixID, Description, FixComments FROM Win32_QuickFixEngineering "));
|
||||||
@ -1097,9 +1079,7 @@ Pandora_Wmi::getRAMInfo (list<string> &rows) {
|
|||||||
if (wmi_svc == NULL) {
|
if (wmi_svc == NULL) {
|
||||||
pandoraLog("Error getting wmi_svc\n");
|
pandoraLog("Error getting wmi_svc\n");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pandoraLog("wmi_svc is ok\n");
|
|
||||||
}
|
|
||||||
dhCheck (dhGetValue (L"%o", &ram_info, wmi_svc,
|
dhCheck (dhGetValue (L"%o", &ram_info, wmi_svc,
|
||||||
L".ExecQuery(%S)",
|
L".ExecQuery(%S)",
|
||||||
L"SELECT Tag, Capacity, Name FROM Win32_PhysicalMemory "));
|
L"SELECT Tag, Capacity, Name FROM Win32_PhysicalMemory "));
|
||||||
@ -1119,7 +1099,6 @@ Pandora_Wmi::getRAMInfo (list<string> &rows) {
|
|||||||
double fcapacity = atof(capacity) / 1048576;
|
double fcapacity = atof(capacity) / 1048576;
|
||||||
ostringstream converter;
|
ostringstream converter;
|
||||||
converter << fcapacity;
|
converter << fcapacity;
|
||||||
pandoraDebug("f:%f s:%s\n",fcapacity,capacity);
|
|
||||||
ret += converter.str() + " MBs";
|
ret += converter.str() + " MBs";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user