Update zabbix.api.php

This commit is contained in:
Namhyeon Go 2020-01-27 19:47:03 +09:00 committed by GitHub
parent f6edabc3cc
commit 2a05f2dca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,7 +29,7 @@ if(!check_function_exists("zabbix_get_base_url")) {
if(!check_function_exists("zabbix_get_id")) {
function zabbix_get_id() {
return rand(10000, 99999) * rand(10000, 99999);
return 1;
}
}
@ -195,3 +195,91 @@ if(!check_function_exists("zabbix_get_triggers")) {
return $triggers;
}
}
if(!check_function_exists("zabbix_get_alerts")) {
function zabbix_get_alerts($hostids=null, $time_from=0, $time_till=0) {
$alerts = false;
$response = false;
// get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth");
if(loadHelper("webpagetool")) {
$params = array(
"output" => "extend",
"hostids" => $hostids,
"sortfield" => array("clock", "eventid"),
"sortorder" => "DESC"
);
if($time_from > 0) {
$params['time_from'] = $time_from - 1;
}
if($time_till > 0) {
$params['time_till'] = $time_till + 1;
}
$response = get_web_json($zabbix_api_url, "jsonrpc2.cache", array(
"method" => "event.get",
"params" => array(
"output" => "extend",
"hostids" => $hostids,
"sortfield" => array("clock", "eventid"),
"sortorder" => "DESC"
),
"auth" => $zabbix_auth,
"id" => zabbix_get_id()
));
$alerts = get_property_value("result", $response);
}
return $alerts;
}
}
if(!check_function_exists("zabbix_get_records")) {
function zabbix_get_records($itemids, $now_dt="", $adjust="-24h") {
$records = false;
$response = false;
// get current datetime
if(empty($now_dt)) {
$now_dt = get_current_datetime();
}
// get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth");
// set time range variables
$time_from = get_current_timestamp(array("now" => $now_dt, "adjust" => $adjust));
$time_till = get_current_timestamp(array("now" => $now_dt));
// get history
if(loadHelper("webpagetool")) {
$params = array(
"output" => "extend",
"history" => 3,
"itemids" => $itemids,
"sortfield" => "clock",
"sortorder" => "DESC",
"time_from" => $time_from,
"time_till" => $time_till
);
$response = get_web_json($zabbix_api_url, "jsonrpc2.cache", array(
"method" => "history.get",
"params" => $params,
"auth" => $zabbix_auth,
"id" => zabbix_get_id()
));
$records = get_property_value("result", $response);
}
return $records;
}
}