2006-07-11 Esteban Sanchez <estebans@artica.es>

* pandora_windows_service.h: Public methods converted into private.

        * modules/pandora_module_freedisk.[cc,h]: Added to repository. Implements a module to check the free space in a disk.

        * modules/pandora_module.h, modules/pandora_module_factory.cc, pandora_module_list.cc: Added support to Pandora_Module_Freedisk modules.

        * ssh/libssh2/channel.c: Fixed a bug on libssh2_channel_wait_closed that caused to not copy the file to the remote host.

        * windows/wmi/pandora_wmi.[cc,h]: Added getDiskFreeSpace() to get support eh Pandora_Module_Freedisk modules.

        * pandora_strutils,[cc,h]: Added longtostr() to convert a long into a string.

        * PandoraAgent.dev: Added new files to the project.

        * bin/PandoraAgent.exe: Updated to the new commit.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@120 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2006-07-11 09:41:22 +00:00
parent 4946412af2
commit be014cfd1c
16 changed files with 234 additions and 22 deletions

View File

@ -1,3 +1,27 @@
2006-07-11 Esteban Sanchez <estebans@artica.es>
* pandora_windows_service.h: Public methods converted into private.
* modules/pandora_module_freedisk.[cc,h]: Added to repository.
Implements a module to check the free space in a disk.
* modules/pandora_module.h, modules/pandora_module_factory.cc,
pandora_module_list.cc: Added support to Pandora_Module_Freedisk
modules.
* ssh/libssh2/channel.c: Fixed a bug on libssh2_channel_wait_closed
that caused to not copy the file to the remote host.
* windows/wmi/pandora_wmi.[cc,h]: Added getDiskFreeSpace() to get
support eh Pandora_Module_Freedisk modules.
* pandora_strutils,[cc,h]: Added longtostr() to convert a long into a
string.
* PandoraAgent.dev: Added new files to the project.
* bin/PandoraAgent.exe: Updated to the new commit.
2006-07-10 Esteban Sanchez <estebans@artica.es>
* modules/pandora_module_list.cc: Delete modules from the list in the

View File

@ -1,7 +1,7 @@
[Project]
FileName=PandoraAgent.dev
Name=PandoraAgent
UnitCount=59
UnitCount=61
Type=1
Ver=1
ObjFiles=
@ -637,3 +637,23 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit60]
FileName=modules\pandora_module_freedisk.cc
CompileCpp=1
Folder=Modules
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit61]
FileName=modules\pandora_module_freedisk.h
CompileCpp=1
Folder=Modules
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

View File

@ -45,12 +45,14 @@ namespace Pandora_Modules {
MODULE_0,
MODULE_EXEC,
MODULE_PROC,
MODULE_SERVICE
MODULE_SERVICE,
MODULE_FREEDISK
};
const string module_exec_str = "module_exec";
const string module_proc_str = "module_proc";
const string module_service_str = "module_service";
const string module_freedisk_str = "module_freedisk";
class Output_Error : public Pandora::Pandora_Exception { };
class Interval_Error : public Pandora::Pandora_Exception { };

View File

@ -23,6 +23,7 @@
#include "pandora_module_exec.h"
#include "pandora_module_proc.h"
#include "pandora_module_service.h"
#include "pandora_module_freedisk.h"
#include "../pandora_strutils.h"
#include <list>
@ -36,6 +37,7 @@ using namespace Pandora_Strutils;
#define TOKEN_EXEC ("module_exec ")
#define TOKEN_PROC ("module_proc ")
#define TOKEN_SERVICE ("module_service ")
#define TOKEN_FREEDISK ("module_freedisk ")
#define TOKEN_MAX ("module_max ")
#define TOKEN_MIN ("module_min ")
#define TOKEN_DESCRIPTION ("module_description ")
@ -59,6 +61,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
string module_name, module_type, module_exec;
string module_min, module_max, module_description;
string module_interval, module_proc, module_service;
string module_freedisk;
Pandora_Module *module;
bool numeric;
@ -100,6 +103,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_service == "") {
module_service = parseLine (line, TOKEN_SERVICE);
}
if (module_freedisk == "") {
module_freedisk = parseLine (line, TOKEN_FREEDISK);
}
if (module_max == "") {
module_max = parseLine (line, TOKEN_MAX);
}
@ -122,6 +128,10 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
} else if (module_service != "") {
module = new Pandora_Module_Service (module_name,
module_service);
} else if (module_freedisk != "") {
module = new Pandora_Module_Freedisk (module_name,
module_freedisk);
} else {
return NULL;
}

View File

