2007-08-29 Esteban Sanchez <estebans@artica.es>
* pandora_windows_service.cc: Fixed a typo. Disconnect ftp client when an error happened. * ftp/pandora_ftp_client.cc: Set network timeout and ftp timeout. Ignore error when executing moving operations, this is compatible with FTP jails * windows/pandora_wmi.cc: Improved WQL queries and fixed some leaks. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@630 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
9f3515799a
commit
d38e422804
|
@ -1,3 +1,14 @@
|
|||
2007-08-29 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* pandora_windows_service.cc: Fixed a typo. Disconnect ftp client when
|
||||
an error happened.
|
||||
|
||||
* ftp/pandora_ftp_client.cc: Set network timeout and ftp timeout.
|
||||
Ignore error when executing moving operations, this is compatible
|
||||
with FTP jails
|
||||
|
||||
* windows/pandora_wmi.cc: Improved WQL queries and fixed some leaks.
|
||||
|
||||
2007-08-28 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* main.cc: Fixed an error with previous commit.
|
||||
|
|
Binary file not shown.
|
@ -155,6 +155,8 @@ Pandora_Ftp_Client::ftpFileFilename (const string remote_filename,
|
|||
curl_easy_setopt (this->curl, CURLOPT_UPLOAD, 1) ;
|
||||
curl_easy_setopt (this->curl, CURLOPT_URL, url.c_str ());
|
||||
curl_easy_setopt (this->curl, CURLOPT_POSTQUOTE, headerlist);
|
||||
curl_easy_setopt (this->curl, CURLOPT_TIMEOUT, 240);
|
||||
curl_easy_setopt (this->curl, CURLOPT_FTP_RESPONSE_TIMEOUT, 60);
|
||||
curl_easy_setopt (this->curl, CURLOPT_READFUNCTION, read_func);
|
||||
curl_easy_setopt (this->curl, CURLOPT_READDATA, fd);
|
||||
curl_easy_setopt (curl, CURLOPT_INFILESIZE_LARGE,
|
||||
|
@ -173,6 +175,8 @@ Pandora_Ftp_Client::ftpFileFilename (const string remote_filename,
|
|||
|
||||
switch (this->result) {
|
||||
case CURLE_OK:
|
||||
case CURLE_FTP_QUOTE_ERROR: /* These error happens when FTP is in a jail.
|
||||
Transfer was OK, moving wasn't. */
|
||||
break;
|
||||
case CURLE_COULDNT_CONNECT:
|
||||
throw Unknown_Host ();
|
||||
|
|
|
@ -238,18 +238,20 @@ Pandora_Windows_Service::copyFtpDataFile (string host,
|
|||
ftp_client.ftpFileFilename (remote_path + filename,
|
||||
filepath);
|
||||
} catch (FTP::Unknown_Host e) {
|
||||
pandoraLog ("Failed when copying to %s (%s)", host.c_str (),
|
||||
ftp_client.getError ().c_str ());
|
||||
pandoraLog ("Pandora Agent: Failed when copying to %s (%s)",
|
||||
host.c_str (), ftp_client.getError ().c_str ());
|
||||
ftp_client.disconnect ();
|
||||
throw e;
|
||||
} catch (FTP::Authentication_Failed e) {
|
||||
pandoraLog ("Pandora Agent: Authentication Failed "
|
||||
"when connecting to %s (%s)",
|
||||
host.c_str (), ftp_client.getError ().c_str ());
|
||||
ftp_client.disconnect ();
|
||||
throw e;
|
||||
} catch (FTP::FTP_Exception e) {
|
||||
pandoraLog ("Pandora Agent: Failed when copying to %s (%s)",
|
||||
host.c_str (), ftp_client.getError ().c_str ());
|
||||
|
||||
ftp_client.disconnect ();
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
@ -275,7 +277,7 @@ Pandora_Windows_Service::copyDataFile (string filename)
|
|||
copyScpDataFile (host, remote_path, filename);
|
||||
} else {
|
||||
pandoraLog ("Invalid transfer mode: %s."
|
||||
"Please rechak transfer_mode option "
|
||||
"Please recheck transfer_mode option "
|
||||
"in configuration file.");
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace Pandora_Wmi;
|
||||
|
@ -58,30 +59,18 @@ Pandora_Wmi::isProcessRunning (string process_name) {
|
|||
CDispPtr wmi_svc, quickfixes;
|
||||
string name;
|
||||
int result = 0;
|
||||
string query;
|
||||
|
||||
struct QFix {
|
||||
CDhStringA name, description, state;
|
||||
};
|
||||
|
||||
query = "SELECT * FROM Win32_Process WHERE Name=\"" + process_name + "\"";
|
||||
cout << "Query: " << query << endl;
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||
L".ExecQuery(%S)",
|
||||
L"SELECT * FROM Win32_Process"));
|
||||
L".ExecQuery(%T)",
|
||||
query.c_str ()));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%s", &fix.name, quickfix,
|
||||
L".Name");
|
||||
|
||||
name = fix.name;
|
||||
transform (name.begin (), name.end (), name.begin (),
|
||||
(int (*) (int)) tolower);
|
||||
|
||||
if (process_name == name) {
|
||||
result++;
|
||||
}
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
pandoraLog ("isProcessRunning error. %s", errstr.c_str ());
|
||||
|
@ -102,39 +91,26 @@ int
|
|||
Pandora_Wmi::isServiceRunning (string service_name) {
|
||||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
string name, state;
|
||||
string query;
|
||||
char *state;
|
||||
int retval;
|
||||
|
||||
struct QFix {
|
||||
CDhStringA name, state;
|
||||
};
|
||||
query = "SELECT * FROM Win32_Service WHERE Name = \"" + service_name + "\"";
|
||||
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||
L".ExecQuery(%S)",
|
||||
L"SELECT * FROM Win32_Service"));
|
||||
L".ExecQuery(%T)",
|
||||
query.c_str ()));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%s", &fix.name, quickfix,
|
||||
L".Name");
|
||||
|
||||
name = fix.name;
|
||||
transform (name.begin (), name.end (), name.begin (),
|
||||
(int (*) (int)) tolower);
|
||||
|
||||
if (service_name == name) {
|
||||
dhGetValue (L"%s", &fix.state, quickfix,
|
||||
dhGetValue (L"%s", &state, quickfix,
|
||||
L".State");
|
||||
state = fix.state;
|
||||
|
||||
if (state == "Running") {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
retval = (state == "Running") ? 1 : 0;
|
||||
dhFreeString (state);
|
||||
|
||||
return retval;
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
pandoraLog ("isServiceRunning error. %s", errstr.c_str ());
|
||||
|
@ -146,7 +122,7 @@ Pandora_Wmi::isServiceRunning (string service_name) {
|
|||
/**
|
||||
* Get the free space in a logical disk drive.
|
||||
*
|
||||
* @param disk_id Disk drive letter (C.
|
||||
* @param disk_id Disk drive letter (C: for example).
|
||||
*
|
||||
* @return Free space amount in MB.
|
||||
*
|
||||
|
@ -172,7 +148,6 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
|||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
dhGetValue (L"%d", &space, quickfix,
|
||||
L".FreeSpace");
|
||||
cout << space << endl;
|
||||
|
||||
return space / 1024 / 1024;
|
||||
} NEXT_THROW (quickfix);
|
||||
|
@ -197,39 +172,28 @@ int
|
|||
Pandora_Wmi::getCpuUsagePercentage (int cpu_id) {
|
||||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
string id, cpu_id_str;
|
||||
|
||||
cpu_id_str = "CPU";
|
||||
cpu_id_str += Pandora_Strutils::inttostr (cpu_id);
|
||||
|
||||
struct QFix {
|
||||
CDhStringA id;
|
||||
string query;
|
||||
long load_percentage;
|
||||
};
|
||||
std::ostringstream stm;
|
||||
|
||||
stm << cpu_id;
|
||||
query = "SELECT * FROM Win32_Processor WHERE DeviceID = \"CPU" + stm.str () + "\"";
|
||||
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||
L".ExecQuery(%S)",
|
||||
L"SELECT * FROM Win32_Processor "));
|
||||
L".ExecQuery(%T)",
|
||||
query.c_str ()));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%s", &fix.id, quickfix,
|
||||
L".DeviceID");
|
||||
|
||||
id = fix.id;
|
||||
|
||||
if (cpu_id_str == id) {
|
||||
dhGetValue (L"%d", &fix.load_percentage, quickfix,
|
||||
dhGetValue (L"%d", &load_percentage, quickfix,
|
||||
L".LoadPercentage");
|
||||
|
||||
return fix.load_percentage;
|
||||
}
|
||||
|
||||
return load_percentage;
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
cout << query << endl;
|
||||
cout << errstr << endl;
|
||||
pandoraLog ("getCpuUsagePercentage error. %s", errstr.c_str ());
|
||||
}
|
||||
|
||||
|
@ -247,10 +211,7 @@ long
|
|||
Pandora_Wmi::getFreememory () {
|
||||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
|
||||
struct QFix {
|
||||
long free_memory;
|
||||
};
|
||||
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
|
@ -259,12 +220,10 @@ Pandora_Wmi::getFreememory () {
|
|||
L"SELECT * FROM Win32_PerfRawData_PerfOS_Memory "));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%d", &fix.free_memory, quickfix,
|
||||
dhGetValue (L"%d", &free_memory, quickfix,
|
||||
L".AvailableMBytes");
|
||||
|
||||
return fix.free_memory;
|
||||
return free_memory;
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
pandoraLog ("getFreememory error. %s", errstr.c_str ());
|
||||
|
@ -282,12 +241,9 @@ string
|
|||
Pandora_Wmi::getOSName () {
|
||||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
char *name = NULL;
|
||||
string ret;
|
||||
|
||||
struct QFix {
|
||||
CDhStringA name, state, description;
|
||||
};
|
||||
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||
|
@ -295,12 +251,11 @@ Pandora_Wmi::getOSName () {
|
|||
L"SELECT * FROM Win32_OperatingSystem "));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%s", &fix.name, quickfix,
|
||||
dhGetValue (L"%s", &name, quickfix,
|
||||
L".Caption");
|
||||
|
||||
ret = fix.name;
|
||||
ret = name;
|
||||
dhFreeString (name);
|
||||
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
|
@ -319,12 +274,9 @@ string
|
|||
Pandora_Wmi::getOSVersion () {
|
||||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
char *version = NULL;
|
||||
string ret;
|
||||
|
||||
struct QFix {
|
||||
CDhStringA name, state, description;
|
||||
};
|
||||
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||
|
@ -332,12 +284,11 @@ Pandora_Wmi::getOSVersion () {
|
|||
L"SELECT * FROM Win32_OperatingSystem "));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%s", &fix.name, quickfix,
|
||||
dhGetValue (L"%s", &version, quickfix,
|
||||
L".CSDVersion");
|
||||
|
||||
ret = fix.name;
|
||||
ret = version;
|
||||
dhFreeString (version);
|
||||
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
|
@ -356,12 +307,9 @@ string
|
|||
Pandora_Wmi::getOSBuild () {
|
||||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
char *build = NULL;
|
||||
string ret;
|
||||
|
||||
struct QFix {
|
||||
CDhStringA name, state, description;
|
||||
};
|
||||
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||
|
@ -369,12 +317,11 @@ Pandora_Wmi::getOSBuild () {
|
|||
L"SELECT * FROM Win32_OperatingSystem "));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%s", &fix.name, quickfix,
|
||||
dhGetValue (L"%s", &build, quickfix,
|
||||
L".Version");
|
||||
|
||||
ret = fix.name;
|
||||
ret = build;
|
||||
dhFreeString (build);
|
||||
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
|
@ -393,12 +340,9 @@ string
|
|||
Pandora_Wmi::getSystemName () {
|
||||
CDhInitialize init;
|
||||
CDispPtr wmi_svc, quickfixes;
|
||||
char *name = NULL;
|
||||
string ret;
|
||||
|
||||
struct QFix {
|
||||
CDhStringA name, state, description;
|
||||
};
|
||||
|
||||
try {
|
||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||
|
@ -406,12 +350,11 @@ Pandora_Wmi::getSystemName () {
|
|||
L"SELECT * FROM Win32_OperatingSystem "));
|
||||
|
||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||
QFix fix = { 0 };
|
||||
|
||||
dhGetValue (L"%s", &fix.name, quickfix,
|
||||
dhGetValue (L"%s", &name, quickfix,
|
||||
L".CSName");
|
||||
|
||||
ret = fix.name;
|
||||
ret = name;
|
||||
dhFreeString (name);
|
||||
|
||||
} NEXT_THROW (quickfix);
|
||||
} catch (string errstr) {
|
||||
|
|
Loading…
Reference in New Issue