Files
librenms-librenms/html/js/sql-parser.min.js

7 lines
29 KiB
JavaScript
Raw Normal View History

feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
/*!
* SQLParser 1.1.0
* Copyright 2012-2015 Andy Kent <andy@forward.co.uk>
* Copyright 2015-2016 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Licensed under MIT (http://opensource.org/licenses/MIT)
*/
!function(t){var e=function(){function t(e){return t[e]}return t["./lexer"]=new function(){var t=this;(function(){var e;e=function(){function t(t,e){var n,i;for(null==e&&(e={}),this.sql=t,this.preserveWhitespace=e.preserveWhitespace||!1,this.tokens=[],this.currentLine=1,i=0;this.chunk=t.slice(i);){if((n=this.keywordToken()||this.starToken()||this.booleanToken()||this.functionToken()||this.windowExtension()||this.sortOrderToken()||this.seperatorToken()||this.operatorToken()||this.mathToken()||this.dotToken()||this.conditionalToken()||this.betweenToken()||this.subSelectOpToken()||this.subSelectUnaryOpToken()||this.numberToken()||this.stringToken()||this.parameterToken()||this.parensToken()||this.whitespaceToken()||this.literalToken())<1)throw new Error("NOTHING CONSUMED: Stopped at - '"+this.chunk.slice(0,30)+"'");i+=n}this.token("EOF",""),this.postProcess()}var e,n,i,r,o,s,u,a,h,c,l,p,f,k,T,E,g,S;return t.prototype.postProcess=function(){var t,e,n,i,r,o,s;for(o=this.tokens,s=[],t=i=0,r=o.length;i<r;t=++i)n=o[t],"STAR"===n[0]?(e=this.tokens[t+1],"SEPARATOR"!==e[0]&&"FROM"!==e[0]?s.push(n[0]="MATH_MULTI"):s.push(void 0)):s.push(void 0);return s},t.prototype.token=function(t,e){return this.tokens.push([t,e,this.currentLine])},t.prototype.tokenizeFromStringRegex=function(t,e,n,i,r){var o,s;return null==n&&(n=0),null==i&&(i=n),null==r&&(r=!0),(o=e.exec(this.chunk))?(s=o[n].replace(/''/g,"'"),r&&this.token(t,s),o[i].length):0},t.prototype.tokenizeFromRegex=function(t,e,n,i,r){var o,s;return null==n&&(n=0),null==i&&(i=n),null==r&&(r=!0),(o=e.exec(this.chunk))?(s=o[n],r&&this.token(t,s),o[i].length):0},t.prototype.tokenizeFromWord=function(t,e){var n,i;return null==e&&(e=t),e=this.regexEscape(e),i=/^\w+$/.test(e)?new RegExp("^("+e+")\\b","ig"):new RegExp("^("+e+")","ig"),(n=i.exec(this.chunk))?(this.token(t,n[1]),n[1].length):0},t.prototype.tokenizeFromList=function(t,e){var n,i,r,o;for(i=0,r=0,o=e.length;r<o&&(n=e[r],!((i=this.tokenizeFromWord(t,n))>0));r++);return i},t.prototype.keywordToken=function(){return this.tokenizeFromWord("SELECT")||this.tokenizeFromWord("INSERT")||this.tokenizeFromWord("INTO")||this.tokenizeFromWord("DEFAULT")||this.tokenizeFromWord("VALUES")||this.tokenizeFromWord("DISTINCT")||this.tokenizeFromWord("FROM")||this.tokenizeFromWord("WHERE")||this.tokenizeFromWord("GROUP")||this.tokenizeFromWord("ORDER")||this.tokenizeFromWord("BY")||this.tokenizeFromWord("HAVING")||this.tokenizeFromWord("LIMIT")||this.tokenizeFromWord("JOIN")||this.tokenizeFromWord("LEFT")||this.tokenizeFromWord("RIGHT")||this.tokenizeFromWord("INNER")||this.tokenizeFromWord("OUTER")||this.tokenizeFromWord("ON")||this.tokenizeFromWord("AS")||this.tokenizeFromWord("UNION")||this.tokenizeFromWord("ALL")||this.tokenizeFromWord("LIMIT")||this.tokenizeFromWord("OFFSET")||this.tokenizeFromWord("FETCH")||this.tokenizeFromWord("ROW")||this.tokenizeFromWord("ROWS")||this.tokenizeFromWord("ONLY")||this.tokenizeFromWord("NEXT")||this.tokenizeFromWord("FIRST")},t.prototype.dotToken=function(){return this.tokenizeFromWord("DOT",".")},t.prototype.operatorToken=function(){return this.tokenizeFromList("OPERATOR",p)},t.prototype.mathToken=function(){return this.tokenizeFromList("MATH",r)||this.tokenizeFromList("MATH_MULTI",o)},t.prototype.conditionalToken=function(){return this.tokenizeFromList("CONDITIONAL",c)},t.prototype.betweenToken=function(){return this.tokenizeFromList("BETWEEN",h)},t.prototype.subSelectOpToken=function(){return this.tokenizeFromList("SUB_SELECT_OP",E)},t.prototype.subSelectUnaryOpToken=function(){return this.tokenizeFromList("SUB_SELECT_UNARY_OP",g)},t.prototype.functionToken=function(){return this.tokenizeFromList("FUNCTION",l)},t.prototype.sortOrderToken=function(){return this.tokenizeFromList("DIRECTION",f)},t.prototype.booleanToken=function(){return this.tokenizeFromList("BOOLEAN",e)},t.prototype.starToken=function(){return this.tokenizeFromRegex("STAR",k)},t.prototype.seperatorToken=function(){return this.tokenizeFromRegex("SEPARATOR",a)},t.prototype.literalToken=function(){return this.tokenizeFromRegex("LITERAL",i,1,0)},t