line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix::API::User; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
776
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
23
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
369
|
|
|
1
|
|
|
|
|
102
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1141
|
use parent qw/Exporter Zabbix::API::CRUDE/; |
|
1
|
|
|
|
|
477
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use constant { |
11
|
1
|
|
|
|
|
1196
|
USER_TYPE_USER => 1, |
12
|
|
|
|
|
|
|
USER_TYPE_ADMIN => 2, |
13
|
|
|
|
|
|
|
USER_TYPE_SUPERADMIN => 3, |
14
|
1
|
|
|
1
|
|
75
|
}; |
|
1
|
|
|
|
|
2
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
17
|
|
|
|
|
|
|
USER_TYPE_USER |
18
|
|
|
|
|
|
|
USER_TYPE_ADMIN |
19
|
|
|
|
|
|
|
USER_TYPE_SUPERADMIN/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
22
|
|
|
|
|
|
|
user_types => [ |
23
|
|
|
|
|
|
|
qw/USER_TYPE_USER |
24
|
|
|
|
|
|
|
USER_TYPE_ADMIN |
25
|
|
|
|
|
|
|
USER_TYPE_SUPERADMIN/ |
26
|
|
|
|
|
|
|
], |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub id { |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
## mutator for id |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if (defined $value) { |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->data->{userid} = $value; |
38
|
0
|
|
|
|
|
|
return $self->data->{userid}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} else { |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $self->data->{userid}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub prefix { |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
1
|
|
my (undef, $suffix) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if ($suffix) { |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return 'user'.$suffix; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} else { |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return 'user'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub extension { |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
0
|
1
|
|
return ( output => 'extend', |
67
|
|
|
|
|
|
|
select_usrgrps => 'refer' ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub collides { |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return @{$self->{root}->query(method => $self->prefix('.get'), |
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
params => { filter => { alias => $self->data->{alias} }, |
77
|
|
|
|
|
|
|
$self->extension })}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub name { |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
0
|
|
|
|
return $self->data->{alias} || '[no username?]'; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub usergroups { |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
## accessor for usergroups |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if (defined $value) { |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
die 'Accessor usergroups called as mutator'; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} else { |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $usergroups = $self->{root}->fetch('UserGroup', params => { usrgrpids => [ map { $_->{usrgrpid} } @{$self->data->{usrgrps}} ] }); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$self->{usergroups} = $usergroups; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return $self->{usergroups}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _usergroup_or_name_to_usergroup { |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
|
|
my $zabbix = shift; |
113
|
0
|
|
|
|
|
|
my $usergroup_or_name = shift; |
114
|
0
|
|
|
|
|
|
my $usergroup; |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
0
|
|
|
|
if (ref $usergroup_or_name and eval { $usergroup_or_name->isa('Zabbix::API::UserGroup') }) { |
|
0
|
0
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# it's a UserGroup object, keep it |
119
|
0
|
|
|
|
|
|
$usergroup = $usergroup_or_name; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} elsif (not ref $usergroup_or_name) { |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$usergroup = $zabbix->fetch('UserGroup', params => { filter => { name => $usergroup_or_name } })->[0]; |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
unless ($usergroup) { |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix::API::UserGroup object or an existing usergroup name'; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} else { |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix::API::UserGroup object or an existing usergroup name'; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $usergroup; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub add_to_usergroup { |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
0
|
1
|
|
my ($self, $usergroup_or_name) = @_; |
144
|
0
|
|
|
|
|
|
my $usergroup = _usergroup_or_name_to_usergroup($self->{root}, $usergroup_or_name); |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
die 'User does not exist (yet?) on server' |
147
|
|
|
|
|
|
|
unless $self->created; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$self->{root}->query(method => 'usergroup.massAdd', |
150
|
|
|
|
|
|
|
params => { usrgrpids => [ $usergroup->id ], |
151
|
|
|
|
|
|
|
userids => [ $self->id ] }); |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
return $self; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub set_usergroups { |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
0
|
1
|
|
my ($self, @list_of_usergroups_or_names) = @_; |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
die 'User does not exist (yet?) on server' |
162
|
|
|
|
|
|
|
unless $self->created; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my @list_of_usergroups = map { _usergroup_or_name_to_usergroup($self->{root}, $_) } @list_of_usergroups_or_names; |
|
0
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
$self->{root}->query(method => 'user.update', |
167
|
|
|
|
|
|
|
params => { userid => $self->id, |
168
|
0
|
|
|
|
|
|
usrgrps => [ map { $_->id } @list_of_usergroups ] }); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
return $self; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub set_password { |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
0
|
1
|
|
my ($self, $password) = @_; |
177
|
0
|
|
|
|
|
|
$self->data->{passwd} = $password; |
178
|
0
|
|
|
|
|
|
return $self; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
183
|
|
|
|
|
|
|
__END__ |