2007-07-31 Sancho Lerena <slerena@gmail.com>

* pandora_snmpconsole: Fixed startup scripts. Many checks added to
        manage NetSNMP Trap daemon. Now uses /usr/sbin/snmptrapd by
        default. Solved many problems. This also solve bug #1763691.

        * conf/pandora_server.conf: Added snmp_logfile token (before
        inside CODE!, UGLY!).

        * bin/pandora_network.pl: I hope Fixed BUG #1763305 with Master Server.

        * bin/PandoraFMS/Config.pm: Support for config token snmp_logfile.

        * bin/PandoraFMS/DB.pm: Fixed (stupid) BUG #1763304 with alerts.

        * bin/pandora_snmpconsole.pl: Removed logfile filename from code
        (VERY ugly!).

        * pandora_server, pandora_network, pandora_recon: This also solve
        bug #1763691. Some additional checks included.

        * util/pandora_SNMP_test.pl: Removed, old stuff.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@576 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2007-07-31 17:26:09 +00:00
parent c292246b61
commit 36c0b32258
12 changed files with 222 additions and 177 deletions

View File

@ -1,3 +1,26 @@
2007-07-31 Sancho Lerena <slerena@gmail.com>
* pandora_snmpconsole: Fixed startup scripts. Many checks added to
manage NetSNMP Trap daemon. Now uses /usr/sbin/snmptrapd by
default. Solved many problems. This also solve bug #1763691.
* conf/pandora_server.conf: Added snmp_logfile token (before
inside CODE!, UGLY!).
* bin/pandora_network.pl: I hope Fixed BUG #1763305 with Master Server.
* bin/PandoraFMS/Config.pm: Support for config token snmp_logfile.
* bin/PandoraFMS/DB.pm: Fixed (stupid) BUG #1763304 with alerts.
* bin/pandora_snmpconsole.pl: Removed logfile filename from code
(VERY ugly!).
* pandora_server, pandora_network, pandora_recon: This also solve
bug #1763691. Some additional checks included.
* util/pandora_SNMP_test.pl: Removed, old stuff.
2007-07-20 Sancho Lerena <slerena@artica.es>
* pandora_network.pl: Fixed a typo in pandora_ping_latency function.

View File

