From c9dfccde07ed2b4c6f569081e0df375d35b4b498 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 8 Oct 2016 12:44:19 +0300 Subject: [PATCH 01/26] Changes for filter form --- zabbix/imap.php | 265 +- zabbix/imap/imap.js | 189 +- zabbix/imap/jquery-ui/AUTHORS.txt | 330 + zabbix/imap/jquery-ui/LICENSE.txt | 43 + .../imap/jquery-ui/external/jquery/jquery.js | 11008 +++++++++ zabbix/imap/jquery-ui/index.html | 559 + zabbix/imap/jquery-ui/jquery-ui.css | 881 + zabbix/imap/jquery-ui/jquery-ui.js | 18686 ++++++++++++++++ zabbix/imap/jquery-ui/jquery-ui.min.css | 6 + zabbix/imap/jquery-ui/jquery-ui.min.js | 13 + zabbix/imap/jquery-ui/jquery-ui.structure.css | 876 + .../jquery-ui/jquery-ui.structure.min.css | 5 + zabbix/imap/jquery-ui/package.json | 74 + zabbix/imap/markers.css | 77 - zabbix/imap/menu.inc.php | 13 + zabbix/imap/menu3.inc.php | 26 + 16 files changed, 32769 insertions(+), 282 deletions(-) create mode 100644 zabbix/imap/jquery-ui/AUTHORS.txt create mode 100644 zabbix/imap/jquery-ui/LICENSE.txt create mode 100644 zabbix/imap/jquery-ui/external/jquery/jquery.js create mode 100644 zabbix/imap/jquery-ui/index.html create mode 100644 zabbix/imap/jquery-ui/jquery-ui.css create mode 100644 zabbix/imap/jquery-ui/jquery-ui.js create mode 100644 zabbix/imap/jquery-ui/jquery-ui.min.css create mode 100644 zabbix/imap/jquery-ui/jquery-ui.min.js create mode 100644 zabbix/imap/jquery-ui/jquery-ui.structure.css create mode 100644 zabbix/imap/jquery-ui/jquery-ui.structure.min.css create mode 100644 zabbix/imap/jquery-ui/package.json create mode 100644 zabbix/imap/menu3.inc.php diff --git a/zabbix/imap.php b/zabbix/imap.php index c1560d1..35191c0 100644 --- a/zabbix/imap.php +++ b/zabbix/imap.php @@ -13,25 +13,6 @@ $page['file'] = 'imap.php'; $page['hist_arg'] = array('groupid', 'hostid', 'show_severity','control_map','with_triggers_only'); -$fields = array( - 'lat' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), - 'lng' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), - 'with_triggers_only' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), - 'control_map' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), - 'severity_min' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1,2,3,4,5'), null), - 'output' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), - 'action_ajax' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), - 'hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), - 'thostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), - 'groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), - 'hardware' => array(T_ZBX_STR, O_OPT, null, null, null), - 'linkid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), - 'linkoptions' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), - 'hardwareField' => array(T_ZBX_STR, O_OPT, null, null, null), - 'searchstring' => array(T_ZBX_STR, O_OPT, P_SYS, null, null) -); -check_fields($fields); - if (function_exists('get_request')) { $lat = get_request('lat', null); $lng = get_request('lng', null); @@ -84,6 +65,43 @@ require_once dirname(__FILE__).'/include/page_header.php'; }; +$fields = array( + 'groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), + 'hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), + 'thostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), + 'linkid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), + 'severity_min' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1,2,3,4,5'), null), + 'fullscreen' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), + 'control_map' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), + 'with_triggers_only' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), + 'output' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), + 'jsscriptid' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), + // ajax + 'favobj' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), + 'favref' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), + 'favid' => array(T_ZBX_INT, O_OPT, P_ACT, null, null), + 'favcnt' => array(T_ZBX_INT, O_OPT, null, null, null), + 'pmasterid' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), + 'favaction' => array(T_ZBX_STR, O_OPT, P_ACT, IN("'add','remove','refresh','flop','sort'"), null), + 'favstate' => array(T_ZBX_INT, O_OPT, P_ACT, NOT_EMPTY, 'isset({favaction})&&("flop"=={favaction})'), + 'favdata' => array(T_ZBX_STR, O_OPT, null, null, null), + 'hardwareField' => array(T_ZBX_STR, O_OPT, null, null, null), + //стандартные + 'btnSelect' => [T_ZBX_STR, O_OPT, null, null, null], + 'filter_rst' => [T_ZBX_STR, O_OPT, P_SYS, null, null], + 'filter_set' => [T_ZBX_STR, O_OPT, P_SYS, null, null], + 'show_triggers' => [T_ZBX_INT, O_OPT, null, null, null], + 'show_events' => [T_ZBX_INT, O_OPT, P_SYS, null, null], + 'ack_status' => [T_ZBX_INT, O_OPT, P_SYS, null, null], + 'show_severity' => [T_ZBX_INT, O_OPT, P_SYS, null, null], + 'status_change_days' => [T_ZBX_INT, O_OPT, null, BETWEEN(1, DAY_IN_YEAR * 2), null], + 'status_change' => [T_ZBX_INT, O_OPT, null, null, null], + 'txt_select' => [T_ZBX_STR, O_OPT, null, null, null], + 'application' => [T_ZBX_STR, O_OPT, null, null, null], + 'inventory' => [T_ZBX_STR, O_OPT, null, null, null] +); +check_fields($fields); + /* * Filter */ @@ -98,21 +116,115 @@ 'withInventory' => true ), 'hostid' => $hostid, - 'groupid' => $groupid, - 'severitiesMin' => array( - TRIGGER_SEVERITY_NOT_CLASSIFIED => getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), - TRIGGER_SEVERITY_INFORMATION => getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), - TRIGGER_SEVERITY_WARNING => getSeverityCaption(TRIGGER_SEVERITY_WARNING), - TRIGGER_SEVERITY_AVERAGE => getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), - TRIGGER_SEVERITY_HIGH => getSeverityCaption(TRIGGER_SEVERITY_HIGH), - TRIGGER_SEVERITY_DISASTER => getSeverityCaption(TRIGGER_SEVERITY_DISASTER) - ), - 'severityMin' => $showSeverity + 'groupid' => $groupid )); $_REQUEST['groupid'] = $pageFilter->groupid; $_REQUEST['hostid'] = $pageFilter->hostid; + +// filter set +if (hasRequest('filter_set')) { + CProfile::update('web.tr_status.filter.show_details', getRequest('show_details', 0), PROFILE_TYPE_INT); + CProfile::update('web.tr_status.filter.show_maintenance', getRequest('show_maintenance', 0), PROFILE_TYPE_INT); + CProfile::update('web.tr_status.filter.show_severity', + getRequest('show_severity', TRIGGER_SEVERITY_NOT_CLASSIFIED), PROFILE_TYPE_INT + ); + CProfile::update('web.tr_status.filter.txt_select', getRequest('txt_select', ''), PROFILE_TYPE_STR); + CProfile::update('web.tr_status.filter.status_change', getRequest('status_change', 0), PROFILE_TYPE_INT); + CProfile::update('web.tr_status.filter.status_change_days', getRequest('status_change_days', 14), + PROFILE_TYPE_INT + ); + CProfile::update('web.tr_status.filter.application', getRequest('application'), PROFILE_TYPE_STR); + + // show triggers + // when this filter is set to "All" it must not be remembered in the profiles because it may render the + // whole page inaccessible on large installations. + if (getRequest('show_triggers') != TRIGGERS_OPTION_ALL) { + CProfile::update('web.tr_status.filter.show_triggers', getRequest('show_triggers'), PROFILE_TYPE_INT); + } + + // show events + $showEvents = getRequest('show_events', EVENTS_OPTION_NOEVENT); + if ($config['event_ack_enable'] == EVENT_ACK_ENABLED || $showEvents != EVENTS_OPTION_NOT_ACK) { + CProfile::update('web.tr_status.filter.show_events', $showEvents, PROFILE_TYPE_INT); + } + + // ack status + if ($config['event_ack_enable'] == EVENT_ACK_ENABLED) { + CProfile::update('web.tr_status.filter.ack_status', getRequest('ack_status', ZBX_ACK_STS_ANY), PROFILE_TYPE_INT); + } + + // update host inventory filter + $inventoryFields = []; + $inventoryValues = []; + foreach (getRequest('inventory', []) as $field) { + if ($field['value'] === '') { + continue; + } + + $inventoryFields[] = $field['field']; + $inventoryValues[] = $field['value']; + } + CProfile::updateArray('web.tr_status.filter.inventory.field', $inventoryFields, PROFILE_TYPE_STR); + CProfile::updateArray('web.tr_status.filter.inventory.value', $inventoryValues, PROFILE_TYPE_STR); +} +elseif (hasRequest('filter_rst')) { + DBStart(); + CProfile::delete('web.tr_status.filter.show_triggers'); + CProfile::delete('web.tr_status.filter.show_details'); + CProfile::delete('web.tr_status.filter.show_maintenance'); + CProfile::delete('web.tr_status.filter.show_events'); + CProfile::delete('web.tr_status.filter.ack_status'); + CProfile::delete('web.tr_status.filter.show_severity'); + CProfile::delete('web.tr_status.filter.txt_select'); + CProfile::delete('web.tr_status.filter.status_change'); + CProfile::delete('web.tr_status.filter.status_change_days'); + CProfile::delete('web.tr_status.filter.application'); + CProfile::deleteIdx('web.tr_status.filter.inventory.field'); + CProfile::deleteIdx('web.tr_status.filter.inventory.value'); + DBend(); +} + +if (hasRequest('filter_set') && getRequest('show_triggers') == TRIGGERS_OPTION_ALL) { + $showTriggers = TRIGGERS_OPTION_ALL; +} +else { + $showTriggers = CProfile::get('web.tr_status.filter.show_triggers', TRIGGERS_OPTION_RECENT_PROBLEM); +} +$showDetails = CProfile::get('web.tr_status.filter.show_details', 0); +$showMaintenance = CProfile::get('web.tr_status.filter.show_maintenance', 1); +$showSeverity = CProfile::get('web.tr_status.filter.show_severity', TRIGGER_SEVERITY_NOT_CLASSIFIED); +$txtSelect = CProfile::get('web.tr_status.filter.txt_select', ''); +$showChange = CProfile::get('web.tr_status.filter.status_change', 0); +$statusChangeBydays = CProfile::get('web.tr_status.filter.status_change_days', 14); +$ackStatus = ($config['event_ack_enable'] == EVENT_ACK_DISABLED) + ? ZBX_ACK_STS_ANY : CProfile::get('web.tr_status.filter.ack_status', ZBX_ACK_STS_ANY); +$showEvents = CProfile::get('web.tr_status.filter.show_events', EVENTS_OPTION_NOEVENT); + +// check event acknowledges +if ($config['event_ack_enable'] == EVENT_ACK_DISABLED && $showEvents == EVENTS_OPTION_NOT_ACK) { + $showEvents = EVENTS_OPTION_NOEVENT; +} + +// fetch filter from profiles +$filter = [ + 'application' => CProfile::get('web.tr_status.filter.application', ''), + 'inventory' => [] +]; + +foreach (CProfile::getArray('web.tr_status.filter.inventory.field', []) as $i => $field) { + $filter['inventory'][] = [ + 'field' => $field, + 'value' => CProfile::get('web.tr_status.filter.inventory.value', null, $i) + ]; +} + + + + + + function rightsErrorAjax() { $responseData = '{"jsonrpc": "2.0","error": {"message": "Access error. Check rights."}}'; echo $responseData; @@ -403,25 +515,79 @@ function rightsForLink($idl) { // $showEvents = $_REQUEST['show_events']; // $ackStatus = $_REQUEST['ack_status']; - $triggerWidget = new CWidget(); +// $triggerWidget = new CWidget(); +// +// $rightForm = new CForm('get'); +// $rightForm->addItem(array(_('Group').SPACE, $pageFilter->getGroupsCB(true))); +// $rightForm->addItem(array(SPACE._('Host').SPACE, $pageFilter->getHostsCB(true))); +// $severityComboBox = new CComboBox('severity_min', $showSeverity,'javascript: submit();'); +// $severityComboBox->addItems($pageFilter->severitiesMin); +// $rightForm->addItem(array(SPACE._('Minimum trigger severity').SPACE, $severityComboBox)); +// +// textdomain("imap"); +// $rightForm->addItem(array(SPACE.SPACE._('Control map').SPACE, new CCheckBox('control_map', $control_map, '_imap.settings.do_map_control = jQuery(\'#control_map\')[0].checked; if (_imap.settings.do_map_control) {mapBbox(_imap.bbox)};', 1))); +// $rightForm->addItem(array(SPACE.SPACE._('With triggers only').SPACE, new CCheckBox('with_triggers_only', $with_triggers_only, 'javascript: submit();', 1))); +// textdomain("frontend"); +// +// $rightForm->addVar('fullscreen', $_REQUEST['fullscreen']); +// +// $triggerWidget->addHeader(SPACE,$rightForm); +// $triggerWidget->addPageHeader(_('Interactive map'), get_icon('fullscreen', array('fullscreen' => $_REQUEST['fullscreen']))); +// +// $triggerWidget->show(); - $rightForm = new CForm('get'); - $rightForm->addItem(array(_('Group').SPACE, $pageFilter->getGroupsCB(true))); - $rightForm->addItem(array(SPACE._('Host').SPACE, $pageFilter->getHostsCB(true))); - $severityComboBox = new CComboBox('severity_min', $showSeverity,'javascript: submit();'); - $severityComboBox->addItems($pageFilter->severitiesMin); - $rightForm->addItem(array(SPACE._('Minimum trigger severity').SPACE, $severityComboBox)); + /* + * Display + */ textdomain("imap"); - $rightForm->addItem(array(SPACE.SPACE._('With triggers only').SPACE, new CCheckBox('with_triggers_only', $with_triggers_only, 'javascript: submit();', 1))); + $triggerWidget = (new CWidget())->setTitle(_('Interactive map')); + + $rightForm = (new CForm('get')) + ->addVar('fullscreen', $_REQUEST['fullscreen']); + + $controls = new CList(); + $controls->addItem(array(SPACE.SPACE._('With triggers only').SPACE, new CCheckBox('with_triggers_only', $with_triggers_only, 'javascript: submit();', 1))); + $controls->addItem(array(SPACE.SPACE._('Control map').SPACE, new CCheckBox('control_map', $control_map, '_imap.settings.do_map_control = jQuery(\'#control_map\')[0].checked; if (_imap.settings.do_map_control) {mapBbox(_imap.bbox)};', 1))); + $controls->addItem([_('Group').SPACE, $pageFilter->getGroupsCB()]); + $controls->addItem([_('Host').SPACE, $pageFilter->getHostsCB()]); + $controls->addItem(get_icon('fullscreen', ['fullscreen' => $_REQUEST['fullscreen']])); + + $rightForm->addItem($controls); + + $triggerWidget->setControls($rightForm); + + + // filter textdomain("frontend"); + $filterFormView = new CView('common.filter.trigger', [ + 'overview' => false, + 'filter' => [ + 'filterid' => 'web.tr_status.filter.state', + 'showTriggers' => $showTriggers, + 'ackStatus' => $ackStatus, + 'showEvents' => $showEvents, + 'showSeverity' => $showSeverity, + 'statusChange' => $showChange, + 'statusChangeDays' => $statusChangeBydays, + 'showDetails' => $showDetails, + 'txtSelect' => $txtSelect, + 'application' => $filter['application'], + 'inventory' => $filter['inventory'], + 'showMaintenance' => $showMaintenance, + 'hostId' => getRequest('hostid'), + 'groupId' => getRequest('groupid'), + 'fullScreen' => getRequest('fullscreen') + ], + 'config' => $config + ]); + + $filterForm = $filterFormView->render(); + $triggerWidget->addItem($filterForm); + // filter end - $rightForm->addVar('fullscreen', $_REQUEST['fullscreen']); - - $triggerWidget->addHeader(SPACE,$rightForm); - $triggerWidget->addPageHeader(_('Interactive map'), get_icon('fullscreen', array('fullscreen' => $_REQUEST['fullscreen']))); - $triggerWidget->show(); + }; $version=trim(file_get_contents('imap/version')); @@ -461,6 +627,9 @@ function rightsForLink($idl) {
+ + + @@ -515,7 +684,7 @@ function rightsForLink($idl) { /* This settings changing in file settings.js */ _imap.settings.show_icons = true; _imap.settings.use_search = true; - _imap.settings.use_zoom_slider = false; + _imap.settings.use_zoom_slider = true; _imap.settings.links_enabled = true; _imap.settings.debug_enabled = false; _imap.settings.hardware_field = 'type'; @@ -567,7 +736,6 @@ function rightsForLink($idl) { locale['Items'] = ''; locale['Discovery rules'] = ''; locale['Web scenarios'] = ''; - locale['Screens'] = ''; locale['Change location'] = ''; @@ -618,7 +786,7 @@ function rightsForLink($idl) { /* Фильтр для отбора хостов и групп */ _imap.filter = { - show_severity: severityMin; ?>, + show_severity: 0, hostid: hostid; ?>, groupid: groupid; ?> }; @@ -633,12 +801,7 @@ function rightsForLink($idl) { if (file_exists('imap/additions.js')) echo ''; if (!$check_links) echo ''; - if (file_exists('imap/js')) { - $files = scandir('imap/js'); - foreach($files as $file) { - if (substr('imap/js/'.$file,-3)=='.js') echo ''; - }; - }; + textdomain("frontend"); if ($output!='block') { diff --git a/zabbix/imap/imap.js b/zabbix/imap/imap.js index 04cb013..bc7ecd2 100644 --- a/zabbix/imap/imap.js +++ b/zabbix/imap/imap.js @@ -16,7 +16,6 @@ _imap.searchmarkers = L.layerGroup(); _imap.googlestreetviewer = false; _imap.googlestreetviewer_marker = false; - _imap.messages = {count:0, text:{}}; _imap.settings._zoom_meters = [1000000,500000,300000,100000,50000,20000,10000,5000,2000,1000,500,300,100,50,30,20,10,5,0]; @@ -72,6 +71,7 @@ baseMaps["Yandex"].options.maxZoom = 18; baseMaps["Yandex Satellite"] = new L.Yandex('satellite'); baseMaps["Yandex Hybrid"] = new L.Yandex('hybrid'); + overlayMaps["Yandex Traffic"] = new L.Yandex("null", {traffic:true, opacity:0.8, overlay:true}); } catch(e) {} finally {}; try { @@ -228,40 +228,7 @@ }); }; - function get_last_messages() { - var onlymes = 1; - if (!getCookie('countertoday')) { - onlymes = 0; - }; - jQuery.ajax({ - url: 'http://imapmessages.lisss.ru', - type: 'POST', - dataType: 'json', - data: { - version: _imap.version, - zabbix: _imap.zabbixversion, - onlymes: onlymes - }, - success: function(data){ - if (onlymes == 0) setCookie('countertoday', '1', {expires: (3600*24), path: '/'}); - var lastmes = +getCookie('imap_messages_last_num'); - if (!lastmes) lastmes = 0; - var newlastmes = 0; - jQuery.each(data,function(num,text){ - _imap.messages.text[num] = text; - if (num>lastmes) { - _imap.messages.count++; - newlastmes = Math.max(num,newlastmes); - }; - }); - _imap.messages.lastnum = newlastmes; - jQuery('.imap_messages_count').html(_imap.messages.count>0?_imap.messages.count:''); - }, - error: function(data){ - - } - }); - }; + function counter() {if (!getCookie('countertoday')) {jQuery.ajax({type: "POST",url: 'http://imapcounter.lisss.ru',data: {version: _imap.version, zabbix: _imap.zabbixversion},dataType: 'text'});setCookie('countertoday', '1', {expires: (3600*24), path: '/'}); };}; /* фильтр поиска хостов */ function hostsFilter(hh,ff) { @@ -907,7 +874,7 @@ }; }; - if (_imap.settings.do_map_control | _imap.vars.it_first) { + if (_imap.settings.do_map_control) { mapBbox(_imap.bbox); }; @@ -1232,26 +1199,12 @@ jQuery('#hostItems'+hh).html(); }; - function getSID(textonly) { - var sid = getCookie('zbx_sessionid'); - if (textonly) return sid.substring(16,32); - return 'sid='+sid.substring(16,32)+'&'; - }; - - function popupFrame(url,text) { + function popupFrame(url) { container = L.DomUtil.create('span', 'graphPopupWindow'); - jQuery(container).dialog({maxWidth:'100%', maxHeight:'100%', width:800, height:650, resizable:true}) + jQuery(container).append( + jQuery("