diff --git a/src/assets/css/components/components/advancedSearch/codemirror.scss b/src/assets/css/components/components/advancedSearch/codemirror.scss index f792c8f4..e21dd841 100644 --- a/src/assets/css/components/components/advancedSearch/codemirror.scss +++ b/src/assets/css/components/components/advancedSearch/codemirror.scss @@ -180,6 +180,9 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;} position: relative; z-index: 0; } +.CodeMirror-scroll::-webkit-scrollbar { + width: 0; +} .CodeMirror-sizer { position: relative; border-right: 50px solid transparent; @@ -356,3 +359,77 @@ div.CodeMirror-dragcursors { /* Help users use markselection to safely style text background */ span.CodeMirror-selectedtext { background: none; } + +.CodeMirror-hint-active { + background-color: #eaf1f5; + color: #5a90b0; +} + +.el-dropdown-menu__item.CodeMirror-hint { + line-height: 20px; + /*font-family: NotoSansSC-Regular;*/ +} + +.hint-clear { + color: #31739C !important; +} + +.hint-title { + margin: 10px 10px 10px 4px; + line-height: 20px; + font-weight: bold; + /* 禁止选中 样式 */ + background: #fff !important; + color: #000 !important; +} + +.cm-s-eclipse span.cm-string-2 { + //color: #D85512; +} + +.CodeMirror-lines { + /*height: 20px;*/ + //padding: 3px 0; +} + +.in-coder-panel { + margin-left: 2px; +} + +.in-coder-panel pre { + height: auto !important; +} + +.in-coder-panel .CodeMirror { + /*height: inherit;*/ +} + +.in-coder-panel input { + font-size: 12px !important; + display: block; + border-color: transparent !important; + padding: 0 0 0 8px !important; +} + +.CodeMirror-hints { + font-family: NotoSansSC-Regular !important; + max-width: 800px; +} + +.CodeMirror-line { + //font-family: Arial !important; +} + +.CodeMirror-hint { + margin: 0; + padding: 0 4px !important; + line-height: 20px !important; + border-radius: 2px; + white-space: pre; + color: black; + cursor: pointer; +} + +.cm-variable-2{ + font-weight: bold; +} diff --git a/src/components/advancedSearch/Index.vue b/src/components/advancedSearch/Index.vue index e032a34e..fc3cb515 100644 --- a/src/components/advancedSearch/Index.vue +++ b/src/components/advancedSearch/Index.vue @@ -10,6 +10,7 @@ :column-list="columnList" :str="str" :show-list="showList" + :is-show-hint="showHint" @changeMode="changeMode" @search="search" :show-close-icon="showCloseIcon" @@ -64,7 +65,11 @@ export default { required: true }, // 连接符列表 - connectionList: Array + connectionList: Array, + showHint: { + type: Boolean, + default: false + } }, emits: ['search'], methods: { diff --git a/src/components/advancedSearch/TagMode.vue b/src/components/advancedSearch/TagMode.vue index f2acd596..6d58136e 100644 --- a/src/components/advancedSearch/TagMode.vue +++ b/src/components/advancedSearch/TagMode.vue @@ -642,7 +642,7 @@ export default { q = decodeURI(q) } else { const str1 = q.substring(q.indexOf('%'), q.indexOf('%') + 3) - if (q.indexOf('%') > 0 && (str1 !== '%20' || str1 === '%25')) { + if (q.indexOf('%') > 0 && (str1 === '%20' || str1 === '%25')) { q = decodeURI(q) } } diff --git a/src/components/advancedSearch/TextMode.vue b/src/components/advancedSearch/TextMode.vue index 495f4958..ea8dd709 100644 --- a/src/components/advancedSearch/TextMode.vue +++ b/src/components/advancedSearch/TextMode.vue @@ -1,37 +1,52 @@ + + diff --git a/src/components/advancedSearch/showhint/Hint/HelperInfo.vue b/src/components/advancedSearch/showhint/Hint/HelperInfo.vue new file mode 100644 index 00000000..f5e95c9a --- /dev/null +++ b/src/components/advancedSearch/showhint/Hint/HelperInfo.vue @@ -0,0 +1,165 @@ + + + + + diff --git a/src/components/advancedSearch/showhint/Hint/Hint.vue b/src/components/advancedSearch/showhint/Hint/Hint.vue new file mode 100644 index 00000000..082adf9c --- /dev/null +++ b/src/components/advancedSearch/showhint/Hint/Hint.vue @@ -0,0 +1,47 @@ + + + + + + diff --git a/src/components/advancedSearch/showhint/Hint/HintInfo.vue b/src/components/advancedSearch/showhint/Hint/HintInfo.vue new file mode 100644 index 00000000..97ce4a01 --- /dev/null +++ b/src/components/advancedSearch/showhint/Hint/HintInfo.vue @@ -0,0 +1,127 @@ + + + + + diff --git a/src/components/advancedSearch/showhint/Hint/Renderer.vue b/src/components/advancedSearch/showhint/Hint/Renderer.vue new file mode 100644 index 00000000..37e46b82 --- /dev/null +++ b/src/components/advancedSearch/showhint/Hint/Renderer.vue @@ -0,0 +1,16 @@ + diff --git a/src/components/advancedSearch/showhint/TextSearch/codeMirror.scss b/src/components/advancedSearch/showhint/TextSearch/codeMirror.scss new file mode 100644 index 00000000..22f401e0 --- /dev/null +++ b/src/components/advancedSearch/showhint/TextSearch/codeMirror.scss @@ -0,0 +1,73 @@ +.CodeMirror-hint-active { + background-color: #eaf1f5; + color: #5a90b0; +} + +.el-dropdown-menu__item.CodeMirror-hint { + line-height: 20px; + /*font-family: NotoSansSC-Regular;*/ +} + +.hint-clear { + color: #31739C !important; +} + +.hint-title { + margin: 10px 10px 10px 4px; + line-height: 20px; + font-weight: bold; + /* 禁止选中 样式 */ + background: #fff !important; + color: #000 !important; +} + +.cm-s-eclipse span.cm-string-2 { + color: #D85512; +} + +.CodeMirror-lines { + /*height: 20px;*/ + padding: 3px 0; +} + +.in-coder-panel { + margin-left: 2px; +} + +.in-coder-panel pre { + height: auto !important; +} + +.in-coder-panel .CodeMirror { + /*height: inherit;*/ +} + +.in-coder-panel input { + font-size: 12px !important; + display: block; + border-color: transparent !important; + padding: 0 0 0 8px !important; +} + +.CodeMirror-hints { + font-family: NotoSansSC-Regular !important; + max-width: 800px; +} + +.CodeMirror-line { + font-family: Arial !important; +} + +.CodeMirror-hint { + margin: 0; + padding: 0 4px !important; + line-height: 20px !important; + border-radius: 2px; + white-space: pre; + color: black; + cursor: pointer; +} + +.cm-variable-2{ + font-weight: bold; +} diff --git a/src/components/advancedSearch/showhint/TextSearch/createHint.js b/src/components/advancedSearch/showhint/TextSearch/createHint.js new file mode 100644 index 00000000..888ccc2b --- /dev/null +++ b/src/components/advancedSearch/showhint/TextSearch/createHint.js @@ -0,0 +1,22 @@ +import sqlHint from './sql-hint.js' +import showHint from './show-hint.js' +import manualShowHint from './manual-show-hint' +import 'codemirror/addon/hint/show-hint.css' + +export default function createHint (hitType = 'default', CodeMirror, { + dataset, + hinthook, + keywordshook, + callback, + keyboardUp, + keyboardDown, + keyboardEnter +}) { + hitType === 'default' ? showHint(CodeMirror) : manualShowHint(CodeMirror, { + cb: callback, + keyboardUp, + keyboardDown, + keyboardEnter + }) + sqlHint(CodeMirror, { dataset, hinthook, keywordshook }) +} diff --git a/src/components/advancedSearch/showhint/TextSearch/manual-show-hint.js b/src/components/advancedSearch/showhint/TextSearch/manual-show-hint.js new file mode 100644 index 00000000..41ec1be9 --- /dev/null +++ b/src/components/advancedSearch/showhint/TextSearch/manual-show-hint.js @@ -0,0 +1,596 @@ +export default function (CodeMirror,{ + cb, + keyboardUp, + keyboardDown, + keyboardEnter +}) { + + var HINT_ELEMENT_CLASS = "CodeMirror-hint"; + var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active"; + + // This is the old interface, kept around for now to stay + // backwards-compatible. + CodeMirror.showHint = function (cm, getHints, options) { + if (!getHints) return cm.showHint(options); + if (options && options.async) getHints.async = true; + var newOpts = {hint: getHints}; + if (options) for (var prop in options) newOpts[prop] = options[prop]; + return cm.showHint(newOpts); + }; + + CodeMirror.defineExtension("showHint", function (options) { + options = parseOptions(this, this.getCursor("start"), options); + var selections = this.listSelections() + if (selections.length > 1) return; + // By default, don't allow completion when something is selected. + // A hint function can have a `supportsSelection` property to + // indicate that it can handle selections. + if (this.somethingSelected()) { + if (!options.hint.supportsSelection) return; + // Don't try with cross-line selections + for (var i = 0; i < selections.length; i++) + if (selections[i].head.line != selections[i].anchor.line) return; + } + if (this.state.completionActive) this.state.completionActive.close(); + var completion = this.state.completionActive = new Completion(this, options); + if (!completion.options.hint) return; + + CodeMirror.signal(this, "startCompletion", this); + completion.update(true); + + cb && cb({completion}) + }); + + CodeMirror.defineExtension("closeHint", function () { + if (this.state.completionActive) this.state.completionActive.close() + }) + + function Completion(cm, options) { + this.cm = cm; + this.options = options; + this.widget = null; + this.debounce = 0; + this.tick = 0; + this.startPos = this.cm.getCursor("start"); + this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length; + + if (this.options.updateOnCursorActivity) { + var self = this; + cm.on("cursorActivity", this.activityFunc = function () { + self.cursorActivity(); + }); + } + } + + var requestAnimationFrame = window.requestAnimationFrame || function (fn) { + return setTimeout(fn, 1000 / 60); + }; + var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout; + + Completion.prototype = { + close: function () { + if (!this.active()) return; + this.cm.state.completionActive = null; + this.tick = null; + if (this.options.updateOnCursorActivity) { + this.cm.off("cursorActivity", this.activityFunc); + } + + if (this.widget && this.data) CodeMirror.signal(this.data, "close"); + if (this.widget) this.widget.close(); + CodeMirror.signal(this.cm, "endCompletion", this.cm); + }, + + active: function () { + return this.cm.state.completionActive == this; + }, + + pick: function (data, i) { + var completion = data.list[i], self = this; + this.cm.operation(function () { + if (completion.hint) + completion.hint(self.cm, data, completion); + else + self.cm.replaceRange(getText(completion), completion.from || data.from, + completion.to || data.to, "complete"); + CodeMirror.signal(data, "pick", completion); + self.cm.scrollIntoView(); + }); + if (this.options.closeOnPick) { + this.close(); + } + }, + + cursorActivity: function () { + if (this.debounce) { + cancelAnimationFrame(this.debounce); + this.debounce = 0; + } + + var identStart = this.startPos; + if (this.data) { + identStart = this.data.from; + } + + var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line); + if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch || + pos.ch < identStart.ch || this.cm.somethingSelected() || + (!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) { + this.close(); + } else { + var self = this; + this.debounce = requestAnimationFrame(function () { + self.update(); + }); + if (this.widget) this.widget.disable(); + } + }, + + update: function (first) { + if (this.tick == null) return + var self = this, myTick = ++this.tick + fetchHints(this.options.hint, this.cm, this.options, function (data) { + if (self.tick == myTick) self.finishUpdate(data, first) + }) + }, + + finishUpdate: function (data, first) { + if (this.data) CodeMirror.signal(this.data, "update"); + + var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle); + if (this.widget) this.widget.close(); + + this.data = data; + + if (data && data.list.length) { + if (picked && data.list.length == 1) { + this.pick(data, 0); + } else { + this.widget = new Widget(this, data); + CodeMirror.signal(data, "shown"); + } + } + } + }; + + function parseOptions(cm, pos, options) { + var editor = cm.options.hintOptions; + var out = {}; + for (var prop in defaultOptions) out[prop] = defaultOptions[prop]; + if (editor) for (var prop in editor) + if (editor[prop] !== undefined) out[prop] = editor[prop]; + if (options) for (var prop in options) + if (options[prop] !== undefined) out[prop] = options[prop]; + if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos) + return out; + } + + function getText(completion) { + if (typeof completion == "string") return completion; + else return completion.text; + } + + function buildKeyMap(completion, handle) { + var baseMap = { + Up: function () { + handle.moveFocus(-1); + }, + Down: function () { + handle.moveFocus(1); + }, + PageUp: function () { + handle.moveFocus(-handle.menuSize() + 1, true); + }, + PageDown: function () { + handle.moveFocus(handle.menuSize() - 1, true); + }, + Home: function () { + handle.setFocus(0); + }, + End: function () { + handle.setFocus(handle.length - 1); + }, + // Enter: handle.pick, + // Tab: handle.pick, + Tab: keyboardEnter, + Enter: keyboardEnter, + Esc: handle.close + }; + + var mac = /Mac/.test(navigator.platform); + + if (mac) { + baseMap["Ctrl-P"] = function () { + handle.moveFocus(-1); + }; + baseMap["Ctrl-N"] = function () { + handle.moveFocus(1); + }; + } + + var custom = completion.options.customKeys; + var ourMap = custom ? {} : baseMap; + + function addBinding(key, val) { + var bound; + if (typeof val != "string") + bound = function (cm) { + return val(cm, handle); + }; + // This mechanism is deprecated + else if (baseMap.hasOwnProperty(val)) + bound = baseMap[val]; + else + bound = val; + ourMap[key] = bound; + } + + if (custom) + for (var key in custom) if (custom.hasOwnProperty(key)) + addBinding(key, custom[key]); + var extra = completion.options.extraKeys; + if (extra) + for (var key in extra) if (extra.hasOwnProperty(key)) + addBinding(key, extra[key]); + return ourMap; + } + + function getHintElement(hintsElement, el) { + while (el && el != hintsElement) { + if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el; + el = el.parentNode; + } + } + + function Widget(completion, data) { + this.id = "cm-complete-" + Math.floor(Math.random(1e6)) + this.completion = completion; + this.data = data; + this.picked = false; + var widget = this, cm = completion.cm; + var ownerDocument = cm.getInputField().ownerDocument; + var parentWindow = ownerDocument.defaultView || ownerDocument.parentWindow; + + var hints = this.hints = ownerDocument.createElement("ul"); + // $(hints).append(` + //

lalallalla

+ // `) + hints.setAttribute("role", "listbox") + hints.setAttribute("aria-expanded", "true") + hints.id = this.id + var theme = completion.cm.options.theme; + hints.className = "CodeMirror-hints " + theme; + this.selectedHint = data.selectedHint || 0; + + var completions = data.list; + for (var i = 0; i < completions.length; ++i) { + var elt = hints.appendChild(ownerDocument.createElement("li")), cur = completions[i]; + var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS); + if (cur.className != null) className = cur.className + " " + className; + elt.className = className; + if (i == this.selectedHint) elt.setAttribute("aria-selected", "true") + elt.id = this.id + "-" + i + elt.setAttribute("role", "option") + if (cur.render) cur.render(elt, data, cur); + else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur))); + elt.hintId = i; + } + + var container = completion.options.container || ownerDocument.body; + var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null); + var left = pos.left, top = pos.bottom, below = true; + var offsetLeft = 0, offsetTop = 0; + if (container !== ownerDocument.body) { + // We offset the cursor position because left and top are relative to the offsetParent's top left corner. + var isContainerPositioned = ['absolute', 'relative', 'fixed'].indexOf(parentWindow.getComputedStyle(container).position) !== -1; + var offsetParent = isContainerPositioned ? container : container.offsetParent; + var offsetParentPosition = offsetParent.getBoundingClientRect(); + var bodyPosition = ownerDocument.body.getBoundingClientRect(); + offsetLeft = (offsetParentPosition.left - bodyPosition.left - offsetParent.scrollLeft); + offsetTop = (offsetParentPosition.top - bodyPosition.top - offsetParent.scrollTop); + } + hints.style.left = (left - offsetLeft) + "px"; + hints.style.top = (top - offsetTop) + "px"; + // todo 隐藏codemirror自带的提示 + hints.style.display = 'none' + + // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor. + var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth); + var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight); + + //不用默认的DOM 下拉提示 + // container.appendChild(hints); + hints.remove() + + cm.getInputField().setAttribute("aria-autocomplete", "list") + cm.getInputField().setAttribute("aria-owns", this.id) + cm.getInputField().setAttribute("aria-activedescendant", this.id + "-" + this.selectedHint) + + var box = completion.options.moveOnOverlap ? hints.getBoundingClientRect() : new DOMRect(); + var scrolls = completion.options.paddingForScrollbar ? hints.scrollHeight > hints.clientHeight + 1 : false; + + // Compute in the timeout to avoid reflow on init + var startScroll; + setTimeout(function () { + startScroll = cm.getScrollInfo(); + }); + + var overlapY = box.bottom - winH; + if (overlapY > 0) { + var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top); + if (curTop - height > 0) { // Fits above cursor + hints.style.top = (top = pos.top - height - offsetTop) + "px"; + below = false; + } else if (height > winH) { + hints.style.height = (winH - 5) + "px"; + hints.style.top = (top = pos.bottom - box.top - offsetTop) + "px"; + var cursor = cm.getCursor(); + if (data.from.ch != cursor.ch) { + pos = cm.cursorCoords(cursor); + hints.style.left = (left = pos.left - offsetLeft) + "px"; + box = hints.getBoundingClientRect(); + } + } + } + var overlapX = box.right - winW; + if (scrolls) overlapX += cm.display.nativeBarWidth; + if (overlapX > 0) { + if (box.right - box.left > winW) { + hints.style.width = (winW - 5) + "px"; + overlapX -= (box.right - box.left) - winW; + } + hints.style.left = (left = Math.max(pos.left - overlapX - offsetLeft, 0)) + "px"; + } + if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling) + node.style.paddingRight = cm.display.nativeBarWidth + "px" + + // debugger + cm.addKeyMap(this.keyMap = buildKeyMap(completion, { + moveFocus: function (n, avoidWrap) { + n === -1 ? keyboardUp && keyboardUp() : keyboardDown && keyboardDown() + widget.changeActive(widget.selectedHint + n, avoidWrap); + }, + setFocus: function (n) { + widget.changeActive(n); + }, + menuSize: function () { + return widget.screenAmount(); + }, + length: completions.length, + close: function () { + completion.close(); + }, + pick: function () { + widget.pick(); + }, + data: data + })); + + if (completion.options.closeOnUnfocus) { + var closingOnBlur; + cm.on("blur", this.onBlur = function () { + closingOnBlur = setTimeout(function () { + completion.close(); + }, 100); + }); + cm.on("focus", this.onFocus = function () { + clearTimeout(closingOnBlur); + }); + } + + cm.on("scroll", this.onScroll = function () { + var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect(); + if (!startScroll) startScroll = cm.getScrollInfo(); + var newTop = top + startScroll.top - curScroll.top; + var point = newTop - (parentWindow.pageYOffset || (ownerDocument.documentElement || ownerDocument.body).scrollTop); + if (!below) point += hints.offsetHeight; + if (point <= editor.top || point >= editor.bottom) return completion.close(); + hints.style.top = newTop + "px"; + hints.style.left = (left + startScroll.left - curScroll.left) + "px"; + }); + + CodeMirror.on(hints, "dblclick", function (e) { + var t = getHintElement(hints, e.target || e.srcElement); + if (t && t.hintId != null) { + widget.changeActive(t.hintId); + widget.pick(); + } + }); + + CodeMirror.on(hints, "click", function (e) { + var t = getHintElement(hints, e.target || e.srcElement); + if (t && t.hintId != null) { + widget.changeActive(t.hintId); + if (completion.options.completeOnSingleClick) widget.pick(); + } + }); + + CodeMirror.on(hints, "mousedown", function () { + setTimeout(function () { + cm.focus(); + }, 20); + }); + + // The first hint doesn't need to be scrolled to on init + var selectedHintRange = this.getSelectedHintRange(); + if (selectedHintRange.from !== 0 || selectedHintRange.to !== 0) { + this.scrollToActive(); + } + + CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]); + return true; + } + + Widget.prototype = { + close: function () { + if (this.completion.widget != this) return; + this.completion.widget = null; + if (this.hints.parentNode) this.hints.parentNode.removeChild(this.hints); + this.completion.cm.removeKeyMap(this.keyMap); + var input = this.completion.cm.getInputField() + input.removeAttribute("aria-activedescendant") + input.removeAttribute("aria-owns") + + var cm = this.completion.cm; + if (this.completion.options.closeOnUnfocus) { + cm.off("blur", this.onBlur); + cm.off("focus", this.onFocus); + } + cm.off("scroll", this.onScroll); + }, + + disable: function () { + this.completion.cm.removeKeyMap(this.keyMap); + var widget = this; + this.keyMap = { + Enter: function () { + widget.picked = true; + } + }; + this.completion.cm.addKeyMap(this.keyMap); + }, + + pick: function () { + this.completion.pick(this.data, this.selectedHint); + }, + + changeActive: function (i, avoidWrap) { + if (i >= this.data.list.length) + i = avoidWrap ? this.data.list.length - 1 : 0; + else if (i < 0) + i = avoidWrap ? 0 : this.data.list.length - 1; + if (this.selectedHint == i) return; + var node = this.hints.childNodes[this.selectedHint]; + if (node) { + node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, ""); + node.removeAttribute("aria-selected") + } + node = this.hints.childNodes[this.selectedHint = i]; + node.className += " " + ACTIVE_HINT_ELEMENT_CLASS; + node.setAttribute("aria-selected", "true") + this.completion.cm.getInputField().setAttribute("aria-activedescendant", node.id) + this.scrollToActive() + CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node); + }, + + scrollToActive: function () { + var selectedHintRange = this.getSelectedHintRange(); + var node1 = this.hints.childNodes[selectedHintRange.from]; + var node2 = this.hints.childNodes[selectedHintRange.to]; + var firstNode = this.hints.firstChild; + if (node1.offsetTop < this.hints.scrollTop) + this.hints.scrollTop = node1.offsetTop - firstNode.offsetTop; + else if (node2.offsetTop + node2.offsetHeight > this.hints.scrollTop + this.hints.clientHeight) + this.hints.scrollTop = node2.offsetTop + node2.offsetHeight - this.hints.clientHeight + firstNode.offsetTop; + }, + + screenAmount: function () { + return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1; + }, + + getSelectedHintRange: function () { + var margin = this.completion.options.scrollMargin || 0; + return { + from: Math.max(0, this.selectedHint - margin), + to: Math.min(this.data.list.length - 1, this.selectedHint + margin), + }; + } + }; + + function applicableHelpers(cm, helpers) { + if (!cm.somethingSelected()) return helpers + var result = [] + for (var i = 0; i < helpers.length; i++) + if (helpers[i].supportsSelection) result.push(helpers[i]) + return result + } + + function fetchHints(hint, cm, options, callback) { + if (hint.async) { + hint(cm, callback, options) + } else { + var result = hint(cm, options) + if (result && result.then) result.then(callback) + else callback(result) + } + } + + function resolveAutoHints(cm, pos) { + var helpers = cm.getHelpers(pos, "hint"), words + if (helpers.length) { + var resolved = function (cm, callback, options) { + var app = applicableHelpers(cm, helpers); + + function run(i) { + if (i == app.length) return callback(null) + fetchHints(app[i], cm, options, function (result) { + if (result && result.list.length > 0) callback(result) + else run(i + 1) + }) + } + + run(0) + } + resolved.async = true + resolved.supportsSelection = true + return resolved + } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) { + return function (cm) { + return CodeMirror.hint.fromList(cm, {words: words}) + } + } else if (CodeMirror.hint.anyword) { + return function (cm, options) { + return CodeMirror.hint.anyword(cm, options) + } + } else { + return function () { + } + } + } + + CodeMirror.registerHelper("hint", "auto", { + resolve: resolveAutoHints + }); + + CodeMirror.registerHelper("hint", "fromList", function (cm, options) { + var cur = cm.getCursor(), token = cm.getTokenAt(cur) + var term, from = CodeMirror.Pos(cur.line, token.start), to = cur + if (token.start < cur.ch && /\w/.test(token.string.charAt(cur.ch - token.start - 1))) { + term = token.string.substr(0, cur.ch - token.start) + } else { + term = "" + from = cur + } + var found = []; + for (var i = 0; i < options.words.length; i++) { + var word = options.words[i]; + if (word.slice(0, term.length) == term) + found.push(word); + } + + if (found.length) return {list: found, from: from, to: to}; + }); + + CodeMirror.commands.autocomplete = CodeMirror.showHint; + + var defaultOptions = { + hint: CodeMirror.hint.auto, + completeSingle: true, + alignWithWord: true, + closeCharacters: /[\s()\[\]{};:>,]/, + + closeOnPick: false, + closeOnUnfocus: false, //阻止提示信息 失焦关闭 + // closeOnUnfocus: false, + + updateOnCursorActivity: true, + completeOnSingleClick: true, + container: null, + customKeys: null, + extraKeys: null, + paddingForScrollbar: true, + moveOnOverlap: true, + }; + CodeMirror.defineOption("hintOptions", null); + +} diff --git a/src/components/advancedSearch/showhint/TextSearch/matchRelatedInfo.js b/src/components/advancedSearch/showhint/TextSearch/matchRelatedInfo.js new file mode 100644 index 00000000..ce581dbb --- /dev/null +++ b/src/components/advancedSearch/showhint/TextSearch/matchRelatedInfo.js @@ -0,0 +1,227 @@ +//正则 向前去找关键字 +/* 用于匹配关系数据 */ +function matchOperator(CodeMirror, hintParams = {}) { + var editor = hintParams.editor; + var Pos = CodeMirror.Pos + var cur = hintParams.cur; + var token = hintParams.token; + if (!editor) { + return + } + + + var start = token.start; + var cont = true; + var leftTokenGroup = []; + while (cont) { + start = token.start; + leftTokenGroup.unshift(token); + token = editor.getTokenAt(Pos(cur.line, token.start)); + cont = !(token.string.match(/^[ ]*$/) || start === 0); //只用空格做终止条件 + } + + var cursorLeftString = editor.getRange(Pos(cur.line, leftTokenGroup[0].start), Pos(cur.line, leftTokenGroup[leftTokenGroup.length - 1].end)) + + //判断是不是满足 运算符 表达式的正则 + //test 如果是ig 会改变正则指针: https://my.oschina.net/jamesview/blog/5460753 + var reg = /^(.*?)(=|!=|>|<|>=|<=)([^ ]*?)$/; + if (reg.test(cursorLeftString)) { + var execArr = reg.exec(cursorLeftString) || [] + return { + leftTokenGroup, + cursorLeftString, + label: execArr[1], + sign: execArr[2], + value: execArr[3], + } + } + return null +} + +function matchCommon(CodeMirror, hintParams = {}) { + //通用情况 QUANTILE(expr,level) 左括号右侧第一个就是 关键字 + var editor = hintParams.editor; + var Pos = CodeMirror.Pos + var cur = hintParams.cur; + var token = hintParams.token; + if (!editor) { + return + } + + + var start = token.start; + var cont = true; + var leftTokenGroup = []; + while (cont) { + start = token.start; + leftTokenGroup.unshift(token); + token = editor.getTokenAt(Pos(cur.line, token.start)); + cont = !(token.string.match(/^[ (]*$/) || start === 0); //括号或者空格为终止条件 + + //括号补上 + if (token.string === '(') { + leftTokenGroup.unshift(token); + } + } + + var cursorLeftString = editor.getRange(Pos(cur.line, leftTokenGroup[0].start), Pos(cur.line, leftTokenGroup[leftTokenGroup.length - 1].end)) + + //判断是不是满足 运算符 表达式的正则 + var reg = /^\((.*?),([^ ]*)$/; + if (reg.test(cursorLeftString)) { + var execArr = reg.exec(cursorLeftString) || [] + return { + leftTokenGroup, + cursorLeftString, + label: execArr[1], + sign: 'unknown', //没必要判断 + value: execArr[2], + } + } + return null +} + +function matchIn(CodeMirror, hintParams = {}) { + //in 的情况比较特殊 + //通用情况 expr not in (values) expr in (values) + var editor = hintParams.editor; + var Pos = CodeMirror.Pos + var cur = hintParams.cur; + var token = hintParams.token; + if (!editor) { + return + } + + + var start = token.start; + var cont = true; + var leftTokenGroup = []; + + //找到左括号 + while (cont) { + start = token.start; + leftTokenGroup.unshift(token); + token = editor.getTokenAt(Pos(cur.line, token.start)); + cont = !(token.string.match(/^[ (]*$/) || start === 0); //括号或者空格为终止条件 + //左括号补上 + if (token.string === '(') { + leftTokenGroup.unshift(token); + } + } + + //左括号继续向右找 + cont = true + while (cont) { + start = token.start; + leftTokenGroup.unshift(token); + token = editor.getTokenAt(Pos(cur.line, token.start)); + cont = !(!token.string.match(/^(in|not| )/g) || start === 0); //括号或者空格为终止条件 + + //string-2 + if (token.type === 'string-2') { + leftTokenGroup.unshift(token); + } + } + var cursorLeftString = editor.getRange(Pos(cur.line, leftTokenGroup[0].start), Pos(cur.line, leftTokenGroup[leftTokenGroup.length - 1].end)) + + //判断是不是满足 运算符 表达式的正则 + var reg = /^(.*?)[ ]+((?:not[ ]+)?in)[ ]*\(([^ ]*?)$/i; + if (reg.test(cursorLeftString)) { + var execArr = reg.exec(cursorLeftString) || [] + return { + leftTokenGroup, + cursorLeftString, + label: execArr[1], + sign: execArr[2], + value: execArr[3], + } + } + return null +} + +function matchLike(CodeMirror, hintParams = {}) { + //like 的情况比较特殊 expr like value , expr not like value + var editor = hintParams.editor; + var Pos = CodeMirror.Pos + var cur = hintParams.cur; + var token = hintParams.token; + if (!editor) { + return + } + + + var start = token.start; + var cont = true; + var leftTokenGroup = []; + + //找到左括号 + while (cont) { + start = token.start; + leftTokenGroup.unshift(token); + token = editor.getTokenAt(Pos(cur.line, token.start)); + cont = !(token.string.match(/^[ ]*$/) || start === 0); //括号或者空格为终止条件 + } + + //左括号继续向右找 + cont = true + while (cont) { + start = token.start; + leftTokenGroup.unshift(token); + token = editor.getTokenAt(Pos(cur.line, token.start)); + cont = !(!token.string.match(/^(like|not| )/g) || start === 0); //括号或者空格为终止条件 + + //string-2 + if (token.type === 'string-2') { + leftTokenGroup.unshift(token); + } + } + var cursorLeftString = editor.getRange(Pos(cur.line, leftTokenGroup[0].start), Pos(cur.line, leftTokenGroup[leftTokenGroup.length - 1].end)) + + //判断是不是满足 运算符 表达式的正则 + var reg = /^(.*?)[ ]+((?:not[ ]+)?like)[ ]*([^ ]*?)$/i; + if (reg.test(cursorLeftString)) { + var execArr = reg.exec(cursorLeftString) || [] + return { + leftTokenGroup, + cursorLeftString, + label: execArr[1], + sign: execArr[2], + value: execArr[3], + } + } + return null + +} + +export const matchMain = (CodeMirror, params, manualParams = {}) => { + var matchRes = null + //匹配 运算符表达式 + matchRes = matchOperator(CodeMirror, manualParams) + if (matchRes) { + return matchRes + } + + //匹配 in表达式 + matchRes = matchIn(CodeMirror, manualParams) + if (matchRes) { + return matchRes + } + + //匹配 like表达式 + matchRes = matchLike(CodeMirror, manualParams) + if (matchRes) { + return matchRes + } + + //这里缺少一个对 count(distinct expr) 模式的匹配, 感觉大数据涉及存在缺陷, 先暂时不写 + + + //匹配 其他表达式 (expr,value1,value2....) 模式的匹配 + matchRes = matchCommon(CodeMirror, manualParams) + if (matchRes) { + // 说明这是一个 运算符表达式 + return matchRes + } + + return matchRes +} diff --git a/src/components/advancedSearch/showhint/TextSearch/show-hint.js b/src/components/advancedSearch/showhint/TextSearch/show-hint.js new file mode 100644 index 00000000..9d268d3a --- /dev/null +++ b/src/components/advancedSearch/showhint/TextSearch/show-hint.js @@ -0,0 +1,591 @@ +export default function showHint(CodeMirror) { + "use strict"; + + var HINT_ELEMENT_CLASS = "CodeMirror-hint"; + var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active"; + + // This is the old interface, kept around for now to stay + // backwards-compatible. + CodeMirror.showHint = function (cm, getHints, options) { + if (!getHints) return cm.showHint(options); + if (options && options.async) getHints.async = true; + var newOpts = {hint: getHints}; + if (options) for (var prop in options) newOpts[prop] = options[prop]; + return cm.showHint(newOpts); + }; + + CodeMirror.defineExtension("showHint", function (options) { + options = parseOptions(this, this.getCursor("start"), options); + var selections = this.listSelections() + if (selections.length > 1) return; + // By default, don't allow completion when something is selected. + // A hint function can have a `supportsSelection` property to + // indicate that it can handle selections. + if (this.somethingSelected()) { + if (!options.hint.supportsSelection) return; + // Don't try with cross-line selections + for (var i = 0; i < selections.length; i++) + if (selections[i].head.line != selections[i].anchor.line) return; + } + + if (this.state.completionActive) this.state.completionActive.close(); + var completion = this.state.completionActive = new Completion(this, options); + if (!completion.options.hint) return; + + CodeMirror.signal(this, "startCompletion", this); + completion.update(true); + }); + + CodeMirror.defineExtension("closeHint", function () { + if (this.state.completionActive) this.state.completionActive.close() + }) + + function Completion(cm, options) { + this.cm = cm; + this.options = options; + this.widget = null; + this.debounce = 0; + this.tick = 0; + this.startPos = this.cm.getCursor("start"); + this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length; + + if (this.options.updateOnCursorActivity) { + var self = this; + cm.on("cursorActivity", this.activityFunc = function () { + self.cursorActivity(); + }); + } + } + + var requestAnimationFrame = window.requestAnimationFrame || function (fn) { + return setTimeout(fn, 1000 / 60); + }; + var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout; + + Completion.prototype = { + close: function () { + if (!this.active()) return; + this.cm.state.completionActive = null; + this.tick = null; + if (this.options.updateOnCursorActivity) { + this.cm.off("cursorActivity", this.activityFunc); + } + + if (this.widget && this.data) CodeMirror.signal(this.data, "close"); + if (this.widget) this.widget.close(); + CodeMirror.signal(this.cm, "endCompletion", this.cm); + }, + + active: function () { + return this.cm.state.completionActive == this; + }, + + pick: function (data, i) { + var completion = data.list[i], self = this; + this.cm.operation(function () { + if (completion.hint) + completion.hint(self.cm, data, completion); + else + self.cm.replaceRange(getText(completion), completion.from || data.from, + completion.to || data.to, "complete"); + CodeMirror.signal(data, "pick", completion); + self.cm.scrollIntoView(); + }); + if (this.options.closeOnPick) { + this.close(); + } + }, + + cursorActivity: function () { + if (this.debounce) { + cancelAnimationFrame(this.debounce); + this.debounce = 0; + } + + var identStart = this.startPos; + if (this.data) { + identStart = this.data.from; + } + + var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line); + if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch || + pos.ch < identStart.ch || this.cm.somethingSelected() || + (!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) { + this.close(); + } else { + var self = this; + this.debounce = requestAnimationFrame(function () { + self.update(); + }); + if (this.widget) this.widget.disable(); + } + }, + + update: function (first) { + if (this.tick == null) return + var self = this, myTick = ++this.tick + fetchHints(this.options.hint, this.cm, this.options, function (data) { + if (self.tick == myTick) self.finishUpdate(data, first) + }) + }, + + finishUpdate: function (data, first) { + if (this.data) CodeMirror.signal(this.data, "update"); + + var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle); + if (this.widget) this.widget.close(); + + this.data = data; + + if (data && data.list.length) { + if (picked && data.list.length == 1) { + this.pick(data, 0); + } else { + this.widget = new Widget(this, data); + CodeMirror.signal(data, "shown"); + } + } + } + }; + + function parseOptions(cm, pos, options) { + var editor = cm.options.hintOptions; + var out = {}; + for (var prop in defaultOptions) out[prop] = defaultOptions[prop]; + if (editor) for (var prop in editor) + if (editor[prop] !== undefined) out[prop] = editor[prop]; + if (options) for (var prop in options) + if (options[prop] !== undefined) out[prop] = options[prop]; + if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos) + return out; + } + + function getText(completion) { + if (typeof completion == "string") return completion; + else return completion.text; + } + + function buildKeyMap(completion, handle) { + var baseMap = { + Up: function () { + handle.moveFocus(-1); + }, + Down: function () { + handle.moveFocus(1); + }, + PageUp: function () { + handle.moveFocus(-handle.menuSize() + 1, true); + }, + PageDown: function () { + handle.moveFocus(handle.menuSize() - 1, true); + }, + Home: function () { + handle.setFocus(0); + }, + End: function () { + handle.setFocus(handle.length - 1); + }, + Enter: handle.pick, + Tab: handle.pick, + Esc: handle.close + }; + + var mac = /Mac/.test(navigator.platform); + + if (mac) { + baseMap["Ctrl-P"] = function () { + handle.moveFocus(-1); + }; + baseMap["Ctrl-N"] = function () { + handle.moveFocus(1); + }; + } + + var custom = completion.options.customKeys; + var ourMap = custom ? {} : baseMap; + + function addBinding(key, val) { + var bound; + if (typeof val != "string") + bound = function (cm) { + return val(cm, handle); + }; + // This mechanism is deprecated + else if (baseMap.hasOwnProperty(val)) + bound = baseMap[val]; + else + bound = val; + ourMap[key] = bound; + } + + if (custom) + for (var key in custom) if (custom.hasOwnProperty(key)) + addBinding(key, custom[key]); + var extra = completion.options.extraKeys; + if (extra) + for (var key in extra) if (extra.hasOwnProperty(key)) + addBinding(key, extra[key]); + return ourMap; + } + + function getHintElement(hintsElement, el) { + while (el && el != hintsElement) { + if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el; + el = el.parentNode; + } + } + + function Widget(completion, data) { + this.id = "cm-complete-" + Math.floor(Math.random(1e6)) + this.completion = completion; + this.data = data; + this.picked = false; + var widget = this, cm = completion.cm; + var ownerDocument = cm.getInputField().ownerDocument; + var parentWindow = ownerDocument.defaultView || ownerDocument.parentWindow; + + var hints = this.hints = ownerDocument.createElement("ul"); + // $(hints).append(` + //

lalallalla

+ // `) + hints.setAttribute("role", "listbox") + hints.setAttribute("aria-expanded", "true") + hints.id = this.id + var theme = completion.cm.options.theme; + hints.className = "CodeMirror-hints " + theme; + this.selectedHint = data.selectedHint || 0; + + var completions = data.list; + for (var i = 0; i < completions.length; ++i) { + var elt = hints.appendChild(ownerDocument.createElement("li")), cur = completions[i]; + var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS); + if (cur.className != null) className = cur.className + " " + className; + elt.className = className; + if (i == this.selectedHint) elt.setAttribute("aria-selected", "true") + elt.id = this.id + "-" + i + elt.setAttribute("role", "option") + if (cur.render) cur.render(elt, data, cur); + else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur))); + elt.hintId = i; + } + + var container = completion.options.container || ownerDocument.body; + var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null); + var left = pos.left, top = pos.bottom, below = true; + var offsetLeft = 0, offsetTop = 0; + if (container !== ownerDocument.body) { + // We offset the cursor position because left and top are relative to the offsetParent's top left corner. + var isContainerPositioned = ['absolute', 'relative', 'fixed'].indexOf(parentWindow.getComputedStyle(container).position) !== -1; + var offsetParent = isContainerPositioned ? container : container.offsetParent; + var offsetParentPosition = offsetParent.getBoundingClientRect(); + var bodyPosition = ownerDocument.body.getBoundingClientRect(); + offsetLeft = (offsetParentPosition.left - bodyPosition.left - offsetParent.scrollLeft); + offsetTop = (offsetParentPosition.top - bodyPosition.top - offsetParent.scrollTop); + } + hints.style.left = (left - offsetLeft) + "px"; + hints.style.top = (top - offsetTop) + "px"; + // todo 隐藏codemirror自带的提示 + hints.style.display = 'none' + + // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor. + var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth); + var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight); + //在这里 添加的DOM 元素 -- 该方案 实现复杂算了吧 + container.appendChild(hints); +// debugger +// $(container).append( +// ` +//
+//

hahah

+// ${ hints } +//
+// ` +// ) + cm.getInputField().setAttribute("aria-autocomplete", "list") + cm.getInputField().setAttribute("aria-owns", this.id) + cm.getInputField().setAttribute("aria-activedescendant", this.id + "-" + this.selectedHint) + + var box = completion.options.moveOnOverlap ? hints.getBoundingClientRect() : new DOMRect(); + var scrolls = completion.options.paddingForScrollbar ? hints.scrollHeight > hints.clientHeight + 1 : false; + + // Compute in the timeout to avoid reflow on init + var startScroll; + setTimeout(function () { + startScroll = cm.getScrollInfo(); + }); + + var overlapY = box.bottom - winH; + if (overlapY > 0) { + var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top); + if (curTop - height > 0) { // Fits above cursor + hints.style.top = (top = pos.top - height - offsetTop) + "px"; + below = false; + } else if (height > winH) { + hints.style.height = (winH - 5) + "px"; + hints.style.top = (top = pos.bottom - box.top - offsetTop) + "px"; + var cursor = cm.getCursor(); + if (data.from.ch != cursor.ch) { + pos = cm.cursorCoords(cursor); + hints.style.left = (left = pos.left - offsetLeft) + "px"; + box = hints.getBoundingClientRect(); + } + } + } + var overlapX = box.right - winW; + if (scrolls) overlapX += cm.display.nativeBarWidth; + if (overlapX > 0) { + if (box.right - box.left > winW) { + hints.style.width = (winW - 5) + "px"; + overlapX -= (box.right - box.left) - winW; + } + hints.style.left = (left = Math.max(pos.left - overlapX - offsetLeft, 0)) + "px"; + } + if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling) + node.style.paddingRight = cm.display.nativeBarWidth + "px" + + // debugger + cm.addKeyMap(this.keyMap = buildKeyMap(completion, { + moveFocus: function (n, avoidWrap) { + widget.changeActive(widget.selectedHint + n, avoidWrap); + }, + setFocus: function (n) { + widget.changeActive(n); + }, + menuSize: function () { + return widget.screenAmount(); + }, + length: completions.length, + close: function () { + completion.close(); + }, + pick: function () { + widget.pick(); + }, + data: data + })); + + if (completion.options.closeOnUnfocus) { + var closingOnBlur; + cm.on("blur", this.onBlur = function () { + closingOnBlur = setTimeout(function () { + completion.close(); + }, 100); + }); + cm.on("focus", this.onFocus = function () { + clearTimeout(closingOnBlur); + }); + } + + cm.on("scroll", this.onScroll = function () { + var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect(); + if (!startScroll) startScroll = cm.getScrollInfo(); + var newTop = top + startScroll.top - curScroll.top; + var point = newTop - (parentWindow.pageYOffset || (ownerDocument.documentElement || ownerDocument.body).scrollTop); + if (!below) point += hints.offsetHeight; + if (point <= editor.top || point >= editor.bottom) return completion.close(); + hints.style.top = newTop + "px"; + hints.style.left = (left + startScroll.left - curScroll.left) + "px"; + }); + + CodeMirror.on(hints, "dblclick", function (e) { + var t = getHintElement(hints, e.target || e.srcElement); + if (t && t.hintId != null) { + widget.changeActive(t.hintId); + widget.pick(); + } + }); + + CodeMirror.on(hints, "click", function (e) { + var t = getHintElement(hints, e.target || e.srcElement); + if (t && t.hintId != null) { + widget.changeActive(t.hintId); + if (completion.options.completeOnSingleClick) widget.pick(); + } + }); + + CodeMirror.on(hints, "mousedown", function () { + setTimeout(function () { + cm.focus(); + }, 20); + }); + + // The first hint doesn't need to be scrolled to on init + var selectedHintRange = this.getSelectedHintRange(); + if (selectedHintRange.from !== 0 || selectedHintRange.to !== 0) { + this.scrollToActive(); + } + + CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]); + return true; + } + + Widget.prototype = { + close: function () { + if (this.completion.widget != this) return; + this.completion.widget = null; + if (this.hints.parentNode) this.hints.parentNode.removeChild(this.hints); + this.completion.cm.removeKeyMap(this.keyMap); + var input = this.completion.cm.getInputField() + input.removeAttribute("aria-activedescendant") + input.removeAttribute("aria-owns") + + var cm = this.completion.cm; + if (this.completion.options.closeOnUnfocus) { + cm.off("blur", this.onBlur); + cm.off("focus", this.onFocus); + } + cm.off("scroll", this.onScroll); + }, + + disable: function () { + this.completion.cm.removeKeyMap(this.keyMap); + var widget = this; + this.keyMap = { + Enter: function () { + widget.picked = true; + } + }; + this.completion.cm.addKeyMap(this.keyMap); + }, + + pick: function () { + this.completion.pick(this.data, this.selectedHint); + }, + + changeActive: function (i, avoidWrap) { + if (i >= this.data.list.length) + i = avoidWrap ? this.data.list.length - 1 : 0; + else if (i < 0) + i = avoidWrap ? 0 : this.data.list.length - 1; + if (this.selectedHint == i) return; + var node = this.hints.childNodes[this.selectedHint]; + if (node) { + node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, ""); + node.removeAttribute("aria-selected") + } + node = this.hints.childNodes[this.selectedHint = i]; + node.className += " " + ACTIVE_HINT_ELEMENT_CLASS; + node.setAttribute("aria-selected", "true") + this.completion.cm.getInputField().setAttribute("aria-activedescendant", node.id) + this.scrollToActive() + CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node); + }, + + scrollToActive: function () { + var selectedHintRange = this.getSelectedHintRange(); + var node1 = this.hints.childNodes[selectedHintRange.from]; + var node2 = this.hints.childNodes[selectedHintRange.to]; + var firstNode = this.hints.firstChild; + if (node1.offsetTop < this.hints.scrollTop) + this.hints.scrollTop = node1.offsetTop - firstNode.offsetTop; + else if (node2.offsetTop + node2.offsetHeight > this.hints.scrollTop + this.hints.clientHeight) + this.hints.scrollTop = node2.offsetTop + node2.offsetHeight - this.hints.clientHeight + firstNode.offsetTop; + }, + + screenAmount: function () { + return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1; + }, + + getSelectedHintRange: function () { + var margin = this.completion.options.scrollMargin || 0; + return { + from: Math.max(0, this.selectedHint - margin), + to: Math.min(this.data.list.length - 1, this.selectedHint + margin), + }; + } + }; + + function applicableHelpers(cm, helpers) { + if (!cm.somethingSelected()) return helpers + var result = [] + for (var i = 0; i < helpers.length; i++) + if (helpers[i].supportsSelection) result.push(helpers[i]) + return result + } + + function fetchHints(hint, cm, options, callback) { + if (hint.async) { + hint(cm, callback, options) + } else { + var result = hint(cm, options) + if (result && result.then) result.then(callback) + else callback(result) + } + } + + function resolveAutoHints(cm, pos) { + var helpers = cm.getHelpers(pos, "hint"), words + if (helpers.length) { + var resolved = function (cm, callback, options) { + var app = applicableHelpers(cm, helpers); + + function run(i) { + if (i == app.length) return callback(null) + fetchHints(app[i], cm, options, function (result) { + if (result && result.list.length > 0) callback(result) + else run(i + 1) + }) + } + + run(0) + } + resolved.async = true + resolved.supportsSelection = true + return resolved + } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) { + return function (cm) { + return CodeMirror.hint.fromList(cm, {words: words}) + } + } else if (CodeMirror.hint.anyword) { + return function (cm, options) { + return CodeMirror.hint.anyword(cm, options) + } + } else { + return function () { + } + } + } + + CodeMirror.registerHelper("hint", "auto", { + resolve: resolveAutoHints + }); + + CodeMirror.registerHelper("hint", "fromList", function (cm, options) { + var cur = cm.getCursor(), token = cm.getTokenAt(cur) + var term, from = CodeMirror.Pos(cur.line, token.start), to = cur + if (token.start < cur.ch && /\w/.test(token.string.charAt(cur.ch - token.start - 1))) { + term = token.string.substr(0, cur.ch - token.start) + } else { + term = "" + from = cur + } + var found = []; + for (var i = 0; i < options.words.length; i++) { + var word = options.words[i]; + if (word.slice(0, term.length) == term) + found.push(word); + } + + if (found.length) return {list: found, from: from, to: to}; + }); + + CodeMirror.commands.autocomplete = CodeMirror.showHint; + + var defaultOptions = { + hint: CodeMirror.hint.auto, + completeSingle: true, + alignWithWord: true, + closeCharacters: /[\s()\[\]{};:>,]/, + closeOnPick: true, + closeOnUnfocus: true, + updateOnCursorActivity: true, + completeOnSingleClick: true, + container: null, + customKeys: null, + extraKeys: null, + paddingForScrollbar: true, + moveOnOverlap: true, + }; + + CodeMirror.defineOption("hintOptions", null); +} diff --git a/src/components/advancedSearch/showhint/TextSearch/sql-hint.js b/src/components/advancedSearch/showhint/TextSearch/sql-hint.js new file mode 100644 index 00000000..8ac4f4d3 --- /dev/null +++ b/src/components/advancedSearch/showhint/TextSearch/sql-hint.js @@ -0,0 +1,372 @@ +import {cloneDeep} from 'lodash' +import {matchMain} from './matchRelatedInfo' + +export default function (CodeMirror, + { + dataset, + hinthook, //生成提示的hook 拦截 + keywordshook //关键字hook 在关键字里面 + } +) { + // "use strict"; + + var tables; + var defaultTable; + var keywords; + var identifierQuote; + var CONS = { + QUERY_DIV: ";", + ALIAS_KEYWORD: "AS" + }; + var Pos = CodeMirror.Pos, cmpPos = CodeMirror.cmpPos; + + function isArray(val) { + return Object.prototype.toString.call(val) == "[object Array]" + } + + function getKeywords(editor) { + var mode = editor.doc.modeOption; + if (mode === "sql") mode = "text/x-sql"; + keywords = CodeMirror.resolveMode(mode).keywords; + if (keywordshook) { + keywords = keywordshook(keywords, CodeMirror.resolveMode(mode)) || keywords + } + return keywords + } + + function getIdentifierQuote(editor) { + var mode = editor.doc.modeOption; + if (mode === "sql") mode = "text/x-sql"; + return CodeMirror.resolveMode(mode).identifierQuote || "`"; + } + + function getText(item) { + return typeof item == "string" ? item : item.text; + } + + function wrapTable(name, value) { + if (isArray(value)) value = {columns: value} + if (!value.text) value.text = name + return value + } + + function parseTables(input) { + //table 名称变大写 统一变成对象格式 columns text + var result = {} + if (isArray(input)) { + for (var i = input.length - 1; i >= 0; i--) { + var item = input[i] + result[getText(item).toUpperCase()] = wrapTable(getText(item), item) + } + } else if (input) { + for (var name in input) + result[name.toUpperCase()] = wrapTable(name, input[name]) + } + return result + } + + function getTable(name) { + return tables[name.toUpperCase()] + } + + function shallowClone(object) { + var result = {}; + for (var key in object) if (object.hasOwnProperty(key)) + result[key] = object[key]; + return result; + } + + function match(string, word) { + var len = string.length; + var sub = getText(word).substr(0, len); + return string.toUpperCase() === sub.toUpperCase(); + } + + function addMatches(result, search, wordlist, formatter) { + if (isArray(wordlist)) { + for (var i = 0; i < wordlist.length; i++) + if (match(search, wordlist[i])) result.push(formatter(wordlist[i])) + } else { + for (var word in wordlist) if (wordlist.hasOwnProperty(word)) { + var val = wordlist[word] + if (!val || val === true) + val = word + else + val = val.displayText ? {text: val.text, displayText: val.displayText} : val.text + if (match(search, val)) result.push(formatter(val)) + } + } + } + + function cleanName(name) { + // Get rid name from identifierQuote and preceding dot(.) + if (name.charAt(0) == ".") { + name = name.substr(1); + } + // replace duplicated identifierQuotes with single identifierQuotes + // and remove single identifierQuotes + var nameParts = name.split(identifierQuote + identifierQuote); + for (var i = 0; i < nameParts.length; i++) + nameParts[i] = nameParts[i].replace(new RegExp(identifierQuote, "g"), ""); + return nameParts.join(identifierQuote); + } + + function insertIdentifierQuotes(name) { + var nameParts = getText(name).split("."); + for (var i = 0; i < nameParts.length; i++) + nameParts[i] = identifierQuote + + // duplicate identifierQuotes + nameParts[i].replace(new RegExp(identifierQuote, "g"), identifierQuote + identifierQuote) + + identifierQuote; + var escaped = nameParts.join("."); + if (typeof name == "string") return escaped; + name = shallowClone(name); + name.text = escaped; + return name; + } + + function getLeftpart(cur, token, result, editor) { + var nameParts = []; + var start = token.start; + var cont = true; + while (cont) { + //全是空格 或者 是操作符 就接着往前找 + cont = ((token.type === 'operator' || token.string.match(/^[ ]*$/)) && start !== 0); + start = token.start; + nameParts.unshift(token.string); + token = editor.getTokenAt(Pos(cur.line, token.start)); + if (token.type === 'operator') { + cont = true; + token = editor.getTokenAt(Pos(cur.line, token.start)); + } + } + + return nameParts[0] + } + + function isRightpart(cur, token, result, editor) { + token = editor.getTokenAt(Pos(cur.line, token.start)); + return token.type === 'operator' + } + + function nameCompletion(cur, token, result, editor) { + // Try to complete table, column names and return start position of completion + var useIdentifierQuotes = false; + var nameParts = []; + var start = token.start; + var cont = true; + while (cont) { + cont = (token.string.charAt(0) == "."); + useIdentifierQuotes = useIdentifierQuotes || (token.string.charAt(0) == identifierQuote); + + start = token.start; + nameParts.unshift(cleanName(token.string)); + + token = editor.getTokenAt(Pos(cur.line, token.start)); + if (token.string == ".") { + cont = true; + token = editor.getTokenAt(Pos(cur.line, token.start)); + } + } + + // Try to complete table names + var string = nameParts.join("."); + addMatches(result, string, tables, function (w) { + return useIdentifierQuotes ? insertIdentifierQuotes(w) : w; + }); + + // Try to complete columns from defaultTable + addMatches(result, string, defaultTable, function (w) { + return useIdentifierQuotes ? insertIdentifierQuotes(w) : w; + }); + + // Try to complete columns + string = nameParts.pop(); + var table = nameParts.join("."); + + var alias = false; + var aliasTable = table; + // Check if table is available. If not, find table by Alias + if (!getTable(table)) { + var oldTable = table; + table = findTableByAlias(table, editor); + if (table !== oldTable) alias = true; + } + + var columns = getTable(table); + if (columns && columns.columns) + columns = columns.columns; + + if (columns) { + addMatches(result, string, columns, function (w) { + var tableInsert = table; + if (alias == true) tableInsert = aliasTable; + if (typeof w == "string") { + w = tableInsert + "." + w; + } else { + w = shallowClone(w); + w.text = tableInsert + "." + w.text; + } + return useIdentifierQuotes ? insertIdentifierQuotes(w) : w; + }); + } + return start; + } + + function eachWord(lineText, f) { + var words = lineText.split(/\s+/) + for (var i = 0; i < words.length; i++) + if (words[i]) f(words[i].replace(/[`,;]/g, '')) + } + + function findTableByAlias(alias, editor) { + var doc = editor.doc; + var fullQuery = doc.getValue(); + var aliasUpperCase = alias.toUpperCase(); + var previousWord = ""; + var table = ""; + var separator = []; + var validRange = { + start: Pos(0, 0), + end: Pos(editor.lastLine(), editor.getLineHandle(editor.lastLine()).length) + }; + + //add separator + var indexOfSeparator = fullQuery.indexOf(CONS.QUERY_DIV); + while (indexOfSeparator != -1) { + separator.push(doc.posFromIndex(indexOfSeparator)); + indexOfSeparator = fullQuery.indexOf(CONS.QUERY_DIV, indexOfSeparator + 1); + } + separator.unshift(Pos(0, 0)); + separator.push(Pos(editor.lastLine(), editor.getLineHandle(editor.lastLine()).text.length)); + + //find valid range + var prevItem = null; + var current = editor.getCursor() + for (var i = 0; i < separator.length; i++) { + if ((prevItem == null || cmpPos(current, prevItem) > 0) && cmpPos(current, separator[i]) <= 0) { + validRange = {start: prevItem, end: separator[i]}; + break; + } + prevItem = separator[i]; + } + + if (validRange.start) { + var query = doc.getRange(validRange.start, validRange.end, false); + + for (var i = 0; i < query.length; i++) { + var lineText = query[i]; + eachWord(lineText, function (word) { + var wordUpperCase = word.toUpperCase(); + if (wordUpperCase === aliasUpperCase && getTable(previousWord)) + table = previousWord; + if (wordUpperCase !== CONS.ALIAS_KEYWORD) + previousWord = word; + }); + if (table) break; + } + } + return table; + } + + CodeMirror.registerHelper("hint", "sql", function (editor, options) { + tables = parseTables(options && options.tables); + var defaultTableName = options && options.defaultTable; //默认table 名称 + var disableKeywords = options && options.disableKeywords; //禁用的keyword + defaultTable = defaultTableName && getTable(defaultTableName); + keywords = getKeywords(editor); //获取 定义defineMIME 时候的关键字参数 + identifierQuote = getIdentifierQuote(editor); //获取 引用标识符 + + if (defaultTableName && !defaultTable) + defaultTable = findTableByAlias(defaultTableName, editor); + + defaultTable = defaultTable || []; + + if (defaultTable.columns) + defaultTable = defaultTable.columns; + + var cur = editor.getCursor(); //line 当前行 ch 索引 sticky ?? + var result = []; + var token = editor.getTokenAt(cur), start, end, search; + if (token.end > cur.ch) { + token.end = cur.ch; + token.string = token.string.slice(0, cur.ch - token.start); + } + + //start end search 赋值 + // todo 此处允许字符串包含 . + // if (token.string.match(/^[.`"'\w@][\w$#]*/g)) { + if (token.string.match(/^[.`"'\w@][\w#]*/g)) { + search = token.string; + start = token.start; + end = token.end; + } else { + start = end = cur.ch; + search = ""; + } + + //对引用标识符 . 的使用,关联table 列 + if (search.charAt(0) == "." || search.charAt(0) == identifierQuote) { + start = nameCompletion(cur, token, result, editor); + } else { + var objectOrClass = function (w, className) { + if (typeof w === "object") { + w.className = className; + } else { + w = {text: w, className: className}; + } + return w; + }; + addMatches(result, search, defaultTable, function (w) { + return objectOrClass(w, "CodeMirror-hint-table CodeMirror-hint-default-table"); + }); + addMatches( + result, + search, + tables, function (w) { + return objectOrClass(w, "CodeMirror-hint-table"); + } + ); + if (!disableKeywords) + addMatches(result, search, keywords, function (w) { + return objectOrClass(w.toUpperCase(), "CodeMirror-hint-keyword"); + }); + } + //写入一个 钩子,在这里决定提示的内容 + if (hinthook) { + var params = { + search, //搜索 关键字 + keywords, //关键字列表 + }; + if (token.type === 'operator') { + params.leftpart = getLeftpart(cur, token, result, editor) || '' + } + if (isRightpart(cur, token, result, editor)) { + params.rightpart = token.string + } + + /* 之后的参数 是为manualHinthook 预备的 */ + + var manualParams = { + search, //搜索 关键字 + // keywords, //关键字列表 没啥用 + from: Pos(cur.line, start), + to: Pos(cur.line, end), + leftpart: getLeftpart(cur, token, result, editor) || '', + rightpart: params.rightpart, + list: cloneDeep(result), + editor, + token, + cur + } + + var refField = matchMain(CodeMirror, params, manualParams); + manualParams.refField = refField + manualParams.leftpart = refField?.label || manualParams.leftpart; + params.leftpart = refField?.label || params.leftpart; + + result = hinthook(result, params, manualParams) || result + } + return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)}; + }); +} diff --git a/src/components/advancedSearch/showhint/TextSearch/sql.js b/src/components/advancedSearch/showhint/TextSearch/sql.js new file mode 100644 index 00000000..4d188521 --- /dev/null +++ b/src/components/advancedSearch/showhint/TextSearch/sql.js @@ -0,0 +1,480 @@ +export default function (CodeMirror, {dataset, modehook}) { + // "use strict"; + CodeMirror.defineMode("sql", function (config, parserConfig) { + var client = parserConfig.client || {}, + atoms = parserConfig.atoms || {"false": true, "true": true, "null": true}, + builtin = parserConfig.builtin || set(defaultBuiltin), + keywords = parserConfig.keywords || set(sqlKeywords), + operatorChars = parserConfig.operatorChars || /^[*+\-%<>!=&|~^\/]/, + support = parserConfig.support || {}, + hooks = parserConfig.hooks || {}, + dateSQL = parserConfig.dateSQL || {"date": true, "time": true, "timestamp": true}, + backslashStringEscapes = parserConfig.backslashStringEscapes !== false, + brackets = parserConfig.brackets || /^[\{}\(\)\[\]]/, + punctuation = parserConfig.punctuation || /^[;.,:]/ + + function tokenBase(stream, state) { + var ch = stream.next(); + + // call hooks from the mime type + if (hooks[ch]) { + var result = hooks[ch](stream, state); + if (result !== false) return result; + } + + if (support.hexNumber && + ((ch == "0" && stream.match(/^[xX][0-9a-fA-F]+/)) + || (ch == "x" || ch == "X") && stream.match(/^'[0-9a-fA-F]+'/))) { + // hex + // ref: http://dev.mysql.com/doc/refman/5.5/en/hexadecimal-literals.html + return "number"; + } else if (support.binaryNumber && + (((ch == "b" || ch == "B") && stream.match(/^'[01]+'/)) + || (ch == "0" && stream.match(/^b[01]+/)))) { + // bitstring + // ref: http://dev.mysql.com/doc/refman/5.5/en/bit-field-literals.html + return "number"; + } else if (ch.charCodeAt(0) > 47 && ch.charCodeAt(0) < 58) { + // numbers + // ref: http://dev.mysql.com/doc/refman/5.5/en/number-literals.html + stream.match(/^[0-9]*(\.[0-9]+)?([eE][-+]?[0-9]+)?/); + support.decimallessFloat && stream.match(/^\.(?!\.)/); + return "number"; + } else if (ch == "?" && (stream.eatSpace() || stream.eol() || stream.eat(";"))) { + // placeholders + return "variable-3"; + } else if (ch == "'" || (ch == '"' && support.doubleQuote)) { + // strings + // ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html + state.tokenize = tokenLiteral(ch); + return state.tokenize(stream, state); + } else if ((((support.nCharCast && (ch == "n" || ch == "N")) + || (support.charsetCast && ch == "_" && stream.match(/[a-z][a-z0-9]*/i))) + && (stream.peek() == "'" || stream.peek() == '"'))) { + // charset casting: _utf8'str', N'str', n'str' + // ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html + return "keyword"; + } else if (support.escapeConstant && (ch == "e" || ch == "E") + && (stream.peek() == "'" || (stream.peek() == '"' && support.doubleQuote))) { + // escape constant: E'str', e'str' + // ref: https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE + state.tokenize = function (stream, state) { + return (state.tokenize = tokenLiteral(stream.next(), true))(stream, state); + } + return "keyword"; + } else if (support.commentSlashSlash && ch == "/" && stream.eat("/")) { + // 1-line comment + stream.skipToEnd(); + return "comment"; + } else if ((support.commentHash && ch == "#") + || (ch == "-" && stream.eat("-") && (!support.commentSpaceRequired || stream.eat(" ")))) { + // 1-line comments + // ref: https://kb.askmonty.org/en/comment-syntax/ + stream.skipToEnd(); + return "comment"; + } else if (ch == "/" && stream.eat("*")) { + // multi-line comments + // ref: https://kb.askmonty.org/en/comment-syntax/ + state.tokenize = tokenComment(1); + return state.tokenize(stream, state); + } else if (ch == ".") { + // .1 for 0.1 + if (support.zerolessFloat && stream.match(/^(?:\d+(?:e[+-]?\d+)?)/i)) + return "number"; + if (stream.match(/^\.+/)) + return null + // .table_name (ODBC) + // // ref: http://dev.mysql.com/doc/refman/5.6/en/identifier-qualifiers.html + if (support.ODBCdotTable && stream.match(/^[\w\d_$#]+/)) + return "variable-2"; + } else if (operatorChars.test(ch)) { + // operators + stream.eatWhile(operatorChars); + return "operator"; + } else if (brackets.test(ch)) { + // brackets + return "bracket"; + } else if (punctuation.test(ch)) { + // punctuation + stream.eatWhile(punctuation); + return "punctuation"; + } else if (ch == '{' && + (stream.match(/^( )*(d|D|t|T|ts|TS)( )*'[^']*'( )*}/) || stream.match(/^( )*(d|D|t|T|ts|TS)( )*"[^"]*"( )*}/))) { + // dates (weird ODBC syntax) + // ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html + return "number"; + } else { + // todo 修改此处,使得keyword由 a_a 格式变为 a.a + // stream.eatWhile(/^[_\w\d]/); + stream.eatWhile(/^[.\w\d]/); + var word = stream.current().toLowerCase(); + // dates (standard SQL syntax) + // ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html + if (dateSQL.hasOwnProperty(word) && (stream.match(/^( )+'[^']*'/) || stream.match(/^( )+"[^"]*"/))) + return "number"; + if (atoms.hasOwnProperty(word)) return "atom"; + if (builtin.hasOwnProperty(word)) return "builtin"; + if (keywords.hasOwnProperty(word)) return "keyword"; + if (client.hasOwnProperty(word)) return "string-2"; + return null; + } + } + + // 'string', with char specified in quote escaped by '\' + function tokenLiteral(quote, backslashEscapes) { + return function (stream, state) { + var escaped = false, ch; + while ((ch = stream.next()) != null) { + if (ch == quote && !escaped) { + state.tokenize = tokenBase; + break; + } + escaped = (backslashStringEscapes || backslashEscapes) && !escaped && ch == "\\"; + } + return "string"; + }; + } + + function tokenComment(depth) { + return function (stream, state) { + var m = stream.match(/^.*?(\/\*|\*\/)/) + if (!m) stream.skipToEnd() + else if (m[1] == "/*") state.tokenize = tokenComment(depth + 1) + else if (depth > 1) state.tokenize = tokenComment(depth - 1) + else state.tokenize = tokenBase + return "comment" + } + } + + function pushContext(stream, state, type) { + state.context = { + prev: state.context, + indent: stream.indentation(), + col: stream.column(), + type: type + }; + } + + function popContext(state) { + state.indent = state.context.indent; + state.context = state.context.prev; + } + + return { + startState: function () { + //tokenize 标记解析 + // Modes that use a state must define a startState method on their mode object. + // This is a function of no arguments that produces a state object to be used at the start of a document. + return {tokenize: tokenBase, context: null}; + }, + + //依次遍历流 + token: function (stream, state) { + if (stream.sol()) { + if (state.context && state.context.align == null) + state.context.align = false; + } + if (state.tokenize == tokenBase && stream.eatSpace()) return null; + + var style = state.tokenize(stream, state); + if (style == "comment") return style; + + if (state.context && state.context.align == null) + state.context.align = true; + + var tok = stream.current(); + if (tok == "(") + pushContext(stream, state, ")"); + else if (tok == "[") + pushContext(stream, state, "]"); + else if (state.context && state.context.type == tok) + popContext(state); + return style; + }, + + //智能缩进 + indent: function (state, textAfter) { + var cx = state.context; + if (!cx) return CodeMirror.Pass; + var closing = textAfter.charAt(0) == cx.type; + if (cx.align) return cx.col + (closing ? 0 : 1); + else return cx.indent + (closing ? 0 : config.indentUnit); + }, + + //支持注释 + blockCommentStart: "/*", + blockCommentEnd: "*/", + lineComment: support.commentSlashSlash ? "//" : support.commentHash ? "#" : "--", + + //自动闭合括号 + closeBrackets: "()[]{}''\"\"``" + }; + }); + + // `identifier` + function hookIdentifier(stream) { + // MySQL/MariaDB identifiers + // ref: http://dev.mysql.com/doc/refman/5.6/en/identifier-qualifiers.html + var ch; + while ((ch = stream.next()) != null) { + if (ch == "`" && !stream.eat("`")) return "variable-2"; + } + stream.backUp(stream.current().length - 1); + return stream.eatWhile(/\w/) ? "variable-2" : null; + } + + // "identifier" + function hookIdentifierDoublequote(stream) { + // Standard SQL /SQLite identifiers + // ref: http://web.archive.org/web/20160813185132/http://savage.net.au/SQL/sql-99.bnf.html#delimited%20identifier + // ref: http://sqlite.org/lang_keywords.html + var ch; + while ((ch = stream.next()) != null) { + if (ch == "\"" && !stream.eat("\"")) return "variable-2"; + } + stream.backUp(stream.current().length - 1); + return stream.eatWhile(/\w/) ? "variable-2" : null; + } + + // variable token + function hookVar(stream) { + // variables + // @@prefix.varName @varName + // varName can be quoted with ` or ' or " + // ref: http://dev.mysql.com/doc/refman/5.5/en/user-variables.html + if (stream.eat("@")) { + stream.match('session.'); + stream.match('local.'); + stream.match('global.'); + } + + if (stream.eat("'")) { + stream.match(/^.*'/); + return "variable-2"; + } else if (stream.eat('"')) { + stream.match(/^.*"/); + return "variable-2"; + } else if (stream.eat("`")) { + stream.match(/^.*`/); + return "variable-2"; + } else if (stream.match(/^[0-9a-zA-Z$\.\_]+/)) { + return "variable-2"; + } + return null; + }; + + // short client keyword token + function hookClient(stream) { + // \N means NULL + // ref: http://dev.mysql.com/doc/refman/5.5/en/null-values.html + if (stream.eat("N")) { + return "atom"; + } + // \g, etc + // ref: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html + return stream.match(/^[a-zA-Z.#!?]/) ? "variable-2" : null; + } + + // these keywords are used by all SQL dialects (however, a mode can still overwrite it) + var sqlKeywords = "alter and as asc between by count create delete desc distinct drop from group having in insert into is join like not on or order select set table union update values where limit "; + + // turn a space-separated list into an array + function set(str) { + var obj = {}, words = str.split(" "); + for (var i = 0; i < words.length; ++i) obj[words[i]] = true; + return obj; + } + + var defaultBuiltin = "bool boolean bit blob enum long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision real date datetime year unsigned signed decimal numeric" + + // A generic SQL Mode. It's not a standard, it just try to support what is generally supported + CodeMirror.defineMIME("text/x-sql", { + name: "sql", + keywords: set(sqlKeywords + "begin"), //sql 关键字 + builtin: set(defaultBuiltin), //内置数据类型 + atoms: set("false true null unknown"), //基本数据类型 + dateSQL: set("date time timestamp"), //时间类型 + support: set("ODBCdotTable doubleQuote binaryNumber hexNumber") //支持的数据编码 ODBC double 二进制 16进制 + }); + + CodeMirror.defineMIME("text/x-mssql", { + name: "sql", + client: set("$partition binary_checksum checksum connectionproperty context_info current_request_id error_line error_message error_number error_procedure error_severity error_state formatmessage get_filestream_transaction_context getansinull host_id host_name isnull isnumeric min_active_rowversion newid newsequentialid rowcount_big xact_state object_id"), + keywords: set(sqlKeywords + "begin trigger proc view index for add constraint key primary foreign collate clustered nonclustered declare exec go if use index holdlock nolock nowait paglock readcommitted readcommittedlock readpast readuncommitted repeatableread rowlock serializable snapshot tablock tablockx updlock with"), + builtin: set("bigint numeric bit smallint decimal smallmoney int tinyint money float real char varchar text nchar nvarchar ntext binary varbinary image cursor timestamp hierarchyid uniqueidentifier sql_variant xml table "), + atoms: set("is not null like and or in left right between inner outer join all any some cross unpivot pivot exists"), + operatorChars: /^[*+\-%<>!=^\&|\/]/, + brackets: /^[\{}\(\)]/, + punctuation: /^[;.,:/]/, + backslashStringEscapes: false, + dateSQL: set("date datetimeoffset datetime2 smalldatetime datetime time"), + hooks: { + "@": hookVar + } + }); + + CodeMirror.defineMIME("text/x-mysql", { + name: "sql", + client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"), + keywords: set(sqlKeywords + "accessible action add after algorithm all analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance diagnostics directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general get global grant grants group group_concat handler hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show signal slave slow smallint snapshot soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"), + builtin: set("bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"), + atoms: set("false true null unknown"), + operatorChars: /^[*+\-%<>!=&|^]/, + dateSQL: set("date time timestamp"), + support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber doubleQuote nCharCast charsetCast commentHash commentSpaceRequired"), + hooks: { + "@": hookVar, + "`": hookIdentifier, + "\\": hookClient + } + }); + + CodeMirror.defineMIME("text/x-mariadb", { + name: "sql", + client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"), + keywords: set(sqlKeywords + "accessible action add after algorithm all always analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance diagnostics directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general generated get global grant grants group groupby_concat handler hard hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password persistent phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show shutdown signal slave slow smallint snapshot soft soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views virtual warnings when while with work write xa xor year_month zerofill begin do then else loop repeat"), + builtin: set("bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric"), + atoms: set("false true null unknown"), + operatorChars: /^[*+\-%<>!=&|^]/, + dateSQL: set("date time timestamp"), + support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber doubleQuote nCharCast charsetCast commentHash commentSpaceRequired"), + hooks: { + "@": hookVar, + "`": hookIdentifier, + "\\": hookClient + } + }); + + // provided by the phpLiteAdmin project - phpliteadmin.org + CodeMirror.defineMIME("text/x-sqlite", { + name: "sql", + // commands of the official SQLite client, ref: https://www.sqlite.org/cli.html#dotcmd + client: set("auth backup bail binary changes check clone databases dbinfo dump echo eqp exit explain fullschema headers help import imposter indexes iotrace limit lint load log mode nullvalue once open output print prompt quit read restore save scanstats schema separator session shell show stats system tables testcase timeout timer trace vfsinfo vfslist vfsname width"), + // ref: http://sqlite.org/lang_keywords.html + keywords: set(sqlKeywords + "abort action add after all analyze attach autoincrement before begin cascade case cast check collate column commit conflict constraint cross current_date current_time current_timestamp database default deferrable deferred detach each else end escape except exclusive exists explain fail for foreign full glob if ignore immediate index indexed initially inner instead intersect isnull key left limit match natural no notnull null of offset outer plan pragma primary query raise recursive references regexp reindex release rename replace restrict right rollback row savepoint temp temporary then to transaction trigger unique using vacuum view virtual when with without"), + // SQLite is weakly typed, ref: http://sqlite.org/datatype3.html. This is just a list of some common types. + builtin: set("bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text clob bigint int int2 int8 integer float double char varchar date datetime year unsigned signed numeric real"), + // ref: http://sqlite.org/syntax/literal-value.html + atoms: set("null current_date current_time current_timestamp"), + // ref: http://sqlite.org/lang_expr.html#binaryops + operatorChars: /^[*+\-%<>!=&|/~]/, + // SQLite is weakly typed, ref: http://sqlite.org/datatype3.html. This is just a list of some common types. + dateSQL: set("date time timestamp datetime"), + support: set("decimallessFloat zerolessFloat"), + identifierQuote: "\"", //ref: http://sqlite.org/lang_keywords.html + hooks: { + // bind-parameters ref:http://sqlite.org/lang_expr.html#varparam + "@": hookVar, + ":": hookVar, + "?": hookVar, + "$": hookVar, + // The preferred way to escape Identifiers is using double quotes, ref: http://sqlite.org/lang_keywords.html + "\"": hookIdentifierDoublequote, + // there is also support for backticks, ref: http://sqlite.org/lang_keywords.html + "`": hookIdentifier + } + }); + + // the query language used by Apache Cassandra is called CQL, but this mime type + // is called Cassandra to avoid confusion with Contextual Query Language + CodeMirror.defineMIME("text/x-cassandra", { + name: "sql", + client: {}, + keywords: set("add all allow alter and any apply as asc authorize batch begin by clustering columnfamily compact consistency count create custom delete desc distinct drop each_quorum exists filtering from grant if in index insert into key keyspace keyspaces level limit local_one local_quorum modify nan norecursive nosuperuser not of on one order password permission permissions primary quorum rename revoke schema select set storage superuser table three to token truncate ttl two type unlogged update use user users using values where with writetime"), + builtin: set("ascii bigint blob boolean counter decimal double float frozen inet int list map static text timestamp timeuuid tuple uuid varchar varint"), + atoms: set("false true infinity NaN"), + operatorChars: /^[<>=]/, + dateSQL: {}, + support: set("commentSlashSlash decimallessFloat"), + hooks: {} + }); + + // this is based on Peter Raganitsch's 'plsql' mode + CodeMirror.defineMIME("text/x-plsql", { + name: "sql", + client: set("appinfo arraysize autocommit autoprint autorecovery autotrace blockterminator break btitle cmdsep colsep compatibility compute concat copycommit copytypecheck define describe echo editfile embedded escape exec execute feedback flagger flush heading headsep instance linesize lno loboffset logsource long longchunksize markup native newpage numformat numwidth pagesize pause pno recsep recsepchar release repfooter repheader serveroutput shiftinout show showmode size spool sqlblanklines sqlcase sqlcode sqlcontinue sqlnumber sqlpluscompatibility sqlprefix sqlprompt sqlterminator suffix tab term termout time timing trimout trimspool ttitle underline verify version wrap"), + keywords: set("abort accept access add all alter and any array arraylen as asc assert assign at attributes audit authorization avg base_table begin between binary_integer body boolean by case cast char char_base check close cluster clusters colauth column comment commit compress connect connected constant constraint crash create current currval cursor data_base database date dba deallocate debugoff debugon decimal declare default definition delay delete desc digits dispose distinct do drop else elseif elsif enable end entry escape exception exception_init exchange exclusive exists exit external fast fetch file for force form from function generic goto grant group having identified if immediate in increment index indexes indicator initial initrans insert interface intersect into is key level library like limited local lock log logging long loop master maxextents maxtrans member minextents minus mislabel mode modify multiset new next no noaudit nocompress nologging noparallel not nowait number_base object of off offline on online only open option or order out package parallel partition pctfree pctincrease pctused pls_integer positive positiven pragma primary prior private privileges procedure public raise range raw read rebuild record ref references refresh release rename replace resource restrict return returning returns reverse revoke rollback row rowid rowlabel rownum rows run savepoint schema segment select separate session set share snapshot some space split sql start statement storage subtype successful synonym tabauth table tables tablespace task terminate then to trigger truncate type union unique unlimited unrecoverable unusable update use using validate value values variable view views when whenever where while with work"), + builtin: set("abs acos add_months ascii asin atan atan2 average bfile bfilename bigserial bit blob ceil character chartorowid chr clob concat convert cos cosh count dec decode deref dual dump dup_val_on_index empty error exp false float floor found glb greatest hextoraw initcap instr instrb int integer isopen last_day least length lengthb ln lower lpad ltrim lub make_ref max min mlslabel mod months_between natural naturaln nchar nclob new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower nls_sort nls_upper nlssort no_data_found notfound null number numeric nvarchar2 nvl others power rawtohex real reftohex round rowcount rowidtochar rowtype rpad rtrim serial sign signtype sin sinh smallint soundex sqlcode sqlerrm sqrt stddev string substr substrb sum sysdate tan tanh to_char text to_date to_label to_multi_byte to_number to_single_byte translate true trunc uid unlogged upper user userenv varchar varchar2 variance varying vsize xml"), + operatorChars: /^[*\/+\-%<>!=~]/, + dateSQL: set("date time timestamp"), + support: set("doubleQuote nCharCast zerolessFloat binaryNumber hexNumber") + }); + + // Created to support specific hive keywords + CodeMirror.defineMIME("text/x-hive", { + name: "sql", + keywords: set("select alter $elem$ $key$ $value$ add after all analyze and archive as asc before between binary both bucket buckets by cascade case cast change cluster clustered clusterstatus collection column columns comment compute concatenate continue create cross cursor data database databases dbproperties deferred delete delimited desc describe directory disable distinct distribute drop else enable end escaped exclusive exists explain export extended external fetch fields fileformat first format formatted from full function functions grant group having hold_ddltime idxproperties if import in index indexes inpath inputdriver inputformat insert intersect into is items join keys lateral left like limit lines load local location lock locks mapjoin materialized minus msck no_drop nocompress not of offline on option or order out outer outputdriver outputformat overwrite partition partitioned partitions percent plus preserve procedure purge range rcfile read readonly reads rebuild recordreader recordwriter recover reduce regexp rename repair replace restrict revoke right rlike row schema schemas semi sequencefile serde serdeproperties set shared show show_database sort sorted ssl statistics stored streamtable table tables tablesample tblproperties temporary terminated textfile then tmp to touch transform trigger unarchive undo union uniquejoin unlock update use using utc utc_tmestamp view when where while with admin authorization char compact compactions conf cube current current_date current_timestamp day decimal defined dependency directories elem_type exchange file following for grouping hour ignore inner interval jar less logical macro minute month more none noscan over owner partialscan preceding pretty principals protection reload rewrite role roles rollup rows second server sets skewed transactions truncate unbounded unset uri user values window year"), + builtin: set("bool boolean long timestamp tinyint smallint bigint int float double date datetime unsigned string array struct map uniontype key_type utctimestamp value_type varchar"), + atoms: set("false true null unknown"), + operatorChars: /^[*+\-%<>!=]/, + dateSQL: set("date timestamp"), + support: set("ODBCdotTable doubleQuote binaryNumber hexNumber") + }); + + CodeMirror.defineMIME("text/x-pgsql", { + name: "sql", + client: set("source"), + // For PostgreSQL - https://www.postgresql.org/docs/11/sql-keywords-appendix.html + // For pl/pgsql lang - https://github.com/postgres/postgres/blob/REL_11_2/src/pl/plpgsql/src/pl_scanner.c + keywords: set(sqlKeywords + "a abort abs absent absolute access according action ada add admin after aggregate alias all allocate also alter always analyse analyze and any are array array_agg array_max_cardinality as asc asensitive assert assertion assignment asymmetric at atomic attach attribute attributes authorization avg backward base64 before begin begin_frame begin_partition bernoulli between bigint binary bit bit_length blob blocked bom boolean both breadth by c cache call called cardinality cascade cascaded case cast catalog catalog_name ceil ceiling chain char char_length character character_length character_set_catalog character_set_name character_set_schema characteristics characters check checkpoint class class_origin clob close cluster coalesce cobol collate collation collation_catalog collation_name collation_schema collect column column_name columns command_function command_function_code comment comments commit committed concurrently condition condition_number configuration conflict connect connection connection_name constant constraint constraint_catalog constraint_name constraint_schema constraints constructor contains content continue control conversion convert copy corr corresponding cost count covar_pop covar_samp create cross csv cube cume_dist current current_catalog current_date current_default_transform_group current_path current_role current_row current_schema current_time current_timestamp current_transform_group_for_type current_user cursor cursor_name cycle data database datalink datatype date datetime_interval_code datetime_interval_precision day db deallocate debug dec decimal declare default defaults deferrable deferred defined definer degree delete delimiter delimiters dense_rank depends depth deref derived desc describe descriptor detach detail deterministic diagnostics dictionary disable discard disconnect dispatch distinct dlnewcopy dlpreviouscopy dlurlcomplete dlurlcompleteonly dlurlcompletewrite dlurlpath dlurlpathonly dlurlpathwrite dlurlscheme dlurlserver dlvalue do document domain double drop dump dynamic dynamic_function dynamic_function_code each element else elseif elsif empty enable encoding encrypted end end_frame end_partition endexec enforced enum equals errcode error escape event every except exception exclude excluding exclusive exec execute exists exit exp explain expression extension external extract false family fetch file filter final first first_value flag float floor following for force foreach foreign fortran forward found frame_row free freeze from fs full function functions fusion g general generated get global go goto grant granted greatest group grouping groups handler having header hex hierarchy hint hold hour id identity if ignore ilike immediate immediately immutable implementation implicit import in include including increment indent index indexes indicator info inherit inherits initially inline inner inout input insensitive insert instance instantiable instead int integer integrity intersect intersection interval into invoker is isnull isolation join k key key_member key_type label lag language large last last_value lateral lead leading leakproof least left length level library like like_regex limit link listen ln load local localtime localtimestamp location locator lock locked log logged loop lower m map mapping match matched materialized max max_cardinality maxvalue member merge message message_length message_octet_length message_text method min minute minvalue mod mode modifies module month more move multiset mumps name names namespace national natural nchar nclob nesting new next nfc nfd nfkc nfkd nil no none normalize normalized not nothing notice notify notnull nowait nth_value ntile null nullable nullif nulls number numeric object occurrences_regex octet_length octets of off offset oids old on only open operator option options or order ordering ordinality others out outer output over overlaps overlay overriding owned owner p pad parallel parameter parameter_mode parameter_name parameter_ordinal_position parameter_specific_catalog parameter_specific_name parameter_specific_schema parser partial partition pascal passing passthrough password path percent percent_rank percentile_cont percentile_disc perform period permission pg_context pg_datatype_name pg_exception_context pg_exception_detail pg_exception_hint placing plans pli policy portion position position_regex power precedes preceding precision prepare prepared preserve primary print_strict_params prior privileges procedural procedure procedures program public publication query quote raise range rank read reads real reassign recheck recovery recursive ref references referencing refresh regr_avgx regr_avgy regr_count regr_intercept regr_r2 regr_slope regr_sxx regr_sxy regr_syy reindex relative release rename repeatable replace replica requiring reset respect restart restore restrict result result_oid return returned_cardinality returned_length returned_octet_length returned_sqlstate returning returns reverse revoke right role rollback rollup routine routine_catalog routine_name routine_schema routines row row_count row_number rows rowtype rule savepoint scale schema schema_name schemas scope scope_catalog scope_name scope_schema scroll search second section security select selective self sensitive sequence sequences serializable server server_name session session_user set setof sets share show similar simple size skip slice smallint snapshot some source space specific specific_name specifictype sql sqlcode sqlerror sqlexception sqlstate sqlwarning sqrt stable stacked standalone start state statement static statistics stddev_pop stddev_samp stdin stdout storage strict strip structure style subclass_origin submultiset subscription substring substring_regex succeeds sum symmetric sysid system system_time system_user t table table_name tables tablesample tablespace temp template temporary text then ties time timestamp timezone_hour timezone_minute to token top_level_count trailing transaction transaction_active transactions_committed transactions_rolled_back transform transforms translate translate_regex translation treat trigger trigger_catalog trigger_name trigger_schema trim trim_array true truncate trusted type types uescape unbounded uncommitted under unencrypted union unique unknown unlink unlisten unlogged unnamed unnest until untyped update upper uri usage use_column use_variable user user_defined_type_catalog user_defined_type_code user_defined_type_name user_defined_type_schema using vacuum valid validate validator value value_of values var_pop var_samp varbinary varchar variable_conflict variadic varying verbose version versioning view views volatile warning when whenever where while whitespace width_bucket window with within without work wrapper write xml xmlagg xmlattributes xmlbinary xmlcast xmlcomment xmlconcat xmldeclaration xmldocument xmlelement xmlexists xmlforest xmliterate xmlnamespaces xmlparse xmlpi xmlquery xmlroot xmlschema xmlserialize xmltable xmltext xmlvalidate year yes zone"), + // https://www.postgresql.org/docs/11/datatype.html + builtin: set("bigint int8 bigserial serial8 bit varying varbit boolean bool box bytea character char varchar cidr circle date double precision float8 inet integer int int4 interval json jsonb line lseg macaddr macaddr8 money numeric decimal path pg_lsn point polygon real float4 smallint int2 smallserial serial2 serial serial4 text time without zone with timetz timestamp timestamptz tsquery tsvector txid_snapshot uuid xml"), + atoms: set("false true null unknown"), + operatorChars: /^[*\/+\-%<>!=&|^\/#@?~]/, + backslashStringEscapes: false, + dateSQL: set("date time timestamp"), + support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber nCharCast charsetCast escapeConstant") + }); + + // Google's SQL-like query language, GQL + CodeMirror.defineMIME("text/x-gql", { + name: "sql", + keywords: set("ancestor and asc by contains desc descendant distinct from group has in is limit offset on order select superset where"), + atoms: set("false true"), + builtin: set("blob datetime first key __key__ string integer double boolean null"), + operatorChars: /^[*+\-%<>!=]/ + }); + + // Greenplum + CodeMirror.defineMIME("text/x-gpsql", { + name: "sql", + client: set("source"), + //https://github.com/greenplum-db/gpdb/blob/master/src/include/parser/kwlist.h + keywords: set("abort absolute access action active add admin after aggregate all also alter always analyse analyze and any array as asc assertion assignment asymmetric at authorization backward before begin between bigint binary bit boolean both by cache called cascade cascaded case cast chain char character characteristics check checkpoint class close cluster coalesce codegen collate column comment commit committed concurrency concurrently configuration connection constraint constraints contains content continue conversion copy cost cpu_rate_limit create createdb createexttable createrole createuser cross csv cube current current_catalog current_date current_role current_schema current_time current_timestamp current_user cursor cycle data database day deallocate dec decimal declare decode default defaults deferrable deferred definer delete delimiter delimiters deny desc dictionary disable discard distinct distributed do document domain double drop dxl each else enable encoding encrypted end enum errors escape every except exchange exclude excluding exclusive execute exists explain extension external extract false family fetch fields filespace fill filter first float following for force foreign format forward freeze from full function global grant granted greatest group group_id grouping handler hash having header hold host hour identity if ignore ilike immediate immutable implicit in including inclusive increment index indexes inherit inherits initially inline inner inout input insensitive insert instead int integer intersect interval into invoker is isnull isolation join key language large last leading least left level like limit list listen load local localtime localtimestamp location lock log login mapping master match maxvalue median merge minute minvalue missing mode modifies modify month move name names national natural nchar new newline next no nocreatedb nocreateexttable nocreaterole nocreateuser noinherit nologin none noovercommit nosuperuser not nothing notify notnull nowait null nullif nulls numeric object of off offset oids old on only operator option options or order ordered others out outer over overcommit overlaps overlay owned owner parser partial partition partitions passing password percent percentile_cont percentile_disc placing plans position preceding precision prepare prepared preserve primary prior privileges procedural procedure protocol queue quote randomly range read readable reads real reassign recheck recursive ref references reindex reject relative release rename repeatable replace replica reset resource restart restrict returning returns revoke right role rollback rollup rootpartition row rows rule savepoint scatter schema scroll search second security segment select sequence serializable session session_user set setof sets share show similar simple smallint some split sql stable standalone start statement statistics stdin stdout storage strict strip subpartition subpartitions substring superuser symmetric sysid system table tablespace temp template temporary text then threshold ties time timestamp to trailing transaction treat trigger trim true truncate trusted type unbounded uncommitted unencrypted union unique unknown unlisten until update user using vacuum valid validation validator value values varchar variadic varying verbose version view volatile web when where whitespace window with within without work writable write xml xmlattributes xmlconcat xmlelement xmlexists xmlforest xmlparse xmlpi xmlroot xmlserialize year yes zone"), + builtin: set("bigint int8 bigserial serial8 bit varying varbit boolean bool box bytea character char varchar cidr circle date double precision float float8 inet integer int int4 interval json jsonb line lseg macaddr macaddr8 money numeric decimal path pg_lsn point polygon real float4 smallint int2 smallserial serial2 serial serial4 text time without zone with timetz timestamp timestamptz tsquery tsvector txid_snapshot uuid xml"), + atoms: set("false true null unknown"), + operatorChars: /^[*+\-%<>!=&|^\/#@?~]/, + dateSQL: set("date time timestamp"), + support: set("ODBCdotTable decimallessFloat zerolessFloat binaryNumber hexNumber nCharCast charsetCast") + }); + + // Spark SQL + CodeMirror.defineMIME("text/x-sparksql", { + name: "sql", + keywords: set("add after all alter analyze and anti archive array as asc at between bucket buckets by cache cascade case cast change clear cluster clustered codegen collection column columns comment commit compact compactions compute concatenate cost create cross cube current current_date current_timestamp database databases data dbproperties defined delete delimited deny desc describe dfs directories distinct distribute drop else end escaped except exchange exists explain export extended external false fields fileformat first following for format formatted from full function functions global grant group grouping having if ignore import in index indexes inner inpath inputformat insert intersect interval into is items join keys last lateral lazy left like limit lines list load local location lock locks logical macro map minus msck natural no not null nulls of on optimize option options or order out outer outputformat over overwrite partition partitioned partitions percent preceding principals purge range recordreader recordwriter recover reduce refresh regexp rename repair replace reset restrict revoke right rlike role roles rollback rollup row rows schema schemas select semi separated serde serdeproperties set sets show skewed sort sorted start statistics stored stratify struct table tables tablesample tblproperties temp temporary terminated then to touch transaction transactions transform true truncate unarchive unbounded uncache union unlock unset use using values view when where window with"), + builtin: set("tinyint smallint int bigint boolean float double string binary timestamp decimal array map struct uniontype delimited serde sequencefile textfile rcfile inputformat outputformat"), + atoms: set("false true null"), + operatorChars: /^[*\/+\-%<>!=~&|^]/, + dateSQL: set("date time timestamp"), + support: set("ODBCdotTable doubleQuote zerolessFloat") + }); + + // Esper + CodeMirror.defineMIME("text/x-esper", { + name: "sql", + client: set("source"), + // http://www.espertech.com/esper/release-5.5.0/esper-reference/html/appendix_keywords.html + keywords: set("alter and as asc between by count create delete desc distinct drop from group having in insert into is join like not on or order select set table union update values where limit after all and as at asc avedev avg between by case cast coalesce count create current_timestamp day days delete define desc distinct else end escape events every exists false first from full group having hour hours in inner insert instanceof into irstream is istream join last lastweekday left limit like max match_recognize matches median measures metadatasql min minute minutes msec millisecond milliseconds not null offset on or order outer output partition pattern prev prior regexp retain-union retain-intersection right rstream sec second seconds select set some snapshot sql stddev sum then true unidirectional until update variable weekday when where window"), + builtin: {}, + atoms: set("false true null"), + operatorChars: /^[*+\-%<>!=&|^\/#@?~]/, + dateSQL: set("time"), + support: set("decimallessFloat zerolessFloat binaryNumber hexNumber") + }); + modehook && modehook(CodeMirror, set, { + hookVar:hookVar, + client: "charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee", + keywords: sqlKeywords + "accessible action add after algorithm all analyze asensitive at authors auto_increment autocommit avg avg_row_length before binary binlog both btree cache call cascade cascaded case catalog_name chain change changed character check checkpoint checksum class_origin client_statistics close coalesce code collate collation collations column columns comment commit committed completion concurrent condition connection consistent constraint contains continue contributors convert cross current current_date current_time current_timestamp current_user cursor data database databases day_hour day_microsecond day_minute day_second deallocate dec declare default delay_key_write delayed delimiter des_key_file describe deterministic dev_pop dev_samp deviance diagnostics directory disable discard distinctrow div dual dumpfile each elseif enable enclosed end ends engine engines enum errors escape escaped even event events every execute exists exit explain extended fast fetch field fields first flush for force foreign found_rows full fulltext function general get global grant grants group group_concat handler hash help high_priority hosts hour_microsecond hour_minute hour_second if ignore ignore_server_ids import index index_statistics infile inner innodb inout insensitive insert_method install interval invoker isolation iterate key keys kill language last leading leave left level limit linear lines list load local localtime localtimestamp lock logs low_priority master master_heartbeat_period master_ssl_verify_server_cert masters match max max_rows maxvalue message_text middleint migrate min min_rows minute_microsecond minute_second mod mode modifies modify mutex mysql_errno natural next no no_write_to_binlog offline offset one online open optimize option optionally out outer outfile pack_keys parser partition partitions password phase plugin plugins prepare preserve prev primary privileges procedure processlist profile profiles purge query quick range read read_write reads real rebuild recover references regexp relaylog release remove rename reorganize repair repeatable replace require resignal restrict resume return returns revoke right rlike rollback rollup row row_format rtree savepoint schedule schema schema_name schemas second_microsecond security sensitive separator serializable server session share show signal slave slow smallint snapshot soname spatial specific sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_no_cache sql_small_result sqlexception sqlstate sqlwarning ssl start starting starts status std stddev stddev_pop stddev_samp storage straight_join subclass_origin sum suspend table_name table_statistics tables tablespace temporary terminated to trailing transaction trigger triggers truncate uncommitted undo uninstall unique unlock upgrade usage use use_frm user user_resources user_statistics using utc_date utc_time utc_timestamp value variables varying view views warnings when while with work write xa xor year_month zerofill begin do then else loop repeat", + builtin: "bool boolean bit blob decimal double float long longblob longtext medium mediumblob mediumint mediumtext time timestamp tinyblob tinyint tinytext text bigint int int1 int2 int3 int4 int8 integer float float4 float8 double char varbinary varchar varcharacter precision date datetime year unsigned signed numeric" + }) +} diff --git a/src/components/advancedSearch/showhint/const/defaultTips.js b/src/components/advancedSearch/showhint/const/defaultTips.js new file mode 100644 index 00000000..96dec36b --- /dev/null +++ b/src/components/advancedSearch/showhint/const/defaultTips.js @@ -0,0 +1,57 @@ +export default { + + default: { + description () { + const code = `SELECT aggregate_function(field) [as field] … (5) +FROM [db.]table|$log_type(1) +WHERE $filter [and ](2) +GROUP BY (3) +[HAVING ](4) +[ORDER BY [ASC|DESC]](6) +[LIMIT [n, ]m ](7)` + return (
+

How To Search

+

You can write a query to retieve logs from an log type, use group by aggregation keywords to calculate + metrics + and generate statistical results , search for specific conditions within a rolling time window, predict future + trends, and so on.

+ +

1. Filter Mode

+

A query in SQL ( also known as a "Where clause") has three basic parts: fields, operators, and values. Where + clause can be combined with AND , OR and NOT keywords.

+ [Field + operator + value] keyword [operator(Field)] + +
    +
  • Field - Fields are different types of traffic attributes int the system. Fields include server_ip, + server_port, ssl_sni , and so on. +
  • +
  • Operator - Operators are the foundation of the query. They relate the field to the value and build a query + condition. Common operators include equals(=), IN, Like, etc. +
  • +
  • + Value - Values are the actual data in the query. +
      +
    • Use the percent (%) wildcard substitutes for one or more characters in a string. Such as ssl_sni like + '%google.com' . +
    • +
    • Use underscore (_) wildcard substitutes for exactly one character in a string. Such as + client_ip like '192.168.10.1_'. +
    • +
    • String requires single quotes (') around text values. Such as client_ip='192.168.10.53'.
    • +
    +
  • +
  • Keyword - Keywords are specific words in the SQL. You can specify the AND and OR in the WHERE clause to + create more complex query conditions. +
  • +
+

2. Statistics Mode

+

More advanced searches use the SQL keywords WHERE, GROUP BY to build aggregated query and return aggregated + results.

+ All clauses are optional , except for the required list of expressions after SELECT, WHERE and GROUP BY . +
+          {code}
+        
+
) + } + } +} diff --git a/src/components/advancedSearch/showhint/const/fieldTips.js b/src/components/advancedSearch/showhint/const/fieldTips.js new file mode 100644 index 00000000..deac8c08 --- /dev/null +++ b/src/components/advancedSearch/showhint/const/fieldTips.js @@ -0,0 +1,36 @@ +export function fieldRender(h, {fieldInfo = {}, funcReference = [], operatorReference = [], operates = [], funs = []}) { + return (
+

{fieldInfo.label}

+

Name: {fieldInfo.name}

+

Type:{fieldInfo.type}

+

Operator: {operates.join(',')}

+

Function: {funs.join(',')}

+

{fieldInfo.options && ( + 'Options: ' + fieldInfo.options.map(item => { + return `${item.displayText}(${item.text})` + }).join(',') + )}

+ +

Enable Operators

+ {/* 提示超过一屏幕 明显不合理 --- 换成简单形式 */} +
    + {operatorReference.map(item => { + return
  • + {item.name} + {item.function} +
  • + })} +
+ + +

Enable Functions

+
    + {funcReference.map(item => { + return
  • + {item.name} + {item.function} +
  • + })} +
+
) +} diff --git a/src/components/advancedSearch/showhint/const/filterTips.js b/src/components/advancedSearch/showhint/const/filterTips.js new file mode 100644 index 00000000..ef3dc5f4 --- /dev/null +++ b/src/components/advancedSearch/showhint/const/filterTips.js @@ -0,0 +1,110 @@ +export const helpInfo=[ + { + operator: "AND", + describe: `Search logs that contain all the search fields. You can use parentheses "()" to control the order in which clauses are executed. `, + example: [ + "Client IP = '192.168.10.53' AND Server IP = '8.8.8.8'", + "Client IP = '192.168.10.53' AND SSL.SNI='google.com'", + ] + }, + // { + // operator: "OR", + // describe: `Search logs that contain any of the search fields. You can use parentheses "()" to control the order in which clauses are executed. `, + // example: [ + // "Client IP = '192.168.10.53' OR Server IP = '8.8.8.8'", + // "Client IP = '192.168.10.53' OR Client IP = '192.168.10.54'", + // ] + // }, + { + operator: "= , !=", + describe: `Search logs that do EQUALS or NOT EQUALS the search value. `, + example: [ + "Client IP != '192.168.10.53' ", + "Server Port != 443", + ] + }, + { + operator: "> , < , >= , <=", + describe: `Search logs greater than and equal or less than and equal a value , or whtin a range. This operator can‘t be used with string fields. `, + example: [ + "Bytes Sent >= 751", + "Bytes Sent >= 751 and Bytes Sent <= 1024", + ] + }, + { + operator: "LIKE , NOT LIKE", + describe: `You can use wildcard searches for value that contain or not contain search fields. Using percent (%) wildcard substitutes for one or more characters in a string. Using underscore (_) wildcard substitutes for exactly one character in a string. `, + example: [ + "SSL.SNI LIKE '%google.com' ", + "Client IP LIKE '192.168.10.1_'", + "SSL.SNI NOT LIKE '%google.com'", + "Client IP NOT LIKE '192.168%'", + ] + }, + { + operator: "IN , NOT IN", + describe: `Specify or exclude multiple values for search fields. IN/NOT IN condition you can use when you need to use multiple OR condition. `, + example: [ + "l7 Protocol IN ('HTTP', 'HTTPS')", + "Server Port NOT IN (443,80)" + ] + }, + { + operator: "EMPTY , NOT EMPTY", + describe: `Specify or exclude empty value for search fields. A string or array is considered non-empty if it contains at least one byte, even if this is a space or a null byte. `, + example: [ + "NOT EMPTY(SSL.SNI)", + "EMPTY(Application Label)" + ] + }, + { + operator: "HAS", + describe: `Search logs that has element value for array type. Example:`, + example: [ + "HAS(FQDN Category, music)" + ] + }, + { + operator: "bitAnd", + describe: `A bitwise And(&) is a binary operation that compares each bit of the first operand to the corresponding bit of the second operand. Both expressions must have integral types. Examples:`, + example: [ + "bitAnd(Flags, Asymmetric|Download) = Asymmetric|Download", + "bitAnd(Flags, Asymmetric|Download) >0" + ] + }, +] +var renderData=[ + helpInfo[0], + helpInfo[1], +]; +export const filterList=renderData +function main(){ + var sqlTips={} + renderData.forEach((item,index)=>{ + var data=item // 这是个闭包 + sqlTips[item.operator]={ + name: item.operator, + // syntax: item.syntax, + type: "filter", + description() { + return (
+

{data.operator}

+

Description:

+

{data.describe}

+

Examples:

+
    + {item.example.map(v => { + return
  • + {v} +
  • + })} +
+
) + } + }; + }) + return sqlTips +} + +var filterTips=main(); +export default filterTips diff --git a/src/components/advancedSearch/showhint/const/functionTips.js b/src/components/advancedSearch/showhint/const/functionTips.js new file mode 100644 index 00000000..55f4046b --- /dev/null +++ b/src/components/advancedSearch/showhint/const/functionTips.js @@ -0,0 +1,329 @@ +var renderData = [ + { + name: "COUNT", + syntax: "count(expr)", + description: "Aggregate function is used to count the number of rows", + example: [ + { + purpose: "Total count of all logs :", + code: "count(*)" + }, + { + purpose: "Counts the occurrences of a Client IP :", + code: "count(client_ip)" + }, + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+ You can use COUNT function by count(*), count(1) or count(field). But there are something difference: +
    +
  • count(*) and count(1) will count all the rows in the table, including NULL values.
  • +
  • count(field) will count all the rows in the specified field while excluding NULL values.
  • +
+
+ } + }, + { + name: "COUNT_DISTINCT", + syntax: "count(distinct expr)", + description: "Aggregate function is used to count only distinct(unique) rows in the specified field", + example: [ + { + purpose: "Counts the number of different Client IP :", + code: "count(distinct client_ip)" + }, + { + purpose: `Counts the number of different "Server IP" and "Server port" :`, + code: "count(distinct server_ip, server_port)" + }, + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
The COUNT DISTINCT function returns the number of unique values in the field or multiple fields. + System will uses an adaptive sampling algorithm to perform fast count distinct operations.
+ } + }, + { + name: "AVG", + syntax: "avg(expr)", + description: "Aggregate function is used to calculate the arithmetic mean in the specified field. EXPR must be Integer,Float or Decimal and returned value as Float.", + example: [ + { + purpose: `Calculates the average(mean) "Byte sent (sent_bytes)" field:`, + code: "avg(sent_bytes)" + }, + { + purpose: `Calculates the average(mean) "Bytes" , rounded to 2 decimal points:`, + code: "round(avg(sent_bytes+received_bytes),2)" + }, + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
You can use ROUND(expr[,decimal_places]) or FLOOR(expr[,decimal_places]) function that rounds or floors a value to a specified number of decimal places.
+ } + }, + { + name: "SUM", + syntax: "sum(expr)", + description: "Aggregate function is used to sum of the values of the specified field. EXPR must be Integer,Float or Decimal.", + example: [ + { + purpose: `The sum of the "Byte sent (sent_bytes)" field:`, + code: "sum(sent_bytes)" + }, + { + purpose: `The sum of the "sent_bytes" and "received_bytes" fields , and rename as "Bytes ":`, + code: "sum(sent_bytes+received_bytes) as Bytes" + }, + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
You can rename the field using the AS keyword.
+ } + }, + { + name: "MAX", + syntax: "max(expr)", + description: "Aggregate function is used to return the maximum value of the specified field.", + example: [ + { + purpose: `Returns the maximum value of the "Byte sent (sent_bytes)" field:`, + code: "max(sent_bytes)" + } + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
The MAX aggregate function can also be used with the DateTime data type, where it will sort the DateTime values and return the last value from the sorted logs.
+ } + }, + { + name: "MIN", + syntax: "min(expr)", + description: "Aggregate function is used to return the minimum value of the specified field.", + example: [ + { + purpose: `Returns the minimum value of the "Byte sent (sent_bytes)" field:`, + code: "min(sent_bytes)" + } + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
The MIN aggregate function can also be used with the DateTime data type, where it will sort the DateTime values and return the minimum value from the sorted logs.
+ } + }, + { + name: "TIME_FLOOR_WITH_FILL", + syntax: "TIME_FLOOR_WITH_FILL(, [,])", + description: "Rounds down a timestamp, returning it as a new timestamp,optionally from some reference fill, and fills time gaps and impute missing values.", + example: [ + { + purpose: `Round the recv_time down to a 5 minutes increment and fill time gaps and impute zero value.`, + code: "TIME_FLOOR_WITH_FILL(recv_time,'PT5M','zero')" + } + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+

The TIME_FLOOR_WITH_FILL function as Timeseries granularity is used for time-based grouping.

+
    +
  • timestamp_expr - Unix Timestamp field
  • +
  • period - can be any ISO8601 period, like P3M (quarters) or PT12H (half-days)
  • +
  • + fill - optionnal. Includes none, null, zero, previous, next value. +
      +
    • none: empty string ""
    • +
    • null:"NULL" expression
    • +
    • zero:zero "0"
    • +
    • previous:previous value
    • +
    • next:next value
    • +
    +
  • +
+
+ } + }, + { + name: "UNIX_TIMESTAMP", + syntax: `UNIX_TIMESTAMP(date)`, + description: `Returns a Unix timestamp the value of the argument as seconds since '1970-01-01 00:00:00' UTC.`, + example: [ + { + purpose: `Specify a datetime string "2019-06-06 19:11:12", calculate the Unix timestamp:`, + code: "UNIX_TIMESTAMP('2019-06-06 19:11:12')" + }, + { + purpose: `Specify a ISO8601 datetime string with time zone information "2019-10-12T14:20:50+08:00", calculate the Unix timestamp:`, + code: "UNIX_TIMESTAMP('2019-10-12T14:20:50+08:00')" + }, + { + purpose: `Specify a ISO8601 datetime string with UTC+0 time zone information "2019-10-12T14:20:50Z", calculate the Unix timestamp:`, + code: "UNIX_TIMESTAMP('2019-10-12T14:20:50Z')" + }, + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+

The date argument may be a DATE, DATETIME or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format.

+
    +
  • Standard datetime string(UTC+0) : UNIX_TIMESTAMP('2019-06-06 19:11:12')
  • +
  • ISO8601 datetime string:UNIX_TIMESTAMP('2019-10-12T14:20:50Z') or UNIX_TIMESTAMP('2019-10-12T14:20:50+08:00')
  • +
  • Date: UNIX_TIMESTAMP(DATE('2019-06-06 19:11:12'))
  • +
+
+ } + }, + { + name: "FROM_UNIXTIME", + syntax: `FROM_UNIXTIME(unix_timestamp)`, + description: `Returns a representation of unix_timestamp as a datetime or character string value. The value returned is expressed using the UTC+0 time zone.`, + example: [ + { + purpose: `Specify a Unix Timestamp "1570881546", calculate the datetime string:`, + code: "FROM_UNIXTIME(1570881546)" + }, + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
The unix_timestamp is an internal timestamp value representing seconds since '1970-01-01 00:00:00' UTC.
+ } + }, + { + name: "DATE_FORMAT", + syntax: "DATE_FORMAT(date, format)", + description: `Formats the date value according to the format string.`, + example: [ + { + purpose: `Specify a Unix Timestamp "1570881546", calculate the datetime string with format "%Y-%m-%d %H:%i:%s":`, + code: "DATE_FORMAT(FROM_UNIXTIME(1570881546), '%Y-%m-%d %H:%i:%s')" + } + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+

The DATE_FORMAT function accepts two parameters as given below :

+
    +
  • date – Specified date to be formatted.
  • +
  • + format – Specified format. This list of formats used in this function are listed below: +
      +
    • %Y - Year, numeric, four digits
    • +
    • %y - Year, numeric (two digits)
    • +
    • %M - Month name (January..December)
    • +
    • %m - Month, numeric (00..12)
    • +
    • %D - Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
    • +
    • %d - Day of the month, numeric (00..31)
    • +
    • %H - Hour (00..23)
    • +
    • %h - Hour (01..12)
    • +
    • %i - Minutes, numeric (00..59)
    • +
    • %s - Seconds (00..59)
    • +
    • %w - Day of the week (0=Sunday..6=Saturday)
    • +
    +
  • +
+
+ } + }, + { + name: "CONVERT_TZ", + syntax:`CONVERT_TZ(dt, from_tz, to_tz)`, + description: `Converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value.`, + example: [ + { + purpose: `Specify a datetime string "2021-11-11 00:00:00", converted from GMT(Greenwich Mean Time) to Asia/Shanghai time zone:`, + code: "CONVERT_TZ('2021-11-11 00:00:00','GMT','Asia/Shanghai')" + }, + { + purpose: `Specify a Unix timestamp "1636588800", converted from GMT(Greenwich Mean Time) to Asia/Shanghai time zone:`, + code: "CONVERT_TZ(FROM_UNIXTIME(1636588800),'GMT','Asia/Shanghai')" + }, + { + purpose: `Specify a Unix timestamp "1636588800", converted from Europe/London to America/New_York time zone:`, + code: "CONVERT_TZ(DATE_FORMAT(FROM_UNIXTIME(1636588800), '%Y-%m-%d %H:%i:%s'),'Europe/London','America/New_York')" + }, + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+

The CONVERT_TZ function accepts a three-parameter:

+
    +
  • dt - The given DateTime which we want to convert.
  • +
  • from_tz - The time zone from which we want to convert DateTime.
  • +
  • to_tz - The time zone in which we want to convert DateTime.
  • +
+
+ } + }, + { + name: "MEDIAN", + syntax:`MEDIAN()`, + description: `Aggregate function is used to calculate median value. expr must be Integer, Float or Decimal.`, + example: [ + { + purpose: `Calculates the median "TCP Handshake Latency (tcp_handshake_latency_ms)" field:`, + code: "MEDIAN(tcp_handshake_latency_ms)" + } + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
In Traffic logs analysis, the function can be useful in calculating the median of certain numbers, e.g. median SSL Handshake Latency or TCP Handshake Latency.
+ } + }, + { + name: "QUANTILE", + syntax:`QUANTILE([, ])`, + description: `Aggregate function is used to calculate an approximate quantile of a numeric data sequence.`, + example: [ + { + purpose: `Calculates the 90th percentile "TCP Handshake Latency (tcp_handshake_latency_ms)" field:`, + code: "QUANTILE(tcp_handshake_latency_ms, 0.9)" + } + ], + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+

The QUANTILE function accepts a two-parameter:

+
    +
  • expr - The column values resulting in integer, Flot or Decimal.
  • +
  • level - Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. We recommend using a level value in the range of [0.01, 0.99]. Default value is 0.5. At level=0.5 the function calculates MEDIAN.
  • +
+
+ } + }, +]; + +function main() { + var functionTips = {} + renderData.forEach((item, index) => { + var data=item // 这是个闭包 + functionTips[item.name] = { + name: item.name, + syntax: item.syntax, + type: "Function", + description() { + return (
+

{data.name}

+

Syntax:{data.syntax}

+

Description:

+

{data.description}

+

Examples:

+
    + {item.example.map(v => { + return
  • + {v.purpose} + {v.code} +
  • + })} +
+

Details:

+ {Object.prototype.toString.call(data.details) === '[object Function]' ? + :

{data.details}

} +
) + } + }; + }) + return functionTips +} +export const functionList=renderData +var functionTips = main(); +export default functionTips diff --git a/src/components/advancedSearch/showhint/const/operatorTips.js b/src/components/advancedSearch/showhint/const/operatorTips.js new file mode 100644 index 00000000..e4b02794 --- /dev/null +++ b/src/components/advancedSearch/showhint/const/operatorTips.js @@ -0,0 +1,274 @@ +var renderData=[ + { + name:"EQUALS", + syntax:"=", + primaryKey:"=", + description:"Search for logs where the value of a specified field exactly matches a specified value.", + example:[ + { + purpose:"Search all logs that are sent by 192.168.10.53:", + code:"client_ip='192.168.10.53'" + }, + { + purpose:"Search all logs that are communication destination port by 443:", + code:"server_port=443" + }, + ], + details(){ + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
If you want search for logs where the value of a specified field is one of multiple specified values. Use multiple EQUALS(=) statements with the OR keyword, or use IN operator.
+ } + }, + { + name:"NOT EQUALS", + syntax:"!=", + primaryKey:"!=", + description:"Search for logs where the value of a specified field doesn't match a specified value.", + example:[ + { + purpose:"Search all logs that are sent to any Client IP except 192.168.10.53:", + code:"client_ip!='192.168.10.53'" + }, + { + purpose:"Search all logs that are not communication port to 443:", + code:"server_port!=443" + }, + ], + details:`If you want search for logs where the value of a specified field is one of multiple specified values. Use multiple NOT EQUALS(!=) statements with the AND keyword, or use NOT IN operator.` + }, + { + name:"GREATER THAN", + syntax:">", + primaryKey:">", + description:"Search logs greater than a value . This operator can't be used with string fields. ", + example:[ + { + purpose:"Search all logs more than 751 Bytes ", + code:"sent_bytes > 751" + }, + { + purpose:"Search all logs where bandwidth is higher than 751 Bytes:", + code:"received_bytes + sent_bytes > 751" + }, + ], + details:`The GREATER THAN(>) condition is usally used with LESS THAN(<) as a range query. ` + }, + { + name:"GREATER THAN EQUALS", + syntax:">=", + primaryKey:">=", + description:"Search logs greater than and equal a value. This operator can't be used with string fields. ", + example:[ + { + purpose:"Search all logs with 751 or more Bytes", + code:"sent_bytes >= 751" + }, + { + purpose:"Search all logs where bandwidth is equal or higher than 751 Bytes:", + code:"received_bytes + sent_bytes >= 751" + }, + ], + details:`The GREATER THAN EQUALS(>=) condition is usally used with LESS THAN EQUALS(<=) as a range query.` + }, + { + name:"LESS THAN", + syntax:"<", + primaryKey:"<", + description:"Search logs less than a value. This operator can't be used with string fields.", + example:[ + { + purpose:"Search all logs less than 751 Bytes :", + code:"sent_bytes < 751" + }, + { + purpose:"Search all logs where bandwidth is less than 751 Bytes:", + code:"received_bytes + sent_bytes < 751" + }, + ], + details:`The LESS THAN(<) condition is usally used with GREATER THAN(>) as a range query.` + }, + { + name:"LESS THAN EQUALS", + syntax:"<=", + primaryKey:"<=", + description:"Search logs less than and equal a value. This operator can't be used with string fields. ", + example:[ + { + purpose:"Search all logs with 751 or fewer Bytes", + code:"sent_bytes <= 751" + }, + { + purpose:"Search all logs where bandwidth is equal or fewer than 751 Bytes:", + code:"received_bytes + sent_bytes <= 751" + }, + ], + details:`LESS THAN EQUALS(<=) condition is usally used with GREATER THAN EQUALS(>=) as a range query. ` + }, + { + name:"IN", + syntax:"in", + primaryKey:"IN", + description:"Search for logs where the value of a specified field is one of multiple specified values.", + example:[ + { + purpose:"Search all logs in communication destination port 443 or 80:", + code:"server_port in (443, 80)" + }, + { + purpose:"Search all logs where the Server IP or Client IP is either 8.8.8.8 or 192.168.10.53:", + code:"client_ip in ('8.8.8.8', '192.168.50.53') or server_ip in ('8.8.8.8', '192.168.10.53')" + }, + ], + details:`The IN condition you can use when you need to use multiple OR condition. The values are specified as a comma-separated(,) list,surrouded by parentheses. Using IN is equivalent to using multiple EQUALS(=)statements with OR expression. That is server_port in (443,80) is the same as (server_port=443 OR server_port=80).` + }, + { + name:"NOT IN", + syntax:"not in", + primaryKey:"NOT IN", + description:"Search for logs where the value of a specified field isn't one of multiple specified values.", + example:[ + { + purpose:"Search all logs not in communication destination port 443 or 80:", + code:"server_port not in (443, 80)" + }, + { + purpose:"Search all logs where the Server IP and Client IP isn't 8.8.8.8 or 192.168.10.53:", + code:"client_ip not in ('8.8.8.8', '192.168.10.53') and server_ip not in ('8.8.8.8', '192.168.10.53')" + }, + ], + details:`The NOT IN condition you can use when you need to use multiple OR condition. The values are specified as a comma-separated(,) list,surrouded by parentheses. Using NOT IN is equivalent to using multiple NOT EQUALS(!=)statements with AND expression. That is , server_port not in (443,80) is the same as (server_port !=443 AND server_port !=80).` + }, + { + name:"LIKE", + syntax:"like", + primaryKey:"LIKE", + description:"Search for logs where use wildcard searches for value that contain search fields. This operator can be used with string fields. ", + example:[ + { + purpose:`Search all logs where the SSL SNI end with( suffix match) "google.com":`, + code:"ssl_sni like '%google.com'" + }, + { + purpose:"Search all logs where the Client IP start with(prefix match) '192.168':", + code:"client_ip like '192.168%'" + }, + { + purpose:`Search all logs where the Client IP contains "192.168.1" , between 192.168.10.10 and 192.168.10.19:`, + code:"client_ip like '192.168.10.1_'" + }, + ], + details:`The LIKE condition supports single and multiple character searches.Using percent (%) wildcard substitutes for one or more characters in a string. Using underscore (_) wildcard substitutes for exactly one character in a string. This operator can be used for searval purposes : checking a substring , checking the start or end of a string.` + }, + { + name:"NOT LIKE", + syntax:"not like", + primaryKey:"NOT LIKE", + description:"Search for logs where use wildcard searches for value that not contain search fields. This operator can be used with string fields.", + example:[ + { + purpose:`Search all logs where the SSL SNI not contain end with( suffix match) "google.com":`, + code:"ssl_sni not like '%google.com'" + }, + { + purpose:"Search all logs where the Client IP not contain start with(prefix match) '192.168':", + code:"client_ip not like '192.168%'" + }, + { + purpose:`Search all logs where the Client IP not contains "192.168.1" , between 192.168.10.10 and 192.168.10.19:`, + code:"client_ip not like '192.168.10.1_'" + }, + ], + details:`The NOT LIKE condition supports single and multiple character searches. Using percent (%) wildcard substitutes for one or more characters in a string. Using underscore (_) wildcard substitutes for exactly one character in a string. This operator can be used for searval purposes : checking a substring , checking the start or end of a string.` + }, + { + name:"HAS", + syntax:"has", + primaryKey:"HAS", + description:"Search for logs where the values of a specified field is one of specified value.This operator can be used with array fields.", + example:[ + { + purpose:`Search all logs where the FQDN Category has the music(60):`, + code:"has(service_category,60)" + } + ], + details:`The HAS condition checks whether the "expr" array has the "value" element. The syntax has(expr, value).` + }, + { + name:"EMPTY", + syntax:"empty", + primaryKey:"EMPTY", + description:"Search for logs where the specified field has empty value. This operator can be used with string and array fields.", + example:[ + { + purpose:`Search all logs where Application is not identified.`, + code:"empty(common_app_label)" + } + ], + details:`An empty string is a string of zero length. However , a NULL has no value at all. An empty string is useful when the data comes from multiple resources. NULL is used when some fields are optional, and the data is unknown.` + }, + { + name:"NOT EMPTY", + syntax:"notEmpty", + primaryKey:"NOTEMPTY", + description:"Search for logs where the specified field has a value. This operator can be used with string and array fields.", + example:[ + { + purpose:`Search all logs that have one or more SNIs.`, + code:"notEmpty(ssl_sni)" + } + ], + details:`A not empty string is considered at least one byte, even if this a space.` + }, + { + name:"Bitwise AND", + syntax:"bitAnd", + primaryKey:"BITAND", + description:`A bitwise And(&) is a binary operation that compares each bit of the first operand to the corresponding bit of the second operand. Both expressions must have integral types.`, + example:[ + { + purpose:`Search all logs where the Flags has the Asymmetric(524288) and Download(134217728):`, + code:"bitAnd(Flags, 134742016) = 134742016" + }, + { + purpose:`Search all logs where the flags has either Asymmetric(524288) or Download(134217728):`, + code:"bitAnd(Flags, 134742016)>0" + } + ], + details:`The operands are converted to 64-bit integers and expressed by a series of bits (zeroes and ones). Sets each bit to 1 if both bits are 1.` + }, +] +export const operatorList=renderData +function main(){ + var operatorTips={} + renderData.forEach((item,index)=>{ + var data=item // 这是个闭包 + operatorTips[item.primaryKey]={ + name: item.name, + syntax: item.syntax, + type: "Operators", + description() { + return (
+

{data.name}

+

Syntax:{data.syntax}

+

Description:

+

{data.description}

+

Examples:

+
    + {item.example.map(v=>{ + return
  • + {v.purpose} + {v.code} +
  • + })} +
+

Details:

+ {Object.prototype.toString.call(data.details) === '[object Function]' ? :

{data.details}

} +
) + } + }; + }) + return operatorTips +} + +var operatorTips=main(); +export default operatorTips diff --git a/src/components/advancedSearch/showhint/const/sqlTips.js b/src/components/advancedSearch/showhint/const/sqlTips.js new file mode 100644 index 00000000..b3f7c7ed --- /dev/null +++ b/src/components/advancedSearch/showhint/const/sqlTips.js @@ -0,0 +1,96 @@ +var renderData=[ + { + name: "FROM", + syntax: `FROM [db.]table |$log_type`, + description: { + title:`The table name of logs. If you type $log_type, the variable value is the current table name of logs.` + } + }, + { + name: "SELECT", + syntax: `Optional. The selected columns(also known as dimensions and metrics).`, + description: { + title:'可选,获取列', + list:[ + `aggregate_function(field) - Aggregate functions, default is count.`, + `as field - Use as to specify a aliases for a field or expression.` + ] + } + }, + { + name: "GROUP BY", + syntax: `GROUP BY `, + description: { + title:'Aggregate data. GROUP BY clause switches the SELECT query into an aggregation mode:', + list:[ + `The list of fields known as "grouping key", while each individual expression be referred to as a "key expression".`, + `All the expressions in the SELECT, HAVING and ORDER BY , must be "key expression" or on aggregate functions.`, + `The result of aggregating SELECT query will return unique values of "grouping key" in log type.` + ] + } + }, + { + name: "HAVING", + syntax: `HAVING `, + description: { + title:`Optional. HAVING clause filtering the aggregation results retrieved by GROUP BY. It is difference is that WHERE is performed before aggregation, while HAVING is performed after it. + Note: HAVING can't be performed if GROUP BY is not performed.` + } + }, + { + name: "LIMIT", + syntax: `LIMIT [n, ]m`, + description: { + title:`Select the m rows from the aggregate results after skipping the first n rows. Default is 10 rows.` + } + }, + { + name: "ORDER BY", + syntax: `ORDER BY [ASC|DESC]`, + description: { + title:`Sort all of the results by the specified fields.` + } + }, + { + name: "WHERE", + syntax: `where $filter [and ]`, + description: { + title:`Filter the data.`, + list:[ + `$filter - Default global filter clause. Include Time period, Vsys ID, and other expressions, etc`, + `and - filter clauses` + ] + } + } +] +export const sqlList=renderData +function main(){ + var sqlTips={} + renderData.forEach((item,index)=>{ + var data=item // 这是个闭包 + sqlTips[item.name]={ + name: item.name, + syntax: item.syntax, + type: "sql", + description() { + return (
+

{data.name}

+

Syntax: {data.syntax}

+

Description:

+

{data.description.title}

+ { + data.description.list &&
    + {data.description.list.map(v=>{ + return
  • {v}
  • + })} +
+ } +
) + } + }; + }) + return sqlTips +} + +var sqlTips=main(); +export default sqlTips diff --git a/src/components/advancedSearch/showhint/const/varTips.js b/src/components/advancedSearch/showhint/const/varTips.js new file mode 100644 index 00000000..3d6a4dc1 --- /dev/null +++ b/src/components/advancedSearch/showhint/const/varTips.js @@ -0,0 +1,48 @@ +var renderData = [ + { + name: '$LOG_TYPE', + description: 'A variable is a symbolic representation of data that enables you to access a value without having to enter it manually wherever you need it. You can use $ to reference variables throughout Advanced Search. ', + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+ $log_type: The table name of logs. +
+ } + }, + { + name: '$FILTER', + description: 'A variable is a symbolic representation of data that enables you to access a value without having to enter it manually wherever you need it. You can use $ to reference variables throughout Advanced Search. ', + details() { + //支持jsx 嵌套写法,万一测试要关键字加重呢 + return
+ $filter: The default filter clauses. such as time period, Vsys ID, and other default expressions, etc. +
+ } + }, +]; + +function main() { + const varTips = {} + renderData.forEach((item, index) => { + const data = item // 这是个闭包 + varTips[item.name] = { + name: item.name, + type: 'Variables', + description() { + return (
+

{data.name}

+

Description:

+

{data.description}

+

Details:

+ {Object.prototype.toString.call(data.details) === '[object Function]' ? + :

{data.details}

} +
) + } + }; + }) + return varTips +} + +export const varList = renderData +const varTips = main() +export default varTips diff --git a/src/components/advancedSearch/showhint/myCodeMirror.js b/src/components/advancedSearch/showhint/myCodeMirror.js new file mode 100644 index 00000000..94e79ebd --- /dev/null +++ b/src/components/advancedSearch/showhint/myCodeMirror.js @@ -0,0 +1,129 @@ +import 'codemirror/lib/codemirror.css' +import 'codemirror/theme/eclipse.css' +import 'codemirror/mode/sql/sql' + +import 'codemirror/theme/ambiance.css' +import 'codemirror/addon/hint/show-hint' +import 'codemirror/addon/hint/show-hint.css' +import 'codemirror/addon/display/placeholder' + +import 'codemirror/addon/hint/anyword-hint' // 关键字 +import 'codemirror/addon/comment/comment' +import 'codemirror/keymap/sublime' +import 'codemirror/addon/edit/closebrackets' +import CodeMirror from 'codemirror' +import createMode from '@/components/advancedSearch/showhint/TextSearch/sql' +import createHint from '@/components/advancedSearch/showhint/TextSearch/createHint' +import { functionList } from '@/components/advancedSearch/showhint/const/functionTips' +import { cloneDeep } from 'lodash' + +const codeMirrorMixins = { + data () { + return { + CodeMirror, + initData: {}, + hintSearch: '', + hintList: [], + hintParams: {}, + completion: null + } + }, + methods: { + initShowHint () { + const dataset = this.dataset + createMode(CodeMirror, { + dataset, + modehook: this.modehook + }) + + const hintHook = this.manualHinthook + const vm = this + createHint('manual', CodeMirror, { + dataset, + hinthook: hintHook, + callback (completion, defaultOptions) { + vm.completion = completion.completion + }, + keyboardUp () { + // 键盘向上 + vm.hintVm?.handleUp() + }, + keyboardDown () { + // 键盘向下 + vm.hintVm?.handleDown() + }, + keyboardEnter () { + if (!vm.hintVisible) { + return + } + // 回车 选中值 + vm.hintVm?.triggerSelect() + } + }) + }, + manualHinthook (result, params, manualParams) { + this.hintParams = manualParams + this.hintSearch = manualParams.search + + this.hintList = [] + const list = this.hinthook(result, params) + this.hintList = cloneDeep(list) + return list + }, + hinthook (result, { search, keywords, leftpart, rightpart }) { + if (leftpart) { + const options = this.matchOptions(leftpart) + if (options) { + return options + } + } + result = this.dataset.getHintList(search, null, null, this.value) + return result + }, + matchOptions (leftpart) { + // 用于匹配下拉选 + + const fieldInfo = this.dataset.getFieldInfo(leftpart) + if (fieldInfo && fieldInfo.options) { + const options = [] + options.push( + { + type: 'abstract', + text: '', + displayText: 'Options', + className: 'divider hint-title' + } + ) + const fieldOptions = cloneDeep(fieldInfo.options) + // eslint-disable-next-line no-return-assign + fieldOptions.forEach(item => item.displayText = `${item.displayText}(${item.text})`) + options.push(...fieldOptions) + return options + } + return null + }, + modehook (CodeMirror, set, { client, keywords, builtin, hookVar }) { + // 自定义 过滤器类型 + const clientWords = this.dataset.getClientwords() + let clientWordsStr = '' + clientWordsStr = clientWords.join(' ') + const dateFuns = functionList.map(v => v.name.toLowerCase()) + CodeMirror.defineMIME('text/x-filter', { + name: 'sql', + client: set(clientWordsStr + ' ' + client), // 客户端解析指令 + builtin: set(builtin + ' like in not empty notempty has bitand'), + keywords: set(keywords + ' and or ' + dateFuns.join(' ')), + + atoms: set('false true null unknown'), + operatorChars: /^[*+\-%<>!=&|^]/, + dateSQL: set('date time timestamp '), + support: set('ODBCdotTable doubleQuote binaryNumber hexNumber'), // 支持的数据编码 ODBC double 二进制 16进制 + hooks: { + $: hookVar + } + }) + } + } +} + +export default codeMirrorMixins diff --git a/src/components/advancedSearch/showhint/packages/getDataset.js b/src/components/advancedSearch/showhint/packages/getDataset.js new file mode 100644 index 00000000..e6b076f2 --- /dev/null +++ b/src/components/advancedSearch/showhint/packages/getDataset.js @@ -0,0 +1,290 @@ +// 改js 用户获取初始化的 SchemaData +import { Scheme } from './service/Scheme' + +export class Dataset { + constructor ({ operatesList, filtersList, operatesDic, funcDic, operatorManual, fields, doc }) { + this.sourceData = {} + this.sourceData = this.keepSourcedata(operatesList, funcDic, filtersList, operatesDic, operatorManual, fields, doc) + // 存储格式化的数据 + this.hintData = {} + this.hintData.operatesList = this.formatOperates(operatesList) + this.hintData.filtersList = this.formatFilters(filtersList) + } + + getHintList (keyword, sqlKeywordsOptions = null, callback, completeFilter) { + // 获取提示列表 + const operatesList = this.matchFilter(sqlKeywordsOptions || this.hintData.operatesList || [], keyword) + const filtersList = this.matchFilter(this.hintData.filtersList || [], keyword) + + const hintList = [...operatesList, ...filtersList] + callback && callback(operatesList, filtersList, hintList) + return hintList + } + + getClientwords () { + // 获取高亮的 可查询的 字段 + const filtersList = this.sourceData.filtersList || [] + const clientwords = [] + filtersList.forEach((item) => { + // 可以在这里增加 过滤逻辑 + // todo client由name改为label + // clientwords.push(item.name) + clientwords.push(item.label) + }) + return clientwords + } + + matchFilter (list, keyword) { + // 用于 匹配过滤器 + const results = list.filter((item) => { + if (item.type === 'abstract') { + return true + } + let displayTextLow = item.displayText + '' ? (item.displayText + '').toLowerCase() : item.displayText + let keywordLow = keyword + '' ? (keyword + '').toLowerCase() : keyword + + const reg = /[ '"]/ig + displayTextLow = (displayTextLow + '').replace(reg, '').toLowerCase() + keywordLow = (keywordLow + '').replace(reg, '').toLowerCase() + + return displayTextLow && displayTextLow.indexOf(keywordLow) !== -1 + }) + const hasEnable = results.some((item) => { + return item.type !== 'abstract' + }) + return hasEnable ? results : [] + } + + formatFilters (list) { + // 格式化 过滤器 + if (!(list && list.length > 0)) { + return + } + let tempTitle + let results + tempTitle = { + type: 'abstract', + text: '', + // displayText: "Filter", + displayText: 'filter', + className: 'divider hint-title', + hint (cm, callback, options) { + } + } + + results = list.map((item) => { + return { + // text: item.name, + // displayText: `${item.label}(${item.name})`, + text: item.label, + displayText: `${item.name}(${item.label})`, + className: 'filter-item el-dropdown-menu__item relative-item' + } + }) + results.unshift(tempTitle) + return results + } + + formatOperates (list) { + // 格式化 操作符 + if (!(list && list.length > 0)) { + return + } + let tempTitle = {} + let results = [] + tempTitle = { + type: 'abstract', + text: '', + // displayText: "Operator", + displayText: 'operator', + className: 'divider hint-title' + // hint(cm, callback, options) {} + } + + results = list.map((item) => { + return { + text: item.name, + displayText: item.name, + className: 'operates-item el-dropdown-menu__item relative-item' + // hint(cm, callback, options) {} + } + }) + results.unshift(tempTitle) + return results + } + + keepSourcedata (operatesList, funcDic, filtersList, operatesDic, operatorManual, fields, doc) { + // 初始化原始数据 方法(存放的是 全量原始数据) + const sourceData = {} + // 支持的逻辑运算符 + sourceData.operatesList = operatesList || [] + // 过滤器列表 + sourceData.filtersList = filtersList || [] + sourceData.operatesDic = operatesDic || [] + sourceData.operatorReference = doc?.functions?.operator || [] + sourceData.operatorManual = operatorManual || [] + + // 添加全量数据 + sourceData.fields = fields || [] + sourceData.doc = doc || {} + + // 存储function 的原始变量 + sourceData.funcDic = funcDic || [] + const aggregation = doc?.functions?.aggregation || [] + const dateFuns = doc?.functions?.date || [] + sourceData.funcReference = [...dateFuns, ...aggregation] + + return sourceData + } + + matchHightlight (keyWord) { + // 匹配高亮 + // var reg = new RegExp(keyWord, 'i') + let matchFlag = false + // reg.test(val) + matchFlag = this.sourceData.operatesList.some((item) => { + return keyWord === item.name + }) + if (matchFlag) { + return 'keyword' + } + if (matchFlag) { + return 'variable-2' + } + matchFlag = this.sourceData.filtersList.some((item) => { + return keyWord === item.name + }) + if (matchFlag) { + return 'comment' + } + matchFlag = this.sourceData.specialCharacters.some((item) => { + return keyWord === item.name + }) + if (matchFlag) { + return 'atom' + } + } + + getOperates (type, item) { + // 获取 当前类型支持的操作符 + let operator_functions = '' + if (item && item.doc && item.doc.constraints && item.doc.constraints.operator_functions) { + operator_functions = item.doc.constraints.operator_functions + } else { + const functions = this.sourceData.operatesDic.find(item => { + return item.type === type + }) + operator_functions = functions && functions.functions || '' + } + const funList = operator_functions.split(',') + let result = [] + result = funList.map((item) => { + return { + text: item, + displayText: item, + className: 'filter-item el-dropdown-menu__item relative-item' + } + }) + return result + } + + getFunctions (type, item) { + // 获取 当前类型支持的操作符 + let functionsInfo = '' + // 这里肯定有问题 + if (item && item.doc && item.doc.constraints && item.doc.constraints.aggregation_functions) { + functionsInfo = item.doc.constraints.aggregation_functions + } else { + const functions = this.sourceData.funcDic.find(item => { + return item.type === type + }) + functionsInfo = functions && functions.functions || '' + } + + const funList = functionsInfo.split(',') + let result = [] + result = funList.map((item) => { + return { + text: item, + displayText: item, + className: 'filter-item el-dropdown-menu__item relative-item' + } + }) + return result + } + + getFieldInfo (keywords) { + // 获取字段的相关信息 1.下拉数据是需要获取的 2.支持的运算符 是不是需要呢 ??? + if (!keywords || !keywords.toLowerCase) { + return + } + keywords = (keywords.trim && keywords.trim()) || keywords + const fieldInfo = {} + const matchItem = this.sourceData.filtersList.find((item) => { + const itemName = item.name && item.name.toLowerCase() + return keywords.toLowerCase() === itemName + }) + if (!matchItem) { + return null + } + // 存在下拉值 候选项 + if (matchItem && matchItem.doc && matchItem.doc.data) { + fieldInfo.options = matchItem.doc.data.map(item => { + return { + text: matchItem.type === 'string' ? `'${item.code}'` : item.code, + displayText: item.value, + className: 'filter-item el-dropdown-menu__item relative-item' + } + }) + fieldInfo.operateType = 'select' + } + // 这是一个 远程下拉值 + if (matchItem && matchItem.doc && matchItem.doc.dict_location) { + fieldInfo.operateType = 'remoteSelect' + } + + fieldInfo._matchItem = matchItem + fieldInfo.name = matchItem.name + fieldInfo.type = matchItem.type + fieldInfo.label = matchItem.label + return fieldInfo + } + + getFieldList () { + // 获取字段列表 + const fieldList = (this.sourceData && this.sourceData.filtersList) || [] + return fieldList + } + + getOperatorItem (code) { + const operators = this.sourceData.operatorManual || [] + const matchItem = operators.find(item => { + return item.name === code.trim() + }) + if (matchItem && !matchItem.label) { + matchItem.label = matchItem.name + } + return matchItem || null + } + + dispose () { + this.sourceData = null + this.hintData.operatesList = null + this.hintData.filtersList = null + this.hintData = null + } +} + +// 获取数据集 +export function getDataset (component, params) { + return new Promise((resolve, reject) => { + const schemeInstance = new Scheme(component, params) + schemeInstance.getFormatedData((schemeData) => { + const dataset = new Dataset(schemeData) + resolve(dataset, () => { + schemeInstance.dispose() + dataset.dispose() + }) + }) + }) +} diff --git a/src/components/advancedSearch/showhint/packages/service/DeviceTag.js b/src/components/advancedSearch/showhint/packages/service/DeviceTag.js new file mode 100644 index 00000000..c5805545 --- /dev/null +++ b/src/components/advancedSearch/showhint/packages/service/DeviceTag.js @@ -0,0 +1,94 @@ +import {dataTemplate, fieldTemplate} from './template' + +export class DeviceTag { + constructor(context, params) { + //先从缓存获取数据 + this.queryparams = params + this.context = context + } + + filterQueryData(list) { + return list + } + + getDataFromRemote() { + //从 远程,也就是请求接口获取数据 + return this.context.$get('/deviceTag', this.queryparams).then((res) => { + this.context.initDataReadyCb && this.context.initDataReadyCb(res.data || null); //组件 请求 文件成功回调 + if (res.code === 200) { + var data = res.data && res.data.list; + return data + } else { + // this.context.$message({ + // message: '请求 DeviceTag数据失败', + // type: 'error', + // showClose: true + // }); + } + return null + }).catch((err) => { + console.error(err) + }) + } + + formatData(data) { + //格式化 获取的数据 + const resultData = { + operatesList: [ + { + "name": "AND", + "function": "A AND B", + type: "abstract", + label: "AND" + } + ], + filtersList: data ? this.filterQueryData(data.fields || []) : [], + //操作符仓库 用于记录 类型 和 操作符之间的映射关系 + operatesDic: data ? data.doc.schema_query.references.operator || [] : [], + //operator 记录运算符的label 和 value 映射 以及操作符的使用方法 + operatorManual: data ? data.doc.functions.operator || [] : [] + } + return resultData + } + + organizeData(data=[]) { + var fields = [] + var res = JSON.parse(JSON.stringify(dataTemplate)); + if (!data ) { + return + } + data.forEach((item, index) => { + var fieldItem = JSON.parse(JSON.stringify(fieldTemplate)); + fieldItem.name = item.tagValue + fieldItem.type = "Array" + fieldItem.label = item.tagName + fieldItem.doc.data = (item.subTags || []).map(tagItem => { + return { + code: `'${tagItem.tagValue}'`, //匹配SQL 的时候,这个Code 要加 '' + value: tagItem.tagName, + type: tagItem.tagType + } + }) + fields.push(fieldItem) + }) + res.fields = fields + return res + } + + getFormatedData(callback) { + this.getDataFromRemote().then(data => { + //组织数据 模拟scama + var organizedData = this.organizeData(data); + //格式化数据 + this.data = this.formatData(organizedData) + //获取scameData的时候 查询映射字段 + callback && callback(this.data) + }) + } + + dispose(){ + this.context=null + this.queryparams=null + this.data=null + } +} diff --git a/src/components/advancedSearch/showhint/packages/service/Scheme.js b/src/components/advancedSearch/showhint/packages/service/Scheme.js new file mode 100644 index 00000000..65e2f9d0 --- /dev/null +++ b/src/components/advancedSearch/showhint/packages/service/Scheme.js @@ -0,0 +1,133 @@ +// import vm from '@/main.js' +import { getSchemaInfo } from '@/utils/timeQueryApi' +import { cacheData } from '@/components/advancedSearch/showhint/packages/service/mockData' +// import {cacheData} from "@/components/common/search/packages/service/oldMockData"; + +export class Scheme { + constructor (context, params) { + // 先从缓存获取数据 + this.queryparams = params + this.context = context + this.schemeData = null + } + + filterQueryData (list) { + // 仅仅过滤掉 无用的数据 allow_query 为false 的数据 visibility==hidden/disabled DoS日志补充 start_time + const denyList = ['recv_time', 'start_time'] + let result + result = list.filter((item, index) => { + // return (item.doc && item.doc.allow_query === 'true') && !denyList.includes(item.name) + // 在前端禁止搜索字段中 或者 接口不允许搜索得字段 过滤掉 + return !(item.doc && item.doc.allow_query === 'false') && !denyList.includes(item.name) && !(item.doc && (item.doc.visibility == 'disabled' || item.doc.visibility == 'hidden')) + }) + return result || [] + } + + async getSchemaDataFromRemote () { + const schemaData = await getSchemaInfo(this.queryparams?.logType) + this.context.initDataReadyCb && this.context.initDataReadyCb(schemaData || null) + return schemaData + } + + formatSchemaData (data) { + // 格式化 获取的数据 + const formatedData = { + operatesList: [ + { + name: 'AND', + function: 'A AND B', + type: 'abstract', + label: 'AND' + } + // { + // name: 'OR', + // function: 'A OR B', + // type: 'abstract', + // label: 'OR' + // } + ], + filtersList: data ? this.filterQueryData(data.fields || []) : [], + // 操作符仓库 用于记录 类型 和 操作符之间的映射关系 + operatesDic: data ? (data.doc.schema_query && data.doc.schema_query.references.operator) || [] : [], + + // 操作符仓库 用于记录 类型 和 聚合函数之间的映射关系 + funcDic: data ? (data.doc.schema_query && data.doc.schema_query.references.aggregation) || [] : [], + + // operator 记录运算符的label 和 value 映射 以及操作符的使用方法 + operatorManual: data ? data.doc.functions.operator || [] : [], + + // 全部附属信息 这些是需要的 + doc: data.doc, + + // 全部字段信息 fields + fields: data.fields + } + + // date 和 timestamp 支持的方法 需要特殊处理 ,补充事件函数处理 + const dateFuns = (data?.doc?.functions?.date || []).map(item => { + return item.name + }) + formatedData.funcDic.forEach(item => { + if (['date', 'timestamp'].includes(item.type)) { + // eslint-disable-next-line no-unused-expressions + dateFuns.length > 0 ? item.functions = item.functions + ',' + dateFuns.join(',') : '' + } + }) + return formatedData + } + + getRemoteOptions () { + // query 查询地址 key 关键字(唯一标识) value 值就是label 用于展示 + this.schemeData.filtersList.forEach((item) => { + if (item.doc && item.doc.data) { + return + } + if (item.doc && item.doc.dict_location) { + const { path, key, value } = item.doc.dict_location + return vm.$get(path, { pageSize: 500, pageNo: 1 }).then((res) => { + if (res.code === 200) { + const dataList = res.data.list + if (res.data.total > 500) { + // 超出500条 直接不处理了 ,没缓存 + return + } + localStorage.setItem(`${this.context.$route.path}_${item.name}`, JSON.stringify(res.data.list)) + const data = dataList.map(item => { + return { + code: item[key], + value: item[value] + } + }) + item.doc.data = data + } + }).catch((err) => { + console.error(err) + }) + } + }) + } + + async getFormatedData (callback) { + const cacheDat = cacheData + if (cacheDat) { + this.schemeData = this.formatSchemaData(cacheDat) + // this.getRemoteOptions() + callback && callback(this.schemeData) + return + } + this.getSchemaDataFromRemote().then(data => { + this.schemeData = this.formatSchemaData(data) + // 获取schemaData的时候 查询映射字段 + // this.getRemoteOptions() + callback && callback(this.schemeData) + }) + callback && callback(this.schemeData) + return this.schemeData + } + + dispose () { + this.context = null + this.schemeData = null + this.queryparams = null + } +} diff --git a/src/components/advancedSearch/showhint/packages/service/mockData.js b/src/components/advancedSearch/showhint/packages/service/mockData.js new file mode 100644 index 00000000..3ea09e63 --- /dev/null +++ b/src/components/advancedSearch/showhint/packages/service/mockData.js @@ -0,0 +1,1062 @@ +export const cacheData = { + "type": "record", + "name": "session_record", + "namespace": "tsg_galaxy_v3", + "doc": { + "primary_key": "log_id", + "partition_key": "recv_time", + "index_key": [ + "vsys_id", + "security_action", + "app", + "proxy_action", + "decoded_as", + "data_center", + "device_group", + "recv_time" + ], + "ttl": 2592000, + "default_ttl": 2592000, + "functions": { + "aggregation": [ + { + "name": "COUNT", + "label": "COUNT", + "function": "count(expr)" + }, + { + "name": "COUNT_DISTINCT", + "label": "COUNT_DISTINCT", + "function": "count(distinct expr)" + }, + { + "name": "AVG", + "label": "AVG", + "function": "avg(expr)" + }, + { + "name": "SUM", + "label": "SUM", + "function": "sum(expr)" + }, + { + "name": "MAX", + "label": "MAX", + "function": "max(expr)" + }, + { + "name": "MIN", + "label": "MIN", + "function": "min(expr)" + }, + { + "name": "MEDIAN", + "label": "MEDIAN", + "function": "MEDIAN(expr)" + }, + { + "name": "QUANTILE", + "label": "QUANTILE", + "function": "QUANTILE(expr,level)" + }, + { + "name": "TIME_FLOOR_WITH_FILL", + "label": "TIME_FLOOR_WITH_FILL", + "function": "TIME_FLOOR_WITH_FILL(expr,period,fill)" + } + ], + "date": [ + { + "name": "UNIX_TIMESTAMP", + "label": "UNIX_TIMESTAMP", + "function": "UNIX_TIMESTAMP(expr)" + }, + { + "name": "FROM_UNIXTIME", + "label": "FROM_UNIXTIME", + "function": "FROM_UNIXTIME(expr)" + }, + { + "name": "DATE_FORMAT", + "label": "DATE_FORMAT", + "function": "DATE_FORMAT(expr,format)" + }, + { + "name": "CONVERT_TZ", + "label": "CONVERT_TZ", + "function": "CONVERT_TZ(expr, from_tz, to_tz)" + } + ], + "operator": [ + { + "name": "=", + "label": "=", + "function": "expr = value" + }, + { + "name": "has", + "label": "HAS", + "function": "has(expr, value)" + }, + { + "name": "in", + "label": "IN", + "function": "expr in (values)" + }, + { + "name": "like", + "label": "LIKE", + "function": "expr like value" + } + ] + }, + "schema_query": { + "dimensions": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "metrics": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "filters": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "references": { + "aggregation": [ + { + "type": "int", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN,MEDIAN,QUANTILE" + }, + { + "type": "string", + "functions": "COUNT,COUNT_DISTINCT" + }, + { + "type": "array", + "functions": "COUNT,COUNT_DISTINCT" + } + ], + "operator": [ + { + "type": "int", + "functions": "=,in,like,has" + }, + { + "type": "string", + "functions": "=,in,like,has" + }, + { + "type": "array", + "functions": "=,in,like,has" + } + ] + }, + "details": { + "general": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info" + ], + "treatment": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "source": [ + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number" + ], + "destination": [ + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain" + ], + "application": [ + "app_path", + "app", + "app_debug_info", + "app_content", + "fqdn_category_list" + ], + "protocol": [ + "protocol_path", + "dns_message_id", + "dns_qr", + "dns_opcode", + "dns_aa", + "dns_tc", + "dns_rd", + "dns_ra", + "dns_rcode", + "dns_qdcount", + "dns_ancount", + "dns_nscount", + "dns_arcount", + "dns_qname", + "dns_qtype", + "dns_qclass", + "dns_cname", + "dns_sub", + "dns_rr", + "dns_response_latency_ms", + "dtls_cookie", + "dtls_version", + "dtls_sni", + "dtls_san", + "dtls_cn", + "dtls_handshake_latency_ms", + "dtls_ja3_fingerprint", + "dtls_ja3_hash", + "dtls_cert_issuer", + "dtls_cert_subject", + "ftp_account", + "ftp_url", + "ftp_link_type", + "http_url", + "http_host", + "http_request_line", + "http_response_line", + "http_request_content_length", + "http_request_content_type", + "http_response_content_length", + "http_response_content_type", + "http_request_body", + "http_response_body", + "http_proxy_flag", + "http_sequence", + "http_cookie", + "http_referer", + "http_user_agent", + "http_set_cookie", + "http_version", + "http_status_code", + "http_response_latency_ms", + "http_session_duration_ms", + "http_action_file_size", + "mail_protocol_type", + "mail_account", + "mail_from_cmd", + "mail_to_cmd", + "mail_from", + "mail_password", + "mail_to", + "mail_cc", + "mail_bcc", + "mail_subject", + "mail_subject_charset", + "mail_attachment_name", + "mail_attachment_name_charset", + "mail_eml_file", + "quic_version", + "quic_sni", + "quic_user_agent", + "rdp_cookie", + "rdp_security_protocol", + "rdp_client_channels", + "rdp_keyboard_layout", + "rdp_client_version", + "rdp_client_name", + "rdp_client_product_id", + "rdp_desktop_width", + "rdp_desktop_height", + "rdp_requested_color_depth", + "rdp_certificate_type", + "rdp_certificate_count", + "rdp_certificate_permanent", + "rdp_encryption_level", + "rdp_encryption_method", + "ssh_version", + "ssh_auth_success", + "ssh_client_version", + "ssh_server_version", + "ssh_cipher_alg", + "ssh_mac_alg", + "ssh_compression_alg", + "ssh_kex_alg", + "ssh_host_key_alg", + "ssh_host_key", + "ssh_hassh", + "ssl_version", + "ssl_sni", + "ssl_san", + "ssl_cn", + "ssl_handshake_latency_ms", + "ssl_ja3_hash", + "ssl_ja3s_hash", + "ssl_cert_issuer", + "ssl_cert_subject", + "ssl_esni_flag", + "ssl_ech_flag", + "sip_call_id", + "sip_originator_description", + "sip_responder_description", + "sip_user_agent", + "sip_server", + "sip_originator_sdp_connect_ip", + "sip_originator_sdp_media_port", + "sip_originator_sdp_media_type", + "sip_originator_sdp_content", + "sip_responder_sdp_connect_ip", + "sip_responder_sdp_media_port", + "sip_responder_sdp_media_type", + "sip_responder_sdp_content", + "sip_duration_s", + "sip_bye", + "rtp_payload_type_c2s", + "rtp_payload_type_s2c", + "rtp_pcap_path", + "rtp_originator_dir", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program", + "stratum_mining_subscribe" + ], + "transmission": [ + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn" + ], + "other": [ + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc" + ] + } + }, + "data_view": { + "PROXY_INTERCEPT_EVENT_VIEW": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "security_rule_list", + "security_action", + "app", + "client_ip", + "client_port", + "server_fqdn", + "app", + "server_ip", + "server_port" + ] + } + }, + "decoded_as": { + "BASE": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port" + ] + }, + "HTTP": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "http_url", + "server_ip", + "server_port" + ] + }, + "MAIL": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "mail_from", + "mail_to", + "mail_subject", + "server_ip", + "server_port" + ] + }, + "DNS": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "client_ip", + "client_port", + "dns_qr", + "dns_qname", + "dns_qtype", + "server_ip", + "server_port" + ] + }, + "SSL": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "ssl_sni", + "server_ip", + "server_port" + ] + }, + "DTLS": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "dtls_sni", + "server_ip", + "server_port" + ] + }, + "QUIC": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "quic_sni", + "server_ip", + "server_port" + ] + }, + "FTP": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "ftp_url", + "server_ip", + "server_port" + ] + }, + "SIP": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "client_ip", + "client_port", + "sip_originator_description", + "sip_responder_description", + "sip_call_id", + "server_ip", + "server_port" + ] + }, + "RTP": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port", + "rtp_pcap_path", + "rtp_originator_dir" + ] + }, + "SSH": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port", + "ssh_auth_success" + ] + }, + "Stratum": { + "columns": [ + 'ip', 'domain', 'app', 'ip.country', 'ip.region', 'ip.city', 'ip.asn', 'ip.isp', 'domain.category', 'app.category', 'tag', 'ip.port', 'ip.potocol', 'security_action' + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_port", + "client_ip", + "server_ip", + "server_port", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program" + ] + } + }, + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port", + "decoded_as", + "server_fqdn" + ], + "internal_columns": [ + "recv_time", + "log_id", + "flags_identify_info", + "tunnels", + "app_debug_info", + "app_content", + "packet_capture_file", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc" + ], + "tunnel_type": { + "GTP": [ + { + "name": "gtp_endpoint_a_ip", + "label": "Endpoint A IP", + "type": "string" + }, + { + "name": "gtp_endpoint_b_ip", + "label": "Endpoint B IP", + "type": "string" + }, + { + "name": "gtp_endpoint_a_port", + "label": "Endpoint A Port", + "type": "int" + }, + { + "name": "gtp_endpoint_b_port", + "label": "Endpoint B Port", + "type": "int" + }, + { + "name": "gtp_endpoint_a2b_teid", + "label": "Endpoint A2B TEID", + "type": "long" + }, + { + "name": "gtp_endpoint_b2a_teid", + "label": "Endpoint B2A TEID", + "type": "long" + } + ], + "MPLS": [ + { + "name": "mpls_c2s_direction_label", + "label": "Multiprotocol Label (c2s)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + }, + { + "name": "mpls_s2c_direction_label", + "label": "Multiprotocol Label (s2c)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + } + ], + "VLAN": [ + { + "name": "vlan_c2s_direction_id", + "label": "VLAN Direction (c2s)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + }, + { + "name": "vlan_s2c_direction_id", + "label": "VLAN Direction (s2c)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + } + ], + "ETHERNET": [ + { + "name": "source_mac", + "label": "Source MAC", + "type": "string" + }, + { + "name": "destination_mac", + "label": "Destination MAC", + "type": "string" + } + ], + "MULTIPATH_ETHERNET": [ + { + "name": "c2s_source_mac", + "label": "Source MAC (c2s)", + "type": "string" + }, + { + "name": "c2s_destination_mac", + "label": "Destination MAC (c2s)", + "type": "string" + }, + { + "name": "s2c_source_mac", + "label": "Source MAC (s2c)", + "type": "string" + }, + { + "name": "s2c_destination_mac", + "label": "Destination MAC (s2c)", + "type": "string" + } + ], + "L2TP": [ + { + "name": "l2tp_version", + "label": "Version", + "type": "string" + }, + { + "name": "l2tp_lac2lns_tunnel_id", + "label": "LAC2LNS Tunnel ID", + "type": "int" + }, + { + "name": "l2tp_lns2lac_tunnel_id", + "label": "LNS2LAC Tunnel ID", + "type": "int" + }, + { + "name": "l2tp_lac2lns_session_id", + "label": "LAC2LNS Session ID", + "type": "int" + }, + { + "name": "l2tp_lns2lac_session_id", + "label": "LNS2LAC Session ID", + "type": "int" + }, + { + "name": "l2tp_access_concentrator_ip", + "label": "Access Concentrator IP", + "type": "string" + }, + { + "name": "l2tp_access_concentrator_port", + "label": "Access Concentrator Port", + "type": "int" + }, + { + "name": "l2tp_network_server_ip", + "label": "Network Server IP", + "type": "string" + }, + { + "name": "l2tp_network_server_port", + "label": "Network Server Port", + "type": "int" + } + ], + "PPTP": [ + { + "name": "pptp_uplink_tunnel_id", + "label": "UpLink Tunnel ID", + "type": "int" + }, + { + "name": "pptp_downlink_tunnel_id", + "label": "Down Tunnel ID", + "type": "int" + } + ] + }, + "measurements": { + "aggregates": { + "sessions": [ + { + "fn": "count", + "column": "log_id", + "value": "sessions", + "label": "Sessions", + "unit": "sessions" + } + ], + "bytes": [ + { + "fn": "sum", + "column": "sent_bytes + received_bytes", + "value": "bytes", + "label": "Bytes", + "unit": "bytes" + } + ], + "incoming_bytes": [ + { + "fn": "sum", + "column": "if(bitAnd(flags, 8) = 8, received_bytes, sent_bytes)", + "value": "incoming_bytes", + "label": "Incoming Bytes", + "unit": "bytes" + } + ], + "outgoing_bytes": [ + { + "fn": "sum", + "column": "if(bitAnd(flags, 8) = 8, sent_bytes, received_bytes)", + "value": "outgoing_bytes", + "label": "Outgoing Bytes", + "unit": "bytes" + } + ] + } + }, + "size": 55784179370 + }, + "fields": [ + { + "name": "ip", + "label": "ip", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "ip", + "type": "ip", + "operator_functions": "=,in,like" + } + } + }, + { + "name": "domain", + "label": "domain", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "domain", + "type": "domain", + "operator_functions": "=,in,like" + } + } + }, + { + "name": "app_name", + "label": "app", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "app", + "operator_functions": "=,in,like" + } + } + }, + { + "name": "ip_country_region", + "label": "ip.country", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + data: [ + { + "code": "China", + "value": "CHina" + }, + { + "code": "American", + "value": "Allow" + } + ], + "type": "string", + "doc": { + "constraints": { + "primay": "ip", + "operator_functions": "=,in" + } + } + }, + { + "name": "ip_super_admin_area", + "label": "ip.region", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "ip", + "operator_functions": "=,in" + } + } + }, + { + "name": "ip_admin_area", + "label": "ip.city", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "ip", + "operator_functions": "=,in" + } + } + }, + { + "name": "ip_asn", + "label": "ip.asn", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "ip", + "operator_functions": "=,in" + } + } + }, + { + "name": "ip_isp", + "label": "ip.isp", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "ip", + "operator_functions": "=,in" + } + } + }, + { + "name": "domain_category_name", + "label": "domain.category", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "domain", + "operator_functions": "=,in" + } + } + }, + { + "name": "app_category", + "label": "app.category", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "app", + "operator_functions": "=,in" + } + } + }, + { + "name": "entity_tags", + "label": "tag", + "connector": { + "alias": "e", + "table": "cn_entity_relation", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": { + "type": "array", + "items": "string" + }, + "doc": { + "constraints": { + "primay": "", + "operator_functions": "has" + } + } + }, + { + "name": "port", + "label": "ip.port", + "connector": { + "alias": "dr", + "table": "cn_ip_dynamic_attribute", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "int", + "doc": { + "constraints": { + "primay": "ip", + "operator_functions": "=,in" + } + } + }, + { + "name": "security_action", + "type": "string", + "doc": { + "visibility": "enabled", + "constraints": { + "operator_functions": "=,!=,in,not in" + }, + "data": [ + { + "code": "Deny", + "value": "Deny" + }, + { + "code": "Allow", + "value": "Allow" + } + ], + "ttl": null, + "size": 4882982 + }, + "label": "security.action" + }, + { + "name": "l7_protocol", + "label": "ip.protocol", + "connector": { + "alias": "dr", + "table": "cn_ip_dynamic_attribute", + "schema": "cyber_narrator_galaxy", + "catalog": "clickhouse" + }, + "type": "string", + "doc": { + "constraints": { + "primay": "ip", + "operator_functions": "=,in" + } + } + } + ] +} diff --git a/src/components/advancedSearch/showhint/packages/service/oldMockData.js b/src/components/advancedSearch/showhint/packages/service/oldMockData.js new file mode 100644 index 00000000..0b3e99d4 --- /dev/null +++ b/src/components/advancedSearch/showhint/packages/service/oldMockData.js @@ -0,0 +1,2881 @@ +export const cacheData = { + "type": "record", + "name": "session_record", + "namespace": "tsg_galaxy_v3", + "doc": { + "primary_key": "log_id", + "partition_key": "recv_time", + "index_key": [ + "vsys_id", + "security_action", + "proxy_action", + "decoded_as", + "data_center", + "device_group", + "recv_time" + ], + "ttl": 2592000, + "default_ttl": 2592000, + "functions": { + "aggregation": [ + { + "name": "COUNT", + "label": "COUNT", + "function": "count(expr)" + }, + { + "name": "COUNT_DISTINCT", + "label": "COUNT_DISTINCT", + "function": "count(distinct expr)" + }, + { + "name": "AVG", + "label": "AVG", + "function": "avg(expr)" + }, + { + "name": "SUM", + "label": "SUM", + "function": "sum(expr)" + }, + { + "name": "MAX", + "label": "MAX", + "function": "max(expr)" + }, + { + "name": "MIN", + "label": "MIN", + "function": "min(expr)" + }, + { + "name": "MEDIAN", + "label": "MEDIAN", + "function": "MEDIAN(expr)" + }, + { + "name": "QUANTILE", + "label": "QUANTILE", + "function": "QUANTILE(expr,level)" + }, + { + "name": "TIME_FLOOR_WITH_FILL", + "label": "TIME_FLOOR_WITH_FILL", + "function": "TIME_FLOOR_WITH_FILL(expr,period,fill)" + } + ], + "date": [ + { + "name": "UNIX_TIMESTAMP", + "label": "UNIX_TIMESTAMP", + "function": "UNIX_TIMESTAMP(expr)" + }, + { + "name": "FROM_UNIXTIME", + "label": "FROM_UNIXTIME", + "function": "FROM_UNIXTIME(expr)" + }, + { + "name": "DATE_FORMAT", + "label": "DATE_FORMAT", + "function": "DATE_FORMAT(expr,format)" + }, + { + "name": "CONVERT_TZ", + "label": "CONVERT_TZ", + "function": "CONVERT_TZ(expr, from_tz, to_tz)" + } + ], + "operator": [ + { + "name": "=", + "label": "=", + "function": "expr = value" + }, + { + "name": "!=", + "label": "!=", + "function": "expr != value" + }, + { + "name": ">", + "label": ">", + "function": "expr > value" + }, + { + "name": "<", + "label": "<", + "function": "expr < value" + }, + { + "name": ">=", + "label": ">=", + "function": "expr >= value" + }, + { + "name": "<=", + "label": "<=", + "function": "expr <= value" + }, + { + "name": "has", + "label": "HAS", + "function": "has(expr, value)" + }, + { + "name": "in", + "label": "IN", + "function": "expr in (values)" + }, + { + "name": "not in", + "label": "NOT IN", + "function": "expr not in (values)" + }, + { + "name": "like", + "label": "LIKE", + "function": "expr like value" + }, + { + "name": "not like", + "label": "NOT LIKE", + "function": "expr not like value" + }, + { + "name": "notEmpty", + "label": "NOT EMPTY", + "function": "notEmpty(expr)" + }, + { + "name": "empty", + "label": "EMPTY", + "function": "empty(expr)" + }, + { + "name": "bitAnd", + "label": "Bitwise AND", + "function": "bitAnd(expr, value)=value" + } + ], + "sketch": [ + { + "name": "APPROX_COUNT_DISTINCT_HLLD", + "label": "APPROX_COUNT_DISTINCT_HLLD", + "function": "APPROX_COUNT_DISTINCT_HLLD(expr, precision,round)" + }, + { + "name": "HLLD", + "label": "HLLD", + "function": "HLLD(expr, precision)" + }, + { + "name": "APPROX_QUANTILE_HDR", + "label": "APPROX_QUANTILE_HDR", + "function": "APPROX_QUANTILE_HDR(expr,probability,numberOfSignificantValueDigits)" + }, + { + "name": "HDR_HISTOGRAM", + "label": "HDR_HISTOGRAM", + "function": "HDR_HISTOGRAM(expr, numberOfSignificantValueDigits)" + }, + { + "name": "HDR_GET_QUANTILES", + "label": "HDR_GET_QUANTILES", + "function": "HDR_GET_QUANTILES(expr,probability0, probability1, ...)" + }, + { + "name": "HDR_GET_PERCENTILES", + "label": "HDR_GET_PERCENTILES", + "function": "HDR_GET_QUANTILES(expr,percentileTicksPerHalfDistance)" + } + ] + }, + "schema_query": { + "dimensions": [ + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "processing_time", + "ingestion_time", + "device_id", + "out_link_id", + "in_link_id", + "data_center", + "sled_ip", + "device_group", + "address_type", + "decoded_as", + "vsys_id", + "flags", + "flags_identify_info", + "security_action", + "security_rule_list", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_action", + "proxy_rule_list", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "in_dest_mac", + "out_dest_mac", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "http_url", + "http_host", + "http_request_line", + "http_response_line", + "http_proxy_flag", + "http_sequence", + "http_cookie", + "http_referer", + "http_user_agent", + "http_request_content_length", + "http_request_content_type", + "http_response_content_length", + "http_response_content_type", + "http_set_cookie", + "http_version", + "http_status_code", + "http_response_latency_ms", + "http_session_duration_ms", + "http_action_file_size", + "mail_protocol_type", + "mail_account", + "mail_from_cmd", + "mail_to_cmd", + "mail_from", + "mail_password", + "mail_to", + "mail_cc", + "mail_bcc", + "mail_subject", + "mail_subject_charset", + "mail_attachment_name", + "mail_attachment_name_charset", + "mail_eml_file", + "dns_message_id", + "dns_qr", + "dns_opcode", + "dns_aa", + "dns_tc", + "dns_rd", + "dns_ra", + "dns_rcode", + "dns_qname", + "dns_qtype", + "dns_qclass", + "dns_cname", + "dns_sub", + "ssl_version", + "ssl_sni", + "ssl_san", + "ssl_cn", + "ssl_ja3_hash", + "ssl_ja3s_hash", + "ssl_cert_issuer", + "ssl_cert_subject", + "ssl_esni_flag", + "ssl_ech_flag", + "dtls_cookie", + "dtls_version", + "dtls_sni", + "dtls_san", + "dtls_cn", + "dtls_handshake_latency_ms", + "dtls_ja3_fingerprint", + "dtls_ja3_hash", + "dtls_cert_issuer", + "dtls_cert_subject", + "quic_sni", + "quic_version", + "quic_user_agent", + "ftp_account", + "ftp_url", + "ftp_link_type", + "sip_call_id", + "sip_originator_description", + "sip_responder_description", + "sip_user_agent", + "sip_server", + "sip_originator_sdp_connect_ip", + "sip_originator_sdp_media_port", + "sip_originator_sdp_media_type", + "sip_responder_sdp_connect_ip", + "sip_responder_sdp_media_port", + "sip_responder_sdp_media_type", + "sip_responder_sdp_content", + "sip_duration_s", + "sip_bye", + "ssh_version", + "ssh_auth_success", + "ssh_client_version", + "ssh_server_version", + "ssh_cipher_alg", + "ssh_mac_alg", + "ssh_compression_alg", + "ssh_kex_alg", + "ssh_host_key_alg", + "ssh_host_key", + "ssh_hassh", + "rtp_payload_type_c2s", + "rtp_payload_type_s2c", + "rtp_originator_dir", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program", + "stratum_mining_subscribe", + "rdp_cookie", + "rdp_security_protocol", + "rdp_client_channels", + "rdp_keyboard_layout", + "rdp_client_version", + "rdp_client_name", + "rdp_client_product_id", + "rdp_desktop_width", + "rdp_desktop_height", + "rdp_requested_color_depth", + "rdp_certificate_type", + "rdp_certificate_count", + "rdp_certificate_permanent", + "rdp_encryption_level", + "rdp_encryption_method" + ], + "metrics": [ + "start_timestamp_ms", + "end_timestamp_ms", + "device_id", + "data_center", + "sled_ip", + "device_group", + "address_type", + "decoded_as", + "vsys_id", + "security_action", + "proxy_action", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "in_dest_mac", + "out_dest_mac", + "app_path", + "app_debug_info", + "app", + "app_content", + "protocol_path", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "duration_ms", + "tcp_handshake_latency_ms", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "http_url", + "http_host", + "http_request_line", + "http_response_line", + "http_proxy_flag", + "http_sequence", + "http_cookie", + "http_referer", + "http_user_agent", + "http_request_content_length", + "http_request_content_type", + "http_response_content_length", + "http_response_content_type", + "http_set_cookie", + "http_version", + "http_status_code", + "http_response_latency_ms", + "http_session_duration_ms", + "http_action_file_size", + "mail_protocol_type", + "mail_account", + "mail_from_cmd", + "mail_to_cmd", + "mail_from", + "mail_password", + "mail_to", + "mail_cc", + "mail_bcc", + "mail_subject", + "mail_subject_charset", + "mail_attachment_name", + "mail_attachment_name_charset", + "mail_eml_file", + "dns_message_id", + "dns_qr", + "dns_opcode", + "dns_aa", + "dns_rd", + "dns_ra", + "dns_rcode", + "dns_qtype", + "dns_qclass", + "dns_qdcount", + "dns_ancount", + "dns_nscount", + "dns_arcount", + "dns_qname", + "dns_qtype", + "dns_qclass", + "dns_cname", + "dns_sub", + "dns_rr", + "dns_response_latency_ms", + "ssl_version", + "ssl_sni", + "ssl_san", + "ssl_cn", + "ssl_handshake_latency_ms", + "ssl_ja3_hash", + "ssl_ja3s_hash", + "ssl_cert_issuer", + "ssl_cert_subject", + "ssl_esni_flag", + "ssl_ech_flag", + "dtls_cookie", + "dtls_version", + "dtls_sni", + "dtls_san", + "dtls_cn", + "dtls_handshake_latency_ms", + "dtls_ja3_fingerprint", + "dtls_ja3_hash", + "dtls_cert_issuer", + "dtls_cert_subject", + "quic_sni", + "quic_version", + "quic_user_agent", + "ftp_account", + "ftp_url", + "ftp_link_type", + "sip_call_id", + "sip_originator_description", + "sip_responder_description", + "sip_user_agent", + "sip_server", + "sip_originator_sdp_connect_ip", + "sip_originator_sdp_media_port", + "sip_originator_sdp_media_type", + "sip_originator_sdp_content", + "sip_responder_sdp_connect_ip", + "sip_responder_sdp_media_port", + "sip_responder_sdp_media_type", + "sip_responder_sdp_content", + "sip_duration_s", + "sip_bye", + "rtp_payload_type_c2s", + "rtp_payload_type_s2c", + "rtp_originator_dir", + "ssh_version", + "ssh_auth_success", + "ssh_client_version", + "ssh_server_version", + "ssh_cipher_alg", + "ssh_mac_alg", + "ssh_compression_alg", + "ssh_kex_alg", + "ssh_host_key_alg", + "ssh_host_key", + "ssh_hassh", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program", + "stratum_mining_subscribe", + "rdp_cookie", + "rdp_security_protocol", + "rdp_client_channels", + "rdp_keyboard_layout", + "rdp_client_version", + "rdp_client_name", + "rdp_client_product_id", + "rdp_desktop_width", + "rdp_desktop_height", + "rdp_requested_color_depth", + "rdp_certificate_type", + "rdp_certificate_count", + "rdp_certificate_permanent", + "rdp_encryption_level", + "rdp_encryption_method" + ], + "filters": [ + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "processing_time", + "ingestion_time", + "device_id", + "data_center", + "sled_ip", + "device_group", + "address_type", + "decoded_as", + "vsys_id", + "flags", + "flags_identify_info", + "security_action", + "security_rule_list", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "in_src_mac", + "out_src_mac", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "in_dest_mac", + "out_dest_mac", + "app_path", + "app_debug_info", + "app", + "app_content", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "http_url", + "http_host", + "http_request_line", + "http_response_line", + "http_proxy_flag", + "http_sequence", + "http_cookie", + "http_referer", + "http_user_agent", + "http_request_content_length", + "http_request_content_type", + "http_response_content_length", + "http_response_content_type", + "http_set_cookie", + "http_version", + "http_status_code", + "http_response_latency_ms", + "http_session_duration_ms", + "http_action_file_size", + "mail_protocol_type", + "mail_account", + "mail_from_cmd", + "mail_to_cmd", + "mail_from", + "mail_password", + "mail_to", + "mail_cc", + "mail_bcc", + "mail_subject", + "mail_subject_charset", + "mail_attachment_name", + "mail_attachment_name_charset", + "mail_eml_file", + "dns_message_id", + "dns_qr", + "dns_opcode", + "dns_aa", + "dns_rd", + "dns_ra", + "dns_rcode", + "dns_qtype", + "dns_qclass", + "dns_qdcount", + "dns_ancount", + "dns_nscount", + "dns_arcount", + "dns_qname", + "dns_qtype", + "dns_qclass", + "dns_cname", + "dns_sub", + "dns_rr", + "dns_response_latency_ms", + "ssl_version", + "ssl_sni", + "ssl_san", + "ssl_cn", + "ssl_handshake_latency_ms", + "ssl_ja3_hash", + "ssl_ja3s_hash", + "ssl_cert_issuer", + "ssl_cert_subject", + "ssl_esni_flag", + "ssl_ech_flag", + "dtls_cookie", + "dtls_version", + "dtls_sni", + "dtls_san", + "dtls_cn", + "dtls_handshake_latency_ms", + "dtls_ja3_fingerprint", + "dtls_ja3_hash", + "dtls_cert_issuer", + "dtls_cert_subject", + "quic_sni", + "quic_version", + "quic_user_agent", + "ftp_account", + "ftp_url", + "ftp_link_type", + "sip_call_id", + "sip_originator_description", + "sip_responder_description", + "sip_user_agent", + "sip_server", + "sip_originator_sdp_connect_ip", + "sip_originator_sdp_media_port", + "sip_originator_sdp_media_type", + "sip_originator_sdp_content", + "sip_responder_sdp_connect_ip", + "sip_responder_sdp_media_port", + "sip_responder_sdp_media_type", + "sip_responder_sdp_content", + "sip_duration_s", + "sip_bye", + "rtp_payload_type_c2s", + "rtp_payload_type_s2c", + "rtp_originator_dir", + "ssh_version", + "ssh_auth_success", + "ssh_client_version", + "ssh_server_version", + "ssh_cipher_alg", + "ssh_mac_alg", + "ssh_compression_alg", + "ssh_kex_alg", + "ssh_host_key_alg", + "ssh_host_key", + "ssh_hassh", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program", + "stratum_mining_subscribe", + "rdp_cookie", + "rdp_security_protocol", + "rdp_client_channels", + "rdp_keyboard_layout", + "rdp_client_version", + "rdp_client_name", + "rdp_client_product_id", + "rdp_desktop_width", + "rdp_desktop_height", + "rdp_requested_color_depth", + "rdp_certificate_type", + "rdp_certificate_count", + "rdp_certificate_permanent", + "rdp_encryption_level", + "rdp_encryption_method" + ], + "references": { + "aggregation": [ + { + "type": "int", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN,MEDIAN,QUANTILE" + }, + { + "type": "long", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN,MEDIAN,QUANTILE" + }, + { + "type": "float", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN,MEDIAN,QUANTILE" + }, + { + "type": "double", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN,MEDIAN,QUANTILE" + }, + { + "type": "string", + "functions": "COUNT,COUNT_DISTINCT" + }, + { + "type": "date", + "functions": "COUNT,COUNT_DISTINCT,MAX,MIN,UNIX_TIMESTAMP,FROM_UNIXTIME,DATE_FORMAT,CONVERT_TZ" + }, + { + "type": "datetime", + "functions": "COUNT,COUNT_DISTINCT,MAX,MIN" + }, + { + "type": "timestamp", + "functions": "COUNT,COUNT_DISTINCT,MAX,MIN,UNIX_TIMESTAMP,FROM_UNIXTIME,DATE_FORMAT,CONVERT_TZ" + }, + { + "type": "array", + "functions": "COUNT,COUNT_DISTINCT" + }, + { + "type": "bit", + "functions": "COUNT,COUNT_DISTINCT" + } + ], + "operator": [ + { + "type": "int", + "functions": "=,!=,>,<,>=,<=,in,not in" + }, + { + "type": "long", + "functions": "=,!=,>,<,>=,<=,in,not in" + }, + { + "type": "float", + "functions": "=,!=,>,<,>=,<=" + }, + { + "type": "double", + "functions": "=,!=,>,<,>=,<=" + }, + { + "type": "string", + "functions": "=,!=,in,not in,like,not like,notEmpty,empty" + }, + { + "type": "date", + "functions": "=,!=,>,<,>=,<=" + }, + { + "type": "dateTime", + "functions": "=,!=,>,<,>=,<=" + }, + { + "type": "timestamp", + "functions": "=,!=,>,<,>=,<=" + }, + { + "type": "array", + "functions": "has,notEmpty,empty" + }, + { + "type": "bit", + "functions": "=,!=,bitAnd" + } + ] + }, + "details": { + "general": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info" + ], + "treatment": [ + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes" + ], + "source": [ + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number" + ], + "destination": [ + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain" + ], + "application": [ + "app_path", + "app", + "app_debug_info", + "app_content", + "fqdn_category_list" + ], + "protocol": [ + "protocol_path", + "dns_message_id", + "dns_qr", + "dns_opcode", + "dns_aa", + "dns_tc", + "dns_rd", + "dns_ra", + "dns_rcode", + "dns_qdcount", + "dns_ancount", + "dns_nscount", + "dns_arcount", + "dns_qname", + "dns_qtype", + "dns_qclass", + "dns_cname", + "dns_sub", + "dns_rr", + "dns_response_latency_ms", + "dtls_cookie", + "dtls_version", + "dtls_sni", + "dtls_san", + "dtls_cn", + "dtls_handshake_latency_ms", + "dtls_ja3_fingerprint", + "dtls_ja3_hash", + "dtls_cert_issuer", + "dtls_cert_subject", + "ftp_account", + "ftp_url", + "ftp_link_type", + "http_url", + "http_host", + "http_request_line", + "http_response_line", + "http_request_content_length", + "http_request_content_type", + "http_response_content_length", + "http_response_content_type", + "http_request_body", + "http_response_body", + "http_proxy_flag", + "http_sequence", + "http_cookie", + "http_referer", + "http_user_agent", + "http_set_cookie", + "http_version", + "http_status_code", + "http_response_latency_ms", + "http_session_duration_ms", + "http_action_file_size", + "mail_protocol_type", + "mail_account", + "mail_from_cmd", + "mail_to_cmd", + "mail_from", + "mail_password", + "mail_to", + "mail_cc", + "mail_bcc", + "mail_subject", + "mail_subject_charset", + "mail_attachment_name", + "mail_attachment_name_charset", + "mail_eml_file", + "quic_version", + "quic_sni", + "quic_user_agent", + "rdp_cookie", + "rdp_security_protocol", + "rdp_client_channels", + "rdp_keyboard_layout", + "rdp_client_version", + "rdp_client_name", + "rdp_client_product_id", + "rdp_desktop_width", + "rdp_desktop_height", + "rdp_requested_color_depth", + "rdp_certificate_type", + "rdp_certificate_count", + "rdp_certificate_permanent", + "rdp_encryption_level", + "rdp_encryption_method", + "ssh_version", + "ssh_auth_success", + "ssh_client_version", + "ssh_server_version", + "ssh_cipher_alg", + "ssh_mac_alg", + "ssh_compression_alg", + "ssh_kex_alg", + "ssh_host_key_alg", + "ssh_host_key", + "ssh_hassh", + "ssl_version", + "ssl_sni", + "ssl_san", + "ssl_cn", + "ssl_handshake_latency_ms", + "ssl_ja3_hash", + "ssl_ja3s_hash", + "ssl_cert_issuer", + "ssl_cert_subject", + "ssl_esni_flag", + "ssl_ech_flag", + "sip_call_id", + "sip_originator_description", + "sip_responder_description", + "sip_user_agent", + "sip_server", + "sip_originator_sdp_connect_ip", + "sip_originator_sdp_media_port", + "sip_originator_sdp_media_type", + "sip_originator_sdp_content", + "sip_responder_sdp_connect_ip", + "sip_responder_sdp_media_port", + "sip_responder_sdp_media_type", + "sip_responder_sdp_content", + "sip_duration_s", + "sip_bye", + "rtp_payload_type_c2s", + "rtp_payload_type_s2c", + "rtp_pcap_path", + "rtp_originator_dir", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program", + "stratum_mining_subscribe" + ], + "transmission": [ + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn" + ], + "other": [ + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc" + ] + } + }, + "data_view": { + "PROXY_INTERCEPT_EVENT_VIEW": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "http_url", + "http_host", + "http_request_line", + "http_response_line", + "http_request_content_length", + "http_request_content_type", + "http_response_content_length", + "http_response_content_type", + "http_request_body", + "http_response_body", + "http_proxy_flag", + "http_sequence", + "http_cookie", + "http_referer", + "http_user_agent", + "http_set_cookie", + "http_version", + "http_status_code", + "http_response_latency_ms", + "http_session_duration_ms", + "http_action_file_size", + "ssl_version", + "ssl_sni", + "ssl_san", + "ssl_cn", + "ssl_handshake_latency_ms", + "ssl_ja3_hash", + "ssl_ja3s_hash", + "ssl_cert_issuer", + "ssl_cert_subject", + "ssl_esni_flag", + "ssl_ech_flag" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "security_rule_list", + "security_action", + "client_ip", + "client_port", + "server_fqdn", + "app", + "server_ip", + "server_port" + ] + } + }, + "decoded_as": { + "BASE": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port" + ] + }, + "HTTP": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "http_url", + "http_host", + "http_request_line", + "http_response_line", + "http_request_content_length", + "http_request_content_type", + "http_response_content_length", + "http_response_content_type", + "http_request_body", + "http_response_body", + "http_proxy_flag", + "http_sequence", + "http_cookie", + "http_referer", + "http_user_agent", + "http_set_cookie", + "http_version", + "http_status_code", + "http_response_latency_ms", + "http_session_duration_ms", + "http_action_file_size" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "http_url", + "server_ip", + "server_port" + ] + }, + "MAIL": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "mail_protocol_type", + "mail_account", + "mail_from_cmd", + "mail_to_cmd", + "mail_from", + "mail_password", + "mail_to", + "mail_cc", + "mail_bcc", + "mail_subject", + "mail_subject_charset", + "mail_attachment_name", + "mail_attachment_name_charset", + "mail_eml_file" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "mail_from", + "mail_to", + "mail_subject", + "server_ip", + "server_port" + ] + }, + "DNS": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "dns_message_id", + "dns_qr", + "dns_opcode", + "dns_aa", + "dns_tc", + "dns_rd", + "dns_ra", + "dns_rcode", + "dns_qdcount", + "dns_ancount", + "dns_nscount", + "dns_arcount", + "dns_qname", + "dns_qtype", + "dns_qclass", + "dns_cname", + "dns_sub", + "dns_rr", + "dns_response_latency_ms" + ], + "default_columns": [ + "recv_time", + "client_ip", + "client_port", + "dns_qr", + "dns_qname", + "dns_qtype", + "server_ip", + "server_port" + ] + }, + "SSL": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "ssl_version", + "ssl_sni", + "ssl_san", + "ssl_cn", + "ssl_handshake_latency_ms", + "ssl_ja3_hash", + "ssl_ja3s_hash", + "ssl_cert_issuer", + "ssl_cert_subject", + "ssl_esni_flag", + "ssl_ech_flag" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "ssl_sni", + "server_ip", + "server_port" + ] + }, + "DTLS": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "dtls_cookie", + "dtls_version", + "dtls_sni", + "dtls_san", + "dtls_cn", + "dtls_handshake_latency_ms", + "dtls_ja3_fingerprint", + "dtls_ja3_hash", + "dtls_cert_issuer", + "dtls_cert_subject" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "dtls_sni", + "server_ip", + "server_port" + ] + }, + "QUIC": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "quic_version", + "quic_sni", + "quic_user_agent" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "quic_sni", + "server_ip", + "server_port" + ] + }, + "FTP": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "ftp_account", + "ftp_url", + "ftp_link_type" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "ftp_url", + "server_ip", + "server_port" + ] + }, + "SIP": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "sip_call_id", + "sip_originator_description", + "sip_responder_description", + "sip_user_agent", + "sip_server", + "sip_originator_sdp_connect_ip", + "sip_originator_sdp_media_port", + "sip_originator_sdp_media_type", + "sip_originator_sdp_content", + "sip_responder_sdp_connect_ip", + "sip_responder_sdp_media_port", + "sip_responder_sdp_media_type", + "sip_responder_sdp_content", + "sip_duration_s", + "sip_bye" + ], + "default_columns": [ + "recv_time", + "client_ip", + "client_port", + "sip_originator_description", + "sip_responder_description", + "sip_call_id", + "server_ip", + "server_port" + ] + }, + "RTP": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "rtp_payload_type_c2s", + "rtp_payload_type_s2c", + "rtp_pcap_path", + "rtp_originator_dir" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port", + "rtp_pcap_path", + "rtp_originator_dir" + ] + }, + "SSH": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "ssh_version", + "ssh_auth_success", + "ssh_client_version", + "ssh_server_version", + "ssh_cipher_alg", + "ssh_mac_alg", + "ssh_compression_alg", + "ssh_kex_alg", + "ssh_host_key_alg", + "ssh_host_key", + "ssh_hassh" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port", + "ssh_auth_success" + ] + }, + "Stratum": { + "columns": [ + "recv_time", + "log_id", + "decoded_as", + "session_id", + "start_timestamp_ms", + "end_timestamp_ms", + "duration_ms", + "tcp_handshake_latency_ms", + "ingestion_time", + "processing_time", + "insert_time", + "device_id", + "out_link_id", + "in_link_id", + "device_tag", + "data_center", + "device_group", + "sled_ip", + "address_type", + "vsys_id", + "t_vsys_id", + "flags", + "flags_identify_info", + "security_rule_list", + "security_action", + "monitor_rule_list", + "shaping_rule_list", + "sc_rule_list", + "sc_rsp_raw", + "sc_rsp_decrypted", + "proxy_rule_list", + "proxy_action", + "proxy_pinning_status", + "proxy_intercept_status", + "proxy_passthrough_reason", + "proxy_client_side_latency_ms", + "proxy_server_side_latency_ms", + "proxy_client_side_version", + "proxy_server_side_version", + "proxy_cert_verify", + "proxy_intercept_error", + "security_mirrored_pkts", + "security_mirrored_bytes", + "client_ip", + "client_port", + "client_os_desc", + "client_geolocation", + "client_asn", + "subscriber_id", + "imei", + "imsi", + "apn", + "phone_number", + "server_ip", + "server_port", + "server_os_desc", + "server_geolocation", + "server_asn", + "server_fqdn", + "server_domain", + "app_path", + "app", + "app_debug_info", + "app_content", + "protocol_path", + "fqdn_category_list", + "sent_pkts", + "received_pkts", + "sent_bytes", + "received_bytes", + "tcp_c2s_ip_fragments", + "tcp_s2c_ip_fragments", + "tcp_c2s_lost_bytes", + "tcp_s2c_lost_bytes", + "tcp_c2s_o3_pkts", + "tcp_s2c_o3_pkts", + "tcp_c2s_rtx_pkts", + "tcp_s2c_rtx_pkts", + "tcp_c2s_rtx_bytes", + "tcp_s2c_rtx_bytes", + "tcp_rtt_ms", + "tcp_client_isn", + "tcp_server_isn", + "packet_capture_file", + "in_src_mac", + "out_src_mac", + "in_dest_mac", + "out_dest_mac", + "tunnels", + "dup_traffic_flag", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program", + "stratum_mining_subscribe" + ], + "default_columns": [ + "recv_time", + "subscriber_id", + "client_port", + "client_ip", + "server_ip", + "server_port", + "stratum_cryptocurrency", + "stratum_mining_pools", + "stratum_mining_program" + ] + } + }, + "default_columns": [ + "recv_time", + "subscriber_id", + "client_ip", + "client_port", + "server_ip", + "server_port", + "decoded_as", + "server_fqdn" + ], + "internal_columns": [ + "recv_time", + "log_id", + "flags_identify_info", + "tunnels", + "app_debug_info", + "app_content", + "packet_capture_file", + "tunnel_endpoint_a_desc", + "tunnel_endpoint_b_desc" + ], + "tunnel_type": { + "GTP": [ + { + "name": "gtp_endpoint_a_ip", + "label": "Endpoint A IP", + "type": "string" + }, + { + "name": "gtp_endpoint_b_ip", + "label": "Endpoint B IP", + "type": "string" + }, + { + "name": "gtp_endpoint_a_port", + "label": "Endpoint A Port", + "type": "int" + }, + { + "name": "gtp_endpoint_b_port", + "label": "Endpoint B Port", + "type": "int" + }, + { + "name": "gtp_endpoint_a2b_teid", + "label": "Endpoint A2B TEID", + "type": "long" + }, + { + "name": "gtp_endpoint_b2a_teid", + "label": "Endpoint B2A TEID", + "type": "long" + } + ], + "MPLS": [ + { + "name": "mpls_c2s_direction_label", + "label": "Multiprotocol Label (c2s)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + }, + { + "name": "mpls_s2c_direction_label", + "label": "Multiprotocol Label (s2c)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + } + ], + "VLAN": [ + { + "name": "vlan_c2s_direction_id", + "label": "VLAN Direction (c2s)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + }, + { + "name": "vlan_s2c_direction_id", + "label": "VLAN Direction (s2c)", + "type": { + "type": "array", + "items": "int", + "logicalType": "array" + } + } + ], + "ETHERNET": [ + { + "name": "source_mac", + "label": "Source MAC", + "type": "string" + }, + { + "name": "destination_mac", + "label": "Destination MAC", + "type": "string" + } + ], + "MULTIPATH_ETHERNET": [ + { + "name": "c2s_source_mac", + "label": "Source MAC (c2s)", + "type": "string" + }, + { + "name": "c2s_destination_mac", + "label": "Destination MAC (c2s)", + "type": "string" + }, + { + "name": "s2c_source_mac", + "label": "Source MAC (s2c)", + "type": "string" + }, + { + "name": "s2c_destination_mac", + "label": "Destination MAC (s2c)", + "type": "string" + } + ], + "L2TP": [ + { + "name": "l2tp_version", + "label": "Version", + "type": "string" + }, + { + "name": "l2tp_lac2lns_tunnel_id", + "label": "LAC2LNS Tunnel ID", + "type": "int" + }, + { + "name": "l2tp_lns2lac_tunnel_id", + "label": "LNS2LAC Tunnel ID", + "type": "int" + }, + { + "name": "l2tp_lac2lns_session_id", + "label": "LAC2LNS Session ID", + "type": "int" + }, + { + "name": "l2tp_lns2lac_session_id", + "label": "LNS2LAC Session ID", + "type": "int" + }, + { + "name": "l2tp_access_concentrator_ip", + "label": "Access Concentrator IP", + "type": "string" + }, + { + "name": "l2tp_access_concentrator_port", + "label": "Access Concentrator Port", + "type": "int" + }, + { + "name": "l2tp_network_server_ip", + "label": "Network Server IP", + "type": "string" + }, + { + "name": "l2tp_network_server_port", + "label": "Network Server Port", + "type": "int" + } + ], + "PPTP": [ + { + "name": "pptp_uplink_tunnel_id", + "label": "UpLink Tunnel ID", + "type": "int" + }, + { + "name": "pptp_downlink_tunnel_id", + "label": "Down Tunnel ID", + "type": "int" + } + ] + }, + "measurements": { + "aggregates": { + "sessions": [ + { + "fn": "count", + "column": "log_id", + "value": "sessions", + "label": "Sessions", + "unit": "sessions" + } + ], + "bytes": [ + { + "fn": "sum", + "column": "sent_bytes + received_bytes", + "value": "bytes", + "label": "Bytes", + "unit": "bytes" + } + ], + "incoming_bytes": [ + { + "fn": "sum", + "column": "if(bitAnd(flags, 8) = 8, received_bytes, sent_bytes)", + "value": "incoming_bytes", + "label": "Incoming Bytes", + "unit": "bytes" + } + ], + "outgoing_bytes": [ + { + "fn": "sum", + "column": "if(bitAnd(flags, 8) = 8, sent_bytes, received_bytes)", + "value": "outgoing_bytes", + "label": "Outgoing Bytes", + "unit": "bytes" + } + ] + } + }, + "size": 56704740769 + }, + "fields": [ + { + "name": "log_id", + "type": "long", + "doc": { + "format": [ + { + "function": "snowflake_id" + } + ], + "visibility": "enabled", + "ttl": 2592000, + "size": 4979695654 + }, + "label": "log.id" + }, + { + "name": "session_id", + "type": "long", + "doc": { + "visibility": "enabled", + "ttl": 2592000, + "size": 4700016584 + }, + "label": "session.id" + }, + { + "name": "start_timestamp_ms", + "type": { + "type": "string", + "logicalType": "datetime64" + }, + "doc": { + "constraints": { + "operator_functions": "=,!=,>,<,>=,<=", + "type": "datetime64" + }, + "format": [ + { + "function": "from_unix_timestamp_ms" + } + ], + "visibility": "enabled", + "ttl": 2592000, + "size": 3465933698 + }, + "label": "start.time" + } + ] +} diff --git a/src/components/advancedSearch/showhint/packages/service/template.js b/src/components/advancedSearch/showhint/packages/service/template.js new file mode 100644 index 00000000..74e03599 --- /dev/null +++ b/src/components/advancedSearch/showhint/packages/service/template.js @@ -0,0 +1,156 @@ +export const dataTemplate = { + "doc": { + "functions": { + "aggregation": [ + { + "name": "COUNT", + "function": "count(expr)", + "label": "COUNT" + }, { + "name": "COUNT_DISTINCT", + "function": "count(distinct expr)", + "label": "COUNT_DISTINCT" + }, { + "name": "AVG", + "function": "avg(expr)", + "label": "AVG" + }, { + "name": "SUM", + "function": "sum(expr)", + "label": "SUM" + }, { + "name": "MAX", + "function": "max(expr)", + "label": "MAX" + }, { + "name": "MIN", + "function": "min(expr)", + "label": "MIN" + }], + "operator": [ + { + "name": "=", + "function": "expr = value", + "label": "=" + }, { + "name": "!=", + "function": "expr != value", + "label": "!=" + }, { + "name": ">", + "function": "expr > value", + "label": ">" + }, { + "name": "<", + "function": "expr < value", + "label": "<" + }, { + "name": ">=", + "function": "expr >= value", + "label": ">=" + }, { + "name": "<=", + "function": "expr <= value", + "label": "<=" + }, { + "name": "has", + "function": "has(expr, value)", + "label": "HAS" + }, { + "name": "in", + "function": "expr in (values)", + "label": "IN" + }, { + "name": "not in", + "function": "expr not in (values)", + "label": "NOT IN" + }, { + "name": "like", + "function": "expr like value", + "label": "LIKE" + }, { + "name": "not like", + "function": "expr not like value", + "label": "NOT LIKE" + }, { + "name": "notEmpty", + "function": "notEmpty(expr)", + "label": "NOT EMPTY" + }, { + "name": "empty", + "function": "empty(expr)", + "label": "EMPTY" + }] + }, + "schema_query": { + "references": { + "aggregation": [ + { + "type": "int", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN" + }, { + "type": "long", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN" + }, { + "type": "float", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN" + }, { + "type": "double", + "functions": "COUNT,COUNT_DISTINCT,AVG,SUM,MAX,MIN" + }, { + "type": "string", + "functions": "COUNT,COUNT_DISTINCT" + }, { + "type": "date", + "functions": "COUNT,COUNT_DISTINCT,MAX,MIN" + }, { + "type": "timestamp", + "functions": "COUNT,COUNT_DISTINCT,MAX,MIN" + } + ], + "operator": [ + { + "type": "int", + "functions": "=,!=,>,<,>=,<=,in,not in" + }, { + "type": "long", + "functions": "=,!=,>,<,>=,<=,in,not in" + }, { + "type": "float", + "functions": "=,!=,>,<,>=,<=" + }, { + "type": "double", + "functions": "=,!=,>,<,>=,<=" + }, { + "type": "string", + "functions": "=,!=,in,not in,like,not like,notEmpty,empty" + }, { + "type": "date", + "functions": "=,!=,>,<,>=,<=" + }, { + "type": "timestamp", + "functions": "=,!=,>,<,>=,<=" + }, { + "type": "array", + "functions": "has" + }] + } + } + }, + "fields": [] +} + +export const fieldTemplate = { + "name": "", + "label": "", + "doc": { + "allow_query": "true", + "visibility": null, + "constraints": { + "type": "tag", + "operator_functions": "in,not in" + }, + "data": [] + }, + "type": "Array" +} diff --git a/src/main.js b/src/main.js index 434fe818..dfd64f4f 100644 --- a/src/main.js +++ b/src/main.js @@ -21,6 +21,7 @@ import DateTimeRange from '@/components/common/TimeRange/DateTimeRange' import TimeRefresh from '@/components/common/TimeRange/TimeRefresh' import PanelChartList from '@/views/charts/PanelChartList' import Error from '@/components/common/Error' +import Renderer from '@/components/advancedSearch/showhint/Hint/Renderer' import 'lib-flexible' const emitter = new bus() @@ -48,6 +49,7 @@ app.component('date-time-range', DateTimeRange) app.component('time-refresh', TimeRefresh) app.component('panel-chart-list', PanelChartList) app.component('chart-error', Error) +app.component('Renderer', Renderer) app.mount('#app') diff --git a/src/utils/timeQueryApi.js b/src/utils/timeQueryApi.js new file mode 100644 index 00000000..05902d09 --- /dev/null +++ b/src/utils/timeQueryApi.js @@ -0,0 +1,151 @@ +import vue from '@/main.js' +// import Moment from "moment/moment"; +// import {transformToUTCTime} from './TimeZone.js' + +//默认Schema 延时15s ,时间粒度 1s +const defaultSchema = { + "doc": { + "measurements": { + "granularity": 1, + "ingestion_delay": 15 + } + } +} + +let schemaDict=null; +function getSchemaFromLocal(schemaType) { + let schemaData=null + // if(schemaDict?.[schemaType]){ + // schemaData=schemaDict + // }else{ + schemaData = localStorage.getItem('TSGSchema') + // } + if (!schemaData) { + return null; + } + const storeData = JSON.parse(schemaData)[schemaType]; + // 如果根据key没有找到数据,直接返回空 + if (!storeData) { + return null; + } + const parsedData = storeData; + const currentTimestamp = new Date().getTime(); + + // 将当前的时间戳和保存在storage中的timestamp进行比较 + // 如果时间差小于等于过期时间说明没有过期,直接返回数据 + // 否则,说明数据已经过期,将storage中的key清除 + if (currentTimestamp - parsedData.timestamp <= parsedData.expire) { + return parsedData.value ? JSON.parse(parsedData.value) : parsedData.value + } else { + setDashboardSchema(schemaType,'') + } + return null; +} + +/** + * 向localStorage中添加字段 + * @param {*} schemaType 保存数据的key + * @param {*} value 保存的数据 + * @param {*} expire 过期时间,默认为1分钟 + */ +function setDashboardSchema(schemaType, value, expire = 60000) { + let schemaData = localStorage.getItem('TSGSchema'); + if (!schemaData) { + localStorage.setItem('TSGSchema', '{}') + } + let TSGSchema = JSON.parse(localStorage.getItem('TSGSchema')) + TSGSchema[schemaType] = { + value: value, + expire: expire, + timestamp: new Date().getTime() + } + const stringfiedData = JSON.stringify(TSGSchema); + localStorage.setItem('TSGSchema', stringfiedData); + schemaDict=TSGSchema; +} + +// 获取过期时间毫秒数 +function getExpireTime(data){ + let expireDate=data.expireDate + if(!expireDate){ + return 24 * 60 * 60 * 1000 + } + let expireTime=new Date().getTime()-expireDate + return expireTime +} + + +function getSchemaFromRemote(schemaType) { + return vue.$get(`/interface/gateway/api/galaxy/v1/metadata/schema/${schemaType}`).then(res => { + if (res.status === 200) { + let expireTime=getExpireTime(res.data) + setDashboardSchema(schemaType, JSON.stringify(res.data), expireTime) + return res.data + } + return defaultSchema + }).catch(err => { + console.error(err) + return defaultSchema + }) +} + + +// async 延时时间 +// 转换时间 start end schmaType 相对时间 绝对时间 +// 时间粒度 + +//获取Schema数据,存在于local 直接取,不存在 直接请求,存本地 +async function getSchemaInfo(schemaType = '') { + var schemaInfo = getSchemaFromLocal(schemaType) + if (!schemaInfo) { + schemaInfo = await getSchemaFromRemote(schemaType) + } + return schemaInfo +} + +/* +* 这里对 时间的延时 +* 时间范围做处理 +* 默认 不做 UTC 转换处理 +* +* granularity 单位必须是S 秒 +* */ +async function getTimeQueryParams({start, end, schemaType = '', granularity = 1, toUtc = false, delay = false}) { + let schemaData = await getSchemaInfo(schemaType); + + const schema_ingestion_delay = schemaData?.doc?.measurements?.ingestion_delay || 0; + const schema_granularity = schemaData?.doc?.measurements?.granularity || 1; + + //这里需要考虑 传入的是UTC 时间,Moment 可以正常处理吗 + var delayTime = delay ? schema_ingestion_delay : 0; + // let startDate = Moment(start).subtract(delayTime, 'seconds') + // let endDate = Moment(end).subtract(delayTime, 'seconds') + let startDate = '1' + let endDate = '2' + + var startStr = startDate.format('YYYY-MM-DD HH:mm:ss') + var endStr = endDate.format('YYYY-MM-DD HH:mm:ss') + + //前端计算时间粒度,不能比Schema 支持的最小时间粒度 小 + var alignmentPeriod = schema_granularity > granularity ? schema_granularity : granularity + + //UTC 转换 + if (toUtc) { + // startStr = transformToUTCTime(startStr) + // endStr = transformToUTCTime(endStr) + startStr = 'transformToUTCTime(startStr)' + endStr = 'transformToUTCTime(endStr)' + } + return { + start: startStr, + end: endStr, + granularity: 'PT'+schema_granularity+'S', + alignmentPeriod: 'PT'+alignmentPeriod+'S', + } +} + +export default { + getTimeQueryParams, + getSchemaInfo +} +export {getSchemaFromLocal, getSchemaInfo, setDashboardSchema, getSchemaFromRemote, getTimeQueryParams}; diff --git a/src/views/entityExplorer/EntityExplorer.vue b/src/views/entityExplorer/EntityExplorer.vue index bc7822cd..4c956650 100644 --- a/src/views/entityExplorer/EntityExplorer.vue +++ b/src/views/entityExplorer/EntityExplorer.vue @@ -824,7 +824,7 @@ export default { if (q && q.indexOf('+') > -1) { q = q.replace('+', '') } - if (q && q.indexOf('%') > 0 && (str1 !== '%20' || str1 === '%25')) { + if (q && q.indexOf('%') > 0 && (str1 === '%20' || str1 === '%25')) { q = decodeURI(q) } this.initSearch(q) diff --git a/src/views/entityExplorer/search/ExplorerSearch.vue b/src/views/entityExplorer/search/ExplorerSearch.vue index ad9397a0..2a0dba57 100644 --- a/src/views/entityExplorer/search/ExplorerSearch.vue +++ b/src/views/entityExplorer/search/ExplorerSearch.vue @@ -10,6 +10,7 @@ :default-mode="defaultMode" :full-text="true" :show-list="showList" + showHint :class="{'advanced-search--show-list': showList}" @search="search" >