zabbix 添加主机成功失败判断

时间:2023-03-08 23:53:38
zabbix 添加主机成功失败判断
zabbix 成功添加后:

$VAR1 = bless( {
'version' => 0,
'content' => {
'jsonrpc' => '2.0',
'id' => 1,
'result' => {
'hostids' => [
'10228'
]
}
},
'jsontext' => '{"jsonrpc":"2.0","result":{"hostids":["10228"]},"id":1}',
'is_success' => 1
}, 'JSON::RPC::ReturnObject' );
----------------------
HASH(0x2857fd0) zabbix 添加是失败的情况: $VAR1 = bless( {
'version' => 0,
'content' => {
'jsonrpc' => '2.0',
'error' => {
'data' => 'Host with the same name "zjtest9-app" already exists.',
'message' => 'Invalid params.',
'code' => -32602
},
'id' => 1
},
'jsontext' => '{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"Host with the same name \\"zjtest9-app\\" already exists."},"id":1}',
'is_success' => 0
}, 'JSON::RPC::ReturnObject' ); 通过判断:
die "host.get failed\n" unless $response->content->{error}->{data};