diff --git a/helper/zabbix.api.php b/helper/zabbix.api.php index d59b26b..d3d7b07 100644 --- a/helper/zabbix.api.php +++ b/helper/zabbix.api.php @@ -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; + } +}