diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index cc84a14157..d0690bb9ab 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,15 @@ +2011-08-18 Sergio Martin + + * win32/windows/pandora_windows_info.h + win32/windows/pandora_wmi.cc + win32/windows/pandora_wmi.h + win32/windows/pandora_windows_info.cc + win32/bin/PandoraAgent.exe + win32/bin/pandora_agent.conf + win32/pandora_windows_service.cc: Added to the windows agent + the address token with manual (specified address) and auto + (detecting from WMI the address) modes + 2011-08-10 Vanessa Gil * unix/pandora_agent.php: Fixed error reading collections of the configuration file. diff --git a/pandora_agents/win32/bin/PandoraAgent.exe b/pandora_agents/win32/bin/PandoraAgent.exe index 9223a6f33b..925f53f2c5 100755 Binary files a/pandora_agents/win32/bin/PandoraAgent.exe and b/pandora_agents/win32/bin/PandoraAgent.exe differ diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index a32f040723..685343c9d3 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -29,6 +29,12 @@ temporal "$AgentTemp$" # agent_name My_Custom_Agent_name +# address: Enforce to server a ip address to this agent +# You can also try to detect the first IP using "auto", for example +#address auto +# or setting a fixed IP address, like for example: +#address 192.168.36.73 + # Group assigned for this agent (descriptive, p.e: Servers) #group Servers diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 32c2d1fd86..822d3378a8 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -356,7 +356,7 @@ Pandora_Windows_Service::lauchTentacleProxy() { string Pandora_Windows_Service::getXmlHeader () { char timestamp[20]; - string agent_name, os_name, os_version, encoding, value, xml; + string agent_name, os_name, os_version, encoding, value, xml, address; time_t ctime; struct tm *ctime_tm = NULL; @@ -397,6 +397,19 @@ Pandora_Windows_Service::getXmlHeader () { xml += "\" timestamp=\""; xml += timestamp; } + + // Get agent address + address = conf->getValue ("address"); + if (address != "") { + if(address == "auto") { + address = Pandora_Windows_Info::getSystemAddress (); + } + + if(address != "") { + xml += "\" address=\""; + xml += address; + } + } xml += "\" interval=\"" + conf->getValue ("interval") + "\" os_name=\"" + os_name + diff --git a/pandora_agents/win32/windows/pandora_windows_info.cc b/pandora_agents/win32/windows/pandora_windows_info.cc index aceb2bdb30..5e3529c93c 100644 --- a/pandora_agents/win32/windows/pandora_windows_info.cc +++ b/pandora_agents/win32/windows/pandora_windows_info.cc @@ -67,6 +67,16 @@ Pandora_Windows_Info::getSystemName () { return Pandora_Wmi::getSystemName (); } +/** + * Get the address of the running system. + * + * @return The system IP address. + */ +string +Pandora_Windows_Info::getSystemAddress () { + return Pandora_Wmi::getSystemAddress (); +} + /** * Get the system path of the running operating system. * diff --git a/pandora_agents/win32/windows/pandora_windows_info.h b/pandora_agents/win32/windows/pandora_windows_info.h index afa3166c22..2e267872fc 100644 --- a/pandora_agents/win32/windows/pandora_windows_info.h +++ b/pandora_agents/win32/windows/pandora_windows_info.h @@ -38,6 +38,7 @@ namespace Pandora_Windows_Info { string getOSVersion (); string getOSBuild (); string getSystemName (); + string getSystemAddress (); string getSystemPath (); HANDLE *getProcessHandles (string name, int *num_procs); string getRegistryValue (HKEY root, const string treepath, const string keyname); diff --git a/pandora_agents/win32/windows/pandora_wmi.cc b/pandora_agents/win32/windows/pandora_wmi.cc index 7b04031edc..b4fc0cfa03 100644 --- a/pandora_agents/win32/windows/pandora_wmi.cc +++ b/pandora_agents/win32/windows/pandora_wmi.cc @@ -1188,3 +1188,43 @@ Pandora_Wmi::getServices (list &rows) { } return num_objects; } + +/** + * Get the system address + * + * @return The system address + */ +string +Pandora_Wmi::getSystemAddress () { + CDhInitialize init; + CDispPtr wmi_svc = NULL, nic_info = NULL; + VARIANT ip_addresses; + char *caption = NULL, *mac_address = NULL; + string ret = ""; + + try { + pandoraLog ("0"); + + dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc)); + dhCheck (dhGetValue (L"%o", &nic_info, wmi_svc, + L".ExecQuery(%S)", + L"SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")); + + FOR_EACH (nic_info_item, nic_info, NULL) { + dhGetValue (L"%v", &ip_addresses, nic_info_item, + L".IPAddress"); + + if (&ip_addresses != NULL) + { + ret = getIPs(&ip_addresses); + if(ret != "0.0.0.0") { + break; + } + } + } NEXT_THROW (nic_info_item); + } catch (string errstr) { + pandoraLog ("runWMIQuery error. %s", errstr.c_str ()); + } + + return ret; +} diff --git a/pandora_agents/win32/windows/pandora_wmi.h b/pandora_agents/win32/windows/pandora_wmi.h index adfd8aa4ef..601499f4a1 100644 --- a/pandora_agents/win32/windows/pandora_wmi.h +++ b/pandora_agents/win32/windows/pandora_wmi.h @@ -52,6 +52,7 @@ namespace Pandora_Wmi { string getOSVersion (); string getOSBuild (); string getSystemName (); + string getSystemAddress (); bool runProgram (string command, DWORD flags = 0); bool startService (string service_name); bool stopService (string service_name);