-
Notifications
You must be signed in to change notification settings - Fork 1
/
example2.pl
43 lines (36 loc) · 902 Bytes
/
example2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use ZabbixAPI;
# Create new host
my $zabbix_top = "http://127.0.0.1/zabbix/";
my $user = "USER";
my $password = "PASSWORD";
my $hostname = 'api_test01';
my $ip = '192.168.1.150';
my @hostgroups = ('Linux servers', 'Zabbix servers');
my @templates = ('Template_Linux', 'Template_App_MySQL');
my $za = ZabbixAPI->new($zabbix_top);
$za->login($user, $password);
my $groupids = $za->hostgroup_get(
{ filter => {name => \@hostgroups} },
'groupid'
);
my $templateids = $za->template_get(
{ filter => {host => \@templates} },
'templateid'
);
my $result = $za->host_create({
host => $hostname,
ip => $ip,
port => "10050",
useip => 1,
groups => [
map {{groupid => $_}} @$groupids
],
templates => [
map {{templateid => $_}} @$templateids
],
});
print Dumper $result;