2007-06-07 Sancho Lerena <slerena@artica.es>

Important update. Now all PM files (library) goes on PandoraFMS
        subdirectory from /bin. This should be copied/moved to system
        default Perl libraries (like /usr/lib/perl). All .PM files changes
        it's name.

        We also replace Net::Ping for Alive checks because recently
        problems discovered in packet lenght payload and problems with
        threads. We fallback to Net::Ping::External, now rewrapped to
        PandoraFMS::PingExternal and distributed with PandoraFMS for easy
        deployment.

        bin/*.pm: Renamed to equivalent files in ./bin/PandoraFMS dir

        * bin/pandora_network.pl: Now uses ping() from PingExternal to
        make alive checks. Latency checks is the only function that
        actually needs root now. External Ping could be executed from any
        user (it uses PING from system).

        * bin/PandoraFMS: Now contains all .PM files for PandoraFMS.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@490 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2007-06-07 10:30:03 +00:00
parent 016aab6d1d
commit 2452a7e164
17 changed files with 586 additions and 146 deletions

View File

@ -1,3 +1,26 @@
2007-06-07 Sancho Lerena <slerena@artica.es>
Important update. Now all PM files (library) goes on PandoraFMS
subdirectory from /bin. This should be copied/moved to system
default Perl libraries (like /usr/lib/perl). All .PM files changes
it's name.
We also replace Net::Ping for Alive checks because recently
problems discovered in packet lenght payload and problems with
threads. We fallback to Net::Ping::External, now rewrapped to
PandoraFMS::PingExternal and distributed with PandoraFMS for easy
deployment.
bin/*.pm: Renamed to equivalent files in ./bin/PandoraFMS dir
* bin/pandora_network.pl: Now uses ping() from PingExternal to
make alive checks. Latency checks is the only function that
actually needs root now. External Ping could be executed from any
user (it uses PING from system).
* bin/PandoraFMS: Now contains all .PM files for PandoraFMS.
2007-06-05 Sancho Lerena <slerena@gmail.com>
* pandora_network.pm: Small bug that causes some hosts to do not reply

View File

@ -1,29 +1,27 @@
package pandora_config;
package PandoraFMS::Config;
##########################################################################
# Pandora Config package
##########################################################################
# Copyright (c) 2004-2007 Sancho Lerena, slerena@gmail.com
# Copyright (c) 2005-2007 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; either version 2
#of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# 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; at version 2.
# 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.
##########################################################################
use warnings;
use Time::Local;
use Date::Manip;
use pandora_tools;
use pandora_db;
use PandoraFMS::Tools;
use PandoraFMS::DB;
require Exporter;
our @ISA = ("Exporter");

View File

@ -1,4 +1,4 @@
package pandora_db;
package PandoraFMS::DB;
##########################################################################
# Pandora FMS Database Package
##########################################################################
@ -26,7 +26,7 @@ use XML::Simple;
use POSIX qw(strtod);
use pandora_tools;
use PandoraFMS::Tools;
require Exporter;
@ -450,31 +450,33 @@ sub pandora_accessupdate (%$$) {
my $id_agent = $_[1];
my $dbh = $_[2];
my $intervalo = dame_intervalo($pa_config, $id_agent, $dbh);
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
my $temp = $intervalo / 2;
my $fecha_limite = DateCalc($timestamp,"- $temp seconds",\$err);
$fecha_limite = &UnixDate($fecha_limite,"%Y-%m-%d %H:%M:%S");
# Fecha limite has limit date, if there are records below this date
# we cannot insert any data in Database. We use a limit based on agent_interval / 2
# So if an agent has interval 300, could have a max of 24 records per hour in access_table
# This is to do not saturate database with access records (because if you hace a network module with interval 30, you have
# a new record each 30 seconds !
# Compare with tagente.ultimo_contacto (tagent_lastcontact in english), so this will have
# the latest update for this agent
my $query = "select count(*) from tagent_access where id_agent = $id_agent and timestamp > '$fecha_limite'";
my $query_exec = $dbh->prepare($query);
my @data_row;
$query_exec ->execute;
@data_row = $query_exec->fetchrow_array();
$temp = $data_row[0];
$query_exec->finish();
if ( $temp == 0) { # We need update access time
my $query2 = "insert into tagent_access (id_agent, timestamp) VALUES ($id_agent,'$timestamp')";
$dbh->do($query2);
logger($pa_config,"Updating tagent_access for agent id $id_agent",9);
}
if ($id_agent != -1){
my $intervalo = dame_intervalo ($pa_config, $id_agent, $dbh);
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
my $temp = $intervalo / 2;
my $fecha_limite = DateCalc($timestamp,"- $temp seconds",\$err);
$fecha_limite = &UnixDate($fecha_limite,"%Y-%m-%d %H:%M:%S");
# Fecha limite has limit date, if there are records below this date
# we cannot insert any data in Database. We use a limit based on agent_interval / 2
# So if an agent has interval 300, could have a max of 24 records per hour in access_table
# This is to do not saturate database with access records (because if you hace a network module with interval 30, you have
# a new record each 30 seconds !
# Compare with tagente.ultimo_contacto (tagent_lastcontact in english), so this will have
# the latest update for this agent
my $query = "select count(*) from tagent_access where id_agent = $id_agent and timestamp > '$fecha_limite'";
my $query_exec = $dbh->prepare($query);
my @data_row;
$query_exec ->execute;
@data_row = $query_exec->fetchrow_array();
$temp = $data_row[0];
$query_exec->finish();
if ( $temp == 0) { # We need update access time
my $query2 = "insert into tagent_access (id_agent, timestamp) VALUES ($id_agent,'$timestamp')";
$dbh->do($query2);
logger($pa_config,"Updating tagent_access for agent id $id_agent",9);
}
}
}
##########################################################################
@ -638,7 +640,7 @@ sub module_generic_data_inc (%$$$$$) {
my $new_data = 0;
my $data_anterior = 0;
my $timestamp_diferencia;
my $timestamp_anterior;
my $timestamp_anterior = 0;
my $m_utimestamp = &UnixDate ($m_timestamp, "%s");
if ($id_agente_modulo == -1) {
@ -1014,7 +1016,7 @@ sub pandora_lastagentcontact (%$$$$$$) {
$query = "update tagente set intervalo = $interval, agent_version = '$agent_version', ultimo_contacto_remoto = '$timestamp', ultimo_contacto = '$time_now', os_version = '$os_data' where id_agente = $id_agente";
}
logger( $pa_config, "pandora_lastagentcontact: Updating Agent last contact data for $nombre_agente",6);
logger( $pa_config, "pandora_lastagentcontact: SQL Query: ".$query,10);
logger( $pa_config, "pandora_lastagentcontact: SQL Query: ".$query,10);
my $sag = $dbh->prepare($query);
$sag ->execute;
$sag ->finish();
@ -1470,23 +1472,26 @@ sub give_network_component_profile_name (%$$) {
## Return interval for id_agente
##########################################################################
sub dame_intervalo (%$$) {
my $pa_config = $_[0];
my $id_agente = $_[1];
my $dbh = $_[2];
my $pa_config = $_[0];
my $id_agente = $_[1];
my $dbh = $_[2];
my $tipo; my @data;
# Calculate agent ID using select by its name
my $query_idag = "select * from tagente where id_agente = ".$id_agente;
my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute;
if ($s_idag->rows == 0) {
logger($pa_config, "ERROR dame_intervalo(): Cannot find agente $id_agente",1);
logger($pa_config, "ERROR: SQL Query is $query_idag ",2);
$tipo = 0;
} else { @data = $s_idag->fetchrow_array(); }
$tipo= $data[7];
$s_idag->finish();
return $tipo;
my $tipo = 0;
my @data;
# Calculate agent ID using select by its name
my $query_idag = "select * from tagente where id_agente = ".$id_agente;
my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute;
if ($s_idag->rows == 0) {
logger($pa_config, "ERROR dame_intervalo(): Cannot find agente $id_agente",1);
logger($pa_config, "ERROR: SQL Query is $query_idag ",2);
$tipo = 0;
} else {
@data = $s_idag->fetchrow_array();
}
$tipo= $data[7];
$s_idag->finish();
return $tipo;
}
##########################################################################

View File

@ -0,0 +1,416 @@
package PandoraFMS::PingExternal;
# Repackaged to "PandoraFMS::PingExternal" due to problems find RPM packages for Net::Ping::External
# Author: Colin McMillen (colinm@cpan.org)
# See also the CREDITS section in the POD below.
#
# Copyright (c) 2003 Colin McMillen. All rights reserved. This
# program is free software; you may redistribute it and/or modify it
# under the same terms as Perl itself.
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
use Carp;
use Socket qw(inet_ntoa);
require Exporter;
$VERSION = "0.11";
our @ISA = ("Exporter");
our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw(ping);
sub ping {
# Set up defaults & override defaults with parameters sent.
my %args = (count => 1, size => 56, @_);
# "host" and "hostname" are synonyms.
$args{host} = $args{hostname} if defined $args{hostname};
# If we have an "ip" argument, convert it to a hostname and use that.
$args{host} = inet_ntoa($args{ip}) if defined $args{ip};
# croak() if no hostname was provided.
croak("You must provide a hostname") unless defined $args{host};
$args{timeout} = 5 unless defined $args{timeout} && $args{timeout} > 0;
my %dispatch =
(linux => \&_ping_linux,
mswin32 => \&_ping_win32,
cygwin => \&_ping_win32,
solaris => \&_ping_solaris,
bsdos => \&_ping_bsdos,
beos => \&_ping_beos,
hpux => \&_ping_hpux,
dec_osf => \&_ping_dec_osf,
bsd => \&_ping_bsd,
darwin => \&_ping_darwin,
openbsd => \&_ping_unix,
freebsd => \&_ping_freebsd,
next => \&_ping_next,
unicosmk => \&_ping_unicosmk,
netbsd => \&_ping_unix,
irix => \&_ping_unix,
aix => \&_ping_aix,
);
my $subref = $dispatch{lc $^O};
croak("External ping not supported on your system") unless $subref;
return $subref->(%args);
}
# Win32 is the only system so far for which we actually need to parse the
# results of the system ping command.
sub _ping_win32 {
my %args = @_;
$args{timeout} *= 1000; # Win32 ping timeout is specified in milliseconds
my $command = "ping -l $args{size} -n $args{count} -w $args{timeout} $args{host}";
print "$command\n" if $DEBUG;
my $result = `$command`;
return 1 if $result =~ /time.*ms/;
return 0;
}
# Generic subroutine to handle pinging using the system() function. Generally,
# UNIX-like systems return 0 on a successful ping and something else on
# failure. If the return value of running $command is equal to the value
# specified as $success, the ping succeeds. Otherwise, it fails.
sub _ping_system {
my ($command, # The ping command to run
$success, # What value the system ping command returns on success
) = @_;
my $devnull = "/dev/null";
$command .= " 1>$devnull 2>$devnull";
my $exit_status = system($command) >> 8;
return 1 if $exit_status == $success;
return 0;
}
# Below are all the systems on which _ping_system() has been tested
# and found OK.
# Mac OS X 10.2 ping does not handle -w timeout now does it return a
# status code if it fails to ping (unless it cannot resolve the domain
# name)
# Thanks to Peter N. Lewis for this one.
sub _ping_darwin {
my %args = @_;
my $command = "ping -s $args{size} -c $args{count} $args{host}";
my $devnull = "/dev/null";
$command .= " 2>$devnull";
print "$command\n" if $DEBUG;
my $result = `$command`;
return 1 if $result =~ /(\d+) packets received/ && $1 > 0;
return 0;
}
# Assumed OK for DEC OSF
sub _ping_dec_osf {
my %args = @_;
my $command = "ping -c $args{count} -s $args{size} -q -u $args{host}";
return _ping_system($command, 0);
}
# Assumed OK for unicosmk
sub _ping_unicosmk {
my %args = @_;
my $command = "ping -s $args{size} -c $args{count} $args{host}";
return _ping_system($command, 0);
}
# NeXTStep 3.3/sparc
sub _ping_next {
my %args = @_;
my $command = "ping $args{host} $args{size} $args{count}";
return _ping_system($command, 0);
}
# Assumed OK for HP-UX.
sub _ping_hpux {
my %args = @_;
my $command = "ping $args{host} $args{size} $args{count}";
return _ping_system($command, 0);
}
# Assumed OK for BSD/OS 4.
sub _ping_bsdos {
my %args = @_;
my $command = "ping -c $args{count} -s $args{size} $args{host}";
return _ping_system($command, 0);
}
# Assumed OK for BeOS.
sub _ping_beos {
my %args = @_;
my $command = "ping -c $args{count} -s $args{size} $args{host}";
return _ping_system($command, 0);
}
# Assumed OK for AIX
sub _ping_aix {
my %args = @_;
my $command = "ping -c $args{count} -s $args{size} -q $args{host}";
return _ping_system($command, 0);
}
# OpenBSD 2.7 OK, IRIX 6.5 OK
# Assumed OK for NetBSD & FreeBSD, but needs testing
sub _ping_unix {
my %args = @_;
my $command = "ping -s $args{size} -c $args{count} -w $args{timeout} $args{host}";
return _ping_system($command, 0);
}
# Assumed OK for FreeBSD 3.4
# -s size option supported -- superuser only... fixme
sub _ping_bsd {
my %args = @_;
my $command = "ping -c $args{count} -q $args{hostname}";
return _ping_system($command, 0);
}
# Debian 2.2 OK, RedHat 6.2 OK
# -s size option available to superuser... FIXME?
sub _ping_linux {
my %args = @_;
my $command = "ping -c $args{count} $args{host}";
return _ping_system($command, 0);
}
# Solaris 2.6, 2.7 OK
sub _ping_solaris {
my %args = @_;
my $command = "ping -s $args{host} $args{size} $args{timeout}";
return _ping_system($command, 0);
}
# FreeBSD. Tested OK for Freebsd 4.3
# -s size option supported -- superuser only... FIXME?
# -w timeout option for BSD replaced by -t
sub _ping_freebsd {
my %args = @_;
my $command = "ping -c $args{count} -t $args{timeout} $args{host}";
return _ping_system($command, 0);
}
1;
__END__
=head1 NAME
Net::Ping::External - Cross-platform interface to ICMP "ping" utilities
=head1 SYNOPSIS
In general:
use Net::Ping::External qw(ping);
ping(%options);
Some examples:
use Net::Ping::External qw(ping);
# Ping a single host
my $alive = ping(host => "127.0.0.1");
print "127.0.0.1 is online" if $alive;
# Or a list of hosts
my @hosts = qw(127.0.0.1 127.0.0.2 127.0.0.3 127.0.0.4);
my $num_alive = 0;
foreach (@hosts) {
$alive = ping(hostname => $_, timeout => 5);
print "$_ is alive!\n" if $alive;
$num_alive++;
}
print "$num_alive hosts are alive.\n";
# Using all the fancy options:
ping(hostname => "127.0.0.1", count => 5, size => 1024, timeout => 3);
=head1 DESCRIPTION
Net::Ping::External is a module which interfaces with the "ping" command
on many systems. It presently provides a single function, C<ping()>, that
takes in a hostname and (optionally) a timeout and returns true if the
host is alive, and false otherwise. Unless you have the ability (and
willingness) to run your scripts as the superuser on your system, this
module will probably provide more accurate results than Net::Ping will.
Why?
=over 4
=item *
ICMP ping is the most reliable way to tell whether a remote host is alive.
=item *
However, Net::Ping cannot use an ICMP ping unless you are running your
script with privileged (AKA "root") access.
=item *
The system's "ping" command uses ICMP and does not usually require
privileged access.
=item *
While it is relatively trivial to write a Perl script that parses the
output of the "ping" command on a given system, the aim of this module
is to encapsulate this functionality and provide a single interface for
it that works on many systems.
=back
=head2 ping() OPTIONS
This module is still "alpha"; it is expected that more options to the C<ping()>
function will be added soon.
=over 4
=item * C<host, hostname>
The hostname (or dotted-quad IP address) of the remote host you are trying
to ping. You must specify either the "hostname" option or the "ip" option.
"host" and "hostname" are synonymous.
=item * C<ip>
A packed bit-string representing the 4-byte packed IP address (as
returned by C<Socket.pm>'s C<inet_aton()> function) of the host that you
would like to ping.
=item * C<timeout>
The maximum amount of time, in seconds, that C<ping()> will wait for a response.
If the remote system does not respond before the timeout has elapsed, C<ping()>
will return false.
Default value: 5.
=item * C<count>
The number of ICMP ping packets to send to the remote host. Eventually,
Net::Ping::External will return the number of packets that were acknowledged
by the remote host; for now, however, C<ping()> still returns just true or false.
Default value: 1.
=item * C<size>
Specifies the number of data bytes to be sent. The default is
56, which translates into 64 ICMP data bytes when combined with
the 8 bytes of ICMP header data.
Default value: 56.
=back
=head2 SUPPORTED PLATFORMS
Support currently exists for interfacing with the standard ping
utilities on the following systems. Please note that the path to the `ping'
should be somewhere in your PATH environment variable (or your system's
closest equivalent thereof.) Otherwise, Net::Ping::External will be unable
to locate your system's `ping' command.
=over 4
=item * Win32
Tested OK on Win98. It should work on other Windows systems as well.
=item * Linux
Tested OK on Debian 2.2 and Redhat 6.2. It appears that different versions
of Linux use different versions of ping, which support different options.
Not sure how I'm going to resolve this yet; for now, all the options but
C<count> are disabled.
=item * BSD
Tested OK on OpenBSD 2.7. Needs testing for FreeBSD, NetBSD, and BSDi.
=item * Solaris
Tested OK on Solaris 2.6 and 2.7.
=item * IRIX
Tested OK on IRIX 6.5.
=item * AIX, DEC OSF, UNICOSMK, NeXTStep, HP-UX, BSD/OS (BSDi), BeOS
Support for these systems is integrated into this module but none have been
tested yet. If you have successful or unsuccessful test results for any of
these systems, please send them to me. On some of these systems, some of the
arguments may not be supported. If you'd like to see better support on your
system, please e-mail me.
=back
More systems will be added as soon as any users request them. If your
system is not currently supported, e-mail me; adding support to your
system is probably trivial.
=head1 BUGS
This module should be considered alpha. Bugs may exist. Although no
specific bugs are known at this time, the module could use testing
on a greater variety of systems.
See the warning below.
=head1 WARNING
This module calls whatever "ping" program it first finds in your PATH
environment variable. If your PATH contains a trojan "ping" program,
this module will call that program. This involves a small amount of
risk, but no more than simply typing "ping" at a system prompt.
Beware Greeks bearing gifts.
=head1 AUTHOR
Colin McMillen (colinm@cpan.org)
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 CREDITS
Dan Moore contributed command-line options and code for NeXT, BeOS,
HP-UX, and BSD/OS.
Jarkko Hietaniemi contributed a huge list of command-line options and results
for the `ping' command on 9 different systems.
Randy Moore contributed several patches for Win32 support.
Marc-Andre Dumas contributed a patch for FreeBSD support.
Jonathan Stowe fixed a bug in 0.09 that prevented the module from
running on some systems.
Numerous people sent in a patch to fix a bug in 0.10 that broke ping on Windown systems.
Peter N. Lewis contributed a patch that works correctly on Mac OS X
10.2 (and hopefully other versions as well).
=head1 SEE ALSO
Net::Ping
=cut

View File

@ -1,4 +1,4 @@
package pandora_tools;
package PandoraFMS::Tools;
##########################################################################
# Pandora Tools Package
##########################################################################

View File

@ -3,19 +3,6 @@
# DBI Memory Leak Tester
##################################################################################
# Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com
# Copyright (c) 2005-2006 Artica Soluciones Tecnológicas 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; either version 2
#of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##################################################################################
use DBI(); # DB interface with MySQL

View File

@ -29,9 +29,10 @@ use SNMP; # For SNMP access (libsnmp-perl PACKAGE!)
use threads;
# Pandora Modules
use pandora_config;
use pandora_tools;
use pandora_db;
use PandoraFMS::Config;
use PandoraFMS::Tools;
use PandoraFMS::DB;
use PandoraFMS::PingExternal; # Use Net:Ping:External (renamed to pandora_ping_external)
# FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE
@ -327,27 +328,22 @@ sub pandora_ping_icmp {
my $l_timeout = $_[1];
# temporal vars.
my $result = 0;
my $p;
# Check for valid destination
if (!defined($dest)) {
return 0;
}
# Some hosts don't accept ICMP with too small payload. Use 32Bytes
$p = Net::Ping->new("icmp",$l_timeout,32);
$result = $p->ping($dest);
$result = ping(hostname => $dest, timeout => $l_timeout, size => 32, count => 1);
# Check for valid result
if (!defined($result)) {
return 0;
}
# Lets see the result
if ($result == 1) {
$p->close();
return 1;
} else {
$p->close();
return 0;
}
}

View File

@ -31,9 +31,9 @@ use Socket; # to resolve address
use threads;
# Pandora Modules
use pandora_config;
use pandora_tools;
use pandora_db;
use PandoraFMS::Config;
use PandoraFMS::Tools;
use PandoraFMS::DB;
# FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE

View File

@ -31,9 +31,9 @@ use threads;
use threads::shared;
# Pandora Modules
use pandora_config;
use pandora_tools;
use pandora_db;
use PandoraFMS::Config;
use PandoraFMS::Tools;
use PandoraFMS::DB;
# FLUSH in each IO, only for DEBUG, very slow !
$| = 0;

View File

@ -27,9 +27,9 @@ use Time::Local; # DateTime basic manipulation
use Time::HiRes; # For high precission timedate functions (Net::Ping)
# Pandora Modules
use pandora_config;
use pandora_tools;
use pandora_db;
use PandoraFMS::Config;
use PandoraFMS::Tools;
use PandoraFMS::DB;
# FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE

View File

@ -6,12 +6,12 @@
# if not given, it takes localhost. It's preferable to setup one
# because machine name could change by some reason.
servername endor
servername ulises
# incomingdir: Defines directory where incoming data packets are stored
# You could set directory relative to base path or absolute, starting with /
incomingdir /var/spool/pandora/data_in
incomingdir /opt/pandora_server/data_in
# log_file: Main logfile for pandora_server
# You could set file relative to base path or absolute, starting with /
@ -25,11 +25,11 @@ errorlog_file /var/log/pandora_server.error
# dbname: Database name (pandora by default
dbname pandora13
dbname pandora
# dbuser: Database user name (pandora by default)
dbuser pandora
dbuser root
# daemon: Runs in daemon mode (background) if 1, if 0 runs in foreground
# this could be setup on command line with -D option
@ -38,7 +38,7 @@ dbuser pandora
# dbpass: Database password
dbpass pandora
dbpass none
# dbhost: Database hostname or IP address
@ -47,7 +47,7 @@ dbhost localhost
# verbosity: level of detail on errors/messages (0 default, 1 verbose, 2 debug.... 10 noisy)
# -v in command line (verbose) or -d (debug)
verbosity 1
verbosity 10
# Alert threshold

View File

@ -0,0 +1 @@
../bin/PandoraFMS/

View File

@ -1 +0,0 @@
../bin/pandora_config.pm

View File

@ -1,12 +1,22 @@
#!/usr/bin/perl
##################################################################################
# Pandora DB Management
##################################################################################
# (c) Sancho Lerena, slerena@gmail.com
# This code is licensed as GPL v2. Please, if you want to modify or use
# for your own purposes, read before GPL v2 license at www.gnu.org/licenses/gpl.txt
##################################################################################
# Pandora FMS DB Management
################################################################################
# Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com
# Copyright (c) 2005-2006 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
# 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;
@ -15,10 +25,11 @@ use DBI; # DB interface with MySQL
use Date::Manip; # Date/Time manipulation
# version: define la version actual del programa
my $version = "1.2beta";
my $version = "1.3 dev";
# Setup variables
my $dirname="";
my $dbname = 'pandora';
my $dbhost ='';
my $dbuser ='';
my $verbosity ='';
@ -56,11 +67,11 @@ sub pandora_purgedb {
# 2) Delete all elements below date limit
# 3) Insert last value in date_limit position
my $days = $_[0];
my $dbname = $_[1];
my $dbuser = $_[2];
my $dbpass = $_[3];
my $dbhost = $_[4];
my $days = $_[0];
my $dbname = $_[1];
my $dbuser = $_[2];
my $dbpass = $_[3];
my $dbhost = $_[4];
my @query;
my $counter;
my $buffer; my $buffer2; my $buffer3;
@ -139,11 +150,11 @@ sub pandora_purgedb {
## SUB pandora_compactdb (days, dbname, dbuser, dbpass, dbhost)
##################################################################################
sub pandora_compactdb {
my $days = $_[0];
my $dbname = $_[1];
my $dbuser = $_[2];
my $dbpass = $_[3];
my $dbhost = $_[4];
my $days = $_[0];
my $dbname = $_[1];
my $dbuser = $_[2];
my $dbpass = $_[3];
my $dbhost = $_[4];
my @data_item; # Array to get data from each record of DB
my %data_list; # Hash to store values (sum) for each id
my %data_list_items; # Hash to store total values for each id
@ -308,7 +319,8 @@ sub pandora_loadconfig {
$parametro = $args[$ax];
if ($parametro =~ m/dirname\z/) { $dirname = $args[$ax+1]; $ax++; }
elsif ($parametro =~ m/dbuser\z/) { $dbuser = $args[$ax+1]; $ax++; }
elsif ($parametro =~ m/dbpass\z/) { $dbpass = $args[$ax+1]; $ax++; }
elsif ($parametro =~ m/dbpass\z/) { $dbpass = $args[$ax+1]; $ax++; }
elsif ($parametro =~ m/dbname\z/) { $dbname = $args[$ax+1]; $ax++; }
elsif ($parametro =~ m/dbhost\z/) { $dbhost = $args[$ax+1]; $ax++; }
elsif ($parametro =~ m/log_file\z/) { $log_file = $args[$ax+1]; $ax++; }
elsif ($parametro =~ m/verbosity\z/) { $verbosity = $args[$ax+1]; $ax++; }
@ -374,7 +386,7 @@ sub pandora_loadconfig {
##############################################################################
sub help_screen{
printf "\n\nSintax: \n pandora_db.pl fullpathname_to_pandora_server.conf \n\n";
printf "\n\nSintax: \n pandora_db.pl fullpathname_to_pandora_server.conf \n\n";
exit;
}
@ -382,7 +394,7 @@ sub help_screen{
# Program main begin
# #################################################################################
sub pandoradb_main {
pandora_purgedb($config_days_purge,"pandora",$dbuser,$dbpass,$dbhost);
pandora_compactdb($config_days_compact,"pandora",$dbuser,$dbpass,$dbhost);
pandora_purgedb ($config_days_purge, $dbname, $dbuser, $dbpass, $dbhost);
pandora_compactdb ($config_days_compact, $dbname, $dbuser, $dbpass, $dbhost);
exit;
}

View File

@ -1 +0,0 @@
../bin/pandora_db.pm

View File

@ -3,25 +3,26 @@
# Pandora DB Stress tool
################################################################################
# Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com
# Copyright (c) 2005-2006 Artica Soluciones Tecnológicas S.L
# Copyright (c) 2005-2006 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; either version 2
#of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# 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
# 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.
################################################################################
# Configure here target (AGENT_ID for Stress)
my $target_agent_id = 1; # -1 for all modules of that agent
my $target_interval = 300;
my $target_days = 45;
my $target_module = -1; # -1 for all modules of that agent
my $target_agent = -1;
my $target_interval = 1200;
my $target_days = 12;
################################################################################
################################################################################
@ -34,14 +35,14 @@ use Date::Manip; # Date/Time manipulation
use Math::Trig; # Math functions
# Pandora Modules
use pandora_config;
use pandora_tools;
use pandora_db;
use PandoraFMS::Config;
use PandoraFMS::Tools;
use PandoraFMS::DB;
################################################################################
################################################################################
my $version = "1.3-dev 070216";
my $version = "1.3-dev 070526";
# FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE
@ -57,9 +58,9 @@ pandora_init(\%pa_config,"Pandora DB Stress tool");
pandora_loadconfig (\%pa_config,0); #Start like a data server
# open database, only ONCE. We pass reference to DBI handler ($dbh) to all subprocess
my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config{'dbhost'}:3306",$pa_config{'dbuser'}, $pa_config{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
my $dbh = DBI->connect("DBI:mysql:$pa_config{'dbname'}:$pa_config{'dbhost'}:3306",$pa_config{'dbuser'}, $pa_config{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
print " [*] Working for agent ID $target_agent_id \n";
print " [*] Working for agent ID $target_agent \n";
print " [*] Generating data of $target_days days ago \n";
print " [*] Interval for this workload is $target_interval \n";
@ -67,7 +68,11 @@ print " [*] Interval for this workload is $target_interval \n";
my $query_idag;
if ($target_agent ne -1){
$query_idag = "select * from tagente_modulo where id_agente = $target_agent";
if ($target_module ne -1){
$query_idag = "select * from tagente_modulo where id_agente = $target_agent AND id_agente_modulo = $target_module";
} else {
$query_idag = "select * from tagente_modulo where id_agente = $target_agent";
}
} else {
$query_idag = "select * from tagente_modulo";
}
@ -78,7 +83,7 @@ my @data;
if ($s_idag->rows != 0) {
while (@data = $s_idag->fetchrow_array()) {
# Fill this module with data !
process_module (\%pa_config, $data[0], $target_interval, $data[4], $target_days, $data[2], $target_agent_id, $dbh);
process_module (\%pa_config, $data[0], $target_interval, $data[4], $target_days, $data[2], $data[1], $dbh);
}
}
$s_idag->finish();

View File

@ -1 +0,0 @@
../bin/pandora_tools.pm