Update zabbix.api.php

This commit is contained in:
Namhyeon Go 2019-04-09 19:41:21 +09:00 committed by GitHub
parent 162fedd2ef
commit 847edab82e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,17 +15,17 @@ if(!check_function_exists("zabbix_get_base_url")) {
if(!check_function_exists("zabbix_get_id")) { if(!check_function_exists("zabbix_get_id")) {
function zabbix_get_id() { function zabbix_get_id() {
return rand(10000, 99999) * rand(10000, 99999)); return rand(10000, 99999) * rand(10000, 99999);
} }
} }
if(!check_function_exists("zabbix_authenticate")) { if(!check_function_exists("zabbix_authenticate")) {
function zabbix_authenticate($host, $username, $password, $protocol="http") { function zabbix_authenticate($host, $username, $password, $protocol="http") {
$response = false; $response = false;
// get zabbix api url // get zabbix api url
$zabbix_api_url = zabbix_get_api_url($host, $protocol); $zabbix_api_url = zabbix_get_api_url($host, $protocol);
// connect to zabbix server // connect to zabbix server
if(loadHelper("webpagetool")) { if(loadHelper("webpagetool")) {
$response = get_web_json($zabbix_api_url, "jsondata", array( $response = get_web_json($zabbix_api_url, "jsondata", array(
@ -44,7 +44,7 @@ if(!check_function_exists("zabbix_authenticate")) {
), ),
)); ));
} }
// set connection to global scope // set connection to global scope
set_scope("zabbix_api_url", $zabbix_api_url); set_scope("zabbix_api_url", $zabbix_api_url);
set_scope("zabbix_auth", get_property_value("result", $response)); set_scope("zabbix_auth", get_property_value("result", $response));
@ -56,7 +56,7 @@ if(!check_function_exists("zabbix_authenticate")) {
if(!check_function_exists("zabbix_retrieve_hosts")) { if(!check_function_exists("zabbix_retrieve_hosts")) {
function zabbix_retrieve_hosts() { function zabbix_retrieve_hosts() {
$response = false; $response = false;
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_scope("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_scope("zabbix_auth");
@ -68,7 +68,7 @@ if(!check_function_exists("zabbix_retrieve_hosts")) {
"Content-Type" => "application/json-rpc", "Content-Type" => "application/json-rpc",
), ),
"data" => array( "data" => array(
"jsonprc" => "2.0", "jsonrpc" => "2.0",
"method" => "host.get", "method" => "host.get",
"params" => array( "params" => array(
"output" => array("hostid", "host"), "output" => array("hostid", "host"),
@ -79,7 +79,7 @@ if(!check_function_exists("zabbix_retrieve_hosts")) {
), ),
)); ));
} }
return $response; return $response;
} }
} }
@ -87,17 +87,11 @@ if(!check_function_exists("zabbix_retrieve_hosts")) {
if(!check_function_exists("zabbix_get_items")) { if(!check_function_exists("zabbix_get_items")) {
function zabbix_get_items($hostids="") { function zabbix_get_items($hostids="") {
$response = false; $response = false;
// check type
if(!(is_array($host_ids) && is_string($host_ids)) {
set_error("hostids must be array or string");
show_errors();
}
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_scope("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_scope("zabbix_auth");
// connect to zabbix server // connect to zabbix server
if(loadHelper("webpagetool")) { if(loadHelper("webpagetool")) {
$response = get_web_json($zabbix_api_url, "jsondata", array( $response = get_web_json($zabbix_api_url, "jsondata", array(
@ -105,7 +99,7 @@ if(!check_function_exists("zabbix_get_items")) {
"Content-Type" => "application/json-rpc", "Content-Type" => "application/json-rpc",
), ),
"data" => array( "data" => array(
"jsonprc" => "2.0", "jsonrpc" => "2.0",
"method" => "host.get", "method" => "host.get",
"params" => array( "params" => array(
"selectInventory" => true, "selectInventory" => true,
@ -120,7 +114,7 @@ if(!check_function_exists("zabbix_get_items")) {
), ),
)); ));
} }
return $response; return $response;
} }
} }