Monitoring-Generator-TestConfig
view release on metacpan or search on metacpan
lib/Monitoring/Generator/TestConfig.pm view on Meta::CPAN
if(!defined $self->{$opt_key} and ref $options{$opt_key} eq '' and defined $options{$opt_key}) {
$self->{$opt_key} = ''.$options{$opt_key};
}
elsif(ref $self->{$opt_key} eq ref $options{$opt_key}) {
$self->{$opt_key} = $options{$opt_key};
}
elsif(ref $options{$opt_key} eq 'Getopt::Long::CallBack') {
$self->{$opt_key} = ''.$options{$opt_key};
}
else {
croak('unknown type for option '.$opt_key.': '.(ref $options{$opt_key}));
}
}
else {
croak("unknown option: $opt_key");
}
}
if(!defined $self->{'layout'}) {
if(defined $ENV{'OMD_ROOT'}) {
$self->{'layout'} = "omd";
} else {
$self->{'layout'} = "nagios";
}
}
if($self->{'layout'} ne 'nagios' and $self->{'layout'} ne 'icinga' and $self->{'layout'} ne 'shinken' and $self->{'layout'} ne 'omd') {
croak('valid layouts are: nagios, icinga, shinken and omd');
}
# set some defaults for OMD
if($self->{'layout'} eq "omd") {
if(!defined $ENV{'OMD_ROOT'}) {
croak('please use omd layout only as OMD siteuser');
}
$self->{'output_dir'} = $ENV{'OMD_ROOT'};
$self->{'overwrite_dir'} = 1;
$self->{'binary'} = $ENV{'OMD_ROOT'}."/bin/nagios";
$self->{'user'} = $ENV{'OMD_SITE'};
$self->{'group'} = $ENV{'OMD_SITE'};
$self->{'prefix'} = $ENV{'OMD_SITE'}."_";
}
if(!defined $self->{'output_dir'}) {
croak('no output_dir given');
}
# strip off last slash
$self->{'output_dir'} =~ s/\/$//mx;
if(-e $self->{'output_dir'} and !$self->{'overwrite_dir'}) {
croak('output_dir '.$self->{'output_dir'}.' does already exist and overwrite_dir not set');
}
# set some defaults
my($user, $group);
if($^O eq "MSWin32") {
$user = getlogin();
$group = "nagios";
} else {
$user = getpwuid($<);
my @userinfo = getpwnam($user);
my @groupinfo = getgrgid($userinfo[3]);
$group = $groupinfo[0];
}
$self->{'user'} = $user unless defined $self->{'user'};
$self->{'group'} = $group unless defined $self->{'group'};
# we dont want the root user to run the core
if($self->{'user'} eq 'root') {
print STDERR "warning: root user is not recommended, using user '".$self->{'layout'}."' instead!\n";
$self->{'user'} = $self->{'layout'};
$self->{'group'} = $self->{'layout'};
}
# try to find a binary in path
if(!defined $self->{'binary'}) {
my @possible_bin_locations;
if($self->{'layout'} eq 'nagios') {
$self->{'binary'} = can_run('nagios3') || can_run('nagios') || undef;
@possible_bin_locations = qw|/usr/sbin/nagios3 /usr/bin/nagios3 /usr/local/bin/nagios3 /usr/sbin/nagios /usr/bin/nagios /usr/local/bin/nagios|;
} elsif($self->{'layout'} eq 'icinga' ) {
$self->{'binary'} = can_run('icinga') || undef;
@possible_bin_locations = qw|/usr/sbin/icinga /usr/bin/icinga /usr/local/bin/icinga|;
} elsif($self->{'layout'} eq 'shinken' ) {
$self->{'binary'} = can_run('shinken-arbiter') || '/usr/local/shinken/bin/shinken-arbiter';
}
# still not defined?
if(!defined $self->{'binary'}) {
for my $loc (@possible_bin_locations) {
if(-x $loc) {
$self->{'binary'} = $loc;
last;
}
}
}
}
if(!defined $self->{'binary'}) {
#carp('found no monitoring binary in path and none defined by the \'binary\' option, using fallback /usr/bin/nagios');
$self->{'binary'} = '/usr/bin/nagios';
}
return $self;
}
########################################
=head1 METHODS
=over 4
=item create
create()
generates and writes the configuration
Returns true on success or undef on errors.
( run in 1.299 second using v1.01-cache-2.11-cpan-d7f47b0818f )