2008-02-25 Sancho Lerena <slerena@gmail.com>
* conf/pandora_server.conf: Added new tokens. * lib/PandoraFMS/Config.pm: Code cleanup and add support for new prediction and plugin server. Added better checks to clean blank spaces inside config tokens. * lib/PandoraFMS/DB.pm: Added comment to the only generic function to database we have. * lib/PandoraFMS/Tools.pm: Created a new function to clean blank spaces, and used to clean setup file parsing. * bin/pandora_plugin: New plugin server skeleton, not functional yet. Need much more improvement, but code skeleton is done. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@725 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a516087894
commit
92f5f37291
|
@ -1,3 +1,19 @@
|
|||
2008-02-25 Sancho Lerena <slerena@gmail.com>
|
||||
|
||||
* conf/pandora_server.conf: Added new tokens.
|
||||
|
||||
* lib/PandoraFMS/Config.pm: Code cleanup and add support for
|
||||
new prediction and plugin server. Added better checks to clean
|
||||
blank spaces inside config tokens.
|
||||
|
||||
* lib/PandoraFMS/DB.pm: Added comment to the only generic function
|
||||
to database we have.
|
||||
|
||||
* lib/PandoraFMS/Tools.pm: Created a new function to clean
|
||||
blank spaces, and used to clean setup file parsing.
|
||||
|
||||
* bin/pandora_plugin: New plugin server skeleton, not functional
|
||||
yet. Need much more improvement, but code skeleton is done.
|
||||
|
||||
2008-02-20 Sancho Lerena <slerena@gmail.com>
|
||||
|
||||
|
|
|
@ -0,0 +1,394 @@
|
|||
#!/usr/bin/perl
|
||||
##########################################################################
|
||||
# Pandora FMS Plugin Server
|
||||
##########################################################################
|
||||
# Copyright (c) 2008 Sancho Lerena, slerena@gmail.com
|
||||
# (c) 2008 Artica Soluciones Tecnologicas S.L
|
||||
# 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; version 2 (only).
|
||||
#
|
||||
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##########################################################################
|
||||
|
||||
# Includes list
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Date::Manip; # Needed to manipulate DateTime formats of input, output and compare
|
||||
use Time::Local; # DateTime basic manipulation
|
||||
use threads;
|
||||
use threads::shared;
|
||||
|
||||
# Pandora Modules
|
||||
use PandoraFMS::Config;
|
||||
use PandoraFMS::Tools;
|
||||
use PandoraFMS::DB;
|
||||
|
||||
# Queue management
|
||||
my @pending_task : shared;
|
||||
my %pending_task_hash : shared;
|
||||
my %current_task_hash : shared;
|
||||
|
||||
# FLUSH in each IO (only for debug, very slooow)
|
||||
# ENABLED in DEBUGMODE
|
||||
# DISABLE FOR PRODUCTION
|
||||
$| = 0;
|
||||
|
||||
my %pa_config;
|
||||
|
||||
$SIG{'TERM'} = 'pandora_shutdown';
|
||||
$SIG{'INT'} = 'pandora_shutdown';
|
||||
|
||||
# Inicio del bucle principal de programa
|
||||
pandora_init(\%pa_config, "Pandora FMS Plugin Server");
|
||||
|
||||
# Read config file for Global variables
|
||||
pandora_loadconfig (\%pa_config, 4);
|
||||
|
||||
# Audit server starting
|
||||
pandora_audit (\%pa_config, "Pandora FMS Plugin server starting", "SYSTEM", "System");
|
||||
|
||||
print " [*] Starting up plugin threads\n";
|
||||
|
||||
if ( $pa_config{"daemon"} eq "1" ) {
|
||||
print " [*] Backgrounding Pandora FMS Plugin Server process.\n\n";
|
||||
&daemonize;
|
||||
}
|
||||
|
||||
/*
|
||||
# Launch now all plugin threads
|
||||
# $ax is local thread id for this server
|
||||
for (my $ax=0; $ax < $pa_config{'plugin_threads'}; $ax++){
|
||||
threads->new( \&pandora_plugin_consumer, \%pa_config, $ax);
|
||||
}
|
||||
|
||||
# Launch now the producer thread
|
||||
threads->new( \&pandora_plugin_producer, \%pa_config);
|
||||
*/
|
||||
|
||||
|
||||
print " [*] All threads loaded and running \n\n";
|
||||
# Last thread is the main process (this process)
|
||||
|
||||
my $dbhost = $pa_config{'dbhost'};
|
||||
my $dbname = $pa_config{'dbname'};
|
||||
my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost:3306",
|
||||
$pa_config{'dbuser'},
|
||||
$pa_config{'dbpass'},
|
||||
{ RaiseError => 1, AutoCommit => 1 });
|
||||
|
||||
|
||||
# Server keepalive thread running in main thread on a infinite loop
|
||||
while (1) {
|
||||
pandora_serverkeepaliver (\%pa_config, 1, $dbh);
|
||||
threads->yield;
|
||||
sleep ($pa_config{"server_threshold"});
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------------
|
||||
#------------------------------------------------------------------------------------
|
||||
#------------------------------------------------------------------------------------
|
||||
#--------------------- Main Perl Code below this line-----------------------
|
||||
#------------------------------------------------------------------------------------
|
||||
#------------------------------------------------------------------------------------
|
||||
#------------------------------------------------------------------------------------
|
||||
|
||||
########################################################################################
|
||||
# pandora_shutdown ()
|
||||
# Close system on a received signal
|
||||
########################################################################################
|
||||
sub pandora_shutdown {
|
||||
logger (\%pa_config,"Pandora FMS Plugin Server Shutdown by signal ",0);
|
||||
print " [*] Shutting down Pandora FMS Plugin Server (received signal)...\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# SUB pandora_network_subsystem
|
||||
# Subsystem to process network modules
|
||||
# This module runs each X seconds (server threshold) checking for network modules status
|
||||
##########################################################################
|
||||
sub pandora_plugin_consumer ($$) {
|
||||
my $pa_config = $_[0];
|
||||
my $thread_id = $_[1];
|
||||
|
||||
print " [*] Starting up Plugin Consumer Thread # $thread_id \n";
|
||||
|
||||
my $data_id_agent_module;
|
||||
# Create Database handler
|
||||
my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
|
||||
my $counter =0;
|
||||
|
||||
while (1) {
|
||||
if ($counter > 10) {
|
||||
sleep (1);
|
||||
$counter = 0;
|
||||
}
|
||||
|
||||
# Take the first element on the shared queue
|
||||
# Insert this element on the current task hash
|
||||
if (scalar(@pending_task) > 0){
|
||||
{
|
||||
lock $queue_lock;
|
||||
$data_id_agent_module = shift(@pending_task);
|
||||
delete($pending_task_hash{$data_id_agent_module});
|
||||
$current_task_hash{$data_id_agent_module}=1;
|
||||
}
|
||||
|
||||
# Executing network task with unmanaged error trapping
|
||||
eval {
|
||||
# Call network execution process
|
||||
exec_network_module ( $pa_config, $data_id_agent_module, $dbh);
|
||||
};
|
||||
if ($@){
|
||||
logger ($pa_config, "[ERROR] Plugin Task for module $data_id_agent_module causes a system exception", 0);
|
||||
logger ($pa_config, "ERROR Code: $@", 1);
|
||||
}
|
||||
|
||||
# Remove from queue. If catch an error, probably data is
|
||||
# not been processed, but has been freed from task queue
|
||||
{
|
||||
lock $queue_lock;
|
||||
delete($current_task_hash{$data_id_agent_module});
|
||||
}
|
||||
$counter = 0;
|
||||
} else {
|
||||
$counter ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub pandora_plugin_producer ($) {
|
||||
my $pa_config = $_[0];
|
||||
print " [*] Starting up Plugin Producer Thread ...\n";
|
||||
|
||||
my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
|
||||
|
||||
my $server_id = $pa_config->{'server_id'};
|
||||
|
||||
# Initialize variables for posterior usage
|
||||
my $query1;
|
||||
my @sql_data1;
|
||||
my $data_id_agente_modulo;
|
||||
my $data_flag;
|
||||
my $exec_sql1;
|
||||
|
||||
while (1) {
|
||||
if ($pa_config->{"pandora_master"} != 1) {
|
||||
# Query for normal server, not MASTER server
|
||||
$query1 = "SELECT
|
||||
tagente_modulo.id_agente_modulo,
|
||||
tagente_modulo.flag
|
||||
FROM
|
||||
tagente, tagente_modulo, tagente_estado
|
||||
WHERE
|
||||
id_server = $server_id
|
||||
AND
|
||||
tagente_modulo.id_agente = tagente.id_agente
|
||||
AND
|
||||
tagente.disabled = 0
|
||||
AND
|
||||
tagente_modulo.id_tipo_modulo > 4
|
||||
AND
|
||||
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
|
||||
AND (
|
||||
(tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP()
|
||||
OR
|
||||
tagente_modulo.flag = 1
|
||||
)
|
||||
ORDER BY
|
||||
last_execution_try ASC ";
|
||||
} else {
|
||||
# Query for MASTER SERVER !
|
||||
$query1 = "SELECT
|
||||
DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag
|
||||
FROM
|
||||
tagente, tagente_modulo, tagente_estado, tserver
|
||||
WHERE
|
||||
( (tagente.id_server = $server_id AND tagente_modulo.id_agente = tagente.id_agente) OR
|
||||
(tagente.id_server != $server_id AND tagente_modulo.id_agente = tagente.id_agente AND tagente.id_server = tserver.id_server AND tserver.status = 0)
|
||||
) AND
|
||||
tagente.disabled = 0
|
||||
AND
|
||||
tagente_modulo.id_tipo_modulo > 4
|
||||
AND
|
||||
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
|
||||
AND
|
||||
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() OR tagente_modulo.flag = 1 )
|
||||
ORDER BY last_execution_try ASC";
|
||||
}
|
||||
$exec_sql1 = $dbh->prepare($query1);
|
||||
$exec_sql1 ->execute;
|
||||
while (@sql_data1 = $exec_sql1->fetchrow_array()) {
|
||||
$data_id_agente_modulo = $sql_data1[0];
|
||||
$data_flag = $sql_data1[1];
|
||||
# Skip modules already queued
|
||||
if ((!defined($pending_task_hash{$data_id_agente_modulo})) &&
|
||||
(!defined($current_task_hash{$data_id_agente_modulo}))) {
|
||||
if ($data_flag == 1){
|
||||
$dbh->do("UPDATE tagente_modulo SET flag = 0 WHERE id_agente_modulo = $data_id_agente_modulo")
|
||||
}
|
||||
# Locking scope, do not remove redundant { }
|
||||
{
|
||||
lock $queue_lock;
|
||||
push (@pending_task, $data_id_agente_modulo);
|
||||
$pending_task_hash {$data_id_agente_modulo}=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#logger ($pa_config, "Items in Network Pending Queue: ".scalar(@pending_task), 5);
|
||||
$exec_sql1->finish();
|
||||
sleep($pa_config->{"server_threshold"});
|
||||
} # Main loop
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# SUB exec_plugin_module (paconfig, id_agente_modulo, dbh )
|
||||
# Execute plugin module task
|
||||
##########################################################################
|
||||
sub exec_plugin_module {
|
||||
my $pa_config = $_[0];
|
||||
my $id_agent_plugin = $_[1];
|
||||
my $dbh = $_[2];
|
||||
|
||||
# Set global variables for this sub
|
||||
my $timeout = $pa_config->{'plugin_timeout'};
|
||||
my $agent_plugin; # hash container for tagent_plugin record
|
||||
my $plugin; # hash container for tplugin
|
||||
|
||||
# Get a full hash for agent_plugin record reference ($agent_plugin)
|
||||
my $query_sql = "SELECT * FROM tagent_plugin WHERE id = $id_agent_plugin";
|
||||
my $exec_sql = $dbh->prepare($query_sql);
|
||||
$exec_sql ->execute;
|
||||
if (! $agent_plugin = $exec_sql->fetchrow_hashref){
|
||||
# This piece of code should not be executed never.
|
||||
$exec_sql->finish();
|
||||
logger (\%pa_config,"[ERROR] Processing data for invalid plugin module", 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
# Get a full hash for plugin record reference ($plugin)
|
||||
$query_sql = "SELECT * FROM tplugin WHERE id = ".$agent_plugin->{'id_plugin'};
|
||||
$exec_sql = $dbh->prepare($query_sql);
|
||||
$exec_sql ->execute;
|
||||
if (! $plugin = $exec_sql->fetchrow_hashref){
|
||||
# This piece of code should not be executed never.
|
||||
$exec_sql->finish();
|
||||
logger (\%pa_config,"[ERROR] Processing data for invalid plugin reference", 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
# Calculate min timeout for this call
|
||||
if ($plugin->{'max_timeout'} < $timeout){
|
||||
$timeout = $plugin->{'max_timeout'};
|
||||
}
|
||||
|
||||
# Initialize another global sub variables.
|
||||
my $agent_name = dame_agente_nombre ($pa_config, $agent_plugin->{'id_agente'}, $dbh);
|
||||
my $module_result = 1; # Fail by default
|
||||
my $module_data = 0; # 0 data for default
|
||||
|
||||
# Build execution command to plugin
|
||||
my $exec_output = "";
|
||||
my $plugin_command = $plugin->{"execute"};
|
||||
if ($plugin->{'net_dst_opt'} ne ""){
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'net_dst_opt'} ." ". $agent_module->{'net_dst'};
|
||||
}
|
||||
if ($plugin->{'net_port_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'net_port_opt'} ." ". $agent_module->{'net_port'};
|
||||
}
|
||||
if ($plugin->{'user_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'user_opt'} ." ". $agent_module->{'access_user'};
|
||||
}
|
||||
if ($plugin->{'pass_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'pass_opt'} ." ". $agent_module->{'access_pass'};
|
||||
}
|
||||
|
||||
# Proccess field / optional / dynamic fields (5)
|
||||
if ($agent_module->{'field1'} ne "") {
|
||||
$plugin_command = $plugin_command . " \"". $agent_module->{'field1'}. "\"";
|
||||
}
|
||||
if ($agent_module->{'field2'} ne "") {
|
||||
$plugin_command = $plugin_command . " \"". $agent_module->{'field2'}. "\"";
|
||||
}
|
||||
if ($agent_module->{'field3'} ne "") {
|
||||
$plugin_command = $plugin_command . " \"". $agent_module->{'field3'}. "\"";
|
||||
}
|
||||
if ($agent_module->{'field4'} ne "") {
|
||||
$plugin_command = $plugin_command . " \"". $agent_module->{'field4'}. "\"";
|
||||
}
|
||||
if ($agent_module->{'field5'} ne "") {
|
||||
$plugin_command = $plugin_command . " \"". $agent_module->{'field5'}. "\"";
|
||||
}
|
||||
|
||||
# Final command line execution is stored at "plugin_command"
|
||||
eval {
|
||||
alarm ($timeout);
|
||||
$module_data = `$plugin_command`;
|
||||
alarm(0); # Cancel the pending alarm if plugin call returns alive
|
||||
$module_result = 0; # If comes here, this is a successfull exec
|
||||
};
|
||||
if ($@ =~ /PANDORA PLUGIN SERVER TIMED OUT/) {
|
||||
logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_plugin->{'id'}." causes a system timeout in exec", 1);
|
||||
# resuming eval block...
|
||||
} else {
|
||||
logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_plugin->{'id'}." causes an unknown system error", 1);
|
||||
logger ($pa_config, "[ERROR] $@", 1);
|
||||
}
|
||||
|
||||
sub timed_out {
|
||||
die "PANDORA PLUGIN SERVER TIMED OUT";
|
||||
}
|
||||
|
||||
# Get current timestamp
|
||||
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
||||
my $utimestamp = &UnixDate("today","%s");
|
||||
|
||||
# If module execution get a valid value
|
||||
if ($module_result == 0) {
|
||||
my %part;
|
||||
$part{'name'}[0] = $agent_plugin->{'id_agent'};
|
||||
$part{'description'}[0] = "";
|
||||
$part{'data'}[0] = $module_data;
|
||||
my $tipo_modulo = dame_nombretipomodulo_idagentemodulo ($pa_config, $agent_plugin->{'id_module_type'}, $dbh);
|
||||
|
||||
if ($tipo_modulo eq 'generic_data') {
|
||||
module_generic_data ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif ($tipo_modulo eq 'generic_data_inc' ) {
|
||||
module_generic_data_inc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif ($tipo_modulo eq 'generic_data_string') {
|
||||
module_generic_data_string ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif ($tipo_modulo eq 'generic_data_proc') {
|
||||
module_generic_proc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
else {
|
||||
logger ($pa_config, "Plugin Server Problem with unknown module type '$tipo_modulo'", 0);
|
||||
goto skipdb_execmod;
|
||||
}
|
||||
# Update agent last contact
|
||||
# Insert Pandora version as agent version
|
||||
pandora_lastagentcontact ($pa_config, $timestamp, $agent_name, $pa_config->{'servername'}.$pa_config->{"servermode"}, $pa_config->{'version'}, -1, $dbh);
|
||||
} else {
|
||||
# If module execution get a INVALID value
|
||||
if ($module_interval == 0){
|
||||
$module_interval = dame_intervalo ($pa_config, $agent_plugin->{'id_agent'}, $dbh);
|
||||
}
|
||||
# Modules who cannot connect or something go bad, update last_execution_try field
|
||||
logger ($pa_config, "Cannot obtain exec Network Module $nombre from agent $agent_name", 4);
|
||||
my $query_act = "UPDATE tagente_estado SET current_interval = $module_interval, last_execution_try = $utimestamp WHERE id_agente_modulo = $id_agente_modulo AND data_source = 2";
|
||||
$dbh->do($query_act);
|
||||
}
|
||||
skipdb_execmod:
|
||||
$exec_sql->finish(); #close tagent_plugin hash reference
|
||||
}
|
|
@ -123,3 +123,19 @@ snmp_timeout 10
|
|||
|
||||
snmp_proc_deadresponse 1
|
||||
|
||||
# plugin_threads: Specify number of plugin server threads for processing plugin calls
|
||||
|
||||
plugin_threads 5
|
||||
|
||||
# plugin_timeout: Specify number of seconds calling plugin exec waiting for response
|
||||
# after this time, call is aborted and result is "unknown".
|
||||
|
||||
plugin_timeout 5
|
||||
|
||||
# pluginserver : 1 or 0. Set to 1 to activate plugin server with this setup
|
||||
|
||||
pluginserver 1
|
||||
|
||||
# predictionserver : 1 or 0. Set to 1 to activate prediction server with this setup
|
||||
|
||||
predictionserver 1
|
||||
|
|
|
@ -35,7 +35,7 @@ our @EXPORT = qw( pandora_help_screen
|
|||
|
||||
# version: Defines actual version of Pandora Server for this module only
|
||||
my $pandora_version = "1.4-dev";
|
||||
my $pandora_build="PS080220";
|
||||
my $pandora_build="PS080225";
|
||||
our $VERSION = $pandora_version." ".$pandora_build;
|
||||
|
||||
# Setup hash
|
||||
|
@ -106,49 +106,54 @@ sub pandora_init {
|
|||
##########################################################################
|
||||
|
||||
sub pandora_loadconfig {
|
||||
my $pa_config = $_[0];
|
||||
my $opmode = $_[1]; # 0 dataserver, 1 network server, 2 snmp console, 3 recon server
|
||||
my $archivo_cfg = $pa_config->{'pandora_path'};
|
||||
my $buffer_line;
|
||||
my @command_line;
|
||||
my $tbuf;
|
||||
my $pa_config = $_[0];
|
||||
my $opmode = $_[1]; # 0 dataserver, 1 network server, 2 snmp console, 3 recon server, 4 plugin server, 5 prediction server
|
||||
my $archivo_cfg = $pa_config->{'pandora_path'};
|
||||
my $buffer_line;
|
||||
my @command_line;
|
||||
my $tbuf;
|
||||
|
||||
# Default values
|
||||
$pa_config->{'version'} = $pandora_version;
|
||||
$pa_config->{'build'} = $pandora_build;
|
||||
$pa_config->{"dbuser"} = "pandora";
|
||||
$pa_config->{"dbpass"} = "pandora";
|
||||
$pa_config->{"dbhost"} = "localhost";
|
||||
$pa_config->{"dbname"} = "pandora";
|
||||
$pa_config->{"basepath"} = $pa_config->{'pandora_path'}; # Compatibility with Pandora 1.1
|
||||
$pa_config->{"incomingdir"} = "/var/spool/pandora/data_in";
|
||||
$pa_config->{"server_threshold"} = 30;
|
||||
$pa_config->{"alert_threshold"} = 60;
|
||||
$pa_config->{"logfile"} = "/var/log/pandora_server.log";
|
||||
$pa_config->{"errorlogfile"} = "/var/log/pandora_server.error";
|
||||
$pa_config->{"networktimeout"} = 15; # By default, not in config file yet
|
||||
$pa_config->{"pandora_master"} = 1; # on by default
|
||||
$pa_config->{"pandora_check"} = 0; # on by default
|
||||
$pa_config->{"version"} = $pandora_version;
|
||||
$pa_config->{"build"} = $pandora_build;
|
||||
$pa_config->{"servername"} = `hostname`;
|
||||
$pa_config->{"servername"} =~ s/\s//g; # Replace ' ' chars
|
||||
$pa_config->{"dataserver"} = 0;
|
||||
$pa_config->{"networkserver"} = 0;
|
||||
$pa_config->{"snmpconsole"} = 0;
|
||||
$pa_config->{"reconserver"} = 0;
|
||||
$pa_config->{"pluginserver"} = 0; # Introduced on 1.4
|
||||
$pa_config->{"predictionserver"} = 0; # Introduced on 1.4
|
||||
$pa_config->{"servermode"} = "";
|
||||
$pa_config->{'snmp_logfile'} = "/var/log/pandora_snmptrap.log";
|
||||
$pa_config->{"network_threads"} = 5; # Fixed default
|
||||
$pa_config->{"keepalive"} = 60; # 60 Seconds initially for server keepalive
|
||||
$pa_config->{"keepalive_orig"} = $pa_config->{"keepalive"};
|
||||
$pa_config->{"icmp_checks"} = 1; # Introduced on 1.3.1
|
||||
$pa_config->{"alert_recovery"} = 0; # Introduced on 1.3.1
|
||||
$pa_config->{"snmp_checks"} = 1; # Introduced on 1.3.1
|
||||
$pa_config->{"snmp_timeout"} = 8; # Introduced on 1.3.1
|
||||
$pa_config->{"tcp_checks"} = 1; # Introduced on 1.3.1
|
||||
$pa_config->{"tcp_timeout"} = 20; # Introduced on 1.3.1
|
||||
$pa_config->{"snmp_proc_deadresponse"} = 0; # Introduced on 1.3.1 10 Feb08
|
||||
$pa_config->{"plugin_threads"} = 3; # Introduced on 1.4
|
||||
$pa_config->{"plugin_timeout"} = 5; # Introduced on 1.
|
||||
|
||||
# Default values
|
||||
$pa_config->{'version'} = $pandora_version;
|
||||
$pa_config->{'build'} = $pandora_build;
|
||||
$pa_config->{"dbuser"} = "pandora";
|
||||
$pa_config->{"dbpass"} = "pandora";
|
||||
$pa_config->{"dbhost"} = "localhost";
|
||||
$pa_config->{"dbname"} = "pandora";
|
||||
$pa_config->{"basepath"} = $pa_config->{'pandora_path'}; # Compatibility with Pandora 1.1
|
||||
$pa_config->{"incomingdir"} = "/var/spool/pandora/data_in";
|
||||
$pa_config->{"server_threshold"} = 30;
|
||||
$pa_config->{"alert_threshold"} = 60;
|
||||
$pa_config->{"logfile"} = "/var/log/pandora_server.log";
|
||||
$pa_config->{"errorlogfile"} = "/var/log/pandora_server.error";
|
||||
$pa_config->{"networktimeout"} = 15; # By default, not in config file yet
|
||||
$pa_config->{"pandora_master"} = 1; # on by default
|
||||
$pa_config->{"pandora_check"} = 0; # on by default
|
||||
$pa_config->{"snmpconsole"} = 0; # off by default
|
||||
$pa_config->{"version"} = $pandora_version;
|
||||
$pa_config->{"build"} = $pandora_build;
|
||||
$pa_config->{"servername"} = `hostname`;
|
||||
$pa_config->{"servername"} =~ s/\s//g; # Replace ' ' chars
|
||||
$pa_config->{"networkserver"} = 0;
|
||||
$pa_config->{"dataserver"} = 0;
|
||||
$pa_config->{"icmp_checks"} = 1; # Introduced on 1.3.1
|
||||
$pa_config->{"reconserver"} = 0;
|
||||
$pa_config->{"servermode"} = "";
|
||||
$pa_config->{'snmp_logfile'} = "/var/log/pandora/pandora_snmptrap.log";
|
||||
$pa_config->{"network_threads"} = 5; # Fixed default
|
||||
$pa_config->{"keepalive"} = 60; # 60 Seconds initially for server keepalive
|
||||
$pa_config->{"keepalive_orig"} = $pa_config->{"keepalive"};
|
||||
$pa_config->{"alert_recovery"} = 0; # Introduced on 1.3.1
|
||||
$pa_config->{"snmp_checks"} = 1; # Introduced on 1.3.1
|
||||
$pa_config->{"snmp_timeout"} = 8; # Introduced on 1.3.1
|
||||
$pa_config->{"tcp_checks"} = 1; # Introduced on 1.3.1
|
||||
$pa_config->{"tcp_timeout"} = 20; # Introduced on 1.3.1
|
||||
$pa_config->{"snmp_proc_deadresponse"} = 0; # Introduced on 1.3.1 10 Feb08
|
||||
# Check for UID0
|
||||
if ($> == 0){
|
||||
printf " [W] Not all Pandora FMS components need to be executed as root\n";
|
||||
|
@ -156,8 +161,9 @@ sub pandora_loadconfig {
|
|||
}
|
||||
# Check for file
|
||||
if ( ! -e $archivo_cfg ) {
|
||||
printf "\n[ERROR] Cannot open configuration file at $archivo_cfg. \n";
|
||||
printf " Please specify a valid Pandora FMS configuration file in command line. \n";
|
||||
printf "\n [ERROR] Cannot open configuration file at $archivo_cfg. \n";
|
||||
printf " Please specify a valid Pandora FMS configuration file in command line.\n";
|
||||
print " Standard configuration file is at /etc/pandora/pandora_server.conf \n";
|
||||
exit 1;
|
||||
}
|
||||
# Collect items from config file and put in an array
|
||||
|
@ -189,8 +195,7 @@ sub pandora_loadconfig {
|
|||
for ($ax=0;$ax<=$ltotal;$ax++){
|
||||
$parametro = $args[$ax];
|
||||
if ($parametro =~ m/^incomingdir\s(.*)/i) {
|
||||
$pa_config->{"incomingdir"} = $1;
|
||||
$tbuf= $1;
|
||||
$tbuf= clean_blank($1);
|
||||
if ($tbuf =~ m/^\.(.*)/){
|
||||
$pa_config->{"incomingdir"} =$pa_config->{"basepath"}.$1;
|
||||
} else {
|
||||
|
@ -198,7 +203,7 @@ sub pandora_loadconfig {
|
|||
}
|
||||
}
|
||||
elsif ($parametro =~ m/^log_file\s(.*)/i) {
|
||||
$tbuf= $1;
|
||||
$tbuf= clean_blank($1);
|
||||
if ($tbuf =~ m/^\.(.*)/){
|
||||
$pa_config->{"logfile"} = $pa_config->{"basepath"}.$1;
|
||||
} else {
|
||||
|
@ -206,65 +211,107 @@ sub pandora_loadconfig {
|
|||
}
|
||||
}
|
||||
elsif ($parametro =~ m/^errorlog_file\s(.*)/i) {
|
||||
$tbuf= $1;
|
||||
$tbuf= clean_blank($1);
|
||||
if ($tbuf =~ m/^\.(.*)/){
|
||||
$pa_config->{"errorlogfile"} = $pa_config->{"basepath"}.$1;
|
||||
} else {
|
||||
$pa_config->{"errorlogfile"} = $tbuf;
|
||||
}
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_logfile\s(.*)/i) { $pa_config->{'snmp_logfile'}= $1; }
|
||||
elsif ($parametro =~ m/^dbname\s(.*)/i) { $pa_config->{'dbname'}= $1; }
|
||||
elsif ($parametro =~ m/^dbuser\s(.*)/i) { $pa_config->{'dbuser'}= $1; }
|
||||
elsif ($parametro =~ m/^dbpass\s(.*)/i) { $pa_config->{'dbpass'}= $1; }
|
||||
elsif ($parametro =~ m/^dbhost\s(.*)/i) { $pa_config->{'dbhost'}= $1; }
|
||||
elsif ($parametro =~ m/^daemon\s([0-9]*)/i) { $pa_config->{'daemon'}= $1;}
|
||||
elsif ($parametro =~ m/^dataserver\s([0-9]*)/i) {
|
||||
$pa_config->{'dataserver'}= $1;
|
||||
elsif ($parametro =~ m/^snmp_logfile\s(.*)/i) {
|
||||
$pa_config->{'snmp_logfile'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^dbname\s(.*)/i) {
|
||||
$pa_config->{'dbname'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^dbuser\s(.*)/i) {
|
||||
$pa_config->{'dbuser'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^dbpass\s(.*)/i) {
|
||||
$pa_config->{'dbpass'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^dbhost\s(.*)/i) {
|
||||
$pa_config->{'dbhost'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^daemon\s([0-9]*)/i) {
|
||||
$pa_config->{'daemon'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^dataserver\s([0-9]*)/i){
|
||||
$pa_config->{'dataserver'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_proc_deadresponse\s([0-9]*)/i) {
|
||||
$pa_config->{"snmp_proc_deadresponse"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) {
|
||||
$pa_config->{'reconserver'}= $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^networkserver\s([0-9]*)/i) {
|
||||
$pa_config->{'networkserver'}= $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^servername\s(.*)/i) { $pa_config->{'servername'}= $1; }
|
||||
elsif ($parametro =~ m/^checksum\s([0-9])/i) { $pa_config->{"pandora_check"} = $1; }
|
||||
elsif ($parametro =~ m/^master\s([0-9])/i) {
|
||||
$pa_config->{"pandora_master"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^icmp_checks\s([0-9])/i) {
|
||||
$pa_config->{"icmp_checks"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^snmpconsole\s([0-9])/i) {
|
||||
$pa_config->{"snmpconsole"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^alert_recovery\s([0-9])/i) {
|
||||
$pa_config->{"alert_recovery"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_checks\s([0-9])/i) {
|
||||
$pa_config->{"snmp_checks"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_timeout\s([0-9])/i) {
|
||||
$pa_config->{"snmp_timeout"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^tcp_checks\s([0-9])/i) {
|
||||
$pa_config->{"tcp_checks"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^tcp_timeout\s([0-9])/i) {
|
||||
$pa_config->{"tcp_timeout"} = $1;
|
||||
}
|
||||
elsif ($parametro =~ m/^pluginserver\s([0-9]*)/i){
|
||||
$pa_config->{'pluginserver'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^predictionserver\s([0-9]*)/i){
|
||||
$pa_config->{'predictionserver'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) {
|
||||
$pa_config->{'reconserver'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^networkserver\s([0-9]*)/i) {
|
||||
$pa_config->{'networkserver'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^servername\s(.*)/i) {
|
||||
$pa_config->{'servername'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^checksum\s([0-9])/i) {
|
||||
$pa_config->{"pandora_check"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^master\s([0-9])/i) {
|
||||
$pa_config->{"pandora_master"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^icmp_checks\s([0-9])/i) {
|
||||
$pa_config->{"icmp_checks"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmpconsole\s([0-9])/i) {
|
||||
$pa_config->{"snmpconsole"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^alert_recovery\s([0-9])/i) {
|
||||
$pa_config->{"alert_recovery"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_checks\s([0-9])/i) {
|
||||
$pa_config->{"snmp_checks"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_timeout\s([0-9])/i) {
|
||||
$pa_config->{"snmp_timeout"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^tcp_checks\s([0-9])/i) {
|
||||
$pa_config->{"tcp_checks"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^tcp_timeout\s([0-9])/i) {
|
||||
$pa_config->{"tcp_timeout"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_proc_deadresponse\s([0-9]*)/i) {
|
||||
$pa_config->{"snmp_proc_deadresponse"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^verbosity\s([0-9]*)/i) {
|
||||
$pa_config->{"verbosity"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^server_threshold\s([0-9]*)/i) {
|
||||
$pa_config->{"server_threshold"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^alert_threshold\s([0-9]*)/i) {
|
||||
$pa_config->{"alert_threshold"} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^network_timeout\s([0-9]*)/i) {
|
||||
$pa_config->{'networktimeout'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^network_threads\s([0-9]*)/i) {
|
||||
$pa_config->{'network_threads'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^plugin_threads\s([0-9]*)/i) {
|
||||
$pa_config->{'plugin_threads'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^plugin_timeout\s([0-9]*)/i) {
|
||||
$pa_config->{'plugin_timeout'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^server_keepalive\s([0-9]*)/i) {
|
||||
$pa_config->{"keepalive"} = clean_blank($1);
|
||||
$pa_config->{"keepalive_orig"} = clean_blank($1);
|
||||
}
|
||||
} # end of loop for parameter #
|
||||
|
||||
|
||||
elsif ($parametro =~ m/^verbosity\s([0-9]*)/i) { $pa_config->{"verbosity"} = $1; }
|
||||
elsif ($parametro =~ m/^server_threshold\s([0-9]*)/i) { $pa_config->{"server_threshold"} = $1; }
|
||||
elsif ($parametro =~ m/^alert_threshold\s([0-9]*)/i) { $pa_config->{"alert_threshold"} = $1; }
|
||||
elsif ($parametro =~ m/^network_timeout\s([0-9]*)/i) { $pa_config->{'networktimeout'}= $1; }
|
||||
elsif ($parametro =~ m/^network_threads\s([0-9]*)/i) { $pa_config->{'network_threads'}= $1; }
|
||||
elsif ($parametro =~ m/^server_keepalive\s([0-9]*)/i) { $pa_config->{"keepalive"} = $1; $pa_config->{"keepalive_orig"} = $1; }
|
||||
}
|
||||
if ( $pa_config->{"verbosity"} > 0){
|
||||
print " [*] Server basepath is ".$pa_config->{'basepath'}."\n";
|
||||
print " [*] Server logfile at ".$pa_config->{"logfile"}."\n";
|
||||
|
@ -275,25 +322,33 @@ sub pandora_loadconfig {
|
|||
}
|
||||
# Check for valid token token values
|
||||
if (( $pa_config->{"dbuser"} eq "" ) || ( $pa_config->{"basepath"} eq "" ) || ( $pa_config->{"incomingdir"} eq "" ) || ( $pa_config->{"logfile"} eq "" ) || ( $pa_config->{"dbhost"} eq "") || ( $pa_config->{"pandora_master"} eq "") || ( $pa_config->{"dbpass"} eq "" ) ) {
|
||||
print "[ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==0) && ($pa_config->{"dataserver"} ne 1)) {
|
||||
print " [ERROR] You must enable Dataserver in setup file to run Pandora FMS Data Server. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==1) && ($pa_config->{"networkserver"} ne 1)) {
|
||||
print " [ERROR] You must enable NetworkServer in setup file to run Pandora FMS Network Server. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==2) && ($pa_config->{"snmpconsole"} ne 1)) {
|
||||
print " [ERROR] You must enable SnmpConsole in setup file to run Pandora FMS SNMP Console. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==3) && ($pa_config->{"reconserver"} ne 1)) {
|
||||
print " [ERROR] You must enable Recon server in setup file to run Pandora FMS Recon server. \n\n";
|
||||
print " [ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==0) && ($pa_config->{"dataserver"} ne 1)) {
|
||||
print " [ERROR] You must enable Dataserver in setup file to run Pandora FMS Data Server. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==1) && ($pa_config->{"networkserver"} ne 1)) {
|
||||
print " [ERROR] You must enable NetworkServer in setup file to run Pandora FMS Network Server. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==2) && ($pa_config->{"snmpconsole"} ne 1)) {
|
||||
print " [ERROR] You must enable SnmpConsole in setup file to run Pandora FMS SNMP Console. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==3) && ($pa_config->{"reconserver"} ne 1)) {
|
||||
print " [ERROR] You must enable Recon server in setup file to run Pandora FMS Recon server. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==4) && ($pa_config->{"pluginserver"} ne 1)) {
|
||||
print " [ERROR] You must enable Plugin server in setup file to run Pandora FMS Plugin server. \n\n";
|
||||
exit;
|
||||
}
|
||||
if (($opmode ==5) && ($pa_config->{"predictionserver"} ne 1)) {
|
||||
print " [ERROR] You must enable Prediction server in setup file to run Pandora FMS Prediction server. \n\n";
|
||||
exit;
|
||||
}
|
||||
if ($opmode == 0){
|
||||
print " [*] You are running Pandora FMS Data Server. \n";
|
||||
$parametro ="Pandora FMS Data Server";
|
||||
|
@ -314,6 +369,16 @@ sub pandora_loadconfig {
|
|||
$parametro ="Pandora FMS Recon Server";
|
||||
$pa_config->{"servermode"}="_Recon";
|
||||
}
|
||||
if ($opmode == 4){
|
||||
print " [*] You are running Pandora FMS Plugin Server. \n";
|
||||
$parametro ="Pandora FMS Plugin Server";
|
||||
$pa_config->{"servermode"}="_Plugin";
|
||||
}
|
||||
if ($opmode == 3){
|
||||
print " [*] You are running Pandora FMS Prediction Server. \n";
|
||||
$parametro ="Pandora FMS Prediction Server";
|
||||
$pa_config->{"servermode"}="_Prediction";
|
||||
}
|
||||
if ($pa_config->{"pandora_check"} == 1) {
|
||||
print " [*] MD5 Security enabled.\n";
|
||||
}
|
||||
|
@ -330,9 +395,8 @@ sub pandora_loadconfig {
|
|||
pandora_updateserver ($pa_config, $pa_config->{'servername'},1, $opmode, $dbh); # Alive status
|
||||
};
|
||||
if ($@) {
|
||||
|
||||
logger ($pa_config, "Error connecting database in init Phase. Aborting startup.",0);
|
||||
print (" [E] Error connecting database in init Phase. Aborting startup. \n\n");
|
||||
print (" [ERROR] Error connecting database in init Phase. Aborting startup. \n\n");
|
||||
print $@;
|
||||
exit;
|
||||
}
|
||||
|
@ -340,9 +404,9 @@ sub pandora_loadconfig {
|
|||
$pa_config->{'server_id'} = dame_server_id ($pa_config, $pa_config->{'servername'}.$pa_config->{"servermode"}, $dbh);
|
||||
|
||||
# Dump all errors to errorlog
|
||||
# DISABLED in DEBUGMODE
|
||||
# ENABLE FOR PRODUCTION
|
||||
open STDERR, ">>$pa_config->{'errorlogfile'}" or die "Can't write to Errorlog : $!";
|
||||
open STDERR, ">>$pa_config->{'errorlogfile'}" or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $!";
|
||||
my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S");
|
||||
print STDERR "$time_now - ".$pa_config->{'servername'}." Starting Pandora FMS server. Error logging activated \n";
|
||||
}
|
||||
|
||||
# End of function declaration
|
||||
|
|
|
@ -1665,6 +1665,7 @@ sub crea_agente_modulo (%$$$$$$$) {
|
|||
|
||||
# ---------------------------------------------------------------
|
||||
# Generic access to a field ($field) given a table
|
||||
# give_db_value (field_name_to_be_returned, table, field_search, condition_value, dbh)
|
||||
# ---------------------------------------------------------------
|
||||
sub give_db_value ($$$$$) {
|
||||
my $field = $_[0];
|
||||
|
|
|
@ -34,6 +34,7 @@ our @EXPORT = qw( daemonize
|
|||
float_equal
|
||||
sqlWrap
|
||||
is_numeric
|
||||
clean_blank
|
||||
);
|
||||
|
||||
|
||||
|
@ -162,6 +163,15 @@ sub limpia_cadena {
|
|||
return $micadena;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# clean_blank (string) - Purge a string for any blank spaces in it
|
||||
##########################################################################
|
||||
sub clean_blank {
|
||||
my $input = $_[0];
|
||||
$input =~ s/\s//g;
|
||||
return $input;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
# sub sqlWrap(texto)
|
||||
# Elimina comillas y caracteres problematicos y los sustituye por equivalentes
|
||||
|
|
Loading…
Reference in New Issue