2009-09-16 Sancho Lerena <slerena@artica.es>

* util/pandora_exec -> bin/pandora_exec: Moved.

	* pandora_server -> util/pandora_server: Moved.

	* plugins/pandora_loadgen.pl
	plugins/pandora_server_status.pl: New plugins for generate data
	and get Pandora FMS server status and load.

	* Config.pm, pandora_db.pl: Version update.

	* pandora_server.spec, 
	Makefile.PL, 
	pandora_server_installer: Updated paths and dependencies



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1946 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2009-09-16 00:02:23 +00:00
parent 13a57d5132
commit bd11f96020
10 changed files with 334 additions and 33 deletions

View File

@ -1,3 +1,19 @@
2009-09-16 Sancho Lerena <slerena@artica.es>
* util/pandora_exec -> bin/pandora_exec: Moved.
* pandora_server -> util/pandora_server: Moved.
* plugins/pandora_loadgen.pl
plugins/pandora_server_status.pl: New plugins for generate data
and get Pandora FMS server status and load.
* Config.pm, pandora_db.pl: Version update.
* pandora_server.spec,
Makefile.PL,
pandora_server_installer: Updated paths and dependencies
2009-09-15 Sancho Lerena <slerena@artica.es>
* util/pandora_backup.sh: Finished backup command line tool

View File

@ -12,16 +12,14 @@ WriteMakefile(
IO::Socket => 0,
Time::Format => 0,
Time::Local => 0,
Date::Manip => 0,
XML::Simple => 0,
Time::HiRes => 0,
IO::Socket => 0,
Mail::Sendmail => 0,
Net::Traceroute::PurePerl => 0,
HTML::Entities => 0,
SNMP => 0
},
EXE_FILES => [ 'bin/pandora_server', 'util/pandora_exec'],
EXE_FILES => [ 'bin/pandora_server', 'bin/pandora_exec'],
PMLIBDIRS => [ 'lib' ],
'dist' => { 'TAR' => 'tar', 'TARFLAGS' => 'cvfz', 'SUFFIX'
=> '.gz', 'COMPRESS' => 'gzip'}

View File

@ -4,7 +4,7 @@
#
# Executes the given command and prints its output to stdout. If the
# execution times out or the command does not exist nothing is printed
# to stdout.
# to stdout. This is part of Pandora FMS Plugin server, do not delete!.
#
# Usage: pandora_exec <timeout in seconds> <command> [arguments]
##########################################################################

View File

