zoukankan      html  css  js  c++  java
  • zabbix 添加主机接口

    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 "-----------------
    ";
    print $response->content->{result} . "
    ";
    
    # Check if response was successful
    die "Authentication failed
    " unless $response->content->{'result'};
    
    $authID = $response->content->{'result'};
    print "Authentication successful. Auth ID: " . $authID . "
    ";
    
    # 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
    " unless $response->content->{'result'};
    
    print "List of hosts
    ";
    foreach my $host ( @{ $response->content->{result} } ) {
        print "Host ID: " . $host->{hostid} . " Host: " . $host->{name} . "
    ";
    }
    
    $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 "----------------------
    ";
       
    if ( $response->content->{result}){print "print $host added success
    ";
    $c->render(text =>  "$host added success" )}
    else {print $response->content->{error}->{data};
         print "
    ";
    	 $c->render(text =>  "$response->content->{error}->{data}" )}
    

  • 相关阅读:
    Systemd 进程管理器
    Fedora 15 LoveLock的新特性
    fedora 15 iso 硬盘安装
    Linux权限360度赤裸裸华丽丽大曝光连载之二:SetUID
    Linux下socket设置为非阻塞方式和fcntl系统调用
    linux 磁盘 空间 不足 符号链接
    U盘成功安装REHL 6.1
    IT公司中最流行的10种编程语言
    C会否像汇编一样退居幕后?
    白宫决策捕杀拉登现场照片公布
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6200102.html
Copyright © 2011-2022 走看看