@ -0,0 +1,62 @@
/* Pandora freedisk module. These modules check the free space in a
logical drive.
Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "pandora_module_freedisk.h"
#include "../windows/pandora_wmi.h"
#include "../pandora_strutils.h"
#include <algorithm>
#include <cctype>
using namespace Pandora;
using namespace Pandora_Modules;
using namespace Pandora_Strutils;
Pandora_Module_Freedisk::Pandora_Module_Freedisk (string name, string disk_id)
: Pandora_Module (name) {
this->disk_id = disk_id;
transform (disk_id.begin (), disk_id.end (),
this->disk_id.begin (), (int (*) (int)) toupper);
this->module_kind_str = module_freedisk_str;
this->module_kind = MODULE_FREEDISK;
}
void
Pandora_Module_Freedisk::run () {
long res;
try {
Pandora_Module::run ();
} catch (Interval_Not_Fulfilled e) {
return;
}
try {
res = Pandora_Wmi::getDiskFreeSpace (this->disk_id);
output = longtostr (res);
pandoraDebug ("%s", output.c_str ());
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
this->has_output = false;
}
}

View File

@ -0,0 +1,38 @@
/* Pandora freedisk module. These modules check the free space in a
logical drive.
Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PANDORA_MODULE_FREEDISK_H__
#define __PANDORA_MODULE_FREEDISK_H__
#include "pandora_module.h"
namespace Pandora_Modules {
class Pandora_Module_Freedisk : public Pandora_Module {
private:
string disk_id;
public:
Pandora_Module_Freedisk (string name, string disk_id);
void run ();
};
}
#endif

View File

@ -23,6 +23,7 @@
#include "pandora_module_exec.h"
#include "pandora_module_proc.h"
#include "pandora_module_service.h"
#include "pandora_module_freedisk.h"
#include <fstream>
using namespace std;
@ -91,10 +92,11 @@ Pandora_Module_List::~Pandora_Module_List () {
void
Pandora_Module_List::parseModuleDefinition (string definition) {
Pandora_Module *module;
Pandora_Module_Exec *module_exec;
Pandora_Module_Proc *module_proc;
Pandora_Module_Service *module_service;
Pandora_Module *module;
Pandora_Module_Exec *module_exec;
Pandora_Module_Proc *module_proc;
Pandora_Module_Service *module_service;
Pandora_Module_Freedisk *module_freedisk;
module = Pandora_Module_Factory::getModuleFromDefinition (definition);
@ -115,6 +117,12 @@ Pandora_Module_List::parseModuleDefinition (string definition) {
module_service = (Pandora_Module_Service *) module;
modules->push_back (module_service);
break;
case MODULE_FREEDISK:
module_freedisk = (Pandora_Module_Freedisk *) module;
modules->push_back (module_freedisk);
break;
default:
break;

View File

@ -49,7 +49,12 @@ Pandora_Strutils::trim (const string str) {
string
Pandora_Strutils::inttostr (const int i) {
std::ostringstream o;
return longtostr (i);
}
string
Pandora_Strutils::longtostr (const long i) {
std::ostringstream o;
o << i;

View File

@ -35,6 +35,7 @@ namespace Pandora_Strutils {
string trim (const string str);
string inttostr (const int i);
string longtostr (const long i);
string longtohex (const long i);
int strtoint (const string str);

View File

@ -39,7 +39,7 @@ private:
string agent_name;
TiXmlElement * getXmlHeader ();
public:
void pandora_run ();
void pandora_init ();
public:

View File

@ -1126,11 +1126,6 @@ LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel)
{
LIBSSH2_SESSION* session = channel->session;
if (!libssh2_channel_eof(channel)) {
libssh2_error(session, LIBSSH2_ERROR_INVAL, "libssh2_channel_wait_closed() invoked when channel is not in EOF state", 0);
return -1;
}
#ifdef LIBSSH2_DEBUG_CONNECTION
_libssh2_debug(session, LIBSSH2_DBG_CONN, "Awaiting close of channel %lu/%lu", channel->local.id, channel->remote.id);
#endif

View File

@ -198,9 +198,9 @@ void _libssh2_debug(LIBSSH2_SESSION *session, int context, const char *format, .
va_start(vargs, format);
len += vsnprintf(buffer + len, 1535 - len, format, vargs);
buffer[len] = '\n';
buffer[len] = '\0';
va_end(vargs);
write(2, buffer, len + 1);
fprintf (stderr,"%s\n", buffer);
}
/* }}} */
#endif

View File

@ -120,7 +120,7 @@ Pandora_SSH_Test::test () {
remote_filepath += "/";
}
cout << "Remote copying " << tmp_filepath << "on server " << remote_host
cout << "Remote copying " << tmp_filepath << " on server " << remote_host
<< " at " << remote_filepath << tmp_filename << endl;
try {
ssh_client->scpFileFilename (remote_filepath + tmp_filename,

View File

@ -132,6 +132,50 @@ Pandora_Wmi::isServiceRunning (string service_name) {
return 0;
}
long
Pandora_Wmi::getDiskFreeSpace (string disk_id) {
CDhInitialize init;
CDispPtr wmi_svc, quickfixes;
string id;
dhToggleExceptions (TRUE);
struct QFix {
CDhStringA id;
long free_space;
};
try {
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
L".ExecQuery(%S)",
L"SELECT * FROM Win32_LogicalDisk "));
FOR_EACH (quickfix, quickfixes, NULL) {
QFix fix = { 0 };
dhGetValue (L"%s", &fix.id, quickfix,
L".DeviceID");
id = fix.id;
pandoraDebug ("%s %s", disk_id.c_str (), id.c_str ());
if (disk_id == id) {
dhGetValue (L"%d", &fix.free_space, quickfix,
L".FreeSpace");
pandoraDebug ("%d Bytes", fix.free_space);
return fix.free_space;
}
} NEXT_THROW (quickfix);
} catch (string errstr) {
pandoraLog ("getOSName error. %s", errstr.c_str ());
}
throw Pandora_Wmi_Error ();
}
string
Pandora_Wmi::getOSName () {
CDhInitialize init;

View File

@ -30,12 +30,15 @@ using namespace Pandora;
using namespace std;
namespace Pandora_Wmi {
int isProcessRunning (string process_name);
int isServiceRunning (string service_name);
string getOSName ();
string getOSVersion ();
string getOSBuild ();
string getSystemName ();
class Pandora_Wmi_Error : public Pandora_Exception { };
int isProcessRunning (string process_name);
int isServiceRunning (string service_name);
long getDiskFreeSpace (string disk_id);
string getOSName ();
string getOSVersion ();
string getOSBuild ();
string getSystemName ();
};
#endif