mirror of
				https://github.com/pandorafms/pandorafms.git
				synced 2025-10-31 11:34:51 +01:00 
			
		
		
		
	2008-06-11 Esteban Sanchez <estebans@artica.es>
* pandora_windows_service.cc, modules/pandora_module_list.cc: Deleted
        debug output.
        * modules/pandora_module_exec.cc: Reindented the code. Add blank
        output to the module if there were nothing to read (like when the
        executions return nothing).
        * bin/PandoraAgent.exe: Updated to commit.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@854 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
			
			
This commit is contained in:
		
							parent
							
								
									48ed82ba8c
								
							
						
					
					
						commit
						6d05eec1c6
					
				| @ -1,3 +1,14 @@ | |||||||
|  | 2008-06-11  Esteban Sanchez  <estebans@artica.es> | ||||||
|  | 
 | ||||||
|  | 	* pandora_windows_service.cc, modules/pandora_module_list.cc: Deleted | ||||||
|  | 	debug output. | ||||||
|  | 
 | ||||||
|  | 	* modules/pandora_module_exec.cc: Reindented the code. Add blank | ||||||
|  | 	output to the module if there were nothing to read (like when the | ||||||
|  | 	executions return nothing). | ||||||
|  | 
 | ||||||
|  | 	* bin/PandoraAgent.exe: Updated to commit. | ||||||
|  | 
 | ||||||
| 2008-06-11  Esteban Sanchez <estebans@artica.es> | 2008-06-11  Esteban Sanchez <estebans@artica.es> | ||||||
| 
 | 
 | ||||||
