2006-06-20 19:05:19 +02:00
|
|
|
/* Library to manage a list of key-value options.
|
|
|
|
|
2023-06-23 23:37:27 +02:00
|
|
|
Copyright (c) 2006-2021 Pandora FMS.
|
2006-06-20 19:05:19 +02:00
|
|
|
Written by Esteban Sanchez.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include "pandora_agent_conf.h"
|
2010-07-13 19:24:00 +02:00
|
|
|
#include "pandora_strutils.h"
|
|
|
|
#include <iostream>
|
2006-06-20 19:05:19 +02:00
|
|
|
#include "pandora.h"
|
|
|
|
|
|
|
|
using namespace std;
|
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
2006-08-25 15:02:03 +02:00
|
|
|
using namespace Pandora;
|
2010-07-13 19:24:00 +02:00
|
|
|
using namespace Pandora_Strutils;
|
2006-06-20 19:05:19 +02:00
|
|
|
|
|
|
|
#define MAX_KEYS 100
|
|
|
|
|
2008-04-02 18:01:35 +02:00
|
|
|
Pandora::Pandora_Agent_Conf::Pandora_Agent_Conf () {
|
2008-11-26 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.cc, pandora_strutils.h, ftp/pandora_ftp_client.cc,
ftp/pandora_ftp_test.cc, ftp/pandora_ftp_client.h,
ftp/pandora_ftp_test.h, windows/pandora_windows_info.h,
windows/pandora_wmi.cc, windows/pandora_windows_info.cc,
misc/pandora_file.cc, misc/pandora_file.h, pandora_agent_conf.cc,
ssh/pandora_ssh_client.cc, ssh/pandora_ssh_test.cc,
ssh/pandora_ssh_client.h, ssh/pandora_ssh_test.h,
pandora_agent_conf.h, windows_service.cc, windows_service.h,
modules/pandora_module.h, modules/pandora_module_logevent.cc,
modules/pandora_module_exec.cc, modules/pandora_module_logevent.h,
modules/pandora_module_exec.h, modules/pandora_module_freedisk.cc,
modules/pandora_module_freedisk.h, modules/pandora_module_service.cc,
modules/pandora_module_service.h, modules/pandora_module_proc.cc,
modules/pandora_data.cc, modules/pandora_module_proc.h,
modules/pandora_data.h, modules/pandora_module_factory.cc,
modules/pandora_module_odbc.cc, modules/pandora_module_odbc.h,
modules/pandora_module_factory.h,
modules/pandora_module_freememory.cc, modules/pandora_module_list.cc,
modules/pandora_module_freememory.h,
modules/pandora_module_cpuusage.cc, modules/pandora_module_cpuusage.h,
modules/pandora_module.cc, pandora.h: Tab style correction.
Indentation blankspaces moved to tab characters.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-11-26 11:08:19 +01:00
|
|
|
this->key_values = NULL;
|
2010-07-13 19:24:00 +02:00
|
|
|
this->collection_list = NULL;
|
2014-10-17 16:39:30 +02:00
|
|
|
this->broker_enabled = false;
|
2008-04-02 18:01:35 +02:00
|
|
|
}
|
|
|
|
|
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
2006-08-25 15:02:03 +02:00
|
|
|
/**
|
2008-04-02 18:01:35 +02:00
|
|
|
* Destroy a Pandora_Agent_Conf object.
|
|
|
|
*/
|
|
|
|
Pandora::Pandora_Agent_Conf::~Pandora_Agent_Conf () {
|
2008-11-26 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.cc, pandora_strutils.h, ftp/pandora_ftp_client.cc,
ftp/pandora_ftp_test.cc, ftp/pandora_ftp_client.h,
ftp/pandora_ftp_test.h, windows/pandora_windows_info.h,
windows/pandora_wmi.cc, windows/pandora_windows_info.cc,
misc/pandora_file.cc, misc/pandora_file.h, pandora_agent_conf.cc,
ssh/pandora_ssh_client.cc, ssh/pandora_ssh_test.cc,
ssh/pandora_ssh_client.h, ssh/pandora_ssh_test.h,
pandora_agent_conf.h, windows_service.cc, windows_service.h,
modules/pandora_module.h, modules/pandora_module_logevent.cc,
modules/pandora_module_exec.cc, modules/pandora_module_logevent.h,
modules/pandora_module_exec.h, modules/pandora_module_freedisk.cc,
modules/pandora_module_freedisk.h, modules/pandora_module_service.cc,
modules/pandora_module_service.h, modules/pandora_module_proc.cc,
modules/pandora_data.cc, modules/pandora_module_proc.h,
modules/pandora_data.h, modules/pandora_module_factory.cc,
modules/pandora_module_odbc.cc, modules/pandora_module_odbc.h,
modules/pandora_module_factory.h,
modules/pandora_module_freememory.cc, modules/pandora_module_list.cc,
modules/pandora_module_freememory.h,
modules/pandora_module_cpuusage.cc, modules/pandora_module_cpuusage.h,
modules/pandora_module.cc, pandora.h: Tab style correction.
Indentation blankspaces moved to tab characters.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-11-26 11:08:19 +01:00
|
|
|
delete key_values;
|
2010-07-13 19:24:00 +02:00
|
|
|
delete collection_list;
|
2008-04-02 18:01:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Pandora_Agent_Conf *
|
|
|
|
Pandora::Pandora_Agent_Conf::getInstance () {
|
|
|
|
static Pandora_Agent_Conf *conf = NULL;
|
|
|
|
|
|
|
|
if (conf)
|
|
|
|
return conf;
|
|
|
|
conf = new Pandora_Agent_Conf ();
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
2011-06-08 16:12:57 +02:00
|
|
|
/**
|
|
|
|
* Additional configuration file.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::parseFile(string path_file, Collection *aux){
|
|
|
|
ifstream file_conf (path_file.c_str ());
|
|
|
|
string buffer;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2011-06-08 16:12:57 +02:00
|
|
|
|
|
|
|
if (!file_conf.is_open ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read and set the file */
|
|
|
|
while (!file_conf.eof ()) {
|
|
|
|
/* Set the value from each line */
|
|
|
|
getline (file_conf, buffer);
|
|
|
|
|
|
|
|
/* Ignore blank or commented lines */
|
|
|
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
|
|
|
/*Check if is a collection*/
|
|
|
|
pos = buffer.find("file_collection");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
string collection_name, trimmed_str;
|
|
|
|
|
|
|
|
/*Add collection to collection_list*/
|
|
|
|
/*The number 15 is the number of character of string file_collection*/
|
|
|
|
collection_name = buffer.substr(pos+15);
|
|
|
|
|
|
|
|
|
|
|
|
aux = new Collection();
|
|
|
|
|
|
|
|
aux->name = trim (collection_name);
|
|
|
|
|
|
|
|
/*Check for ".." substring for security issues*/
|
|
|
|
if ( collection_name.find("..") == string::npos ) {
|
|
|
|
aux->verify = 0;
|
|
|
|
collection_list->push_back (*aux);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_conf.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
/**
|
|
|
|
* Create configuration file for drone agents.
|
|
|
|
* @param filename Configuration file to open.
|
|
|
|
* @param path_broker Configuration file to write.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
writeBrokerConf(string path_broker, string filename, string name_broker){
|
|
|
|
ifstream file_conf (filename.c_str ());
|
2011-09-06 15:59:35 +02:00
|
|
|
ofstream file_broker ((Pandora::getPandoraInstallDir ()+path_broker).c_str ());
|
2011-07-11 17:49:29 +02:00
|
|
|
string buffer;
|
|
|
|
string comp;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2011-09-16 14:35:18 +02:00
|
|
|
int i;
|
|
|
|
int ok;
|
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
/* Read and set the file */
|
|
|
|
while (!file_conf.eof ()) {
|
|
|
|
/* Set the value from each line */
|
|
|
|
getline (file_conf, buffer);
|
|
|
|
|
|
|
|
pos = buffer.find("agent_name");
|
|
|
|
if (pos != string::npos){
|
2011-09-16 14:35:18 +02:00
|
|
|
ok = 1;
|
|
|
|
|
|
|
|
for(i=0; i < pos; i++) {
|
|
|
|
|
|
|
|
if(buffer[i] != ' ' && buffer[i] != '\t' && buffer[i] != '#') {
|
|
|
|
ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ok) {
|
2011-07-11 17:49:29 +02:00
|
|
|
buffer = "agent_name "+name_broker+"\n";
|
2011-09-16 14:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-11 17:49:29 +02:00
|
|
|
|
|
|
|
pos = buffer.find("broker_agent");
|
|
|
|
if (pos != string::npos){
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
buffer = buffer + "\n";
|
|
|
|
}
|
|
|
|
file_broker << buffer;
|
|
|
|
|
|
|
|
}
|
|
|
|
file_conf.close ();
|
|
|
|
file_broker.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::setFile (string *all_conf){
|
|
|
|
string buffer, filename;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2011-07-11 17:49:29 +02:00
|
|
|
Collection *aux;
|
|
|
|
|
|
|
|
filename = Pandora::getPandoraInstallDir ();
|
|
|
|
filename += "pandora_agent.conf";
|
2011-07-14 10:58:18 +02:00
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
ifstream file (filename.c_str ());
|
|
|
|
|
|
|
|
if (this->key_values)
|
|
|
|
delete this->key_values;
|
|
|
|
this->key_values = new list<Key_Value> ();
|
|
|
|
|
|
|
|
if (this->collection_list)
|
|
|
|
delete this->collection_list;
|
|
|
|
this->collection_list = new list<Collection> ();
|
|
|
|
|
|
|
|
if (!file.is_open ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read and set the file */
|
|
|
|
while (!file.eof ()) {
|
|
|
|
/* Set the value from each line */
|
|
|
|
getline (file, buffer);
|
|
|
|
|
|
|
|
/* Ignore blank or commented lines */
|
|
|
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
|
|
|
/*Check if is a include*/
|
|
|
|
pos = buffer.find("include");
|
|
|
|
if (pos != string::npos){
|
|
|
|
string path_file;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos_c;
|
2011-07-11 17:49:29 +02:00
|
|
|
|
|
|
|
path_file = buffer.substr(pos+8);
|
|
|
|
|
|
|
|
pos_c = path_file.find("\"");
|
|
|
|
/* Remove " */
|
|
|
|
while (pos_c != string::npos){
|
|
|
|
path_file.replace(pos_c, 1, "");
|
|
|
|
pos_c = path_file.find("\"",pos_c+1);
|
|
|
|
}
|
|
|
|
parseFile(path_file, aux);
|
|
|
|
}
|
|
|
|
/*Check if is a broker_agent*/
|
|
|
|
pos = buffer.find("broker_agent");
|
|
|
|
if (pos != string::npos){
|
|
|
|
string path_broker, name_broker;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos_c;
|
2011-07-11 17:49:29 +02:00
|
|
|
int position = 0;
|
2014-10-17 16:39:30 +02:00
|
|
|
this->broker_enabled = true;
|
2011-07-11 17:49:29 +02:00
|
|
|
|
|
|
|
name_broker = buffer.substr(pos+13);
|
|
|
|
path_broker = name_broker+".conf";
|
|
|
|
|
|
|
|
all_conf[position] = Pandora::getPandoraInstallDir () + path_broker;
|
|
|
|
position += 1;
|
|
|
|
|
2011-09-06 15:59:35 +02:00
|
|
|
ifstream file_br ((Pandora::getPandoraInstallDir () + path_broker).c_str ());
|
2011-07-11 17:49:29 +02:00
|
|
|
/* Check if already exists the configuration file*/
|
2011-09-06 15:59:35 +02:00
|
|
|
if (!file_br.is_open()){
|
2011-07-11 17:49:29 +02:00
|
|
|
writeBrokerConf(path_broker, filename, name_broker);
|
2011-09-06 15:59:35 +02:00
|
|
|
} else {
|
|
|
|
file_br.close();
|
|
|
|
}
|
2011-07-11 17:49:29 +02:00
|
|
|
}
|
|
|
|
|
2014-11-16 04:04:00 +01:00
|
|
|
/*Check if is a agent_name_cmd"*/
|
|
|
|
pos = buffer.find("agent_name_cmd");
|
|
|
|
if (pos != string::npos){
|
|
|
|
Key_Value kv;
|
|
|
|
kv.parseLineByPosition(buffer, 14);
|
|
|
|
key_values->push_back (kv);
|
|
|
|
continue;
|
|
|
|
}
|
2017-04-17 12:50:46 +02:00
|
|
|
|
|
|
|
/*Check if is a agent_alias_cmd"*/
|
|
|
|
pos = buffer.find("agent_alias_cmd");
|
|
|
|
if (pos != string::npos){
|
|
|
|
Key_Value kv;
|
|
|
|
kv.parseLineByPosition(buffer, 15);
|
|
|
|
key_values->push_back (kv);
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-16 04:04:00 +01:00
|
|
|
|
2011-07-11 17:49:29 +02:00
|
|
|
/*Check if is a collection*/
|
|
|
|
pos = buffer.find("file_collection");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
string collection_name, trimmed_str;
|
|
|
|
|
|
|
|
/*Add collection to collection_list*/
|
|
|
|
/*The number 15 is the number of character of string file_collection*/
|
|
|
|
collection_name = buffer.substr(pos+15);
|
|
|
|
|
|
|
|
aux = new Collection();
|
|
|
|
|
|
|
|
aux->name = trim (collection_name);
|
|
|
|
|
|
|
|
/*Check for ".." substring for security issues*/
|
|
|
|
if ( collection_name.find("..") == string::npos ) {
|
|
|
|
aux->verify = 0;
|
|
|
|
collection_list->push_back (*aux);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*Check if is a module*/
|
|
|
|
pos = buffer.find ("module_");
|
|
|
|
if (pos == string::npos) {
|
|
|
|
Key_Value kv;
|
|
|
|
|
|
|
|
kv.parseLine (buffer);
|
|
|
|
key_values->push_back (kv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close ();
|
|
|
|
}
|
|
|
|
|
2008-04-02 18:01:35 +02:00
|
|
|
/**
|
|
|
|
* Sets configuration file to Pandora_Agent_Conf object instance.
|
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
2006-08-25 15:02:03 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-04-02 18:01:35 +02:00
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::setFile (string filename) {
|
|
|
|
ifstream file (filename.c_str ());
|
2008-11-26 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.cc, pandora_strutils.h, ftp/pandora_ftp_client.cc,
ftp/pandora_ftp_test.cc, ftp/pandora_ftp_client.h,
ftp/pandora_ftp_test.h, windows/pandora_windows_info.h,
windows/pandora_wmi.cc, windows/pandora_windows_info.cc,
misc/pandora_file.cc, misc/pandora_file.h, pandora_agent_conf.cc,
ssh/pandora_ssh_client.cc, ssh/pandora_ssh_test.cc,
ssh/pandora_ssh_client.h, ssh/pandora_ssh_test.h,
pandora_agent_conf.h, windows_service.cc, windows_service.h,
modules/pandora_module.h, modules/pandora_module_logevent.cc,
modules/pandora_module_exec.cc, modules/pandora_module_logevent.h,
modules/pandora_module_exec.h, modules/pandora_module_freedisk.cc,
modules/pandora_module_freedisk.h, modules/pandora_module_service.cc,
modules/pandora_module_service.h, modules/pandora_module_proc.cc,
modules/pandora_data.cc, modules/pandora_module_proc.h,
modules/pandora_data.h, modules/pandora_module_factory.cc,
modules/pandora_module_odbc.cc, modules/pandora_module_odbc.h,
modules/pandora_module_factory.h,
modules/pandora_module_freememory.cc, modules/pandora_module_list.cc,
modules/pandora_module_freememory.h,
modules/pandora_module_cpuusage.cc, modules/pandora_module_cpuusage.h,
modules/pandora_module.cc, pandora.h: Tab style correction.
Indentation blankspaces moved to tab characters.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-11-26 11:08:19 +01:00
|
|
|
string buffer;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2010-07-20 18:38:29 +02:00
|
|
|
Collection *aux;
|
2011-06-08 16:12:57 +02:00
|
|
|
|
2008-04-02 18:01:35 +02:00
|
|
|
if (this->key_values)
|
|
|
|
delete this->key_values;
|
2008-11-26 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.cc, pandora_strutils.h, ftp/pandora_ftp_client.cc,
ftp/pandora_ftp_test.cc, ftp/pandora_ftp_client.h,
ftp/pandora_ftp_test.h, windows/pandora_windows_info.h,
windows/pandora_wmi.cc, windows/pandora_windows_info.cc,
misc/pandora_file.cc, misc/pandora_file.h, pandora_agent_conf.cc,
ssh/pandora_ssh_client.cc, ssh/pandora_ssh_test.cc,
ssh/pandora_ssh_client.h, ssh/pandora_ssh_test.h,
pandora_agent_conf.h, windows_service.cc, windows_service.h,
modules/pandora_module.h, modules/pandora_module_logevent.cc,
modules/pandora_module_exec.cc, modules/pandora_module_logevent.h,
modules/pandora_module_exec.h, modules/pandora_module_freedisk.cc,
modules/pandora_module_freedisk.h, modules/pandora_module_service.cc,
modules/pandora_module_service.h, modules/pandora_module_proc.cc,
modules/pandora_data.cc, modules/pandora_module_proc.h,
modules/pandora_data.h, modules/pandora_module_factory.cc,
modules/pandora_module_odbc.cc, modules/pandora_module_odbc.h,
modules/pandora_module_factory.h,
modules/pandora_module_freememory.cc, modules/pandora_module_list.cc,
modules/pandora_module_freememory.h,
modules/pandora_module_cpuusage.cc, modules/pandora_module_cpuusage.h,
modules/pandora_module.cc, pandora.h: Tab style correction.
Indentation blankspaces moved to tab characters.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-11-26 11:08:19 +01:00
|
|
|
this->key_values = new list<Key_Value> ();
|
2010-07-13 19:24:00 +02:00
|
|
|
|
|
|
|
if (this->collection_list)
|
|
|
|
delete this->collection_list;
|
2010-07-20 18:38:29 +02:00
|
|
|
this->collection_list = new list<Collection> ();
|
2008-11-26 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.cc, pandora_strutils.h, ftp/pandora_ftp_client.cc,
ftp/pandora_ftp_test.cc, ftp/pandora_ftp_client.h,
ftp/pandora_ftp_test.h, windows/pandora_windows_info.h,
windows/pandora_wmi.cc, windows/pandora_windows_info.cc,
misc/pandora_file.cc, misc/pandora_file.h, pandora_agent_conf.cc,
ssh/pandora_ssh_client.cc, ssh/pandora_ssh_test.cc,
ssh/pandora_ssh_client.h, ssh/pandora_ssh_test.h,
pandora_agent_conf.h, windows_service.cc, windows_service.h,
modules/pandora_module.h, modules/pandora_module_logevent.cc,
modules/pandora_module_exec.cc, modules/pandora_module_logevent.h,
modules/pandora_module_exec.h, modules/pandora_module_freedisk.cc,
modules/pandora_module_freedisk.h, modules/pandora_module_service.cc,
modules/pandora_module_service.h, modules/pandora_module_proc.cc,
modules/pandora_data.cc, modules/pandora_module_proc.h,
modules/pandora_data.h, modules/pandora_module_factory.cc,
modules/pandora_module_odbc.cc, modules/pandora_module_odbc.h,
modules/pandora_module_factory.h,
modules/pandora_module_freememory.cc, modules/pandora_module_list.cc,
modules/pandora_module_freememory.h,
modules/pandora_module_cpuusage.cc, modules/pandora_module_cpuusage.h,
modules/pandora_module.cc, pandora.h: Tab style correction.
Indentation blankspaces moved to tab characters.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-11-26 11:08:19 +01:00
|
|
|
|
|
|
|
if (!file.is_open ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read and set the file */
|
|
|
|
while (!file.eof ()) {
|
|
|
|
/* Set the value from each line */
|
|
|
|
getline (file, buffer);
|
|
|
|
|
|
|
|
/* Ignore blank or commented lines */
|
|
|
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
2011-06-08 16:12:57 +02:00
|
|
|
/*Check if is a include*/
|
|
|
|
pos = buffer.find("include");
|
|
|
|
if (pos != string::npos){
|
|
|
|
string path_file;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos_c;
|
2011-06-08 16:12:57 +02:00
|
|
|
|
|
|
|
path_file = buffer.substr(pos+8);
|
|
|
|
|
|
|
|
pos_c = path_file.find("\"");
|
|
|
|
/* Remove " */
|
|
|
|
while (pos_c != string::npos){
|
|
|
|
path_file.replace(pos_c, 1, "");
|
|
|
|
pos_c = path_file.find("\"",pos_c+1);
|
|
|
|
}
|
|
|
|
parseFile(path_file, aux);
|
|
|
|
}
|
2011-07-11 17:49:29 +02:00
|
|
|
|
2010-07-13 19:24:00 +02:00
|
|
|
/*Check if is a collection*/
|
|
|
|
pos = buffer.find("file_collection");
|
|
|
|
if(pos != string::npos) {
|
|
|
|
string collection_name, trimmed_str;
|
|
|
|
|
|
|
|
/*Add collection to collection_list*/
|
|
|
|
/*The number 15 is the number of character of string file_collection*/
|
|
|
|
collection_name = buffer.substr(pos+15);
|
2010-07-20 18:38:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
aux = new Collection();
|
|
|
|
|
|
|
|
aux->name = trim (collection_name);
|
2010-07-21 12:03:20 +02:00
|
|
|
|
|
|
|
/*Check for ".." substring for security issues*/
|
|
|
|
if ( collection_name.find("..") == string::npos ) {
|
|
|
|
aux->verify = 0;
|
|
|
|
collection_list->push_back (*aux);
|
|
|
|
}
|
2010-07-13 19:24:00 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*Check if is a module*/
|
2008-11-26 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.cc, pandora_strutils.h, ftp/pandora_ftp_client.cc,
ftp/pandora_ftp_test.cc, ftp/pandora_ftp_client.h,
ftp/pandora_ftp_test.h, windows/pandora_windows_info.h,
windows/pandora_wmi.cc, windows/pandora_windows_info.cc,
misc/pandora_file.cc, misc/pandora_file.h, pandora_agent_conf.cc,
ssh/pandora_ssh_client.cc, ssh/pandora_ssh_test.cc,
ssh/pandora_ssh_client.h, ssh/pandora_ssh_test.h,
pandora_agent_conf.h, windows_service.cc, windows_service.h,
modules/pandora_module.h, modules/pandora_module_logevent.cc,
modules/pandora_module_exec.cc, modules/pandora_module_logevent.h,
modules/pandora_module_exec.h, modules/pandora_module_freedisk.cc,
modules/pandora_module_freedisk.h, modules/pandora_module_service.cc,
modules/pandora_module_service.h, modules/pandora_module_proc.cc,
modules/pandora_data.cc, modules/pandora_module_proc.h,
modules/pandora_data.h, modules/pandora_module_factory.cc,
modules/pandora_module_odbc.cc, modules/pandora_module_odbc.h,
modules/pandora_module_factory.h,
modules/pandora_module_freememory.cc, modules/pandora_module_list.cc,
modules/pandora_module_freememory.h,
modules/pandora_module_cpuusage.cc, modules/pandora_module_cpuusage.h,
modules/pandora_module.cc, pandora.h: Tab style correction.
Indentation blankspaces moved to tab characters.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-11-26 11:08:19 +01:00
|
|
|
pos = buffer.find ("module_");
|
|
|
|
if (pos == string::npos) {
|
|
|
|
Key_Value kv;
|
|
|
|
|
|
|
|
kv.parseLine (buffer);
|
|
|
|
key_values->push_back (kv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close ();
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2016-09-29 12:50:04 +02:00
|
|
|
/**
|
|
|
|
* Update a configuration value in the configuration file. If it is not found,
|
|
|
|
* it is appended at the end of the file.
|
|
|
|
*
|
|
|
|
* @param string key Name of the configuration option.
|
|
|
|
* @param string value New value.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::updateFile (string key, string value){
|
|
|
|
string buffer, filename, temp_filename;
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
/* Open the configuration file. */
|
|
|
|
filename = Pandora::getPandoraInstallDir ();
|
|
|
|
filename += "pandora_agent.conf";
|
|
|
|
ifstream file (filename.c_str ());
|
|
|
|
if (!file.is_open ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the temporary file. */
|
|
|
|
temp_filename = filename + ".tmp";
|
|
|
|
ofstream temp_file (temp_filename.c_str ());
|
|
|
|
if (!temp_file.is_open ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for the configuration value. */
|
|
|
|
bool found = false;
|
|
|
|
while (!file.eof ()) {
|
|
|
|
getline (file, buffer);
|
|
|
|
|
|
|
|
/* Copy the rest of the file if the key was found. */
|
|
|
|
if (found) {
|
|
|
|
temp_file << buffer << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We will only look for the key in the first three characters, hoping
|
|
|
|
to catch "key", "#key" and "# key". We would also catch "..key", but
|
|
|
|
no such keys exist in the configuration file. */
|
|
|
|
pos = buffer.find(key);
|
|
|
|
if (pos == std::string::npos || pos > 2) {
|
|
|
|
temp_file << buffer << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Match! */
|
|
|
|
found = true;
|
|
|
|
temp_file << key + " " + value << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the value at the end of the file if it was not found. */
|
|
|
|
if (!found) {
|
|
|
|
temp_file << key + " " + value << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Rename the temporary file. */
|
|
|
|
file.close ();
|
|
|
|
temp_file.close ();
|
|
|
|
remove(filename.c_str());
|
|
|
|
rename(temp_filename.c_str(), filename.c_str());
|
|
|
|
}
|
|
|
|
|
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
2006-08-25 15:02:03 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-06-20 19:05:19 +02:00
|
|
|
string
|
2007-08-07 16:28:14 +02:00
|
|
|
Pandora::Pandora_Agent_Conf::getValue (const string key)
|
|
|
|
{
|
2008-11-26 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.cc, pandora_strutils.h, ftp/pandora_ftp_client.cc,
ftp/pandora_ftp_test.cc, ftp/pandora_ftp_client.h,
ftp/pandora_ftp_test.h, windows/pandora_windows_info.h,
windows/pandora_wmi.cc, windows/pandora_windows_info.cc,
misc/pandora_file.cc, misc/pandora_file.h, pandora_agent_conf.cc,
ssh/pandora_ssh_client.cc, ssh/pandora_ssh_test.cc,
ssh/pandora_ssh_client.h, ssh/pandora_ssh_test.h,
pandora_agent_conf.h, windows_service.cc, windows_service.h,
modules/pandora_module.h, modules/pandora_module_logevent.cc,
modules/pandora_module_exec.cc, modules/pandora_module_logevent.h,
modules/pandora_module_exec.h, modules/pandora_module_freedisk.cc,
modules/pandora_module_freedisk.h, modules/pandora_module_service.cc,
modules/pandora_module_service.h, modules/pandora_module_proc.cc,
modules/pandora_data.cc, modules/pandora_module_proc.h,
modules/pandora_data.h, modules/pandora_module_factory.cc,
modules/pandora_module_odbc.cc, modules/pandora_module_odbc.h,
modules/pandora_module_factory.h,
modules/pandora_module_freememory.cc, modules/pandora_module_list.cc,
modules/pandora_module_freememory.h,
modules/pandora_module_cpuusage.cc, modules/pandora_module_cpuusage.h,
modules/pandora_module.cc, pandora.h: Tab style correction.
Indentation blankspaces moved to tab characters.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-11-26 11:08:19 +01:00
|
|
|
std::list<Key_Value>::iterator i;
|
|
|
|
|
|
|
|
for (i = key_values->begin (); i != key_values->end (); i++) {
|
|
|
|
if ((*i).getKey () == key) {
|
|
|
|
return (*i).getValue ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
2006-06-20 19:05:19 +02:00
|
|
|
}
|
|
|
|
|
2016-09-29 12:50:04 +02:00
|
|
|
/**
|
|
|
|
* Sets a configuration value.
|
|
|
|
*
|
|
|
|
* @param key Key to look for.
|
|
|
|
* @param string New value.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::setValue (const string key, const string value)
|
|
|
|
{
|
|
|
|
std::list<Key_Value>::iterator i;
|
|
|
|
|
|
|
|
// Update.
|
|
|
|
for (i = this->key_values->begin (); i != this->key_values->end (); i++) {
|
|
|
|
if ((*i).getKey () == key) {
|
|
|
|
(*i).setValue (value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append.
|
|
|
|
Key_Value kv;
|
|
|
|
kv.setKey(key);
|
|
|
|
kv.setValue(value);
|
|
|
|
this->key_values->push_back (kv);
|
|
|
|
}
|
|
|
|
|
2010-07-14 19:16:08 +02:00
|
|
|
/**
|
|
|
|
* Queries for a collection name.
|
|
|
|
*
|
|
|
|
* This method returns the name of the current
|
|
|
|
* collection pointed by an iterator.
|
|
|
|
*
|
|
|
|
* @return The name of the current colletion
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
string
|
2010-07-20 18:38:29 +02:00
|
|
|
Pandora::Pandora_Agent_Conf::getCurrentCollectionName() {
|
2010-07-14 19:16:08 +02:00
|
|
|
string aux;
|
2010-07-20 18:38:29 +02:00
|
|
|
aux = collection_it->name;
|
2010-07-14 19:16:08 +02:00
|
|
|
return aux;
|
|
|
|
}
|
|
|
|
|
2010-07-20 18:38:29 +02:00
|
|
|
/**
|
|
|
|
* Queries for a collection check of added to PATH.
|
|
|
|
*
|
|
|
|
* This method returns 1 if the collections is in the PATH
|
|
|
|
*
|
|
|
|
* @return 1 if the collections is added to PATH
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
unsigned char
|
|
|
|
Pandora::Pandora_Agent_Conf::getCurrentCollectionVerify() {
|
|
|
|
unsigned char aux;
|
|
|
|
aux = collection_it->verify;
|
|
|
|
return aux;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set check path add field to 1.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::setCurrentCollectionVerify() {
|
|
|
|
collection_it->verify = 1;
|
|
|
|
}
|
|
|
|
|
2010-07-21 12:03:20 +02:00
|
|
|
/**
|
|
|
|
* Check is there is a collection with the same name in the list
|
|
|
|
*
|
|
|
|
* @param The name of the collection to check.
|
|
|
|
*
|
|
|
|
* @return True if there is a collection with the same name.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
Pandora::Pandora_Agent_Conf::isInCollectionList(string name) {
|
|
|
|
list<Collection>::iterator p;
|
|
|
|
string name_md5;
|
|
|
|
for (p = collection_list->begin();p != collection_list->end();p++) {
|
|
|
|
name_md5 = p->name+".md5";
|
|
|
|
if ( (strcmp(p->name.c_str(), name.c_str()) == 0) ||
|
|
|
|
(strcmp(name_md5.c_str(), name.c_str()) == 0)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-14 19:16:08 +02:00
|
|
|
/**
|
|
|
|
* Set iterator pointing to the first collection of the list.
|
|
|
|
*
|
|
|
|
* This method set the iterator pointing to the first collection of the list.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::goFirstCollection() {
|
|
|
|
collection_it = collection_list->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the collection iterator to the next item
|
|
|
|
*
|
|
|
|
* This method move the iterator to the next item.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Pandora::Pandora_Agent_Conf::goNextCollection() {
|
|
|
|
this->collection_it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare the iterator with the last collection.
|
|
|
|
*
|
|
|
|
* This method return true if the iterator is pointing to the last collection
|
|
|
|
*
|
|
|
|
* @return True if the iterator is pointing to the last collection
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
Pandora::Pandora_Agent_Conf::isLastCollection() {
|
|
|
|
return collection_it == collection_list->end();
|
|
|
|
}
|
2014-10-17 16:39:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether there are broker agents configured.
|
|
|
|
*
|
|
|
|
* @return True if there is at least one broker agent.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
Pandora::Pandora_Agent_Conf::isBrokerEnabled() {
|
|
|
|
return this->broker_enabled;
|
|
|
|
}
|