2011-11-29 Ramon Novoa <rnovoa@artica.es>

* modules/pandora_module.h,
	  modules/pandora_module_exec.cc,
	  modules/pandora_module_exec.h,
	  modules/pandora_module_list.cc,
	  modules/pandora_module_factory.cc,
	  modules/pandora_module.cc,
	  Makefile.am: Added native ping and SNMP get modules that wrap the
	  calls to ping.exe and snmpget.exe.

	* modules/pandora_module_ping.h,
	  modules/pandora_module_snmpget.h,
	  modules/pandora_module_ping.cc,
	  modules/pandora_module_snmpget.cc: Added to repository. Ping and
	  SNMP get modules.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5203 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2011-11-29 13:19:34 +00:00
parent f3d48b37b8
commit 7544bac9a9
12 changed files with 289 additions and 19 deletions

View File

@ -1,3 +1,20 @@
2011-11-29 Ramon Novoa <rnovoa@artica.es>
* modules/pandora_module.h,
modules/pandora_module_exec.cc,
modules/pandora_module_exec.h,
modules/pandora_module_list.cc,
modules/pandora_module_factory.cc,
modules/pandora_module.cc,
Makefile.am: Added native ping and SNMP get modules that wrap the
calls to ping.exe and snmpget.exe.
* modules/pandora_module_ping.h,
modules/pandora_module_snmpget.h,
modules/pandora_module_ping.cc,
modules/pandora_module_snmpget.cc: Added to repository. Ping and
SNMP get modules.
2011-11-29 Ramon Novoa <rnovoa@artica.es>
* bin/PandoraAgent.exe: Updated to current revision.

View File

@ -1,9 +1,9 @@
bin_PROGRAMS = PandoraAgent
if DEBUG
PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_odbc.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc debug_new.cpp
PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_odbc.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc debug_new.cpp
PandoraAgent_CXXFLAGS=-g -O0 -DCURL_STATICLIB -D__DEBUG__
else
PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_odbc.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc
PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_odbc.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc
PandoraAgent_CXXFLAGS=-O2 -DCURL_STATICLIB
endif
PandoraAgent_LDFLAGS=-static-libgcc -static-libstdc++

View File

@ -218,6 +218,10 @@ Pandora_Module::parseModuleKindFromString (string kind) {
return MODULE_REGEXP;
} else if (kind == module_plugin_str) {
return MODULE_PLUGIN;
} else if (kind == module_ping_str) {
return MODULE_PING;
} else if (kind == module_snmpget_str) {
return MODULE_SNMPGET;
} else {
return MODULE_0;
}

View File

@ -86,7 +86,9 @@ namespace Pandora_Modules {
MODULE_PERFCOUNTER, /**< The module reads performance counters */
MODULE_TCPCHECK, /**< The module checks whether a tcp port is open */
MODULE_REGEXP, /**< The module searches a file for matches of a regular expression */
MODULE_PLUGIN /**< Plugin */
MODULE_PLUGIN, /**< Plugin */
MODULE_PING, /**< Ping module */
MODULE_SNMPGET /**< SNMP get module */
} Module_Kind;
/**
@ -137,8 +139,10 @@ namespace Pandora_Modules {
const string module_perfcounter_str = "module_perfcounter";
const string module_tcpcheck_str = "module_tcpcheck";
const string module_regexp_str = "module_regexp";
const string module_plugin_str = "module_plugin";
const string module_plugin_str = "module_plugin";
const string module_ping_str = "module_ping";
const string module_snmpget_str = "module_snmpget";
/**
* Pandora module super-class exception.
*/

View File

@ -37,7 +37,7 @@ using namespace Pandora_Modules;
Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec)
: Pandora_Module (name) {
this->module_exec = "cmd.exe /c \"" + exec + "\"";
this->proc = 0;
this->setKind (module_exec_str);
}
@ -148,18 +148,28 @@ Pandora_Module_Exec::run () {
pandoraLog ("TerminateJobObject failed. (error %d)",
GetLastError ());
}
if (retval != STILL_ACTIVE) {
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
this->module_name.c_str (), retval);
}
this->has_output = false;
if (retval != STILL_ACTIVE && this->proc == 0) {
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
this->module_name.c_str (), retval);
}
this->has_output = false;
}
if (!output.empty()) {
this->setOutput (output);
} else {
this->setOutput ("");
}
// Proc mode
if (this->proc == 1) {
if (retval == 0) {
this->setOutput ("1");
} else {
this->setOutput ("0");
this->has_output = true;
}
}
// Command output mode
else if (!output.empty()) {
this->setOutput (output);
} else {
this->setOutput ("");
}
/* Close job, process and thread handles. */
CloseHandle (job);

