2006-08-15 Esteban Sanchez <estebans@artica.es>
* autogen.sh, configure.in, Makefile.am, Doxyfile.in: Added to repository. They are used to generate documentation, not to compile. * main.cc: Added some comments. Style correction. * pandora.[cc,h]: Added documentation comments. Changed visibility of some attributes. * pandora_agent_conf.[cc,h]: Added to Pandora namespace. Added documentation comments. * pandora_windows_service.[cc,h], pandora_strutils.[cc,h], windows/pandora_windows_infp.[cc,h], ssh/pandora_ssh_test.[cc,h]: Added documentation comments. * ssh/pandora_ssh_client.[cc,h]:Added documentation comments. Removed old method to connect with user and password. Style correction. * misc/pandora_file.[cc,h]: Added documentation comments. Renamed some parameters. * modules/pandora_module.[cc,h]: Added documentation comments. Put a name to the enumerators. Added a new class to agroupate all exceptions produced by Pandora_Module child class objects. Changed visibility of some attributes. Added some new methods and renamed others. * modules/pandora_module_cpuusage.[cc,h], modules/pandora_module_exec.[cc,h], modules/pandora_module_freememory.[cc,h], modules/pandora_module_freedisk.[cc,h], modules/pandora_module_proc.[cc,h], modules/pandora_module_service.[cc,h]: Added documentation comments. Some changes to adapt the objects to the Pandora_Module changes. * modules/pandora_module_list.[cc,h]: Added documentation comments. Some changes to adapt the objects to the Pandora_Module changes. Added to Pandora_Modules namespace. * windows/pandora_windows_wmi.[cc,h]: Added documentation comments. Renamed Pandora_Wmi_Error to Pandora_Wmi_Exception. * windows_service.[cc,h]: Added documentation comments. Changed visibility of some attributes. Style correction. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@150 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
2d31510f16
commit
ed134b442c
|
@ -1,3 +1,48 @@
|
|||
2006-08-15 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* autogen.sh, configure.in, Makefile.am, Doxyfile.in: Added to
|
||||
repository. They are used to generate documentation, not to compile.
|
||||
|
||||
* main.cc: Added some comments. Style correction.
|
||||
|
||||
* pandora.[cc,h]: Added documentation comments. Changed visibility of
|
||||
some attributes.
|
||||
|
||||
* pandora_agent_conf.[cc,h]: Added to Pandora namespace. Added
|
||||
documentation comments.
|
||||
|
||||
* pandora_windows_service.[cc,h], pandora_strutils.[cc,h],
|
||||
windows/pandora_windows_infp.[cc,h], ssh/pandora_ssh_test.[cc,h]:
|
||||
Added documentation comments.
|
||||
|
||||
* ssh/pandora_ssh_client.[cc,h]:Added documentation comments. Removed
|
||||
old method to connect with user and password. Style correction.
|
||||
|
||||
* misc/pandora_file.[cc,h]: Added documentation comments. Renamed some
|
||||
parameters.
|
||||
|
||||
* modules/pandora_module.[cc,h]: Added documentation comments. Put a
|
||||
name to the enumerators. Added a new class to agroupate all exceptions
|
||||
produced by Pandora_Module child class objects. Changed visibility of
|
||||
some attributes. Added some new methods and renamed others.
|
||||
|
||||
* modules/pandora_module_cpuusage.[cc,h],
|
||||
modules/pandora_module_exec.[cc,h],
|
||||
modules/pandora_module_freememory.[cc,h],
|
||||
modules/pandora_module_freedisk.[cc,h], modules/pandora_module_proc.[cc,h],
|
||||
modules/pandora_module_service.[cc,h]: Added documentation comments.
|
||||
Some changes to adapt the objects to the Pandora_Module changes.
|
||||
|
||||
* modules/pandora_module_list.[cc,h]: Added documentation comments.
|
||||
Some changes to adapt the objects to the Pandora_Module changes. Added
|
||||
to Pandora_Modules namespace.
|
||||
|
||||
* windows/pandora_windows_wmi.[cc,h]: Added documentation comments.
|
||||
Renamed Pandora_Wmi_Error to Pandora_Wmi_Exception.
|
||||
|
||||
* windows_service.[cc,h]: Added documentation comments. Changed
|
||||
visibility of some attributes. Style correction.
|
||||
|
||||
2006-07-17 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* main.cc: Added "--help" option.
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
# Doxyfile 0.1
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# General configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
PROJECT_NAME = pandora-agent-win32
|
||||
PROJECT_NUMBER = @VERSION@
|
||||
OUTPUT_DIRECTORY = doc/api
|
||||
OUTPUT_LANGUAGE = English
|
||||
EXTRACT_ALL = NO
|
||||
EXTRACT_PRIVATE = NO
|
||||
EXTRACT_STATIC = NO
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
HIDE_UNDOC_MEMBERS = YES
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
FULL_PATH_NAMES = NO
|
||||
STRIP_FROM_PATH =
|
||||
INTERNAL_DOCS = NO
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
CASE_SENSE_NAMES = YES
|
||||
SHORT_NAMES = NO
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
JAVADOC_AUTOBRIEF = YES
|
||||
INHERIT_DOCS = YES
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
TAB_SIZE = 8
|
||||
GENERATE_TODOLIST = YES
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = YES
|
||||
ALIASES =
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
SHOW_USED_FILES = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to warning and progress messages
|
||||
#---------------------------------------------------------------------------
|
||||
QUIET = YES
|
||||
WARNINGS = NO
|
||||
WARN_IF_UNDOCUMENTED = NO
|
||||
WARN_FORMAT =
|
||||
WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = @top_srcdir@/
|
||||
FILE_PATTERNS = *.cc *.h
|
||||
RECURSIVE = YES
|
||||
EXCLUDE = ssh/libssh2 tinyxml windows/wmi
|
||||
|
||||
# If the value of the INPUT tag contains directories, you can use the
|
||||
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
|
||||
# certain files from those directories.
|
||||
|
||||
EXCLUDE_PATTERNS = Makefile.* ChangeLog CHANGES CHANGES.* README \
|
||||
README.* *.png AUTHORS DESIGN DESIGN.* *.desktop \
|
||||
DESKTOP* COMMENTS HOWTO magic NOTES TODO THANKS \
|
||||
|
||||
|
||||
# The EXAMPLE_PATH tag can be used to specify one or more files or
|
||||
# directories that contain example code fragments that are included (see
|
||||
# the \include command).
|
||||
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS =
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to source browsing
|
||||
#---------------------------------------------------------------------------
|
||||
SOURCE_BROWSER = YES
|
||||
INLINE_SOURCES = NO
|
||||
REFERENCED_BY_RELATION = YES
|
||||
REFERENCES_RELATION = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
ALPHABETICAL_INDEX = NO
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the HTML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_HTML = YES
|
||||
HTML_OUTPUT =
|
||||
HTML_HEADER =
|
||||
HTML_FOOTER =
|
||||
HTML_STYLESHEET =
|
||||
HTML_ALIGN_MEMBERS = YES
|
||||
GENERATE_HTMLHELP = NO
|
||||
GENERATE_CHI = NO
|
||||
BINARY_TOC = NO
|
||||
TOC_EXPAND = NO
|
||||
DISABLE_INDEX = NO
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
GENERATE_TREEVIEW = NO
|
||||
TREEVIEW_WIDTH = 250
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_LATEX = NO
|
||||
LATEX_OUTPUT =
|
||||
COMPACT_LATEX = NO
|
||||
PAPER_TYPE = a4wide
|
||||
EXTRA_PACKAGES =
|
||||
LATEX_HEADER =
|
||||
PDF_HYPERLINKS = NO
|
||||
USE_PDFLATEX = NO
|
||||
LATEX_BATCHMODE = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_RTF = NO
|
||||
RTF_OUTPUT =
|
||||
COMPACT_RTF = NO
|
||||
RTF_HYPERLINKS = NO
|
||||
RTF_STYLESHEET_FILE =
|
||||
RTF_EXTENSIONS_FILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the man page output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_MAN = YES
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_LINKS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the XML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_XML = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the preprocessor
|
||||
#---------------------------------------------------------------------------
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = YES
|
||||
EXPAND_ONLY_PREDEF = YES
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED = "PANDORA_BEGIN_DECLS=" \
|
||||
"PANDORA_END_DECLS=" \
|
||||
"DOXYGEN_SHOULD_SKIP_THIS" \
|
||||
"_PANDORA_DEFINE_GLOBAL_LOCK(name)=" \
|
||||
"_PANDORA_GNUC_PRINTF(from,to)="
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::addtions related to external references
|
||||
#---------------------------------------------------------------------------
|
||||
TAGFILES =
|
||||
GENERATE_TAGFILE =
|
||||
ALLEXTERNALS = NO
|
||||
PERL_PATH =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = YES
|
||||
HAVE_DOT = YES
|
||||
CLASS_GRAPH = YES
|
||||
COLLABORATION_GRAPH = YES
|
||||
TEMPLATE_RELATIONS = YES
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
INCLUDE_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
DOT_PATH =
|
||||
DOTFILE_DIRS =
|
||||
MAX_DOT_GRAPH_WIDTH = 640
|
||||
MAX_DOT_GRAPH_HEIGHT = 1024
|
||||
GENERATE_LEGEND = YES
|
||||
DOT_CLEANUP = YES
|
||||
DOT_IMAGE_FORMAT = png
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::addtions related to the search engine
|
||||
#---------------------------------------------------------------------------
|
||||
SEARCHENGINE = NO
|
|
@ -0,0 +1,43 @@
|
|||
#! /bin/sh
|
||||
|
||||
# $Id: autogen.sh,v 1.4 2002/12/02 01:39:49 murrayc Exp $
|
||||
#
|
||||
# Copyright (c) 2002 Daniel Elstner <daniel.elstner@gmx.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License VERSION 2 as
|
||||
# published by the Free Software Foundation. You are not allowed to
|
||||
# use any other version of the license; unless you got the explicit
|
||||
# permission from the author to do so.
|
||||
#
|
||||
# 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
|
||||
|
||||
dir=`echo "$0" | sed 's,[^/]*$,,'`
|
||||
test "x${dir}" = "x" && dir='.'
|
||||
|
||||
if test "x`cd "${dir}" 2>/dev/null && pwd`" != "x`pwd`"
|
||||
then
|
||||
echo "This script must be executed directly from the source directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f config.cache acconfig.h
|
||||
|
||||
echo "- Running aclocal." && \
|
||||
aclocal && \
|
||||
echo "- Running autoconf." && \
|
||||
autoconf && \
|
||||
echo "- Running automake." && \
|
||||
automake --add-missing --gnu && \
|
||||
echo && \
|
||||
./configure "$@" && exit 0
|
||||
|
||||
exit 1
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
AC_PREREQ(2.59)
|
||||
|
||||
AC_INIT([pandora-agent-win32], [1.0.0])
|
||||
|
||||
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
|
||||
|
||||
AC_OUTPUT([
|
||||
Doxyfile
|
||||
Makefile
|
||||
])
|
|
@ -44,19 +44,25 @@ main (int argc, char *argv[]) {
|
|||
pos = aux.rfind ("\\");
|
||||
aux.erase (pos + 1);
|
||||
Pandora::setPandoraInstallDir (aux);
|
||||
|
||||
|
||||
/* Check the parameters */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (_stricmp(argv[i], SERVICE_INSTALL_CMDLINE_PARAM) == 0) {
|
||||
/* Install parameter */
|
||||
service->install (Pandora::getPandoraInstallPath ().c_str ());
|
||||
|
||||
delete service;
|
||||
|
||||
return 0;
|
||||
} else if (_stricmp(argv[i], SERVICE_UNINSTALL_CMDLINE_PARAM) == 0) {
|
||||
/* Uninstall parameter */
|
||||
service->uninstall ();
|
||||
|
||||
delete service;
|
||||
|
||||
return 0;
|
||||
} else if (_stricmp(argv[i], SSH_TEST_CMDLINE_PARAM) == 0) {
|
||||
/* SSH test parameter */
|
||||
SSH::Pandora_SSH_Test ssh_test;
|
||||
|
||||
delete service;
|
||||
|
@ -66,24 +72,33 @@ main (int argc, char *argv[]) {
|
|||
} catch (Pandora_Exception e) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
|
||||
/* Help parameter */
|
||||
cout << "Usage: " << argv[0] << " [OPTION]" << endl << endl;
|
||||
cout << "Available options are:" << endl;
|
||||
cout << "\t" << SERVICE_INSTALL_CMDLINE_PARAM << ": Install the Pandora Agent service." << endl;
|
||||
cout << "\t" << SERVICE_UNINSTALL_CMDLINE_PARAM << ": Uninstall the Pandora Agent service." << endl;
|
||||
cout << "\t" << SSH_TEST_CMDLINE_PARAM << ": Test the SSH Pandora Agent configuration." << endl;
|
||||
cout << "\t" << SERVICE_INSTALL_CMDLINE_PARAM;
|
||||
cout << ": Install the Pandora Agent service." << endl;
|
||||
cout << "\t" << SERVICE_UNINSTALL_CMDLINE_PARAM;
|
||||
cout << ": Uninstall the Pandora Agent service." << endl;
|
||||
cout << "\t" << SSH_TEST_CMDLINE_PARAM;
|
||||
cout << ": Test the SSH Pandora Agent configuration." << endl;
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
cout << "Usage: " << argv[0] << " [" << SERVICE_INSTALL_CMDLINE_PARAM
|
||||
<< "] [" << SERVICE_UNINSTALL_CMDLINE_PARAM << "]" << endl;
|
||||
cerr << "Run " << argv[0] << "with " << HELP_CMDLINE_PARAM << " parameter for more info." << endl;
|
||||
/* No parameter recognized */
|
||||
cout << "Usage: " << argv[0] << " [" << SERVICE_INSTALL_CMDLINE_PARAM;
|
||||
cout << "] [" << SERVICE_UNINSTALL_CMDLINE_PARAM << "]" << endl;
|
||||
cout << "Run " << argv[0] << "with " << HELP_CMDLINE_PARAM;
|
||||
cout << " parameter for more info." << endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
service->run ();
|
||||
|
||||
delete service;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,10 +25,20 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Reads a file and returns its content.
|
||||
*
|
||||
* @param filepath Path of the file to read.
|
||||
*
|
||||
* @return File content.
|
||||
*
|
||||
* @exception File_Not_Found throwed if the path is incorrect or the
|
||||
* file does not exists or could not be opened.
|
||||
**/
|
||||
string
|
||||
Pandora_File::readFile (const string filename) {
|
||||
Pandora_File::readFile (const string filepath) {
|
||||
string line, result;
|
||||
ifstream myfile (filename.c_str ());
|
||||
ifstream myfile (filepath.c_str ());
|
||||
|
||||
if (! myfile.is_open ()) {
|
||||
throw File_Not_Found ();
|
||||
|
@ -44,16 +54,32 @@ Pandora_File::readFile (const string filename) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a file from a directory.
|
||||
*
|
||||
* @param filepath Path of the file to delete.
|
||||
*
|
||||
* @exception Delete_Error if the file could not be deleted.
|
||||
*/
|
||||
void
|
||||
Pandora_File::removeFile (const string filename) {
|
||||
if (remove (filename.c_str ()) == -1) {
|
||||
Pandora_File::removeFile (const string filepath) {
|
||||
if (remove (filepath.c_str ()) == -1) {
|
||||
throw Delete_Error ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data into a text file.
|
||||
*
|
||||
* @param filepath Path of the file to write in.
|
||||
* @param data Data to be written.
|
||||
*
|
||||
* @exception File_Not_Found throwed if the path is incorrect or the
|
||||
* file does not exists or could not be opened.
|
||||
*/
|
||||
void
|
||||
Pandora_File::writeFile (const string filename, const string data) {
|
||||
ofstream file (filename.c_str ());
|
||||
Pandora_File::writeFile (const string filepath, const string data) {
|
||||
ofstream file (filepath.c_str ());
|
||||
|
||||
if (! file.is_open ()) {
|
||||
throw File_Not_Found ();
|
||||
|
|
|
@ -26,13 +26,30 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* File operations.
|
||||
*/
|
||||
namespace Pandora_File {
|
||||
class File_Not_Found : Pandora::Pandora_Exception {
|
||||
/**
|
||||
* File super-class exception.
|
||||
*/
|
||||
class File_Exception : Pandora::Pandora_Exception {
|
||||
};
|
||||
|
||||
class Delete_Error : Pandora::Pandora_Exception {
|
||||
|
||||
/**
|
||||
* Exception throwed when a file could not be found when doing
|
||||
* a file operation.
|
||||
*/
|
||||
class File_Not_Found : Pandora_File::File_Exception {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Exception throwed when a file could not be deleted on a delete
|
||||
* operation.
|
||||
*/
|
||||
class Delete_Error : Pandora_File::File_Exception {
|
||||
};
|
||||
|
||||
string readFile (const string filename);
|
||||
void removeFile (const string filename);
|
||||
void writeFile (const string filename, const string data);
|
||||
|
|
|
@ -26,6 +26,13 @@ using namespace Pandora;
|
|||
using namespace Pandora_Modules;
|
||||
using namespace Pandora_Strutils;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module.
|
||||
*
|
||||
* Initializes all attributes. The default interval is set to 1 loop.
|
||||
*
|
||||
* @param name Module name.
|
||||
*/
|
||||
Pandora_Module::Pandora_Module (string name) {
|
||||
this->module_name = name;
|
||||
this->executions = 0;
|
||||
|
@ -36,11 +43,23 @@ Pandora_Module::Pandora_Module (string name) {
|
|||
this->has_limits = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual destructor of Pandora_Module.
|
||||
*
|
||||
* Should be redefined by child classes.
|
||||
*/
|
||||
Pandora_Module::~Pandora_Module () {
|
||||
}
|
||||
|
||||
int
|
||||
Pandora_Module::getModuleType (string type) {
|
||||
/**
|
||||
* Get the Module_Type from a string type.
|
||||
*
|
||||
* @param type String type.
|
||||
*
|
||||
* @return The Module_Type which represents the type.
|
||||
*/
|
||||
Module_Type
|
||||
Pandora_Module::parseModuleTypeFromString (string type) {
|
||||
if (type == module_generic_data_str) {
|
||||
return TYPE_GENERIC_DATA;
|
||||
} else if (type == module_generic_data_inc_str) {
|
||||
|
@ -54,26 +73,104 @@ Pandora_Module::getModuleType (string type) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Module_Kind from a string Kind.
|
||||
*
|
||||
* @param kind String Kind.
|
||||
*
|
||||
* @return The Module_Kind which represents the Kind.
|
||||
*/
|
||||
Module_Kind
|
||||
Pandora_Module::parseModuleKindFromString (string kind) {
|
||||
if (kind == module_exec_str) {
|
||||
return MODULE_EXEC;
|
||||
} else if (kind == module_proc_str) {
|
||||
return MODULE_PROC;
|
||||
} else if (kind == module_service_str) {
|
||||
return MODULE_SERVICE;
|
||||
} else if (kind == module_freedisk_str) {
|
||||
return MODULE_FREEDISK;
|
||||
} else if (kind == module_freememory_str) {
|
||||
return MODULE_FREEMEMORY;
|
||||
} else if (kind == module_cpuusage_str) {
|
||||
return MODULE_CPUUSAGE;
|
||||
} else {
|
||||
return MODULE_0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the module.
|
||||
*
|
||||
* @return The name of the module.
|
||||
*/
|
||||
string
|
||||
Pandora_Module::getName () const {
|
||||
return this->module_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description of the module.
|
||||
*
|
||||
* @return The module description.
|
||||
*/
|
||||
string
|
||||
Pandora_Module::getDescription () const {
|
||||
return this->module_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the module type in a human readable string.
|
||||
*
|
||||
* @return The module type..
|
||||
*/
|
||||
string
|
||||
Pandora_Module::getTypeString () const {
|
||||
return this->module_type_str;
|
||||
}
|
||||
|
||||
int
|
||||
/**
|
||||
* Get the module type in a integer value.
|
||||
*
|
||||
* @return The module type in a integer value.
|
||||
*/
|
||||
Module_Type
|
||||
Pandora_Module::getTypeInt () const {
|
||||
return this->module_type;
|
||||
}
|
||||
|
||||
int
|
||||
/**
|
||||
* Get the kind of the module in a integer_value.
|
||||
*
|
||||
* @return The module kind in a integer value.
|
||||
*/
|
||||
Module_Kind
|
||||
Pandora_Module::getModuleKind () const {
|
||||
return this->module_kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the module in a integer_value.
|
||||
*
|
||||
* @return The module type in a integer value.
|
||||
*/
|
||||
Module_Type
|
||||
Pandora_Module::getModuleType () const {
|
||||
return this->module_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the module output.
|
||||
*
|
||||
* After running the module, this function will return the output,
|
||||
* based on the module_type and the interval.
|
||||
*
|
||||
* @return The output in a string.
|
||||
*
|
||||
* @exception Output_Error Throwed if the module_type is not correct.
|
||||
* @exception Value_Error Throwed when the output is not in
|
||||
* the interval range.
|
||||
*/
|
||||
string
|
||||
Pandora_Module::getOutput () const {
|
||||
switch (this->module_type) {
|
||||
|
@ -90,7 +187,7 @@ Pandora_Module::getOutput () const {
|
|||
|
||||
if (this->has_limits) {
|
||||
if (value >= this->max || value <= this->min) {
|
||||
throw Interval_Error ();
|
||||
throw Value_Error ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,6 +197,16 @@ Pandora_Module::getOutput () const {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the module and generates the output.
|
||||
*
|
||||
* It is used by the child classes to check the execution interval
|
||||
* value and increment the executions variable.
|
||||
*
|
||||
* @exception Interval_Not_Fulfilled Throwed when the execution
|
||||
* interval value indicates that the module doesn't have
|
||||
* to execute.
|
||||
*/
|
||||
void
|
||||
Pandora_Module::run () {
|
||||
|
||||
|
@ -120,6 +227,23 @@ Pandora_Module::run () {
|
|||
has_output = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the XML output of the value.
|
||||
*
|
||||
* The output is a element of the TinyXML library. A sample output of
|
||||
* a module is:
|
||||
* @verbatim
|
||||
<module>
|
||||
<name>Conexiones abiertas</name>
|
||||
<type>generic_data</type>
|
||||
<data>5</data>
|
||||
<description>Conexiones abiertas</description>
|
||||
</module>
|
||||
@endverbatim
|
||||
*
|
||||
* @return A pointer to the TiXmlElement if successful which has to be
|
||||
* freed by the caller. NULL if the XML could not be created.
|
||||
*/
|
||||
TiXmlElement *
|
||||
Pandora_Module::getXml () {
|
||||
string data;
|
||||
|
@ -141,7 +265,7 @@ Pandora_Module::getXml () {
|
|||
this->module_name.c_str ());
|
||||
|
||||
return NULL;
|
||||
} catch (Interval_Error e) {
|
||||
} catch (Value_Error e) {
|
||||
pandoraLog ("The returned value was not in the interval on module %s",
|
||||
this->module_name.c_str ());
|
||||
|
||||
|
@ -183,29 +307,69 @@ Pandora_Module::getXml () {
|
|||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the max value the module can have.
|
||||
*
|
||||
* The range is closed, so the value is included.
|
||||
*
|
||||
* @param value Max value to set.
|
||||
*/
|
||||
void
|
||||
Pandora_Module::setMax (int value) {
|
||||
this->has_limits = true;
|
||||
this->max = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the min value the module can have.
|
||||
*
|
||||
* The range is closed, so the value is included.
|
||||
*
|
||||
* @param value Min value to set.
|
||||
*/
|
||||
void
|
||||
Pandora_Module::setMin (int value) {
|
||||
this->has_limits = true;
|
||||
this->min = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the module type from a string type.
|
||||
*
|
||||
* @param type String type.
|
||||
*/
|
||||
void
|
||||
Pandora_Module::setType (string type) {
|
||||
this->module_type_str = type;
|
||||
this->module_type = getModuleType (type);
|
||||
this->module_type = parseModuleTypeFromString (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the module kind from a string kind.
|
||||
*
|
||||
* @param kind String kind.
|
||||
*/
|
||||
void
|
||||
Pandora_Module::setKind (string kind) {
|
||||
this->module_kind_str = kind;
|
||||
this->module_kind = parseModuleKindFromString (kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the interval execution.
|
||||
*
|
||||
* @param interval Interval between executions.
|
||||
*/
|
||||
void
|
||||
Pandora_Module::setInterval (int interval) {
|
||||
this->module_interval = interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the module description.
|
||||
*
|
||||
* @param description Description of the module.
|
||||
*/
|
||||
void
|
||||
Pandora_Module::setDescription (string description) {
|
||||
this->module_description = description;
|
||||
|
|
|
@ -26,30 +26,47 @@
|
|||
#include <list>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* Definition of Pandora modules.
|
||||
*/
|
||||
namespace Pandora_Modules {
|
||||
|
||||
enum {
|
||||
TYPE_0,
|
||||
TYPE_GENERIC_DATA,
|
||||
TYPE_GENERIC_DATA_INC,
|
||||
TYPE_GENERIC_PROC,
|
||||
TYPE_GENERIC_DATA_STRING
|
||||
};
|
||||
/**
|
||||
* Defines the type of the module.
|
||||
*
|
||||
* The type of a module is the value type the module can have.
|
||||
*/
|
||||
typedef enum {
|
||||
TYPE_0, /**< Invalid value */
|
||||
TYPE_GENERIC_DATA, /**< The value is an integer */
|
||||
TYPE_GENERIC_DATA_INC, /**< The value is an integer with
|
||||
* incremental diferences */
|
||||
TYPE_GENERIC_PROC, /**< The value is a 0 or a 1 */
|
||||
TYPE_GENERIC_DATA_STRING /**< The value is a string */
|
||||
} Module_Type;
|
||||
|
||||
const string module_generic_data_str = "generic_data";
|
||||
const string module_generic_data_inc_str = "generic_data_inc";
|
||||
const string module_generic_proc_str = "generic_proc";
|
||||
const string module_generic_data_string_str = "generic_data_string";
|
||||
|
||||
enum {
|
||||
MODULE_0,
|
||||
MODULE_EXEC,
|
||||
MODULE_PROC,
|
||||
MODULE_SERVICE,
|
||||
MODULE_FREEDISK,
|
||||
MODULE_CPUUSAGE,
|
||||
MODULE_FREEMEMORY
|
||||
};
|
||||
/**
|
||||
* Defines the kind of the module.
|
||||
*
|
||||
* The kind of a module is the work the module does.
|
||||
*/
|
||||
typedef enum {
|
||||
MODULE_0, /**< Invalid kind */
|
||||
MODULE_EXEC, /**< The module run a custom command */
|
||||
MODULE_PROC, /**< The module checks for a running
|
||||
* process */
|
||||
MODULE_SERVICE, /**< The module checks for a running
|
||||
* service */
|
||||
MODULE_FREEDISK, /**< The module checks the free */
|
||||
MODULE_CPUUSAGE, /**< The module checks the CPU usage */
|
||||
MODULE_FREEMEMORY /**< The module checks the amount of
|
||||
* freememory in the system */
|
||||
} Module_Kind;
|
||||
|
||||
const string module_exec_str = "module_exec";
|
||||
const string module_proc_str = "module_proc";
|
||||
|
@ -58,49 +75,89 @@ namespace Pandora_Modules {
|
|||
const string module_freememory_str = "module_freememory";
|
||||
const string module_cpuusage_str = "module_cpuusage";
|
||||
|
||||
class Output_Error : public Pandora::Pandora_Exception { };
|
||||
class Interval_Error : public Pandora::Pandora_Exception { };
|
||||
class Interval_Not_Fulfilled : public Pandora::Pandora_Exception { };
|
||||
|
||||
/**
|
||||
* Pandora module super-class exception.
|
||||
*/
|
||||
class Module_Exception : public Pandora::Pandora_Exception { };
|
||||
|
||||
/**
|
||||
* An error happened with the module output.
|
||||
*/
|
||||
class Output_Error : public Pandora_Modules::Module_Exception { };
|
||||
|
||||
/**
|
||||
* The module value is not correct, usually beacause of the limits.
|
||||
*/
|
||||
class Value_Error : public Pandora_Modules::Module_Exception { };
|
||||
|
||||
/**
|
||||
* The module does not satisfy its interval.
|
||||
*/
|
||||
class Interval_Not_Fulfilled : public Pandora_Modules::Module_Exception { };
|
||||
|
||||
/**
|
||||
* Pandora module super-class.
|
||||
*
|
||||
* Every defined module must inherit of this class.
|
||||
*/
|
||||
class Pandora_Module {
|
||||
private:
|
||||
int module_interval;
|
||||
int executions;
|
||||
int max, min;
|
||||
bool has_limits;
|
||||
string module_type_str;
|
||||
Module_Type module_type;
|
||||
string module_kind_str;
|
||||
Module_Kind module_kind;
|
||||
protected:
|
||||
string module_name;
|
||||
string module_type_str;
|
||||
int module_type;
|
||||
string module_kind_str;
|
||||
string module_description;
|
||||
int module_kind;
|
||||
int module_interval;
|
||||
int executions;
|
||||
string output;
|
||||
int max, min;
|
||||
bool has_limits;
|
||||
bool has_output;
|
||||
/**
|
||||
* Module output generated at execution.
|
||||
*/
|
||||
string output;
|
||||
/**
|
||||
* Indicates if the module generated output in
|
||||
* his last execution.
|
||||
*/
|
||||
bool has_output;
|
||||
/**
|
||||
* The name of the module.
|
||||
*/
|
||||
string module_name;
|
||||
/**
|
||||
* The description of the module.
|
||||
*/
|
||||
string module_description;
|
||||
public:
|
||||
Pandora_Module (string name);
|
||||
virtual ~Pandora_Module ();
|
||||
Pandora_Module (string name);
|
||||
virtual ~Pandora_Module ();
|
||||
|
||||
static Module_Type
|
||||
parseModuleTypeFromString (string type);
|
||||
|
||||
static Module_Kind
|
||||
parseModuleKindFromString (string kind);
|
||||
|
||||
void setInterval (int interval);
|
||||
|
||||
static int getModuleType (string type);
|
||||
TiXmlElement *getXml ();
|
||||
|
||||
void setInterval (int interval);
|
||||
virtual void run ();
|
||||
|
||||
/* Get the XML output of the agent. */
|
||||
TiXmlElement *getXml ();
|
||||
virtual string getOutput () const;
|
||||
|
||||
/* Execute the agent */
|
||||
virtual void run ();
|
||||
string getName () const;
|
||||
string getDescription () const;
|
||||
string getTypeString () const;
|
||||
Module_Type getTypeInt () const;
|
||||
Module_Type getModuleType () const;
|
||||
Module_Kind getModuleKind () const;
|
||||
|
||||
virtual string getOutput () const;
|
||||
|
||||
string getName () const;
|
||||
string getTypeString () const;
|
||||
int getTypeInt () const;
|
||||
int getModuleKind () const;
|
||||
|
||||
void setType (string type);
|
||||
void setDescription (string description);
|
||||
void setMax (int value);
|
||||
void setMin (int value);
|
||||
void setType (string type);
|
||||
void setKind (string kind);
|
||||
void setDescription (string description);
|
||||
void setMax (int value);
|
||||
void setMin (int value);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -27,13 +27,18 @@ using namespace Pandora;
|
|||
using namespace Pandora_Modules;
|
||||
using namespace Pandora_Strutils;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module_Cpuusage object.
|
||||
*
|
||||
* @param name Module name.
|
||||
* @param cpu_id CPU id to control. It's 0 in monoprocessor systems.
|
||||
*/
|
||||
Pandora_Module_Cpuusage::Pandora_Module_Cpuusage (string name, int cpu_id)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
this->cpu_id = cpu_id;
|
||||
|
||||
this->module_kind_str = module_cpuusage_str;
|
||||
this->module_kind = MODULE_CPUUSAGE;
|
||||
this->setKind (module_cpuusage_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -49,8 +54,8 @@ Pandora_Module_Cpuusage::run () {
|
|||
try {
|
||||
res = Pandora_Wmi::getCpuUsagePercentage (this->cpu_id);
|
||||
|
||||
output = inttostr (res);
|
||||
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
|
||||
this->output = inttostr (res);
|
||||
} catch (Pandora_Wmi::Pandora_Wmi_Exception e) {
|
||||
this->has_output = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
#include "pandora_module.h"
|
||||
|
||||
namespace Pandora_Modules {
|
||||
/**
|
||||
* Module to retrieve the CPU usage percentage.
|
||||
*/
|
||||
class Pandora_Module_Cpuusage : public Pandora_Module {
|
||||
private:
|
||||
int cpu_id;
|
||||
|
|
|
@ -28,12 +28,17 @@ using namespace Pandora;
|
|||
using namespace Pandora_Strutils;
|
||||
using namespace Pandora_Modules;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module_Exec object.
|
||||
*
|
||||
* @param name Module name
|
||||
* @param exec Command to be executed.
|
||||
*/
|
||||
Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec)
|
||||
: Pandora_Module (name) {
|
||||
this->module_exec = "cmd.exe /c \"" + exec + "\"";
|
||||
|
||||
this->module_kind_str = module_exec_str;
|
||||
this->module_kind = MODULE_EXEC;
|
||||
this->setKind (module_exec_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -48,6 +53,7 @@ Pandora_Module_Exec::run () {
|
|||
try {
|
||||
Pandora_Module::run ();
|
||||
} catch (Interval_Not_Fulfilled e) {
|
||||
this->has_output = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -62,6 +68,7 @@ Pandora_Module_Exec::run () {
|
|||
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
||||
if (job == NULL) {
|
||||
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
|
||||
this->has_output = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -70,6 +77,7 @@ Pandora_Module_Exec::run () {
|
|||
|
||||
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
||||
pandoraLog ("CreatePipe failed. Err: %d", GetLastError ());
|
||||
this->has_output = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -100,6 +108,7 @@ Pandora_Module_Exec::run () {
|
|||
working_dir.c_str (), &si, &pi)) {
|
||||
pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d",
|
||||
this->module_name.c_str (), GetLastError ());
|
||||
this->has_output = false;
|
||||
} else {
|
||||
char buffer[BUFSIZE + 1];
|
||||
unsigned long read, avail;
|
||||
|
@ -123,6 +132,7 @@ Pandora_Module_Exec::run () {
|
|||
|
||||
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
|
||||
this->module_name.c_str (), retval);
|
||||
this->has_output = false;
|
||||
}
|
||||
|
||||
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
#include "pandora_module.h"
|
||||
|
||||
namespace Pandora_Modules {
|
||||
/**
|
||||
* Module to execute a custom command using the Windows command
|
||||
* line.
|
||||
*
|
||||
* Any custom order that want to be executed can be put in
|
||||
* the <code>util</code> directory into the Pandora agent path.
|
||||
*/
|
||||
class Pandora_Module_Exec : public Pandora_Module {
|
||||
private:
|
||||
string module_exec;
|
||||
|
|
|
@ -62,6 +62,14 @@ parseLine (string line, string token) {
|
|||
return retstr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module object based on a string definition.
|
||||
*
|
||||
* @param definition Module definition readed from the configuration file.
|
||||
*
|
||||
* @return A new Pandora_Module object. NULL if the definition is
|
||||
* incorrect.
|
||||
*/
|
||||
Pandora_Module *
|
||||
Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||
list<string> tokens;
|
||||
|
@ -72,6 +80,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
string module_freedisk, module_cpuusage, module_freememory;
|
||||
Pandora_Module *module;
|
||||
bool numeric;
|
||||
Module_Type type;
|
||||
|
||||
module_name = "";
|
||||
module_type = "";
|
||||
|
@ -82,8 +91,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
module_exec = "";
|
||||
module_proc = "";
|
||||
module_service = "";
|
||||
|
||||
|
||||
|
||||
stringtok (tokens, definition, "\n");
|
||||
|
||||
/* Pick the first and the last value of the token list */
|
||||
|
@ -171,8 +179,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
if (module_description != "") {
|
||||
module->setDescription (module_description);
|
||||
}
|
||||
|
||||
switch (Pandora_Module::getModuleType (module_type)) {
|
||||
|
||||
type = Pandora_Module::parseModuleTypeFromString (module_type);
|
||||
switch (type) {
|
||||
case TYPE_GENERIC_DATA:
|
||||
case TYPE_GENERIC_DATA_INC:
|
||||
case TYPE_GENERIC_PROC:
|
||||
|
|
|
@ -28,9 +28,11 @@
|
|||
using namespace std;
|
||||
using namespace Pandora_Modules;
|
||||
|
||||
/**
|
||||
* Factoy to create Pandora_Module objects by parsing a definition.
|
||||
*/
|
||||
namespace Pandora_Module_Factory {
|
||||
Pandora_Module * getModuleFromDefinition (string definition);
|
||||
string getModuleResult (Pandora_Module *module);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,12 @@ using namespace Pandora;
|
|||
using namespace Pandora_Modules;
|
||||
using namespace Pandora_Strutils;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module_Freedisk object.
|
||||
*
|
||||
* @param name Module name.
|
||||
* @param disk_id Logical drive id to be monitorized. Usually it's "C:"
|
||||
*/
|
||||
Pandora_Module_Freedisk::Pandora_Module_Freedisk (string name, string disk_id)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
|
@ -37,8 +43,7 @@ Pandora_Module_Freedisk::Pandora_Module_Freedisk (string name, string 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;
|
||||
this->setKind (module_freedisk_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -54,8 +59,8 @@ Pandora_Module_Freedisk::run () {
|
|||
try {
|
||||
res = Pandora_Wmi::getDiskFreeSpace (this->disk_id);
|
||||
|
||||
output = longtostr (res);
|
||||
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
|
||||
this->output = longtostr (res);
|
||||
} catch (Pandora_Wmi::Pandora_Wmi_Exception e) {
|
||||
this->has_output = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include "pandora_module.h"
|
||||
|
||||
namespace Pandora_Modules {
|
||||
/**
|
||||
* Module to retrieve the free space available in a logical volume
|
||||
* disk.
|
||||
*/
|
||||
class Pandora_Module_Freedisk : public Pandora_Module {
|
||||
private:
|
||||
string disk_id;
|
||||
|
|
|
@ -27,11 +27,15 @@ using namespace Pandora;
|
|||
using namespace Pandora_Modules;
|
||||
using namespace Pandora_Strutils;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module_Freememory object.
|
||||
*
|
||||
* @param name Module name.
|
||||
*/
|
||||
Pandora_Module_Freememory::Pandora_Module_Freememory (string name)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
this->module_kind_str = module_freememory_str;
|
||||
this->module_kind = MODULE_FREEMEMORY;
|
||||
this->setKind (module_freememory_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -47,8 +51,8 @@ Pandora_Module_Freememory::run () {
|
|||
try {
|
||||
res = Pandora_Wmi::getFreememory ();
|
||||
|
||||
output = longtostr (res);
|
||||
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
|
||||
this->output = longtostr (res);
|
||||
} catch (Pandora_Wmi::Pandora_Wmi_Exception e) {
|
||||
this->has_output = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "pandora_module.h"
|
||||
|
||||
namespace Pandora_Modules {
|
||||
/**
|
||||
* Module to retrieve the free memory amount of the system.
|
||||
*/
|
||||
class Pandora_Module_Freememory : public Pandora_Module {
|
||||
public:
|
||||
Pandora_Module_Freememory (string name);
|
||||
|
|
|
@ -29,9 +29,16 @@
|
|||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace Pandora;
|
||||
|
||||
Pandora_Module_List::Pandora_Module_List (string filename) {
|
||||
/**
|
||||
* Read and set a key-value set from a file.
|
||||
*
|
||||
* It parses the file and create a Pandora_Module object with
|
||||
*
|
||||
* @param filename Path to the configuration file that includes the
|
||||
* module definitions.
|
||||
*/
|
||||
Pandora_Modules::Pandora_Module_List::Pandora_Module_List (string filename) {
|
||||
ifstream file (filename.c_str ());
|
||||
string buffer;
|
||||
unsigned int pos;
|
||||
|
@ -74,7 +81,12 @@ Pandora_Module_List::Pandora_Module_List (string filename) {
|
|||
*current = modules->begin ();
|
||||
}
|
||||
|
||||
Pandora_Module_List::~Pandora_Module_List () {
|
||||
/**
|
||||
* Destroy the list.
|
||||
*
|
||||
* Note it also deletes all modules from the list.
|
||||
*/
|
||||
Pandora_Modules::Pandora_Module_List::~Pandora_Module_List () {
|
||||
Pandora_Module *module;
|
||||
std::list<Pandora_Module *>::iterator iter;
|
||||
|
||||
|
@ -93,7 +105,7 @@ Pandora_Module_List::~Pandora_Module_List () {
|
|||
}
|
||||
|
||||
void
|
||||
Pandora_Module_List::parseModuleDefinition (string definition) {
|
||||
Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition) {
|
||||
Pandora_Module *module;
|
||||
Pandora_Module_Exec *module_exec;
|
||||
Pandora_Module_Proc *module_proc;
|
||||
|
@ -144,49 +156,73 @@ Pandora_Module_List::parseModuleDefinition (string definition) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Pandora_Module that is pointed by the internal current pointer.
|
||||
*
|
||||
* @return The current Pandora_Module.
|
||||
*/
|
||||
Pandora_Module *
|
||||
Pandora_Module_List::getCurrentValue () {
|
||||
Pandora_Modules::Pandora_Module_List::getCurrentValue () {
|
||||
return *(*current);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the current pointer to the first element of the list.
|
||||
*/
|
||||
void
|
||||
Pandora_Module_List::goFirst () {
|
||||
Pandora_Modules::Pandora_Module_List::goFirst () {
|
||||
if (modules != NULL) {
|
||||
*current = modules->begin ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the current pointer to the last element of the list.
|
||||
*/
|
||||
void
|
||||
Pandora_Module_List::goLast () {
|
||||
Pandora_Modules::Pandora_Module_List::goLast () {
|
||||
if (modules != NULL) {
|
||||
*current = modules->end ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the current pointer to the next element of the list.
|
||||
*/
|
||||
void
|
||||
Pandora_Module_List::goNext () {
|
||||
Pandora_Modules::Pandora_Module_List::goNext () {
|
||||
if (current != NULL && !isLast ()) {
|
||||
(*current)++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the current pointer to the previous element of the list.
|
||||
*/
|
||||
void
|
||||
Pandora_Module_List::goPrev () {
|
||||
Pandora_Modules::Pandora_Module_List::goPrev () {
|
||||
if (current != NULL && !isFirst ()) {
|
||||
(*current)--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current pointer is the last one of the list.
|
||||
*/
|
||||
bool
|
||||
Pandora_Module_List::isLast () {
|
||||
Pandora_Modules::Pandora_Module_List::isLast () {
|
||||
if (current == NULL || modules == NULL) {
|
||||
return true;
|
||||
}
|
||||
return *current == modules->end ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current pointer is the first one of the list.
|
||||
*/
|
||||
bool
|
||||
Pandora_Module_List::isFirst () {
|
||||
Pandora_Modules::Pandora_Module_List::isFirst () {
|
||||
if (current == NULL || modules == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -28,32 +28,36 @@
|
|||
|
||||
using namespace std;
|
||||
using namespace Pandora;
|
||||
using namespace Pandora_Modules;
|
||||
|
||||
class Pandora_Module_List {
|
||||
protected:
|
||||
list<Pandora_Module *> *modules;
|
||||
list<Pandora_Module *>::iterator *current;
|
||||
private:
|
||||
void parseModuleDefinition (string definition);
|
||||
public:
|
||||
/* Read and set a key-value set from a file. */
|
||||
Pandora_Module_List (string filename);
|
||||
|
||||
~Pandora_Module_List ();
|
||||
|
||||
Pandora_Module * getCurrentValue ();
|
||||
|
||||
/* Move to the first element of the list */
|
||||
void goFirst ();
|
||||
|
||||
/* Move to the last element of the list */
|
||||
void goLast ();
|
||||
void goNext ();
|
||||
void goPrev ();
|
||||
|
||||
bool isLast ();
|
||||
bool isFirst ();
|
||||
};
|
||||
|
||||
namespace Pandora_Modules {
|
||||
/**
|
||||
* Class to handle a list of Pandora_Module objects.
|
||||
*
|
||||
* It provides a set of methods to iterate through the list
|
||||
* by using a internal "current module" pointer.
|
||||
*/
|
||||
class Pandora_Module_List {
|
||||
private:
|
||||
list<Pandora_Module *> *modules;
|
||||
list<Pandora_Module *>::iterator *current;
|
||||
void parseModuleDefinition (string definition);
|
||||
public:
|
||||
Pandora_Module_List (string filename);
|
||||
|
||||
~Pandora_Module_List ();
|
||||
|
||||
Pandora_Module * getCurrentValue ();
|
||||
|
||||
/* Move to the first element of the list */
|
||||
void goFirst ();
|
||||
|
||||
/* Move to the last element of the list */
|
||||
void goLast ();
|
||||
void goNext ();
|
||||
void goPrev ();
|
||||
|
||||
bool isLast ();
|
||||
bool isFirst ();
|
||||
};
|
||||
}
|
||||
#endif /* __PANDORA_MODULE_LIST_H__ */
|
||||
|
|
|
@ -28,6 +28,12 @@ using namespace Pandora;
|
|||
using namespace Pandora_Modules;
|
||||
using namespace Pandora_Strutils;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module_Proc object.
|
||||
*
|
||||
* @param name Module name.
|
||||
* @param process_name Process name to check.
|
||||
*/
|
||||
Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
|
@ -35,8 +41,7 @@ Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
|
|||
transform (process_name.begin (), process_name.end (),
|
||||
this->process_name.begin (), (int (*) (int)) tolower);
|
||||
|
||||
this->module_kind_str = module_proc_str;
|
||||
this->module_kind = MODULE_PROC;
|
||||
this->setKind (module_proc_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -51,5 +56,5 @@ Pandora_Module_Proc::run () {
|
|||
|
||||
res = Pandora_Wmi::isProcessRunning (this->process_name);
|
||||
|
||||
output = inttostr (res);
|
||||
this->output = inttostr (res);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "pandora_module.h"
|
||||
|
||||
namespace Pandora_Modules {
|
||||
/**
|
||||
* Module to check that a process is running on the system.
|
||||
*/
|
||||
class Pandora_Module_Proc : public Pandora_Module {
|
||||
private:
|
||||
string process_name;
|
||||
|
|
|
@ -29,6 +29,12 @@ using namespace Pandora;
|
|||
using namespace Pandora_Modules;
|
||||
using namespace Pandora_Strutils;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_Module_Service object.
|
||||
*
|
||||
* @param name Module name.
|
||||
* @param service_name Service internal name to check.
|
||||
*/
|
||||
Pandora_Module_Service::Pandora_Module_Service (string name, string service_name)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
|
@ -37,8 +43,7 @@ Pandora_Module_Service::Pandora_Module_Service (string name, string service_name
|
|||
transform (service_name.begin (), service_name.end (),
|
||||
this->service_name.begin (), (int (*) (int)) tolower);
|
||||
|
||||
this->module_kind_str = module_service_str;
|
||||
this->module_kind = MODULE_SERVICE;
|
||||
this->setKind (module_service_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -52,5 +57,5 @@ Pandora_Module_Service::run () {
|
|||
}
|
||||
|
||||
res = Pandora_Wmi::isServiceRunning (this->service_name);
|
||||
output = inttostr (res);
|
||||
this->output = inttostr (res);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include "pandora_module.h"
|
||||
|
||||
namespace Pandora_Modules {
|
||||
/**
|
||||
* Module to check that a windows service is running on the
|
||||
* system.
|
||||
*/
|
||||
class Pandora_Module_Service : public Pandora_Module {
|
||||
private:
|
||||
string service_name;
|
||||
|
|
|
@ -37,6 +37,13 @@ string pandora_dir;
|
|||
bool pandora_debug;
|
||||
string pandora_version = PANDORA_VERSION;
|
||||
|
||||
/**
|
||||
* Parses a string and initialize the key and the value.
|
||||
*
|
||||
* The string should be in the format:
|
||||
* - <code>key value</code>
|
||||
* - <code>key "value with blankspaces"</code>
|
||||
*/
|
||||
void
|
||||
Key_Value::parseLine (string str) {
|
||||
unsigned int pos;
|
||||
|
@ -68,11 +75,21 @@ Key_Value::parseLine (string str) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key of the object.
|
||||
*
|
||||
* @return The key
|
||||
*/
|
||||
string
|
||||
Key_Value::getKey () {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the object.
|
||||
*
|
||||
* @return The value
|
||||
*/
|
||||
string
|
||||
Key_Value::getValue () {
|
||||
return value;
|
||||
|
@ -104,6 +121,15 @@ pandoraWriteLog (string filename, string line) {
|
|||
cout << line << endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message in the log file.
|
||||
*
|
||||
* The log file is used to write the output of errors and problems of the
|
||||
* agent.
|
||||
*
|
||||
* @param format String output format.
|
||||
* @param ... Variable argument list
|
||||
*/
|
||||
void
|
||||
Pandora::pandoraLog (char *format, ...) {
|
||||
va_list args;
|
||||
|
@ -116,6 +142,15 @@ Pandora::pandoraLog (char *format, ...) {
|
|||
pandoraWriteLog ("pandora-log.log", (char *) msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message in the debug file.
|
||||
*
|
||||
* The log file is used to write the output of debugging information of the
|
||||
* agent.
|
||||
*
|
||||
* @param format String output format.
|
||||
* @param ... Variable argument list
|
||||
*/
|
||||
void
|
||||
Pandora::pandoraDebug (char *format, ...) {
|
||||
if (pandora_debug) {
|
||||
|
@ -131,38 +166,95 @@ Pandora::pandoraDebug (char *format, ...) {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Secure free of a pointer.
|
||||
*
|
||||
* @param pointer pointer to free.
|
||||
*/
|
||||
void
|
||||
Pandora::pandoraFree (void * e) {
|
||||
if (e != NULL)
|
||||
free (e);
|
||||
Pandora::pandoraFree (void * pointer) {
|
||||
if (pointer != NULL)
|
||||
free (pointer);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the installation directory of the application.
|
||||
*
|
||||
* This directory is the path to the directory which holds
|
||||
* the binary file.
|
||||
*
|
||||
* @param dir The path to the directory.
|
||||
*
|
||||
* @see getPandoraInstallDir
|
||||
*/
|
||||
void
|
||||
Pandora::setPandoraInstallDir (string dir) {
|
||||
pandora_dir = dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the installation directory of the application.
|
||||
*
|
||||
* This directory is the path to the directory which holds
|
||||
* the binary file.
|
||||
*
|
||||
* @return The path to the directory.
|
||||
*
|
||||
* @see setPandoraInstallDir
|
||||
*/
|
||||
string
|
||||
Pandora::getPandoraInstallDir () {
|
||||
return pandora_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the installation path of the application.
|
||||
*
|
||||
* This the complete path to the binary file.
|
||||
*
|
||||
* @param path The path to the binary file.
|
||||
*
|
||||
* @see getPandoraInstallPath
|
||||
*/
|
||||
void
|
||||
Pandora::setPandoraInstallPath (string path) {
|
||||
pandora_path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the installation path of the application.
|
||||
*
|
||||
* This the complete path to the binary file.
|
||||
*
|
||||
* @return The path.
|
||||
*
|
||||
* @see setPandoraInstallPath
|
||||
*/
|
||||
string
|
||||
Pandora::getPandoraInstallPath () {
|
||||
return pandora_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the debug flag.
|
||||
*
|
||||
* If the flag is false output wil be generated.
|
||||
*
|
||||
* @param dbg Turns the debug flag on/off.
|
||||
*
|
||||
* @see pandoraDebug
|
||||
*/
|
||||
void
|
||||
Pandora::setPandoraDebug (bool dbg) {
|
||||
pandora_debug = dbg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of the agent.
|
||||
*
|
||||
* @return The version.
|
||||
*/
|
||||
string
|
||||
Pandora::getPandoraAgentVersion () {
|
||||
return pandora_version;
|
||||
|
|
|
@ -29,12 +29,18 @@ using namespace std;
|
|||
|
||||
#define PANDORA_DEBUG 1
|
||||
|
||||
/**
|
||||
* Main application.
|
||||
*/
|
||||
namespace Pandora {
|
||||
|
||||
/**
|
||||
* A Key_Value object holds a relation between a value and a
|
||||
* unique key value.
|
||||
*/
|
||||
class Key_Value {
|
||||
protected:
|
||||
string key;
|
||||
string value;
|
||||
private:
|
||||
string key;
|
||||
string value;
|
||||
public:
|
||||
void parseLine (string str);
|
||||
string getKey ();
|
||||
|
@ -45,7 +51,7 @@ namespace Pandora {
|
|||
const char * const name = "PandoraAgent";
|
||||
const char * const display_name = "Pandora agent";
|
||||
const char * const description = "The Pandora Agent service";
|
||||
|
||||
|
||||
void setPandoraInstallDir (string dir);
|
||||
string getPandoraInstallDir ();
|
||||
void setPandoraInstallPath (string path);
|
||||
|
@ -56,7 +62,13 @@ namespace Pandora {
|
|||
void pandoraDebug (char *format, ...);
|
||||
void pandoraLog (char *format, ...);
|
||||
void pandoraFree (void * e);
|
||||
|
||||
|
||||
/**
|
||||
* Super-class exception.
|
||||
*
|
||||
* Other exceptions generated in the application should inherate from
|
||||
* this class. This allow a easier handling on throw and catch blocks.
|
||||
*/
|
||||
class Pandora_Exception { };
|
||||
}
|
||||
|
||||
|
|
|
@ -23,10 +23,22 @@
|
|||
#include "pandora.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Pandora;
|
||||
|
||||
#define MAX_KEYS 100
|
||||
|
||||
Pandora_Agent_Conf::Pandora_Agent_Conf (string filename) {
|
||||
/**
|
||||
* Creates a new Pandora_Agent_Conf.
|
||||
*
|
||||
* It parses the filename and initialize the internal structures
|
||||
* of configuration values. The configuration file consist of a number of
|
||||
* lines of some of these forms:
|
||||
* - <code>name value</code>
|
||||
* - <code>name "value with blankspaces"</code>
|
||||
*
|
||||
* @param filename Configuration file to open.
|
||||
*/
|
||||
Pandora::Pandora_Agent_Conf::Pandora_Agent_Conf (string filename) {
|
||||
ifstream file (filename.c_str ());
|
||||
string buffer;
|
||||
unsigned int pos;
|
||||
|
@ -56,12 +68,26 @@ Pandora_Agent_Conf::Pandora_Agent_Conf (string filename) {
|
|||
file.close ();
|
||||
}
|
||||
|
||||
Pandora_Agent_Conf::~Pandora_Agent_Conf () {
|
||||
delete key_values;
|
||||
/**
|
||||
* Destroy a Pandora_Agent_Conf object.
|
||||
*/
|
||||
Pandora::Pandora_Agent_Conf::~Pandora_Agent_Conf () {
|
||||
delete key_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries for a configuration value.
|
||||
*
|
||||
* This method search in the key_values attribute for a
|
||||
* configuration value which match the key supplied.
|
||||
*
|
||||
* @param key Key to look for.
|
||||
*
|
||||
* @return The value of the configuration key looked for.
|
||||
* If it could not be found then an empty string is returned.
|
||||
*/
|
||||
string
|
||||
Pandora_Agent_Conf::getValue (const string key) {
|
||||
Pandora::Pandora_Agent_Conf::getValue (const string key) {
|
||||
std::list<Key_Value>::iterator i = key_values->begin ();
|
||||
|
||||
while (i != key_values->end ()) {
|
||||
|
|
|
@ -26,19 +26,25 @@
|
|||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Pandora;
|
||||
|
||||
class Pandora_Agent_Conf {
|
||||
protected:
|
||||
list<Key_Value> *key_values; /* Key-value list */
|
||||
public:
|
||||
/* Read and set a key-value set from a file. */
|
||||
Pandora_Agent_Conf (string filename);
|
||||
|
||||
~Pandora_Agent_Conf ();
|
||||
|
||||
/* Get the value of a key from a key-value set. */
|
||||
string getValue (const string key);
|
||||
};
|
||||
namespace Pandora {
|
||||
/**
|
||||
* Agent main configuration class.
|
||||
*
|
||||
* Stores a list of Key_Value objects with the agent configuration.
|
||||
* It parses a configuration file and supplies a function to get the
|
||||
* configuration values.
|
||||
*/
|
||||
class Pandora_Agent_Conf {
|
||||
private:
|
||||
list<Key_Value> *key_values;
|
||||
public:
|
||||
Pandora_Agent_Conf (string filename);
|
||||
|
||||
~Pandora_Agent_Conf ();
|
||||
|
||||
string getValue (const string key);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __BABEL_AGENT_CONF_H__ */
|
||||
#endif /* __PANDORA_AGENT_CONF_H__ */
|
||||
|
|
|
@ -27,6 +27,15 @@
|
|||
|
||||
using namespace Pandora;
|
||||
|
||||
/**
|
||||
* Removes heading and tailing blank spaces from a string.
|
||||
*
|
||||
* The blank spaces removed are " ", "\t", "\r" and "\n".
|
||||
*
|
||||
* @param str String to be trimmed.
|
||||
*
|
||||
* @return The trimmed string.
|
||||
*/
|
||||
string
|
||||
Pandora_Strutils::trim (const string str) {
|
||||
char * delims = " \t\r\n";
|
||||
|
@ -47,11 +56,25 @@ Pandora_Strutils::trim (const string str) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an integer variable into a string.
|
||||
*
|
||||
* @param i Integer to transform.
|
||||
*
|
||||
* @return A string with the integer value.
|
||||
*/
|
||||
string
|
||||
Pandora_Strutils::inttostr (const int i) {
|
||||
return longtostr (i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a long variable into a string.
|
||||
*
|
||||
* @param i Long variable to transform
|
||||
*
|
||||
* @return A string with the long value.
|
||||
*/
|
||||
string
|
||||
Pandora_Strutils::longtostr (const long i) {
|
||||
std::ostringstream o;
|
||||
|
@ -61,6 +84,13 @@ Pandora_Strutils::longtostr (const long i) {
|
|||
return o.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a long variable into hexadecimal.
|
||||
*
|
||||
* @param i Long variable to transform.
|
||||
*
|
||||
* @return The hexadecimal value of the long variable.
|
||||
*/
|
||||
string
|
||||
Pandora_Strutils::longtohex (const long i) {
|
||||
std::ostringstream o;
|
||||
|
@ -69,6 +99,16 @@ Pandora_Strutils::longtohex (const long i) {
|
|||
return o.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tranform a string into a integer.
|
||||
*
|
||||
* @param str String to convert.
|
||||
*
|
||||
* @return The integer value of the string.
|
||||
*
|
||||
* @exception Invalid_Conversion throwed if the string has non-
|
||||
* decimal values.
|
||||
*/
|
||||
int
|
||||
Pandora_Strutils::strtoint (const string str) {
|
||||
int result;
|
||||
|
@ -79,6 +119,15 @@ Pandora_Strutils::strtoint (const string str) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace every occurence of a pattern in a string with other substring.
|
||||
*
|
||||
* @param in Objective string.
|
||||
* @param pattern Pattern to be replaced.
|
||||
* @param rep Substring that replace every occurence of the pattern.
|
||||
*
|
||||
* @return The input string with all pattern occurence replaced.
|
||||
*/
|
||||
string
|
||||
Pandora_Strutils::strreplace (string in, string pattern, string rep) {
|
||||
int i = in.find (pattern);
|
||||
|
@ -107,9 +156,19 @@ isseparator (char c, char const * const wstr) {
|
|||
return (strchr (wstr, c) != NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a string into diferent tokens, divided by one or many
|
||||
* field separators.
|
||||
*
|
||||
* @param l Returned string list with every tokens. Must be initialized
|
||||
* before calling the function.
|
||||
* @param s Input string.
|
||||
* @param separators Field separators string. I.e. " \t" will separate
|
||||
* with every " " and "\t". Can be ommited and will be " \t\n".
|
||||
*/
|
||||
void
|
||||
Pandora_Strutils::stringtok (list<string> &l, string const &s,
|
||||
char const * const separators) {
|
||||
char const * const separators) {
|
||||
|
||||
const string::size_type strsize = s.size();
|
||||
string::size_type i = 0;
|
||||
|
@ -136,5 +195,3 @@ Pandora_Strutils::stringtok (list<string> &l, string const &s,
|
|||
i = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,13 +27,22 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Operations with strings.
|
||||
*/
|
||||
namespace Pandora_Strutils {
|
||||
class Invalid_Conversion : Pandora::Pandora_Exception {};
|
||||
|
||||
/* Strip blank spaces characters from the end and the beginning of a
|
||||
string. */
|
||||
/**
|
||||
* String super-class exception.
|
||||
*/
|
||||
class String_Exception : Pandora::Pandora_Exception {};
|
||||
|
||||
/**
|
||||
* Exception throwed when a conversion could no be successful.
|
||||
*/
|
||||
class Invalid_Conversion : Pandora_Strutils::String_Exception {};
|
||||
|
||||
string trim (const string str);
|
||||
|
||||
|
||||
string inttostr (const int i);
|
||||
string longtostr (const long i);
|
||||
string longtohex (const long i);
|
||||
|
|
|
@ -38,18 +38,31 @@ using namespace Pandora_Strutils;
|
|||
|
||||
string enabled_values[] = {"enabled", "1", "on", "yes", "si", "sí", "ok", ""};
|
||||
|
||||
/**
|
||||
* Creates a new Pandora_Windows_Service.
|
||||
*
|
||||
* @param svc_name Internal service name
|
||||
* @param svc_display_name Service name that will appear in the
|
||||
* Windows service administration tool.
|
||||
* @param svc_description Long description of the service.
|
||||
*/
|
||||
Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name,
|
||||
const char * svc_display_name,
|
||||
const char * svc_description)
|
||||
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::*) ()) &Pandora_Windows_Service::pandora_run);
|
||||
this->setInitFunction ((void (Windows_Service::*) ())
|
||||
&Pandora_Windows_Service::pandora_init);
|
||||
this->setRunFunction ((void (Windows_Service::*) ())
|
||||
&Pandora_Windows_Service::pandora_run);
|
||||
execution_number = 0;
|
||||
this->modules = NULL;
|
||||
this->conf = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a Pandora_Windows_Service object.
|
||||
*/
|
||||
Pandora_Windows_Service::~Pandora_Windows_Service () {
|
||||
if (this->conf != NULL) {
|
||||
delete this->conf;
|
||||
|
@ -86,7 +99,7 @@ Pandora_Windows_Service::pandora_init () {
|
|||
|
||||
conf_file = Pandora::getPandoraInstallDir ();
|
||||
conf_file += "pandora_agent.conf";
|
||||
this->conf = new Pandora_Agent_Conf (conf_file);
|
||||
this->conf = new Pandora::Pandora_Agent_Conf (conf_file);
|
||||
this->modules = new Pandora_Module_List (conf_file);
|
||||
|
||||
/* Get the interval value (in minutes) and set it to the service */
|
||||
|
|
|
@ -30,23 +30,28 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class Pandora_Windows_Service : public Windows_Service {
|
||||
private:
|
||||
SSH::Pandora_Ssh_Client *ssh_client;
|
||||
Pandora_Agent_Conf *conf;
|
||||
Pandora_Module_List *modules;
|
||||
long execution_number;
|
||||
string agent_name;
|
||||
namespace Pandora {
|
||||
/**
|
||||
* Class to implement the Pandora Windows service.
|
||||
*/
|
||||
class Pandora_Windows_Service : public Windows_Service {
|
||||
private:
|
||||
SSH::Pandora_Ssh_Client *ssh_client;
|
||||
Pandora_Agent_Conf *conf;
|
||||
Pandora_Modules::Pandora_Module_List *modules;
|
||||
long execution_number;
|
||||
string agent_name;
|
||||
|
||||
TiXmlElement * getXmlHeader ();
|
||||
TiXmlElement *getXmlHeader ();
|
||||
|
||||
void pandora_run ();
|
||||
void pandora_init ();
|
||||
public:
|
||||
Pandora_Windows_Service (const char * svc_name,
|
||||
const char * svc_display_name,
|
||||
const char * svc_description);
|
||||
~Pandora_Windows_Service ();
|
||||
};
|
||||
void pandora_run ();
|
||||
void pandora_init ();
|
||||
public:
|
||||
Pandora_Windows_Service (const char * svc_name,
|
||||
const char * svc_display_name,
|
||||
const char * svc_description);
|
||||
~Pandora_Windows_Service ();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,18 +36,37 @@ using namespace std;
|
|||
using namespace SSH;
|
||||
using namespace Pandora;
|
||||
|
||||
/**
|
||||
* Creates a Connection_Failed exception.
|
||||
*
|
||||
* @param e Numeric error code.
|
||||
*/
|
||||
Connection_Failed::Connection_Failed (int e) {
|
||||
err_number = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the numeric error code.
|
||||
*
|
||||
* @return The numeric code.
|
||||
*/
|
||||
int
|
||||
Connection_Failed::getError () {
|
||||
return err_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Scp_Failed exception.
|
||||
*
|
||||
* @param e Error description.
|
||||
*/
|
||||
Scp_Failed::Scp_Failed (char *e) {
|
||||
errmsg = strdup (e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SSH client object and initialize its attributes.
|
||||
*/
|
||||
Pandora_Ssh_Client::Pandora_Ssh_Client () {
|
||||
sock = 0;
|
||||
fingerprint = "";
|
||||
|
@ -56,6 +75,13 @@ Pandora_Ssh_Client::Pandora_Ssh_Client () {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a SSH client object.
|
||||
*
|
||||
* It also disconnect the client from the host if connected.
|
||||
*
|
||||
* @see disconnect
|
||||
*/
|
||||
Pandora_Ssh_Client::~Pandora_Ssh_Client () {
|
||||
if (session != NULL) {
|
||||
disconnect ();
|
||||
|
@ -64,7 +90,11 @@ Pandora_Ssh_Client::~Pandora_Ssh_Client () {
|
|||
return;
|
||||
}
|
||||
|
||||
/* Disconnects from remote host. It will close all open connections and channels. */
|
||||
/**
|
||||
* Disconnects from remote host.
|
||||
*
|
||||
* It will close all open connections and channels.
|
||||
*/
|
||||
void
|
||||
Pandora_Ssh_Client::disconnect () {
|
||||
if (channel != NULL) {
|
||||
|
@ -142,28 +172,22 @@ Pandora_Ssh_Client::newConnection (const string host, const int port) {
|
|||
fingerprint.erase (fingerprint.length () - 1, 2);
|
||||
}
|
||||
|
||||
/* Connects to specified host and port using a username and a password */
|
||||
void
|
||||
Pandora_Ssh_Client::connectWithUserPass (const string host, const int port,
|
||||
const string username, const string passwd) {
|
||||
try {
|
||||
newConnection (host, port);
|
||||
} catch (Session_Already_Opened e) {
|
||||
}
|
||||
|
||||
if (session != NULL) {
|
||||
if (libssh2_userauth_password (session, username.c_str (),
|
||||
passwd.c_str ())) {
|
||||
disconnect ();
|
||||
throw Authentication_Failed ();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Connects to specified host and port using a username and a public/private key.
|
||||
/**
|
||||
* Connects to specified host and port using a username and a public/private key.
|
||||
*
|
||||
* The keys are the filename that contains the public and the private keys.
|
||||
* The passphrase is the password for these keys. */
|
||||
* The passphrase is the password for these keys.
|
||||
*
|
||||
* @param host Remote host to connect to.
|
||||
* @param port Remote port to connect to.
|
||||
* @param username Remote host username to connect to.
|
||||
* @param filename_pubkey Path to the public key file.
|
||||
* @param filename_privkey Path to the private key file.
|
||||
* @param passphrase Passphrase of the keys.
|
||||
*
|
||||
* @exception Authentication_Failed throwed when the atuhentication could not
|
||||
* be done.
|
||||
*/
|
||||
void
|
||||
Pandora_Ssh_Client::connectWithPublicKey (const string host, const int port,
|
||||
const string username, const string filename_pubkey,
|
||||
|
@ -186,13 +210,28 @@ Pandora_Ssh_Client::connectWithPublicKey (const string host, const int port,
|
|||
return;
|
||||
}
|
||||
|
||||
/* Copy a file using a SSH connection (scp).
|
||||
/**
|
||||
* Copy a file using a SSH connection via scp method.
|
||||
*
|
||||
* The function receives a filename in the local filesystem and copies all
|
||||
* its content to the remote host. The remote filename will be the
|
||||
* basename of the local file and will be copied in the remote actual
|
||||
* directory. */
|
||||
* directory.
|
||||
*
|
||||
* @param remote_filename Remote path to copy the local file in.
|
||||
* @param filename Path to the local file.
|
||||
*
|
||||
* @exception Session_Not_Opened Throwed if the session was not opened before
|
||||
* calling this function.
|
||||
* @exception Pandora_File::File_Not_Found Throwed if the local file does not
|
||||
* exists.
|
||||
* @exception Channel_Error Throwd if there was an error with the SSH channel.
|
||||
* @exception Scp_Failed Throwed if the scp operations failed when copying the
|
||||
* file.
|
||||
*/
|
||||
void
|
||||
Pandora_Ssh_Client::scpFileFilename (const string remote_filename, const string filename) {
|
||||
Pandora_Ssh_Client::scpFileFilename (const string remote_filename,
|
||||
const string filename) {
|
||||
LIBSSH2_CHANNEL *scp_channel;
|
||||
size_t to_send, sent;
|
||||
char *errmsg;
|
||||
|
@ -207,7 +246,7 @@ Pandora_Ssh_Client::scpFileFilename (const string remote_filename, const string
|
|||
} catch (Pandora_File::File_Not_Found e) {
|
||||
pandoraLog ("Pandora_Ssh_Client: File %s not found",
|
||||
filename.c_str());
|
||||
return;
|
||||
throw e;
|
||||
}
|
||||
|
||||
to_send = buffer.length ();
|
||||
|
@ -243,6 +282,14 @@ Pandora_Ssh_Client::scpFileFilename (const string remote_filename, const string
|
|||
libssh2_channel_free (scp_channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fingerprint of the remote host.
|
||||
*
|
||||
* The finger print is a unical identifier of the host. It's a method
|
||||
* to ensure that the host is the host we supposed.
|
||||
*
|
||||
* @return The fingerprint of the remote host.
|
||||
*/
|
||||
string
|
||||
Pandora_Ssh_Client::getFingerprint () {
|
||||
return this->fingerprint;
|
||||
|
|
|
@ -27,41 +27,81 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* SSH connection classes.
|
||||
*/
|
||||
namespace SSH {
|
||||
/* SSH Client exceptions */
|
||||
class Session_Already_Opened : public Pandora::Pandora_Exception {
|
||||
/**
|
||||
* A SSH super-class exception.
|
||||
*/
|
||||
class SSH_Exception : public Pandora::Pandora_Exception {
|
||||
};
|
||||
|
||||
/**
|
||||
* A SSH session has already be opened and a new
|
||||
* connection is attemped without closing it.
|
||||
*/
|
||||
class Session_Already_Opened : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class Session_Not_Opened : public Pandora::Pandora_Exception {
|
||||
/**
|
||||
* A SSH operations is tried and a session
|
||||
* has still not be opened.
|
||||
*/
|
||||
class Session_Not_Opened : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class Session_Error : public Pandora::Pandora_Exception {
|
||||
/**
|
||||
* There were unknown problems with the SSH session.
|
||||
*/
|
||||
class Session_Error : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class Authentication_Failed : public Pandora::Pandora_Exception {
|
||||
|
||||
/**
|
||||
* The SSH authentication fails when connecting.
|
||||
*/
|
||||
class Authentication_Failed : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class Resolv_Failed : public Pandora::Pandora_Exception {
|
||||
/**
|
||||
* The host could not be resolved.
|
||||
*/
|
||||
class Resolv_Failed : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class Socket_Error : public Pandora::Pandora_Exception {
|
||||
/**
|
||||
* Unknown socket error.
|
||||
*/
|
||||
class Socket_Error : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class File_Error : public Pandora::Pandora_Exception {
|
||||
|
||||
/**
|
||||
* An error happened with a file.
|
||||
*/
|
||||
class File_Error : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class Channel_Error : public Pandora::Pandora_Exception {
|
||||
|
||||
/**
|
||||
* An error occured with the SSH channel.
|
||||
*/
|
||||
class Channel_Error : public SSH::SSH_Exception {
|
||||
};
|
||||
|
||||
class Connection_Failed : public Pandora::Pandora_Exception {
|
||||
|
||||
/**
|
||||
* Connection failed with the host.
|
||||
*/
|
||||
class Connection_Failed : public SSH::SSH_Exception {
|
||||
private:
|
||||
int err_number;
|
||||
public:
|
||||
Connection_Failed (int e);
|
||||
int getError ();
|
||||
};
|
||||
|
||||
class Scp_Failed : public Pandora::Pandora_Exception {
|
||||
|
||||
/**
|
||||
* The scp operation failed due to some unknow error.
|
||||
*/
|
||||
class Scp_Failed : public SSH::SSH_Exception {
|
||||
private:
|
||||
char *errmsg;
|
||||
public:
|
||||
|
@ -69,7 +109,9 @@ namespace SSH {
|
|||
~Scp_Failed () { Pandora::pandoraFree (errmsg); };
|
||||
};
|
||||
|
||||
/* SSH Client class */
|
||||
/**
|
||||
* Client to perform a SSH connection to a host.
|
||||
*/
|
||||
class Pandora_Ssh_Client {
|
||||
private:
|
||||
int sock;
|
||||
|
@ -82,21 +124,11 @@ namespace SSH {
|
|||
Pandora_Ssh_Client ();
|
||||
~Pandora_Ssh_Client ();
|
||||
|
||||
/* Connects to specified host and port using a username and a password
|
||||
*
|
||||
* Throws: Authentication_Failed */
|
||||
void connectWithUserPass (const string host, const int port,
|
||||
const string username, const string passwd);
|
||||
/* Connects to specified host and port using a username and a public/private key.
|
||||
* The keys are the filename that contains the public and the private keys.
|
||||
* The passphrase is the password for these keys.
|
||||
*
|
||||
* Throws: Authentication_Failed */
|
||||
void connectWithPublicKey (const string host, const int port,
|
||||
const string username, const string filename_pubkey,
|
||||
const string filename_privkey, const string passphrase);
|
||||
|
||||
/* Disconnects from remote host. It will close all open connections and channels. */
|
||||
|
||||
void disconnect ();
|
||||
|
||||
/* Copy a file using a SSH connection (scp).
|
||||
|
|
|
@ -26,21 +26,47 @@
|
|||
using namespace std;
|
||||
using namespace SSH;
|
||||
|
||||
/**
|
||||
* Creates a Pandora_SSH_Test.
|
||||
*
|
||||
* It will read the configuration file and prepares
|
||||
* all the information to perform a SSH test.
|
||||
*/
|
||||
Pandora_SSH_Test::Pandora_SSH_Test () {
|
||||
string conf_file;
|
||||
|
||||
conf_file = Pandora::getPandoraInstallDir ();
|
||||
conf_file += "pandora_agent.conf";
|
||||
conf = new Pandora_Agent_Conf (conf_file);
|
||||
conf = new Pandora::Pandora_Agent_Conf (conf_file);
|
||||
|
||||
ssh_client = new SSH::Pandora_Ssh_Client ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a Pandora_SSH_Test object.
|
||||
*/
|
||||
Pandora_SSH_Test::~Pandora_SSH_Test () {
|
||||
delete conf;
|
||||
delete ssh_client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a SSH test.
|
||||
*
|
||||
* It will generate a lot of output to the stdout.
|
||||
*
|
||||
* @exception Authentication_Failed Throwed if the authentication process
|
||||
* failed when connecting to the host.
|
||||
* @exception Socket_Error Throwed when something goes bad with the sockets.
|
||||
* @exception Resolv_Failed Throwed when the remote host could not be resolved
|
||||
* to a valid IP.
|
||||
* @exception Connection_Failed Throwed if the TCP/IP connection to the host
|
||||
* failed or could not be done. It includes timeouts, route failures,
|
||||
* etc
|
||||
* @exception Session_Error Throwed if there was problem with the SSH session.
|
||||
* @exception Pandora::Pandora_Exception Throwed if there was an unespecified
|
||||
* error.
|
||||
*/
|
||||
void
|
||||
Pandora_SSH_Test::test () {
|
||||
string pubkey_file, privkey_file, tmp_filename;
|
||||
|
@ -107,7 +133,7 @@ Pandora_SSH_Test::test () {
|
|||
saved = doc->SaveFile();
|
||||
delete doc;
|
||||
if (!saved) {
|
||||
Pandora_Exception e;
|
||||
Pandora::Pandora_Exception e;
|
||||
cout << "Error when saving the XML in " << tmp_filepath << endl;
|
||||
cout << "Check the configuration file" << endl;
|
||||
throw e;
|
||||
|
@ -131,7 +157,7 @@ Pandora_SSH_Test::test () {
|
|||
cout << "Check the network configuration." << endl;
|
||||
try {
|
||||
Pandora_File::removeFile (tmp_filepath);
|
||||
} catch (Pandora_Exception e) {
|
||||
} catch (Pandora::Pandora_Exception e) {
|
||||
}
|
||||
throw e;
|
||||
} catch (Scp_Failed e) {
|
||||
|
@ -140,10 +166,10 @@ Pandora_SSH_Test::test () {
|
|||
cout << "Check the network configuration." << endl;
|
||||
try {
|
||||
Pandora_File::removeFile (tmp_filepath);
|
||||
} catch (Pandora_Exception e) {
|
||||
} catch (Pandora::Pandora_Exception e) {
|
||||
}
|
||||
throw e;
|
||||
} catch (Pandora_Exception e) {
|
||||
} catch (Pandora::Pandora_Exception e) {
|
||||
ssh_client->disconnect();
|
||||
cout << "An unhandled exception happened." << endl;
|
||||
throw e;
|
||||
|
|
|
@ -25,10 +25,16 @@
|
|||
#include "../pandora_agent_conf.h"
|
||||
|
||||
namespace SSH {
|
||||
/**
|
||||
* Class to perform a test of the SSH configuration.
|
||||
*
|
||||
* An object of this class will read the configuration file
|
||||
* and copy a blank xml file into remote server path.
|
||||
*/
|
||||
class Pandora_SSH_Test {
|
||||
private:
|
||||
Pandora_Ssh_Client *ssh_client;
|
||||
Pandora_Agent_Conf *conf;
|
||||
Pandora_Ssh_Client *ssh_client;
|
||||
Pandora::Pandora_Agent_Conf *conf;
|
||||
public:
|
||||
Pandora_SSH_Test ();
|
||||
~Pandora_SSH_Test ();
|
||||
|
|
|
@ -26,26 +26,51 @@
|
|||
using namespace Pandora_Strutils;
|
||||
using namespace Pandora_Windows_Info;
|
||||
|
||||
/**
|
||||
* Get the name of the running operating system.
|
||||
*
|
||||
* @return The name of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Windows_Info::getOSName () {
|
||||
return Pandora_Wmi::getOSName ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the versioof the running operating system.
|
||||
*
|
||||
* @return The version of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Windows_Info::getOSVersion () {
|
||||
return Pandora_Wmi::getOSVersion ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the build of the running operating system.
|
||||
*
|
||||
* @return The build of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Windows_Info::getOSBuild () {
|
||||
return Pandora_Wmi::getOSBuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the system name of the running operating system.
|
||||
*
|
||||
* @return The system name of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Windows_Info::getSystemName () {
|
||||
return Pandora_Wmi::getSystemName ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the system path of the running operating system.
|
||||
*
|
||||
* @return The system path of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Windows_Info::getSystemPath () {
|
||||
char buffer[MAX_PATH];
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
using namespace Pandora;
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Windows information functions.
|
||||
*/
|
||||
namespace Pandora_Windows_Info {
|
||||
|
||||
string getOSName ();
|
||||
|
|
|
@ -45,6 +45,13 @@ getWmiStr (LPCWSTR computer) {
|
|||
return wmi_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a process is running.
|
||||
*
|
||||
* @param process_name Name of the process with extension.
|
||||
*
|
||||
* @return Number of instances of the process running.
|
||||
*/
|
||||
int
|
||||
Pandora_Wmi::isProcessRunning (string process_name) {
|
||||
CDhInitialize init;
|
||||
|
@ -83,6 +90,14 @@ Pandora_Wmi::isProcessRunning (string process_name) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Windows service is running.
|
||||
*
|
||||
* @param service_name Internal name of the service to check.
|
||||
*
|
||||
* @retval 1 The service is running
|
||||
* @retval 0 The service is stopped
|
||||
*/
|
||||
int
|
||||
Pandora_Wmi::isServiceRunning (string service_name) {
|
||||
CDhInitialize init;
|
||||
|
@ -128,6 +143,13 @@ Pandora_Wmi::isServiceRunning (string service_name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the free space in a logical disk drive.
|
||||
*
|
||||
* @param disk_id Disk drive letter (C.
|
||||
*
|
||||
* @return Free space amount in MB.
|
||||
*/
|
||||
long
|
||||
Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
||||
CDhInitialize init;
|
||||
|
@ -162,7 +184,7 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
|||
try {
|
||||
space = Pandora_Strutils::strtoint (space_str);
|
||||
} catch (Pandora_Exception e) {
|
||||
throw Pandora_Wmi_Error ();
|
||||
throw Pandora_Wmi_Exception ();
|
||||
}
|
||||
|
||||
return space / 1024 / 1024;
|
||||
|
@ -173,9 +195,16 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
|||
pandoraLog ("getDiskFreeSpace error. %s", errstr.c_str ());
|
||||
}
|
||||
|
||||
throw Pandora_Wmi_Error ();
|
||||
throw Pandora_Wmi_Exception ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CPU usage percentage in the last minutes.
|
||||
*
|
||||
* @param cpu_id CPU identifier.
|
||||
*
|
||||
* @return The usage percentage of the CPU.
|
||||
*/
|
||||
int
|
||||
Pandora_Wmi::getCpuUsagePercentage (int cpu_id) {
|
||||
CDhInitialize init;
|
||||
|
@ -216,10 +245,14 @@ Pandora_Wmi::getCpuUsagePercentage (int cpu_id) {
|
|||
pandoraLog ("getCpuUsagePercentage error. %s", errstr.c_str ());
|
||||
}
|
||||
|
||||
throw Pandora_Wmi_Error ();
|
||||
throw Pandora_Wmi_Exception ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the amount of free memory in the system
|
||||
*
|
||||
* @return The amount of free memory in MB.
|
||||
*/
|
||||
long
|
||||
Pandora_Wmi::getFreememory () {
|
||||
CDhInitialize init;
|
||||
|
@ -247,9 +280,14 @@ Pandora_Wmi::getFreememory () {
|
|||
pandoraLog ("getFreememory error. %s", errstr.c_str ());
|
||||
}
|
||||
|
||||
throw Pandora_Wmi_Error ();
|
||||
throw Pandora_Wmi_Exception ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the operating system.
|
||||
*
|
||||
* @return The name of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Wmi::getOSName () {
|
||||
CDhInitialize init;
|
||||
|
@ -282,6 +320,11 @@ Pandora_Wmi::getOSName () {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of the operating system.
|
||||
*
|
||||
* @return The version of the operaing system.
|
||||
*/
|
||||
string
|
||||
Pandora_Wmi::getOSVersion () {
|
||||
CDhInitialize init;
|
||||
|
@ -314,6 +357,11 @@ Pandora_Wmi::getOSVersion () {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the build of the operating system.
|
||||
*
|
||||
* @return The build of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Wmi::getOSBuild () {
|
||||
CDhInitialize init;
|
||||
|
@ -346,6 +394,11 @@ Pandora_Wmi::getOSBuild () {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the system name of the operating system.
|
||||
*
|
||||
* @return The system name of the operating system.
|
||||
*/
|
||||
string
|
||||
Pandora_Wmi::getSystemName () {
|
||||
CDhInitialize init;
|
||||
|
|
|
@ -29,8 +29,14 @@
|
|||
using namespace Pandora;
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Operations with the Windows Management Instrumentation (WMI)
|
||||
*/
|
||||
namespace Pandora_Wmi {
|
||||
class Pandora_Wmi_Error : public Pandora_Exception { };
|
||||
/**
|
||||
* Exception super-class when doing a WMI operation.
|
||||
*/
|
||||
class Pandora_Wmi_Exception : public Pandora_Exception { };
|
||||
|
||||
int isProcessRunning (string process_name);
|
||||
int isServiceRunning (string service_name);
|
||||
|
|
|
@ -40,12 +40,24 @@ static void SetWindowsServiceStatus (DWORD dwCurrentState,
|
|||
DWORD dwWaitHint);
|
||||
static void ErrorStopService (LPTSTR lpszAPI);
|
||||
|
||||
/**
|
||||
* Set the values of the service to run.
|
||||
*
|
||||
* All the attributes are set to NULL.
|
||||
*/
|
||||
Windows_Service::Windows_Service () {
|
||||
service_name = NULL;
|
||||
service_display_name = NULL;
|
||||
service_description = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the values of the service to run.
|
||||
*
|
||||
* @param svc_name Internal service name.
|
||||
* @param svc_display_name Service name to display in the Windows
|
||||
* service administration utility.
|
||||
* @param svc_description Long description of the service.
|
||||
*/
|
||||
Windows_Service::Windows_Service (const char * svc_name,
|
||||
const char * svc_display_name,
|
||||
const char * svc_description) {
|
||||
|
@ -59,21 +71,44 @@ Windows_Service::Windows_Service (const char * svc_name,
|
|||
current_service = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the service
|
||||
*/
|
||||
Windows_Service::~Windows_Service () {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the function to run on service execution.
|
||||
*
|
||||
* @param f Pointer to execution function.
|
||||
*/
|
||||
void
|
||||
Windows_Service::setRunFunction (void (Windows_Service::*f) ()) {
|
||||
run_function = f;
|
||||
current_service->run_function = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the function to initialize the service.
|
||||
*
|
||||
* This functions is executed before the run function.
|
||||
*
|
||||
* @param f Pointer to init function.
|
||||
*/
|
||||
void
|
||||
Windows_Service::setInitFunction (void (Windows_Service::*f) ()) {
|
||||
init_function = f;
|
||||
current_service->init_function = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec the run function.
|
||||
*
|
||||
* If the sleep_time is set to a greater value than 0, then the
|
||||
* function will execute infinitely.
|
||||
* Notice: This function does not have to be called from the main
|
||||
* function
|
||||
*/
|
||||
void
|
||||
Windows_Service::execRunFunction () {
|
||||
if (run_function != NULL) {
|
||||
|
@ -86,6 +121,9 @@ Windows_Service::execRunFunction () {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec the init function.
|
||||
*/
|
||||
void
|
||||
Windows_Service::execInitFunction () {
|
||||
if (init_function != NULL) {
|
||||
|
@ -93,17 +131,36 @@ Windows_Service::execInitFunction () {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the internal service name.
|
||||
*
|
||||
* @return The internal service name.
|
||||
*/
|
||||
LPSTR
|
||||
Windows_Service::getServiceName () {
|
||||
return service_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time between executions.
|
||||
*
|
||||
* If it's set to 0 (default value), the service will execute
|
||||
* the run function once. Else it's executed infinitely every
|
||||
* s seconds
|
||||
*
|
||||
* @param s Seconds between executions.
|
||||
*/
|
||||
void
|
||||
Windows_Service::setSleepTime (unsigned int s) {
|
||||
sleep_time = s;
|
||||
current_service->sleep_time = sleep_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the service in the Windows services system.
|
||||
*
|
||||
* @param application_binary_path Path to binary file.
|
||||
*/
|
||||
void
|
||||
Windows_Service::install (LPCTSTR application_binary_path) {
|
||||
SC_HANDLE sc_manager;
|
||||
|
@ -225,6 +282,9 @@ Windows_Service::install (LPCTSTR application_binary_path) {
|
|||
CloseServiceHandle (sc_manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall the service from the system.
|
||||
*/
|
||||
void
|
||||
Windows_Service::uninstall () {
|
||||
SC_HANDLE sc_manager, sc_service;
|
||||
|
@ -336,8 +396,13 @@ Windows_Service::uninstall () {
|
|||
}
|
||||
|
||||
|
||||
/* this is the entry point which is called from main() */
|
||||
int
|
||||
/**
|
||||
* Run the service.
|
||||
*
|
||||
* This function must be called from main function to
|
||||
* start the service when started by Windows services system.
|
||||
*/
|
||||
void
|
||||
Windows_Service::run () {
|
||||
SERVICE_TABLE_ENTRY ste_dispatch_table[] =
|
||||
{
|
||||
|
@ -353,8 +418,6 @@ Windows_Service::run () {
|
|||
memset (msg, sizeof (msg), '\0');
|
||||
svc_format_message (msg, sizeof (msg));
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void WINAPI
|
||||
|
|
|
@ -25,57 +25,44 @@
|
|||
#include <windows.h>
|
||||
#include <winsvc.h> /* for Service stuff */
|
||||
|
||||
/**
|
||||
* Class to install and use a Windows service easily.
|
||||
*
|
||||
* If you want to use it, create a child class that
|
||||
* set the init_function and run_function. Then use
|
||||
* install function to perform the service installation
|
||||
* and the run function on the main function to start it.
|
||||
* Notice: A program can have only one object of this class.
|
||||
*/
|
||||
class Windows_Service {
|
||||
protected:
|
||||
private:
|
||||
char *service_name;
|
||||
char *service_display_name;
|
||||
char *service_description;
|
||||
HANDLE stop_event;
|
||||
int sleep_time;
|
||||
SC_HANDLE sc_service;
|
||||
/* Pointer to functions that will run the service */
|
||||
|
||||
void (Windows_Service::*run_function) ();
|
||||
void (Windows_Service::*init_function) ();
|
||||
public:
|
||||
Windows_Service ();
|
||||
Windows_Service ();
|
||||
|
||||
/* Set the values of the service to run.
|
||||
Notice: A program can have ONLY ONE object of this class. */
|
||||
Windows_Service (const char * svc_name, const char * svc_display_name,
|
||||
const char * svc_description);
|
||||
Windows_Service (const char * svc_name,
|
||||
const char * svc_display_name,
|
||||
const char * svc_description);
|
||||
|
||||
~Windows_Service ();
|
||||
~Windows_Service ();
|
||||
|
||||
/* Install the service in the Windows registry. */
|
||||
void install (LPCTSTR application_binary_path);
|
||||
|
||||
/* Uninstall the service, removint the key in the Windows registry. */
|
||||
void uninstall ();
|
||||
|
||||
/* Run the service, which has to be installed previously.
|
||||
* The service will execute the function indicated in the
|
||||
* setRunFunction */
|
||||
int run ();
|
||||
|
||||
/* Set the function that will be called on service start. This
|
||||
* is called the "run function" */
|
||||
void setRunFunction (void (Windows_Service::*f) ());
|
||||
|
||||
/* Set the function that will be called on service init. This
|
||||
* is called the "init function" */
|
||||
void setInitFunction (void (Windows_Service::*f) ());
|
||||
void install (LPCTSTR application_binary_path);
|
||||
void uninstall ();
|
||||
void run ();
|
||||
void setRunFunction (void (Windows_Service::*f) ());
|
||||
void setInitFunction (void (Windows_Service::*f) ());
|
||||
LPSTR getServiceName ();
|
||||
void setSleepTime (unsigned int s);
|
||||
|
||||
/* Calls the functions. There's no need to be called from the outside of this
|
||||
* class. They are used in a internal method because of another Windows
|
||||
* matter... */
|
||||
void execRunFunction ();
|
||||
void execInitFunction ();
|
||||
|
||||
LPSTR getServiceName ();
|
||||
|
||||
/* Set the time that the service will sleep between each execution of
|
||||
* the work funtion. If this value is not set, the service will run this
|
||||
* function once. */
|
||||
void setSleepTime (unsigned int s);
|
||||
void execRunFunction ();
|
||||
void execInitFunction ();
|
||||
};
|
||||
#endif /* __WINDOWS_SERVICE_H__ */
|
||||
|
|
Loading…
Reference in New Issue