| 	* bin/libodbc++.dll: Added to repository. Needed to run agent since | 	* bin/libodbc++.dll: Added to repository. Needed to run agent since | ||||||
|  | |||||||
										
											Binary file not shown.
										
									
								
							| @ -294,7 +294,6 @@ Pandora_Module::getXml () { | |||||||
| 	TiXmlText    *text; | 	TiXmlText    *text; | ||||||
| 	string        item_clean, data_clean, desc_clean; | 	string        item_clean, data_clean, desc_clean; | ||||||
| 	Pandora_Data *data; | 	Pandora_Data *data; | ||||||
| 
 |  | ||||||
| 	 | 	 | ||||||
| 	pandoraDebug ("%s getXML begin", module_name.c_str ()); | 	pandoraDebug ("%s getXML begin", module_name.c_str ()); | ||||||
| 	 | 	 | ||||||
| @ -317,7 +316,7 @@ Pandora_Module::getXml () { | |||||||
|         root->InsertEndChild (*element); |         root->InsertEndChild (*element); | ||||||
|         delete element; |         delete element; | ||||||
|         delete text; |         delete text; | ||||||
| 
 | 	 | ||||||
| 	if (this->data_list && this->data_list->size () > 1) { | 	if (this->data_list && this->data_list->size () > 1) { | ||||||
| 		list<Pandora_Data *>::iterator iter; | 		list<Pandora_Data *>::iterator iter; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,127 +36,129 @@ using namespace Pandora_Modules; | |||||||
|  */ |  */ | ||||||
| Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec) | Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec) | ||||||
|                                          : Pandora_Module (name) { |                                          : Pandora_Module (name) { | ||||||
|         this->module_exec = "cmd.exe /c \"" + exec + "\""; | 	this->module_exec = "cmd.exe /c \"" + exec + "\""; | ||||||
|          | 	 | ||||||
|         this->setKind (module_exec_str); | 	this->setKind (module_exec_str); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
| Pandora_Module_Exec::run () { | Pandora_Module_Exec::run () { | ||||||
|         STARTUPINFO         si; | 	STARTUPINFO         si; | ||||||
|         PROCESS_INFORMATION pi; | 	PROCESS_INFORMATION pi; | ||||||
|         DWORD               retval; | 	DWORD               retval; | ||||||
|         SECURITY_ATTRIBUTES attributes; | 	SECURITY_ATTRIBUTES attributes; | ||||||
|         HANDLE              out, new_stdout, out_read, job; | 	HANDLE              out, new_stdout, out_read, job; | ||||||
|         string              working_dir; | 	string              working_dir; | ||||||
|          | 
 | ||||||
|         try { | 	try { | ||||||
|                 Pandora_Module::run (); | 		Pandora_Module::run (); | ||||||
|         } catch (Interval_Not_Fulfilled e) { | 	} catch (Interval_Not_Fulfilled e) { | ||||||
| 		this->has_output = false; | 		this->has_output = false; | ||||||
|                 return; | 		return; | ||||||
|         } | 	} | ||||||
|          | 
 | ||||||
|         /* Set the bInheritHandle flag so pipe handles are inherited. */ | 	/* Set the bInheritHandle flag so pipe handles are inherited. */ | ||||||
|         attributes.nLength = sizeof (SECURITY_ATTRIBUTES);  | 	attributes.nLength = sizeof (SECURITY_ATTRIBUTES);  | ||||||
|         attributes.bInheritHandle = TRUE;  | 	attributes.bInheritHandle = TRUE;  | ||||||
|         attributes.lpSecurityDescriptor = NULL;  | 	attributes.lpSecurityDescriptor = NULL;  | ||||||
|          | 
 | ||||||
|         /* Create a job to kill the child tree if it become zombie */ | 	/* Create a job to kill the child tree if it become zombie */ | ||||||
|         /* CAUTION: In order to work this, WINVER should be defined to 0x0500.
 | 	/* CAUTION: In order to compile this, WINVER should be defined to 0x0500.
 | ||||||
|                     This may need no change, since it was redefined by the  | 	   This may need no change, since it was redefined by the  | ||||||
|                     program, but if needed, the macro is defined  | 	   program, but if needed, the macro is defined  | ||||||
|                     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 ("CreateJobObject bad. Err: %d", GetLastError ()); | ||||||
| 		this->has_output = false; | 		this->has_output = false; | ||||||
|                 return; | 		return; | ||||||
|         } | 	} | ||||||
|          | 
 | ||||||
|         /* Get the handle to the current STDOUT. */ | 	/* Get the handle to the current STDOUT. */ | ||||||
|         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 ("CreatePipe failed. Err: %d", GetLastError ()); | ||||||
| 		this->has_output = false; | 		this->has_output = false; | ||||||
|                 return; | 		return; | ||||||
|         } | 	} | ||||||
|          | 
 | ||||||
|         /* Ensure the read handle to the pipe for STDOUT is not inherited */ | 	/* Ensure the read handle to the pipe for STDOUT is not inherited */ | ||||||
|         SetHandleInformation (out_read, HANDLE_FLAG_INHERIT, 0); | 	SetHandleInformation (out_read, HANDLE_FLAG_INHERIT, 0); | ||||||
|          | 
 | ||||||
|         /* Set up members of the STARTUPINFO structure. */ | 	/* Set up members of the STARTUPINFO structure. */ | ||||||
|         ZeroMemory (&si, sizeof (si)); | 	ZeroMemory (&si, sizeof (si)); | ||||||
|         GetStartupInfo (&si); | 	GetStartupInfo (&si); | ||||||
|          | 
 | ||||||
|         si.cb = sizeof (si); | 	si.cb = sizeof (si); | ||||||
|         si.dwFlags     = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; | 	si.dwFlags     = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; | ||||||
|         si.wShowWindow = SW_HIDE; | 	si.wShowWindow = SW_HIDE; | ||||||
|         si.hStdError   = new_stdout; | 	si.hStdError   = new_stdout; | ||||||
|         si.hStdOutput  = new_stdout; | 	si.hStdOutput  = new_stdout; | ||||||
|          | 
 | ||||||
|         /* 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", this->module_exec.c_str ()); | 	pandoraDebug ("Executing: %s", this->module_exec.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 */ | ||||||
|         working_dir = getPandoraInstallDir () + "util\\"; | 	working_dir = getPandoraInstallDir () + "util\\"; | ||||||
|          | 
 | ||||||
|         /* Create the child process. */ | 	/* Create the child process. */ | ||||||
|         if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL, | 	if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL, | ||||||
|                              NULL, TRUE, CREATE_SUSPENDED, NULL, | 			     NULL, TRUE, CREATE_SUSPENDED, NULL, | ||||||
|                              working_dir.c_str (), &si, &pi)) { | 			     working_dir.c_str (), &si, &pi)) { | ||||||
|                 pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d", | 		pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d", | ||||||
|                             this->module_name.c_str (), GetLastError ()); | 			    this->module_name.c_str (), GetLastError ()); | ||||||
| 		this->has_output = false; | 		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 ("Could not assigned proccess to job (error %d)", | ||||||
|                                     GetLastError ()); | 				    GetLastError ()); | ||||||
|                 } | 		} | ||||||
|                 ResumeThread (pi.hThread); | 		ResumeThread (pi.hThread); | ||||||
|                  | 	 | ||||||
|                 /* Wait until process exits. */ | 		/* Wait until process exits. */ | ||||||
|                 /* TODO: The time should be an attribute*/ | 		/* TODO: The time should be an attribute*/ | ||||||
|                 WaitForSingleObject (pi.hProcess, 15000); | 		WaitForSingleObject (pi.hProcess, 15000); | ||||||
|                  | 	 | ||||||
|                 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. (error %d)", | 				pandoraLog ("TerminateJobObject failed. (error %d)", | ||||||
|                                             GetLastError ()); | 					    GetLastError ()); | ||||||
|                         } | 			} | ||||||
|                          | 		 | ||||||
|                         pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)", | 			pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)", | ||||||
|                                     this->module_name.c_str (), retval); | 				    this->module_name.c_str (), retval); | ||||||
| 			this->has_output = false; | 			this->has_output = false; | ||||||
|                 } | 		} | ||||||
|                  | 	 | ||||||
|                 PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL); | 		PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL); | ||||||
|                 /* Read from the stdout */ | 		/* Read from the stdout */ | ||||||
|                 if (read != 0) { | 		if (read != 0) { | ||||||
| 			string output; | 			string output; | ||||||
|                         do { | 			do { | ||||||
|                                 ReadFile (out_read, buffer, BUFSIZE, &read, | 				ReadFile (out_read, buffer, BUFSIZE, &read, | ||||||
|                                           NULL); | 					  NULL); | ||||||
|                                 buffer[read] = '\0'; | 				buffer[read] = '\0'; | ||||||
|                                 output += (char *) buffer; | 				output += (char *) buffer; | ||||||
|                         } while (read >= BUFSIZE); | 			} while (read >= BUFSIZE); | ||||||
| 			this->setOutput (output); | 			this->setOutput (output); | ||||||
|                 } | 		} else { | ||||||
|                  | 			this->setOutput (""); | ||||||
|                 /* Close job, process and thread handles. */ | 		} | ||||||
|                 CloseHandle (job); | 	 | ||||||
|                 CloseHandle (pi.hProcess); | 		/* Close job, process and thread handles. */ | ||||||
|                 CloseHandle (pi.hThread); | 		CloseHandle (job); | ||||||
|         } | 		CloseHandle (pi.hProcess); | ||||||
|          | 		CloseHandle (pi.hThread); | ||||||
|         CloseHandle (new_stdout); | 	} | ||||||
|         CloseHandle (out_read); | 
 | ||||||
