bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/expr/elastic.go (about) 1 package expr 2 3 import ( 4 "strings" 5 6 "bosun.org/cmd/bosun/expr/parse" 7 "bosun.org/models" 8 ) 9 10 func elasticTagQuery(args []parse.Node) (parse.Tags, error) { 11 n := args[1].(*parse.StringNode) 12 t := make(parse.Tags) 13 for _, s := range strings.Split(n.Text, ",") { 14 t[s] = struct{}{} 15 } 16 return t, nil 17 } 18 19 // ElasticFuncs are specific functions that query an elasticsearch instance. 20 // They are only loaded when the elastic hosts are set in the config file 21 var Elastic = map[string]parse.Func{ 22 // Funcs for querying elastic 23 "escount": { 24 Args: []models.FuncType{models.TypeESIndexer, models.TypeString, models.TypeESQuery, models.TypeString, models.TypeString, models.TypeString}, 25 Return: models.TypeSeriesSet, 26 Tags: elasticTagQuery, 27 F: ESCount, 28 PrefixEnabled: true, 29 }, 30 "esstat": { 31 Args: []models.FuncType{models.TypeESIndexer, models.TypeString, models.TypeESQuery, models.TypeString, models.TypeString, models.TypeString, models.TypeString, models.TypeString}, 32 Return: models.TypeSeriesSet, 33 Tags: elasticTagQuery, 34 F: ESStat, 35 PrefixEnabled: true, 36 }, 37 38 // Funcs to create elastic index names (ESIndexer type) 39 "esindices": { 40 Args: []models.FuncType{models.TypeString, models.TypeString}, 41 VArgs: true, 42 VArgsPos: 1, 43 Return: models.TypeESIndexer, 44 F: ESIndicies, 45 }, 46 "esdaily": { 47 Args: []models.FuncType{models.TypeString, models.TypeString, models.TypeString}, 48 Return: models.TypeESIndexer, 49 F: ESDaily, 50 }, 51 "esmonthly": { 52 Args: []models.FuncType{models.TypeString, models.TypeString, models.TypeString}, 53 Return: models.TypeESIndexer, 54 F: ESMonthly, 55 }, 56 "esls": { 57 Args: []models.FuncType{models.TypeString}, 58 Return: models.TypeESIndexer, 59 F: ESLS, 60 }, 61 62 // Funcs for generate elastic queries (ESQuery Type) to further filter results 63 "esall": { 64 Args: []models.FuncType{}, 65 Return: models.TypeESQuery, 66 F: ESAll, 67 }, 68 "esregexp": { 69 Args: []models.FuncType{models.TypeString, models.TypeString}, 70 Return: models.TypeESQuery, 71 F: ESRegexp, 72 }, 73 "esquery": { 74 Args: []models.FuncType{models.TypeString, models.TypeString}, 75 Return: models.TypeESQuery, 76 F: ESQueryString, 77 }, 78 "esexists": { 79 Args: []models.FuncType{models.TypeString}, 80 Return: models.TypeESQuery, 81 F: ESExists, 82 }, 83 "esand": { 84 Args: []models.FuncType{models.TypeESQuery}, 85 VArgs: true, 86 Return: models.TypeESQuery, 87 F: ESAnd, 88 }, 89 "esor": { 90 Args: []models.FuncType{models.TypeESQuery}, 91 VArgs: true, 92 Return: models.TypeESQuery, 93 F: ESOr, 94 }, 95 "esnot": { 96 Args: []models.FuncType{models.TypeESQuery}, 97 Return: models.TypeESQuery, 98 F: ESNot, 99 }, 100 "esgt": { 101 Args: []models.FuncType{models.TypeString, models.TypeScalar}, 102 Return: models.TypeESQuery, 103 F: ESGT, 104 }, 105 "esgte": { 106 Args: []models.FuncType{models.TypeString, models.TypeScalar}, 107 Return: models.TypeESQuery, 108 F: ESGTE, 109 }, 110 "eslt": { 111 Args: []models.FuncType{models.TypeString, models.TypeScalar}, 112 Return: models.TypeESQuery, 113 F: ESLT, 114 }, 115 "eslte": { 116 Args: []models.FuncType{models.TypeString, models.TypeScalar}, 117 Return: models.TypeESQuery, 118 F: ESLTE, 119 }, 120 }