2009-01-16 Sancho Lerena <slerena@artica.es>
* pandora_wmi, pandora_plugin, pandora_recon: Updates merged from 2.0 version. Different small fixes and improved performance. * DB.pm: Support for fixes in wmi/plugin server. Call of enterprise function pandora_mcast_change_report() is done now on real status change code not in alert. Added update_on_error() function to update status table when remote modules cannot init (update last_try field to avoid unnecesary attempts). * Config.pm: Build update, some stuff cleaned. Server startup info is show only when verbose level is activated. * pandora_network: Startup messages are not shown if verbose < 5. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1358 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
ae5d805e08
commit
6172955e54
|
@ -1,3 +1,19 @@
|
|||
2009-01-16 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* pandora_wmi, pandora_plugin, pandora_recon: Updates merged from
|
||||
2.0 version. Different small fixes and improved performance.
|
||||
|
||||
* DB.pm: Support for fixes in wmi/plugin server. Call of enterprise
|
||||
function pandora_mcast_change_report() is done now on real status change
|
||||
code not in alert. Added update_on_error() function to update status table
|
||||
when remote modules cannot init (update last_try field to avoid unnecesary
|
||||
attempts).
|
||||
|
||||
* Config.pm: Build update, some stuff cleaned. Server startup info is show
|
||||
only when verbose level is activated.
|
||||
|
||||
* pandora_network: Startup messages are not shown if verbose < 5.
|
||||
|
||||
2009-01-16 Raul Mateos <raulofpandora@gmail.com>
|
||||
|
||||
* lib/PandoraFMS/Config.pm: Updated Build and Headers.
|
||||
|
|
|
@ -68,13 +68,14 @@ pandora_loadconfig (\%pa_config,1);
|
|||
pandora_audit (\%pa_config, "Pandora FMS Network Daemon starting", "SYSTEM", "System");
|
||||
|
||||
# Thread startup
|
||||
if ($pa_config{"quiet"} == 0){
|
||||
|
||||
if ($pa_config{"verbosity"} > 4){
|
||||
print " [*] Starting up network threads\n";
|
||||
}
|
||||
|
||||
# Daemonize and put in background
|
||||
if ( $pa_config{"daemon"} eq "1" ){
|
||||
if ($pa_config{"quiet"} eq "0"){
|
||||
if (($pa_config{"quiet"} == 0) && ($pa_config{"verbosity"} > 4)){
|
||||
print " [*] Backgrounding Pandora FMS Network Server process.\n\n";
|
||||
}
|
||||
&pandora_daemonize ( \%pa_config);
|
||||
|
@ -91,7 +92,7 @@ for (my $ax=0; $ax < $pa_config{'network_threads'}; $ax++){
|
|||
threads->new( \&pandora_network_producer, \%pa_config);
|
||||
|
||||
|
||||
if ($pa_config{"quiet"} == 0){
|
||||
if ($pa_config{"verbosity"} > 4){
|
||||
print " [*] All threads loaded and running \n\n";
|
||||
}
|
||||
|
||||
|
@ -132,7 +133,7 @@ sub pandora_network_consumer ($$) {
|
|||
my $pa_config = $_[0];
|
||||
my $thread_id = $_[1];
|
||||
|
||||
if ($pa_config->{"quiet"} == 0){
|
||||
if ($pa_config->{"verbosity"} > 4){
|
||||
print " [*] Starting up Network Consumer Thread # $thread_id \n";
|
||||
}
|
||||
|
||||
|
@ -185,7 +186,7 @@ sub pandora_network_consumer ($$) {
|
|||
sub pandora_network_producer ($) {
|
||||
my $pa_config = $_[0];
|
||||
|
||||
if ($pa_config->{"quiet"} == 0){
|
||||
if ($pa_config->{"verbosity"} > 4){
|
||||
print " [*] Starting up Network Producer Thread ...\n";
|
||||
}
|
||||
|
||||
|
@ -706,7 +707,9 @@ sub exec_network_module {
|
|||
sub pandora_shutdown {
|
||||
logger (\%pa_config,"Pandora FMS Server '".$pa_config{'servername'}.$pa_config{"servermode"}."' Shutdown by signal ",0);
|
||||
pandora_updateserver (\%pa_config, $pa_config{'servername'}, 0, 1, $dbh);
|
||||
print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n";
|
||||
if ($pa_config{"quiet"} == 0){
|
||||
print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n";
|
||||
}
|
||||
pandora_event (\%pa_config, $pa_config{'servername'}.$pa_config{"servermode"}." going Down", 0,
|
||||
0, 4, 0, 0, "system", $dbh);
|
||||
exit;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
# Pandora FMS Plugin Server
|
||||
# http://www.pandorafms.com
|
||||
##########################################################################
|
||||
# Copyright (c) 2008 Sancho Lerena, slerena@gmail.com
|
||||
# (c) 2008 Artica Soluciones Tecnologicas S.L
|
||||
# Copyright (c) 2008-2009 Sancho Lerena, slerena@gmail.com
|
||||
# (c) 2008-2009 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
|
||||
|
@ -286,87 +286,79 @@ sub pandora_plugin_producer ($) {
|
|||
# Execute plugin module task
|
||||
##########################################################################
|
||||
sub exec_plugin_module {
|
||||
my $pa_config = $_[0];
|
||||
my $id_am = $_[1];
|
||||
my $dbh = $_[2];
|
||||
my $pa_config = $_[0];
|
||||
my $id_am = $_[1];
|
||||
my $dbh = $_[2];
|
||||
|
||||
# Set global variables for this sub
|
||||
my $timeout = $pa_config->{'plugin_timeout'};
|
||||
# Set global variables for this sub
|
||||
my $timeout = $pa_config->{'plugin_timeout'};
|
||||
my $agent_module; # hash container for tagente_modulo record
|
||||
my $plugin; # hash container for tplugin
|
||||
my $plugin; # hash container for tplugin
|
||||
|
||||
# Get a full hash for agent_plugin record reference ($agent_module)
|
||||
# Get a full hash for agent_plugin record reference ($agent_module)
|
||||
my $query_sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo = $id_am";
|
||||
my $exec_sql = $dbh->prepare($query_sql);
|
||||
$exec_sql ->execute;
|
||||
$agent_module = $exec_sql->fetchrow_hashref;
|
||||
|
||||
# Get a full hash for plugin record reference ($plugin)
|
||||
$query_sql = "SELECT * FROM tplugin WHERE id = ".$agent_module->{'id_plugin'};
|
||||
$exec_sql = $dbh->prepare($query_sql);
|
||||
$exec_sql->execute();
|
||||
$plugin = $exec_sql->fetchrow_hashref;
|
||||
# Get a full hash for plugin record reference ($plugin)
|
||||
$query_sql = "SELECT * FROM tplugin WHERE id = ".$agent_module->{'id_plugin'};
|
||||
$exec_sql = $dbh->prepare($query_sql);
|
||||
$exec_sql->execute();
|
||||
$plugin = $exec_sql->fetchrow_hashref;
|
||||
|
||||
# Calculate min timeout for this call
|
||||
if ($plugin->{'max_timeout'} < $timeout){
|
||||
$timeout = $plugin->{'max_timeout'};
|
||||
}
|
||||
# Calculate min timeout for this call
|
||||
if ($plugin->{'max_timeout'} < $timeout){
|
||||
$timeout = $plugin->{'max_timeout'};
|
||||
}
|
||||
|
||||
# Initialize another global sub variables.
|
||||
# Initialize another global sub variables.
|
||||
my $agent_name = dame_agente_nombre ($pa_config, $agent_module->{'id_agente'}, $dbh);
|
||||
my $module_result = 1; # Fail by default
|
||||
my $module_data = 0; # 0 data for default
|
||||
my $module_interval = 0;
|
||||
my $module_interval = 0;
|
||||
|
||||
# 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->{'ip_target'};
|
||||
}
|
||||
if ($plugin->{'net_port_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'net_port_opt'} ." ". $agent_module->{'tcp_port'};
|
||||
}
|
||||
if ($plugin->{'user_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'user_opt'} ." ". $agent_module->{'plugin_user'};
|
||||
}
|
||||
if ($plugin->{'pass_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'pass_opt'} ." ". $agent_module->{'plugin_pass'};
|
||||
}
|
||||
# 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->{'ip_target'};
|
||||
}
|
||||
if ($plugin->{'net_port_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'net_port_opt'} ." ". $agent_module->{'tcp_port'};
|
||||
}
|
||||
if ($plugin->{'user_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'user_opt'} ." ". $agent_module->{'plugin_user'};
|
||||
}
|
||||
if ($plugin->{'pass_opt'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $plugin->{'pass_opt'} ." ". $agent_module->{'plugin_pass'};
|
||||
}
|
||||
|
||||
# Proccess field / optional / dynamic field
|
||||
if ($agent_module->{'plugin_parameter'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $agent_module->{'plugin_parameter'};
|
||||
}
|
||||
# Proccess field / optional / dynamic field
|
||||
if ($agent_module->{'plugin_parameter'} ne "") {
|
||||
$plugin_command = $plugin_command . " ". $agent_module->{'plugin_parameter'};
|
||||
}
|
||||
|
||||
$plugin_command = decode_entities($plugin_command);
|
||||
$plugin_command = decode_entities($plugin_command);
|
||||
|
||||
logger ($pa_config, "Executing AM # $id_am plugin command '$plugin_command'", 9);
|
||||
# Final command line execution is stored at "plugin_command"
|
||||
logger ($pa_config, "Executing AM # $id_am plugin command '$plugin_command'", 9);
|
||||
# Final command line execution is stored at "plugin_command"
|
||||
|
||||
$module_data = `$pandora_exec $timeout $plugin_command`;
|
||||
if ($module_data eq "") {
|
||||
$module_result = 1;
|
||||
} else {
|
||||
$module_result = 0;
|
||||
}
|
||||
|
||||
# Error
|
||||
if ($module_result == 1) {
|
||||
logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_module->{'id_agente_modulo'}." causes an unknown system error", 1);
|
||||
logger ($pa_config, "[ERROR] $@", 1);
|
||||
}
|
||||
$module_data = `$pandora_exec $timeout $plugin_command`;
|
||||
if ($module_data eq "") {
|
||||
update_on_error ($pa_config, $id_am, $dbh);
|
||||
undef $plugin;
|
||||
undef $agent_module;
|
||||
return;
|
||||
}
|
||||
|
||||
# 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_module->{'nombre'};
|
||||
$part{'description'}[0] = "";
|
||||
$part{'data'}[0] = $module_data;
|
||||
my %part;
|
||||
$part{'name'}[0] = $agent_module->{'nombre'};
|
||||
$part{'description'}[0] = "";
|
||||
$part{'data'}[0] = $module_data;
|
||||
my $tipo_modulo = dame_nombretipomodulo_idagentemodulo ($pa_config, $agent_module->{'id_tipo_modulo'}, $dbh);
|
||||
|
||||
# 1 - generic_data
|
||||
|
@ -375,44 +367,31 @@ sub exec_plugin_module {
|
|||
# 4 - generic_data_inc
|
||||
# 19, 20 - image
|
||||
|
||||
if (1 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (4 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_inc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (3 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_string ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
if (1 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (4 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_inc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (3 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_string ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
# Generic_proc
|
||||
elsif (2 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_proc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (2 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_proc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif ( (19 == $agent_module->{'id_tipo_modulo'}) || (20 == $agent_module->{'id_tipo_modulo'}) ) {
|
||||
module_generic_image ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
else { # Unknown module!, this IS a problem
|
||||
logger ($pa_config, "Plugin Server Problem with unknown module type '$tipo_modulo'", 0);
|
||||
$module_result = 1;
|
||||
}
|
||||
# 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);
|
||||
}
|
||||
|
||||
# If something went wrong in module processing...
|
||||
if ($module_result != 0){
|
||||
|
||||
# If module execution get a INVALID value
|
||||
if ($agent_module->{'intervalo'} == 0){
|
||||
$module_interval = dame_intervalo ($pa_config, $agent_module->{'id_agente'}, $dbh);
|
||||
}
|
||||
|
||||
# Modules who cannot connect or something go bad, update last_execution_try field
|
||||
logger ($pa_config, "Cannot obtain exec plugin Module ".$agent_module->{'nombre'}." from agent $agent_name", 2);
|
||||
my $query_act = "UPDATE tagente_estado SET current_interval = $module_interval, last_execution_try = $utimestamp WHERE id_agente_modulo = ".$agent_module->{'id_agente_modulo'};
|
||||
$dbh->do($query_act);
|
||||
else { # Unknown module!, this IS a problem
|
||||
logger ($pa_config, "Plugin Server Problem with unknown module type '$tipo_modulo'", 0);
|
||||
}
|
||||
|
||||
# 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);
|
||||
|
||||
$exec_sql->finish(); #close tagent_plugin hash reference
|
||||
undef $plugin;
|
||||
undef $agent_module;
|
||||
undef %part;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ use NetAddr::IP; # To manage IP Addresses
|
|||
# Detect if Net:Traceroute::Pureperl is available.
|
||||
# If not, parent detection will be disabled
|
||||
my $traceroute_loaded = 1;
|
||||
|
||||
# Traceroute needs traceroute command
|
||||
unless ( eval "use Net::Traceroute::PurePerl; 1" ) {
|
||||
$traceroute_loaded = 0;
|
||||
|
@ -48,7 +47,6 @@ use threads::shared;
|
|||
use PandoraFMS::Config;
|
||||
use PandoraFMS::Tools;
|
||||
use PandoraFMS::DB;
|
||||
|
||||
# Alarm signal management
|
||||
$SIG{ALRM} = sub { return 0; };
|
||||
|
||||
|
@ -300,7 +298,6 @@ sub pandora_recon_exec_task {
|
|||
my $target_network = $sql_data->{"subnet"};
|
||||
my $task_name = $sql_data->{"name"};
|
||||
my $task_ncprofile = $sql_data->{"id_network_profile"};
|
||||
|
||||
my $task_group = $sql_data->{"id_group"};
|
||||
my $task_create_incident = $sql_data->{"create_incident"};
|
||||
my $task_id_os = $sql_data->{"id_os"};
|
||||
|
@ -634,8 +631,10 @@ sub pandora_task_create_agentmodules {
|
|||
$query_sql4 = "INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, estado, id_agente, last_try, utimestamp, current_interval, running_by) VALUES ($last_id_agente_modulo, '', '0000-00-00 00:00:00', 1, $agent_id, '0000-00-00 00:00:00', 0, $interval, 0)";
|
||||
|
||||
$dbh->do($query_sql4);
|
||||
undef $sql_data2;
|
||||
}
|
||||
$exec_sql2->finish();
|
||||
undef $sql_data;
|
||||
}
|
||||
$exec_sql->finish();
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
# Pandora FMS WMI Server
|
||||
# http://www.pandorafms.com
|
||||
##########################################################################
|
||||
# Copyright (c) 2008 Sancho Lerena, slerena@gmail.com
|
||||
# (c) 2008 Artica Soluciones Tecnologicas S.L
|
||||
# Copyright (c) 2008-2009 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
|
||||
|
@ -106,37 +105,6 @@ while (1) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
# New samples
|
||||
|
||||
# Process executing (return PID)
|
||||
# SELECT ProcessId FROM Win32_Process WHERE Caption = "spoolsv.exe"
|
||||
|
||||
# Service State of a service (Running or Stopped)
|
||||
# SELECT State FROM Win32_Service WHERE Name = "Eventlog"
|
||||
|
||||
# CPU de CPU0
|
||||
# SELECT LoadPercentage from Win32_Processor WHERE DeviceID = "CPU0"
|
||||
|
||||
# Available memory (bytes)
|
||||
# SELECT AvailableBytes from Win32_PerfRawData_PerfOS_Memory
|
||||
|
||||
# Available cache memory (bytes)
|
||||
# SELECT CacheBytes from Win32_PerfRawData_PerfOS_Memory
|
||||
|
||||
# AvgDiskBytesPerTransfer
|
||||
# DiskReadsPersec
|
||||
# DiskTransfersPersec
|
||||
# FreeMegabytes
|
||||
# SELECT * from Win32_PerfRawData_PerfDisk_LogicalDisk WHERE Name = "F:"
|
||||
|
||||
|
||||
# FragmentedDatagramsPersec
|
||||
# FragmentationFailures
|
||||
# DatagramsReceivedPersec
|
||||
# DatagramsSentPersec
|
||||
# SELECT * from Win32_PerfFormattedData_Tcpip_IP
|
||||
|
||||
#------------------------------------------------------------------------------------
|
||||
#------------------------------------------------------------------------------------
|
||||
#------------------------------------------------------------------------------------
|
||||
|
@ -303,69 +271,62 @@ sub pandora_wmi_producer ($) {
|
|||
} # Main loop
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# SUB exec_wmi_module (paconfig, id_agente_modulo, dbh )
|
||||
# Execute WMI module task
|
||||
##########################################################################
|
||||
sub exec_wmi_module {
|
||||
my $pa_config = $_[0];
|
||||
my $id_am = $_[1];
|
||||
my $dbh = $_[2];
|
||||
my $pa_config = $_[0];
|
||||
my $id_am = $_[1];
|
||||
my $dbh = $_[2];
|
||||
|
||||
# Set global variables for this sub
|
||||
my $timeout = $pa_config->{'wmi_timeout'};
|
||||
# Set global variables for this sub
|
||||
my $timeout = $pa_config->{'wmi_timeout'};
|
||||
my $agent_module; # hash container for tagente_modulo record
|
||||
|
||||
# Get a full hash for agent_plugin record reference ($agent_module)
|
||||
# Get a full hash for agent_plugin record reference ($agent_module)
|
||||
my $query_sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo = $id_am";
|
||||
my $exec_sql = $dbh->prepare($query_sql);
|
||||
$exec_sql ->execute;
|
||||
$agent_module = $exec_sql->fetchrow_hashref;
|
||||
|
||||
# Calculate min timeout for this call
|
||||
if ($agent_module->{'max_timeout'} < $timeout){
|
||||
$timeout = $agent_module->{'max_timeout'};
|
||||
}
|
||||
# Calculate min timeout for this call
|
||||
if ($agent_module->{'max_timeout'} < $timeout){
|
||||
$timeout = $agent_module->{'max_timeout'};
|
||||
}
|
||||
|
||||
# Initialize another global sub variables.
|
||||
# Initialize another global sub variables.
|
||||
my $agent_name = dame_agente_nombre ($pa_config, $agent_module->{'id_agente'}, $dbh);
|
||||
my $module_result = 1; # Fail by default
|
||||
my $module_data = '';
|
||||
my $module_interval = 0;
|
||||
my $module_interval = $agent_module->{'module_interval'};
|
||||
|
||||
# Build execution command to plugin
|
||||
# Sample exec: wmic -U Administrador%none //192.168.50.123 "SELECT State FROM Win32_Service WHERE Name = \"Eventlog\""
|
||||
|
||||
# This returns several lines that needs to be processed
|
||||
# OM Win32_Service WHERE Name = \"Eventlog\""
|
||||
# CLASS: Win32_Service
|
||||
# Name|State
|
||||
# Eventlog|Running
|
||||
# Build execution command to plugin
|
||||
|
||||
my $wmi_query = decode_entities($agent_module->{'snmp_oid'});
|
||||
$wmi_query =~ s/\"/\'/g;
|
||||
|
||||
my $wmi_command = "$wmi_client -U \"". $agent_module->{'plugin_user'} ."\"%\"". $agent_module->{'plugin_pass'} . "\"";
|
||||
my $wmi_command = "$wmi_client -U \"". $agent_module->{'plugin_user'} ."\"%\"". $agent_module->{'plugin_pass'} . "\"";
|
||||
|
||||
# Custom namespace
|
||||
if ($agent_module->{'tcp_send'} ne '') {
|
||||
# Custom namespace
|
||||
if ($agent_module->{'tcp_send'} ne '') {
|
||||
$agent_module->{'tcp_send'} =~ s/\"/\'/g;
|
||||
$wmi_command .= " --namespace=\"" . $agent_module->{'tcp_send'} . "\"";
|
||||
}
|
||||
$wmi_command .= " //". $agent_module->{'ip_target'};
|
||||
$wmi_command .= " \"". $wmi_query . "\"";
|
||||
logger ($pa_config, "Executing AM # $id_am WMI command '$wmi_command'", 9);
|
||||
$wmi_command .= " --namespace=\"" . $agent_module->{'tcp_send'} . "\"";
|
||||
}
|
||||
|
||||
$wmi_command .= " //". $agent_module->{'ip_target'};
|
||||
$wmi_command .= " \"". $wmi_query . "\"";
|
||||
logger ($pa_config, "Executing AM # $id_am WMI command '$wmi_command'", 9);
|
||||
|
||||
$module_data = `$wmi_command`;
|
||||
my $module_data = `$wmi_command`;
|
||||
if (! defined($module_data)) {
|
||||
#logger ($pa_config, "[ERROR] Unexpected response from $wmi_client\n");
|
||||
update_on_error ($pa_config, $id_am, $dbh);
|
||||
undef $agent_module;
|
||||
return;
|
||||
}
|
||||
|
||||
my @data = split("\n", $module_data);
|
||||
if ($#data < 2) {
|
||||
#logger ($pa_config, "[ERROR] Unexpected response from $wmi_client\n");
|
||||
update_on_error ($pa_config, $id_am, $dbh);
|
||||
undef $agent_module;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -378,10 +339,10 @@ sub exec_wmi_module {
|
|||
|
||||
# Look for errors
|
||||
if ($module_data =~ /ERROR/) {
|
||||
$module_result = 1;
|
||||
} else {
|
||||
$module_result = 0; # If comes here, this is a successfull exec
|
||||
}
|
||||
update_on_error ($pa_config, $id_am, $dbh);
|
||||
undef $agent_module;
|
||||
return 0;
|
||||
}
|
||||
|
||||
# Special word to know is something is OK or not,
|
||||
# for example "Running". Defined by user in console. It uses snmp_community
|
||||
|
@ -396,68 +357,47 @@ sub exec_wmi_module {
|
|||
}
|
||||
}
|
||||
|
||||
# Error
|
||||
if ($module_result == 1) {
|
||||
logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_module->{'id_agente_modulo'}." causes an unknown system error", 1);
|
||||
logger ($pa_config, "[ERROR] $@", 1);
|
||||
}
|
||||
|
||||
# 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_module->{'nombre'};
|
||||
$part{'description'}[0] = "";
|
||||
$part{'data'}[0] = $module_data;
|
||||
# If module execution get a valid value
|
||||
my %part;
|
||||
$part{'name'}[0] = $agent_module->{'nombre'};
|
||||
$part{'description'}[0] = "";
|
||||
$part{'data'}[0] = $module_data;
|
||||
my $tipo_modulo = dame_nombretipomodulo_idagentemodulo ($pa_config, $agent_module->{'id_tipo_modulo'}, $dbh);
|
||||
|
||||
# 1 - generic_data
|
||||
# 2 - generic_proc
|
||||
# 3 - generic_data_string
|
||||
# 4 - generic_data_inc
|
||||
# 19, 20 - image
|
||||
|
||||
if (1 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (4 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_inc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (3 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_string ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
# Generic_proc
|
||||
elsif (2 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_proc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif ( (19 == $agent_module->{'id_tipo_modulo'}) || (20 == $agent_module->{'id_tipo_modulo'}) ) {
|
||||
module_generic_image ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
else { # Unknown module!, this IS a problem
|
||||
logger ($pa_config, "WMI Server Problem with unknown module type '$tipo_modulo'", 0);
|
||||
$module_result = 1;
|
||||
}
|
||||
# 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);
|
||||
}
|
||||
|
||||
# If something went wrong in module processing...
|
||||
if ($module_result != 0){
|
||||
|
||||
# If module execution get a INVALID value
|
||||
if ($agent_module->{'intervalo'} == 0){
|
||||
$module_interval = dame_intervalo ($pa_config, $agent_module->{'id_agente'}, $dbh);
|
||||
}
|
||||
|
||||
# Modules who cannot connect or something go bad, update last_execution_try field
|
||||
logger ($pa_config, "Cannot obtain exec WMI Module ".$agent_module->{'nombre'}." from agent $agent_name", 2);
|
||||
my $query_act = "UPDATE tagente_estado SET current_interval = $module_interval, last_execution_try = $utimestamp WHERE id_agente_modulo = ".$agent_module->{'id_agente_modulo'};
|
||||
$dbh->do($query_act);
|
||||
if (1 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (4 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_inc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
elsif (3 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_data_string ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
# Generic_proc
|
||||
elsif (2 == $agent_module->{'id_tipo_modulo'}) {
|
||||
module_generic_proc ($pa_config, \%part, $timestamp, $agent_name, $tipo_modulo, $dbh);
|
||||
}
|
||||
else { # Unknown module!, this IS a problem
|
||||
logger ($pa_config, "WMI Server Problem with unknown module type '$tipo_modulo'", 0);
|
||||
update_on_error ($pa_config, $id_am, $dbh);
|
||||
undef $agent_module;
|
||||
undef %part;
|
||||
return 0;
|
||||
}
|
||||
# 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);
|
||||
|
||||
$exec_sql->finish(); #close tagent_plugin hash reference
|
||||
undef %part;
|
||||
undef $agent_module;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ our @EXPORT = qw(
|
|||
|
||||
# version: Defines actual version of Pandora Server for this module only
|
||||
my $pandora_version = "2.1-dev";
|
||||
my $pandora_build="PS090115";
|
||||
my $pandora_build="PS090116";
|
||||
our $VERSION = $pandora_version." ".$pandora_build;
|
||||
|
||||
# Setup hash
|
||||
|
@ -54,12 +54,12 @@ my %pa_config;
|
|||
sub help_screen {
|
||||
printf "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file > \n\n";
|
||||
printf "Following options are optional : \n";
|
||||
printf " -v : Verbose mode activated, write more information in logfile \n";
|
||||
printf " -d : Debug mode activated, write extensive information in logfile \n";
|
||||
printf " -D : Daemon mode (runs in background)\n";
|
||||
printf " -v : Verbose mode activated, give more information in logfile \n";
|
||||
printf " -d : Debug mode activated, give extensive information in logfile \n";
|
||||
printf " -D : Daemon mode (runs in backgroup)\n";
|
||||
printf " -P <file> : Store PID to file.\n";
|
||||
printf " -q : Quiet startup\n";
|
||||
printf " -h : This screen. It shows a little help screen \n";
|
||||
printf " -h : This screen, show a little help screen \n";
|
||||
printf " \n";
|
||||
exit;
|
||||
}
|
||||
|
@ -78,11 +78,11 @@ sub pandora_init {
|
|||
|
||||
# Load config file from command line
|
||||
if ($#ARGV == -1 ){
|
||||
print "I need at least one parameter: Complete path to Pandora FMS Server configuration file. \n";
|
||||
print "I Need at least one parameter: Complete path to Pandora FMS Server configuration file. \n";
|
||||
help_screen;
|
||||
exit;
|
||||
}
|
||||
$pa_config->{"verbosity"}=1; # Verbose 1 by default
|
||||
$pa_config->{"verbosity"}=0; # Verbose 1 by default
|
||||
$pa_config->{"daemon"}=0; # Daemon 0 by default
|
||||
$pa_config->{'PID'}=""; # PID file not exist by default
|
||||
$pa_config->{"quiet"}=0; # Daemon 0 by default
|
||||
|
@ -115,7 +115,7 @@ sub pandora_init {
|
|||
}
|
||||
}
|
||||
if ($pa_config->{"pandora_path"} eq ""){
|
||||
print " [ERROR] I need at least one parameter: Complete path to Pandora FMS configuration file. \n";
|
||||
print " [ERROR] I Need at least one parameter: Complete path to Pandora FMS configuration file. \n";
|
||||
print " For example: ./pandora_server /etc/pandora/pandora_server.conf\n\n";
|
||||
exit;
|
||||
}
|
||||
|
@ -150,23 +150,21 @@ sub pandora_loadconfig {
|
|||
$pa_config->{"errorlogfile"} = "/var/log/pandora_server.error";
|
||||
$pa_config->{"networktimeout"} = 5; # 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->{"pandora_check"} = 0; # Deprecated since 2.0
|
||||
$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->{"wmiserver"} = 0; # Introduced on 2.0
|
||||
$pa_config->{"pluginserver"} = 0; # Introduced on 2.0
|
||||
$pa_config->{"predictionserver"} = 0; # Introduced on 2.0
|
||||
$pa_config->{"exportserver"} = 0; # 2.0
|
||||
$pa_config->{"inventoryserver"} = 0; # 2.1
|
||||
$pa_config->{"dataserver"} = 1; # default
|
||||
$pa_config->{"networkserver"} = 1; # default
|
||||
$pa_config->{"snmpconsole"} = 1; # default
|
||||
$pa_config->{"reconserver"} = 1; # default
|
||||
$pa_config->{"wmiserver"} = 1; # default
|
||||
$pa_config->{"pluginserver"} = 1; # default
|
||||
$pa_config->{"predictionserver"} = 1; # default
|
||||
$pa_config->{"exportserver"} = 1; # default
|
||||
$pa_config->{"inventoryserver"} = 1; # default
|
||||
$pa_config->{"servermode"} = "";
|
||||
$pa_config->{'snmp_logfile'} = "/var/log/pandora_snmptrap.log";
|
||||
$pa_config->{"network_threads"} = 5; # Fixed default
|
||||
$pa_config->{"network_threads"} = 3; # 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
|
||||
|
@ -175,16 +173,16 @@ sub pandora_loadconfig {
|
|||
$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 2.0
|
||||
$pa_config->{"recon_threads"} = 3; # Introduced on 2.0
|
||||
$pa_config->{"prediction_threads"} = 3; # Introduced on 2.0
|
||||
$pa_config->{"snmp_proc_deadresponse"} = 1; # Introduced on 1.3.1 10 Feb08
|
||||
$pa_config->{"plugin_threads"} = 2; # Introduced on 2.0
|
||||
$pa_config->{"recon_threads"} = 2; # Introduced on 2.0
|
||||
$pa_config->{"prediction_threads"} = 1; # Introduced on 2.0
|
||||
$pa_config->{"plugin_timeout"} = 5; # Introduced on 2.0
|
||||
$pa_config->{"wmi_threads"} = 3; # Introduced on 2.0
|
||||
$pa_config->{"wmi_threads"} = 2; # Introduced on 2.0
|
||||
$pa_config->{"wmi_timeout"} = 5; # Introduced on 2.0
|
||||
$pa_config->{"compound_max_depth"} = 5; # Maximum nested compound alert depth. Not in config file.
|
||||
$pa_config->{"dataserver_threads"} = 3; # Introduced on 2.0
|
||||
$pa_config->{"inventory_threads"} = 5; # 2.1
|
||||
$pa_config->{"dataserver_threads"} = 2; # Introduced on 2.0
|
||||
$pa_config->{"inventory_threads"} = 2; # 2.1
|
||||
|
||||
# Internal MTA for alerts, each server need its own config.
|
||||
$pa_config->{"mta_address"} = '127.0.0.1'; # Introduced on 2.0
|
||||
|
@ -198,7 +196,6 @@ sub pandora_loadconfig {
|
|||
$pa_config->{"xprobe2"} = "/usr/bin/xprobe2";
|
||||
$pa_config->{'autocreate_group'} = 2;
|
||||
$pa_config->{'autocreate'} = 1;
|
||||
$pa_config->{'recon_threads'} = 3;
|
||||
|
||||
# max log size (bytes)
|
||||
$pa_config->{'max_log_size'} = 1048576; # 1MB by default
|
||||
|
@ -427,7 +424,7 @@ sub pandora_loadconfig {
|
|||
} # end of loop for parameter #
|
||||
|
||||
|
||||
if (($pa_config->{"verbosity"} > 0) && ($pa_config->{"quiet"} == 0)){
|
||||
if (($pa_config->{"verbosity"} > 4) && ($pa_config->{"quiet"} == 0)){
|
||||
if ($pa_config->{"PID"} ne ""){
|
||||
print " [*] PID File is written at ".$pa_config->{'PID'}."\n";
|
||||
}
|
||||
|
@ -476,7 +473,7 @@ sub pandora_loadconfig {
|
|||
exit;
|
||||
}
|
||||
# Show some config options in startup
|
||||
if ($pa_config->{"quiet"} == 0){
|
||||
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
|
||||
if ($opmode == 0){
|
||||
print " [*] You are running Pandora FMS Data Server. \n";
|
||||
$parametro ="Pandora FMS Data Server";
|
||||
|
@ -544,7 +541,7 @@ sub pandora_loadconfig {
|
|||
print $@;
|
||||
exit;
|
||||
}
|
||||
if ($pa_config->{"quiet"} == 0){
|
||||
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)){
|
||||
print " [*] Pandora FMS Server [".$pa_config->{'servername'}.$pa_config->{"servermode"}."] is running and operative \n";
|
||||
}
|
||||
$pa_config->{'server_id'} = dame_server_id ($pa_config, $pa_config->{'servername'}.$pa_config->{"servermode"}, $dbh);
|
||||
|
@ -553,7 +550,6 @@ sub pandora_loadconfig {
|
|||
}
|
||||
|
||||
|
||||
|
||||
sub pandora_startlog ($){
|
||||
my $pa_config = $_[0];
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ our @ISA = ("Exporter");
|
|||
our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw(
|
||||
crea_agente_modulo
|
||||
crea_agente_modulo
|
||||
update_on_error
|
||||
dame_server_id
|
||||
dame_agente_id
|
||||
dame_agente_modulo_id
|
||||
|
@ -290,8 +291,6 @@ sub pandora_process_alert (%$$$$$%$$) {
|
|||
$id_agent, $alert_data->{'priority'}, $alert_data->{'id_template_module'}, $alert_data->{'id_agent_module'},
|
||||
"alert_recovered", $dbh);
|
||||
|
||||
# Send a status change report
|
||||
enterprise_hook('pandora_mcast_change_report', [$pa_config, $alert_data->{'id_agent_module'}, $timestamp, 'OK', $dbh]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -305,8 +304,6 @@ sub pandora_process_alert (%$$$$$%$$) {
|
|||
|
||||
execute_alert ($pa_config, $alert_data, $id_agent, $id_group, $agent_name,
|
||||
$module_data, 0, $dbh);
|
||||
# Send a status change report
|
||||
enterprise_hook('pandora_mcast_change_report', [$pa_config, $alert_data->{'id_agent_module'}, $timestamp, 'OK', $dbh]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -360,8 +357,6 @@ sub pandora_process_alert (%$$$$$%$$) {
|
|||
execute_alert ($pa_config, $alert_data, $id_agent, $id_group, $agent_name,
|
||||
$module_data, 1, $dbh);
|
||||
|
||||
# Send a status change report
|
||||
enterprise_hook('pandora_mcast_change_report', [$pa_config, $alert_data->{'id_agent_module'}, $timestamp, 'ERR', $dbh]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -753,18 +748,22 @@ sub pandora_writestate (%$$$$$$) {
|
|||
$event_type = "going_up_warning";
|
||||
$status_name = "going up to WARNING";
|
||||
$severity = 3;
|
||||
enterprise_hook('pandora_mcast_change_report', [$pa_config, $id_agente_modulo, $timestamp, 'WARN', $dbh]);
|
||||
} elsif (($data_status->{'last_status'} == 1) && ($data_status->{'estado'} == 2)){
|
||||
$event_type = "going_down_warning";
|
||||
$status_name = "going down to WARNING";
|
||||
$severity = 3;
|
||||
enterprise_hook('pandora_mcast_change_report', [$pa_config, $id_agente_modulo, $timestamp, 'WARN', $dbh]);
|
||||
} elsif ($data_status->{'estado'} == 1){
|
||||
$event_type = "going_up_critical";
|
||||
$status_name = "going up to CRITICAL";
|
||||
$severity = 4;
|
||||
enterprise_hook('pandora_mcast_change_report', [$pa_config, $id_agente_modulo, $timestamp, 'ERR', $dbh]);
|
||||
} elsif ($data_status->{'estado'} == 0){
|
||||
$event_type = "going_down_normal";
|
||||
$status_name = "going down to NORMAL";
|
||||
$severity = 2;
|
||||
enterprise_hook('pandora_mcast_change_report', [$pa_config, $id_agente_modulo, $timestamp, 'OK', $dbh]);
|
||||
}
|
||||
$data_status->{'status_changes'} = 0;
|
||||
$data_status->{'last_status'} = $data_status->{'estado'};
|
||||
|
@ -861,9 +860,13 @@ sub module_generic_proc (%$$$$$) {
|
|||
my $a_datos = $datos->{data}->[0];
|
||||
|
||||
if ((ref($a_datos) eq "HASH")){
|
||||
$a_datos = 0;# If get bad data, then this is bad value, not "unknown" (> 1.3 version)
|
||||
$a_datos = 0; # If get bad data, then this is bad value, not "unknown" (> 1.3 version)
|
||||
} else {
|
||||
$a_datos = sprintf("%.2f", $a_datos);# Two decimal float. We cannot store more
|
||||
if (!is_numeric($a_datos)){
|
||||
$a_datos = 0;
|
||||
} else {
|
||||
$a_datos = sprintf("%.2f", $a_datos); # Two decimal float. We cannot store more
|
||||
}
|
||||
} # to change this, you need to change mysql structure
|
||||
$a_datos =~ s/\,/\./g; # replace "," by "." avoiding locale problems
|
||||
my $a_name = $datos->{name}->[0];
|
||||
|
@ -2363,6 +2366,26 @@ sub export_module_data {
|
|||
'$data', '$timestamp')");
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# SUB update_on_error (pa_config, id_agent_module, dbh )
|
||||
# Modules who cannot connect or something go bad, update last_execution_try field
|
||||
##########################################################################
|
||||
sub update_on_error {
|
||||
my $pa_config = $_[0];
|
||||
my $id_agent_module = $_[1];
|
||||
my $dbh = $_[2];
|
||||
|
||||
my $utimestamp = &UnixDate("today","%s");
|
||||
|
||||
# Modules who cannot connect or something go bad, update last_execution_try field
|
||||
logger ($pa_config, "Cannot obtain Module from IdAgentModule $id_agent_module", 3);
|
||||
db_update ("UPDATE tagente_estado
|
||||
SET current_interval = 300, last_execution_try = $utimestamp
|
||||
WHERE id_agente_modulo = $id_agent_module", $dbh);
|
||||
;
|
||||
|
||||
}
|
||||
# End of function declaration
|
||||
# End of defined Code
|
||||
|
||||
|
|
Loading…
Reference in New Issue