View File

@ -35,6 +35,7 @@ namespace Pandora_Modules {
private:
string module_exec;
public:
unsigned char proc;
Pandora_Module_Exec (string name, string exec);
void run ();

View File

@ -36,6 +36,8 @@
#include "pandora_module_tcpcheck.h"
#include "pandora_module_regexp.h"
#include "pandora_module_plugin.h"
#include "pandora_module_ping.h"
#include "pandora_module_snmpget.h"
#include "../pandora_strutils.h"
#include <list>
@ -93,6 +95,15 @@ using namespace Pandora_Strutils;
#define TOKEN_CRONINTERVAL ("module_cron_interval ")
#define TOKEN_PRECONDITION ("module_precondition ")
#define TOKEN_NOSEEKEOF ("module_noseekeof ")
#define TOKEN_PING ("module_ping ")
#define TOKEN_PING_COUNT ("module_ping_count ")
#define TOKEN_PING_TIMEOUT ("module_ping_timeout ")
#define TOKEN_SNMPGET ("module_snmpget")
#define TOKEN_SNMPVERSION ("module_snmp_version ")
#define TOKEN_SNMPCOMMUNITY ("module_snmp_community ")
#define TOKEN_SNMPAGENT ("module_snmp_agent ")
#define TOKEN_SNMPOID ("module_snmp_oid ")
#define TOKEN_ADVANCEDOPTIONS ("module_advanced_options ")
string
parseLine (string line, string token) {
@ -139,6 +150,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
string module_crontab, module_cron_interval, module_post_process;
string module_min_critical, module_max_critical, module_min_warning, module_max_warning;
string module_disabled, module_min_ff_event, module_noseekeof;
string module_ping, module_ping_count, module_ping_timeout;
string module_snmpget, module_snmp_version, module_snmp_community, module_snmp_agent, module_snmp_oid;
string module_advanced_options;
Pandora_Module *module;
bool numeric;
Module_Type type;
@ -191,8 +205,17 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module_max_warning = "";
module_disabled = "";
module_min_ff_event = "";
module_noseekeof = "";
module_noseekeof = "";
module_ping = "";
module_ping_count = "";
module_ping_timeout = "";
module_snmpget = "";
module_snmp_version = "";
module_snmp_community = "";
module_snmp_agent = "";
module_snmp_oid = "";
module_advanced_options = "";
stringtok (tokens, definition, "\n");
/* Pick the first and the last value of the token list */
@ -364,7 +387,33 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_noseekeof == "") {
module_noseekeof = parseLine (line, TOKEN_NOSEEKEOF);
}
if (module_ping == "") {
module_ping = parseLine (line, TOKEN_PING);
}
if (module_ping_count == "") {
module_ping_count = parseLine (line, TOKEN_PING_COUNT);
}
if (module_ping_timeout == "") {
module_ping_timeout = parseLine (line, TOKEN_PING_TIMEOUT);
}
if (module_snmpget == "") {
module_snmpget = parseLine (line, TOKEN_SNMPGET);
}
if (module_snmp_version == "") {
module_snmp_version = parseLine (line, TOKEN_SNMPVERSION);
}
if (module_snmp_community == "") {
module_snmp_community = parseLine (line, TOKEN_SNMPCOMMUNITY);
}
if (module_snmp_agent == "") {
module_snmp_agent = parseLine (line, TOKEN_SNMPAGENT);
}
if (module_snmp_oid == "") {
module_snmp_oid = parseLine (line, TOKEN_SNMPOID);
}
if (module_advanced_options == "") {
module_advanced_options = parseLine (line, TOKEN_ADVANCEDOPTIONS);
}
iter++;
}
@ -455,6 +504,34 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module = new Pandora_Module_Regexp (module_name, module_regexp, module_pattern, (unsigned char) atoi (module_noseekeof.c_str ()));
} else if (module_plugin != "") {
module = new Pandora_Module_Plugin (module_name, module_plugin);
} else if (module_ping != "") {
if (module_ping_count == "") {
module_ping_count = "1";
}
if (module_ping_timeout == "") {
module_ping_timeout = "1000";
}
module = new Pandora_Module_Ping (module_name, module_ping, module_ping_count, module_ping_timeout, module_advanced_options);
if (module_timeout != "") {
module->setTimeout (atoi (module_timeout.c_str ()));
}
} else if (module_snmpget != "") {
if (module_snmp_version == "") {
module_snmp_version = "1";
}
if (module_snmp_community == "") {
module_snmp_community = "public";
}
if (module_snmp_agent == "") {
module_snmp_agent = "localhost";
}
module = new Pandora_Module_SNMPGet (module_name, module_snmp_version, module_snmp_community, module_snmp_agent, module_snmp_oid, module_advanced_options);
if (module_timeout != "") {
module->setTimeout (atoi (module_timeout.c_str ()));
}
} else {
return NULL;
}