@ -34,8 +34,8 @@ our @EXPORT = qw( pandora_help_screen
# There is no global vars, all variables (setup) passed as hash reference
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "1.3-beta2";
my $pandora_build="PS070717";
my $pandora_version = "1.3-dev";
my $pandora_build="PS070731";
our $VERSION = $pandora_version;
# Setup hash
@ -138,7 +138,8 @@ sub pandora_loadconfig {
$pa_config->{"dataserver"}=0;
$pa_config->{"reconserver"}=0;
$pa_config->{"servermode"}="";
$pa_config->{"network_threads"}=4; # Fixed default
$pa_config->{'pandora_snmp_logfile'}="/var/log/pandora/pandora_snmptrap.log";
$pa_config->{"network_threads"}=5; # Fixed default
$pa_config->{"keepalive"}=60; # 60 Seconds initially for server keepalive
$pa_config->{"keepalive_orig"} = $pa_config->{"keepalive"};
# Check for UID0
@ -204,6 +205,7 @@ sub pandora_loadconfig {
$pa_config->{"errorlogfile"} = $tbuf;
}
}
elsif ($parametro =~ m/^pandora_snmp_logfile\s(.*)/i) { $pa_config->{'pandora_snmp_logfile'}= $1; }
elsif ($parametro =~ m/^dbname\s(.*)/i) { $pa_config->{'dbname'}= $1; }
elsif ($parametro =~ m/^dbuser\s(.*)/i) { $pa_config->{'dbuser'}= $1; }
elsif ($parametro =~ m/^dbpass\s(.*)/i) { $pa_config->{'dbpass'}= $1; }

View File

@ -64,6 +64,7 @@ our @EXPORT = qw( crea_agente_modulo
execute_alert
give_network_component_profile_name
pandora_create_incident
give_db_value
);
# Spanish translation note:
@ -375,10 +376,7 @@ sub pandora_writestate (%$$$$$$$) {
# Check alert subroutine
eval {
# Alerts checks for Agents, only for master servers
if ($pa_config->{"pandora_master"} == 1){
pandora_calcula_alerta ($pa_config, $timestamp, $nombre_agente, $tipo_modulo, $nombre_modulo, $datos, $dbh);
}
pandora_calcula_alerta ($pa_config, $timestamp, $nombre_agente, $tipo_modulo, $nombre_modulo, $datos, $dbh);
};
if ($@) {
logger($pa_config, "ERROR: Error in SUB calcula_alerta(). ModuleName: $nombre_modulo ModuleType: $tipo_modulo AgentName: $nombre_agente", 4);
@ -780,7 +778,7 @@ sub pandora_writedata (%$$$$$$$$$$){
$min = "0";
}
# Obtenemos los identificadores
my $id_agente = dame_agente_id($pa_config, $nombre_agente,$dbh);
my $id_agente = dame_agente_id ($pa_config, $nombre_agente,$dbh);
# Check if exists module and agent_module reference in DB, if not, and learn mode activated, insert module in DB
if ($id_agente eq "-1"){
goto fin_DB_insert_datos;
@ -809,7 +807,7 @@ sub pandora_writedata (%$$$$$$$$$$){
$min = $data[6];
$s_idag->finish();
} else { # Id AgenteModulo DOESNT exist, it could need to be created...
if (dame_learnagente($pa_config, $id_agente,$dbh) eq "1"){
if (dame_learnagente($pa_config, $id_agente,$dbh) eq "1" ){
# Try to write a module and agent_module definition for that datablock
logger( $pa_config, "Pandora_insertdata will create module (learnmode) for agent $nombre_agente",6);
$id_agente_modulo = crea_agente_modulo ($pa_config, $nombre_agente, $tipo_modulo, $nombre_modulo, $max, $min, $descripcion, $dbh);

View File

@ -37,7 +37,7 @@ use PandoraFMS::DB;
# FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE
# DISABLE FOR PRODUCTION
$| = 0;
$| = 1;
my %pa_config;
my @pending_task : shared;
@ -173,7 +173,7 @@ sub pandora_network_producer ($) {
my $exec_sql1;
while (1) {
if ($pa_config->{"pandora_master"} != 666) {
if ($pa_config->{"pandora_master"} != 1) {
# Query for normal server, not MASTER server
$query1 = "SELECT
tagente_modulo.id_agente_modulo,
@ -198,8 +198,23 @@ sub pandora_network_producer ($) {
ORDER BY
last_execution_try ASC ";
} else {
# Query for master server
# PENDING TODO !
# Query for MASTER SERVER !
$query1 = "SELECT
DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag
FROM
tagente, tagente_modulo, tagente_estado, tserver
WHERE
( (tagente.id_server = $server_id AND tagente_modulo.id_agente = tagente.id_agente) OR
(tagente.id_server != $server_id AND tagente_modulo.id_agente = tagente.id_agente AND tagente.id_server = tserver.id_server AND tserver.status = 0)
) AND
tagente.disabled = 0
AND
tagente_modulo.id_tipo_modulo > 4
AND
tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND
((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() OR tagente_modulo.flag = 1 )
ORDER BY last_execution_try ASC";
}
$exec_sql1 = $dbh->prepare($query1);
$exec_sql1 ->execute;
@ -221,6 +236,7 @@ sub pandora_network_producer ($) {
}
}
}
#logger ($pa_config, "Items in Network Pending Queue: ".scalar(@pending_task), 5);
$exec_sql1->finish();
sleep($pa_config->{"server_threshold"});
} # Main loop
@ -325,7 +341,7 @@ sub pandora_query_tcp (%$$$$$$$) {
if (($tcp_rcv ne "") || ($id_tipo_modulo == 10) || ($id_tipo_modulo ==8) || ($id_tipo_modulo == 11)) {
# Receive data, non-blocking !!!! (VERY IMPORTANT!)
$temp2 = "";
for ($tam=0; $tam<($pa_config->{'networktimeout'}/2); $tam++){
for ($tam=0; $tam<($pa_config->{'networktimeout'}); $tam++){
$handle->recv($temp,16000,0x40);
$temp2 = $temp2.$temp;
if ($temp ne ""){
@ -452,7 +468,9 @@ sub exec_network_module {
my $id_module_group;
my $flag;
my @sql_data;
if ((!defined($id_agente_modulo)) || ($id_agente_modulo eq "")){
return;
}
my $query_sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
my $exec_sql = $dbh->prepare($query_sql);
$exec_sql ->execute;
@ -579,9 +597,13 @@ sub exec_network_module {
pandora_lastagentcontact ($pa_config, $timestamp, $agent_name, $pa_config->{'servername'}.$pa_config->{"servermode"}, $pa_config->{'version'}, -1, $dbh);
} else {
# $module_result != 0)
if ($module_interval == 0){
$module_interval = dame_intervalo ($pa_config, $id_agente, $dbh);
}
# Modules who cannot connect or something go bad, update last_execution_try field
logger ($pa_config, "Cannot obtain exec Network Module $nombre from agent $agent_name", 4);
my $query_act = "UPDATE tagente_estado SET last_execution_try = $utimestamp WHERE id_agente_modulo = $id_agente_modulo ";
my $query_act = "UPDATE tagente_estado SET current_interval = $module_interval, last_execution_try = $utimestamp WHERE id_agente_modulo = $id_agente_modulo ";
my $a_idages = $dbh->prepare($query_act);
$a_idages->execute;
$a_idages->finish();

View File

@ -62,7 +62,7 @@ pandora_snmptrapd (\%pa_config);
sub pandora_snmptrapd {
my $pa_config = $_[0];
my $snmp_logfile = $pa_config->{'pandora_path'}."/log/snmptrapd.log";
my $snmp_logfile = $pa_config->{'pandora_snmp_logfile'};
my $logfile_size; # Size of logfile, use for calculating index file
my @array;
my $datos;

View File

@ -6,7 +6,7 @@
# if not given, it takes localhost. It's preferable to setup one
# because machine name could change by some reason.
servername endor
#servername endor
# incomingdir: Defines directory where incoming data packets are stored
# You could set directory relative to base path or absolute, starting with /
@ -18,6 +18,10 @@ incomingdir /var/spool/pandora/data_in
log_file /var/log/pandora_server.log
# Log file for Pandora FMS SNMP console. Its generated by NetSNMP Trap daemon
snmp_logfile /var/log/pandora/pandora_snmptrap.log
# Error logfile: aux logfile for pandora_server errors (in Daemon mode)
# You could set file relative to base path or absolute, starting with /
@ -25,11 +29,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 zhriopul
# daemon: Runs in daemon mode (background) if 1, if 0 runs in foreground
# this could be setup on command line with -D option
@ -55,7 +59,7 @@ alert_threshold 45
# Master Server, 1 if master server (normal mode), 0 for slave mode (slave in multi-server setup)
master 0
master 1
# Check datafiles using a MD5 hash, 1 to check (default), 0 to ignore .checksum

View File

@ -1,16 +1,23 @@
#!/bin/bash
# Pandora Network Server, startup script
# Pandora FMS Network Server, startup script
# Sancho Lerena, <slerena@gmail.com>
# Linux Version (generico)
# v1.3 (Jul/2007)
# Linux Version (generic)
# v1.3 Build 070731
# Configurable path and filenames
PANDORA_HOME="/usr/share/pandora_server"
PANDORA_NETWORK_PID="/var/run/pandora/pandora_network.pid"
PANDORA_PID_PATH="/var/run/pandora"
PANDORA_PID=$PANDORA_PID_PATH/pandora_network.pid
# Main script
if [ ! -d "$PANDORA_PID_PATH" ]
then
echo "Pandora FMS cannot write it's PID file in $PANDORA_PID_PATH. Please create that directory"
exit
fi
if [ ! -f $PANDORA_HOME/bin/pandora_network.pl ]
then
echo "Pandora FMS Network Server not found, please check setup and read manual"
@ -20,34 +27,40 @@ fi
case "$1" in
start)
OLD_PATH="`pwd`"
if [ -f $PANDORA_NETWORK_PID ]
if [ -f $PANDORA_PID ]
then
echo "Pandora FMS Network Server is currently running on this machine. Aborting now..."
exit
CHECK_PID=`cat $PANDORA_PID`
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "pandora_network" | wc -l`
if [ $CHECK_PID_RESULT == 1 ]
then
echo "Pandora FMS Network Server is currently running on this machine with PID ($CHECK_PID). Aborting now..."
exit
fi
fi
cd $PANDORA_HOME/bin
./pandora_network.pl $PANDORA_HOME -D
MYPID=`ps aux | grep 'pandora_network.pl' | grep -v grep | tail -1 | awk '{print $2}'`
if [ ! -z "$MYPID" ]
then
echo $MYPID > $PANDORA_NETWORK_PID
echo $MYPID > $PANDORA_PID
echo "Pandora Network Server is now running with PID $MYPID"
else
echo "Cannot start Pandora FMS Network Server. Aborted."
fi
cd "$OLD_PATH"
cd "$OLD_PATH"
;;
stop)
if [ -f $PANDORA_NETWORK_PID ]
if [ -f $PANDORA_PID ]
then
echo "Stopping Pandora FMS Network Server"
PID_2=`cat $PANDORA_NETWORK_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_network'`" ]
PID_2=`cat $PANDORA_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_network' `" ]
then
kill `cat $PANDORA_NETWORK_PID` 2> /dev/null > /dev/null
kill `cat $PANDORA_PID` 2> /dev/null > /dev/null
fi
rm -f $PANDORA_NETWORK_PID
rm -f $PANDORA_PID
else
echo "Pandora FMS Network Server is not running, cannot stop it."
fi

View File

@ -1,15 +1,23 @@
#!/bin/sh
#!/bin/bash
# Pandora FMS Recon Server, startup script
# Sancho Lerena, <slerena@gmail.com>
# Linux Version (generic)
# v1.3 (Jul/2007)
# v1.3 Build 070731
# Configurable path and filenames
PANDORA_HOME="/usr/share/pandora_server"
PANDORA_PID="/var/run/pandora/pandora_recon.pid"
PANDORA_PID_PATH="/var/run/pandora"
PANDORA_PID=$PANDORA_PID_PATH/pandora_recon.pid
# Main script
if [ ! -d "$PANDORA_PID_PATH" ]
then
echo "Pandora FMS cannot write it's PID file in $PANDORA_PID_PATH. Please create that directory"
exit
fi
if [ ! -f $PANDORA_HOME/bin/pandora_recon.pl ]
then
echo "Pandora FMS Recon Server not found, please check setup and read manual"
@ -21,32 +29,34 @@ case "$1" in
OLD_PATH="`pwd`"
if [ -f $PANDORA_PID ]
then
PID_2=`cat $PANDORA_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_recon.pl'`" ]
CHECK_PID=`cat $PANDORA_PID`
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "pandora_recon" | wc -l`
if [ $CHECK_PID_RESULT == 1 ]
then
echo "Pandora FMS Recon Server is currently running on this machine. Aborting now..."
echo "Pandora FMS Recon Server is currently running on this machine with PID ($CHECK_PID). Aborting now..."
exit
fi
fi
cd $PANDORA_HOME/bin
./pandora_recon.pl $PANDORA_HOME -D
MYPID=`ps aux | grep 'pandora_recon.pl' | grep -v grep | tail -1 | awk '{print $2}'`
if [ ! -z "$MYPID" ]
then
echo $MYPID > $PANDORA_PID
echo "Pandora FMS Recon Server is now running with PID $MYPID"
echo "Pandora Recon Server is now running with PID $MYPID"
else
echo "Cannot start Pandora FMS Recon Server. Aborted"
echo "Cannot start Pandora FMS Recon Server. Aborted."
fi
cd "$OLD_PATH"
cd "$OLD_PATH"
;;
stop)
if [ -f $PANDORA_PID ]
then
echo "Stopping Pandora FMS Recon Server"
PID_2=`cat $PANDORA_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_recon.pl'`" ]
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_recon' `" ]
then
kill `cat $PANDORA_PID` 2> /dev/null > /dev/null
fi

View File

@ -1,15 +1,23 @@
#!/bin/bash
# Pandora Data Server startup script
# Pandora Data Server, startup script
# Sancho Lerena, <slerena@gmail.com>
# Linux Version (generic)
# v1.3 (Jul/2007)
# Linux Version (generico)
# v1.3 Build 070731
# Configurable path and filenames
PANDORA_HOME="/usr/share/pandora_server"
PANDORA_SERVER_PID="/var/run/pandora/pandora_server.pid"
PANDORA_PID_PATH="/var/run/pandora"
PANDORA_PID=$PANDORA_PID_PATH/pandora_dataserver.pid
# Main script
if [ ! -d "$PANDORA_PID_PATH" ]
then
echo "Pandora FMS cannot write it's PID file in $PANDORA_PID_PATH. Please create that directory"
exit
fi
if [ ! -f $PANDORA_HOME/bin/pandora_server.pl ]
then
echo "Pandora FMS Data Server not found, please check setup and read manual"
@ -19,34 +27,40 @@ fi
case "$1" in
start)
OLD_PATH="`pwd`"
if [ -f $PANDORA_SERVER_PID ]
if [ -f $PANDORA_PID ]
then
echo "Pandora FMS Data Server is currently running on this machine. Aborting now..."
exit
CHECK_PID=`cat $PANDORA_PID`
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "pandora_server.pl" | wc -l`
if [ $CHECK_PID_RESULT == 1 ]
then
echo "Pandora FMS Data Server is currently running on this machine with PID ($CHECK_PID). Aborting now..."
exit
fi
fi
cd $PANDORA_HOME/bin
./pandora_server.pl $PANDORA_HOME -D
MYPID=`ps aux | grep 'pandora_server.pl' | grep -v grep | tail -1 | awk '{print $2}'`
if [ ! -z "$MYPID" ]
then
echo $MYPID > $PANDORA_SERVER_PID
echo "Pandora FMS Data Server is now running with PID $MYPID"
echo $MYPID > $PANDORA_PID
echo "Pandora Data Server is now running with PID $MYPID"
else
echo "Cannot start Pandora FMS Data Server. Aborted"
echo "Cannot start Pandora FMS Data Server. Aborted."
fi
cd "$OLD_PATH"
;;
stop)
if [ -f $PANDORA_SERVER_PID ]
if [ -f $PANDORA_PID ]
then
echo "Stopping Pandora FMS Data Server"
PID_2=`cat $PANDORA_SERVER_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_server'`" ]
PID_2=`cat $PANDORA_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_server' `" ]
then
kill `cat $PANDORA_SERVER_PID` 2> /dev/null > /dev/null
kill `cat $PANDORA_PID` 2> /dev/null > /dev/null
fi
rm -f $PANDORA_SERVER_PID
rm -f $PANDORA_PID
else
echo "Pandora FMS Data Server is not running, cannot stop it."
fi

View File

@ -1,24 +1,36 @@
#!/bin/bash
# Startup script for Pandora SNMP Console
# Sancho Lerena, <slerena@gmail.com>
# Linux Version(generic)
# v1.3 (May/2007)
# Linux Version (generic)
# v1.3 BUILD 070731
# Compatible with NetSNMP 5.1 or higher
# Configurable path and filenames
PANDORA_HOME="/usr/share/pandora_server"
DAEMON_PATH="$PANDORA_HOME/util"
DAEMON_LOG="$PANDORA_HOME/log/snmptrapd.log"
DAEMON_PID="$PANDORA_HOME/var/snmptrapd.pid"
PANDORA_SNMP_PID="$PANDORA_HOME/var/pandora_snmp.pid"
PANDORA_PID_PATH="/var/run/pandora"
PANDORA_PID=$PANDORA_PID_PATH/pandora_snmp.pid
# Dont touch this call unless you know are doing.
DAEMON="$DAEMON_PATH/snmptrapd -t -On -n -a -Lf $DAEMON_LOG -p $DAEMON_PID -F %4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%B[**]%N[**]%w[**]%W[**]%q[**]%v\n"
DAEMON_LOG="/var/log/pandora/pandora_snmptrap.log"
DAEMON_PID="$PANDORA_PID_PATH/pandora_snmptrapd.pid"
DAEMON_PATH=/usr/sbin/snmptrapd
if [ ! -f $DAEMON_PATH/snmptrapd ]
# Dont touch this call unless you know are doing. For different versions of NetSNMP Trap daemon, it's possible you need to change some options
# Please refer NetSNMP documentation in that case.
DAEMON_OPTIONS="-t -On -n -a -Lf $DAEMON_LOG -p $DAEMON_PID -F %4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%B[**]%N[**]%w[**]%W[**]%q[**]%v\n"
DAEMON="$DAEMON_PATH $DAEMON_OPTIONS"
if [ ! -d "$PANDORA_PID_PATH" ]
then
echo "NetSNMP snmptrapd not found at $DAEMON_PATH/snmptrapd, please check setup and read manual"
echo "Pandora FMS cannot write it's PID file in $PANDORA_PID_PATH. Please create that directory"
exit
fi
if [ ! -f "$DAEMON_PATH" ]
then
echo "NetSNMP snmptrapd not found at $DAEMON_PATH, please check setup and read manual"
exit
fi
@ -26,13 +38,46 @@ case "$1" in
start)
if [ -f $DAEMON_PID ]
then
echo "NetSNMP Trap daemon is currently running on this machine. Aborting now..."
CHECK_PID=`cat $DAEMON_PID`
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "snmp" | wc -l`
if [ $CHECK_PID_RESULT == 1 ]
then
echo "NetSNMP Trap daemon is currently running on this machine with PID ($CHECK_PID). Aborting now..."
exit
fi
fi
SNMP_WARNING=`ps aux | grep "snmptrapd" | grep -v grep | wc -l`
if [ $SNMP_WARNING == 1 ]
then
echo "WARNING: Seems to be already running a SNMP trap daemon on this system not associated with Pandora FMS"
echo "Check manually if their output logfile is been used for Pandora FMS and it's format is correct"
fi
# Launch SNMP TRAP Daemon
$DAEMON
sleep 1
if [ ! -f $DAEMON_LOG ]
then
echo "Problem with NetSNMP Trap daemon (Logfile $DAEMON_LOG not found!). Aborting"
exit
fi
if [ -f $DAEMON_PID ]
then
CHECK_PID=`cat $DAEMON_PID`
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "snmp" | wc -l`
if [ $CHECK_PID_RESULT != 1 ]
then
echo "Problem starting NetSNMP Trap daemon on this machine (PID File not correct). Aborting now..."
exit
fi
else
echo "Problem starting NetSNMP Trap daemon on this machine (Cannot get PID File). Aborting now..."
exit
fi
rm -f $DAEMON_LOG 2> /dev/null
$DAEMON 2> /dev/null
sleep 1
RESULT="`cat $DAEMON_LOG | grep 'errno 13' 2> /dev/null`"
if [ -z "$RESULT" ]
then
@ -41,19 +86,25 @@ case "$1" in
echo "NetSNMP cannot open port (udp/162). Please execute as root user"
rm -f $DAEMON_PID 2> /dev/null
fi
if [ -f $PANDORA_SNMP_PID ]
then
echo "Pandora FMS SNMP Server is currently running on this machine. Aborting now..."
exit
fi
if [ -f $PANDORA_PID ]
then
CHECK_PID=`cat $PANDORA_PID`
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "pandora_snmpconsole.pl" | wc -l`
if [ $CHECK_PID_RESULT == 1 ]
then
echo "Pandora FMS SNMP Server is currently running on this machine with PID ($CHECK_PID). Aborting now..."
exit
fi
fi
cd $PANDORA_HOME/bin
./pandora_snmpconsole.pl $PANDORA_HOME -D
MYPID=`ps aux | grep 'pandora_snmpconsole.pl' | grep -v grep | tail -1 | awk '{print $2}'`
if [ ! -z "$MYPID" ]
then
echo $MYPID > $PANDORA_SNMP_PID
echo $MYPID > $PANDORA_PID
echo "Pandora FMS SNMP Server is now running with PID $MYPID"
else
echo "Cannot start Pandora FMS SNMP Server. Aborted"
@ -75,15 +126,15 @@ case "$1" in
echo "NetSNMP Trap daemon is not running, cannot stop it."
fi
if [ -f $PANDORA_SNMP_PID ]
if [ -f $PANDORA_PID ]
then
echo "Stopping Pandora SNMP Console"
PID_2=`cat $PANDORA_SNMP_PID`
PID_2=`cat $PANDORA_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_snmpconsole'`" ]
then
kill `cat $PANDORA_SNMP_PID` 2> /dev/null > /dev/null
kill `cat $PANDORA_PID` 2> /dev/null > /dev/null
fi
rm -f $PANDORA_SNMP_PID
rm -f $PANDORA_PID
else
echo "Pandora FMS SNMP Console is not running, cannot stop it."
fi

View File

@ -1,92 +0,0 @@
#!/usr/bin/perl
##################################################################################
# SNMP Test tool
##################################################################################
# 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 Net::SNMP; # For query2 testing
use SNMP '5.0.2.pre1' || die("Cannot load module\n");
##########################################################################################
# SUB pandora_query_snmp (pa_config, oid, community, target, error, dbh)
# Makes a call to SNMP modules to get a value,
##########################################################################################
sub pandora_query_snmp2 {
my $snmp_oid = shift;
my $snmp_community = shift;
my $snmp_target = shift;
print "DEBUG OID $snmp_oid comm $snmp_community target $snmp_target \n";
my $output ="";
my ($session1, $error) = Net::SNMP->session(
-hostname => $snmp_target,
-community => $snmp_community,
-port => 161 );
if (!defined($session1)) {
printf("SNMP ERROR SESSION");
}
my $result = $session1->get_request(
-varbindlist => $snmp_oid
);
if (!defined($result)) {
printf("SNMP ERROR GET");
$session1->close;
} else {
$output = $result->{$snmp_oid};
$session1->close;
}
return $output;
}
sub pandora_query_snmp {
my $snmp_oid = shift;
my $snmp_community = shift;
my $snmp_target = shift;
$ENV{'MIBS'}="ALL"; #Load all available MIBs
$SNMP_TARGET = $snmp_target;
$SNMP_COMMUNITY = $snmp_community;
$SESSION = new SNMP::Session (DestHost => $SNMP_TARGET,
Community => $SNMP_COMMUNITY,
Version => 1);
# Populate a VarList with OID values.
$APC_VLIST = new SNMP::VarList([$snmp_oid]);
# Pass the VarList to getnext building an array of the output
@APC_INFO = $SESSION->getnext($APC_VLIST);
print $APC_INFO[0];
print "\n";
}
if ($#ARGV == -1 ){
print "Syntax: snmptest community hostname oid\n";
exit;
}
my $snmp_community = $ARGV[0];
my $snmp_target = $ARGV[1];
my $snmp_oid = $ARGV[2];
pandora_query_snmp($snmp_oid, $snmp_community, $snmp_target);

Binary file not shown.