2010-10-08 Sancho Lerena <slerena@artica.es>

* unix/pandora_agent_daemon: Kill with -9 to be sure is killed,
        because UDP server mode "captures" the INT signal to restart
        the agent when receibe REFRESH AGENT on UDP client.

        * unix/Linux/pandora_agent.conf: New config tokens to support
        UDP server options.

        * unix/pandora_agent: UDP Server mode implemented in the
        Unix/Perl agent, only for REFRESH AGENT option, no remote commands
        possible.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3370 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2010-10-08 09:58:18 +00:00
parent f5f859faff
commit fe21083399
4 changed files with 108 additions and 24 deletions

View File

@ -1,3 +1,15 @@
2010-10-08 Sancho Lerena <slerena@artica.es>
* unix/pandora_agent_daemon: Kill with -9 to be sure is killed,
because UDP server mode "captures" the INT signal to restart
the agent when receibe REFRESH AGENT on UDP client.
* unix/Linux/pandora_agent.conf: New config tokens to support UDP
server options.
* unix/pandora_agent: UDP Server mode implemented in the Unix/Perl
agent, only for REFRESH AGENT option, no remote commands possible.
2010-10-06 Junichi Satoh <junichi@rworks.jp> 2010-10-06 Junichi Satoh <junichi@rworks.jp>
* unix/pandora_agent: Added FreeBSD specific commands. * unix/pandora_agent: Added FreeBSD specific commands.

View File

@ -19,14 +19,23 @@ interval 300
# and does not copy XML to server. # and does not copy XML to server.
debug 0 debug 0
# Optional. UDP Server to receive orders from outside
# By default is disabled, set 1 to enable
# Set port (41122 by default)
# Set address to restrict who can order a agent restart (0.0.0.0 = anybody)
#
udp_server 0
udp_server_port 41122
udp_server_auth_address 0.0.0.0
# By default, agent takes machine name # By default, agent takes machine name
#agent_name adama #agent_name adama
#Parent agent_name #Parent agent_name
#parent_agent_name parent_name #parent_agent_name caprica
# Agent description # Agent description
#description Demo agent #description This is a demo agent for Linux
# Group assigned for this agent (descriptive, p.e: Servers) # Group assigned for this agent (descriptive, p.e: Servers)
#group Servers #group Servers
@ -82,7 +91,7 @@ transfer_mode tentacle
# Cron mode replace Pandora FMS own task schedule each XX interval seconds by the use # Cron mode replace Pandora FMS own task schedule each XX interval seconds by the use
# of old style cron. You should add to crontab Pandora FMS agent script to use this mode. # of old style cron. You should add to crontab Pandora FMS agent script to use this mode.
# This is disabled by default, and is not recommended. Use Pandora FMS internal scheduler # This is disabled by default, and is not recommended. Use Pandora FMS internal scheduler
# is much more safe. # is much more safe
#cron_mode #cron_mode
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version) # If set to 1 allows the agent to be configured via the web console (Only Enterprise version)

View File

