| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | package Ym; | ||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Ym; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||
| 10 | sub Lookup; # Function prototype definition for recursion calls. | ||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | # Determine value of definition ($opt) for specified object. | ||||||||||||||||||||||||||||||||||||||||
| 13 | # If there is no clear definition, than we recursively look in templates. | ||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub Lookup { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
Lookup: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my ($tree, $leaf, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $ret = 0; | |||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if (defined($leaf->{$opt})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $ret = $leaf->{$opt}; | |||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||
| 20 | else { | ||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if (defined($leaf->{'use'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $template = $leaf->{'use'}; | |||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if (!defined($tree->{'service_templates'}->{$template})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $template_ref = $tree->{'service_templates'}->{$template}; | |||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $ret = Lookup($tree, $template_ref, $opt); | |||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||
| 33 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||
| 34 | ### O B J E C T D E F I N I T I O N F U N C T I O N S ### | ||||||||||||||||||||||||||||||||||||||||
| 35 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||
| 37 | ### H O S T C O M M A N D S ### | ||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub AddHost { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddHost: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($tree, $object, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $sub_name = 'AddHost'; | |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if (!ref($opts) || ref($opts) ne "HASH") { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $opts or ref $opts ne "HASH"
MC/DC0%0/2
not ref $opts or ref $opts ne "HASH"
not ref $opts
ref $opts ne "HASH"
Truth table0%0/3
not(A) or B
A= not ref $optsB= ref $opts ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | die "$sub_name: third argument must be a hash reference\n"; | |||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $obj_ref = Ym::GetObjectList($object); | |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | foreach my $h (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 54 | 0 | warn "$sub_name: host \"$h\" exists. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | ($verbose) && print "Adding host \"$h\"\n" . Dumper($opts); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | %{$tree->{'hosts'}->{$h}} = %$opts; | |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $href = $tree->{'hosts'}->{$h}; | |||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | foreach my $k (qw/host_name address alias/) { | |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $href->{$k} = $h unless defined($href->{$k}); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | print "$sub_name: added: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub DeleteHost { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeleteHost: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($tree, $object, $group_list) = @_; | |||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $sub_name = 'DeleteHost'; | |||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||
| 77 | my $obj_ref = Ym::GetObjectList($object, $group_list, | ||||||||||||||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||||||||||||||
| 79 | 'obj_branch' => $tree->{'hosts'}, | ||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | 'grp_branch' => $tree->{'hostgroups'}, | |||||||||||||||||||||||||||||||||||||||
| 81 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||
| 85 | # Delete hosts from their hostgroups | ||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $membership = ShowMembership($tree, $obj_ref, "hosts"); | |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my %uniq_groups; | |||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | foreach my $g (@$membership) { | |||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $uniq_groups{$g} = 1; | |||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | foreach my $g (keys %uniq_groups) { | |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | DeleteItem($tree, $tree->{'hostgroups'}->{$g}, $obj_ref, "members"); | |||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | foreach my $h (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$h})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 100 | 0 | warn "$sub_name: host \"$h\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 101 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | ($verbose) && print "Deleting host \"$h\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | delete($tree->{'hosts'}->{$h}); | |||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||
| 109 | # Delete empty hostgroups | ||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | foreach my $hg (@$group_list) { | |||||||||||||||||||||||||||||||||||||||
| 111 | 0 | DeleteHostgroup($tree, [$hg]); | |||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | print "$sub_name: deleted: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub ModifyHost { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
ModifyHost: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($tree, $object, $group_list, $opts, $remove) = @_; | |||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $sub_name = 'ModifyHost'; | |||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (!ref($opts) || ref($opts) ne "HASH") { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $opts or ref $opts ne "HASH"
MC/DC0%0/2
not ref $opts or ref $opts ne "HASH"
not ref $opts
ref $opts ne "HASH"
Truth table0%0/3
not(A) or B
A= not ref $optsB= ref $opts ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | die "$sub_name: fouth argument must be a hash reference\n"; | |||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||
| 128 | my $obj_ref = Ym::GetObjectList($object, $group_list, | ||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||
| 130 | 'obj_branch' => $tree->{'hosts'}, | ||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | 'grp_branch' => $tree->{'hostgroups'}, | |||||||||||||||||||||||||||||||||||||||
| 132 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | foreach my $h (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$h})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | warn "$sub_name: host \"$h\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 140 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | ($verbose) && print "Modifying host \"$h\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | while (my ($k, $v) = each %$opts) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $tree->{'hosts'}->{$h}->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||
| 148 | my $attrs = Ym::GetObjectList($remove, undef, | ||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | 'obj_branch' => $tree->{'hosts'}->{$h}, | |||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | foreach my $k (@$attrs) { | |||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | next if (ref($tree->{'hosts'}->{$h}->{$k})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | delete($tree->{'hosts'}->{$h}->{$k}); | |||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | print "$sub_name: modified: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub CopyHost { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
CopyHost: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my ($tree, $object, $dest) = @_; | |||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $sub_name = 'CopyHost'; | |||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ($object =~ /\/(.*)\//o) { # If item contains regexp | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | die "$sub_name: invalid argument \"$object\". No regexp allowed in this function.\n"; | |||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $clones = Ym::GetObjectList($dest); | |||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$object})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | die "$sub_name: source host \"$object\" is not defined.\n"; | |||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | foreach my $h (@$clones) { | |||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 183 | 0 | warn "$sub_name: host \"$h\" exists. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 184 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | ($verbose) && print "Copying host \"$h\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | %{$tree->{'hosts'}->{$h}} = %{Storable::dclone($tree->{'hosts'}->{$object})}; | |||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $href = $tree->{'hosts'}->{$h}; | |||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | foreach my $k (qw/host_name address alias/) { | |||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $href->{$k} = $h; | |||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | foreach my $srv (keys %{$href->{'services'}}) { | |||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $href->{'services'}->{$srv}->{'host_name'} = $h; | |||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||
| 199 | # Add clone to same hostgroups as a master host | ||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my @mh = ($object); | |||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my @new_m = ($h); | |||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $membership = ShowMembership($tree, \@mh, "hosts"); | |||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | foreach my $g (@$membership) { | |||||||||||||||||||||||||||||||||||||||
| 205 | 0 | AddItem($tree, $tree->{'hostgroups'}->{$g}, \@new_m, "members"); | |||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | print "$sub_name: copied: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||
| 213 | ### S E R V I C E C O M M A N D S ### | ||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub AddService { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddService: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my ($tree, $srv_list, $host_list, $group_list, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $sub_name = 'AddService'; | |||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | $opts = {} unless $opts; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $srv_ref = Ym::GetObjectList($srv_list); | |||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||
| 226 | my $hosts_ref = Ym::GetObjectList($host_list, $group_list, | ||||||||||||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||||||||||||
| 228 | 'obj_branch' => $tree->{'hosts'}, | ||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | 'grp_branch' => $tree->{'hostgroups'}, | |||||||||||||||||||||||||||||||||||||||
| 230 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||
| 232 | ); | ||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | foreach my $h (@$hosts_ref) { | |||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $href = $tree->{'hosts'}->{$h}; | |||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$h})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | warn "$sub_name: host \"$h\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ++$skipped; | |||||||||||||||||||||||||||||||||||||||
| 239 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | foreach my $srv (@$srv_ref) { | |||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ( defined($href->{'services'}) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $href->{"services"} and defined $href->{"services"}{$srv}
MC/DC0%0/2
defined $href->{"services"} and defined $href->{"services"}{$srv}
defined $href->{"services"}
defined $href->{"services"}{$srv}
Truth table0%0/3
A and B
A= defined $href->{"services"}B= defined $href->{"services"}{$srv}
| |||||||||||||||||||||||||||||||||||||||||
| 243 | && defined($href->{'services'}->{$srv})) | ||||||||||||||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 246 | 0 | warn "$sub_name: service \"$srv\" on host \"$h\" exists. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 247 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | ($verbose) && print "Adding service \"$srv\" to host \"$h\"\n" . Dumper($opts); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if (!defined($opts->{'use'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $opts->{'use'} = "default-service"; | |||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | %{$href->{'services'}->{$srv}} = %$opts; | |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $srvref = $href->{'services'}; | |||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $srvref->{$srv}{'host_name'} = $h; | |||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $srvref->{$srv}{'service_description'} = $srv; | |||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $srvref->{$srv}{'contact_groups'} = Lookup($tree, $href, "contact_groups"); | |||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | ($verbose) && print "HOST:$h\n" . Dumper $tree->{'hosts'}->{$h}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | print "$sub_name: added: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub DeleteService { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeleteService: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my ($tree, $srv_list, $host_list, $group_list) = @_; | |||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $sub_name = 'DeleteService'; | |||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||
| 274 | my $hosts_ref = Ym::GetObjectList($host_list, $group_list, | ||||||||||||||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||||||||||||||
| 276 | 'obj_branch' => $tree->{'hosts'}, | ||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | 'grp_branch' => $tree->{'hostgroups'}, | |||||||||||||||||||||||||||||||||||||||
| 278 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||
| 280 | ); | ||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | foreach my $h (@$hosts_ref) { | |||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$h})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 285 | 0 | warn "$sub_name: host \"$h\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 286 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $href = $tree->{'hosts'}->{$h}; | |||||||||||||||||||||||||||||||||||||||
| 289 | my $srv_ref = Ym::GetObjectList($srv_list, undef, | ||||||||||||||||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | 'obj_branch' => $href->{'services'}, | |||||||||||||||||||||||||||||||||||||||
| 292 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||
| 294 | ); | ||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | foreach my $srv (@$srv_ref) { | |||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if (!defined($href->{'services'}->{$srv})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 299 | 0 | warn "$sub_name: service \"$srv\" on host \"$h\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 300 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | ($verbose) && print "Deleting service \"$srv\" oh host \"$h\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | delete($href->{'services'}->{$srv}); | |||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | print "$sub_name: deleted: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub ModifyService { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
ModifyService: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my ($tree, $srv_list, $host_list, $group_list, $opts, $remove) = @_; | |||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $sub_name = 'ModifyService'; | |||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||
| 317 | my $hosts_ref = Ym::GetObjectList($host_list, $group_list, | ||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||
| 319 | 'obj_branch' => $tree->{'hosts'}, | ||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | 'grp_branch' => $tree->{'hostgroups'}, | |||||||||||||||||||||||||||||||||||||||
| 321 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||
| 323 | ); | ||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | foreach my $h (@$hosts_ref) { | |||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$h})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 328 | 0 | warn "$sub_name: host \"$h\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 329 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $href = $tree->{'hosts'}->{$h}; | |||||||||||||||||||||||||||||||||||||||
| 332 | my $srv_ref = Ym::GetObjectList($srv_list, undef, | ||||||||||||||||||||||||||||||||||||||||
| 333 | { | ||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | 'obj_branch' => $href->{'services'}, | |||||||||||||||||||||||||||||||||||||||
| 335 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||
| 337 | ); | ||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | foreach my $srv (@$srv_ref) { | |||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $srvref = $href->{'services'}; | |||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if (!defined($srvref->{$srv})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 344 | 0 | warn "$sub_name: service \"$srv\" on host \"$h\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 345 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | ($verbose) && print "Modifying service \"$srv\" oh host \"$h\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | while (my ($k, $v) = each %$opts) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $srvref->{$srv}->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||
| 352 | my $attrs = Ym::GetObjectList($remove, undef, | ||||||||||||||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | 'obj_branch' => $href->{'services'}->{$srv}, | |||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||
| 356 | ); | ||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | foreach my $k (@$attrs) { | |||||||||||||||||||||||||||||||||||||||
| 359 | 0 | delete($href->{'services'}{$srv}->{$k}); | |||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | print "$sub_name: modified: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub CopyService { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
CopyService: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 369 | # Clone service in terms of one particular host. | ||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my ($tree, $service, $dest, $host) = @_; | |||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $sub_name = 'CopyService'; | |||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||
| 376 | # Verify list. No regexp allowed in this function | ||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ($service =~ /\/(.*)\//o) # If item contains regexp | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | die "$sub_name: invalid argument \"$service\". No regexp allowed in this function.\n"; | |||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | foreach my $obj (@$dest) { | |||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ($obj =~ /\/(.*)\//o && $obj !~ /^READ_FILE/o) # If item contains regexp | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
MC/DC0%0/2
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
$obj =~ m[/(.*)/]o
not $obj =~ /^READ_FILE/o
Truth table0%0/3
A and not(B)
A= $obj =~ m[/(.*)/]oB= not $obj =~ /^READ_FILE/o
| |||||||||||||||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | die "$sub_name: invalid argument \"$obj\". No regexp allowed in this function.\n"; | |||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$host})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | die "$sub_name: source host \"$host\" does not exist.\n"; | |||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if (!defined($tree->{'hosts'}->{$host}->{'services'}->{$service})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | die "$sub_name: service \"$service\" on host \"$host\" does not exist.\n"; | |||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $href = $tree->{'hosts'}->{$host}; | |||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $clones = Ym::GetObjectList($dest); | |||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | foreach my $srv (@$clones) { | |||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | if (defined($href->{'services'}->{$srv})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 402 | 0 | warn "$sub_name: service \"$srv\" on host \"$host\" exists. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 403 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | %{$href->{'services'}->{$srv}} = %{$href->{'services'}->{$service}}; | |||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $href->{'services'}->{$srv}->{'service_description'} = $srv; | |||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | ($verbose) && print "Copying service \"$service\" to \"$srv\" on host \"$host\".\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | print "$sub_name: copied: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||
| 415 | ### C O M M A N D S D E F I N I T I O N F U N C T I O N S ### | ||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub AddCommand { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddCommand: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my ($tree, $object, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $sub_name = 'AddCommand'; | |||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if (!ref($opts) || ref($opts) ne "HASH") { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $opts or ref $opts ne "HASH"
MC/DC0%0/2
not ref $opts or ref $opts ne "HASH"
not ref $opts
ref $opts ne "HASH"
Truth table0%0/3
not(A) or B
A= not ref $optsB= ref $opts ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | die "$sub_name: third argument must be a hash reference\n"; | |||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||
| 426 | # Verify object list. No regexp allowed in this function | ||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | foreach my $obj (@$object) { | |||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if ($obj =~ /\/(.*)\//o && $obj !~ /^READ_FILE/o) # If item contains regexp | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
MC/DC0%0/2
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
$obj =~ m[/(.*)/]o
not $obj =~ /^READ_FILE/o
Truth table0%0/3
A and not(B)
A= $obj =~ m[/(.*)/]oB= not $obj =~ /^READ_FILE/o
| |||||||||||||||||||||||||||||||||||||||||
| 429 | { | ||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | die "$sub_name: invalid argument \"$obj\". No regexp allowed in this function.\n"; | |||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $obj_ref = Ym::GetObjectList($object); | |||||||||||||||||||||||||||||||||||||||
| 435 | 0 | foreach my $cmd (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if (defined($tree->{'commands'}->{$cmd})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 438 | 0 | warn "$sub_name: command \"$cmd\" exists. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 439 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | ($verbose) && print "Adding command \"$cmd\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | %{$tree->{'commands'}->{$cmd}} = %$opts; | |||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $tree->{'commands'}->{$cmd}->{'command_name'} = $cmd; | |||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | print "$sub_name: added: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | sub DeleteCommand { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeleteCommand: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my ($tree, $object) = @_; | |||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $sub_name = 'DeleteCommand'; | |||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||
| 457 | my $obj_ref = Ym::GetObjectList($object, undef, | ||||||||||||||||||||||||||||||||||||||||
| 458 | { | ||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | 'obj_branch' => $tree->{'commands'}, | |||||||||||||||||||||||||||||||||||||||
| 460 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||
| 462 | ); | ||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | foreach my $cmd (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | if (!defined($tree->{'commands'}->{$cmd})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 467 | 0 | warn "$sub_name: command \"$cmd\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 468 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | ($verbose) && print "Deleting command \"$cmd\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | delete($tree->{'commands'}->{$cmd}); | |||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | print "$sub_name: deleted: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | sub ModifyCommand { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
ModifyCommand: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | my ($tree, $object, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 482 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my $sub_name = 'ModifyCommand'; | |||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if (!ref($opts) || ref($opts) ne "HASH") { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $opts or ref $opts ne "HASH"
MC/DC0%0/2
not ref $opts or ref $opts ne "HASH"
not ref $opts
ref $opts ne "HASH"
Truth table0%0/3
not(A) or B
A= not ref $optsB= ref $opts ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | die "$sub_name: third argument must be a hash reference\n"; | |||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||
| 489 | my $obj_ref = Ym::GetObjectList($object, undef, | ||||||||||||||||||||||||||||||||||||||||
| 490 | { | ||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | 'obj_branch' => $tree->{'commands'}, | |||||||||||||||||||||||||||||||||||||||
| 492 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||
| 494 | ); | ||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | foreach my $cmd (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if (!defined($tree->{'commands'}->{$cmd})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 499 | 0 | warn "$sub_name: command \"$cmd\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 500 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | ($verbose) && print "Modifying command \"$cmd\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | while (my ($k, $v) = each %$opts) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $tree->{'commands'}->{$cmd}->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | print "$sub_name: modified: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||
| 513 | ### H O S T G R O U P S D E F I N I T I O N F U N C T I O N S ### | ||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | sub AddHostgroup { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddHostgroup: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | my ($tree, $object, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 516 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my $sub_name = 'AddHostgroup'; | |||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | $opts = {} unless $opts; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | if (!ref($opts) || ref($opts) ne "HASH") { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $opts or ref $opts ne "HASH"
MC/DC0%0/2
not ref $opts or ref $opts ne "HASH"
not ref $opts
ref $opts ne "HASH"
Truth table0%0/3
not(A) or B
A= not ref $optsB= ref $opts ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | die "$sub_name: third argument must be a hash reference\n"; | |||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||
| 526 | # Verify object list. No regexp allowed in this function | ||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | foreach my $obj (@$object) { | |||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | if ($obj =~ /\/(.*)\//o && $obj !~ /^READ_FILE/o) # If item contains regexp | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
MC/DC0%0/2
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
$obj =~ m[/(.*)/]o
not $obj =~ /^READ_FILE/o
Truth table0%0/3
A and not(B)
A= $obj =~ m[/(.*)/]oB= not $obj =~ /^READ_FILE/o
| |||||||||||||||||||||||||||||||||||||||||
| 529 | { | ||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | die "$sub_name: invalid argument \"$obj\". No regexp allowed in this function.\n"; | |||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my $obj_ref = Ym::GetObjectList($object); | |||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | foreach my $hg (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if (defined($tree->{'hostgroups'}->{$hg})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 539 | 0 | warn "$sub_name: hostgroup \"$hg\" exists. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 540 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | ($verbose) && print "Adding hostgroup \"$hg\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | %{$tree->{'hostgroups'}->{$hg}} = %$opts; | |||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | $tree->{'hostgroups'}->{$hg}->{'hostgroup_name'} = $hg; | |||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | unless(defined($tree->{'hostgroups'}->{$hg}->{'alias'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $tree->{'hostgroups'}->{$hg}->{'alias'} = $hg; | |||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ++$processed; | |||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | print "$sub_name: added: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | sub DeleteHostgroup { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeleteHostgroup: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | my ($tree, $object) = @_; | |||||||||||||||||||||||||||||||||||||||
| 559 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my $sub_name = 'DeleteHostgroup'; | |||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||
| 563 | my $obj_ref = Ym::GetObjectList($object, undef, | ||||||||||||||||||||||||||||||||||||||||
| 564 | { | ||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | 'obj_branch' => $tree->{'hostgroups'}, | |||||||||||||||||||||||||||||||||||||||
| 566 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||
| 568 | ); | ||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | foreach my $hg (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if (!defined($tree->{'hostgroups'}->{$hg})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 573 | 0 | warn "$sub_name: hostgroup \"$hg\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 574 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | ($verbose) && print "Deleting hostgroup \"$hg\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | delete($tree->{'hostgroups'}->{$hg}); | |||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | print "$sub_name: deleted: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | sub ModifyHostgroup { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
ModifyHostgroup: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my ($tree, $object, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 587 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 589 | 0 | my $sub_name = 'ModifyHostgroup'; | |||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | $opts = {} unless $opts; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||
| 593 | my $obj_ref = Ym::GetObjectList($object, undef, | ||||||||||||||||||||||||||||||||||||||||
| 594 | { | ||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | 'obj_branch' => $tree->{'hostgroups'}, | |||||||||||||||||||||||||||||||||||||||
| 596 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||
| 598 | ); | ||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | foreach my $hg (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if (!defined($tree->{'hostgroups'}->{$hg})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 603 | 0 | warn "$sub_name: hostgroup \"$hg\" does not exist. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 604 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | ($verbose) && print "Modifying hostgroup \"$hg\"\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | while (my ($k, $v) = each %$opts) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | $tree->{'hostgroups'}->{$hg}->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | Ym::TouchTree($tree) if ($processed > 0); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | print "$sub_name: modified: $processed; skipped: $skipped\n"; | |||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | sub ShowMembers { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowMembers: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | my ($tree, $object, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||
| 619 | 0 | my %members = (); | |||||||||||||||||||||||||||||||||||||||
| 620 | 0 | my $sub_name = 'ShowMembers'; | |||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | $opts = {} unless $opts; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if(!defined($opts->{'type'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | die "$sub_name: Programmer error - 'type' option is not specified.\n"; | |||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | if($opts->{'type'} !~ /^(hostgroups|contactgroups)$/o) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | die "$sub_name: Programmer error - unknown 'type' option value.\n"; | |||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | my $t = $opts->{'type'}; | |||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||
| 634 | my $obj_ref = Ym::GetObjectList($object, undef, | ||||||||||||||||||||||||||||||||||||||||
| 635 | { | ||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | 'obj_branch' => $tree->{$t}, | |||||||||||||||||||||||||||||||||||||||
| 637 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||
| 639 | ); | ||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | foreach my $o (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | next unless (defined($tree->{$t}->{$o})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | next unless (defined($tree->{$t}->{$o}->{'members'})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | my $hg_ref = $tree->{$t}->{$o}; | |||||||||||||||||||||||||||||||||||||||
| 646 | 0 | my $split_pattern = '[,:;\s]+'; | |||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | foreach my $m (split(/$split_pattern/o, $hg_ref->{'members'})) { | |||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $members{$m} = 1; | |||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | foreach my $m (sort keys %members) { | |||||||||||||||||||||||||||||||||||||||
| 654 | 0 | print "$m\n"; | |||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||
| 658 | ### G E N E R A L C O M M A N D S ### | ||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | ▶ | sub AddItem { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddItem: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 660 | # Like add some member(s) to contactgroup, or add member(s) to hostgroup | ||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | my ($tree, $dest, $object, $attr) = @_; | |||||||||||||||||||||||||||||||||||||||
| 663 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 664 | 0 | my $sub_name = 'AddItem'; | |||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | ▶ | if (!defined($dest->{$attr})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | die "$sub_name: attribute $attr is not defined for given object.\n"; | |||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||
| 670 | # Verify object list. No regexp allowed in this function | ||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | foreach my $obj (@$object) { | |||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | if ($obj =~ /\/(.*)\//o && $obj !~ /^READ_FILE/o) # If item contains regexp | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
MC/DC0%0/2
$obj =~ m[/(.*)/]o and not $obj =~ /^READ_FILE/o
$obj =~ m[/(.*)/]o
not $obj =~ /^READ_FILE/o
Truth table0%0/3
A and not(B)
A= $obj =~ m[/(.*)/]oB= not $obj =~ /^READ_FILE/o
| |||||||||||||||||||||||||||||||||||||||||
| 673 | { | ||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | die "$sub_name: invalid argument \"$obj\". No regexp allowed in this function.\n"; | |||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | my $obj_ref = Ym::GetObjectList($object); | |||||||||||||||||||||||||||||||||||||||
| 678 | 0 | push @$obj_ref, (split ",", $dest->{$attr}); | |||||||||||||||||||||||||||||||||||||||
| 679 | 0 | my %items; # key - item name; value - fake value | |||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | foreach my $o (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $items{$o} = 1; | |||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | $dest->{$attr} = join ",", (sort keys %items); | |||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | Ym::TouchTree($tree); | |||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | sub DeleteItem { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeleteItem: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 690 | # Like delete some member(s) from contactgroup, or from member(s) from hostgroup | ||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | my ($tree, $dest, $object, $attr) = @_; | |||||||||||||||||||||||||||||||||||||||
| 693 | 0 | my $verbose = $Ym::VERBOSE; | |||||||||||||||||||||||||||||||||||||||
| 694 | 0 | my $sub_name = 'DeleteItem'; | |||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | if (!defined($dest) || !ref($dest)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $dest and ref $dest
MC/DC0%0/2
defined $dest and ref $dest
defined $dest
ref $dest
Truth table0%0/3
A and B
A= defined $destB= ref $dest
| |||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | die "$sub_name: first argument must be defined reference to data structure.\n"; | |||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | if (!defined($dest->{$attr})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | die "$sub_name: attribute $attr is not defined for given object.\n"; | |||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||
| 703 | my $obj_ref = Ym::GetObjectList($object, undef, | ||||||||||||||||||||||||||||||||||||||||
| 704 | { | ||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | 'obj_branch' => $dest->{$attr}, | |||||||||||||||||||||||||||||||||||||||
| 706 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||
| 708 | ); | ||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | my %items; # key - item name; value - fake value | |||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | foreach my $o (split ",", $dest->{$attr}) { | |||||||||||||||||||||||||||||||||||||||
| 712 | 0 | $items{$o} = 1; | |||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | foreach my $d (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | if (defined($items{$d})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | delete($items{$d}); | |||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | $dest->{$attr} = join ",", (sort keys %items); | |||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | Ym::TouchTree($tree); | |||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | sub List { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
List: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | my ($branch, $object) = @_; | |||||||||||||||||||||||||||||||||||||||
| 726 | 0 | my $sub_name = 'List'; | |||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | if (!defined($branch) || !ref($branch)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $branch and ref $branch
MC/DC0%0/2
defined $branch and ref $branch
defined $branch
ref $branch
Truth table0%0/3
A and B
A= defined $branchB= ref $branch
| |||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | die "$sub_name: first argument must be defined reference to data structure.\n"; | |||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | my $obj_ref = Ym::GetObjectList($object, undef, | |||||||||||||||||||||||||||||||||||||||
| 733 | { | ||||||||||||||||||||||||||||||||||||||||
| 734 | 'obj_branch' => $branch, | ||||||||||||||||||||||||||||||||||||||||
| 735 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||
| 737 | ); | ||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | foreach my $obj (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | next unless defined($branch->{$obj}); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | print "$obj\n"; | |||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | sub Dump { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
Dump: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | my ($branch, $object) = @_; | |||||||||||||||||||||||||||||||||||||||
| 747 | 0 | my $sub_name = 'Dump'; | |||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | if (!defined($branch) || !ref($branch)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $branch and ref $branch
MC/DC0%0/2
defined $branch and ref $branch
defined $branch
ref $branch
Truth table0%0/3
A and B
A= defined $branchB= ref $branch
| |||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | die "$sub_name: first argument must be defined reference to data structure.\n"; | |||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | my $obj_ref = Ym::GetObjectList($object, undef, | |||||||||||||||||||||||||||||||||||||||
| 754 | { | ||||||||||||||||||||||||||||||||||||||||
| 755 | 'obj_branch' => $branch, | ||||||||||||||||||||||||||||||||||||||||
| 756 | 'allow_regex_in_obj' => 1, | ||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||
| 758 | ); | ||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | foreach my $obj (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | next unless defined($branch->{$obj}); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | print "$obj " . Dumper($branch->{$obj}); | |||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | sub ShowMembership { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowMembership: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | my ($tree, $object, $type) = @_; | |||||||||||||||||||||||||||||||||||||||
| 768 | 0 | my ($processed, $skipped) = (0, 0); | |||||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $sub_name = 'ShowMembership'; | |||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | if ($type ne "hosts" && $type ne "contacts") { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type ne "hosts" and $type ne "contacts"
MC/DC0%0/2
$type ne "hosts" and $type ne "contacts"
$type ne "hosts"
$type ne "contacts"
Truth table0%0/3
A and B
A= $type ne "hosts"B= $type ne "contacts"
| |||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | die "$sub_name: don't know how to process type \"$type\"\n"; | |||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | my $obj_ref = Ym::GetObjectList($object); | |||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my %groups; # key - contact or hostgroup names; | |||||||||||||||||||||||||||||||||||||||
| 777 | # value - hash (key - contact or host name; | ||||||||||||||||||||||||||||||||||||||||
| 778 | # value = 1 fake value. group members) | ||||||||||||||||||||||||||||||||||||||||
| 779 | my $ref; | ||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | if ($type eq "hosts") { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | $ref = $tree->{'hostgroups'}; | |||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||
| 784 | elsif ($type eq "contacts") { | ||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | $ref = $tree->{'contactgroups'}; | |||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | foreach my $g (keys %$ref) { | |||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | next unless defined($ref->{$g}->{'members'}); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | foreach my $member (split ",", $ref->{$g}->{'members'}) { | |||||||||||||||||||||||||||||||||||||||
| 791 | 0 | $groups{$g}->{$member} = 1; | |||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | my @membership; | |||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | foreach my $obj (@$obj_ref) { | |||||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | if (!defined($tree->{$type}->{$obj})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | $skipped++; | |||||||||||||||||||||||||||||||||||||||
| 799 | 0 | warn "$sub_name: object \"$obj\" is not defined in $type. Skipping.\n"; | |||||||||||||||||||||||||||||||||||||||
| 800 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | foreach my $g (keys %groups) { | |||||||||||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | if (defined($groups{$g}->{$obj})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | push @membership, $g; | |||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | return \@membership; | |||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||
| 812 | sub Lookup_deep; # Function prototype definition for recursion calls. | ||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||
| 814 | # Determine value of definition ($opt) for specified object. | ||||||||||||||||||||||||||||||||||||||||
| 815 | # If there is no clear definition, than we recursively look in templates. | ||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | sub Lookup_deep { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
Lookup_deep: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | my ($branch, $leaf, $opts, $key) = @_; | |||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||
| 819 | my $res2; | ||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | foreach my $opt (@$opts) { | |||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | if (defined($leaf->{$opt})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | $res->{$opt}->{$leaf->{$opt}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | if (defined($leaf->{$key})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | my $include = $leaf->{$key}; | |||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | if (defined($branch->{$include})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | my $include_ref = $branch->{$include}; | |||||||||||||||||||||||||||||||||||||||
| 830 | 0 | $res2 = Lookup_deep($branch, $include_ref, $opts, $key); | |||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | ▶ | if (defined($res2)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | foreach my $o (@$opts) { | |||||||||||||||||||||||||||||||||||||||
| 835 | 0 | ▶ | next unless (defined($res2->{$o})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | foreach (keys %{$res2->{$o}}) { | |||||||||||||||||||||||||||||||||||||||
| 837 | 0 | $res->{$o}->{$_} = 1; | |||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | ▶ | sub Cleanup { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
Cleanup: not called CC=100 SCAR=92.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | my ($tree, $params) = @_; | |||||||||||||||||||||||||||||||||||||||
| 846 | 0 | my $sub_name = 'Cleanup'; | |||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | ▶ | my $ask = $params->{'ask'} if defined $params->{'ask'}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | ▶ | my $diff = $params->{'diff'} if defined $params->{'diff'}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | my $dump = $params->{'dump'} if defined $params->{'dump'}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | my $type = $params->{'type'} if defined $params->{'type'}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||
| 853 | # Store used objects | ||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | my %used_host_templates = (); | |||||||||||||||||||||||||||||||||||||||
| 855 | 0 | my %used_service_templates = (); | |||||||||||||||||||||||||||||||||||||||
| 856 | 0 | my %used_contactgroups = (); | |||||||||||||||||||||||||||||||||||||||
| 857 | 0 | my %used_contacts = (); | |||||||||||||||||||||||||||||||||||||||
| 858 | 0 | my %used_contact_templates = (); | |||||||||||||||||||||||||||||||||||||||
| 859 | 0 | my %used_commands = (); | |||||||||||||||||||||||||||||||||||||||
| 860 | 0 | my %used_timeperiods = (); | |||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | my %used_obj = ( | |||||||||||||||||||||||||||||||||||||||
| 863 | 'host_templates' => \%used_host_templates, | ||||||||||||||||||||||||||||||||||||||||
| 864 | 'service_templates' => \%used_service_templates, | ||||||||||||||||||||||||||||||||||||||||
| 865 | 'contactgroups' => \%used_contactgroups, | ||||||||||||||||||||||||||||||||||||||||
| 866 | 'contacts' => \%used_contacts, | ||||||||||||||||||||||||||||||||||||||||
| 867 | 'contact_templates' => \%used_contact_templates, | ||||||||||||||||||||||||||||||||||||||||
| 868 | 'commands' => \%used_commands, | ||||||||||||||||||||||||||||||||||||||||
| 869 | 'timeperiods' => \%used_timeperiods, | ||||||||||||||||||||||||||||||||||||||||
| 870 | ); | ||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | ▶ | unless ($type =~ /^(host_templates|service_templates|contacts|contact_templates|timeperiods)$/o) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 874 | { | ||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | die "$sub_name: wrong type of object in '--type' directive.\n"; | |||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||
| 879 | # Walk through all hosts, find all usable host_templates, contactgroups, contacts, | ||||||||||||||||||||||||||||||||||||||||
| 880 | # commands, timeperiods. Mark all of them as 'used'. | ||||||||||||||||||||||||||||||||||||||||
| 881 | 0 | foreach my $h (keys %{$tree->{'hosts'}}) { | |||||||||||||||||||||||||||||||||||||||
| 882 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h}->{'use'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | $used_host_templates{$tree->{'hosts'}->{$h}->{'use'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h}->{'contact_groups'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | foreach my $cg (split(',', $tree->{'hosts'}->{$h}->{'contact_groups'})) { | |||||||||||||||||||||||||||||||||||||||
| 887 | 0 | $used_contactgroups{$cg} = 1; | |||||||||||||||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h}->{'contacts'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | foreach my $c (split(',', $tree->{'hosts'}->{$h}->{'contacts'})) # Might be several contacts | |||||||||||||||||||||||||||||||||||||||
| 892 | { | ||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | $used_contacts{$c} = 1; | |||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h}->{'check_command'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 897 | my @cmd_args = | ||||||||||||||||||||||||||||||||||||||||
| 898 | 0 | split('!', $tree->{'hosts'}->{$h}->{'check_command'}); # Might be a command with args | |||||||||||||||||||||||||||||||||||||||
| 899 | 0 | $used_commands{$cmd_args[0]} = 1; | |||||||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h}->{'event_handler'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 902 | 0 | $used_commands{$tree->{'hosts'}->{$h}->{'event_handler'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 903 | } | ||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h}->{'check_period'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | $used_timeperiods{$tree->{'hosts'}->{$h}->{'check_period'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | ▶ | if (defined($tree->{'hosts'}->{$h}->{'notification_period'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | $used_timeperiods{$tree->{'hosts'}->{$h}->{'notification_period'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||
| 911 | # Now do all the same things with host's services | ||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | foreach my $s (keys %{$tree->{'hosts'}->{$h}->{'services'}}) { | |||||||||||||||||||||||||||||||||||||||
| 913 | 0 | my $srv = $tree->{'hosts'}->{$h}->{'services'}->{$s}; | |||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | ▶ | if (defined($srv->{'use'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | $used_service_templates{$srv->{'use'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | ▶ | if (defined($srv->{'contact_groups'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | foreach my $c (split(',', $srv->{'contact_groups'})) # For multiple contactgroups | |||||||||||||||||||||||||||||||||||||||
| 920 | { | ||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | $used_contactgroups{$c} = 1; | |||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | ▶ | if (defined($srv->{'contacts'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | foreach my $c (split(',', $srv->{'contacts'})) # For multiple contacts | |||||||||||||||||||||||||||||||||||||||
| 926 | { | ||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | $used_contacts{$c} = 1; | |||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||
| 929 | } | ||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | if (defined($srv->{'check_command'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | my @cmd_args = split('!', $srv->{'check_command'}); # Might be a command with args | |||||||||||||||||||||||||||||||||||||||
| 932 | 0 | $used_commands{$cmd_args[0]} = 1; | |||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | ▶ | if (defined($srv->{'event_handler'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | $used_commands{$srv->{'event_handler'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | ▶ | if (defined($srv->{'check_period'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | $used_timeperiods{$srv->{'check_period'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | ▶ | if (defined($srv->{'notification_period'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 941 | 0 | $used_timeperiods{$srv->{'notification_period'}} = 1; | |||||||||||||||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||
| 946 | # Recursively look through host templates to find various objects | ||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | foreach my $t (keys %used_host_templates) { | |||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||
| 949 | # What fields to find in templates | ||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | my @opts = | |||||||||||||||||||||||||||||||||||||||
| 951 | qw/use contact_groups contacts check_command event_handler check_period notification_period/; | ||||||||||||||||||||||||||||||||||||||||
| 952 | my $res = | ||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | Lookup_deep($tree->{'host_templates'}, $tree->{'host_templates'}->{$t}, \@opts, 'use'); | |||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||
| 955 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||
| 956 | 0 | ▶ | next unless (defined($res->{$opt})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 957 | 0 | foreach my $k (keys %{$res->{$opt}}) { | |||||||||||||||||||||||||||||||||||||||
| 958 | 0 | ▶ | if ($opt eq 'contacts') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | foreach my $c (split(',', $res->{$opt}->{$k})) { | |||||||||||||||||||||||||||||||||||||||
| 960 | 0 | $used_obj{'contacts'}->{$c} = 1; | |||||||||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||
| 963 | elsif ($opt eq 'contact_groups') { | ||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | foreach my $cg (split(',', $res->{$opt}->{$k})) { | |||||||||||||||||||||||||||||||||||||||
| 965 | 0 | $used_obj{'contactgroups'}->{$cg} = 1; | |||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||
| 967 | } | ||||||||||||||||||||||||||||||||||||||||
| 968 | elsif ($opt eq 'use') { | ||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | $used_obj{'host_templates'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||||||||||||||
| 971 | ▶ | elsif ($opt eq 'check_command' || $opt eq 'event_handler') { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt eq "check_command" or $opt eq "event_handler"
MC/DC0%0/2
$opt eq "check_command" or $opt eq "event_handler"
$opt eq "check_command"
$opt eq "event_handler"
Truth table0%0/3
A or B
A= $opt eq "check_command"B= $opt eq "event_handler"
| |||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | $used_obj{'commands'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||
| 974 | ▶ | elsif ($opt eq 'check_period' || $opt eq 'notification_period') { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt eq "check_period" or $opt eq "notification_period"
MC/DC0%0/2
$opt eq "check_period" or $opt eq "notification_period"
$opt eq "check_period"
$opt eq "notification_period"
Truth table0%0/3
A or B
A= $opt eq "check_period"B= $opt eq "notification_period"
| |||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | $used_obj{'timeperiods'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 976 | } | ||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||
| 981 | # Recursively look through service templates to find various objects | ||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | foreach my $t (keys %used_service_templates) { | |||||||||||||||||||||||||||||||||||||||
| 983 | 0 | my @opts = | |||||||||||||||||||||||||||||||||||||||
| 984 | qw/use contact_groups contacts check_command event_handler check_period notification_period/; | ||||||||||||||||||||||||||||||||||||||||
| 985 | my $res = | ||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | Lookup_deep($tree->{'service_templates'}, $tree->{'service_templates'}->{$t}, \@opts, 'use'); | |||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||
| 989 | 0 | ▶ | next unless (defined($res->{$opt})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | foreach my $k (keys %{$res->{$opt}}) { | |||||||||||||||||||||||||||||||||||||||
| 991 | 0 | ▶ | if ($opt eq 'contacts') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | foreach my $c (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 993 | 0 | $used_obj{$opt}->{$c} = 1; | |||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||
| 996 | elsif ($opt eq 'contact_groups') { | ||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | foreach my $cg (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 998 | 0 | $used_obj{'contactgroups'}->{$cg} = 1; | |||||||||||||||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||
| 1001 | elsif ($opt eq 'use') { | ||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | $used_obj{'service_templates'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||
| 1004 | ▶ | elsif ($opt eq 'check_command' || $opt eq 'event_handler') { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt eq "check_command" or $opt eq "event_handler"
MC/DC0%0/2
$opt eq "check_command" or $opt eq "event_handler"
$opt eq "check_command"
$opt eq "event_handler"
Truth table0%0/3
A or B
A= $opt eq "check_command"B= $opt eq "event_handler"
| |||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | my @cmd_args = (split('!', $k)); | |||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | $used_obj{'commands'}->{$cmd_args[0]} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||||||||||||||
| 1008 | ▶ | elsif ($opt eq 'check_period' || $opt eq 'notification_period') { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt eq "check_period" or $opt eq "notification_period"
MC/DC0%0/2
$opt eq "check_period" or $opt eq "notification_period"
$opt eq "check_period"
$opt eq "notification_period"
Truth table0%0/3
A or B
A= $opt eq "check_period"B= $opt eq "notification_period"
| |||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | $used_obj{'timeperiods'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1010 | } | ||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||
| 1015 | # Recursively look through contactgroups to find various objects | ||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | foreach my $t (keys %used_contactgroups) { | |||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | my @opts = qw/members contactgroup_members/; | |||||||||||||||||||||||||||||||||||||||
| 1018 | my $res = Lookup_deep( | ||||||||||||||||||||||||||||||||||||||||
| 1019 | $tree->{'contactgroups'}, | ||||||||||||||||||||||||||||||||||||||||
| 1020 | 0 | $tree->{'contactgroups'}->{$t}, | |||||||||||||||||||||||||||||||||||||||
| 1021 | \@opts, 'contactgroup_members' | ||||||||||||||||||||||||||||||||||||||||
| 1022 | ); | ||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | ▶ | next unless (defined($res->{$opt})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | foreach my $k (keys %{$res->{$opt}}) { | |||||||||||||||||||||||||||||||||||||||
| 1027 | 0 | ▶ | if ($opt eq 'members') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 1028 | 0 | foreach my $c (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 1029 | 0 | $used_obj{'contacts'}->{$c} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||||||||||||||
| 1031 | } | ||||||||||||||||||||||||||||||||||||||||
| 1032 | elsif ($opt eq 'contactgroup_members') { | ||||||||||||||||||||||||||||||||||||||||
| 1033 | 0 | foreach my $cg (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | $used_obj{'contactgroups'}->{$cg} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1035 | } | ||||||||||||||||||||||||||||||||||||||||
| 1036 | } | ||||||||||||||||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||||||||||||||
| 1038 | } | ||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||
| 1041 | # Recursively look through contacts to find various objects | ||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | foreach my $t (keys %used_contacts) { | |||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my @opts = qw/ | |||||||||||||||||||||||||||||||||||||||
| 1044 | contactgroups use | ||||||||||||||||||||||||||||||||||||||||
| 1045 | host_notification_commands service_notification_commands | ||||||||||||||||||||||||||||||||||||||||
| 1046 | host_notification_period service_notification_period | ||||||||||||||||||||||||||||||||||||||||
| 1047 | /; | ||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | my $res = Lookup_deep($tree->{'contacts'}, $tree->{'contacts'}->{$t}, \@opts, 'use'); | |||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | ▶ | next unless (defined($res->{$opt})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | foreach my $k (keys %{$res->{$opt}}) { | |||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | ▶ | if ($opt eq 'host_notification_commands' || $opt eq 'service_notification_commands') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$opt eq "host_notification_commands" or $opt eq "service_notification_commands"
MC/DC0%0/2
$opt eq "host_notification_commands" or $opt eq "service_notification_commands"
$opt eq "host_notification_commands"
$opt eq "service_notification_commands"
Truth table0%0/3
A or B
A= $opt eq "host_notification_commands"B= $opt eq "service_notification_commands"
| |||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | foreach my $c (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | $used_obj{'commands'}->{$c} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||
| 1058 | elsif ($opt eq 'contactgroups') { | ||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | foreach my $cg (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | $used_obj{'contactgroups'}->{$cg} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||
| 1063 | elsif ($opt eq 'use') { | ||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | $used_obj{'contact_templates'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||
| 1066 | ▶ | elsif ($opt eq 'host_notification_period' || $opt eq 'service_notification_period') { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt eq "host_notification_period" or $opt eq "service_notification_period"
MC/DC0%0/2
$opt eq "host_notification_period" or $opt eq "service_notification_period"
$opt eq "host_notification_period"
$opt eq "service_notification_period"
Truth table0%0/3
A or B
A= $opt eq "host_notification_period"B= $opt eq "service_notification_period"
| |||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | $used_obj{'timeperiods'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||
| 1070 | } | ||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||
| 1073 | # Recursively look through contact_templates to find various objects | ||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | foreach my $t (keys %used_contact_templates) { | |||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | my @opts = qw/ | |||||||||||||||||||||||||||||||||||||||
| 1076 | contactgroups use | ||||||||||||||||||||||||||||||||||||||||
| 1077 | host_notification_commands service_notification_commands | ||||||||||||||||||||||||||||||||||||||||
| 1078 | host_notification_period service_notification_period | ||||||||||||||||||||||||||||||||||||||||
| 1079 | /; | ||||||||||||||||||||||||||||||||||||||||
| 1080 | my $res = | ||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | Lookup_deep($tree->{'contact_templates'}, $tree->{'contact_templates'}->{$t}, \@opts, 'use'); | |||||||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | ▶ | next unless (defined($res->{$opt})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1085 | 0 | foreach my $k (keys %{$res->{$opt}}) { | |||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | ▶ | if ($opt eq 'host_notification_commands' || $opt eq 'service_notification_commands') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$opt eq "host_notification_commands" or $opt eq "service_notification_commands"
MC/DC0%0/2
$opt eq "host_notification_commands" or $opt eq "service_notification_commands"
$opt eq "host_notification_commands"
$opt eq "service_notification_commands"
Truth table0%0/3
A or B
A= $opt eq "host_notification_commands"B= $opt eq "service_notification_commands"
| |||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | foreach my $c (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 1088 | 0 | my @cmd_args = split('!', $c); | |||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | $used_obj{'commands'}->{$cmd_args[0]} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1090 | } | ||||||||||||||||||||||||||||||||||||||||
| 1091 | } | ||||||||||||||||||||||||||||||||||||||||
| 1092 | elsif ($opt eq 'contactgroups') { | ||||||||||||||||||||||||||||||||||||||||
| 1093 | 0 | foreach my $cg (split(',', $k)) { | |||||||||||||||||||||||||||||||||||||||
| 1094 | 0 | $used_obj{'contactgroups'}->{$cg} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1095 | } | ||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||
| 1097 | elsif ($opt eq 'use') { | ||||||||||||||||||||||||||||||||||||||||
| 1098 | 0 | $used_obj{'contact_templates'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||||||||||||||
| 1100 | ▶ | elsif ($opt eq 'host_notification_period' || $opt eq 'service_notification_period') { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt eq "host_notification_period" or $opt eq "service_notification_period"
MC/DC0%0/2
$opt eq "host_notification_period" or $opt eq "service_notification_period"
$opt eq "host_notification_period"
$opt eq "service_notification_period"
Truth table0%0/3
A or B
A= $opt eq "host_notification_period"B= $opt eq "service_notification_period"
| |||||||||||||||||||||||||||||||||||||||||
| 1101 | 0 | $used_obj{'timeperiods'}->{$k} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||||||||||||||||||||||
| 1103 | } | ||||||||||||||||||||||||||||||||||||||||
| 1104 | } | ||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||
| 1107 | # Find some usable commands in Nagios main config | ||||||||||||||||||||||||||||||||||||||||
| 1108 | 0 | foreach my $opt ( | |||||||||||||||||||||||||||||||||||||||
| 1109 | qw/ | ||||||||||||||||||||||||||||||||||||||||
| 1110 | global_host_event_handler global_service_event_handler | ||||||||||||||||||||||||||||||||||||||||
| 1111 | ocsp_command ochp_command | ||||||||||||||||||||||||||||||||||||||||
| 1112 | host_perfdata_command service_perfdata_command | ||||||||||||||||||||||||||||||||||||||||
| 1113 | host_perfdata_file_processing_command service_perfdata_file_processing_command/ | ||||||||||||||||||||||||||||||||||||||||
| 1114 | ) | ||||||||||||||||||||||||||||||||||||||||
| 1115 | { | ||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | ▶ | next unless (defined($tree->{'config'}->{$opt})); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1117 | 0 | my @cmd_args = split('!', $tree->{'config'}->{$opt}); | |||||||||||||||||||||||||||||||||||||||
| 1118 | 0 | $used_obj{'commands'}->{$cmd_args[0]} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||
| 1121 | # Also we need to check host/service escalations and dependencies, | ||||||||||||||||||||||||||||||||||||||||
| 1122 | # but I know that we do not use escalations at all and timeperiods in dependencies. | ||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||
| 1124 | # After all we've got actual list of object definitions. | ||||||||||||||||||||||||||||||||||||||||
| 1125 | # Now check all defined objects and verify their presence in %used_obj | ||||||||||||||||||||||||||||||||||||||||
| 1126 | # Make list of candidates to delete. | ||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | my $unused; | |||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | foreach my $k (keys %used_obj) { | |||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | foreach my $obj (keys %{$tree->{$k}}) { | |||||||||||||||||||||||||||||||||||||||
| 1131 | 0 | ▶ | unless (defined($used_obj{$k}->{$obj})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | $unused->{$k}->{$obj} = 1; | |||||||||||||||||||||||||||||||||||||||
| 1133 | } | ||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||
| 1137 | # Remove unused objects | ||||||||||||||||||||||||||||||||||||||||
| 1138 | 0 | foreach my $k (keys %$unused) { | |||||||||||||||||||||||||||||||||||||||
| 1139 | 0 | ▶ | next if ($type && $k ne $type); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type and $k ne $type
MC/DC0%0/2
$type and $k ne $type
$type
$k ne $type
Truth table0%0/3
A and B
A= $typeB= $k ne $type
| |||||||||||||||||||||||||||||||||||||||||
| 1140 | 0 | ▶ | ($diff) && print "Removing unused $k\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1141 | 0 | foreach my $obj (keys %{$unused->{$k}}) { | |||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | ▶ | ($dump) && print Dumper $tree->{$k}->{$obj}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1143 | 0 | ▶ | if ($ask) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1144 | 0 | print "Going to remove {$k}->{$obj}. Remove? y/n: "; | |||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | chomp(my $ans = <STDIN>); | |||||||||||||||||||||||||||||||||||||||
| 1146 | 0 | ▶ | until ($ans =~ /[yn]/io) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | print "Going to remove {$k}->{$obj}. Remove? y/n: "; | |||||||||||||||||||||||||||||||||||||||
| 1148 | 0 | chomp($ans = <STDIN>); | |||||||||||||||||||||||||||||||||||||||
| 1149 | } | ||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | ▶ | next if ($ans eq 'n'); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1151 | } | ||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | ▶ | ($diff) && print "Removing {$k}->{$obj}\n\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 1153 | 0 | delete($tree->{$k}->{$obj}); | |||||||||||||||||||||||||||||||||||||||
| 1154 | } | ||||||||||||||||||||||||||||||||||||||||
| 1155 | } | ||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||
| 1158 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||