blib/lib/Zabbix7/API/HostGroup.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 78 CC 4 SCAR 14.4
CC
4
Cov
0%
_prefix
12.0
id
6.0
_readonly_properties
2.0
CRAP 4.2
1 package Zabbix7::API::HostGroup;
2
3 use strict;
4 use warnings;
5 use 5.010;
6 use Carp;
7 use autodie;
8 use utf8;
9
10 use Zabbix7::API::Host;
11
12 use Moo;
13
14 extends qw/Zabbix7::API::CRUDE/;
15
16 has 'hosts' => (is => 'ro',
17 lazy => 1,
18 builder => '_fetch_hosts');
19
20 sub id {
21 my ($self, $value) = @_;
22 if (defined $value) {
23 $self->data->{groupid} = $value;
24 return $self->data->{groupid};
25 }
26 return $self->data->{groupid};
27 }
28
29 sub _readonly_properties {
30 return {
31 groupid => 1,
32 flags => 1, # Added for Zabbix 7.0 (read-only)
33 };
34 }
35
36 sub _prefix {
37 my (undef, $suffix) = @_;
38 if ($suffix and $suffix =~ m/ids?/) {
39 return 'group' . $suffix;
40 } elsif ($suffix) {
41 return 'hostgroup' . $suffix;
42 }
43 return 'hostgroup';
44 }
45
46 sub _extension {
47 return (
48 output => 'extend',
49 selectHosts => ['hostid', 'host'], # Added for Zabbix 7.0
50 );
51 }
52
53 sub name {
54 my $self = shift;
55 return $self->data->{name} || '';
56 }
57
58 sub _fetch_hosts {
59 my $self = shift;
60 my $hosts = $self->{root}->fetch('Host', params => { groupids => [ $self->id ] });
61 Log::Any->get_logger->debug("Fetched " . scalar @$hosts . " hosts for hostgroup ID: " . $self->id);
62 return $hosts;
63 }
64
65 1;
66 __END__