| 1 | package Monitoring::Generator::TestConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use POSIX qw(ceil); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use IPC::Cmd qw(can_run); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Monitoring::Generator::TestConfig::ServiceCheckData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Monitoring::Generator::TestConfig::HostCheckData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Monitoring::Generator::TestConfig::InitScriptData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Monitoring::Generator::TestConfig::P1Data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Monitoring::Generator::TestConfig::Modules::Shinken; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Monitoring::Generator::TestConfig::ShinkenInitScriptData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | our $VERSION = '0.54'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Monitoring::Generator::TestConfig - generate monitoring configurations (nagios/icinga/shinken) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | use Monitoring::Generator::TestConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $ngt = Monitoring::Generator::TestConfig->new( 'output_dir' => '/tmp/test_monitoring' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $ngt->create(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | This modul generates test configurations for your monitoring. This can be useful if you | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | want for doing load tests or testing addons and plugins. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | =item new ( [ARGS] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | Creates an C<Monitoring::Generator::TestConfig> object. C<new> takes at least the output_dir. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | Arguments are in key-value pairs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | verbose verbose mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | output_dir export directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | overwrite_dir overwrite contents of an existing directory. Default: false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | layout which config should be generated, valid options are "nagios", "icinga", "shinken" and "omd" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | user user, defaults to the current user | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | group group, defaults to the current users group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | prefix prefix to all hosts / services / contacts / contactgroups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | binary path to your nagios/icinga bin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | hostcount amount of hosts to export, Default 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | hostcheckcmd use custom hostcheck command line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | servicecheckcmd use custom servicecheck command line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | routercount amount of router to export, Default 5 ( exported as host and used as parent ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | services_per_host amount of services per host, Default 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | host_settings key/value settings for use in the define host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | service_settings key/value settings for use in the define service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | main_cfg overwrite/add settings from the nagios.cfg/icinga.cfg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | hostfailrate chance of a host to fail, Default 2% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | servicefailrate chance of a service to fail, Default 5% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | host_types key/value settings for percentage of hosttypes, possible keys are up,down,flap,random,block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | router_types key/value settings for percentage of hosttypes for router | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | service_types key/value settings for percentage of servicetypes, possible keys are ok,warning,critical,unknown,flap,random,block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | skip_dependencies no service dependencies will be exported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | contacts_count amount of contacts to export, Default 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | contactgroups_count amount of contactgroups to export, Default 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | contacts_per_group amount of contacts to export, Default 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | contacts_per_host amount of contacts per host, Default 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | contactgroups_per_host amount of contactgroups per host, Default 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | contacts_per_service amount of contacts per service, Default 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | contactgroups_per_service amount of contactgroups per service, Default 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | skip_hostgroups no hostgroups will be exported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | skip_servicegroups no servicegroups will be exported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=35 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | my($class,%options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'verbose' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'output_dir' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 'layout' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 'user' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 'group' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 'prefix' => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 'overwrite_dir' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 'binary' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 'contacts_count' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 'contactgroups_count' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 'contacts_per_group' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 'contacts_per_host' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 'contactgroups_per_host' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 'contacts_per_service' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 'contactgroups_per_service' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'routercount' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 'hostcount' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 'hostcheckcmd' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 'servicecheckcmd' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 'services_per_host' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 'main_cfg' => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 'host_settings' => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 'service_settings' => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 'servicefailrate' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'hostfailrate' => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 'skip_dependencies' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 'skip_hostgroups' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 'skip_servicegroups' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 'fixed_length' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 'router_types' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 'down' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 'up' => 50, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 'flap' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 'random' => 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 'pending' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 'block' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 'host_types' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 'down' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 'up' => 50, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 'flap' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 'random' => 35, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 'pending' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'block' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 'service_types' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 'ok' => 50, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 'warning' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 'unknown' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 'critical' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 'pending' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 'flap' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 'random' => 25, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 'block' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | for my $opt_key (keys %options) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 13 | ▶ | if(exists $self->{$opt_key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # set option to scalar because getopt now uses objects instead of scalars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 13 | ▶ | if(!defined $self->{$opt_key} and ref $options{$opt_key} eq '' and defined $options{$opt_key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
not defined $self->{$opt_key} and ref $options{$opt_key} eq "" and defined $options{$opt_key}
not defined $self->{$opt_key} and ref $options{$opt_key} eq ""
MC/DC33%1/3
not defined $self->{$opt_key} and ref $options{$opt_key} eq "" and defined $options{$opt_key}
not defined $self->{$opt_key}
ref $options{$opt_key} eq ""
defined $options{$opt_key}
Truth table50%2/4
not(A) and B and C
A= not defined $self->{$opt_key}B= ref $options{$opt_key} eq ""C= defined $options{$opt_key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | $self->{$opt_key} = ''.$options{$opt_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | elsif(ref $self->{$opt_key} eq ref $options{$opt_key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 5 | $self->{$opt_key} = $options{$opt_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | elsif(ref $options{$opt_key} eq 'Getopt::Long::CallBack') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->{$opt_key} = ''.$options{$opt_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | croak('unknown type for option '.$opt_key.': '.(ref $options{$opt_key})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | croak("unknown option: $opt_key"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | ▶ | if(!defined $self->{'layout'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | if(defined $ENV{'OMD_ROOT'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->{'layout'} = "omd"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | $self->{'layout'} = "nagios"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | ▶ | if($self->{'layout'} ne 'nagios' and $self->{'layout'} ne 'icinga' and $self->{'layout'} ne 'shinken' and $self->{'layout'} ne 'omd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$self->{"layout"} ne "nagios" and $self->{"layout"} ne "icinga" and $self->{"layout"} ne "shinken" and $self->{"layout"} ne "omd"
$self->{"layout"} ne "nagios" and $self->{"layout"} ne "icinga" and $self->{"layout"} ne "shinken"
$self->{"layout"} ne "nagios" and $self->{"layout"} ne "icinga"
MC/DC0%0/4
$self->{"layout"} ne "nagios" and $self->{"layout"} ne "icinga" and $self->{"layout"} ne "shinken" and $self->{"layout"} ne "omd"
$self->{"layout"} ne "nagios"
$self->{"layout"} ne "icinga"
$self->{"layout"} ne "shinken"
$self->{"layout"} ne "omd"
Truth table60%3/5
A and B and C and D
A= $self->{"layout"} ne "nagios"B= $self->{"layout"} ne "icinga"C= $self->{"layout"} ne "shinken"D= $self->{"layout"} ne "omd"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | croak('valid layouts are: nagios, icinga, shinken and omd'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # set some defaults for OMD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 5 | ▶ | if($self->{'layout'} eq "omd") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if(!defined $ENV{'OMD_ROOT'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | croak('please use omd layout only as OMD siteuser'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $self->{'output_dir'} = $ENV{'OMD_ROOT'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->{'overwrite_dir'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $self->{'binary'} = $ENV{'OMD_ROOT'}."/bin/nagios"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->{'user'} = $ENV{'OMD_SITE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->{'group'} = $ENV{'OMD_SITE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $self->{'prefix'} = $ENV{'OMD_SITE'}."_"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | if(!defined $self->{'output_dir'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | croak('no output_dir given'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # strip off last slash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | $self->{'output_dir'} =~ s/\/$//mx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | if(-e $self->{'output_dir'} and !$self->{'overwrite_dir'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $self->{"output_dir"} and not $self->{"overwrite_dir"}
MC/DC0%0/2
-e $self->{"output_dir"} and not $self->{"overwrite_dir"}
-e $self->{"output_dir"}
not $self->{"overwrite_dir"}
Truth table33%1/3
A and not(B)
A= -e $self->{"output_dir"}B= not $self->{"overwrite_dir"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | croak('output_dir '.$self->{'output_dir'}.' does already exist and overwrite_dir not set'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # set some defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | my($user, $group); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | ▶ | if($^O eq "MSWin32") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $user = getlogin(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $group = "nagios"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | $user = getpwuid($<); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 5 | my @userinfo = getpwnam($user); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 5 | my @groupinfo = getgrgid($userinfo[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | $group = $groupinfo[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 5 | ▶ | $self->{'user'} = $user unless defined $self->{'user'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | ▶ | $self->{'group'} = $group unless defined $self->{'group'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # we dont want the root user to run the core | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | ▶ | if($self->{'user'} eq 'root') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | print STDERR "warning: root user is not recommended, using user '".$self->{'layout'}."' instead!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $self->{'user'} = $self->{'layout'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $self->{'group'} = $self->{'layout'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # try to find a binary in path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | ▶ | if(!defined $self->{'binary'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 5 | my @possible_bin_locations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 5 | ▶ | if($self->{'layout'} eq 'nagios') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 3 | ▶ | $self->{'binary'} = can_run('nagios3') || can_run('nagios') || undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
can_run('nagios3') || can_run('nagios') || undef
can_run("nagios3") or can_run("nagios")
MC/DC0%0/2
can_run('nagios3') || can_run('nagios') || undef
can_run("nagios3")
can_run("nagios")
Truth table33%1/3
A or B
A= can_run("nagios3")B= can_run("nagios")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | @possible_bin_locations = qw|/usr/sbin/nagios3 /usr/bin/nagios3 /usr/local/bin/nagios3 /usr/sbin/nagios /usr/bin/nagios /usr/local/bin/nagios|; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } elsif($self->{'layout'} eq 'icinga' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | $self->{'binary'} = can_run('icinga') || undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
can_run('icinga') || undef
MC/DC0%0/1
can_run('icinga') || undef
can_run('icinga')
Truth table50%1/2
A
A= can_run('icinga')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | @possible_bin_locations = qw|/usr/sbin/icinga /usr/bin/icinga /usr/local/bin/icinga|; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } elsif($self->{'layout'} eq 'shinken' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | ▶ | $self->{'binary'} = can_run('shinken-arbiter') || '/usr/local/shinken/bin/shinken-arbiter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
can_run('shinken-arbiter') || '/usr/local/shinken/bin/shinken-arbiter'
MC/DC0%0/1
can_run('shinken-arbiter') || '/usr/local/shinken/bin/shinken-arbiter'
can_run('shinken-arbiter')
Truth table50%1/2
A
A= can_run('shinken-arbiter')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # still not defined? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | ▶ | if(!defined $self->{'binary'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 4 | for my $loc (@possible_bin_locations) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 21 | ▶ | if(-x $loc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $self->{'binary'} = $loc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 5 | ▶ | if(!defined $self->{'binary'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | #carp('found no monitoring binary in path and none defined by the \'binary\' option, using fallback /usr/bin/nagios'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | $self->{'binary'} = '/usr/bin/nagios'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | =item create | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | create() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | generates and writes the configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | Returns true on success or undef on errors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=26 SCAR=40.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # set open umask, so the webserver can read those files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | umask(0022); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | ▶ | if(!-d $self->{'output_dir'}."/.") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | mkdir($self->{'output_dir'}) or croak('failed to create output_dir '.$self->{'output_dir'}.':'.$!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # write out main config file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | ▶ | unless($self->{'layout'} eq 'omd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | my $mainconfigfilename = $self->{'layout'}.'.cfg'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | open(my $fh, '>', $self->{'output_dir'}.'/'.$mainconfigfilename) or die('cannot write: '.$!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | print $fh $self->_get_main_cfg(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # create some missing dirs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | ▶ | unless($self->{'layout'} eq 'omd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | for my $dir (qw{etc etc/conf.d var var/checkresults var/tmp plugins archives init.d}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 8 | ▶ | if(!-d $self->{'output_dir'}.'/'.$dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | mkdir($self->{'output_dir'}.'/'.$dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 8 | ▶ | or croak('failed to create dir ('.$self->{'output_dir'}.'/'.$dir.') :' .$!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # export config files and plugins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | my $init = $self->{'layout'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | my $objects = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | my($contactnames, $contactgroupnames) = $self->_set_contacts_cfg($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | $objects = $self->_set_hosts_cfg($objects, $contactnames, $contactgroupnames); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | $objects = $self->_set_hostgroups_cfg($objects) unless $self->{'skip_hostgroups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | $objects = $self->_set_services_cfg($objects, $contactnames, $contactgroupnames); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | $objects = $self->_set_servicegroups_cfg($objects) unless $self->{'skip_servicegroups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | $objects = $self->_set_commands_cfg($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | $objects = $self->_set_timeperiods_cfg($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | my $obj_prefix = '/etc/conf.d'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | my $plg_prefix = '/plugins'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | if($self->{'layout'} eq 'omd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $obj_prefix = '/etc/nagios/conf.d/generated'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $plg_prefix = '/local/lib/nagios/plugins'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | my $exportedFiles = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | { file => $obj_prefix.'/hosts.cfg', data => $self->_create_object_conf('host', $objects->{'host'}) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | { file => $obj_prefix.'/hostgroups.cfg', data => $self->_create_object_conf('hostgroup', $objects->{'hostgroup'}) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | { file => $obj_prefix.'/services.cfg', data => $self->_create_object_conf('service', $objects->{'service'}) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | { file => $obj_prefix.'/servicegroups.cfg', data => $self->_create_object_conf('servicegroup', $objects->{'servicegroup'}) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | { file => $obj_prefix.'/contacts.cfg', data => $self->_create_object_conf('contactgroup', $objects->{'contactgroup'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | .$self->_create_object_conf('contact', $objects->{'contact'}) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | { file => $obj_prefix.'/commands.cfg', data => $self->_create_object_conf('command', $objects->{'command'}) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | { file => $plg_prefix.'/test_servicecheck.pl', data => Monitoring::Generator::TestConfig::ServiceCheckData->get_test_servicecheck() }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | { file => $plg_prefix.'/test_hostcheck.pl', data => Monitoring::Generator::TestConfig::HostCheckData->get_test_hostcheck() }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | { file => '/recreate.pl', data => $self->_get_recreate_pl($self->_get_used_libs($self->{'output_dir'}.'/recreate.pl')) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | if($self->{'layout'} ne 'omd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | push(@{$exportedFiles}, { file => $obj_prefix.'/timeperiods.cfg', data => $self->_create_object_conf('timeperiod', $objects->{'timeperiod'}) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | push(@{$exportedFiles}, { file => '/etc/resource.cfg', data => '$USER1$='.$self->{'output_dir'}."/plugins\n" }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | ▶ | if ($self->{'layout'} eq 'nagios' or $self->{'layout'} eq 'icinga') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"layout"} eq "nagios" or $self->{"layout"} eq "icinga"
MC/DC0%0/2
$self->{"layout"} eq "nagios" or $self->{"layout"} eq "icinga"
$self->{"layout"} eq "nagios"
$self->{"layout"} eq "icinga"
Truth table33%1/3
A or B
A= $self->{"layout"} eq "nagios"B= $self->{"layout"} eq "icinga"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | push(@{$exportedFiles}, { file => '/plugins/p1.pl', data => Monitoring::Generator::TestConfig::P1Data->get_p1_script() }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | push(@{$exportedFiles}, { file => '/init.d/'.$init, data => Monitoring::Generator::TestConfig::InitScriptData->get_init_script( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | $self->{'output_dir'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | $self->{'binary'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | $self->{'user'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | $self->{'group'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | $self->{'layout'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | )}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | ▶ | if ($self->{'layout'} eq 'shinken') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | push(@{$exportedFiles}, { file => '/etc/shinken-specific.cfg', data => Monitoring::Generator::TestConfig::Modules::Shinken::_get_shinken_specific_cfg($self) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | push(@{$exportedFiles}, { file => '/etc/schedulerd.cfg', data => Monitoring::Generator::TestConfig::Modules::Shinken::_get_shinken_schedulerd_cfg($self) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | push(@{$exportedFiles}, { file => '/etc/pollerd.cfg', data => Monitoring::Generator::TestConfig::Modules::Shinken::_get_shinken_pollerd_cfg($self) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | push(@{$exportedFiles}, { file => '/etc/brokerd.cfg', data => Monitoring::Generator::TestConfig::Modules::Shinken::_get_shinken_brokerd_cfg($self) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | push(@{$exportedFiles}, { file => '/etc/reactionnerd.cfg', data => Monitoring::Generator::TestConfig::Modules::Shinken::_get_shinken_reactionnerd_cfg($self) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | push(@{$exportedFiles}, { file => '/init.d/'.$init, data => Monitoring::Generator::TestConfig::ShinkenInitScriptData->get_init_script( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | $self->{'output_dir'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $self->{'binary'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | ) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # export service dependencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | my $servicedependency = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | ▶ | unless ($self->{'skip_dependencies'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | $objects = $self->_set_servicedependency_cfg($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | $servicedependency = $self->_create_object_conf('servicedependency', $objects->{'servicedependency'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | push(@{$exportedFiles}, { file => $obj_prefix.'/dependencies.cfg', data => $servicedependency }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | ▶ | if( !-d $self->{'output_dir'}."/".$obj_prefix ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | mkdir($self->{'output_dir'}."/".$obj_prefix) or croak('failed to create output_dir '.$self->{'output_dir'}."/".$obj_prefix.':'.$!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | for my $exportFile (@{$exportedFiles}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 14 | ▶ | open(my $fh, '>', $self->{'output_dir'}.$exportFile->{'file'}) or die('cannot write '.$self->{'output_dir'}.$exportFile->{'file'}.': '.$!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 14 | print $fh $exportFile->{'data'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 14 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | ▶ | chmod 0755, $self->{'output_dir'}.$plg_prefix.'/test_servicecheck.pl' or die("cannot change modes: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | ▶ | chmod 0755, $self->{'output_dir'}.$plg_prefix.'/test_hostcheck.pl' or die("cannot change modes: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | chmod 0755, $self->{'output_dir'}.'/plugins/p1.pl'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | chmod 0755, $self->{'output_dir'}.'/init.d/'.$init; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | chmod 0755, $self->{'output_dir'}.'/recreate.pl'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # check user/group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ▶ | if( $^O ne "MSWin32" and $< == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$^O ne "MSWin32" and $< == 0
MC/DC0%0/2
$^O ne "MSWin32" and $< == 0
$^O ne "MSWin32"
$< == 0
Truth table33%1/3
A and B
A= $^O ne "MSWin32"B= $< == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | `chown -R $self->{'user'}:$self->{'group'} $self->{'output_dir'}`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | ▶ | if($self->{'layout'} eq 'omd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | print "exported omd test config to: ".$self->{'output_dir'}.$obj_prefix."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | print "check your configuration with: ~/etc/init.d/nagios checkconfig\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | print "exported ".$self->{'layout'}." test config to: $self->{'output_dir'}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | print "check your configuration with: $self->{'output_dir'}/init.d/".$init." checkconfig\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | print "configuration can be adjusted and recreated with $self->{'output_dir'}/recreate.pl\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | ▶ | sub _set_hosts_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_hosts_cfg: called CC=27 SCAR=33.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | my($self, $objects, $contactnames, $contactgroupnames) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | ▶ | $objects->{'host'} = [] unless defined $objects->{'host'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | my $hostconfig = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 'name' => 'generic-mgt-test-host', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 'notifications_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 'event_handler_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 'flap_detection_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 'failure_prediction_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 'process_perf_data' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 'retain_status_information' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 'retain_nonstatus_information' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 'max_check_attempts' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 'check_interval' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 'retry_interval' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 'check_period' => '24x7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 'notification_interval' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 'notification_period' => '24x7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 'notification_options' => 'd,u,r', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 'register' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | my $merged = $self->_merge_config_hashes($hostconfig, $self->{'host_settings'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | push @{$objects->{'host'}}, $merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | my @router; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # router | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | ▶ | if($self->{'routercount'} > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | my @routertypes = @{$self->_fisher_yates_shuffle($self->_get_types($self->{'routercount'}, $self->{'router_types'}))}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | ▶ | my $nr_length = $self->{'fixed_length'} || length($self->{'routercount'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'fixed_length'} || length $self->{'routercount'}
MC/DC0%0/2
$self->{'fixed_length'} || length $self->{'routercount'}
$self->{'fixed_length'}
length $self->{'routercount'}
Truth table33%1/3
A || B
A= $self->{'fixed_length'}B= length $self->{'routercount'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | for(my $x = 0; $x < $self->{'routercount'}; $x++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 5 | my $hostgroup = "router"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 5 | my $nr = sprintf("%0".$nr_length."d", $x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 5 | my $type = shift @routertypes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 5 | push @router, $self->{'prefix'}."router_$nr"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | my $host = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 'host_name' => $self->{'prefix'}."router_".$nr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 5 | 'alias' => $self->{'prefix'}.$type."_".$nr, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 'use' => 'generic-mgt-test-host', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 'address' => '127.0.'.$x.'.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 'hostgroups' => $hostgroup, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 'check_command' => 'test-check-host-alive!'.$type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 'icon_image' => '../../docs/images/switch.png', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 5 | ▶ | $host->{'active_checks_enabled'} = '0' if $type eq 'pending'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 5 | ▶ | delete $host->{'hostgroups'} if $self->{'skip_hostgroups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # first router gets additional infos | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 5 | ▶ | if($x == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | $host->{'notes_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/README'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | $host->{'notes'} = 'just a notes string'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | $host->{'icon_image_alt'} = 'icon alt string'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | $host->{'action_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 5 | ▶ | if($x == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | $host->{'notes_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/README'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | $host->{'action_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 5 | ▶ | if($x == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | $host->{'notes_url'} = 'http://google.com/?q=$HOSTNAME$'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | $host->{'action_url'} = 'http://google.com/?q=$HOSTNAME$'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # add contacts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 5 | my @contacts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 5 | ▶ | for(my $z = 0; $z < $self->{'contacts_per_host'}; $z++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | push @contacts, $contactnames->[ rand @{$contactnames} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 5 | ▶ | $host->{'contacts'} = join(',', @contacts) if scalar @contacts > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # add contactgroups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 5 | my @contactgroups = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 5 | ▶ | for(my $z = 0; $z < $self->{'contactgroups_per_host'}; $z++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 5 | push @contactgroups, $contactgroupnames->[ rand @{$contactgroupnames} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 5 | ▶ | $host->{'contact_groups'} = join(',', @contactgroups) if scalar @contactgroups > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 5 | $host = $self->_merge_config_hashes($host, $self->{'host_settings'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 5 | push @{$objects->{'host'}}, $host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # hosts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | my @hosttypes = @{$self->_fisher_yates_shuffle($self->_get_types($self->{'hostcount'}, $self->{'host_types'}))}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | ▶ | my $nr_length = $self->{'fixed_length'} || length($self->{'hostcount'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'fixed_length'} || length $self->{'hostcount'}
MC/DC0%0/2
$self->{'fixed_length'} || length $self->{'hostcount'}
$self->{'fixed_length'}
length $self->{'hostcount'}
Truth table33%1/3
A || B
A= $self->{'fixed_length'}B= length $self->{'hostcount'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | ▶ | for(my $x = 0; $x < $self->{'hostcount'}; $x++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 10 | my $hostgroup = "hostgroup_01"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 10 | ▶ | $hostgroup = "hostgroup_02" if $x%5 == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 10 | ▶ | $hostgroup = "hostgroup_03" if $x%5 == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 10 | ▶ | $hostgroup = "hostgroup_04" if $x%5 == 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 10 | ▶ | $hostgroup = "hostgroup_05" if $x%5 == 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 10 | my $nr = sprintf("%0".$nr_length."d", $x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 10 | my $type = shift @hosttypes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 10 | my $num_router = scalar @router + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 10 | my $cur_router = $x % $num_router; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | my $host = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 'host_name' => $self->{'prefix'}."host_".$nr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 10 | 'alias' => $self->{'prefix'}.$type."_".$nr, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 'use' => 'generic-mgt-test-host', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 'address' => '127.0.'.$cur_router.'.'.($x + 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 'hostgroups' => $hostgroup.','.$type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 'check_command' => 'test-check-host-alive!'.$type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 10 | ▶ | if(defined $router[$cur_router]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 9 | $host->{'parents'} = $router[$cur_router]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 9 | $host->{'check_command'} = 'test-check-host-alive-parent!'.$type.'!$HOSTSTATE:'.$router[$cur_router].'$'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 10 | ▶ | $host->{'active_checks_enabled'} = '0' if $type eq 'pending'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 10 | ▶ | delete $host->{'hostgroups'} if $self->{'skip_hostgroups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # add contacts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 10 | my @contacts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 10 | ▶ | for(my $z = 0; $z < $self->{'contacts_per_host'}; $z++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | push @contacts, $contactnames->[ rand @{$contactnames} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 10 | ▶ | $host->{'contacts'} = join(',', @contacts) if scalar @contacts > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # add contactgroups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 10 | my @contactgroups = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 10 | ▶ | for(my $z = 0; $z < $self->{'contactgroups_per_host'}; $z++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 10 | push @contactgroups, $contactgroupnames->[ rand @{$contactgroupnames} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 10 | ▶ | $host->{'contact_groups'} = join(',', @contactgroups) if scalar @contactgroups > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 10 | $host = $self->_merge_config_hashes($host, $self->{'host_settings'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 10 | push @{$objects->{'host'}}, $host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | return($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | ▶ | sub _set_hostgroups_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_hostgroups_cfg: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | my $objects = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | ▶ | $objects->{'hostgroup'} = [] unless defined $objects->{'hostgroup'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | push @{$objects->{'hostgroup'}}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | { hostgroup_name => 'router', alias => 'All Router Hosts' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | { hostgroup_name => 'hostgroup_01', alias => 'hostgroup_alias_01' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | { hostgroup_name => 'hostgroup_02', alias => 'hostgroup_alias_02' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | { hostgroup_name => 'hostgroup_03', alias => 'hostgroup_alias_03' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | { hostgroup_name => 'hostgroup_04', alias => 'hostgroup_alias_04' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | { hostgroup_name => 'hostgroup_05', alias => 'hostgroup_alias_05' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | { hostgroup_name => 'up', alias => 'All Up Hosts' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | { hostgroup_name => 'down', alias => 'All Down Hosts' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | { hostgroup_name => 'pending', alias => 'All Pending Hosts' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | { hostgroup_name => 'random', alias => 'All Random Hosts' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | { hostgroup_name => 'flap', alias => 'All Flapping Hosts' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | { hostgroup_name => 'block', alias => 'All Blocking Hosts' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | return($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | ▶ | sub _set_services_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_services_cfg: called CC=19 SCAR=29.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | my($self, $objects, $contactnames, $contactgroupnames) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | ▶ | $objects->{'service'} = [] unless defined $objects->{'service'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | my $serviceconfig = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 'name' => 'generic-mgt-test-service', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 'active_checks_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 'passive_checks_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 'parallelize_check' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 'obsess_over_service' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 'check_freshness' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 'notifications_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 'event_handler_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 'flap_detection_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 'failure_prediction_enabled' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 'process_perf_data' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 'retain_status_information' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 'retain_nonstatus_information' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 'notification_interval' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 'is_volatile' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 'check_period' => '24x7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 'check_interval' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 'retry_interval' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 'max_check_attempts' => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 'notification_period' => '24x7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 'notification_options' => 'w,u,c,r', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 'register' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 1 | my $merged = $self->_merge_config_hashes($serviceconfig, $self->{'service_settings'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 1 | push @{$objects->{'service'}}, $merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | my @servicetypes = @{$self->_fisher_yates_shuffle($self->_get_types($self->{'hostcount'} * $self->{'services_per_host'}, $self->{'service_types'}))}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 1 | ▶ | my $hostnr_length = $self->{'fixed_length'} || length($self->{'hostcount'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'fixed_length'} || length $self->{'hostcount'}
MC/DC0%0/2
$self->{'fixed_length'} || length $self->{'hostcount'}
$self->{'fixed_length'}
length $self->{'hostcount'}
Truth table33%1/3
A || B
A= $self->{'fixed_length'}B= length $self->{'hostcount'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | ▶ | my $servicenr_length = $self->{'fixed_length'} || length($self->{'services_per_host'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'fixed_length'} || length $self->{'services_per_host'}
MC/DC0%0/2
$self->{'fixed_length'} || length $self->{'services_per_host'}
$self->{'fixed_length'}
length $self->{'services_per_host'}
Truth table33%1/3
A || B
A= $self->{'fixed_length'}B= length $self->{'services_per_host'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | ▶ | for(my $x = 0; $x < $self->{'hostcount'}; $x++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 10 | my $host_nr = sprintf("%0".$hostnr_length."d", $x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 10 | ▶ | for(my $y = 0; $y < $self->{'services_per_host'}; $y++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 100 | my $service_nr = sprintf("%0".$servicenr_length."d", $y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 100 | my $servicegroup = "servicegroup_01"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 100 | ▶ | $servicegroup = "servicegroup_02" if $y%5 == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 100 | ▶ | $servicegroup = "servicegroup_03" if $y%5 == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 100 | ▶ | $servicegroup = "servicegroup_04" if $y%5 == 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 100 | ▶ | $servicegroup = "servicegroup_05" if $y%5 == 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 100 | my $type = shift @servicetypes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | my $service = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 'host_name' => $self->{'prefix'}."host_".$host_nr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 100 | 'service_description' => $self->{'prefix'}.$type."_".$service_nr, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 'check_command' => 'check_service!'.$type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 'use' => 'generic-mgt-test-service', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 'servicegroups' => $servicegroup.','.$type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 100 | ▶ | $service->{'active_checks_enabled'} = '0' if $type eq 'pending'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 100 | ▶ | delete $service->{'servicegroups'} if $self->{'skip_servicegroups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # first router gets additional infos | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 100 | ▶ | if($y == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 10 | $service->{'notes_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/README'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 10 | $service->{'notes'} = 'just a notes string'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 10 | $service->{'icon_image_alt'} = 'icon alt string'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 10 | $service->{'icon_image'} = 'tux.png'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 10 | $service->{'action_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 100 | ▶ | if($y == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 10 | $service->{'notes_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/README'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 10 | $service->{'action_url'} = 'http://search.cpan.org/dist/Monitoring-Generator-TestConfig/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 100 | ▶ | if($y == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 10 | $service->{'notes_url'} = 'http://google.com/?q=$HOSTNAME$'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 10 | $service->{'action_url'} = 'http://google.com/?q=$HOSTNAME$'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | # add contacts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 100 | my @contacts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 100 | ▶ | for(my $z = 0; $z < $self->{'contacts_per_service'}; $z++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | push @contacts, $contactnames->[ rand @{$contactnames} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 100 | ▶ | $service->{'contacts'} = join(',', @contacts) if scalar @contacts > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | # add contactgroups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 100 | my @contactgroups = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 100 | ▶ | for(my $z = 0; $z < $self->{'contactgroups_per_service'}; $z++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 100 | push @contactgroups, $contactgroupnames->[ rand @{$contactgroupnames} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 100 | ▶ | $service->{'contact_groups'} = join(',', @contactgroups) if scalar @contactgroups > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 100 | $service = $self->_merge_config_hashes($service, $self->{'service_settings'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 100 | push @{$objects->{'service'}}, $service; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | return($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | ▶ | sub _set_servicegroups_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_servicegroups_cfg: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 1 | my $objects = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 1 | ▶ | $objects->{'servicegroup'} = [] unless defined $objects->{'servicegroup'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 1 | push @{$objects->{'servicegroup'}}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | { servicegroup_name => 'servicegroup_01', alias => 'servicegroup_alias_01' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | { servicegroup_name => 'servicegroup_02', alias => 'servicegroup_alias_02' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | { servicegroup_name => 'servicegroup_03', alias => 'servicegroup_alias_03' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | { servicegroup_name => 'servicegroup_04', alias => 'servicegroup_alias_04' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | { servicegroup_name => 'servicegroup_05', alias => 'servicegroup_alias_05' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | { servicegroup_name => 'ok', alias => 'All Ok Services' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | { servicegroup_name => 'warning', alias => 'All Warning Services' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | { servicegroup_name => 'unknown', alias => 'All Unknown Services' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | { servicegroup_name => 'critical', alias => 'All Critical Services' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | { servicegroup_name => 'pending', alias => 'All Pending Services' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | { servicegroup_name => 'random', alias => 'All Random Services' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | { servicegroup_name => 'flap', alias => 'All Flapping Services' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | { servicegroup_name => 'block', alias => 'All Blocking Services' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | return($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 1 | ▶ | sub _set_servicedependency_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_servicedependency_cfg: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1 | my $objects = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 1 | ▶ | $objects->{'servicedependency'} = [] unless defined $objects->{'servicedependency'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | my $service_size = scalar @{$objects->{'service'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 1 | ▶ | for(my $x = 2; $x < $service_size; $x+=5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 20 | my $dependent = $objects->{'service'}->[$x]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 20 | my $master = $objects->{'service'}->[$x-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 20 | ▶ | next unless defined $dependent->{'host_name'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 20 | ▶ | next unless defined $master->{'host_name'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 20 | push @{$objects->{'servicedependency'}}, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 'dependent_host_name' => $dependent->{'host_name'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 'dependent_service_description' => $dependent->{'service_description'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 'host_name' => $master->{'host_name'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 20 | 'service_description' => $master->{'service_description'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 'execution_failure_criteria' => 'w,u,c', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 'notification_failure_criteria' => 'w,u,c', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 1 | return $objects; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 1 | ▶ | sub _set_contacts_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_contacts_cfg: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 1 | my($self, $objects) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 1 | ▶ | $objects->{'contact'} = [] unless defined $objects->{'contact'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 1 | my @contacts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 1 | ▶ | my $nr_length = $self->{'fixed_length'} || length($self->{'contacts_count'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'fixed_length'} || length $self->{'contacts_count'}
MC/DC0%0/2
$self->{'fixed_length'} || length $self->{'contacts_count'}
$self->{'fixed_length'}
length $self->{'contacts_count'}
Truth table33%1/3
A || B
A= $self->{'fixed_length'}B= length $self->{'contacts_count'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 1 | ▶ | for(my $x = 0; $x < $self->{'contacts_count'}; $x++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 1 | my $nr = sprintf("%0".$nr_length."d", $x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 1 | my $name = $self->{'prefix'}."contact_".$nr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 1 | push @contacts, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 1 | push @{$objects->{'contact'}}, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 'contact_name' => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 1 | 'alias' => $self->{'prefix'}."contactalias_".$nr, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 'service_notification_period' => '24x7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 'host_notification_period' => '24x7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 'service_notification_options' => 'w,u,c,r', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 'host_notification_options' => 'd,r', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 'service_notification_commands' => 'notify-service', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 'host_notification_commands' => 'notify-host', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 'email' => 'nobody@localhost', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 1 | my @contactgroups = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 1 | ▶ | $objects->{'contactgroup'} = [] unless defined $objects->{'contactgroup'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 1 | ▶ | $nr_length = $self->{'fixed_length'} || length($self->{'contactgroups_count'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'fixed_length'} || length $self->{'contactgroups_count'}
MC/DC0%0/2
$self->{'fixed_length'} || length $self->{'contactgroups_count'}
$self->{'fixed_length'}
length $self->{'contactgroups_count'}
Truth table33%1/3
A || B
A= $self->{'fixed_length'}B= length $self->{'contactgroups_count'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 1 | ▶ | for(my $x = 0; $x < $self->{'contactgroups_count'}; $x++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 1 | my $nr = sprintf("%0".$nr_length."d", $x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 1 | my @members = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 1 | ▶ | for(my $y = 0; $y < $self->{'contacts_per_group'}; $y++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 1 | push @members, $contacts[ rand @contacts ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 1 | my $name = $self->{'prefix'}."contactgroup_".$nr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 1 | push @contactgroups, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 1 | push @{$objects->{'contactgroup'}}, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 'contactgroup_name' => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 1 | 'alias' => $self->{'prefix'}."groupalias_".$nr, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 'members' => join(',', @members), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 1 | return(\@contacts, \@contactgroups); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 1 | ▶ | sub _set_commands_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_commands_cfg: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 1 | my $objects = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 1 | my $usr_macro = "USER1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 1 | ▶ | if($self->{'layout'} eq 'omd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | $usr_macro = "USER2"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 1 | ▶ | $objects->{'command'} = [] unless defined $objects->{'command'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 1 | ▶ | push @{$objects->{'command'}}, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 'command_name' => 'test-check-host-alive', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 'command_line' => (defined $self->{'hostcheckcmd'} ? $self->{'hostcheckcmd'} : '$'.$usr_macro.'$/test_hostcheck.pl --type=$ARG1$ --failchance='.$self->{'hostfailrate'}.'% --previous-state=$HOSTSTATE$ --state-duration=$HOSTDURATIONSEC$ --hostname $HOSTNAME$'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | }, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 'command_name' => 'test-check-host-alive-parent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 'command_line' => (defined $self->{'hostcheckcmd'} ? $self->{'hostcheckcmd'} : '$'.$usr_macro.'$/test_hostcheck.pl --type=$ARG1$ --failchance='.$self->{'hostfailrate'}.'% --previous-state=$HOSTSTATE$ --state-duration=$HOSTDURATIONSEC$ --parent-state=$ARG2$ --hostname $HOSTNAME$'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | }, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 'command_name' => 'notify-host', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 'command_line' => 'sleep 1 && /bin/true', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | }, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 'command_name' => 'notify-service', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 'command_line' => 'sleep 1 && /bin/true', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | }, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 'command_name' => 'check_service', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 1 | 'command_line' => (defined $self->{'servicecheckcmd'} ? $self->{'servicecheckcmd'} : '$'.$usr_macro.'$/test_servicecheck.pl --type=$ARG1$ --failchance='.$self->{'servicefailrate'}.'% --previous-state=$SERVICESTATE$ --state-duration=$SERVICEDURATIONSEC$ --total-critical-on-host=$TOTALHOSTSERVICESCRITICAL$ --total-warning-on-host=$TOTALHOSTSERVICESWARNING$ --hostname $HOSTNAME$ --servicedesc $SERVICEDESC$'), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 1 | return($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 1 | ▶ | sub _set_timeperiods_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_timeperiods_cfg: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 1 | my $objects = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 1 | ▶ | $objects->{'timeperiod'} = [] unless defined $objects->{'timeperiod'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 1 | push @{$objects->{'timeperiod'}}, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 'timeperiod_name' => '24x7', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 'alias' => '24 Hours A Day, 7 Days A Week', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 'sunday' => '00:00-24:00', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 'monday' => '00:00-24:00', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 'tuesday' => '00:00-24:00', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 'wednesday' => '00:00-24:00', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 'thursday' => '00:00-24:00', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 'friday' => '00:00-24:00', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 'saturday' => '00:00-24:00', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 1 | return($objects); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 1 | ▶ | sub _get_main_cfg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_main_cfg: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | my $main_cfg = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 'log_file' => $self->{'output_dir'}.'/var/'.$self->{'layout'}.'.log', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 'cfg_dir' => $self->{'output_dir'}.'/etc/conf.d', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 'object_cache_file' => $self->{'output_dir'}.'/var/objects.cache', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 'precached_object_file' => $self->{'output_dir'}.'/var/objects.precache', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 'resource_file' => $self->{'output_dir'}.'/etc/resource.cfg', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 'status_file' => $self->{'output_dir'}.'/var/status.dat', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 'status_update_interval' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | $self->{'layout'}.'_user' => $self->{'user'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | $self->{'layout'}.'_group' => $self->{'group'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 'check_external_commands' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 'command_check_interval' => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 'command_file' => $self->{'output_dir'}.'/var/'.$self->{'layout'}.'.cmd', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 'external_command_buffer_slots' => 4096, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 'lock_file' => $self->{'output_dir'}.'/var/'.$self->{'layout'}.'.pid', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 'temp_file' => $self->{'output_dir'}.'/var/tmp/'.$self->{'layout'}.'.tmp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 'temp_path' => $self->{'output_dir'}.'/var/tmp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 'event_broker_options' =>-1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 'log_rotation_method' =>'d', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 'log_archive_path' => $self->{'output_dir'}.'/archives', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 'use_syslog' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 'log_notifications' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 'log_service_retries' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 'log_host_retries' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 'log_event_handlers' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 'log_initial_states' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 'log_external_commands' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 'log_passive_checks' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 'service_inter_check_delay_method' => 's', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 'max_service_check_spread' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 'service_interleave_factor' => 's', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 'host_inter_check_delay_method' => 's', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 'max_host_check_spread' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 'max_concurrent_checks' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 'check_result_reaper_frequency' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 'max_check_result_reaper_time' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 'check_result_path' => $self->{'output_dir'}.'/var/checkresults', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 'max_check_result_file_age' => 3600, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 'cached_host_check_horizon' => 15, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 'cached_service_check_horizon' => 15, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 'enable_predictive_host_dependency_checks' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 'enable_predictive_service_dependency_checks' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 'soft_state_dependencies' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 'auto_reschedule_checks' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 'auto_rescheduling_interval' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 'auto_rescheduling_window' => 180, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 'sleep_time' => 0.25, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 'service_check_timeout' => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 'host_check_timeout' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 'event_handler_timeout' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 'notification_timeout' => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 'ocsp_timeout' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 'perfdata_timeout' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 'retain_state_information' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 'state_retention_file' => $self->{'output_dir'}.'/var/retention.dat', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 'retention_update_interval' => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 'use_retained_program_state' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 'use_retained_scheduling_info' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 'retained_host_attribute_mask' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 'retained_service_attribute_mask' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 'retained_process_host_attribute_mask' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 'retained_process_service_attribute_mask' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 'retained_contact_host_attribute_mask' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 'retained_contact_service_attribute_mask' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 'interval_length' => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 'use_aggressive_host_checking' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 'execute_service_checks' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 'accept_passive_service_checks' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 'execute_host_checks' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 'accept_passive_host_checks' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 'enable_notifications' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 'enable_event_handlers' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 'process_performance_data' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 'obsess_over_services' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 'obsess_over_hosts' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 'translate_passive_host_checks' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 'passive_host_checks_are_soft' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 'check_for_orphaned_services' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 'check_for_orphaned_hosts' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 'check_service_freshness' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 'service_freshness_check_interval' => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 'check_host_freshness' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 'host_freshness_check_interval' => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 'additional_freshness_latency' => 15, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 'enable_flap_detection' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 'low_service_flap_threshold' => 5.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 'high_service_flap_threshold' => 20.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 'low_host_flap_threshold' => 5.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 'high_host_flap_threshold' => 20.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 'date_format' => 'iso8601', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 'p1_file' => $self->{'output_dir'}.'/plugins/p1.pl', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 'enable_embedded_perl' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 'use_embedded_perl_implicitly' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 'illegal_object_name_chars' => '`~!\\$%^&*|\'"<>?,()=', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 'illegal_macro_output_chars' => '`~\\$&|\'"<>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 'use_regexp_matching' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 'use_true_regexp_matching' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 'admin_email' => $self->{'user'}.'@localhost', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 'admin_pager' => $self->{'user'}.'@localhost', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 'daemon_dumps_core' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 'use_large_installation_tweaks' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 'enable_environment_macros' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 'debug_level' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 'debug_verbosity' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 1 | 'debug_file' => $self->{'output_dir'}.'/var/'.$self->{'layout'}.'.debug', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 'max_debug_file_size' => 1000000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 1 | ▶ | $main_cfg->{'use_large_installation_tweaks'} = 1 if ($self->{'hostcount'} * $self->{'services_per_host'} > 2000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 1 | my $merged = $self->_merge_config_hashes($main_cfg, $self->{'main_cfg'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 1 | my $confstring = $self->_config_hash_to_string($merged); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 1 | return($confstring); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 121 | ▶ | sub _merge_config_hashes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_config_hashes: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 121 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 121 | my $conf1 = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 121 | my $conf2 = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 121 | my $merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 121 | for my $key (keys %{$conf1}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 976 | $merged->{$key} = $conf1->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 121 | for my $key (keys %{$conf2}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 4 | $merged->{$key} = $conf2->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 121 | return($merged); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 2 | ▶ | sub _config_hash_to_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_config_hash_to_string: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 2 | my $conf = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 2 | my $confstring; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 2 | for my $key (sort keys %{$conf}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 108 | my $value = $conf->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 108 | ▶ | if(ref($value) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 1 | for my $newval (@{$value}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 3 | $confstring .= $key."=".$newval."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 107 | $confstring .= $key."=".$value."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 2 | return($confstring); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 9 | ▶ | sub _create_object_conf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_object_conf: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 9 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 9 | my $objects = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 9 | my $cfg = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 9 | ▶ | return $cfg unless defined $objects; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 9 | for my $obj (@{$objects}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 170 | $cfg .= 'define '.$type."{\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 170 | for my $key (sort _sort_object_key keys %{$obj}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 1063 | my $value = $obj->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 1063 | $cfg .= ' '.sprintf("%-30s", $key)." ".$value."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 170 | $cfg .= "}\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 9 | return($cfg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 3 | ▶ | sub _fisher_yates_shuffle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fisher_yates_shuffle: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 3 | my $array = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 3 | my $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 3 | ▶ | for ($i = @$array; --$i; ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 116 | my $j = int rand ($i+1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 116 | ▶ | next if $i == $j; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 108 | @$array[$i,$j] = @$array[$j,$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 3 | return($array); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 3 | ▶ | sub _get_types { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_types: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 3 | my $count = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 3 | my $types = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 3 | my $total = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 3 | for my $type (keys %{$types}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 20 | $total += $types->{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 3 | my @types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 3 | for my $type (keys %{$types}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 20 | my $perc = $types->{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 20 | for(1..ceil($count/$total*$perc)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 119 | push @types, $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 3 | ▶ | if(scalar @types < $count) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | warn("got only ".scalar @types." types, expected ".$count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 3 | return(\@types); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 1 | ▶ | sub _get_recreate_pl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_recreate_pl: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 1 | ▶ | my $libs = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 1 | my $pl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 1 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 1 | my $conf = Dumper($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 1 | $conf =~ s/^\$VAR1\ =\ bless\(\ \{//mx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 1 | $conf =~ s/},\ 'Monitoring::Generator::TestConfig'\ \);$//mx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 1 | $pl = <<EOT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | #!$^X | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | $libs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | use Monitoring::Generator::TestConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | my \$ngt = Monitoring::Generator::TestConfig->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | $conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | \$ngt->create(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | EOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 1 | return $pl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 2015 | ▶ | sub _sort_object_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sort_object_key: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 2015 | ▶ | return -7 if $a eq 'dependent_service_description'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 1968 | ▶ | return -6 if $a eq 'dependent_host_name'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 1932 | ▶ | return -5 if $a eq 'name'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 1928 | ▶ | return -4 if $a =~ m/_name$/mx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 1639 | ▶ | return -3 if $a =~ m/_description$/mx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 1381 | ▶ | return -2 if $a eq 'use'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1153 | ▶ | return 7 if $b eq 'dependent_service_description'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 1147 | ▶ | return 6 if $b eq 'dependent_host_name'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 1139 | ▶ | return 5 if $b eq 'name'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 1134 | ▶ | return 4 if $b =~ m/_name$/mx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 1019 | ▶ | return 3 if $b =~ m/_description$/mx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 952 | ▶ | return 2 if $b eq 'use'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 861 | return $a cmp $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 1 | ▶ | sub _get_used_libs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_used_libs: called CC=5 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 1 | my($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 1 | my $libs = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 1 | ▶ | return $libs unless -r $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | ▶ | open(my $fh, '<', $file) or die('cannot read file '.$file.': '.$!); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 0 | ▶ | while(my $line = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | ▶ | next unless $line =~ m/^\s*use\s+lib\s+/gmx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 0 | $libs .= $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | close($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | return $libs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||