2012-03-07 Sancho Lerena <slerena@artica.es>

* lib/PandoraFMS/Core.pm: Updated version.

        * lib/PandoraFMS/DataServer.pm: Support for "UNIT" tag in the
        XML to update module data units from the XML.

        * util/pandora_csvbridge.pl: New tool to create XML data files
        from CSV files containing data.

        * util/pandora_watchdog.sh: Watchdog for Pandora FMS server,
        taken from the documentation and updated.

        *  util/pandora_dbstress.pl, 
        util/pandora_db.pl: Updated version strings.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5713 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2012-03-07 19:42:28 +00:00
parent 05dae5868d
commit 24874818f3
8 changed files with 341 additions and 9 deletions

View File

@ -1,3 +1,19 @@
2012-03-07 Sancho Lerena <slerena@artica.es>
* lib/PandoraFMS/Core.pm: Updated version.
* lib/PandoraFMS/DataServer.pm: Support for "UNIT" tag in the
XML to update module data units from the XML.
* util/pandora_csvbridge.pl: New tool to create XML data files
from CSV files containing data.
* util/pandora_watchdog.sh: Watchdog for Pandora FMS server,
taken from the documentation and updated.
* util/pandora_dbstress.pl,
util/pandora_db.pl: Updated version strings.
2012-02-29 Vanessa Gil <vanessa.gil@artica.es>
* bin/PandoraFMS/Core.pm: Fixed bug: HTML entities in alert name.

View File

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

View File

@ -23,7 +23,7 @@ PandoraFMS::Core - Core functions of Pandora FMS
=head1 VERSION
Version 3.2
Version 5.0
=head1 SYNOPSIS

View File

