From 14b720494671c251addb8de6c4f83968c9cd3681 Mon Sep 17 00:00:00 2001 From: raulmateos Date: Sat, 24 Jan 2009 15:41:39 +0000 Subject: [PATCH] 2009-01-24 Raul Mateos * lib/PandoraFMS/Config.pm: Changed some texts for last time. Sancho, please read diffs before commit.Use tabs instead spaces. * lib/PandoraFMS/Tools.pm: Header updated. Use tabs instead spaces. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1395 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 9 +- pandora_server/lib/PandoraFMS/Config.pm | 580 ++++++++++++------------ pandora_server/lib/PandoraFMS/Tools.pm | 158 +++---- 3 files changed, 376 insertions(+), 371 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index ebcfbea5e3..8812c00e72 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2009-01-24 Raul Mateos + + * lib/PandoraFMS/Config.pm: Changed some texts for last time. Use tabs + instead spaces. + + * lib/PandoraFMS/Tools.pm: Header updated. Use tabs instead spaces. + 2009-01-21 Ramon Novoa * lib/PandoraFMS/DB.pm: Changes in multicast change reports. @@ -11,7 +18,7 @@ * pandora_server/lib/PandoraFMS/Config.pm: Updated configuration options. -2009-01-21 Sancho Leren +2009-01-21 Sancho Lerena * pandora_server_upgrade: Script to upgrade to latest version Pandora FMS server components / code. diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 37c64cf602..2b5d2faf32 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -7,8 +7,8 @@ package PandoraFMS::Config; # Copyright (c) 2005-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 -# as published by the Free Software Foundation; at version 2. +# modify it under the terms of the GNU Lesser 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 @@ -52,14 +52,14 @@ my %pa_config; ########################################################################## sub help_screen { - printf "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file > \n\n"; + printf "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file (pandora_server.conf) > \n\n"; printf "Following options are optional : \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 " -v : Verbose mode activated. Writes more information in the logfile \n"; + printf " -d : Debug mode activated. Writes extensive information in the logfile \n"; + printf " -D : Daemon mode (runs in background)\n"; printf " -P : Store PID to file.\n"; - printf " -q : Quiet startup\n"; - printf " -h : This screen, show a little help screen \n"; + printf " -q : Quiet startup \n"; + printf " -h : This screen. Shows a little help screen \n"; printf " \n"; exit; } @@ -78,45 +78,45 @@ 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"}=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 + $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 # If there are not valid parameters my $parametro; my $ltotal=$#ARGV; my $ax; for ($ax=0;$ax<=$ltotal;$ax++){ $parametro = $ARGV[$ax]; - if (($parametro =~ m/-h\z/i ) || ($parametro =~ m/help\z/i )) { - help_screen(); + if (($parametro =~ m/-h\z/i ) || ($parametro =~ m/help\z/i )) { + help_screen(); } - elsif ($parametro =~ m/-v\z/i) { - $pa_config->{"verbosity"}=5; + elsif ($parametro =~ m/-v\z/i) { + $pa_config->{"verbosity"}=5; } - elsif ($parametro =~ m/^-P\z/i) { + elsif ($parametro =~ m/^-P\z/i) { $pa_config->{'PID'}= clean_blank($ARGV[$ax+1]); } - elsif ($parametro =~ m/-d\z/) { - $pa_config->{"verbosity"}=10; + elsif ($parametro =~ m/-d\z/) { + $pa_config->{"verbosity"}=10; } - elsif ($parametro =~ m/-q\z/) { - $pa_config->{"quiet"}=1; + elsif ($parametro =~ m/-q\z/) { + $pa_config->{"quiet"}=1; } - elsif ($parametro =~ m/-D\z/) { - $pa_config->{"daemon"}=1; + elsif ($parametro =~ m/-D\z/) { + $pa_config->{"daemon"}=1; } - else { - ($pa_config->{"pandora_path"} = $parametro); + else { + ($pa_config->{"pandora_path"} = $parametro); } } if ($pa_config->{"pandora_path"} eq ""){ - 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"; + 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; } } @@ -127,9 +127,9 @@ sub pandora_init { sub pandora_loadconfig { my $pa_config = $_[0]; - my $opmode = $_[1]; # 0 dataserver, 1 network server, 2 snmp console - # 3 recon srv, 4 plugin srv, 5 prediction srv - # 6 WMI server, 7 export server + my $opmode = $_[1]; # 0 dataserver, 1 network server, 2 snmp console + # 3 recon srv, 4 plugin srv, 5 prediction srv + # 6 WMI server, 7 export server my $archivo_cfg = $pa_config->{'pandora_path'}; my $buffer_line; my @command_line; @@ -148,8 +148,8 @@ sub pandora_loadconfig { $pa_config->{"alert_threshold"} = 60; $pa_config->{"logfile"} = "/var/log/pandora_server.log"; $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->{"networktimeout"} = 5; # By default, not in config file yet + $pa_config->{"pandora_master"} = 1; # on by default $pa_config->{"pandora_check"} = 0; # Deprecated since 2.0 $pa_config->{"servername"} = `hostname`; $pa_config->{"servername"} =~ s/\s//g; # Replace ' ' chars @@ -190,7 +190,7 @@ sub pandora_loadconfig { $pa_config->{"mta_user"} = ''; # Introduced on 2.0 $pa_config->{"mta_pass"} = ''; # Introduced on 2.0 $pa_config->{"mta_auth"} = 'none'; # Introduced on 2.0 (Support LOGIN PLAIN CRAM-MD5 DIGEST-MD) - $pa_config->{"mta_from"} = 'pandora@localhost'; # Introduced on 2.0 + $pa_config->{"mta_from"} = 'pandora@localhost'; # Introduced on 2.0 # Xprobe2 for recon OS fingerprinting (optional feature to detect OS) $pa_config->{"xprobe2"} = "/usr/bin/xprobe2"; @@ -202,7 +202,7 @@ sub pandora_loadconfig { # Multicast status report $pa_config->{'mcast_status_group'} = '226.1.1.2'; - $pa_config->{'mcast_status_port'} = '2000'; + $pa_config->{'mcast_status_port'} = '2000'; # Multicast change report @@ -213,15 +213,15 @@ sub pandora_loadconfig { if ($pa_config->{"quiet"} != 0){ if ($> == 0){ printf " [W] Not all Pandora FMS components need to be executed as root\n"; - printf " please consider starting it with a non-privileged user.\n"; + printf " please consider starting it with a non-privileged user.\n"; } } # Check for file if ( ! -e $archivo_cfg ) { printf "\n [ERROR] Cannot open configuration file at $archivo_cfg. \n"; - printf " Please specify a valid Pandora FMS configuration file in command line.\n"; - print " Standard configuration file is at /etc/pandora/pandora_server.conf \n"; + printf " Please specify a valid Pandora FMS configuration file in command line. \n"; + print " Standard configuration file is at /etc/pandora/pandora_server.conf \n"; exit 1; } # Collect items from config file and put in an array @@ -281,164 +281,164 @@ sub pandora_loadconfig { } # MTA setup (2.0) - elsif ($parametro =~ m/^mta_user\s(.*)/i) { - $pa_config->{'mta_user'}= clean_blank($1); - } - elsif ($parametro =~ m/^mta_pass\s(.*)/i) { - $pa_config->{'mta_pass'}= clean_blank($1); - } - elsif ($parametro =~ m/^mta_address\s(.*)/i) { - $pa_config->{'mta_address'}= clean_blank($1); - } - elsif ($parametro =~ m/^mta_port\s(.*)/i) { - $pa_config->{'mta_port'}= clean_blank($1); - } - elsif ($parametro =~ m/^mta_auth\s(.*)/i) { - $pa_config->{'mta_auth'}= clean_blank($1); - } - elsif ($parametro =~ m/^mta_from\s(.*)/i) { - $pa_config->{'mta_from'}= clean_blank($1); - } - elsif ($parametro =~ m/^snmp_logfile\s(.*)/i) { - $pa_config->{'snmp_logfile'}= clean_blank($1); - } + elsif ($parametro =~ m/^mta_user\s(.*)/i) { + $pa_config->{'mta_user'}= clean_blank($1); + } + elsif ($parametro =~ m/^mta_pass\s(.*)/i) { + $pa_config->{'mta_pass'}= clean_blank($1); + } + elsif ($parametro =~ m/^mta_address\s(.*)/i) { + $pa_config->{'mta_address'}= clean_blank($1); + } + elsif ($parametro =~ m/^mta_port\s(.*)/i) { + $pa_config->{'mta_port'}= clean_blank($1); + } + elsif ($parametro =~ m/^mta_auth\s(.*)/i) { + $pa_config->{'mta_auth'}= clean_blank($1); + } + elsif ($parametro =~ m/^mta_from\s(.*)/i) { + $pa_config->{'mta_from'}= clean_blank($1); + } + elsif ($parametro =~ m/^snmp_logfile\s(.*)/i) { + $pa_config->{'snmp_logfile'}= clean_blank($1); + } elsif ($parametro =~ m/^dbname\s(.*)/i) { - $pa_config->{'dbname'}= clean_blank($1); - } + $pa_config->{'dbname'}= clean_blank($1); + } elsif ($parametro =~ m/^dbuser\s(.*)/i) { - $pa_config->{'dbuser'}= clean_blank($1); - } - elsif ($parametro =~ m/^dbpass\s(.*)/i) { - $pa_config->{'dbpass'}= clean_blank($1); - } - elsif ($parametro =~ m/^dbhost\s(.*)/i) { - $pa_config->{'dbhost'}= clean_blank($1); - } - elsif ($parametro =~ m/^daemon\s([0-9]*)/i) { - $pa_config->{'daemon'}= clean_blank($1); - } + $pa_config->{'dbuser'}= clean_blank($1); + } + elsif ($parametro =~ m/^dbpass\s(.*)/i) { + $pa_config->{'dbpass'}= clean_blank($1); + } + elsif ($parametro =~ m/^dbhost\s(.*)/i) { + $pa_config->{'dbhost'}= clean_blank($1); + } + elsif ($parametro =~ m/^daemon\s([0-9]*)/i) { + $pa_config->{'daemon'}= clean_blank($1); + } elsif ($parametro =~ m/^dataserver\s([0-9]*)/i){ $pa_config->{'dataserver'}= clean_blank($1); } - elsif ($parametro =~ m/^networkserver\s([0-9]*)/i){ - $pa_config->{'networkserver'}= clean_blank($1); - } - elsif ($parametro =~ m/^pluginserver\s([0-9]*)/i){ - $pa_config->{'pluginserver'}= clean_blank($1); - } - elsif ($parametro =~ m/^predictionserver\s([0-9]*)/i){ - $pa_config->{'predictionserver'}= clean_blank($1); - } - elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) { - $pa_config->{'reconserver'}= clean_blank($1); - } - elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) { - $pa_config->{'reconserver'}= clean_blank($1); - } - elsif ($parametro =~ m/^wmiserver\s([0-9]*)/i) { - $pa_config->{'wmiserver'}= clean_blank($1); - } - elsif ($parametro =~ m/^exportserver\s([0-9]*)/i) { - $pa_config->{'exportserver'}= clean_blank($1); - } - elsif ($parametro =~ m/^servername\s(.*)/i) { - $pa_config->{'servername'}= clean_blank($1); - } - elsif ($parametro =~ m/^checksum\s([0-9])/i) { - $pa_config->{"pandora_check"} = clean_blank($1); - } - elsif ($parametro =~ m/^master\s([0-9])/i) { - $pa_config->{"pandora_master"} = clean_blank($1); - } - elsif ($parametro =~ m/^icmp_checks\s([0-9]*)/i) { - $pa_config->{"icmp_checks"} = clean_blank($1); - } - elsif ($parametro =~ m/^snmpconsole\s([0-9]*)/i) { - $pa_config->{"snmpconsole"} = clean_blank($1); - } - elsif ($parametro =~ m/^alert_recovery\s([0-9]*)/i) { - $pa_config->{"alert_recovery"} = clean_blank($1); - } - elsif ($parametro =~ m/^snmp_checks\s([0-9]*)/i) { - $pa_config->{"snmp_checks"} = clean_blank($1); - } - elsif ($parametro =~ m/^snmp_timeout\s([0-9]*)/i) { - $pa_config->{"snmp_timeout"} = clean_blank($1); - } - elsif ($parametro =~ m/^tcp_checks\s([0-9]*)/i) { - $pa_config->{"tcp_checks"} = clean_blank($1); - } - elsif ($parametro =~ m/^tcp_timeout\s([0-9]*)/i) { - $pa_config->{"tcp_timeout"} = clean_blank($1); - } - elsif ($parametro =~ m/^snmp_proc_deadresponse\s([0-9]*)/i) { - $pa_config->{"snmp_proc_deadresponse"} = clean_blank($1); - } - elsif ($parametro =~ m/^verbosity\s([0-9]*)/i) { - $pa_config->{"verbosity"} = clean_blank($1); - } - elsif ($parametro =~ m/^server_threshold\s([0-9]*)/i) { - $pa_config->{"server_threshold"} = clean_blank($1); - } - elsif ($parametro =~ m/^alert_threshold\s([0-9]*)/i) { - $pa_config->{"alert_threshold"} = clean_blank($1); - } - elsif ($parametro =~ m/^network_timeout\s([0-9]*)/i) { - $pa_config->{'networktimeout'}= clean_blank($1); - } - elsif ($parametro =~ m/^network_threads\s([0-9]*)/i) { - $pa_config->{'network_threads'}= clean_blank($1); - } - elsif ($parametro =~ m/^plugin_threads\s([0-9]*)/i) { - $pa_config->{'plugin_threads'}= clean_blank($1); - } - elsif ($parametro =~ m/^prediction_threads\s([0-9]*)/i) { - $pa_config->{'prediction_threads'}= clean_blank($1); - } - elsif ($parametro =~ m/^plugin_timeout\s([0-9]*)/i) { - $pa_config->{'plugin_timeout'}= clean_blank($1); - } - elsif ($parametro =~ m/^dataserver_threads\s([0-9]*)/i) { - $pa_config->{'dataserver_threads'}= clean_blank($1); - } - elsif ($parametro =~ m/^server_keepalive\s([0-9]*)/i) { - $pa_config->{"keepalive"} = clean_blank($1); - $pa_config->{"keepalive_orig"} = clean_blank($1); - } - elsif ($parametro =~ m/^xprobe2\s(.*)/i) { - $pa_config->{'xprobe2'}= clean_blank($1); - } + elsif ($parametro =~ m/^networkserver\s([0-9]*)/i){ + $pa_config->{'networkserver'}= clean_blank($1); + } + elsif ($parametro =~ m/^pluginserver\s([0-9]*)/i){ + $pa_config->{'pluginserver'}= clean_blank($1); + } + elsif ($parametro =~ m/^predictionserver\s([0-9]*)/i){ + $pa_config->{'predictionserver'}= clean_blank($1); + } + elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) { + $pa_config->{'reconserver'}= clean_blank($1); + } + elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) { + $pa_config->{'reconserver'}= clean_blank($1); + } + elsif ($parametro =~ m/^wmiserver\s([0-9]*)/i) { + $pa_config->{'wmiserver'}= clean_blank($1); + } + elsif ($parametro =~ m/^exportserver\s([0-9]*)/i) { + $pa_config->{'exportserver'}= clean_blank($1); + } + elsif ($parametro =~ m/^servername\s(.*)/i) { + $pa_config->{'servername'}= clean_blank($1); + } + elsif ($parametro =~ m/^checksum\s([0-9])/i) { + $pa_config->{"pandora_check"} = clean_blank($1); + } + elsif ($parametro =~ m/^master\s([0-9])/i) { + $pa_config->{"pandora_master"} = clean_blank($1); + } + elsif ($parametro =~ m/^icmp_checks\s([0-9]*)/i) { + $pa_config->{"icmp_checks"} = clean_blank($1); + } + elsif ($parametro =~ m/^snmpconsole\s([0-9]*)/i) { + $pa_config->{"snmpconsole"} = clean_blank($1); + } + elsif ($parametro =~ m/^alert_recovery\s([0-9]*)/i) { + $pa_config->{"alert_recovery"} = clean_blank($1); + } + elsif ($parametro =~ m/^snmp_checks\s([0-9]*)/i) { + $pa_config->{"snmp_checks"} = clean_blank($1); + } + elsif ($parametro =~ m/^snmp_timeout\s([0-9]*)/i) { + $pa_config->{"snmp_timeout"} = clean_blank($1); + } + elsif ($parametro =~ m/^tcp_checks\s([0-9]*)/i) { + $pa_config->{"tcp_checks"} = clean_blank($1); + } + elsif ($parametro =~ m/^tcp_timeout\s([0-9]*)/i) { + $pa_config->{"tcp_timeout"} = clean_blank($1); + } + elsif ($parametro =~ m/^snmp_proc_deadresponse\s([0-9]*)/i) { + $pa_config->{"snmp_proc_deadresponse"} = clean_blank($1); + } + elsif ($parametro =~ m/^verbosity\s([0-9]*)/i) { + $pa_config->{"verbosity"} = clean_blank($1); + } + elsif ($parametro =~ m/^server_threshold\s([0-9]*)/i) { + $pa_config->{"server_threshold"} = clean_blank($1); + } + elsif ($parametro =~ m/^alert_threshold\s([0-9]*)/i) { + $pa_config->{"alert_threshold"} = clean_blank($1); + } + elsif ($parametro =~ m/^network_timeout\s([0-9]*)/i) { + $pa_config->{'networktimeout'}= clean_blank($1); + } + elsif ($parametro =~ m/^network_threads\s([0-9]*)/i) { + $pa_config->{'network_threads'}= clean_blank($1); + } + elsif ($parametro =~ m/^plugin_threads\s([0-9]*)/i) { + $pa_config->{'plugin_threads'}= clean_blank($1); + } + elsif ($parametro =~ m/^prediction_threads\s([0-9]*)/i) { + $pa_config->{'prediction_threads'}= clean_blank($1); + } + elsif ($parametro =~ m/^plugin_timeout\s([0-9]*)/i) { + $pa_config->{'plugin_timeout'}= clean_blank($1); + } + elsif ($parametro =~ m/^dataserver_threads\s([0-9]*)/i) { + $pa_config->{'dataserver_threads'}= clean_blank($1); + } + elsif ($parametro =~ m/^server_keepalive\s([0-9]*)/i) { + $pa_config->{"keepalive"} = clean_blank($1); + $pa_config->{"keepalive_orig"} = clean_blank($1); + } + elsif ($parametro =~ m/^xprobe2\s(.*)/i) { + $pa_config->{'xprobe2'}= clean_blank($1); + } elsif ($parametro =~ m/^autocreate\s([0-9*]*)/i) { - $pa_config->{'autocreate'}= clean_blank($1); - } + $pa_config->{'autocreate'}= clean_blank($1); + } elsif ($parametro =~ m/^autocreate_group\s([0-9*]*)/i) { - $pa_config->{'autocreate_group'}= clean_blank($1); - } - elsif ($parametro =~ m/^recon_threads\s([0-9]*)/i) { - $pa_config->{'recon_threads'}= clean_blank($1); - } + $pa_config->{'autocreate_group'}= clean_blank($1); + } + elsif ($parametro =~ m/^recon_threads\s([0-9]*)/i) { + $pa_config->{'recon_threads'}= clean_blank($1); + } elsif ($parametro =~ m/^max_log_size\s([0-9]*)/i) { - $pa_config->{'max_log_size'}= clean_blank($1); - } + $pa_config->{'max_log_size'}= clean_blank($1); + } elsif ($parametro =~ m/^mcast_status_group\s([0-9\.]*)/i) { - $pa_config->{'mcast_status_group'}= clean_blank($1); - } + $pa_config->{'mcast_status_group'}= clean_blank($1); + } elsif ($parametro =~ m/^mcast_change_group\s([0-9\.]*)/i) { - $pa_config->{'mcast_change_group'}= clean_blank($1); - } + $pa_config->{'mcast_change_group'}= clean_blank($1); + } elsif ($parametro =~ m/^mcast_status_port\s([0-9]*)/i) { - $pa_config->{'mcast_status_port'}= clean_blank($1); - } + $pa_config->{'mcast_status_port'}= clean_blank($1); + } elsif ($parametro =~ m/^mcast_change_port\s([0-9]*)/i) { - $pa_config->{'mcast_change_port'}= clean_blank($1); - } - } # end of loop for parameter # + $pa_config->{'mcast_change_port'}= clean_blank($1); + } + } # end of loop for parameter # if (($pa_config->{"verbosity"} > 4) && ($pa_config->{"quiet"} == 0)){ - if ($pa_config->{"PID"} ne ""){ - print " [*] PID File is written at ".$pa_config->{'PID'}."\n"; - } + if ($pa_config->{"PID"} ne ""){ + print " [*] PID File is written at ".$pa_config->{'PID'}."\n"; + } print " [*] Server basepath is ".$pa_config->{'basepath'}."\n"; print " [*] Server logfile at ".$pa_config->{"logfile"}."\n"; print " [*] Server errorlogfile at ".$pa_config->{"errorlogfile"}."\n"; @@ -451,111 +451,111 @@ sub pandora_loadconfig { print " [ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file. \n\n"; exit; } - if (($opmode ==0) && ($pa_config->{"dataserver"} ne 1)) { - print " [ERROR] You must enable 'dataserver' in setup file to run Pandora FMS Data Server. \n\n"; - exit; - } - if (($opmode ==1) && ($pa_config->{"networkserver"} ne 1)) { - print " [ERROR] You must enable 'networkserver' in setup file to run Pandora FMS Network Server. \n\n"; - exit; - } - if (($opmode ==2) && ($pa_config->{"snmpconsole"} ne 1)) { - print " [ERROR] You must enable 'snmpconsole' in setup file to run Pandora FMS SNMP Console. \n\n"; - exit; - } - if (($opmode ==3) && ($pa_config->{"reconserver"} ne 1)) { - print " [ERROR] You must enable 'reconserver' in setup file to run Pandora FMS Recon server. \n\n"; - exit; - } - if (($opmode ==4) && ($pa_config->{"pluginserver"} ne 1)) { - print " [ERROR] You must enable 'pluginserver' in setup file to run Pandora FMS Plugin server. \n\n"; - exit; - } - if (($opmode ==5) && ($pa_config->{"predictionserver"} ne 1)) { - print " [ERROR] You must enable 'predictionserver' in setup file to run Pandora FMS Prediction server. \n\n"; - exit; - } - if (($opmode ==6) && ($pa_config->{"wmiserver"} ne 1)) { - print " [ERROR] You must enable 'wmiserver' in setup file to run Pandora FMS WMI server. \n\n"; - exit; - } - if (($opmode ==7) && ($pa_config->{"exportserver"} ne 1)) { - print " [ERROR] You must enable 'exportserver' in setup file to run Pandora FMS Export server. \n\n"; - exit; - } + if (($opmode ==0) && ($pa_config->{"dataserver"} ne 1)) { + print " [ERROR] You must enable 'dataserver' in setup file to run Pandora FMS Data Server. \n\n"; + exit; + } + if (($opmode ==1) && ($pa_config->{"networkserver"} ne 1)) { + print " [ERROR] You must enable 'networkserver' in setup file to run Pandora FMS Network Server. \n\n"; + exit; + } + if (($opmode ==2) && ($pa_config->{"snmpconsole"} ne 1)) { + print " [ERROR] You must enable 'snmpconsole' in setup file to run Pandora FMS SNMP Console. \n\n"; + exit; + } + if (($opmode ==3) && ($pa_config->{"reconserver"} ne 1)) { + print " [ERROR] You must enable 'reconserver' in setup file to run Pandora FMS Recon server. \n\n"; + exit; + } + if (($opmode ==4) && ($pa_config->{"pluginserver"} ne 1)) { + print " [ERROR] You must enable 'pluginserver' in setup file to run Pandora FMS Plugin server. \n\n"; + exit; + } + if (($opmode ==5) && ($pa_config->{"predictionserver"} ne 1)) { + print " [ERROR] You must enable 'predictionserver' in setup file to run Pandora FMS Prediction server. \n\n"; + exit; + } + if (($opmode ==6) && ($pa_config->{"wmiserver"} ne 1)) { + print " [ERROR] You must enable 'wmiserver' in setup file to run Pandora FMS WMI server. \n\n"; + exit; + } + if (($opmode ==7) && ($pa_config->{"exportserver"} ne 1)) { + print " [ERROR] You must enable 'exportserver' in setup file to run Pandora FMS Export server. \n\n"; + exit; + } # Show some config options in startup - if ($opmode == 0){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS Data Server. \n"; - } - $parametro ="Pandora FMS Data Server"; - $pa_config->{"servermode"}="_Data"; - } - if ($opmode == 1){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS Network Server. \n"; - } - $parametro ="Pandora FMS Network Server"; - $pa_config->{"servermode"}="_Net"; - } - if ($opmode == 2){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS SNMP Console. \n"; - } - $parametro ="Pandora FMS SNMP Console"; - $pa_config->{"servermode"}="_SNMP"; - } - if ($opmode == 3){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS Recon Server. \n"; - } - $parametro ="Pandora FMS Recon Server"; - $pa_config->{"servermode"}="_Recon"; - } - if ($opmode == 4){ + if ($opmode == 0){ if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS Plugin Server. \n"; - } - $parametro ="Pandora FMS Plugin Server"; - $pa_config->{"servermode"}="_Plugin"; - } - if ($opmode == 5){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS Prediction Server. \n"; - } - $parametro ="Pandora FMS Prediction Server"; - $pa_config->{"servermode"}="_Prediction"; - } - if ($opmode == 6){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS WMI Server. \n"; - } - $parametro ="Pandora FMS WMI Server"; - $pa_config->{"servermode"}="_WMI"; - } - if ($opmode == 7){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS Export Server. \n"; - } - $parametro ="Pandora FMS Export Server"; - $pa_config->{"servermode"}="_Export"; - } - if ($opmode == 8){ - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - print " [*] You are running Pandora FMS Inventory Server. \n"; - } - $parametro ="Pandora FMS Inventory Server"; - $pa_config->{"servermode"}="_Inventory"; - } - if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { - if ($pa_config->{"pandora_check"} == 1) { - print " [*] MD5 Security enabled.\n"; - } - if ($pa_config->{"pandora_master"} == 1) { - print " [*] This server is running in MASTER mode.\n"; - } - } + print " [*] You are running Pandora FMS Data Server. \n"; + } + $parametro ="Pandora FMS Data Server"; + $pa_config->{"servermode"}="_Data"; + } + if ($opmode == 1){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS Network Server. \n"; + } + $parametro ="Pandora FMS Network Server"; + $pa_config->{"servermode"}="_Net"; + } + if ($opmode == 2){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS SNMP Console. \n"; + } + $parametro ="Pandora FMS SNMP Console"; + $pa_config->{"servermode"}="_SNMP"; + } + if ($opmode == 3){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS Recon Server. \n"; + } + $parametro ="Pandora FMS Recon Server"; + $pa_config->{"servermode"}="_Recon"; + } + if ($opmode == 4){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS Plugin Server. \n"; + } + $parametro ="Pandora FMS Plugin Server"; + $pa_config->{"servermode"}="_Plugin"; + } + if ($opmode == 5){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS Prediction Server. \n"; + } + $parametro ="Pandora FMS Prediction Server"; + $pa_config->{"servermode"}="_Prediction"; + } + if ($opmode == 6){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS WMI Server. \n"; + } + $parametro ="Pandora FMS WMI Server"; + $pa_config->{"servermode"}="_WMI"; + } + if ($opmode == 7){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS Export Server. \n"; + } + $parametro ="Pandora FMS Export Server"; + $pa_config->{"servermode"}="_Export"; + } + if ($opmode == 8){ + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + print " [*] You are running Pandora FMS Inventory Server. \n"; + } + $parametro ="Pandora FMS Inventory Server"; + $pa_config->{"servermode"}="_Inventory"; + } + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { + if ($pa_config->{"pandora_check"} == 1) { + print " [*] MD5 Security enabled.\n"; + } + if ($pa_config->{"pandora_master"} == 1) { + print " [*] This server is running in MASTER mode.\n"; + } + } logger ($pa_config, "Launching $pa_config->{'version'} $pa_config->{'build'}", 0); my $config_options = "Logfile at ".$pa_config->{"logfile"}.", Basepath is ".$pa_config->{"basepath"}.", Checksum is ".$pa_config->{"pandora_check"}.", Master is ".$pa_config->{"pandora_master"}.", SNMP Console is ".$pa_config->{"snmpconsole"}.", Server Threshold at ".$pa_config->{"server_threshold"}." sec, verbosity at ".$pa_config->{"verbosity"}.", Alert Threshold at $pa_config->{'alert_threshold'}, ServerName is '".$pa_config->{'servername'}.$pa_config->{"servermode"}."'"; @@ -576,19 +576,17 @@ sub pandora_loadconfig { 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); - pandora_event ($pa_config, $pa_config->{'servername'}.$pa_config->{"servermode"}." going UP", 0, - 0, 3, 0, 0, "system", $dbh); + pandora_event ($pa_config, $pa_config->{'servername'}.$pa_config->{"servermode"}." going UP", 0, 0, 3, 0, 0, "system", $dbh); } sub pandora_startlog ($){ - my $pa_config = $_[0]; + my $pa_config = $_[0]; - # Dump all errors to errorlog - open STDERR, ">>$pa_config->{'errorlogfile'}" or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \n"; - my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S"); - print STDERR "$time_now - ".$pa_config->{'servername'}.$pa_config->{"servermode"}." Starting Pandora FMS Server. Error logging activated \n"; - + # Dump all errors to errorlog + open STDERR, ">>$pa_config->{'errorlogfile'}" or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \n"; + my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S"); + print STDERR "$time_now - ".$pa_config->{'servername'}.$pa_config->{"servermode"}." Starting Pandora FMS Server. Error logging activated \n"; } # End of function declaration # End of defined Code diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 2cba1caff6..6f12732d80 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -3,26 +3,26 @@ package PandoraFMS::Tools; # Tools Package # Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org ########################################################################## -# Copyright (c) 2004-2008 Sancho Lerena, slerena@gmail.com -# Copyright (c) 2005-2008 Artica Soluciones Tecnologicas S.L +# Copyright (c) 2004-2009 Sancho Lerena, slerena@gmail.com +# Copyright (c) 2005-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 -#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. +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser 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 warnings; use Time::Local; -use Date::Manip; # Needed to manipulate DateTime formats of input, output and compare +use Date::Manip; # Needed to manipulate DateTime formats of input, output and compare use POSIX qw(setsid); -use Mail::Sendmail; # New in 2.0. Used to sendmail internally, without external scripts +use Mail::Sendmail; # New in 2.0. Used to sendmail internally, without external scripts require Exporter; @@ -30,20 +30,20 @@ our @ISA = ("Exporter"); our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( - pandora_daemonize - logger - limpia_cadena - md5check - float_equal - sqlWrap - is_numeric - clean_blank - pandora_sendmail - pandora_get_os - pandora_trash_ascii - enterprise_hook - enterprise_load - ); + pandora_daemonize + logger + limpia_cadena + md5check + float_equal + sqlWrap + is_numeric + clean_blank + pandora_sendmail + pandora_get_os + pandora_trash_ascii + enterprise_hook + enterprise_load +); ########################################################################## ## SUB pandora_trash_ascii @@ -51,14 +51,14 @@ our @EXPORT = qw( ########################################################################## sub pandora_trash_ascii { - my $config_depth = $_[0]; - my $a; - my $output; + my $config_depth = $_[0]; + my $a; + my $output; - for ($a=0;$a<$config_depth;$a++){ - $output = $output.chr(int(rand(25)+97)); - } - return $output + for ($a=0;$a<$config_depth;$a++){ + $output = $output.chr(int(rand(25)+97)); + } + return $output } @@ -108,22 +108,22 @@ sub pandora_get_os ($) { ########################################################################## sub pandora_daemonize { - my $pa_config = $_[0]; - open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; - open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!"; - open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!"; - chdir '/tmp' or die "Can't chdir to /tmp: $!"; - defined(my $pid = fork) or die "Can't fork: $!"; - exit if $pid; - setsid or die "Can't start a new session: $!"; - umask 0; + my $pa_config = $_[0]; + open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!"; + open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!"; + chdir '/tmp' or die "Can't chdir to /tmp: $!"; + defined(my $pid = fork) or die "Can't fork: $!"; + exit if $pid; + setsid or die "Can't start a new session: $!"; + umask 0; - # Store PID of this process in file presented by config token - if ($pa_config->{'PID'} ne ""){ - open (FILE, "> ".$pa_config->{'PID'}) or die "[FATAL] Cannot open PIDfile at ".$pa_config->{'PID'}; - print FILE "$$"; - close (FILE); - } + # Store PID of this process in file presented by config token + if ($pa_config->{'PID'} ne ""){ + open (FILE, "> ".$pa_config->{'PID'}) or die "[FATAL] Cannot open PIDfile at ".$pa_config->{'PID'}; + print FILE "$$"; + close (FILE); + } } @@ -142,29 +142,29 @@ sub pandora_daemonize { ########################################################################## sub pandora_sendmail { # added in 2.0 version - my $pa_config = $_[0]; - my $to_address = $_[1]; - my $subject = $_[2]; - my $message = $_[3]; + my $pa_config = $_[0]; + my $to_address = $_[1]; + my $subject = $_[2]; + my $message = $_[3]; - my %mail = ( To => $to_address, - Message => $message, - Subject => $subject, - Smtp => $pa_config->{"mta_address"}, - Port => $pa_config->{"mta_port"}, - From => $pa_config->{"mta_from"}, - ); + my %mail = ( To => $to_address, + Message => $message, + Subject => $subject, + Smtp => $pa_config->{"mta_address"}, + Port => $pa_config->{"mta_port"}, + From => $pa_config->{"mta_from"}, + ); - if ($pa_config->{"mta_user"} ne ""){ - $mail{auth} = {user=>$config->{"mta_user"}, password=>$config->{"mta_pass"}, method=>$config->{"mta_auth"}, required=>0 } - } - eval { - sendmail(%mail); - }; - if ($@){ - logger ($pa_config, "[ERROR] Sending email to $to_address with subject $subject", 1); - logger ($pa_config, "ERROR Code: $@", 4); - } + if ($pa_config->{"mta_user"} ne ""){ + $mail{auth} = {user=>$config->{"mta_user"}, password=>$config->{"mta_pass"}, method=>$config->{"mta_auth"}, required=>0 } + } + eval { + sendmail(%mail); + }; + if ($@){ + logger ($pa_config, "[ERROR] Sending email to $to_address with subject $subject", 1); + logger ($pa_config, "ERROR Code: $@", 4); + } } ########################################################################## @@ -286,9 +286,9 @@ sub limpia_cadena { # clean_blank (string) - Purge a string for any blank spaces in it ########################################################################## sub clean_blank { - my $input = $_[0]; - $input =~ s/\s//g; - return $input; + my $input = $_[0]; + $input =~ s/\s//g; + return $input; } ######################################################################################## @@ -299,9 +299,9 @@ sub clean_blank { sub sqlWrap { my $toBeWrapped = shift(@_); if (defined $toBeWrapped){ - $toBeWrapped =~ s/\'/\\\'/g; - $toBeWrapped =~ s/\"/\\\'/g; - return "'".$toBeWrapped."'"; + $toBeWrapped =~ s/\'/\\\'/g; + $toBeWrapped =~ s/\"/\\\'/g; + return "'".$toBeWrapped."'"; } } @@ -312,8 +312,8 @@ sub sqlWrap { # Taken from Perl Cookbook, O'Reilly. Thanks, guys. ########################################################################## sub float_equal { - my ($A, $B, $dp) = @_; - return sprintf("%.${dp}g", $A) eq sprintf("%.${dp}g", $B); + my ($A, $B, $dp) = @_; + return sprintf("%.${dp}g", $A) eq sprintf("%.${dp}g", $B); } ##########################################################################