The main added 1 Selectinterfaces records, the essence is that the database is the join this table. The Perl code is as follows:
#!/usr/bin/perl UseStrict; Usewarnings; UseJSON::RPC::Client; UseData::dumper; UseJSON; UseUTF8; UseParallel::Forkmanager;my $pm= Parallel::forkmanager->new ( -); #define the number of open processes$| =1;Binmode(STDIN,': Encoding (UTF8)' );Binmode(STDOUT,': Encoding (UTF8)' ); #Three rowsBinmode(STDERR,': Encoding (UTF8)' ); #for normal output Chinese # Authenticate yourselfmy $client= new JSON::RPC::Client;my $url='http://zabbix.mcshell.org/api_jsonrpc.php';my $authID;my $response; my $json={Jsonrpc="2.0",Method="User.login",params={User="User",Password="Password" },ID=1}; $response=$client->call ($url,$json ); #Check If response was successful die "Authentication failed\n" unless $response->content->{'result'}; $authID=$response->content->{'result'};Print "authentication successful. Auth ID:".$authID."\ n"; PrintDumper \get_all_host_and_ip ();SubGet_all_host_and_ip {my $json={Jsonrpc='2.0',Method='Host.get',params= { "Output"= ['name',"Host"],#fuzzy matching is possible "selectinterfaces"= ["Interfaces","IP" ] #Filter IP},ID=1,Auth="$authID", }; my $response=$client->call ($url,$json ); die "Host.get failed\n" unless $response->content->{result}; my $hostID; foreach my $host( @{$response->content->{result}}) { for my $num( @{$host-{Interfaces}}) { $hostID->{$host-{host}}=$num-{IP}; } } return $hostID; }
Zabbix API gets all host names, IP