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>
|
2006-07-17 Esteban Sanchez <estebans@artica.es>
|
||||||
|
|
||||||
* main.cc: Added "--help" option.
|
* 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 ("\\");
|
pos = aux.rfind ("\\");
|
||||||
aux.erase (pos + 1);
|
aux.erase (pos + 1);
|
||||||
Pandora::setPandoraInstallDir (aux);
|
Pandora::setPandoraInstallDir (aux);
|
||||||
|
|
||||||
|
/* Check the parameters */
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (_stricmp(argv[i], SERVICE_INSTALL_CMDLINE_PARAM) == 0) {
|
if (_stricmp(argv[i], SERVICE_INSTALL_CMDLINE_PARAM) == 0) {
|
||||||
|
/* Install parameter */
|
||||||
service->install (Pandora::getPandoraInstallPath ().c_str ());
|
service->install (Pandora::getPandoraInstallPath ().c_str ());
|
||||||
|
|
||||||
delete service;
|
delete service;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (_stricmp(argv[i], SERVICE_UNINSTALL_CMDLINE_PARAM) == 0) {
|
} else if (_stricmp(argv[i], SERVICE_UNINSTALL_CMDLINE_PARAM) == 0) {
|
||||||
|
/* Uninstall parameter */
|
||||||
service->uninstall ();
|
service->uninstall ();
|
||||||
|
|
||||||
delete service;
|
delete service;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (_stricmp(argv[i], SSH_TEST_CMDLINE_PARAM) == 0) {
|
} else if (_stricmp(argv[i], SSH_TEST_CMDLINE_PARAM) == 0) {
|
||||||
|
/* SSH test parameter */
|
||||||
SSH::Pandora_SSH_Test ssh_test;
|
SSH::Pandora_SSH_Test ssh_test;
|
||||||
|
|
||||||
delete service;
|
delete service;
|
||||||
|
@ -66,24 +72,33 @@ main (int argc, char *argv[]) {
|
||||||
} catch (Pandora_Exception e) {
|
} catch (Pandora_Exception e) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
|
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
|
||||||
|
/* Help parameter */
|
||||||
cout << "Usage: " << argv[0] << " [OPTION]" << endl << endl;
|
cout << "Usage: " << argv[0] << " [OPTION]" << endl << endl;
|
||||||
cout << "Available options are:" << endl;
|
cout << "Available options are:" << endl;
|
||||||
cout << "\t" << SERVICE_INSTALL_CMDLINE_PARAM << ": Install the Pandora Agent service." << endl;
|
cout << "\t" << SERVICE_INSTALL_CMDLINE_PARAM;
|
||||||
cout << "\t" << SERVICE_UNINSTALL_CMDLINE_PARAM << ": Uninstall the Pandora Agent service." << endl;
|
cout << ": Install the Pandora Agent service." << endl;
|
||||||
cout << "\t" << SSH_TEST_CMDLINE_PARAM << ": Test the SSH Pandora Agent configuration." << 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;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
cout << "Usage: " << argv[0] << " [" << SERVICE_INSTALL_CMDLINE_PARAM
|
/* No parameter recognized */
|
||||||
<< "] [" << SERVICE_UNINSTALL_CMDLINE_PARAM << "]" << endl;
|
cout << "Usage: " << argv[0] << " [" << SERVICE_INSTALL_CMDLINE_PARAM;
|
||||||
cerr << "Run " << argv[0] << "with " << HELP_CMDLINE_PARAM << " parameter for more info." << endl;
|
cout << "] [" << SERVICE_UNINSTALL_CMDLINE_PARAM << "]" << endl;
|
||||||
|
cout << "Run " << argv[0] << "with " << HELP_CMDLINE_PARAM;
|
||||||
|
cout << " parameter for more info." << endl;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
service->run ();
|
service->run ();
|
||||||
|
|
||||||
delete service;
|
delete service;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,20 @@
|
||||||
|
|
||||||
using namespace std;
|
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
|
string
|
||||||
Pandora_File::readFile (const string filename) {
|
Pandora_File::readFile (const string filepath) {
|
||||||
string line, result;
|
string line, result;
|
||||||
ifstream myfile (filename.c_str ());
|
ifstream myfile (filepath.c_str ());
|
||||||
|
|
||||||
if (! myfile.is_open ()) {
|
if (! myfile.is_open ()) {
|
||||||
throw File_Not_Found ();
|
throw File_Not_Found ();
|
||||||
|
@ -44,16 +54,32 @@ Pandora_File::readFile (const string filename) {
|
||||||
return result;
|
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
|
void
|
||||||
Pandora_File::removeFile (const string filename) {
|
Pandora_File::removeFile (const string filepath) {
|
||||||
if (remove (filename.c_str ()) == -1) {
|
if (remove (filepath.c_str ()) == -1) {
|
||||||
throw Delete_Error ();
|
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
|
void
|
||||||
Pandora_File::writeFile (const string filename, const string data) {
|
Pandora_File::writeFile (const string filepath, const string data) {
|
||||||
ofstream file (filename.c_str ());
|
ofstream file (filepath.c_str ());
|
||||||
|
|
||||||
if (! file.is_open ()) {
|
if (! file.is_open ()) {
|
||||||
throw File_Not_Found ();
|
throw File_Not_Found ();
|
||||||
|
|
|
@ -26,13 +26,30 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File operations.
|
||||||
|
*/
|
||||||
namespace Pandora_File {
|
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);
|
string readFile (const string filename);
|
||||||
void removeFile (const string filename);
|
void removeFile (const string filename);
|
||||||
void writeFile (const string filename, const string data);
|
void writeFile (const string filename, const string data);
|
||||||
|
|
|
@ -26,6 +26,13 @@ using namespace Pandora;
|
||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
using namespace Pandora_Strutils;
|
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) {
|
Pandora_Module::Pandora_Module (string name) {
|
||||||
this->module_name = name;
|
this->module_name = name;
|
||||||
this->executions = 0;
|
this->executions = 0;
|
||||||
|
@ -36,11 +43,23 @@ Pandora_Module::Pandora_Module (string name) {
|
||||||
this->has_limits = false;
|
this->has_limits = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Virtual destructor of Pandora_Module.
|
||||||
|
*
|
||||||
|
* Should be redefined by child classes.
|
||||||
|
*/
|
||||||
Pandora_Module::~Pandora_Module () {
|
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) {
|
if (type == module_generic_data_str) {
|
||||||
return TYPE_GENERIC_DATA;
|
return TYPE_GENERIC_DATA;
|
||||||
} else if (type == module_generic_data_inc_str) {
|
} 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
|
string
|
||||||
Pandora_Module::getName () const {
|
Pandora_Module::getName () const {
|
||||||
return this->module_name;
|
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
|
string
|
||||||
Pandora_Module::getTypeString () const {
|
Pandora_Module::getTypeString () const {
|
||||||
return this->module_type_str;
|
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 {
|
Pandora_Module::getTypeInt () const {
|
||||||
return this->module_type;
|
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 {
|
Pandora_Module::getModuleKind () const {
|
||||||
return this->module_kind;
|
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
|
string
|
||||||
Pandora_Module::getOutput () const {
|
Pandora_Module::getOutput () const {
|
||||||
switch (this->module_type) {
|
switch (this->module_type) {
|
||||||
|
@ -90,7 +187,7 @@ Pandora_Module::getOutput () const {
|
||||||
|
|
||||||
if (this->has_limits) {
|
if (this->has_limits) {
|
||||||
if (value >= this->max || value <= this->min) {
|
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
|
void
|
||||||
Pandora_Module::run () {
|
Pandora_Module::run () {
|
||||||
|
|
||||||
|
@ -120,6 +227,23 @@ Pandora_Module::run () {
|
||||||
has_output = true;
|
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 *
|
TiXmlElement *
|
||||||
Pandora_Module::getXml () {
|
Pandora_Module::getXml () {
|
||||||
string data;
|
string data;
|
||||||
|
@ -141,7 +265,7 @@ Pandora_Module::getXml () {
|
||||||
this->module_name.c_str ());
|
this->module_name.c_str ());
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} catch (Interval_Error e) {
|
} catch (Value_Error e) {
|
||||||
pandoraLog ("The returned value was not in the interval on module %s",
|
pandoraLog ("The returned value was not in the interval on module %s",
|
||||||
this->module_name.c_str ());
|
this->module_name.c_str ());
|
||||||
|
|
||||||
|
@ -183,29 +307,69 @@ Pandora_Module::getXml () {
|
||||||
return root;
|
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
|
void
|
||||||
Pandora_Module::setMax (int value) {
|
Pandora_Module::setMax (int value) {
|
||||||
this->has_limits = true;
|
this->has_limits = true;
|
||||||
this->max = value;
|
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
|
void
|
||||||
Pandora_Module::setMin (int value) {
|
Pandora_Module::setMin (int value) {
|
||||||
this->has_limits = true;
|
this->has_limits = true;
|
||||||
this->min = value;
|
this->min = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the module type from a string type.
|
||||||
|
*
|
||||||
|
* @param type String type.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Module::setType (string type) {
|
Pandora_Module::setType (string type) {
|
||||||
this->module_type_str = 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
|
void
|
||||||
Pandora_Module::setInterval (int interval) {
|
Pandora_Module::setInterval (int interval) {
|
||||||
this->module_interval = interval;
|
this->module_interval = interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the module description.
|
||||||
|
*
|
||||||
|
* @param description Description of the module.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Module::setDescription (string description) {
|
Pandora_Module::setDescription (string description) {
|
||||||
this->module_description = description;
|
this->module_description = description;
|
||||||
|
|
|
@ -26,30 +26,47 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition of Pandora modules.
|
||||||
|
*/
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
|
|
||||||
enum {
|
/**
|
||||||
TYPE_0,
|
* Defines the type of the module.
|
||||||
TYPE_GENERIC_DATA,
|
*
|
||||||
TYPE_GENERIC_DATA_INC,
|
* The type of a module is the value type the module can have.
|
||||||
TYPE_GENERIC_PROC,
|
*/
|
||||||
TYPE_GENERIC_DATA_STRING
|
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_str = "generic_data";
|
||||||
const string module_generic_data_inc_str = "generic_data_inc";
|
const string module_generic_data_inc_str = "generic_data_inc";
|
||||||
const string module_generic_proc_str = "generic_proc";
|
const string module_generic_proc_str = "generic_proc";
|
||||||
const string module_generic_data_string_str = "generic_data_string";
|
const string module_generic_data_string_str = "generic_data_string";
|
||||||
|
|
||||||
enum {
|
/**
|
||||||
MODULE_0,
|
* Defines the kind of the module.
|
||||||
MODULE_EXEC,
|
*
|
||||||
MODULE_PROC,
|
* The kind of a module is the work the module does.
|
||||||
MODULE_SERVICE,
|
*/
|
||||||
MODULE_FREEDISK,
|
typedef enum {
|
||||||
MODULE_CPUUSAGE,
|
MODULE_0, /**< Invalid kind */
|
||||||
MODULE_FREEMEMORY
|
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_exec_str = "module_exec";
|
||||||
const string module_proc_str = "module_proc";
|
const string module_proc_str = "module_proc";
|
||||||
|
@ -58,49 +75,89 @@ namespace Pandora_Modules {
|
||||||
const string module_freememory_str = "module_freememory";
|
const string module_freememory_str = "module_freememory";
|
||||||
const string module_cpuusage_str = "module_cpuusage";
|
const string module_cpuusage_str = "module_cpuusage";
|
||||||
|
|
||||||
class Output_Error : public Pandora::Pandora_Exception { };
|
/**
|
||||||
class Interval_Error : public Pandora::Pandora_Exception { };
|
* Pandora module super-class exception.
|
||||||
class Interval_Not_Fulfilled : public Pandora::Pandora_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 {
|
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:
|
protected:
|
||||||
string module_name;
|
/**
|
||||||
string module_type_str;
|
* Module output generated at execution.
|
||||||
int module_type;
|
*/
|
||||||
string module_kind_str;
|
string output;
|
||||||
string module_description;
|
/**
|
||||||
int module_kind;
|
* Indicates if the module generated output in
|
||||||
int module_interval;
|
* his last execution.
|
||||||
int executions;
|
*/
|
||||||
string output;
|
bool has_output;
|
||||||
int max, min;
|
/**
|
||||||
bool has_limits;
|
* The name of the module.
|
||||||
bool has_output;
|
*/
|
||||||
|
string module_name;
|
||||||
|
/**
|
||||||
|
* The description of the module.
|
||||||
|
*/
|
||||||
|
string module_description;
|
||||||
public:
|
public:
|
||||||
Pandora_Module (string name);
|
Pandora_Module (string name);
|
||||||
virtual ~Pandora_Module ();
|
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. */
|
virtual string getOutput () const;
|
||||||
TiXmlElement *getXml ();
|
|
||||||
|
|
||||||
/* Execute the agent */
|
string getName () const;
|
||||||
virtual void run ();
|
string getDescription () const;
|
||||||
|
string getTypeString () const;
|
||||||
|
Module_Type getTypeInt () const;
|
||||||
|
Module_Type getModuleType () const;
|
||||||
|
Module_Kind getModuleKind () const;
|
||||||
|
|
||||||
virtual string getOutput () const;
|
void setType (string type);
|
||||||
|
void setKind (string kind);
|
||||||
string getName () const;
|
void setDescription (string description);
|
||||||
string getTypeString () const;
|
void setMax (int value);
|
||||||
int getTypeInt () const;
|
void setMin (int value);
|
||||||
int getModuleKind () const;
|
|
||||||
|
|
||||||
void setType (string type);
|
|
||||||
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_Modules;
|
||||||
using namespace Pandora_Strutils;
|
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_Cpuusage::Pandora_Module_Cpuusage (string name, int cpu_id)
|
||||||
: Pandora_Module (name) {
|
: Pandora_Module (name) {
|
||||||
|
|
||||||
this->cpu_id = cpu_id;
|
this->cpu_id = cpu_id;
|
||||||
|
|
||||||
this->module_kind_str = module_cpuusage_str;
|
this->setKind (module_cpuusage_str);
|
||||||
this->module_kind = MODULE_CPUUSAGE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -49,8 +54,8 @@ Pandora_Module_Cpuusage::run () {
|
||||||
try {
|
try {
|
||||||
res = Pandora_Wmi::getCpuUsagePercentage (this->cpu_id);
|
res = Pandora_Wmi::getCpuUsagePercentage (this->cpu_id);
|
||||||
|
|
||||||
output = inttostr (res);
|
this->output = inttostr (res);
|
||||||
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
|
} catch (Pandora_Wmi::Pandora_Wmi_Exception e) {
|
||||||
this->has_output = false;
|
this->has_output = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
|
/**
|
||||||
|
* Module to retrieve the CPU usage percentage.
|
||||||
|
*/
|
||||||
class Pandora_Module_Cpuusage : public Pandora_Module {
|
class Pandora_Module_Cpuusage : public Pandora_Module {
|
||||||
private:
|
private:
|
||||||
int cpu_id;
|
int cpu_id;
|
||||||
|
|
|
@ -28,12 +28,17 @@ using namespace Pandora;
|
||||||
using namespace Pandora_Strutils;
|
using namespace Pandora_Strutils;
|
||||||
using namespace Pandora_Modules;
|
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_Exec::Pandora_Module_Exec (string name, string exec)
|
||||||
: Pandora_Module (name) {
|
: Pandora_Module (name) {
|
||||||
this->module_exec = "cmd.exe /c \"" + exec + "\"";
|
this->module_exec = "cmd.exe /c \"" + exec + "\"";
|
||||||
|
|
||||||
this->module_kind_str = module_exec_str;
|
this->setKind (module_exec_str);
|
||||||
this->module_kind = MODULE_EXEC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -48,6 +53,7 @@ Pandora_Module_Exec::run () {
|
||||||
try {
|
try {
|
||||||
Pandora_Module::run ();
|
Pandora_Module::run ();
|
||||||
} catch (Interval_Not_Fulfilled e) {
|
} catch (Interval_Not_Fulfilled e) {
|
||||||
|
this->has_output = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +68,7 @@ Pandora_Module_Exec::run () {
|
||||||
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
||||||
if (job == NULL) {
|
if (job == NULL) {
|
||||||
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
|
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
|
||||||
|
this->has_output = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +77,7 @@ Pandora_Module_Exec::run () {
|
||||||
|
|
||||||
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
||||||
pandoraLog ("CreatePipe failed. Err: %d", GetLastError ());
|
pandoraLog ("CreatePipe failed. Err: %d", GetLastError ());
|
||||||
|
this->has_output = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +108,7 @@ Pandora_Module_Exec::run () {
|
||||||
working_dir.c_str (), &si, &pi)) {
|
working_dir.c_str (), &si, &pi)) {
|
||||||
pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d",
|
pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d",
|
||||||
this->module_name.c_str (), GetLastError ());
|
this->module_name.c_str (), GetLastError ());
|
||||||
|
this->has_output = false;
|
||||||
} else {
|
} else {
|
||||||
char buffer[BUFSIZE + 1];
|
char buffer[BUFSIZE + 1];
|
||||||
unsigned long read, avail;
|
unsigned long read, avail;
|
||||||
|
@ -123,6 +132,7 @@ Pandora_Module_Exec::run () {
|
||||||
|
|
||||||
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
|
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
|
||||||
this->module_name.c_str (), retval);
|
this->module_name.c_str (), retval);
|
||||||
|
this->has_output = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
||||||
|
|
|
@ -24,6 +24,13 @@
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
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 {
|
class Pandora_Module_Exec : public Pandora_Module {
|
||||||
private:
|
private:
|
||||||
string module_exec;
|
string module_exec;
|
||||||
|
|
|
@ -62,6 +62,14 @@ parseLine (string line, string token) {
|
||||||
return retstr;
|
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 *
|
||||||
Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
list<string> tokens;
|
list<string> tokens;
|
||||||
|
@ -72,6 +80,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
string module_freedisk, module_cpuusage, module_freememory;
|
string module_freedisk, module_cpuusage, module_freememory;
|
||||||
Pandora_Module *module;
|
Pandora_Module *module;
|
||||||
bool numeric;
|
bool numeric;
|
||||||
|
Module_Type type;
|
||||||
|
|
||||||
module_name = "";
|
module_name = "";
|
||||||
module_type = "";
|
module_type = "";
|
||||||
|
@ -82,8 +91,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
module_exec = "";
|
module_exec = "";
|
||||||
module_proc = "";
|
module_proc = "";
|
||||||
module_service = "";
|
module_service = "";
|
||||||
|
|
||||||
|
|
||||||
stringtok (tokens, definition, "\n");
|
stringtok (tokens, definition, "\n");
|
||||||
|
|
||||||
/* Pick the first and the last value of the token list */
|
/* Pick the first and the last value of the token list */
|
||||||
|
@ -171,8 +179,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
if (module_description != "") {
|
if (module_description != "") {
|
||||||
module->setDescription (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:
|
||||||
case TYPE_GENERIC_DATA_INC:
|
case TYPE_GENERIC_DATA_INC:
|
||||||
case TYPE_GENERIC_PROC:
|
case TYPE_GENERIC_PROC:
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factoy to create Pandora_Module objects by parsing a definition.
|
||||||
|
*/
|
||||||
namespace Pandora_Module_Factory {
|
namespace Pandora_Module_Factory {
|
||||||
Pandora_Module * getModuleFromDefinition (string definition);
|
Pandora_Module * getModuleFromDefinition (string definition);
|
||||||
string getModuleResult (Pandora_Module *module);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,6 +29,12 @@ using namespace Pandora;
|
||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
using namespace Pandora_Strutils;
|
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_Freedisk::Pandora_Module_Freedisk (string name, string disk_id)
|
||||||
: Pandora_Module (name) {
|
: 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 (),
|
transform (disk_id.begin (), disk_id.end (),
|
||||||
this->disk_id.begin (), (int (*) (int)) toupper);
|
this->disk_id.begin (), (int (*) (int)) toupper);
|
||||||
|
|
||||||
this->module_kind_str = module_freedisk_str;
|
this->setKind (module_freedisk_str);
|
||||||
this->module_kind = MODULE_FREEDISK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -54,8 +59,8 @@ Pandora_Module_Freedisk::run () {
|
||||||
try {
|
try {
|
||||||
res = Pandora_Wmi::getDiskFreeSpace (this->disk_id);
|
res = Pandora_Wmi::getDiskFreeSpace (this->disk_id);
|
||||||
|
|
||||||
output = longtostr (res);
|
this->output = longtostr (res);
|
||||||
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
|
} catch (Pandora_Wmi::Pandora_Wmi_Exception e) {
|
||||||
this->has_output = false;
|
this->has_output = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
|
/**
|
||||||
|
* Module to retrieve the free space available in a logical volume
|
||||||
|
* disk.
|
||||||
|
*/
|
||||||
class Pandora_Module_Freedisk : public Pandora_Module {
|
class Pandora_Module_Freedisk : public Pandora_Module {
|
||||||
private:
|
private:
|
||||||
string disk_id;
|
string disk_id;
|
||||||
|
|
|
@ -27,11 +27,15 @@ using namespace Pandora;
|
||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
using namespace Pandora_Strutils;
|
using namespace Pandora_Strutils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Pandora_Module_Freememory object.
|
||||||
|
*
|
||||||
|
* @param name Module name.
|
||||||
|
*/
|
||||||
Pandora_Module_Freememory::Pandora_Module_Freememory (string name)
|
Pandora_Module_Freememory::Pandora_Module_Freememory (string name)
|
||||||
: Pandora_Module (name) {
|
: Pandora_Module (name) {
|
||||||
|
|
||||||
this->module_kind_str = module_freememory_str;
|
this->setKind (module_freememory_str);
|
||||||
this->module_kind = MODULE_FREEMEMORY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -47,8 +51,8 @@ Pandora_Module_Freememory::run () {
|
||||||
try {
|
try {
|
||||||
res = Pandora_Wmi::getFreememory ();
|
res = Pandora_Wmi::getFreememory ();
|
||||||
|
|
||||||
output = longtostr (res);
|
this->output = longtostr (res);
|
||||||
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
|
} catch (Pandora_Wmi::Pandora_Wmi_Exception e) {
|
||||||
this->has_output = false;
|
this->has_output = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
|
/**
|
||||||
|
* Module to retrieve the free memory amount of the system.
|
||||||
|
*/
|
||||||
class Pandora_Module_Freememory : public Pandora_Module {
|
class Pandora_Module_Freememory : public Pandora_Module {
|
||||||
public:
|
public:
|
||||||
Pandora_Module_Freememory (string name);
|
Pandora_Module_Freememory (string name);
|
||||||
|
|
|
@ -29,9 +29,16 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace std;
|
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 ());
|
ifstream file (filename.c_str ());
|
||||||
string buffer;
|
string buffer;
|
||||||
unsigned int pos;
|
unsigned int pos;
|
||||||
|
@ -74,7 +81,12 @@ Pandora_Module_List::Pandora_Module_List (string filename) {
|
||||||
*current = modules->begin ();
|
*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;
|
Pandora_Module *module;
|
||||||
std::list<Pandora_Module *>::iterator iter;
|
std::list<Pandora_Module *>::iterator iter;
|
||||||
|
|
||||||
|
@ -93,7 +105,7 @@ Pandora_Module_List::~Pandora_Module_List () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pandora_Module_List::parseModuleDefinition (string definition) {
|
Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition) {
|
||||||
Pandora_Module *module;
|
Pandora_Module *module;
|
||||||
Pandora_Module_Exec *module_exec;
|
Pandora_Module_Exec *module_exec;
|
||||||
Pandora_Module_Proc *module_proc;
|
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 *
|
||||||
Pandora_Module_List::getCurrentValue () {
|
Pandora_Modules::Pandora_Module_List::getCurrentValue () {
|
||||||
return *(*current);
|
return *(*current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the current pointer to the first element of the list.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Module_List::goFirst () {
|
Pandora_Modules::Pandora_Module_List::goFirst () {
|
||||||
if (modules != NULL) {
|
if (modules != NULL) {
|
||||||
*current = modules->begin ();
|
*current = modules->begin ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the current pointer to the last element of the list.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Module_List::goLast () {
|
Pandora_Modules::Pandora_Module_List::goLast () {
|
||||||
if (modules != NULL) {
|
if (modules != NULL) {
|
||||||
*current = modules->end ();
|
*current = modules->end ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the current pointer to the next element of the list.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Module_List::goNext () {
|
Pandora_Modules::Pandora_Module_List::goNext () {
|
||||||
if (current != NULL && !isLast ()) {
|
if (current != NULL && !isLast ()) {
|
||||||
(*current)++;
|
(*current)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the current pointer to the previous element of the list.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Module_List::goPrev () {
|
Pandora_Modules::Pandora_Module_List::goPrev () {
|
||||||
if (current != NULL && !isFirst ()) {
|
if (current != NULL && !isFirst ()) {
|
||||||
(*current)--;
|
(*current)--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current pointer is the last one of the list.
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
Pandora_Module_List::isLast () {
|
Pandora_Modules::Pandora_Module_List::isLast () {
|
||||||
if (current == NULL || modules == NULL) {
|
if (current == NULL || modules == NULL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return *current == modules->end ();
|
return *current == modules->end ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current pointer is the first one of the list.
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
Pandora_Module_List::isFirst () {
|
Pandora_Modules::Pandora_Module_List::isFirst () {
|
||||||
if (current == NULL || modules == NULL) {
|
if (current == NULL || modules == NULL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,32 +28,36 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Pandora;
|
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__ */
|
#endif /* __PANDORA_MODULE_LIST_H__ */
|
||||||
|
|
|
@ -28,6 +28,12 @@ using namespace Pandora;
|
||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
using namespace Pandora_Strutils;
|
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_Proc::Pandora_Module_Proc (string name, string process_name)
|
||||||
: Pandora_Module (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 (),
|
transform (process_name.begin (), process_name.end (),
|
||||||
this->process_name.begin (), (int (*) (int)) tolower);
|
this->process_name.begin (), (int (*) (int)) tolower);
|
||||||
|
|
||||||
this->module_kind_str = module_proc_str;
|
this->setKind (module_proc_str);
|
||||||
this->module_kind = MODULE_PROC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -51,5 +56,5 @@ Pandora_Module_Proc::run () {
|
||||||
|
|
||||||
res = Pandora_Wmi::isProcessRunning (this->process_name);
|
res = Pandora_Wmi::isProcessRunning (this->process_name);
|
||||||
|
|
||||||
output = inttostr (res);
|
this->output = inttostr (res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
|
/**
|
||||||
|
* Module to check that a process is running on the system.
|
||||||
|
*/
|
||||||
class Pandora_Module_Proc : public Pandora_Module {
|
class Pandora_Module_Proc : public Pandora_Module {
|
||||||
private:
|
private:
|
||||||
string process_name;
|
string process_name;
|
||||||
|
|
|
@ -29,6 +29,12 @@ using namespace Pandora;
|
||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
using namespace Pandora_Strutils;
|
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_Service::Pandora_Module_Service (string name, string service_name)
|
||||||
: Pandora_Module (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 (),
|
transform (service_name.begin (), service_name.end (),
|
||||||
this->service_name.begin (), (int (*) (int)) tolower);
|
this->service_name.begin (), (int (*) (int)) tolower);
|
||||||
|
|
||||||
this->module_kind_str = module_service_str;
|
this->setKind (module_service_str);
|
||||||
this->module_kind = MODULE_SERVICE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -52,5 +57,5 @@ Pandora_Module_Service::run () {
|
||||||
}
|
}
|
||||||
|
|
||||||
res = Pandora_Wmi::isServiceRunning (this->service_name);
|
res = Pandora_Wmi::isServiceRunning (this->service_name);
|
||||||
output = inttostr (res);
|
this->output = inttostr (res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
|
/**
|
||||||
|
* Module to check that a windows service is running on the
|
||||||
|
* system.
|
||||||
|
*/
|
||||||
class Pandora_Module_Service : public Pandora_Module {
|
class Pandora_Module_Service : public Pandora_Module {
|
||||||
private:
|
private:
|
||||||
string service_name;
|
string service_name;
|
||||||
|
|
|
@ -37,6 +37,13 @@ string pandora_dir;
|
||||||
bool pandora_debug;
|
bool pandora_debug;
|
||||||
string pandora_version = PANDORA_VERSION;
|
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
|
void
|
||||||
Key_Value::parseLine (string str) {
|
Key_Value::parseLine (string str) {
|
||||||
unsigned int pos;
|
unsigned int pos;
|
||||||
|
@ -68,11 +75,21 @@ Key_Value::parseLine (string str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the key of the object.
|
||||||
|
*
|
||||||
|
* @return The key
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Key_Value::getKey () {
|
Key_Value::getKey () {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the object.
|
||||||
|
*
|
||||||
|
* @return The value
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Key_Value::getValue () {
|
Key_Value::getValue () {
|
||||||
return value;
|
return value;
|
||||||
|
@ -104,6 +121,15 @@ pandoraWriteLog (string filename, string line) {
|
||||||
cout << line << endl;
|
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
|
void
|
||||||
Pandora::pandoraLog (char *format, ...) {
|
Pandora::pandoraLog (char *format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -116,6 +142,15 @@ Pandora::pandoraLog (char *format, ...) {
|
||||||
pandoraWriteLog ("pandora-log.log", (char *) msg);
|
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
|
void
|
||||||
Pandora::pandoraDebug (char *format, ...) {
|
Pandora::pandoraDebug (char *format, ...) {
|
||||||
if (pandora_debug) {
|
if (pandora_debug) {
|
||||||
|
@ -131,38 +166,95 @@ Pandora::pandoraDebug (char *format, ...) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Secure free of a pointer.
|
||||||
|
*
|
||||||
|
* @param pointer pointer to free.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Pandora::pandoraFree (void * e) {
|
Pandora::pandoraFree (void * pointer) {
|
||||||
if (e != NULL)
|
if (pointer != NULL)
|
||||||
free (e);
|
free (pointer);
|
||||||
return;
|
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
|
void
|
||||||
Pandora::setPandoraInstallDir (string dir) {
|
Pandora::setPandoraInstallDir (string dir) {
|
||||||
pandora_dir = 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
|
string
|
||||||
Pandora::getPandoraInstallDir () {
|
Pandora::getPandoraInstallDir () {
|
||||||
return pandora_dir;
|
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
|
void
|
||||||
Pandora::setPandoraInstallPath (string path) {
|
Pandora::setPandoraInstallPath (string path) {
|
||||||
pandora_path = 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
|
string
|
||||||
Pandora::getPandoraInstallPath () {
|
Pandora::getPandoraInstallPath () {
|
||||||
return pandora_path;
|
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
|
void
|
||||||
Pandora::setPandoraDebug (bool dbg) {
|
Pandora::setPandoraDebug (bool dbg) {
|
||||||
pandora_debug = dbg;
|
pandora_debug = dbg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the version of the agent.
|
||||||
|
*
|
||||||
|
* @return The version.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora::getPandoraAgentVersion () {
|
Pandora::getPandoraAgentVersion () {
|
||||||
return pandora_version;
|
return pandora_version;
|
||||||
|
|
|
@ -29,12 +29,18 @@ using namespace std;
|
||||||
|
|
||||||
#define PANDORA_DEBUG 1
|
#define PANDORA_DEBUG 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main application.
|
||||||
|
*/
|
||||||
namespace Pandora {
|
namespace Pandora {
|
||||||
|
/**
|
||||||
|
* A Key_Value object holds a relation between a value and a
|
||||||
|
* unique key value.
|
||||||
|
*/
|
||||||
class Key_Value {
|
class Key_Value {
|
||||||
protected:
|
private:
|
||||||
string key;
|
string key;
|
||||||
string value;
|
string value;
|
||||||
public:
|
public:
|
||||||
void parseLine (string str);
|
void parseLine (string str);
|
||||||
string getKey ();
|
string getKey ();
|
||||||
|
@ -45,7 +51,7 @@ namespace Pandora {
|
||||||
const char * const name = "PandoraAgent";
|
const char * const name = "PandoraAgent";
|
||||||
const char * const display_name = "Pandora agent";
|
const char * const display_name = "Pandora agent";
|
||||||
const char * const description = "The Pandora Agent service";
|
const char * const description = "The Pandora Agent service";
|
||||||
|
|
||||||
void setPandoraInstallDir (string dir);
|
void setPandoraInstallDir (string dir);
|
||||||
string getPandoraInstallDir ();
|
string getPandoraInstallDir ();
|
||||||
void setPandoraInstallPath (string path);
|
void setPandoraInstallPath (string path);
|
||||||
|
@ -56,7 +62,13 @@ namespace Pandora {
|
||||||
void pandoraDebug (char *format, ...);
|
void pandoraDebug (char *format, ...);
|
||||||
void pandoraLog (char *format, ...);
|
void pandoraLog (char *format, ...);
|
||||||
void pandoraFree (void * e);
|
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 { };
|
class Pandora_Exception { };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,22 @@
|
||||||
#include "pandora.h"
|
#include "pandora.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace Pandora;
|
||||||
|
|
||||||
#define MAX_KEYS 100
|
#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 ());
|
ifstream file (filename.c_str ());
|
||||||
string buffer;
|
string buffer;
|
||||||
unsigned int pos;
|
unsigned int pos;
|
||||||
|
@ -56,12 +68,26 @@ Pandora_Agent_Conf::Pandora_Agent_Conf (string filename) {
|
||||||
file.close ();
|
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
|
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 ();
|
std::list<Key_Value>::iterator i = key_values->begin ();
|
||||||
|
|
||||||
while (i != key_values->end ()) {
|
while (i != key_values->end ()) {
|
||||||
|
|
|
@ -26,19 +26,25 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Pandora;
|
|
||||||
|
|
||||||
class Pandora_Agent_Conf {
|
namespace Pandora {
|
||||||
protected:
|
/**
|
||||||
list<Key_Value> *key_values; /* Key-value list */
|
* Agent main configuration class.
|
||||||
public:
|
*
|
||||||
/* Read and set a key-value set from a file. */
|
* Stores a list of Key_Value objects with the agent configuration.
|
||||||
Pandora_Agent_Conf (string filename);
|
* It parses a configuration file and supplies a function to get the
|
||||||
|
* configuration values.
|
||||||
~Pandora_Agent_Conf ();
|
*/
|
||||||
|
class Pandora_Agent_Conf {
|
||||||
/* Get the value of a key from a key-value set. */
|
private:
|
||||||
string getValue (const string key);
|
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;
|
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
|
string
|
||||||
Pandora_Strutils::trim (const string str) {
|
Pandora_Strutils::trim (const string str) {
|
||||||
char * delims = " \t\r\n";
|
char * delims = " \t\r\n";
|
||||||
|
@ -47,11 +56,25 @@ Pandora_Strutils::trim (const string str) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform an integer variable into a string.
|
||||||
|
*
|
||||||
|
* @param i Integer to transform.
|
||||||
|
*
|
||||||
|
* @return A string with the integer value.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Strutils::inttostr (const int i) {
|
Pandora_Strutils::inttostr (const int i) {
|
||||||
return longtostr (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
|
string
|
||||||
Pandora_Strutils::longtostr (const long i) {
|
Pandora_Strutils::longtostr (const long i) {
|
||||||
std::ostringstream o;
|
std::ostringstream o;
|
||||||
|
@ -61,6 +84,13 @@ Pandora_Strutils::longtostr (const long i) {
|
||||||
return o.str();
|
return o.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform a long variable into hexadecimal.
|
||||||
|
*
|
||||||
|
* @param i Long variable to transform.
|
||||||
|
*
|
||||||
|
* @return The hexadecimal value of the long variable.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Strutils::longtohex (const long i) {
|
Pandora_Strutils::longtohex (const long i) {
|
||||||
std::ostringstream o;
|
std::ostringstream o;
|
||||||
|
@ -69,6 +99,16 @@ Pandora_Strutils::longtohex (const long i) {
|
||||||
return o.str();
|
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
|
int
|
||||||
Pandora_Strutils::strtoint (const string str) {
|
Pandora_Strutils::strtoint (const string str) {
|
||||||
int result;
|
int result;
|
||||||
|
@ -79,6 +119,15 @@ Pandora_Strutils::strtoint (const string str) {
|
||||||
return result;
|
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
|
string
|
||||||
Pandora_Strutils::strreplace (string in, string pattern, string rep) {
|
Pandora_Strutils::strreplace (string in, string pattern, string rep) {
|
||||||
int i = in.find (pattern);
|
int i = in.find (pattern);
|
||||||
|
@ -107,9 +156,19 @@ isseparator (char c, char const * const wstr) {
|
||||||
return (strchr (wstr, c) != NULL);
|
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
|
void
|
||||||
Pandora_Strutils::stringtok (list<string> &l, string const &s,
|
Pandora_Strutils::stringtok (list<string> &l, string const &s,
|
||||||
char const * const separators) {
|
char const * const separators) {
|
||||||
|
|
||||||
const string::size_type strsize = s.size();
|
const string::size_type strsize = s.size();
|
||||||
string::size_type i = 0;
|
string::size_type i = 0;
|
||||||
|
@ -136,5 +195,3 @@ Pandora_Strutils::stringtok (list<string> &l, string const &s,
|
||||||
i = j + 1;
|
i = j + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,22 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operations with strings.
|
||||||
|
*/
|
||||||
namespace Pandora_Strutils {
|
namespace Pandora_Strutils {
|
||||||
class Invalid_Conversion : Pandora::Pandora_Exception {};
|
/**
|
||||||
|
* String super-class exception.
|
||||||
/* Strip blank spaces characters from the end and the beginning of a
|
*/
|
||||||
string. */
|
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 trim (const string str);
|
||||||
|
|
||||||
string inttostr (const int i);
|
string inttostr (const int i);
|
||||||
string longtostr (const long i);
|
string longtostr (const long i);
|
||||||
string longtohex (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", ""};
|
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,
|
Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name,
|
||||||
const char * svc_display_name,
|
const char * svc_display_name,
|
||||||
const char * svc_description)
|
const char * svc_description)
|
||||||
: Windows_Service (svc_name, svc_display_name, svc_description) {
|
: Windows_Service (svc_name, svc_display_name, svc_description) {
|
||||||
|
|
||||||
this->setInitFunction ((void (Windows_Service::*) ()) &Pandora_Windows_Service::pandora_init);
|
this->setInitFunction ((void (Windows_Service::*) ())
|
||||||
this->setRunFunction ((void (Windows_Service::*) ()) &Pandora_Windows_Service::pandora_run);
|
&Pandora_Windows_Service::pandora_init);
|
||||||
|
this->setRunFunction ((void (Windows_Service::*) ())
|
||||||
|
&Pandora_Windows_Service::pandora_run);
|
||||||
execution_number = 0;
|
execution_number = 0;
|
||||||
this->modules = NULL;
|
this->modules = NULL;
|
||||||
this->conf = NULL;
|
this->conf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys a Pandora_Windows_Service object.
|
||||||
|
*/
|
||||||
Pandora_Windows_Service::~Pandora_Windows_Service () {
|
Pandora_Windows_Service::~Pandora_Windows_Service () {
|
||||||
if (this->conf != NULL) {
|
if (this->conf != NULL) {
|
||||||
delete this->conf;
|
delete this->conf;
|
||||||
|
@ -86,7 +99,7 @@ Pandora_Windows_Service::pandora_init () {
|
||||||
|
|
||||||
conf_file = Pandora::getPandoraInstallDir ();
|
conf_file = Pandora::getPandoraInstallDir ();
|
||||||
conf_file += "pandora_agent.conf";
|
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);
|
this->modules = new Pandora_Module_List (conf_file);
|
||||||
|
|
||||||
/* Get the interval value (in minutes) and set it to the service */
|
/* Get the interval value (in minutes) and set it to the service */
|
||||||
|
|
|
@ -30,23 +30,28 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Pandora_Windows_Service : public Windows_Service {
|
namespace Pandora {
|
||||||
private:
|
/**
|
||||||
SSH::Pandora_Ssh_Client *ssh_client;
|
* Class to implement the Pandora Windows service.
|
||||||
Pandora_Agent_Conf *conf;
|
*/
|
||||||
Pandora_Module_List *modules;
|
class Pandora_Windows_Service : public Windows_Service {
|
||||||
long execution_number;
|
private:
|
||||||
string agent_name;
|
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_run ();
|
||||||
void pandora_init ();
|
void pandora_init ();
|
||||||
public:
|
public:
|
||||||
Pandora_Windows_Service (const char * svc_name,
|
Pandora_Windows_Service (const char * svc_name,
|
||||||
const char * svc_display_name,
|
const char * svc_display_name,
|
||||||
const char * svc_description);
|
const char * svc_description);
|
||||||
~Pandora_Windows_Service ();
|
~Pandora_Windows_Service ();
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,18 +36,37 @@ using namespace std;
|
||||||
using namespace SSH;
|
using namespace SSH;
|
||||||
using namespace Pandora;
|
using namespace Pandora;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Connection_Failed exception.
|
||||||
|
*
|
||||||
|
* @param e Numeric error code.
|
||||||
|
*/
|
||||||
Connection_Failed::Connection_Failed (int e) {
|
Connection_Failed::Connection_Failed (int e) {
|
||||||
err_number = e;
|
err_number = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the numeric error code.
|
||||||
|
*
|
||||||
|
* @return The numeric code.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
Connection_Failed::getError () {
|
Connection_Failed::getError () {
|
||||||
return err_number;
|
return err_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Scp_Failed exception.
|
||||||
|
*
|
||||||
|
* @param e Error description.
|
||||||
|
*/
|
||||||
Scp_Failed::Scp_Failed (char *e) {
|
Scp_Failed::Scp_Failed (char *e) {
|
||||||
errmsg = strdup (e);
|
errmsg = strdup (e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a SSH client object and initialize its attributes.
|
||||||
|
*/
|
||||||
Pandora_Ssh_Client::Pandora_Ssh_Client () {
|
Pandora_Ssh_Client::Pandora_Ssh_Client () {
|
||||||
sock = 0;
|
sock = 0;
|
||||||
fingerprint = "";
|
fingerprint = "";
|
||||||
|
@ -56,6 +75,13 @@ Pandora_Ssh_Client::Pandora_Ssh_Client () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy a SSH client object.
|
||||||
|
*
|
||||||
|
* It also disconnect the client from the host if connected.
|
||||||
|
*
|
||||||
|
* @see disconnect
|
||||||
|
*/
|
||||||
Pandora_Ssh_Client::~Pandora_Ssh_Client () {
|
Pandora_Ssh_Client::~Pandora_Ssh_Client () {
|
||||||
if (session != NULL) {
|
if (session != NULL) {
|
||||||
disconnect ();
|
disconnect ();
|
||||||
|
@ -64,7 +90,11 @@ Pandora_Ssh_Client::~Pandora_Ssh_Client () {
|
||||||
return;
|
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
|
void
|
||||||
Pandora_Ssh_Client::disconnect () {
|
Pandora_Ssh_Client::disconnect () {
|
||||||
if (channel != NULL) {
|
if (channel != NULL) {
|
||||||
|
@ -142,28 +172,22 @@ Pandora_Ssh_Client::newConnection (const string host, const int port) {
|
||||||
fingerprint.erase (fingerprint.length () - 1, 2);
|
fingerprint.erase (fingerprint.length () - 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connects to specified host and port using a username and a password */
|
/**
|
||||||
void
|
* Connects to specified host and port using a username and a public/private key.
|
||||||
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.
|
|
||||||
* The keys are the filename that contains the public and the private keys.
|
* 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
|
void
|
||||||
Pandora_Ssh_Client::connectWithPublicKey (const string host, const int port,
|
Pandora_Ssh_Client::connectWithPublicKey (const string host, const int port,
|
||||||
const string username, const string filename_pubkey,
|
const string username, const string filename_pubkey,
|
||||||
|
@ -186,13 +210,28 @@ Pandora_Ssh_Client::connectWithPublicKey (const string host, const int port,
|
||||||
return;
|
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
|
* The function receives a filename in the local filesystem and copies all
|
||||||
* its content to the remote host. The remote filename will be the
|
* 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
|
* 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
|
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;
|
LIBSSH2_CHANNEL *scp_channel;
|
||||||
size_t to_send, sent;
|
size_t to_send, sent;
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
|
@ -207,7 +246,7 @@ Pandora_Ssh_Client::scpFileFilename (const string remote_filename, const string
|
||||||
} catch (Pandora_File::File_Not_Found e) {
|
} catch (Pandora_File::File_Not_Found e) {
|
||||||
pandoraLog ("Pandora_Ssh_Client: File %s not found",
|
pandoraLog ("Pandora_Ssh_Client: File %s not found",
|
||||||
filename.c_str());
|
filename.c_str());
|
||||||
return;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
to_send = buffer.length ();
|
to_send = buffer.length ();
|
||||||
|
@ -243,6 +282,14 @@ Pandora_Ssh_Client::scpFileFilename (const string remote_filename, const string
|
||||||
libssh2_channel_free (scp_channel);
|
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
|
string
|
||||||
Pandora_Ssh_Client::getFingerprint () {
|
Pandora_Ssh_Client::getFingerprint () {
|
||||||
return this->fingerprint;
|
return this->fingerprint;
|
||||||
|
|
|
@ -27,41 +27,81 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SSH connection classes.
|
||||||
|
*/
|
||||||
namespace SSH {
|
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:
|
private:
|
||||||
int err_number;
|
int err_number;
|
||||||
public:
|
public:
|
||||||
Connection_Failed (int e);
|
Connection_Failed (int e);
|
||||||
int getError ();
|
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:
|
private:
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
public:
|
public:
|
||||||
|
@ -69,7 +109,9 @@ namespace SSH {
|
||||||
~Scp_Failed () { Pandora::pandoraFree (errmsg); };
|
~Scp_Failed () { Pandora::pandoraFree (errmsg); };
|
||||||
};
|
};
|
||||||
|
|
||||||
/* SSH Client class */
|
/**
|
||||||
|
* Client to perform a SSH connection to a host.
|
||||||
|
*/
|
||||||
class Pandora_Ssh_Client {
|
class Pandora_Ssh_Client {
|
||||||
private:
|
private:
|
||||||
int sock;
|
int sock;
|
||||||
|
@ -82,21 +124,11 @@ namespace SSH {
|
||||||
Pandora_Ssh_Client ();
|
Pandora_Ssh_Client ();
|
||||||
~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,
|
void connectWithPublicKey (const string host, const int port,
|
||||||
const string username, const string filename_pubkey,
|
const string username, const string filename_pubkey,
|
||||||
const string filename_privkey, const string passphrase);
|
const string filename_privkey, const string passphrase);
|
||||||
|
|
||||||
/* Disconnects from remote host. It will close all open connections and channels. */
|
|
||||||
void disconnect ();
|
void disconnect ();
|
||||||
|
|
||||||
/* Copy a file using a SSH connection (scp).
|
/* Copy a file using a SSH connection (scp).
|
||||||
|
|
|
@ -26,21 +26,47 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace SSH;
|
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 () {
|
Pandora_SSH_Test::Pandora_SSH_Test () {
|
||||||
string conf_file;
|
string conf_file;
|
||||||
|
|
||||||
conf_file = Pandora::getPandoraInstallDir ();
|
conf_file = Pandora::getPandoraInstallDir ();
|
||||||
conf_file += "pandora_agent.conf";
|
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 ();
|
ssh_client = new SSH::Pandora_Ssh_Client ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a Pandora_SSH_Test object.
|
||||||
|
*/
|
||||||
Pandora_SSH_Test::~Pandora_SSH_Test () {
|
Pandora_SSH_Test::~Pandora_SSH_Test () {
|
||||||
delete conf;
|
delete conf;
|
||||||
delete ssh_client;
|
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
|
void
|
||||||
Pandora_SSH_Test::test () {
|
Pandora_SSH_Test::test () {
|
||||||
string pubkey_file, privkey_file, tmp_filename;
|
string pubkey_file, privkey_file, tmp_filename;
|
||||||
|
@ -107,7 +133,7 @@ Pandora_SSH_Test::test () {
|
||||||
saved = doc->SaveFile();
|
saved = doc->SaveFile();
|
||||||
delete doc;
|
delete doc;
|
||||||
if (!saved) {
|
if (!saved) {
|
||||||
Pandora_Exception e;
|
Pandora::Pandora_Exception e;
|
||||||
cout << "Error when saving the XML in " << tmp_filepath << endl;
|
cout << "Error when saving the XML in " << tmp_filepath << endl;
|
||||||
cout << "Check the configuration file" << endl;
|
cout << "Check the configuration file" << endl;
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -131,7 +157,7 @@ Pandora_SSH_Test::test () {
|
||||||
cout << "Check the network configuration." << endl;
|
cout << "Check the network configuration." << endl;
|
||||||
try {
|
try {
|
||||||
Pandora_File::removeFile (tmp_filepath);
|
Pandora_File::removeFile (tmp_filepath);
|
||||||
} catch (Pandora_Exception e) {
|
} catch (Pandora::Pandora_Exception e) {
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Scp_Failed e) {
|
} catch (Scp_Failed e) {
|
||||||
|
@ -140,10 +166,10 @@ Pandora_SSH_Test::test () {
|
||||||
cout << "Check the network configuration." << endl;
|
cout << "Check the network configuration." << endl;
|
||||||
try {
|
try {
|
||||||
Pandora_File::removeFile (tmp_filepath);
|
Pandora_File::removeFile (tmp_filepath);
|
||||||
} catch (Pandora_Exception e) {
|
} catch (Pandora::Pandora_Exception e) {
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Pandora_Exception e) {
|
} catch (Pandora::Pandora_Exception e) {
|
||||||
ssh_client->disconnect();
|
ssh_client->disconnect();
|
||||||
cout << "An unhandled exception happened." << endl;
|
cout << "An unhandled exception happened." << endl;
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -25,10 +25,16 @@
|
||||||
#include "../pandora_agent_conf.h"
|
#include "../pandora_agent_conf.h"
|
||||||
|
|
||||||
namespace SSH {
|
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 {
|
class Pandora_SSH_Test {
|
||||||
private:
|
private:
|
||||||
Pandora_Ssh_Client *ssh_client;
|
Pandora_Ssh_Client *ssh_client;
|
||||||
Pandora_Agent_Conf *conf;
|
Pandora::Pandora_Agent_Conf *conf;
|
||||||
public:
|
public:
|
||||||
Pandora_SSH_Test ();
|
Pandora_SSH_Test ();
|
||||||
~Pandora_SSH_Test ();
|
~Pandora_SSH_Test ();
|
||||||
|
|
|
@ -26,26 +26,51 @@
|
||||||
using namespace Pandora_Strutils;
|
using namespace Pandora_Strutils;
|
||||||
using namespace Pandora_Windows_Info;
|
using namespace Pandora_Windows_Info;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the running operating system.
|
||||||
|
*
|
||||||
|
* @return The name of the operating system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Windows_Info::getOSName () {
|
Pandora_Windows_Info::getOSName () {
|
||||||
return Pandora_Wmi::getOSName ();
|
return Pandora_Wmi::getOSName ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the versioof the running operating system.
|
||||||
|
*
|
||||||
|
* @return The version of the operating system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Windows_Info::getOSVersion () {
|
Pandora_Windows_Info::getOSVersion () {
|
||||||
return Pandora_Wmi::getOSVersion ();
|
return Pandora_Wmi::getOSVersion ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the build of the running operating system.
|
||||||
|
*
|
||||||
|
* @return The build of the operating system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Windows_Info::getOSBuild () {
|
Pandora_Windows_Info::getOSBuild () {
|
||||||
return Pandora_Wmi::getOSBuild();
|
return Pandora_Wmi::getOSBuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the system name of the running operating system.
|
||||||
|
*
|
||||||
|
* @return The system name of the operating system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Windows_Info::getSystemName () {
|
Pandora_Windows_Info::getSystemName () {
|
||||||
return Pandora_Wmi::getSystemName ();
|
return Pandora_Wmi::getSystemName ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the system path of the running operating system.
|
||||||
|
*
|
||||||
|
* @return The system path of the operating system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Windows_Info::getSystemPath () {
|
Pandora_Windows_Info::getSystemPath () {
|
||||||
char buffer[MAX_PATH];
|
char buffer[MAX_PATH];
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
using namespace Pandora;
|
using namespace Pandora;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Windows information functions.
|
||||||
|
*/
|
||||||
namespace Pandora_Windows_Info {
|
namespace Pandora_Windows_Info {
|
||||||
|
|
||||||
string getOSName ();
|
string getOSName ();
|
||||||
|
|
|
@ -45,6 +45,13 @@ getWmiStr (LPCWSTR computer) {
|
||||||
return wmi_str;
|
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
|
int
|
||||||
Pandora_Wmi::isProcessRunning (string process_name) {
|
Pandora_Wmi::isProcessRunning (string process_name) {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -83,6 +90,14 @@ Pandora_Wmi::isProcessRunning (string process_name) {
|
||||||
return result;
|
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
|
int
|
||||||
Pandora_Wmi::isServiceRunning (string service_name) {
|
Pandora_Wmi::isServiceRunning (string service_name) {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -128,6 +143,13 @@ Pandora_Wmi::isServiceRunning (string service_name) {
|
||||||
return 0;
|
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
|
long
|
||||||
Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -162,7 +184,7 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
||||||
try {
|
try {
|
||||||
space = Pandora_Strutils::strtoint (space_str);
|
space = Pandora_Strutils::strtoint (space_str);
|
||||||
} catch (Pandora_Exception e) {
|
} catch (Pandora_Exception e) {
|
||||||
throw Pandora_Wmi_Error ();
|
throw Pandora_Wmi_Exception ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return space / 1024 / 1024;
|
return space / 1024 / 1024;
|
||||||
|
@ -173,9 +195,16 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) {
|
||||||
pandoraLog ("getDiskFreeSpace error. %s", errstr.c_str ());
|
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
|
int
|
||||||
Pandora_Wmi::getCpuUsagePercentage (int cpu_id) {
|
Pandora_Wmi::getCpuUsagePercentage (int cpu_id) {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -216,10 +245,14 @@ Pandora_Wmi::getCpuUsagePercentage (int cpu_id) {
|
||||||
pandoraLog ("getCpuUsagePercentage error. %s", errstr.c_str ());
|
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
|
long
|
||||||
Pandora_Wmi::getFreememory () {
|
Pandora_Wmi::getFreememory () {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -247,9 +280,14 @@ Pandora_Wmi::getFreememory () {
|
||||||
pandoraLog ("getFreememory error. %s", errstr.c_str ());
|
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
|
string
|
||||||
Pandora_Wmi::getOSName () {
|
Pandora_Wmi::getOSName () {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -282,6 +320,11 @@ Pandora_Wmi::getOSName () {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the version of the operating system.
|
||||||
|
*
|
||||||
|
* @return The version of the operaing system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Wmi::getOSVersion () {
|
Pandora_Wmi::getOSVersion () {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -314,6 +357,11 @@ Pandora_Wmi::getOSVersion () {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the build of the operating system.
|
||||||
|
*
|
||||||
|
* @return The build of the operating system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Wmi::getOSBuild () {
|
Pandora_Wmi::getOSBuild () {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
@ -346,6 +394,11 @@ Pandora_Wmi::getOSBuild () {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the system name of the operating system.
|
||||||
|
*
|
||||||
|
* @return The system name of the operating system.
|
||||||
|
*/
|
||||||
string
|
string
|
||||||
Pandora_Wmi::getSystemName () {
|
Pandora_Wmi::getSystemName () {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
|
|
|
@ -29,8 +29,14 @@
|
||||||
using namespace Pandora;
|
using namespace Pandora;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operations with the Windows Management Instrumentation (WMI)
|
||||||
|
*/
|
||||||
namespace Pandora_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 isProcessRunning (string process_name);
|
||||||
int isServiceRunning (string service_name);
|
int isServiceRunning (string service_name);
|
||||||
|
|
|
@ -40,12 +40,24 @@ static void SetWindowsServiceStatus (DWORD dwCurrentState,
|
||||||
DWORD dwWaitHint);
|
DWORD dwWaitHint);
|
||||||
static void ErrorStopService (LPTSTR lpszAPI);
|
static void ErrorStopService (LPTSTR lpszAPI);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the values of the service to run.
|
||||||
|
*
|
||||||
|
* All the attributes are set to NULL.
|
||||||
|
*/
|
||||||
Windows_Service::Windows_Service () {
|
Windows_Service::Windows_Service () {
|
||||||
service_name = NULL;
|
service_name = NULL;
|
||||||
service_display_name = NULL;
|
service_display_name = NULL;
|
||||||
service_description = 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,
|
Windows_Service::Windows_Service (const char * svc_name,
|
||||||
const char * svc_display_name,
|
const char * svc_display_name,
|
||||||
const char * svc_description) {
|
const char * svc_description) {
|
||||||
|
@ -59,21 +71,44 @@ Windows_Service::Windows_Service (const char * svc_name,
|
||||||
current_service = this;
|
current_service = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the service
|
||||||
|
*/
|
||||||
Windows_Service::~Windows_Service () {
|
Windows_Service::~Windows_Service () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the function to run on service execution.
|
||||||
|
*
|
||||||
|
* @param f Pointer to execution function.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Windows_Service::setRunFunction (void (Windows_Service::*f) ()) {
|
Windows_Service::setRunFunction (void (Windows_Service::*f) ()) {
|
||||||
run_function = f;
|
run_function = f;
|
||||||
current_service->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
|
void
|
||||||
Windows_Service::setInitFunction (void (Windows_Service::*f) ()) {
|
Windows_Service::setInitFunction (void (Windows_Service::*f) ()) {
|
||||||
init_function = f;
|
init_function = f;
|
||||||
current_service->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
|
void
|
||||||
Windows_Service::execRunFunction () {
|
Windows_Service::execRunFunction () {
|
||||||
if (run_function != NULL) {
|
if (run_function != NULL) {
|
||||||
|
@ -86,6 +121,9 @@ Windows_Service::execRunFunction () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exec the init function.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Windows_Service::execInitFunction () {
|
Windows_Service::execInitFunction () {
|
||||||
if (init_function != NULL) {
|
if (init_function != NULL) {
|
||||||
|
@ -93,17 +131,36 @@ Windows_Service::execInitFunction () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the internal service name.
|
||||||
|
*
|
||||||
|
* @return The internal service name.
|
||||||
|
*/
|
||||||
LPSTR
|
LPSTR
|
||||||
Windows_Service::getServiceName () {
|
Windows_Service::getServiceName () {
|
||||||
return service_name;
|
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
|
void
|
||||||
Windows_Service::setSleepTime (unsigned int s) {
|
Windows_Service::setSleepTime (unsigned int s) {
|
||||||
sleep_time = s;
|
sleep_time = s;
|
||||||
current_service->sleep_time = sleep_time;
|
current_service->sleep_time = sleep_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install the service in the Windows services system.
|
||||||
|
*
|
||||||
|
* @param application_binary_path Path to binary file.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Windows_Service::install (LPCTSTR application_binary_path) {
|
Windows_Service::install (LPCTSTR application_binary_path) {
|
||||||
SC_HANDLE sc_manager;
|
SC_HANDLE sc_manager;
|
||||||
|
@ -225,6 +282,9 @@ Windows_Service::install (LPCTSTR application_binary_path) {
|
||||||
CloseServiceHandle (sc_manager);
|
CloseServiceHandle (sc_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uninstall the service from the system.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Windows_Service::uninstall () {
|
Windows_Service::uninstall () {
|
||||||
SC_HANDLE sc_manager, sc_service;
|
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 () {
|
Windows_Service::run () {
|
||||||
SERVICE_TABLE_ENTRY ste_dispatch_table[] =
|
SERVICE_TABLE_ENTRY ste_dispatch_table[] =
|
||||||
{
|
{
|
||||||
|
@ -353,8 +418,6 @@ Windows_Service::run () {
|
||||||
memset (msg, sizeof (msg), '\0');
|
memset (msg, sizeof (msg), '\0');
|
||||||
svc_format_message (msg, sizeof (msg));
|
svc_format_message (msg, sizeof (msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WINAPI
|
static void WINAPI
|
||||||
|
|
|
@ -25,57 +25,44 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsvc.h> /* for Service stuff */
|
#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 {
|
class Windows_Service {
|
||||||
protected:
|
private:
|
||||||
char *service_name;
|
char *service_name;
|
||||||
char *service_display_name;
|
char *service_display_name;
|
||||||
char *service_description;
|
char *service_description;
|
||||||
HANDLE stop_event;
|
HANDLE stop_event;
|
||||||
int sleep_time;
|
int sleep_time;
|
||||||
SC_HANDLE sc_service;
|
SC_HANDLE sc_service;
|
||||||
/* Pointer to functions that will run the service */
|
|
||||||
void (Windows_Service::*run_function) ();
|
void (Windows_Service::*run_function) ();
|
||||||
void (Windows_Service::*init_function) ();
|
void (Windows_Service::*init_function) ();
|
||||||
public:
|
public:
|
||||||
Windows_Service ();
|
Windows_Service ();
|
||||||
|
|
||||||
/* Set the values of the service to run.
|
Windows_Service (const char * svc_name,
|
||||||
Notice: A program can have ONLY ONE object of this class. */
|
const char * svc_display_name,
|
||||||
Windows_Service (const char * svc_name, const char * svc_display_name,
|
const char * svc_description);
|
||||||
const char * svc_description);
|
|
||||||
|
|
||||||
~Windows_Service ();
|
~Windows_Service ();
|
||||||
|
|
||||||
/* Install the service in the Windows registry. */
|
void install (LPCTSTR application_binary_path);
|
||||||
void install (LPCTSTR application_binary_path);
|
void uninstall ();
|
||||||
|
void run ();
|
||||||
/* Uninstall the service, removint the key in the Windows registry. */
|
void setRunFunction (void (Windows_Service::*f) ());
|
||||||
void uninstall ();
|
void setInitFunction (void (Windows_Service::*f) ());
|
||||||
|
LPSTR getServiceName ();
|
||||||
/* Run the service, which has to be installed previously.
|
void setSleepTime (unsigned int s);
|
||||||
* 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) ());
|
|
||||||
|
|
||||||
/* Calls the functions. There's no need to be called from the outside of this
|
void execRunFunction ();
|
||||||
* class. They are used in a internal method because of another Windows
|
void execInitFunction ();
|
||||||
* 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);
|
|
||||||
};
|
};
|
||||||
#endif /* __WINDOWS_SERVICE_H__ */
|
#endif /* __WINDOWS_SERVICE_H__ */
|
||||||
|
|
Loading…
Reference in New Issue