bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/ace/mode-bosun.js (about)

     1  ace.define("ace/mode/bosun_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
     2  "use strict";
     3  
     4  var oop = require("../lib/oop");
     5  var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
     6  
     7  var BosunHighlightRules = function() {
     8  
     9  	var globals = "checkFrequency|tsdbHost|graphiteHost|logstashElasticHosts|httpListen|hostname|relayListen|smtpHost|smtpUsername|smtpPassword|emailFrom|stateFile|ping|pingDuration|noSleep|blockedPutIPs|allowedPutIPs|unknownThreshold|timeAndDate|responseLimit|searchSince|unknownTemplate|squelch|shortURLKey|tsdbVersion|elasticHosts|annotateElasticHosts|defaultRunEvery|redisHost|influxHost|influxUsername|influxPassword|influxTLS|influxTimeout|ledisDir";
    10  
    11  	var inAlertKeywords = "macro|template|crit|warn|depends|squelch|critNotification|" +
    12  	"warnNotification|unknown|unjoinedOk|ignoreUnknown|log|maxLogFrequency"
    13  
    14  	var inNotificationKeywords = "email|post|get|print|contentType|next|timeout|bodyTemplate|postTemplate|getTemplate|emailSubjectTemplate|runOnActions|groupActions|unknownMinGroupSize|unknownThreshold";
    15  	for (var action of ["Get","Post","Body","EmailSubject"]){
    16  		inNotificationKeywords += "|action"+action;
    17  		inNotificationKeywords += "|unknown"+action;
    18  		inNotificationKeywords += "|unknownMulti"+action;
    19  		for (var type of ["Ack", "Close", "Forget", "ForceClose", "Purge", "Note", "DelayedClose","CancelClose"]){
    20  			inNotificationKeywords += "|action"+action+type;
    21  		}
    22  	}
    23  	var inTemplateKeywords = "subject|body";
    24  
    25  	var inSectionKeywords = [inAlertKeywords, inNotificationKeywords, inTemplateKeywords].join("|");
    26  _
    27  	var confFuncs = "alert|lookup|lookupSeries";
    28  
    29  	var graphiteFuncs = "graphiteBand|graphite";
    30  
    31  	var tsdbFuncs = "band|change|count|diff|q|over|shiftBand";
    32  
    33  	var builtinFuncs = "abs|avg|cCount|d|des|dev|diff|dropbool|dropg|dropge|dropl|drople|dropna|epoch|filter|first|forecastlr|last|len|limit|linelr|max|median|merge|min|nv|percentile|rename|series|shift|since|sort|streak|sum|t|tod|ungroup";
    34  
    35  	var logstashFuncs = "lsstat|lscount";
    36  
    37  	var elasticFuncs = "esall|esand|escount|esdaily|esgt|esgte|esindices|esls|eslt|eslte|esor|esquery|esregexp|esstat"
    38  
    39  	var exprFuncs = [confFuncs, graphiteFuncs, tsdbFuncs, builtinFuncs, logstashFuncs, elasticFuncs].join("|")
    40  
    41  	this.$rules = {
    42  		"start" : [
    43  			{
    44  				token: "keyword",
    45  				regex: "^(" + globals + ")",
    46  				next: "consumeLine"
    47  			},
    48  			{
    49  				token: "variable.instance",
    50  				regex: "[$]",
    51  				next: "variable"
    52  			},
    53  			{
    54  				token: ["keyword", "space", "variable", "space", "paren.lparent"],
    55  				regex: "^(alert|notification|lookup|macro|template)(\\s+)([-a-zA-Z0-9._]+)(\\s)+([{])",
    56  			},
    57  			{
    58  				token: ["space", "keyword", "space", "regexp", "space", "paren.lparen"],
    59  				regex: "(\\s*)(entry)(\\s*)(.*)(\\s)([{])",
    60  			},
    61  			{
    62  				token: ["space", "keyword", "space", "keyword.operator", "regexp"],
    63  				regex: "(\\s*)(squelch)(\\s*)(=)(.*)",
    64  			},
    65  			{
    66  				token: ["space", "keyword", "space", "equals"],
    67  				regex: "(\\s*)(" + inSectionKeywords + ")(\\s*)(=)",
    68  			},
    69  			{
    70  				token: "string",
    71  				regex: '"',
    72  				next: "qqstring"
    73  			},
    74  			{
    75  				token: "string",
    76  				regex : "[']" + '(?:(?:\\\\.)|(?:[^' + "'" + '\\\\]))*?' + "[']"},
    77  			{
    78  				token: "string",
    79  				regex : '[`](?:[^`]*)[`]'}, // single line
    80  			{
    81  				token: "string", merge : true,
    82  				regex : '[`](?:[^`]*)$', next : "bqstring"
    83  			},
    84  			{
    85  				token: "doc.comment",
    86  				regex : /^\s*#.*/},
    87  			{
    88  				token: "constant.numeric",
    89  				regex: "[+-]?[0-9.]+e?[0-9.]*\\b"},
    90  			{
    91  				token: "keyword.operator",
    92  				regex: "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|!|\\||\\^|~|<|>|<=|=>|==|!=|<>|="},
    93  			{
    94  				token: "paren.lparen",
    95  				regex : "[\\[({]"},
    96  			{
    97  				token: "paren.rparen",
    98  				regex : "[\\])}]"},
    99  			{
   100  				token: ["support.function", "paren.lparen"],
   101  				regex: "(" + exprFuncs + ")([(])"},
   102  			{
   103  				caseInsensitive: true
   104  			}
   105  		],
   106  		"consumeLine": [
   107  			{
   108  				token: "consumeLine",
   109  				regex: ".*$",
   110  				next: "start"
   111  			},
   112  		],
   113  		"qqstring": [
   114  			{
   115  				token: "variable",
   116  				regex: /\$\{\w+}|\$\w+\b/,
   117  				push: "variable"
   118  			}, {
   119  				token: "string",
   120  				regex: '"',
   121  				next: "start"
   122  			}, {
   123  				defaultToken: "string"
   124  			}],
   125  		"bqstring": [
   126  			{
   127  				token: "string",
   128  				regex : '(?:[^`]*)`',
   129  				next : "start"},
   130  			{
   131  				token: "string",
   132  				regex : '.+'
   133  			}
   134  		],
   135  		"variable": [
   136  			{
   137  				token: "variable.instance", // variable
   138  				regex: "[a-zA-Z_\\d]+(?:[(][.a-zA-Z_\\d]+[)])?",
   139  				next : "start"
   140  			}, {
   141  				token: "variable.instance", // with braces
   142  				regex: "{?[.a-zA-Z_\\d]+}?",
   143  				next: "start"
   144  			}
   145  		],
   146  	};
   147  };
   148  
   149  oop.inherits(BosunHighlightRules, TextHighlightRules);
   150  
   151  exports.BosunHighlightRules = BosunHighlightRules;
   152  });
   153  
   154  ace.define("ace/mode/bosun",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/bosun_highlight_rules"], function(require, exports, module) {
   155  "use strict";
   156  
   157  var oop = require("../lib/oop");
   158  var TextMode = require("./text").Mode;
   159  var BosunHighlightRules = require("./bosun_highlight_rules").BosunHighlightRules;
   160  
   161  var Mode = function() {
   162  	this.HighlightRules = BosunHighlightRules;
   163  };
   164  
   165  oop.inherits(Mode, TextMode);
   166  
   167  (function() {
   168  	this.$id = "ace/mode/bosun";
   169  }).call(Mode.prototype);
   170  
   171  exports.Mode = Mode;
   172  });