|  | 	CloseHandle (new_stdout); | ||||||
|  | 	CloseHandle (out_read); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -119,7 +119,6 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition) | |||||||
|         module = Pandora_Module_Factory::getModuleFromDefinition (definition); |         module = Pandora_Module_Factory::getModuleFromDefinition (definition); | ||||||
|          |          | ||||||
|         if (module != NULL) { |         if (module != NULL) { | ||||||
| 		cout << module->getModuleKind () << endl; |  | ||||||
|                 switch (module->getModuleKind ()) { |                 switch (module->getModuleKind ()) { | ||||||
|                 case MODULE_EXEC: |                 case MODULE_EXEC: | ||||||
|                         module_exec = (Pandora_Module_Exec *) module; |                         module_exec = (Pandora_Module_Exec *) module; | ||||||
|  | |||||||
| @ -135,7 +135,6 @@ Pandora_Windows_Service::pandora_init () { | |||||||
| 			this->transfer_interval = this->interval; | 			this->transfer_interval = this->interval; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	cout << "trans: " << this->transfer_interval << endl; |  | ||||||
| 	 | 	 | ||||||
|         srand ((unsigned) time (0)); |         srand ((unsigned) time (0)); | ||||||
|         this->setSleepTime (this->interval); |         this->setSleepTime (this->interval); | ||||||
| @ -631,7 +630,7 @@ Pandora_Windows_Service::pandora_run () { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this->elapsed_transfer_time += interval; |         this->elapsed_transfer_time += interval; | ||||||
| 	cout << "interval time: " << interval << " transfer time:"  << this->transfer_interval << " time passed: " << this->elapsed_transfer_time << endl; | 
 | ||||||
| 	if (this->elapsed_transfer_time >= this->transfer_interval) { | 	if (this->elapsed_transfer_time >= this->transfer_interval) { | ||||||
| 		agent = getXmlHeader (); | 		agent = getXmlHeader (); | ||||||
| 		 | 		 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user