@ -37,7 +37,7 @@ our @EXPORT = qw(
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "3.0-dev";
my $pandora_build = "PS090901";
my $pandora_build = "PS090915";
our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash

View File

@ -22,7 +22,7 @@ Requires(pre): /usr/sbin/useradd
AutoReq: 0
Provides: %{name}-%{version}
Requires: perl-mail-sendmail perl-DBI perl-DBD-mysql perl-time-format
Requires: perl-mail-sendmail perl-netaddr-ip perl-SNMP net-snmp
Requires: perl-mail-sendmail perl-netaddr-ip net-snmp
Requires: nmap wmic sudo
%description
@ -36,8 +36,10 @@ rm -rf $RPM_BUILD_ROOT
%build
%install
#Uncomment this if you build from other RPM system (fedora, opensuse != 11..)
#%define perl_version %(rpm -q --queryformat='%{VERSION}' perl)
#export perl_version=`rpm -q --queryformat='%{VERSION}' perl`
# Temporal hack for For SLES 11 only, warning
export perl_version=5.10.0
%define perl_version 5.10.0
@ -55,18 +57,18 @@ mkdir -p $RPM_BUILD_ROOT/var/spool/pandora/data_in/md5
mkdir -p $RPM_BUILD_ROOT/var/log/pandora/
mkdir -p $RPM_BUILD_ROOT%{prefix}/pandora_server/conf/
mkdir -p $RPM_BUILD_ROOT/usr/lib/perl5/site_perl/$perl_version/
# All binaries go to /usr/local/bin
cp -aRf bin/pandora_server $RPM_BUILD_ROOT/usr/local/bin/
cp -aRf util/pandora_exec $RPM_BUILD_ROOT/usr/local/bin/
cp -aRf bin/pandora_exec $RPM_BUILD_ROOT/usr/local/bin/
cp -aRf bin/tentacle_server $RPM_BUILD_ROOT/usr/local/bin/
#cp -aRf util/wmic $RPM_BUILD_ROOT/usr/bin/
cp -aRf conf/* $RPM_BUILD_ROOT%{prefix}/pandora_server/conf/
cp -aRf util $RPM_BUILD_ROOT%{prefix}/pandora_server/
cp -aRf lib/* $RPM_BUILD_ROOT/usr/lib/perl5/site_perl/$perl_version/
#cp -aRf util/Time/ $RPM_BUILD_ROOT/usr/lib/perl5/site_perl/$perl_version/
#cp -aRf util/Traceroute/ $RPM_BUILD_ROOT/usr/lib/perl5/site_perl/$perl_version/Net
#cp -aRf util/Traceroute.pm $RPM_BUILD_ROOT/usr/lib/perl5/site_perl/$perl_version/Net
cp -aRf AUTHORS COPYING ChangeLog README $RPM_BUILD_ROOT%{prefix}/pandora_server/
cp -aRf pandora_server $RPM_BUILD_ROOT/etc/init.d/
cp -aRf util/pandora_server $RPM_BUILD_ROOT/etc/init.d/
cp -aRf util/tentacle_serverd $RPM_BUILD_ROOT/etc/init.d/
%clean

View File

@ -59,15 +59,15 @@ install () {
echo "The complete installation guide is at: "http://www.openideas.info/wiki/index.php?title=Pandora_2.0:Documentation_en:Install_Server#Pandora_FMS_Server_installation" "
echo " "
echo "Debian-based distribution do:"
echo " $ apt-get install libdate-manip-perl snmp snmpd libsnmp-perl libtime-format-perl libxml-simple-perl libnetaddr-ip-perl libdbi-perl libxml-simple-perl libnetaddr-ip-perl libhtml-parser-perl wmi-client xprobe2 libmail-sendmail-perl"
echo " $ apt-get install snmp snmpd libtime-format-perl libxml-simple-perl libnetaddr-ip-perl libdbi-perl libxml-simple-perl libnetaddr-ip-perl libhtml-parser-perl wmi-client xprobe2 libmail-sendmail-perl"
echo " "
echo "RPM distribution do"
echo " "
echo " $ yum perl-XML-SAX* perl-Tie* perl-XML-Simple* perl-IO-Socket* perl-Time-modules* perl-NetAddr-IP* perl-GD* perl-DateTime* perl-ExtUtils perl-DBI perl-Date-Manip perl-SNMP"
echo " $ yum perl-XML-SAX* perl-Tie* perl-XML-Simple* perl-IO-Socket* perl-Time-modules* perl-NetAddr-IP* perl-DateTime* perl-ExtUtils perl-DBI"
echo " "
echo "To get it from source through CPAN do"
echo " "
echo " $ cpan Digest::MD5 Time::Local DBI threads threads::shared IO::Socket Time::HiRes Time::Format NetAddr::IP Mail::Sendmail Net::Traceroute::PurePerl HTML::Entities Date::Manip"
echo " $ cpan Digest::MD5 Time::Local DBI XML::Simple IO::Socket Time::HiRes Time::Format NetAddr::IP Mail::Sendmail Net::Traceroute::PurePerl HTML::Entities"
echo " "
rm output
else
@ -111,7 +111,7 @@ install () {
then
chown -R pandora:www-data /var/spool/pandora/
else
chown -R pandora:www /var/spool/pandora/
chown -R pandora:www /var/spool/pandora/
fi
echo "Creating setup directory in /etc/pandora"
@ -126,7 +126,7 @@ install () {
chmod 770 /etc/pandora/pandora_server.conf
echo "Copying the daemon script into /etc/init.d/pandora_server"
cp pandora_server /etc/init.d/
cp util/pandora_server /etc/init.d/
if [ "$DISTRO" == "UBUNTU" ]
then
@ -138,14 +138,6 @@ install () {
ln -s /etc/init.d/pandora_server /etc/rc.d/rc$INITLV.d/S90pandora_server
fi
echo "Creating links for /usr/local/bin/pandora_server"
if [ -e /usr/local/bin/pandora_server ]
then
ln -s /usr/local/bin/pandora_server /usr/bin/pandora_server 2> /dev/null
else
ln -s /usr/bin/pandora_server /usr/local/bin/pandora_server 2> /dev/null
fi
echo "Creating logrotate.d entry for Pandora FMS log management"
cp util/pandora_logrotate /etc/logrotate.d/pandora

View File

@ -26,7 +26,7 @@ use PandoraFMS::Tools;
use PandoraFMS::DB;
# version: define la version actual del programa
my $version = "2.1 PS090105";
my $version = "3.0 PS090915";
# Setup variables
my $dirname="";
@ -86,9 +86,6 @@ sub pandora_purgedb {
my $ulimit_timestamp = &UnixDate("today","%s") - (86400 * $days);
my $limit_timestamp = DateCalc("today","-$days days",\$err);
print "[PURGE] Deleting old access data (More than 24hr) \n";
$dbh->do("DELETE FROM tagent_access WHERE utimestamp < '$ulimit_access_timestamp'");
print "[PURGE] Deleting old event data (More than $config_days_purge days)... \n";
$dbh->do("DELETE FROM tevento WHERE utimestamp < '$ulimit_timestamp'");
@ -117,6 +114,9 @@ sub pandora_purgedb {
print "[PURGE] Delete old data from SNMP Traps \n";
$dbh->do ("DELETE FROM ttrap WHERE timestamp < '$limit_timestamp'");
print "[PURGE] Deleting old access data (More than 24hr) \n";
$dbh->do("DELETE FROM tagent_access WHERE utimestamp < '$ulimit_access_timestamp'");
$dbh->disconnect();
}
@ -251,7 +251,7 @@ sub pandora_compactdb {
##############################################################################
sub pandora_init {
print "\nPandora FMS DB Tool $version Copyright (c) 2004-2008 Sancho Lerena\n";
print "\nPandora FMS DB Tool $version Copyright (c) 2004-2008 Artica ST\n";
print "This program is Free Software, licensed under the terms of GPL License v2\n";
print "You can download latest versions and documentation at http://www.pandorafms.org\n";

View File

@ -2,9 +2,9 @@
# Pandora FMS Server, startup script
# Copyright (c) 2006-2009 Sancho Lerena, <sancho.lerena@artica.es>
# Linux Version (generic), for SuSe and Debian/Ubuntu.
# Linux Version (generic), for SuSe, Debian and Ubuntu.
# other Linux distros could not work properly without modifications
# v3.0 Build 090810
# v3.0 Build 090915
# http://www.pandorafms.com
### BEGIN INIT INTO
@ -25,7 +25,7 @@ PANDORA_DAEMON=/usr/local/bin/pandora_server
# This function replace pidof, not working in the same way in different linux distros
function pidof_pandora () (
PANDORA_PID=`ps aux | grep $PANDORA_DAEMON | grep -v grep | tail -1 | awk '{ print $2 }'`
PANDORA_PID=`ps aux | grep $PANDORA_DAEMON $PANDORA_HOME| grep -v grep | tail -1 | awk '{ print $2 }'`
echo $PANDORA_PID
)

View File

@ -0,0 +1,85 @@
#!/usr/bin/perl -w
##################################################################################
# Fake data generator Plugin for Pandora FMS 3.0
# (c) Sancho Lerena 2009, slerena@gmail.com
# idea from Miguel de Dios, sorry dude, I made it first ! ;-))
#
# 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.
##################################################################################
use strict;
use warnings;
use Getopt::Long;
my $max = 10;
my $min = 0;
my $alphanumeric = 0;
# -- Subroutine / Functions ------------------------------------
sub help {
print "\nFake data generator plugin for Pandora FMS\n\n";
print "Syntax: \n\n\t ./pandora_loadgen.pl [-string] -max <max_value> -min <min_value> \n\n";
print "Sample usage:\n\n\t ./pandora_loadgen.pl -t 0 -max 100 -min 0\n\n";
print "\tIf -string provided, it generates an alphanumeric string with min-max lenght\n";
print "\totherwise it generates a random integer from min to max\n\n";
}
sub pandora_trash_ascii {
my $config_depth = $_[0];
my $a;
my $output = "";
for ($a=0;$a<$config_depth;$a++){
$output = $output.chr(int(rand(25)+97));
}
return $output
}
sub pandora_random {
my $min = $_[0];
my $max = $_[1];
return int(rand($max+1) + $min);
}
# -----------------------------------------------------------------------
# Main code -------------------------------------------------------------
# -----------------------------------------------------------------------
if ($#ARGV == -1){
help();
}
GetOptions(
"" => sub { help() },
"h" => sub { help() },
"help" => sub { help() },
"string+" => \$alphanumeric,
"max=i" => \$max,
"min=i" => \$min
);
if ($alphanumeric == 1){
print pandora_trash_ascii (pandora_random($min,$max));
}
else {
print pandora_random ($min, $max);
}
exit 0;
# -----------------------------------------------------------------------
# End main code ---------------------------------------------------------
# -----------------------------------------------------------------------

View File

@ -0,0 +1,208 @@
#!/usr/bin/perl -w
##################################################################################
# Server status Plugin for Pandora FMS 3.0
# (c) Sancho Lerena 2009, slerena@gmail.com
#
# 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.
##################################################################################
use strict;
use warnings;
use Getopt::Long;
use DBI;
my %pa_config;
my $cfgfile = "/etc/pandora/pandora_server.conf";
my $servername = "";
my $servertype = 0;
my $timeout = 10;
my $queuedmodules = 0;
my $module_result;
my $sql_query;
# -- Subroutine / Functions ------------------------------------
sub die_return {
print "0";
exit 1;
}
sub die_return_timeout {
print "0";
exit -1;
}
sub help {
print "\nPandora FMS Plugin for Pandora FMS server check\n\n";
print "Syntax: \n\n\t ./pandora_server_status.pl [-c /etc/pandora/pandora_server.conf] -t <server_type> -n <server_name> [ -q ] \n\n";
print "\t -q Return queued modules for given server name & type. \n";
print "\t -c It's optional, by default read Pandora FMS config file at /etc/pandora\n";
print "\n\t If -q is not given, it reports 1 if server is OK, or 0 if it's down\n\n";
print "Sample usage:\n\n\t ./pandora_server_status.pl -t 3 -n myserver\n\n";
print "Server types:
\t\t--0 dataserver
\t\t--1 network
\t\t--2 snmp trap console
\t\t--3 recon
\t\t--4 plugin
\t\t--5 prediction
\t\t--6 wmi
\t\t--7 export
\t\t--8 inventory
\t\t--9 web \n\n";
}
sub clean_blank {
my $input = $_[0];
$input =~ s/\s//g;
return $input;
}
sub load_config {
my $cfgfile = $_[0];
my $pa_config = $_[1];
my $buffer_line;
my @command_line;
my $tbuf;
# Collect items from config file and put in an array
open (CFG, "< $cfgfile");
while (<CFG>){
$buffer_line = $_;
if ($buffer_line =~ /^[a-zA-Z]/){ # begins with letters
if ($buffer_line =~ m/([\w\-\_\.]+)\s([0-9\w\-\_\.\/\?\&\=\)\(\_\-\!\*\@\#\%\$\~\"\']+)/){
push @command_line, $buffer_line;
}
}
}
close (CFG);
# Process this array with commandline like options
# Process input parameters
my @args = @command_line;
my $parametro;
my $ltotal=$#args;
my $ax;
# Has read setup file ok ?
if ( $ltotal == 0 ) {
print "[ERROR] No valid setup tokens readed in $cfgfile";
exit;
}
for ($ax=0;$ax<=$ltotal;$ax++){
$parametro = $args[$ax];
if ($parametro =~ m/^incomingdir\s(.*)/i) {
$tbuf= clean_blank($1);
if ($tbuf =~ m/^\.(.*)/){
$pa_config->{"incomingdir"} =$pa_config->{"basepath"}.$1;
} else {
$pa_config->{"incomingdir"} = $tbuf;
}
}
elsif ($parametro =~ m/^log_file\s(.*)/i) {
$tbuf= clean_blank($1);
if ($tbuf =~ m/^\.(.*)/){
$pa_config->{"logfile"} = $pa_config->{"basepath"}.$1;
} else {
$pa_config->{"logfile"} = $tbuf;
}
}
elsif ($parametro =~ m/^errorlog_file\s(.*)/i) {
$tbuf= clean_blank($1);
if ($tbuf =~ m/^\.(.*)/){
$pa_config->{"errorlogfile"} = $pa_config->{"basepath"}.$1;
} else {
$pa_config->{"errorlogfile"} = $tbuf;
}
}
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);
}
} # end of loop for parameter #
}
# -----------------------------------------------------------------------
# Main code -------------------------------------------------------------
# -----------------------------------------------------------------------
if ($#ARGV == -1){
help();
}
GetOptions(
"" => sub { help() },
"h" => sub { help() },
"help" => sub { help() },
"c=s" => \$cfgfile,
"n=s" => \$servername,
"q+" => \$queuedmodules,
"t=i" => \$servertype
);
load_config ($cfgfile, \%pa_config);
alarm($timeout);
$SIG{ALRM} = sub { die_return_timeout(); };
eval {
# Connect to MySQL
my $dbh = DBI->connect("DBI:mysql:".$pa_config{'dbname'}.":".$pa_config{"dbhost"}.":3306", $pa_config{"dbuser"}, $pa_config{"dbpass"}, { RaiseError => 1, AutoCommit => 1 });
return undef unless defined ($dbh);
if ($queuedmodules == 0){
$sql_query = "SELECT status FROM tserver WHERE server_type = $servertype and name = '$servername'";
}
else {
$sql_query = "SELECT queued_modules FROM tserver WHERE server_type = $servertype and name = '$servername'";
}
my $idag = $dbh->prepare($sql_query);
$idag ->execute;
my @datarow;
if ($idag->rows != 0) {
@datarow = $idag->fetchrow_array();
print $datarow[0] ."\n";
exit;
}
print "0\n";
};
if ($@){
die_return_timeout();
}
# -----------------------------------------------------------------------
# End main code ---------------------------------------------------------
# -----------------------------------------------------------------------