@ -456,7 +456,7 @@ sub process_module_data ($$$$$$$$$) {
my $tags = {'name' => 0, 'data' => 0, 'type' => 0, 'description' => 0, 'max' => 0,
'min' => 0, 'descripcion' => 0, 'post_process' => 0, 'module_interval' => 0, 'min_critical' => 0,
'max_critical' => 0, 'min_warning' => 0, 'max_warning' => 0, 'disabled' => 0, 'min_ff_event' => 0,
'datalist' => 0, 'status' => 0, 'timestamp' => 0};
'datalist' => 0, 'status' => 0, 'unit' => 0, 'timestamp' => 0};
# Other tags will be saved here
$module_conf->{'extended_info'} = '';
@ -518,6 +518,7 @@ sub process_module_data ($$$$$$$$$) {
$module_conf->{'disabled'} = 0 unless defined ($module_conf->{'disabled'});
$module_conf->{'min_ff_event'} = 0 unless defined ($module_conf->{'min_ff_event'});
$module_conf->{'extended_info'} = '' unless defined ($module_conf->{'extended_info'});
$module_conf->{'unit'} = '' unless defined ($module_conf->{'unit'});
# Create the module
pandora_create_module ($pa_config, $agent->{'id_agente'}, $module_id, $module_name,
@ -548,6 +549,7 @@ sub process_module_data ($$$$$$$$$) {
$module_conf->{'disabled'} = $module->{'disabled'} unless defined ($module_conf->{'disabled'});
$module_conf->{'min_ff_event'} = $module->{'min_ff_event'} unless defined ($module_conf->{'min_ff_event'});
$module_conf->{'extended_info'} = $module->{'extended_info'} unless defined ($module_conf->{'extended_info'});
$module_conf->{'unit'} = '' unless defined ($module_conf->{'unit'});
# The group name has to be translated to a group ID
my $conf_group_id = -1;
@ -638,18 +640,18 @@ sub update_module_configuration ($$$$) {
my ($pa_config, $dbh, $module, $module_conf) = @_;
# Update if at least one of the configuration tokens has changed
foreach my $conf_token ('min', 'max', 'descripcion', 'post_process', 'module_interval', 'min_critical', 'max_critical', 'min_warning', 'max_warning', 'disabled', 'min_ff_event', 'extended_info') {
foreach my $conf_token ('min', 'max', 'descripcion', 'post_process', 'module_interval', 'min_critical', 'max_critical', 'min_warning', 'max_warning', 'disabled', 'min_ff_event', 'extended_info', 'unit') {
if ($module->{$conf_token} ne $module_conf->{$conf_token}) {
logger ($pa_config, "Updating configuration for module '" . $module->{'nombre'} . "'.", 10);
db_do ($dbh, 'UPDATE tagente_modulo SET min = ?, max = ?, descripcion = ?, post_process = ?, module_interval = ?, min_critical = ?, max_critical = ?, min_warning = ?, max_warning = ?, disabled = ?, min_ff_event = ?, extended_info = ?
WHERE id_agente_modulo = ?', $module_conf->{'min'}, $module_conf->{'max'}, $module_conf->{'descripcion'} eq '' ? $module->{'descripcion'} : $module_conf->{'descripcion'},
db_do ($dbh, 'UPDATE tagente_modulo SET unit = ?, min = ?, max = ?, descripcion = ?, post_process = ?, module_interval = ?, min_critical = ?, max_critical = ?, min_warning = ?, max_warning = ?, disabled = ?, min_ff_event = ?, extended_info = ?
WHERE id_agente_modulo = ?', $module_conf->{'unit'}, $module_conf->{'min'}, $module_conf->{'max'}, $module_conf->{'descripcion'} eq '' ? $module->{'descripcion'} : $module_conf->{'descripcion'},
$module_conf->{'post_process'}, $module_conf->{'module_interval'}, $module_conf->{'min_critical'}, $module_conf->{'max_critical'}, $module_conf->{'min_warning'}, $module_conf->{'max_warning'}, $module_conf->{'disabled'}, $module_conf->{'min_ff_event'}, $module_conf->{'extended_info'}, $module->{'id_agente_modulo'});
last;
}
}
# Update module hash
foreach my $conf_token ('min', 'max', 'post_process', 'module_interval', 'min_critical', 'max_critical', 'min_warning', 'max_warning', 'disabled', 'min_ff_event', 'extended_info') {
foreach my $conf_token ('min', 'max', 'post_process', 'module_interval', 'min_critical', 'max_critical', 'min_warning', 'max_warning', 'disabled', 'min_ff_event', 'extended_info', 'unit') {
$module->{$conf_token} = $module_conf->{$conf_token};
}
$module->{'descripcion'} = ($module_conf->{'descripcion'} eq '') ? $module->{'descripcion'} : $module_conf->{'descripcion'};

View File

@ -0,0 +1,190 @@
#!/usr/bin/perl
##################################################################################
# CSV/XML Bridge Tool for Pandora FMS
# (c) Sancho Lerena 2012, 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 Getopt::Long;
my $version = "v1.0";
sub print_usage () {
print "Usage: $0 $version\n\n";
print "\t-A <field position for Agent> \n";
print "\t-Y <field position for module data value> \n";
print "\t-T <module type, by default is 'generic_data'> \n";
print "\t-O <field position for module description> \n";
print "\t-N <field position for agent description> \n";
print "\t-M <module name> \n";
print "\t-X <field position for data timestamp> \n";
print "\t-I <agent interval (in secs)> \n";
print "\t-G <field position for agent group> \n";
print "\t-s <Skip # firt lines (2 by default)> \n";
print "\t-c <character delimitator>\n";
print "\t-f <CSV file to process>\n";
print "\t-d <destination directory>\n";
print "\t-R Is used to dump header fields / order, to select \n";
print "\t what fields you need to parse\n";
print "\t-hV Help (this help)\n";
print "\nSample Usage:\n\n";
print "\tperl pandora_csv_bridge.pl -f datos4.csv -c @ -A 2 -Y 26 -M Consumo_Electrico -d /tmp/dump -G 3 -X 12\n\n";
exit;
}
sub transform_date ($){
#'2012/03/26 19:37:22 # Output format needed
my $orig_data = $_[0];
my $date;
my @t1;
if ($orig_data =~ /\//){
@t1 = split ("/", $orig_data);
} else {
@t1 = split ("-", $orig_data);
}
# We asume 3rd digit is YEAR in "two digits" format
# 2nd field is DAY and 1st field is month
if ($t1[0] < 12){
$date = "20".$t1[2]."/".$t1[0]."/".$t1[1]. " 00:00:00";
} else {
$date = "20".$t1[2]."/".$t1[1]."/".$t1[0]. " 00:00:00";
}
return $date;
}
my ($opt_v, $opt_h, $opt_d, $opt_c, $opt_f, $opt_s, $opt_R, $opt_A, $opt_O, $opt_Y, $opt_T, $opt_X, $opt_I, $opt_M, $opt_G, $opt_N);
# Default values
$opt_N = "";
$opt_G = "Servers";
$opt_I = "300";
$opt_I = "300";
$opt_s = 2;
$opt_T = "generic_data";
my $utimestamp;
my $utimestamp_extra;
GetOptions
("h" => \$opt_h,
"R" => \$opt_R,
"help" => \$opt_h,
"c=s" => \$opt_c,
"f=s" => \$opt_f,
"d=s" => \$opt_d,
"s=s" => \$opt_s,
"M=s" => \$opt_M,
"N=s" => \$opt_N,
"A=s" => \$opt_A,
"O=s" => \$opt_O,
"Y=s" => \$opt_Y,
"T=s" => \$opt_T,
"X=s" => \$opt_X,
"G=s" => \$opt_G,
"I=s" => \$opt_I,
"v" => \$opt_v,
"verbose" => \$opt_v);
if ($opt_v) {
print "\n";
print "$0 Pandora FMS CSV / XML Bridge Tool $version\n";
print "\n";
print_usage();
}
if ($opt_h) {
print_usage();
}
if (!defined($opt_R)){
if ( !defined($opt_f)){
print_usage();
}
if ( !defined($opt_X)){
print_usage();
}
}
# DEBUG
#print "Opening file $opt_f with CSV character $opt_c Agent name $opt_A Timestamp Field $opt_X \n";
open (FIDATA, "< $opt_f");
my @data;
my $header;
# Skip first $opt_s lines of File
my $ax; my $temp_skip;
for ($ax = 0; $ax < $opt_s; $ax++){
if ($ax == 0) {
$header = <FIDATA>;
}
else {
$temp_skip = <FIDATA>;
$header = $temp_skip;
}
}
# Dump header
if ( defined($opt_R)){
my @header_data = split ("$opt_c", $header );
my $key;
print "\nDumping CSV Structure (Field Label -> Field Order)\n\n";
foreach $key (keys @header_data){
print $header_data[$key] ." -> ". $key ." \n";
}
exit;
}
# Begin process file
my $buffer_line;
my $filename;
my $counter = 1;
print "Generating data from CSV file $opt_f, with CSV character $opt_c Agent name $opt_A Timestamp Field $opt_X \n";
while (<FIDATA>){
$counter++;
$buffer_line = $_;
@data = split ("$opt_c", $buffer_line);
# Let's create the damm XML for each line
$utimestamp = time ();
$utimestamp_extra = int(rand(10000));
$utimestamp = $utimestamp . $utimestamp_extra;
$utimestamp = $utimestamp + $counter;
$filename = $opt_d."/". $data[$opt_A].".".$utimestamp.".data";
open (OUTDATA, "> $filename");
print OUTDATA "<?xml version='1.0' encoding='ISO-8859-1'?>";
print OUTDATA "<agent_data description='$data[$opt_N]' group='$data[$opt_G]' os_name='other' os_version='1.0' interval='$opt_I' version='4.0.1' timestamp='".transform_date($data[$opt_X])."' agent_name='$data[$opt_A]' timezone_offset='0'>";
print OUTDATA "<module>
<name>$opt_M</name>
<type>$opt_T</type>
<description>$data[$opt_O]</description>
<data>$data[$opt_Y]</data>
</module>";
print OUTDATA "</agent_data>";
close (OUTDATA);
}

View File

@ -30,7 +30,7 @@ use PandoraFMS::Tools;
use PandoraFMS::DB;
# version: define current version
my $version = "4.0.1 PS111213";
my $version = "5.0 Build 120307";
# Pandora server configuration
my %conf;

View File

@ -46,7 +46,7 @@ use PandoraFMS::Core;
################################################################################
################################################################################
my $version = "4.0 PS110923";
my $version = "5.0 Build 120307";
# FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE

View File

@ -0,0 +1,124 @@
#!/bin/bash
# Copyright (c) 2005-2009 Artica ST
# Author: Sancho Lerena <slerena@artica.es> 2009
# Licence: GPL2
#
# daemon_watchdog
#
# Generic watchdog to detect if a daemon is running. If cannot restart, execute
# a custom-user defined command to notify daemon is down and continues in
# standby (without notifying / checking) until daemon is alive again.
# Default configuration is for Pandora FMS Server daemon
# =====================================================================
# Configuration begins here. Please use "" if data contain blank spaces
export DAEMON_WATCHDOG=pandora_watchdog.sh
# DAEMON_WATCHDOG: Name of this script. Used to check if its running already
export DAEMON_CHECK="/usr/bin/pandora_server /etc/pandora/pandora_server.conf"
# DAEMON_CHECK: Daemon monitored, please use full path and parameters like
# are shown doing a ps aux of ps -Alf
export DAEMON_RESTART="/etc/init.d/pandora_server restart"
# DAEMON_RESTART: Command to try to restart the daemon
export DAEMON_DEADWAIT=90
# DAEMON_DEADWAIT: Time this script checks after detect that
# daemon is down before to consider is really down.
export DAEMON_ALERT="/usr/bin/pandora_alert"
# DAEMON_ALERT: Command/Script executed if after detecting daemon is down,
# and waiting DAEMON_DEADWAIT, and daemon continues down.
export DAEMON_LOOP=7
# DAEMON_LOOP: Interval within daemon_wathdog checks if daemon is alive.
# DO NOT use values under 3-5 seconds or could be CPU consuming.
# NEVER NEVER NEVER use 0 value or gets 100% CPU!.
# Configuration stop here
# =====================================================================
# Check if another instance of this script
RUNNING_CHECK=`ps aux | grep "$DAEMON_WATCHDOG" | grep -v grep |wc -l`
if [ $RUNNING_CHECK -gt 2 ]
then
echo "Aborting, seems that there are more '$DAEMON_WATCHDOG' running in this system"
logger $DAEMON_WATCHDOG aborted execution because another watchdog seems to be running
exit -1
fi
# This value always must be 0 at start. Do not alter
export DAEMON_STANDBY=0
# This function replace pidof, not working in the same way in different linux distros
function pidof_daemon () (
# This sets COLUMNS to XXX chars, because if command is run
# in a "strech" term, ps aux don't report more than COLUMNS
# characters and this will not work.
COLUMNS=300
DAEMON_PID=`ps aux | grep "$DAEMON_CHECK" | grep -v grep | tail -1 | awk '{ print $2 }'`
echo $DAEMON_PID
)
# Main script
if [ ! -f `echo $DAEMON_CHECK | awk '{ print $1 }'` ]
then
echo "Daemon you want to check is not present in the system. Aborting watchdog"
exit
fi
while [ 1 ]
do
DAEMON_PID=`pidof_daemon`
if [ -z "$DAEMON_PID" ]
then
echo "Checkpoint #1 $DAEMON_PID "
if [ $DAEMON_STANDBY == 0 ]
then
# Daemon down, first detection
# Restart it !
logger $DAEMON_WATCHDOG restarting $DAEMON_CHECK
$DAEMON_RESTART 2> /dev/null > /dev/null
# Just WAIT another DAEMON_DEADWAIT before consider it DEAD
echo "Going to DAEMON_DEADEWAIT"
sleep $DAEMON_DEADWAIT
DAEMON_PID=`pidof_daemon`
if [ -z "$DAEMON_PID" ]
then
# Is dead and can't be restarted properly. Execute alert
echo "I cannot startup again the process"
logger $DAEMON_WATCHDOG $DAEMON_CHECK is dead, alerting !
$DAEMON_ALERT 2> /dev/null > /dev/null
# Watchdog process puts in STANDBY mode until process get alive again
logger $DAEMON_WATCHDOG "Entering in Stabdby mode"
DAEMON_STANDBY=1
fi
fi
else
echo "Checkpoint #1B $DAEMON_PID "
DAEMON_STANDBY=0
fi
sleep $DAEMON_LOOP
done