line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix2::API::User; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
689
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
5
|
2
|
|
|
2
|
|
41
|
use 5.010; |
|
2
|
|
|
|
|
7
|
|
6
|
2
|
|
|
2
|
|
6
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
118
|
|
7
|
2
|
|
|
2
|
|
448
|
use autodie; |
|
2
|
|
|
|
|
11743
|
|
|
2
|
|
|
|
|
9
|
|
8
|
2
|
|
|
2
|
|
7208
|
use utf8; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
45
|
use Moo::Lax; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
11
|
|
|
|
|
|
|
extends qw/Exporter Zabbix2::API::CRUDE/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant { |
14
|
2
|
|
|
|
|
1217
|
USER_TYPE_USER => 1, |
15
|
|
|
|
|
|
|
USER_TYPE_ADMIN => 2, |
16
|
|
|
|
|
|
|
USER_TYPE_SUPERADMIN => 3, |
17
|
2
|
|
|
2
|
|
945
|
}; |
|
2
|
|
|
|
|
4
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
20
|
|
|
|
|
|
|
USER_TYPE_USER |
21
|
|
|
|
|
|
|
USER_TYPE_ADMIN |
22
|
|
|
|
|
|
|
USER_TYPE_SUPERADMIN/; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
25
|
|
|
|
|
|
|
user_types => [ |
26
|
|
|
|
|
|
|
qw/USER_TYPE_USER |
27
|
|
|
|
|
|
|
USER_TYPE_ADMIN |
28
|
|
|
|
|
|
|
USER_TYPE_SUPERADMIN/ |
29
|
|
|
|
|
|
|
], |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _readonly_properties { |
33
|
|
|
|
|
|
|
return { |
34
|
0
|
|
|
0
|
|
|
userid => 1, |
35
|
|
|
|
|
|
|
attempt_clock => 1, |
36
|
|
|
|
|
|
|
attempt_failed => 1, |
37
|
|
|
|
|
|
|
attempt_ip => 1, |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub id { |
42
|
|
|
|
|
|
|
## mutator for id |
43
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
44
|
0
|
0
|
|
|
|
|
if (defined $value) { |
45
|
0
|
|
|
|
|
|
$self->data->{userid} = $value; |
46
|
0
|
|
|
|
|
|
return $self->data->{userid}; |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
return $self->data->{userid}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _prefix { |
53
|
0
|
|
|
0
|
|
|
my (undef, $suffix) = @_; |
54
|
0
|
0
|
|
|
|
|
if ($suffix) { |
55
|
0
|
|
|
|
|
|
return 'user'.$suffix; |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
|
return 'user'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _extension { |
62
|
0
|
|
|
0
|
|
|
return (output => 'extend'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub name { |
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
67
|
0
|
|
0
|
|
|
|
return $self->data->{alias} || '???'; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _usergroup_or_name_to_usergroup { |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
|
|
my $zabbix = shift; |
73
|
0
|
|
|
|
|
|
my $usergroup_or_name = shift; |
74
|
0
|
|
|
|
|
|
my $usergroup; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
if (ref $usergroup_or_name and eval { $usergroup_or_name->isa('Zabbix2::API::UserGroup') }) { |
|
0
|
0
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# it's a UserGroup object, keep it |
79
|
0
|
|
|
|
|
|
$usergroup = $usergroup_or_name; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} elsif (not ref $usergroup_or_name) { |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$usergroup = $zabbix->fetch_single('UserGroup', params => { filter => { name => $usergroup_or_name } }); |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
unless ($usergroup) { |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix2::API::UserGroup object or an existing usergroup name'; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix2::API::UserGroup object or an existing usergroup name'; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return $usergroup; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub add_to_usergroup { |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
0
|
1
|
|
my ($self, $usergroup_or_name) = @_; |
104
|
0
|
|
|
|
|
|
my $usergroup = _usergroup_or_name_to_usergroup($self->{root}, $usergroup_or_name); |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
croak('Cannot add user without ID to usergroup: needs to be created or fetched') |
107
|
|
|
|
|
|
|
unless $self->id; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->{root}->query(method => 'usergroup.massAdd', |
110
|
|
|
|
|
|
|
params => { usrgrpids => [ $usergroup->id ], |
111
|
|
|
|
|
|
|
userids => [ $self->id ] }); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $self; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub set_usergroups { |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
0
|
1
|
|
my ($self, @list_of_usergroups_or_names) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
die 'User does not exist (yet?) on server' |
122
|
|
|
|
|
|
|
unless $self->created; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my @list_of_usergroups = map { _usergroup_or_name_to_usergroup($self->{root}, $_) } @list_of_usergroups_or_names; |
|
0
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$self->{root}->query(method => 'user.update', |
127
|
|
|
|
|
|
|
params => { userid => $self->id, |
128
|
0
|
|
|
|
|
|
usrgrps => [ map { $_->id } @list_of_usergroups ] }); |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $self; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub set_password { |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
0
|
1
|
|
my ($self, $password) = @_; |
137
|
0
|
|
|
|
|
|
$self->data->{passwd} = $password; |
138
|
0
|
|
|
|
|
|
return $self; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
__END__ |