@ -28,6 +28,7 @@ use POSIX qw(strftime floor);
use Sys::Hostname; use Sys::Hostname;
use File::Basename; use File::Basename;
use File::Copy; use File::Copy;
use IO::Socket;
# Agent XML data # Agent XML data
my $Xml; my $Xml;
@ -47,6 +48,7 @@ eval {
require threads; require threads;
require threads::shared; require threads::shared;
require Thread::Semaphore; require Thread::Semaphore;
require IO::Socket;
}; };
if (!$@) { if (!$@) {
threads::shared::share (\$Xml); threads::shared::share (\$Xml);
@ -54,8 +56,8 @@ if (!$@) {
$Sem = Thread::Semaphore->new; $Sem = Thread::Semaphore->new;
} }
use constant AGENT_VERSION => '3.1'; use constant AGENT_VERSION => '3.2dev';
use constant AGENT_BUILD => '100608'; use constant AGENT_BUILD => '101008';
# Commands to retrieve total memory information in kB # Commands to retrieve total memory information in kB
use constant TOTALMEMORY_CMDS => { use constant TOTALMEMORY_CMDS => {
@ -146,7 +148,10 @@ my %Conf = (
'autotime' => 0, 'autotime' => 0,
'timezone_offset' => 0, 'timezone_offset' => 0,
'pandora_exec' => 'pandora_exec', 'pandora_exec' => 'pandora_exec',
'agent_threads' => 1 'agent_threads' => 1,
'udp_server_port' => 41122,
'udp_server_auth_address' => '0.0.0.0',
'udp_server' => 0
); );
# Modules # Modules
@ -1203,6 +1208,43 @@ sub write_module_xml ($@) {
$Sem->up () if (defined ($Sem)); $Sem->up () if (defined ($Sem));
} }
################################################################################
# Receive a UDP server signal to restart agent
################################################################################
sub udp_server_signal () {
log_message ('udp server', 'Received signal to restart the agent.');
}
################################################################################
# Basic UDP server to restart agent on UDP signal received
################################################################################
sub udp_server ($$) {
my $udp_port = shift;
my $udp_auth_address = shift;
my $parent_pid = getppid();
my($sock, $oldmsg, $newmsg, $hisaddr, $hishost, $MAXLEN);
$MAXLEN = 1024;
log_message ('udp server', 'Starting UDP server listening on '.$udp_auth_address.":".$udp_port);
$sock = IO::Socket::INET->new(LocalPort => $udp_port, Proto => 'udp') or die "socket: $@";
while ($sock->recv($newmsg, $MAXLEN)) {
my($port, $ipaddr) = sockaddr_in($sock->peername);
$hishost = gethostbyaddr($ipaddr, AF_INET);
log_message ('udp server', 'Received signal from '.$hishost);
if (($udp_auth_address eq "0.0.0.0") || ($hishost eq $udp_auth_address)){
if ($newmsg =~ /REFRESH AGENT/){
# Send signal to restart agent
kill 'SIGINT' , $parent_pid;
}
}
}
}
################################################################################ ################################################################################
# Execute the given plugin. # Execute the given plugin.
################################################################################ ################################################################################
@ -1260,9 +1302,25 @@ my $PID = $$;
# Add the plugins directory to the PATH # Add the plugins directory to the PATH
$ENV{'PATH'} .= ":$ConfDir/plugins"; $ENV{'PATH'} .= ":$ConfDir/plugins";
# Start UDP server if configured
if ($Conf{'udp_server'} == 1){
my $pid = fork();
if ($pid == 0){
udp_server ($Conf{'udp_server_port'}, $Conf{'udp_server_auth_address'});
exit;
}
}
# Loop # Loop
while (1) { while (1) {
# Ignore signals from UDP server while processing execution
if ($Conf{'udp_server'} == 1){
$SIG{'INT'} = 'DEFAULT';
}
# Check for a new configuration # Check for a new configuration
check_remote_config () unless ($Conf{'debug'} eq '1'); check_remote_config () unless ($Conf{'debug'} eq '1');
@ -1353,6 +1411,11 @@ while (1) {
# Cron mode # Cron mode
last if ($Conf{'cron_mode'} == 1); last if ($Conf{'cron_mode'} == 1);
# Enable signal capture to break the Sleep interval on UDP signal
if ($Conf{'udp_server'} == 1){
$SIG{'INT'} = \&udp_server_signal;
}
# Go to sleep # Go to sleep
sleep ($Conf{'interval'}); sleep ($Conf{'interval'});
} }

View File

@ -93,7 +93,7 @@ case "$1" in
exit 1 exit 1
else else
echo "Stopping Pandora Agent." echo "Stopping Pandora Agent."
kill $PANDORA_PID > /dev/null 2>&1 kill -9 $PANDORA_PID > /dev/null 2>&1
fi fi
;; ;;