2008-07-09 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.[cc,h]: Added strUnicodeToAnsi(). * modules/pandora_module_logevent.cc, pandora_windows_service.[cc,h], windows/pandora_wmi.h: Tabs and blankspace style correction. * windows/pandora_wmi.cc: Convert result in getEventList() to ANSI, which was causing some BADXML errors on server. Tabs and blankspace style correction. * bin/PandoraAgent.exe: Updated to last commit. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@946 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
8e9b10cdc2
commit
654405d451
|
@ -1,3 +1,16 @@
|
|||
2008-07-09 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* pandora_strutils.[cc,h]: Added strUnicodeToAnsi().
|
||||
|
||||
* modules/pandora_module_logevent.cc, pandora_windows_service.[cc,h],
|
||||
windows/pandora_wmi.h: Tabs and blankspace style correction.
|
||||
|
||||
* windows/pandora_wmi.cc: Convert result in getEventList() to ANSI,
|
||||
which was causing some BADXML errors on server. Tabs and blankspace
|
||||
style correction.
|
||||
|
||||
* bin/PandoraAgent.exe: Updated to last commit.
|
||||
|
||||
2008-06-11 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* bin/PandoraAgent.exe: Updated to commit, fixed an error when
|
||||
|
|
Binary file not shown.
|
@ -76,7 +76,7 @@ Pandora_Module_Logevent::run () {
|
|||
return;
|
||||
}
|
||||
|
||||
for(event = event_list.begin (); event != event_list.end(); ++event) {
|
||||
for (event = event_list.begin (); event != event_list.end(); ++event) {
|
||||
// No WMI timestamp?
|
||||
if (event->size () < 26) {
|
||||
this->setOutput (*event);
|
||||
|
@ -84,7 +84,7 @@ Pandora_Module_Logevent::run () {
|
|||
}
|
||||
|
||||
// Get the timestamp
|
||||
Pandora_Wmi::convertWMIDate(event->substr (0, 26), &system_time);
|
||||
Pandora_Wmi::convertWMIDate (event->substr (0, 26), &system_time);
|
||||
|
||||
// Store the data
|
||||
this->setOutput (event->substr (26), &system_time);
|
||||
|
|
|
@ -42,12 +42,12 @@ Pandora_Strutils::trim (const string str) {
|
|||
string result = str;
|
||||
string::size_type index = result.find_last_not_of (delims);
|
||||
|
||||
if(index != string::npos) {
|
||||
if (index != string::npos) {
|
||||
result.erase (++index);
|
||||
}
|
||||
|
||||
index = result.find_first_not_of (delims);
|
||||
if(index != std::string::npos) {
|
||||
if (index != std::string::npos) {
|
||||
result.erase (0, index);
|
||||
} else {
|
||||
result.erase ();
|
||||
|
@ -56,6 +56,41 @@ Pandora_Strutils::trim (const string str) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an unicode string to a ANSI string.
|
||||
*
|
||||
* @param s String to convert
|
||||
*
|
||||
* @return String converted into ANSI code
|
||||
*/
|
||||
LPSTR
|
||||
Pandora_Strutils::strUnicodeToAnsi (LPCWSTR s) {
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
int cw = lstrlenW (s);
|
||||
if (cw == 0) {
|
||||
CHAR *psz = new CHAR[1];
|
||||
*psz='\0';
|
||||
return psz;
|
||||
}
|
||||
|
||||
int cc = WideCharToMultiByte (CP_ACP,0, s, cw, NULL, 0, NULL, NULL);
|
||||
if (cc==0)
|
||||
return NULL;
|
||||
|
||||
CHAR *psz = new CHAR[cc+1];
|
||||
cc = WideCharToMultiByte (CP_ACP, 0, s, cw, psz, cc, NULL, NULL);
|
||||
|
||||
if (cc == 0) {
|
||||
delete[] psz;
|
||||
return NULL;
|
||||
}
|
||||
psz[cc]='\0';
|
||||
|
||||
return psz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an integer variable into a string.
|
||||
*
|
||||
|
|
|
@ -43,6 +43,8 @@ namespace Pandora_Strutils {
|
|||
|
||||
string trim (const string str);
|
||||
|
||||
LPSTR strUnicodeToAnsi (LPCWSTR s);
|
||||
|
||||
string inttostr (const int i);
|
||||
string longtostr (const long i);
|
||||
string longtohex (const long i);
|
||||
|
|
|
@ -52,7 +52,6 @@ Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name,
|
|||
const char * svc_display_name,
|
||||
const char * svc_description)
|
||||
: Windows_Service (svc_name, svc_display_name, svc_description) {
|
||||
|
||||
this->setInitFunction ((void (Windows_Service::*) ())
|
||||
&Pandora_Windows_Service::pandora_init);
|
||||
this->setRunFunction ((void (Windows_Service::*) ())
|
||||
|
|
|
@ -392,9 +392,11 @@ Pandora_Wmi::getEventList (string source, string type, string pattern, int inter
|
|||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
char *value = NULL;
|
||||
WCHAR *unicode_value;
|
||||
string event, limit, message, query, timestamp;
|
||||
char *encode;
|
||||
|
||||
limit = getTimestampLimit(interval);
|
||||
limit = getTimestampLimit (interval);
|
||||
if (limit.empty()) {
|
||||
pandoraDebug ("Pandora_Wmi::getEventList: getTimestampLimit error");
|
||||
return;
|
||||
|
@ -423,13 +425,14 @@ Pandora_Wmi::getEventList (string source, string type, string pattern, int inter
|
|||
dhFreeString (value);
|
||||
|
||||
// Message
|
||||
dhGetValue (L"%s", &value, quickfix,
|
||||
dhGetValue (L"%S", &unicode_value, quickfix,
|
||||
L".Message");
|
||||
message = value;
|
||||
value = Pandora_Strutils::strUnicodeToAnsi (unicode_value);
|
||||
message = Pandora_Strutils::trim (value);
|
||||
dhFreeString (value);
|
||||
|
||||
// LIKE is not always available, we have to filter ourselves
|
||||
if (pattern.empty() || (message.find(pattern) != string::npos)) {
|
||||
if (pattern.empty () || (message.find (pattern) != string::npos)) {
|
||||
event = timestamp + " " + message;
|
||||
event_list.push_back(event);
|
||||
}
|
||||
|
@ -438,8 +441,6 @@ Pandora_Wmi::getEventList (string source, string type, string pattern, int inter
|
|||
} catch (string errstr) {
|
||||
pandoraDebug ("Pandora_Wmi::getEventList: error: %s", errstr.c_str ());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -492,16 +493,19 @@ Pandora_Wmi::getTimestampLimit (int interval) {
|
|||
return string (limit_str);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Converts a date in WMI format to SYSTEMTIME format.
|
||||
*
|
||||
* @param wmi_date Date in WMI format
|
||||
* @param system_time Output system time variable
|
||||
*/
|
||||
void
|
||||
Pandora_Wmi::convertWMIDate (string wmi_date, SYSTEMTIME *system_time) {
|
||||
|
||||
system_time->wYear = atoi(wmi_date.substr (0, 4).c_str());
|
||||
system_time->wMonth = atoi(wmi_date.substr (4, 2).c_str());
|
||||
system_time->wDay = atoi(wmi_date.substr (6, 2).c_str());
|
||||
system_time->wHour = atoi(wmi_date.substr (8, 2).c_str());
|
||||
system_time->wMinute = atoi(wmi_date.substr (10, 2).c_str());
|
||||
system_time->wSecond = atoi(wmi_date.substr (12, 2).c_str());
|
||||
Pandora_Wmi::convertWMIDate (string wmi_date, SYSTEMTIME *system_time)
|
||||
{
|
||||
system_time->wYear = atoi (wmi_date.substr (0, 4).c_str());
|
||||
system_time->wMonth = atoi (wmi_date.substr (4, 2).c_str());
|
||||
system_time->wDay = atoi (wmi_date.substr (6, 2).c_str());
|
||||
system_time->wHour = atoi (wmi_date.substr (8, 2).c_str());
|
||||
system_time->wMinute = atoi (wmi_date.substr (10, 2).c_str());
|
||||
system_time->wSecond = atoi (wmi_date.substr (12, 2).c_str());
|
||||
}
|
||||
|
|
|
@ -50,9 +50,6 @@ namespace Pandora_Wmi {
|
|||
void getEventList (string source, string type, string pattern, int interval, list<string> &event_list);
|
||||
string getTimestampLimit (int interval);
|
||||
void convertWMIDate (string wmi_date, SYSTEMTIME *system_time);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue