zabbix 添加主机接口
2016-05-03 16:15
330 查看
http://192.168.32.101:3000/api/zabbix/add_Host?env=test&host=zjtest9-app&ip=192.168.32.250&groupid=11&templateid=10001 my $c = shift; my $env = $c->param('env'); my $host = $c->param('host'); my $ip = $c->param('ip'); my $groupid = $c->param('groupid'); my $templateid = $c->param('templateid'); if ($env eq "pro"){ my $client = new JSON::RPC::Client; my $url = 'http://192.168.32.xxx/zabbix/api_jsonrpc.php'; my $authID; my $response; my $json = { jsonrpc => "2.0", method => "user.login", params => { user => "admin", password => "zabbix" }, id => 1 }; $response = $client->call( $url, $json ); print "-----------------\n"; print $response->content->{result} . "\n"; # Check if response was successful die "Authentication failed\n" unless $response->content->{'result'}; $authID = $response->content->{'result'}; print "Authentication successful. Auth ID: " . $authID . "\n"; # Get list of all hosts using authID $json = { jsonrpc => '2.0', method => 'host.get', params => { output => [ 'hostid', 'name' ], # get only host id and host name sortfield => 'name', # sort by host name }, id => 2, auth => "$authID", }; $response = $client->call( $url, $json ); # Check if response was successful die "host.get failed\n" unless $response->content->{'result'}; print "List of hosts\n"; foreach my $host ( @{ $response->content->{result} } ) { print "Host ID: " . $host->{hostid} . " Host: " . $host->{name} . "\n"; } $json = { "jsonrpc" => "2.0", "method" => "host.create", "params" => { "host" => "$host", "interfaces" => [ { "type" => 1, "main" => 1, "useip" => 1, "ip" => "$ip", "dns" => "", "port" => "10050" } ], "groups" => [ { "groupid" => "$groupid" } ], "templates" => [ { "templateid" => "$templateid" } ] }, "auth" => "$authID", "id" => 1 }; $response = $client->call( $url, $json ); use Data::Dumper; my $str = Dumper($response); print $str; print "----------------------\n"; if ( $response->content->{result}){print "print $host added success\n"; $c->render(text => "$host added success" )} else {print $response->content->{error}->{data}; print "\n"; $c->render(text => "$response->content->{error}->{data}" )}
相关文章推荐
- 二叉树的非递归遍历
- Learning to Rank中Pointwise关于PRank算法源码实现
- iOS NSIndexPath
- HDU 4052 Adding New Machine (线段树+离散化)
- 解决MySQL5.6出现"Using a password on the command line interface..."
- GDOI2016总结
- Android 分享到微信6.0后好友、朋友圈
- 验证码生成类
- 【转】如何分析解决Android ANR
- 2016年5月02日 - 精华
- axis2客户端调用服务器
- 练习三 1001
- 【VS开发】关于在CFormView中实现CListCtrl控件的注意事项
- MySQL 多表连接查询
- 第12期【江山代有才人出】5月刊
- redis的aof持久化深入解析
- Fast RCNN 训练自己数据集 (1编译配置)
- 重要的东西
- openwrt创建软件包
- JSTL 字符串长度判断并截取