2011-07-08 Vanessa Gil <vanessa.gil@artica.es>

* unix/pandora_agent: Allow drone agents in Unix.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4538 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
vgilc 2011-07-08 11:46:38 +00:00
parent 343c3bb61d
commit 5b6d88b589
2 changed files with 55 additions and 32 deletions

View File

@ -1,3 +1,7 @@
2011-07-08 Vanessa Gil <vanessa.gil@artica.es>
* unix/pandora_agent: Allow drone agents in Unix.
2011-06-28 Sergio Martin <sergio.martin@artica.es> 2011-06-28 Sergio Martin <sergio.martin@artica.es>
* unix/Linux/pandora_agent.conf: Typo fixed * unix/Linux/pandora_agent.conf: Typo fixed

View File

@ -112,6 +112,7 @@ my $ConfDir = '';
# Pandora FMS agent configuration file # Pandora FMS agent configuration file
my $ConfFile = 'pandora_agent.conf'; my $ConfFile = 'pandora_agent.conf';
my @all_conf;
# Configuration tokens # Configuration tokens
my %Conf = ( my %Conf = (
@ -421,15 +422,23 @@ sub parse_conf_modules($) {
################################################################################ ################################################################################
# Create configuration file for drone agents. # Create configuration file for drone agents.
################################################################################ ################################################################################
sub write_broker_conf($$){ sub write_broker_conf($$$){
my ($conf_file, $broker_file) = @_; my ($conf_file, $broker_file, $name_agent) = @_;
my $content = ''; my $content = '';
open (CONF_FILE, "$ConfDir/$ConfFile") or error ("Could not open file '$ConfDir/$ConfFile': $!."); open (CONF_FILE, "$ConfDir/$ConfFile") or error ("Could not open file '$ConfDir/$ConfFile': $!.");
open (BROKER_FILE, ">$broker_file") or error ("Could not write configuration file: $!"); open (BROKER_FILE, ">$broker_file") or error ("Could not write configuration file: $!");
print BROKER_FILE while (<CONF_FILE>); while (my $line = <CONF_FILE>){
if ($line =~ /^broker_agent\s+(\w*)\s*/){
next;
}
#Change agent_name
if ($line =~ m/^\s*#*\s*agent_name\s+(\w*)\s*/) {
$line = "agent_name $name_agent";
}
print BROKER_FILE $line;
}
close (BROKER_FILE); close (BROKER_FILE);
close (CONF_FILE); close (CONF_FILE);
} }
@ -450,7 +459,6 @@ sub read_config (;$) {
foreach my $line (@file){ foreach my $line (@file){
# Skip comments and empty lines # Skip comments and empty lines
next if ($line =~ m/^\s*#/) or ($line =~ m/^\s*$/); next if ($line =~ m/^\s*#/) or ($line =~ m/^\s*$/);
# Single token search # Single token search
if (defined ($token)) { if (defined ($token)) {
return $2 if ($line =~ /^\s*(\S+)\s+(.*)$/ && $1 eq $token); return $2 if ($line =~ /^\s*(\S+)\s+(.*)$/ && $1 eq $token);
@ -467,7 +475,11 @@ sub read_config (;$) {
if ($line =~ /^broker_agent\s+(\w*)\s*/){ if ($line =~ /^broker_agent\s+(\w*)\s*/){
my $path_conf = "$ConfDir/$ConfFile"; my $path_conf = "$ConfDir/$ConfFile";
my $path_broker = "$ConfDir/$1.conf"; my $path_broker = "$ConfDir/$1.conf";
write_broker_conf($path_conf, $path_broker); my $name_agent = $1;
push (@all_conf, "$1.conf");
unless (-e $path_broker){
write_broker_conf($path_conf, $path_broker, $name_agent);
}
} }
#Configuration token #Configuration token
if ($line =~ /^\s*(\S+)\s+(.*)$/) { if ($line =~ /^\s*(\S+)\s+(.*)$/) {
@ -1506,9 +1518,15 @@ print_usage unless ($#ARGV == 0);
$ConfDir = fix_directory ($ARGV[0]); $ConfDir = fix_directory ($ARGV[0]);
error ("Directory '$ConfDir' does not exist.") unless (-d "$ConfDir"); error ("Directory '$ConfDir' does not exist.") unless (-d "$ConfDir");
# Get user to run as push (@all_conf, $ConfFile);
my $pandora_user = read_config ('pandora_user');
if (defined ($pandora_user)) { foreach my $conf_agent (@all_conf){
$ConfFile = $conf_agent;
# Get user to run as
my $pandora_user = read_config ('pandora_user');
if (defined ($pandora_user)) {
# Change the EUID # Change the EUID
my $pandora_user_uid = getpwnam ($pandora_user); my $pandora_user_uid = getpwnam ($pandora_user);
if (!defined ($pandora_user_uid)) { if (!defined ($pandora_user_uid)) {
@ -1518,21 +1536,21 @@ if (defined ($pandora_user)) {
if ($> != $pandora_user_uid) { if ($> != $pandora_user_uid) {
error ("Cannot run as $pandora_user: Insufficient permissions."); error ("Cannot run as $pandora_user: Insufficient permissions.");
} }
}
# Guess the OS version
$OS_VERSION = guess_os_version ($OS);
# Initialize MD5 variables
md5_init ();
# Start logging
start_log ();
log_message ('log', 'Running as user ' . getpwuid ($>));
# Read configuration file
read_config ();
} }
# Guess the OS version
$OS_VERSION = guess_os_version ($OS);
# Initialize MD5 variables
md5_init ();
# Start logging
start_log ();
log_message ('log', 'Running as user ' . getpwuid ($>));
# Read configuration file
read_config ();
# Fix directory names # Fix directory names
$Conf{'temporal'} = fix_directory ($Conf{'temporal'}); $Conf{'temporal'} = fix_directory ($Conf{'temporal'});
error ("Temporal directory '" . $Conf{'temporal'} . "' does not exist.") unless (-d "$Conf{'temporal'}"); error ("Temporal directory '" . $Conf{'temporal'} . "' does not exist.") unless (-d "$Conf{'temporal'}");
@ -1571,7 +1589,6 @@ if ($Conf{'udp_server'} == 1){
} }
} }
# Loop # Loop
while (1) { while (1) {
@ -1715,10 +1732,12 @@ while (1) {
# Go to sleep # Go to sleep
# #
sleep ($Conf{'interval'}); sleep ($Conf{'interval'});
} }
__END__ __END__
=head1 EXIT STATUS =head1 EXIT STATUS