View File

@ -36,6 +36,8 @@
#include "pandora_module_tcpcheck.h"
#include "pandora_module_regexp.h"
#include "pandora_module_plugin.h"
#include "pandora_module_ping.h"
#include "pandora_module_snmpget.h"
#include <fstream>
using namespace std;
@ -231,6 +233,8 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition)
Pandora_Module_Tcpcheck *module_tcpcheck;
Pandora_Module_Regexp *module_regexp;
Pandora_Module_Plugin *module_plugin;
Pandora_Module_Ping *module_ping;
Pandora_Module_SNMPGet *module_snmpget;
module = Pandora_Module_Factory::getModuleFromDefinition (definition);
@ -310,6 +314,14 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition)
module_plugin = (Pandora_Module_Plugin *) module;
modules->push_back (module_plugin);
break;
case MODULE_PING:
module_ping = (Pandora_Module_Ping *) module;
modules->push_back (module_ping);
break;
case MODULE_SNMPGET:
module_snmpget = (Pandora_Module_SNMPGet *) module;
modules->push_back (module_snmpget);
break;
default:
break;
}

View File

@ -0,0 +1,37 @@
/* Pandora ping module. These modules ping a command.
Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "pandora_module_ping.h"
using namespace Pandora;
using namespace Pandora_Modules;
/**
* Creates a Pandora_Module_Ping object.
*
* @param name Module name
* @param host Host to be pinged.
*/
Pandora_Module_Ping::Pandora_Module_Ping (string name, string host, string count, string timeout, string advanced_options)
: Pandora_Module_Exec (name, "ping -n " + count + " -w " + timeout + " " + advanced_options + " " + host) {
this->proc = 1;
this->setKind (module_ping_str);
}

View File

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

View File

@ -0,0 +1,36 @@
/* Pandora SNMPGet module. These modules SNMPGet a command.
Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "pandora_module_snmpget.h"
using namespace Pandora;
using namespace Pandora_Modules;
/**
* Creates a Pandora_Module_SNMPGet object.
*
* @param name Module name
* @param host Host to be SNMPGeted.
*/
Pandora_Module_SNMPGet::Pandora_Module_SNMPGet (string name, string version, string community, string agent, string oid, string advanced_options)
: Pandora_Module_Exec (name, "snmpget.exe -v " + version + " -c " + community + " " + advanced_options + " " + agent + " " + oid + " 2>nul | tail.exe -1 | cut.exe -d\" \" -f 4- | tr.exe -d \\\"\\n") {
this->setKind (module_snmpget_str);
}

View File

@ -0,0 +1,36 @@
/* Pandora SNMPGet module. These modules SNMPGet a command
Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PANDORA_MODULE_SNMPGet_H__
#define __PANDORA_MODULE_SNMPGet_H__
#include "pandora_module_exec.h"
namespace Pandora_Modules {
/**
* Module to execute an SNMP get request.
*/
class Pandora_Module_SNMPGet : public Pandora_Module_Exec {
public:
Pandora_Module_SNMPGet (string name, string version, string community, string agent, string oid, string advanced_options);
};
}
#endif