├── images
└── InfluxDB_WDC.png
├── .idea
└── vcs.xml
├── package.json
├── LICENSE
├── README.md
├── InfluxDB.html
└── InfluxDB_WDC.js
/images/InfluxDB_WDC.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tagyoureit/InfluxDB_WDC/HEAD/images/InfluxDB_WDC.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "influxdb_wdc",
3 | "version": "2.0.5",
4 | "description": "A Tableau Web Data Connector (WDC) for InfluxDB",
5 | "main": "Influx.html",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/tagyoureit/InfluxDB_WDC.git"
12 | },
13 | "keywords": [
14 | "tableau",
15 | "influxdb",
16 | "influx",
17 | "wdc",
18 | "web",
19 | "data",
20 | "connector"
21 | ],
22 | "author": "Russell Goldin",
23 | "license": "MIT",
24 | "bugs": {
25 | "url": "https://github.com/tagyoureit/InfluxDB_WDC/issues"
26 | },
27 | "homepage": "https://github.com/tagyoureit/InfluxDB_WDC#readme",
28 | "dependencies": {}
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # InfluxDB_WDC
2 | A Tableau Web Data Connector (WDC) to pull data from [InfluxDB](https://github.com/influxdata/influxdb)
3 |
4 | Github Repository: [https://github.com/tagyoureit/InfluxDB_WDC](https://github.com/tagyoureit/InfluxDB_WDC)
5 |
6 | 
7 |
8 | ## Release Notes
9 | 1. 2.0.5
10 | * Fixed es6 incompatibility introduced with 2.0.4
11 | 1. 2.0.4
12 | * Fixed loading large data sets
13 | * Fixed existing settings are reloaded when editing data source
14 | * Fixed processing measurements with identical tag/field names (use custom sql)
15 | * Fixed custom sql parsing
16 | * Updated dependencies
17 | * Updated console debug statements
18 | 1. 2.0.3
19 | * Fixed inability to select HTTPS. Issue #10.
20 | 1. 2.0.2
21 | * Added fix for focus on QueryType button when using keyboard
22 | 1. 2.0.1
23 | * Added fix for . (dot) in special characters
24 | 1. 2.0 -
25 | * Added Custom SQL - read more below for further details
26 | * Revamped UI
27 | * Removed https+influxdb:\\; It was only for embedded code.
28 | * Upgraded components Bootstrap 4, WDC 2.3, and other components.
29 | * Fixed issue with empty table crashing connector.
30 | 1. 1.4 - Added protocol https+influxdb:\\ per Issue #4.
31 | 1. 1.3 - Additional error logging.
32 | 1. 1.2 - Added support for special characters - ` (space)`, `,`, `\ and /`, `' and "`,`-` and other special characters.
33 | 1. 1.1 - When editing a connection, the previous values will be restored (except for the password). Increased, and dismissible, alert information. Formatting of # of rows returned with ",".
34 | 1. 1.0 - Initial version
35 |
36 | ## Instructions
37 |
38 | ### Local install
39 | * npm install influxdb_wdc
40 | OR
41 | * Download the files and put them in a local web server.
42 |
43 | * Open in Tableau 10.2+ and point to your URL.
44 |
45 | ### Use it in place
46 |
47 | This is hosted by Github Pages. To use it, open Tableau (10.2+), select "Web Data Connector" and point to this URL: [https://tagyoureit.github.io/InfluxDB_WDC/InfluxDB.html](https://tagyoureit.github.io/InfluxDB_WDC/InfluxDB.html)
48 |
49 | #### Authorization
50 | If you use authorization on your InfluxDB, you can click the link to reload the page with the username/password fields. Alternatively, add `?auth=true` or `?auth=false` to the end of the URL to access these directly.
51 |
52 | ## Features
53 |
54 | * Basic Auth or no Auth
55 | * Custom SQL
56 | * Full or Incremental refresh
57 | * Row count for extract creation progress
58 |
59 | ## How To Use
60 |
61 | 4 easy steps.
62 | 1. Enter your server details (protocol, hostname, port and optionally username/password)
63 | 2. Press connect to load the databases and then select the appropriate one
64 | 3. Choose the type of query you want (See details below)
65 | 4. Press Submit to load the schema into Tableau
66 |
67 | ### Query Types
68 | #### All Rows
69 | This is the most basic query. It is equivalent to writing "select * from [measurement]" in InfluxQL CLI. You will be presented with a schema in the Tableau Data Source page and can select your tables and Tableau will then load the data. This will support Incremental refreshes.
70 |
71 | #### Aggregation
72 | This is a shortcut for simple aggregations. You can choose one of 9 basic aggregations and the interval type (microseconds up to weeks) and the interval time. Like with all rows, you will be able to select the specific tables you want at Tableau Data Source Screen and this supports Incremental Refreshes.
73 |
74 | #### Custom SQL
75 | This allows you to enter any custom sql that you could write into InfluxQL for any query not supported by the other two types. In addition, this supports multiple statements and multiple series.
76 |
77 | * Multiple statements - You can write multiple InfluxQL statements separated by ';'. For example,
78 | ```
79 | select * from tableA; select * from tableB
80 | ```
81 | Tableau will load the schema for tableaA and tableB and you can choose to then load the data individually or join them together (see note on aggregation below).
82 |
83 | * Multiple series - This connector supports grouping the data by series. In InfluxQL if you write a sql statement like `select * from tableC group by "someTag"` and someTag has multiple values Influx will return multiple series. See [group by](https://docs.influxdata.com/influxdb/v1.5/query_language/data_exploration/#group-by-tags) in the Influx help pages. This connector will union all of the data in each series into a single table. You can then format the data in any number of ways using Tableau.
84 |
85 | You can combine multiple series and multiple statements with the custom sql option. Incremental refreshes are not supported with custom sql at this time (please submit an issue if you feel this is important).
86 |
87 | ## Suggestions on use
88 | ### Tableau and Time Series
89 | Tableau works great with time data, but time series metrics can be a challenge. The most metrics you can have on a single graph is 2 (with Dual Axis). If you want to show many metrics you'll want to create a dashboard with individual measurements.
90 |
91 | ### Aggregation
92 | Aggregation is a great way to be able to do a row-level join on time series data that would otherwise not be joinable. When you aggregate to any interval, Influx will "fill in" the missing values with nulls. This should enable an inner join where you can use all of your data from a single Tableau Data Source. In Tableau, use your table with earliest/latest dates and then connect to it with a left-outer join.
93 |
94 | Aggregation can significantly decrease (or increase) the number of data points that are returned. If your DB stores 1000 measurements per second, and aggregate up to the minute you'll reduce the data by 59,999 points per minute. On the other hand, if you store 1 measurement per hour and aggregate by the milli-second you'll pull an extra 59,999 data points per minute.
95 |
96 | If you don't aggregate the measurements, then you will likely want to create a separate Tableau Data Source for each measurement.
97 |
98 | #### Do you need MAX in Tableau?
99 | By default, Tableau will try to SUM all of your measurements. If you bring data back and try to display it in Tableau at a higher level aggregation (eg you collect temperature readings every 20 minutes) and graph this at an hourly measurement, you may see you steady 80 degrees appear as 240 degrees!
100 |
101 | ## Limitations
102 |
103 | Currently, the admin user is needed to populate the list of databases. Once the extract is created if you want to refresh it you can enter a read (or write) only user account in Tableau.
104 |
--------------------------------------------------------------------------------
/InfluxDB.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | InfluxDB Feed
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
Influx DB - Tableau Web Data Connector
33 |
Bring in your time series data!
34 |
35 |
36 |
41 |
42 |
43 |
44 |
45 |
46 |
1. Connection Information
47 |
48 |
55 |
56 |
57 |
58 |
80 |
81 |
82 |
83 |
84 |
96 |
97 |
105 |
106 |
107 |
108 |
109 |
2. Databases
110 |
111 |
112 | Connect
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | Group By
154 |
155 |
156 |
158 | mean
159 |
160 |
161 |
172 |
173 |
174 |
175 |
176 |
197 |
198 |
199 |
200 |
201 |
212 |
213 |
214 |
4. Submit to Tableau
215 |
216 |
Submit
217 |
218 |
219 |
220 |
221 |
222 |
223 |
Version 2.0.5 - Release
225 | Notes
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
--------------------------------------------------------------------------------
/InfluxDB_WDC.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | var myConnector = tableau.makeConnector();
4 | var schema = [];
5 | var server = 'localhost';
6 | var port = 8086;
7 | var db = '';
8 | var debug = true; // set to true to enable JS Console debug messages
9 | var protocol = 'http://'; // default to non-encrypted. To setup InfluxDB with https see https://docs.influxdata.com/influxdb/v1.2/administration/https_setup/
10 | var useAuth = false; // bool to include/prompt for username/password
11 | var username = '';
12 | var password = '';
13 | var queryString_Auth; // string to hold the &u=_user_&p=_pass_ part of the query string
14 | var queryString_Auth_Log; // use for logging the redacted password
15 |
16 | var queryType = 'all'; // var to store query type
17 | var interval_time = '30'; // value for the group by time
18 | var interval_measure = 'm'; // h=hour, m=min, etc
19 | var interval_measure_string = 'minutes'; // full string for interval
20 | var aggregation = 'mean'; // value for aggregating database value
21 | var customSql = ''; // value for custom SQL as user typed it
22 | var customSqlSplit = {}; // values of query part of custom sql; to be used with getData
23 |
24 |
25 | // from https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_tutorial/#special-characters-and-keywords
26 | // Influx allows <, = space "> which can't be used as a Tableau id field (https://github.com/tagyoureit/InfluxDB_WDC/issues/3)
27 | // Tableau only allows letters, numbers or underscores
28 | function replaceSpecialChars_forTableau_ID(str) {
29 |
30 | var newStr = str.replace(/ /g, '_')
31 | .replace(/"/g, '_doublequote_')
32 | .replace(/,/g, '_comma_')
33 | .replace(/=/g, '_equal_')
34 | .replace(/\//g, '_fslash_')
35 | .replace(/-/g, '_dash_')
36 | .replace(/\./g, '_dot_')
37 | .replace(/[^A-Za-z0-9_]/g, '_');
38 | return newStr;
39 | }
40 |
41 | function influx_escape_char_for_URI(str) {
42 | var newStr = str.replace(/\\/g, '\\\\');
43 | newStr = newStr.replace(/\//g, '//');
44 | newStr = newStr.replace(/ /g, '%20');
45 | newStr = newStr.replace(/"/g, '\\"');
46 | return newStr;
47 | }
48 |
49 | function resetSchema() {
50 | schema = [];
51 | console.log('Schema has been reset');
52 | }
53 |
54 | resetSchema();
55 |
56 | function queryStringTags(index, queryString_tags) {
57 | if (debug) console.log('Retrieving tags with query: %s', queryString_tags);
58 | // Create a JQuery Promise object
59 | var deferred = $.Deferred();
60 | $.getJSON(queryString_tags, function (tags) {
61 | if (debug) console.log('tag query string for ' + index + ': ' + JSON.stringify(tags));
62 |
63 | // this if statement checks to see if there is an empty series (just skip it)
64 | // empty resultset: tag query string for 7: {"results":[{"statement_id":0}]}
65 | if (tags.results[0].hasOwnProperty('series')) {
66 | // Create a factory (array) of async functions
67 | var deferreds = (tags.results[0].series[0].values).map(function (tag, tag_index) {
68 | if (debug) console.log('in queryStringTags. tag: ' + tag[0] + ' tag_index: ' + tag_index);
69 | schema[index].columns.push({
70 | id: replaceSpecialChars_forTableau_ID(tag[0]),
71 | alias: tag[0],
72 | dataType: tableau.dataTypeEnum.string,
73 | });
74 | if (debug) console.log(JSON.stringify(schema));
75 | });
76 | }
77 | // Execute all async functions in array
78 | return $.when.apply($, deferreds)
79 | .then(function () {
80 | if (debug) console.log('finished processing tags');
81 | deferred.resolve();
82 | });
83 |
84 | })
85 | .fail(function (jqXHR, textStatus, errorThrown) {
86 | console.log(JSON.stringify(errorThrown));
87 | console.log(errorThrown)
88 | tableau.abortWithError(errorThrown);
89 | doneCallback();
90 | });
91 | return deferred.promise();
92 |
93 | }
94 |
95 | function queryStringFields(index, queryString_fields) {
96 | var deferred = $.Deferred();
97 | if (debug) console.log('Retrieving fields with query: ' + queryString_fields);
98 | $.getJSON(queryString_fields, function (fields) {
99 | // this if statement checks to see if there is an empty series (just skip it)
100 | // empty resultset: tag query string for 7: {"results":[{"statement_id":0}]}
101 | if (fields.results[0].hasOwnProperty('series')) {
102 | var deferreds = (fields.results[0].series[0].values).map(function (field, field_index) {
103 | if (debug) console.log('in queryStringFields. field: ' + field[0] + ' field_index: ' + field_index);
104 | var id_str,
105 | alias_str;
106 | if (queryType === 'aggregation') {
107 | id_str = aggregation + '_' + replaceSpecialChars_forTableau_ID(field[0]);
108 | alias_str = aggregation + '_' + field[0];
109 | } else if (queryType === 'all') {
110 | id_str = replaceSpecialChars_forTableau_ID(field[0]);
111 | alias_str = field[0];
112 | }
113 | // force the correct mapping of data types
114 | var tabDataType;
115 | switch (field[1]) {
116 | case 'float':
117 | tabDataType = tableau.dataTypeEnum.float;
118 | break;
119 | case 'integer':
120 | tabDataType = tableau.dataTypeEnum.int;
121 | break;
122 | case 'string':
123 | tabDataType = tableau.dataTypeEnum.string;
124 | break;
125 | case 'boolean':
126 | tabDataType = tableau.dataTypeEnum.bool;
127 | break;
128 | }
129 | schema[index].columns.push({
130 | id: id_str,
131 | alias: alias_str,
132 | dataType: tabDataType,
133 | });
134 | });
135 | }
136 | return $.when.apply($, deferreds)
137 | .then(function () {
138 | if (debug) console.log('finished processing fields');
139 | deferred.resolve();
140 | });
141 | })
142 | .fail(function (jqXHR, textStatus, errorThrown) {
143 | tableau.abortWithError(errorThrown);
144 | console.log('INFLUX ERROR!');
145 | console.log(errorThrown);
146 | doneCallback();
147 | });
148 | return deferred.promise();
149 | }
150 |
151 | function addTimeTag() {
152 | // the "time" tag isn't returned by the schema. Add it to every measurement.
153 | $.each(schema, function (index, e) {
154 | schema[index].columns.unshift({
155 | id: 'time',
156 | dataType: tableau.dataTypeEnum.datetime,
157 | });
158 | });
159 | }
160 | function sleep(ms) {
161 | return new Promise(function(resolve){setTimeout(resolve, ms)});
162 | }
163 | function checkForDuplicateNames() {
164 | // Duplicate fields are too hard to use
165 | // https://docs.influxdata.com/influxdb/v1.8/troubleshooting/frequently-asked-questions/#tag-and-field-key-with-the-same-name
166 | // Remove the measurement and raise an alert
167 | var s = schema.slice();
168 | var removed = [];
169 | console.log(Object.keys(s))
170 | // loop through each column
171 | for (var c = 0; c < schema.length; c++){
172 |
173 | var measurement = schema[c];
174 | console.log(measurement.id)
175 | var list = [measurement.columns[0].id];
176 | console.log(list);
177 | for (var f = 1; f < measurement.columns.length; f++){
178 | var curr = measurement.columns[f].id;
179 | if (list.indexOf(curr) === -1) {
180 | list.push(curr); // no match
181 | }
182 | else {
183 | console.log('MATCH: duplicate field/tag: ' + measurement.id + ', ' + curr);
184 | removed.push(measurement.id+'/'+curr);
185 | // remove from original schema
186 | // find new index
187 | var idx = s.findIndex(function(el){return el.id === measurement.id});
188 | s.splice(idx, 1);
189 | }
190 | }
191 | }
192 | if (removed.length){
193 | schema = s;
194 | influx_alert('Duplicate tag/keys found in the following measurements. Please use custom sql to query', removed.join(", ")+ '\nThis window will close automatically in 5s.');
195 | console.log(removed)
196 | return sleep(5000);
197 | }
198 | }
199 |
200 | function getMeasurements(db, queryString) {
201 | // Get all measurements (aka Tables) from the DB
202 |
203 | $.getJSON(queryString, function (resp) {
204 | if (debug) console.log('retrieved all measurements: ' + resp);
205 | if (debug) console.log('resp.results[0].series[0].values: ' + resp.results[0].series[0].values);
206 |
207 | // for each measurement, save the async function to a "factory" array
208 | var deferreds = (resp.results[0].series[0].values).map(function (measurement, index) {
209 | schema[index] = {
210 | id: replaceSpecialChars_forTableau_ID(measurement[0]),
211 | alias: measurement[0],
212 | incrementColumnId: 'time',
213 | columns: [],
214 | };
215 | if (debug) console.log(schema);
216 | if (debug) console.log('analyzing index: ' + index + ' measurement: ' + measurement[0]);
217 | if (debug) console.log('schema now is: ' + schema);
218 |
219 | var deferred_tags_and_fields = [];
220 |
221 | // Get the tags (items that can be used in a where clause) in the measurement
222 | var newM = influx_escape_char_for_URI(measurement[0]);
223 | var queryString_tags = protocol + server + ':' + port + '/query?q=SHOW+TAG+KEYS+FROM+%22' + newM + '%22&db=' + db;
224 | if (useAuth) {
225 | setAuth();
226 | queryString_tags += queryString_Auth;
227 | }
228 |
229 | // Get fields/values
230 | var queryString_fields = protocol + server + ':' + port + '/query?q=SHOW+FIELD+KEYS+FROM+%22' + newM + '%22&db=' + db;
231 | if (useAuth) {
232 | setAuth();
233 | queryString_fields += queryString_Auth;
234 | }
235 |
236 | deferred_tags_and_fields.push(queryStringTags(index, queryString_tags));
237 | deferred_tags_and_fields.push(queryStringFields(index, queryString_fields));
238 |
239 | return $.when.apply($, deferred_tags_and_fields)
240 | .then(function () {
241 | if (debug) console.log('finished processing queryStringTags and queryStringFields for ' + measurement[0]);
242 | });
243 | });
244 |
245 | return $.when.apply($, deferreds)
246 | .then(function () {
247 | if (debug) console.log('Finished getting ALL tags and fields for ALL measurements. Hooray!');
248 | if (debug) console.log('schema is now: ' + JSON.stringify(schema));
249 | })
250 | .then(addTimeTag)
251 | .then(checkForDuplicateNames)
252 | .then(function () {
253 | if (debug) console.log('schema finally: ' + JSON.stringify(schema));
254 |
255 | // Once we have the tags/fields enable the Load button
256 | loadSchemaIntoTableau();
257 | });
258 | })
259 | .fail(function (jqXHR, textStatus, errorThrown) {
260 | console.log('INFLUX ERROR!');
261 | console.log(errorThrown);
262 | tableau.abortWithError(errorThrown);
263 | doneCallback();
264 | });
265 |
266 | }
267 |
268 | function modifyLimitAndSlimit(sql) {
269 | // this function modifies/add series and row limits so we only get 1 row of data back for the schema.
270 | // On the getData side, we will union all of these series together.
271 |
272 | console.log('sql before regex:', sql);
273 | var limitRegex = /\b(limit\s\d{0,10})/gmi;
274 | var slimitRegex = /\b(slimit\s\d{0,10})/gmi;
275 | if (sql.search(limitRegex) === -1) {
276 | // no limit x in sql
277 | sql += ' limit 1';
278 | }
279 | else {
280 | // limit x found; replace with limit 1
281 | sql = sql.replace(limitRegex, ' limit 1');
282 | }
283 |
284 | if (sql.search(slimitRegex) === -1) {
285 | // no slimit x in sql
286 | sql += ' slimit 1';
287 | }
288 | else {
289 | // slimit x found; replace with limit 1
290 | sql = sql.replace(slimitRegex, ' slimit 1');
291 | }
292 |
293 | return sql;
294 | }
295 |
296 |
297 | function buildCustomSqlString(db, _customSql) {
298 | var modifiedCustomSql = modifyLimitAndSlimit(_customSql);
299 | var queryString = protocol + server + ':' + port + '/query?q=' + encodeURIComponent(modifiedCustomSql) + '&db=' + db;
300 | if (useAuth) {
301 | setAuth();
302 | queryString += queryString_Auth;
303 | }
304 |
305 | if (debug) console.log('Custom SQL url: ' + queryString);
306 | return queryString;
307 | }
308 |
309 | function getCustomSqlSchema(queryString, originalSql) {
310 | var deferred = new $.Deferred();
311 |
312 | $.getJSON(queryString)
313 | .done(function (resp) {
314 | var _schema = [];
315 | if (!resp.results[0].hasOwnProperty('series')) {
316 | influx_alert('No rows returned', JSON.stringify(resp));
317 | }
318 | else {
319 | if (debug) console.log('retrieved custom sql response: ' + JSON.stringify(resp));
320 | if (debug) console.log('resp.results[0].series[0].values: ' + JSON.stringify(resp.results[0].series[0].values));
321 |
322 | var cols = [];
323 |
324 | // columns/fields
325 | resp.results[0].series[0].columns.forEach(function (el, index) {
326 | if (el === 'time') {
327 | type = tableau.dataTypeEnum.datetime;
328 | }
329 | else {
330 | type = enumType(resp.results[0].series[0].values[0][index]);
331 | }
332 | cols.push({
333 | id: replaceSpecialChars_forTableau_ID(el),
334 | alias: el,
335 | dataType: type,
336 | });
337 | });
338 |
339 | // tags; will only be present with multiple group by clauses
340 | if (resp.results[0].series[0].hasOwnProperty('tags')) {
341 | for (var el in resp.results[0].series[0].tags) {
342 |
343 | cols.push({
344 | id: replaceSpecialChars_forTableau_ID(el),
345 | alias: el,
346 | dataType: tableau.dataTypeEnum.string,
347 | sql: queryString,
348 | });
349 | }
350 | }
351 |
352 | _schema = {
353 | id: replaceSpecialChars_forTableau_ID(resp.results[0].series[0].name),
354 | alias: resp.results[0].series[0].name,
355 | //incrementColumnId: "time",
356 | columns: cols,
357 | };
358 | customSqlSplit[resp.results[0].series[0].name] = originalSql;
359 |
360 | if (debug) console.log('schema for query: ' + JSON.stringify(_schema));
361 | schema.push(_schema);
362 | deferred.resolve();
363 | }
364 | })
365 | .fail(function (jqXHR, textStatus, errorThrown) {
366 | console.log('INFLUX ERROR getCustomSqlSchema!');
367 | console.log('jqXHR: ' + JSON.stringify(jqXHR));
368 | console.log('textStatus: ' + JSON.stringify(textStatus));
369 | console.log('errorThrown: ' + JSON.stringify(errorThrown));
370 | influx_alert('Error parsing sql', 'Response error: ' + errorThrown + ' Response text: ' + JSON.stringify(jqXHR.responseJSON));
371 | });
372 | return deferred.promise();
373 |
374 | }
375 |
376 |
377 | function parseCustomSql(db, _customSql) {
378 | // Get all measurements (aka Tables) from the DB
379 |
380 |
381 | /*
382 | Sample of return values for single series
383 | {
384 | "results"
385 | :
386 | [
387 | {
388 | "statement_id": 0,
389 | "series": [
390 | {
391 | "name": "tank_level",
392 | "columns": [
393 | "time",
394 | "max_gallons_of_chemical",
395 | "max_gallons_of_water",
396 | "max_status",
397 | "max_strength_of_chemical",
398 | "max_total_gallons"
399 | ],
400 | "values": [
401 | [
402 | "1970-01-01T00:00:00Z",
403 | 1,
404 | 1,
405 | 1,
406 | 0.145,
407 | 2
408 | ]
409 | ]
410 | }
411 | ]
412 | }
413 | ]
414 | }
415 |
416 |
417 | Sample of return for multiple series
418 | {
419 | "results"
420 | :
421 | [{
422 | "statement_id": 0,
423 | "series": [{
424 | "name": "tank_pump",
425 | "tags": {"pump": "acid"},
426 | "columns": ["time", "integral"],
427 | "values": [["2018-06-29T05:00:00Z", 2.881666666666667], ["2018-06-29T06:00:00Z", 3.4783333333333335], ["2018-06-29T07:00:00Z", 3.4008333333333334], ["2018-06-29T08:00:00Z", 3.974166666666667], ["2018-06-29T09:00:00Z", 4.004166666666667], ["2018-06-29T10:00:00Z", 3.9775], ["2018-06-29T11:00:00Z", 3.9000000000000004], ["2018-06-29T12:00:00Z", 3.9608333333333334]]
428 | }],
429 | "partial": true
430 | }]
431 | }
432 | {
433 | "results"
434 | :
435 | [{
436 | "statement_id": 0,
437 | "series": [{
438 | "name": "tank_pump",
439 | "tags": {"pump": "chlorine"},
440 | "columns": ["time", "integral"],
441 | "values": [["2018-06-29T04:00:00Z", 3.706666666666667], ["2018-06-29T05:00:00Z", 1.0125]]
442 | }],
443 | "partial": true
444 | }]
445 | }
446 | {
447 | "results"
448 | :
449 | [{
450 | "statement_id": 0,
451 | "series": [{
452 | "name": "tank_pump",
453 | "tags": {"pump": "acid"},
454 | "columns": ["time", "integral"],
455 | "values": [["2018-06-29T13:00:00Z", 0.8616666666666667]]
456 | }]
457 | }]
458 | }
459 | */
460 |
461 | customSql = _customSql;
462 |
463 | deferred_array = [];
464 | if (customSql.indexOf(';') !== -1) {
465 | customSqlArray = customSql.split(';');
466 | // can have select * from measurement; and still be a single query
467 | if (customSqlArray.length > 1) {
468 | if (debug) console.log('Multiple sql statements (${customSqlArray.length}) found for ' + customSql + ':' + customSqlArray);
469 | }
470 | // for each query, get tables
471 | for (var i = 0; i < customSqlArray.length; i++) {
472 | if (customSqlArray[i].length > 6){
473 | var newsql = buildCustomSqlString(db, customSqlArray[i]);
474 | deferred_array.push(getCustomSqlSchema(newsql, customSql));
475 | }
476 | else {
477 | console.log('Skipping SQL fragment: ' + customSqlArray[i]);
478 | }
479 | }
480 | }
481 | else {
482 | var newsql = buildCustomSqlString(db, customSql);
483 | deferred_array.push(getCustomSqlSchema(newsql, customSql));
484 | }
485 | resetSchema();
486 |
487 | $.when.apply($, deferred_array)
488 | .then(function () {
489 | if (debug) console.log('finished processing all cust sql for ' + JSON.stringify(customSql));
490 | // Once we have the schema enable the Load button
491 | if (debug) console.log('custom sql schema finally: ' + JSON.stringify(schema));
492 | loadSchemaIntoTableau();
493 | });
494 | }
495 |
496 |
497 | function enumType(type) {
498 | if (isNaN(type) === true) {
499 | return tableau.dataTypeEnum.string;
500 | }
501 | else {
502 | return tableau.dataTypeEnum.float;
503 | }
504 | }
505 |
506 | function setAuth() {
507 | username = $('#username')
508 | .val();
509 | password = $('#password')
510 | .val();
511 | queryString_Auth = '&u=' + username + '&p=' + password;
512 | queryString_Auth_Log = '&u=' + username + '&p=[redacted]';
513 | }
514 |
515 | function getDBs() {
516 | try {
517 | $('.proto_sel')
518 | .click(function () {
519 | if (debug) {
520 | console.log('Protocol changed to: ' + $(this)
521 | .text());
522 | }
523 | $('.proto_sel').parent().parent().find('.btn').html($(this)
524 | .text() + ' ')
525 | // $(this)
526 | // .html($(this)
527 | // .text() + ' ');
528 | // $(this)
529 | // .val($(this)
530 | // .data('value'));
531 |
532 | protocol = $(this)
533 | .text();
534 | })
535 |
536 |
537 |
538 |
539 |
540 | $('#interval_time')
541 | .change(function () {
542 | if ($(this)
543 | .val() === '') {
544 | interval_time = $(this)
545 | .prop('placeholder');
546 | } else {
547 | interval_time = $(this)
548 | .val();
549 | }
550 | });
551 |
552 |
553 | // retrieve the list of databases from the server
554 | $('#tableButton')
555 | .click(function () {
556 |
557 | // Reset the dropdown in case the user selects another server
558 | $('.selectpicker')
559 | .html('');
560 | $('.selectpicker')
561 | .selectpicker('refresh');
562 |
563 |
564 | if ($('#servername')
565 | .val() !== '') {
566 | server = $('#servername')
567 | .val();
568 | } else {
569 | server = 'localhost';
570 | }
571 |
572 | if ($('#serverport')
573 | .val() !== '') {
574 | port = $('#serverport')
575 | .val();
576 | } else {
577 | port = 8086;
578 | }
579 |
580 | var queryString_DBs = protocol + server + ':' + port + '/query?q=SHOW+DATABASES';
581 | if (useAuth) {
582 | setAuth();
583 | queryString_DBs += queryString_Auth;
584 | }
585 |
586 | if (debug) console.log('Retrieving databases with querystring: ' + queryString_DBs);
587 | $.ajax({
588 | url: queryString_DBs,
589 | dataType: 'json',
590 | timeout: 3000,
591 | success: function (resp) {
592 | if (debug) console.log(resp.results[0].series[0].values);
593 |
594 | $('.selectpicker')
595 | .html('');
596 | $.each(resp.results[0].series[0].values, function (index, value) {
597 | $('' + value + ' ')
598 | .appendTo('.selectpicker');
599 | });
600 | $('.selectpicker')
601 | .selectpicker('refresh');
602 |
603 | // Once we have the databases, enable the 'load schema' button
604 | $('#getSchemaButton')
605 | .prop('disabled', false);
606 | },
607 | })
608 | .done(function () {
609 | // alert("done")
610 | })
611 | .fail(function (err) {
612 | console.log('INFLUX ERROR!');
613 | console.log(JSON.stringify(err))
614 | console.log(err);
615 | influx_alert('Error loading database', JSON.stringify(err) + '\n If you are using 2019.4 or later you may be experiencing a CORS limitation. You need to enable HTTPS on Influx (https://docs.influxdata.com/influxdb/v1.8/administration/https_setup/) or install this extension locally and run it from an http server.');
616 | });
617 | });
618 |
619 | $('#db_dropdown')
620 | .on('changed.bs.select', function (e) {
621 | if (debug) console.log(e.target.value + ' has been selected');
622 |
623 | // reset the schema if the database selection changes
624 | resetSchema();
625 | });
626 |
627 | $('#getSchemaButton')
628 | .click(function () {
629 | db = $('#db_dropdown option:selected')
630 | .text();
631 | if (queryType === 'custom'){
632 | parseCustomSql(db, $('#customSql')
633 | .val());
634 | }
635 | else {
636 | var queryString = protocol + server + ':' + port + '/query?q=SHOW+MEASUREMENTS&db=' + db;
637 | if (useAuth) {
638 | setAuth();
639 | queryString += queryString_Auth;
640 | }
641 | getMeasurements(db, queryString);
642 | }
643 |
644 | });
645 | console.log('done with getDBs')
646 | } catch (err) {
647 | console.log(JSON.stringify(err));
648 | tableau.abortWithError(err);
649 | doneCallback();
650 | }
651 | }
652 |
653 | function influx_alert(errorType, err) {
654 | console.log(err);
655 | $('#influx_alert')
656 | .html('× ' + errorType + ': ' + err + '
');
657 | $('#influx_alert')
658 | .fadeIn();
659 | }
660 |
661 | function loadSchemaIntoTableau() {
662 | tableau.connectionName = 'InfluxDB';
663 | var json = {
664 | db: db,
665 | server: server,
666 | aggregation: aggregation,
667 | interval_time: interval_time,
668 | interval_measure: interval_measure,
669 | interval_measure_string: interval_measure_string,
670 | protocol: protocol,
671 | port: port,
672 | useAuth: useAuth,
673 | queryType: queryType,
674 | schema: schema,
675 | customSql: customSql,
676 | customSqlSplit: customSqlSplit,
677 | };
678 | if (useAuth) {
679 | tableau.username = username;
680 | tableau.password = password;
681 | }
682 | tableau.connectionData = JSON.stringify(json);
683 | console.log('Loading schema with connectionData: ' + JSON.stringify(json));
684 | console.log(json);
685 | console.log('Tableau object: ' + JSON.stringify(tableau));
686 | console.log(tableau);
687 | tableau.submit();
688 | }
689 |
690 | function numberWithCommas(x) {
691 | return x.toString()
692 | .replace(/\B(?=(\d{3})+(?!\d))/g, ',');
693 | }
694 |
695 |
696 | function setValues(){
697 | if (tableau.connectionData !== undefined) {
698 | if (tableau.connectionData.length > 0) {
699 | try {
700 | console.log('Loading previously stored values');
701 | var json = JSON.parse(tableau.connectionData);
702 |
703 | // set all local vars
704 | schema = json.schema;
705 | server = json.server;
706 | port = json.port;
707 | db = json.db;
708 | protocol = json.protocol;
709 | username = tableau.password;
710 | queryType = json.queryType;
711 | interval_time = json.interval_time;
712 | interval_measure = json.interval_measure;
713 | interval_measure_string = json.interval_measure_string;
714 | aggregation = json.aggregation;
715 |
716 | // set all HTML elements
717 | $('#servername')
718 | .val(json.server);
719 | $('#servername')
720 | .attr('placeholder', json.server);
721 | $('#serverport')
722 | .val(json.port);
723 | $('.selectpicker')
724 | .html('' + json.db + ' ');
725 | $('.selectpicker')
726 | .selectpicker('refresh');
727 | $('#protocol_selector_button')
728 | .html(json.protocol + ' ');
729 | if (json.queryType === 'aggregation') {
730 | $('#aggregationGroup')
731 | .collapse('show');
732 | $('#customSqlGroup')
733 | .collapse('hide');
734 | $('#aggregation_selector_button')
735 | .html(json.aggregation + ' ');
736 | $('#interval_measure_button')
737 | .html(json.interval_measure_string + ' ');
738 | $('#interval_time')
739 | .val(json.interval_time);
740 | $('#querytype_aggregation')
741 | .click();
742 |
743 | } else if (json.queryType === 'all') {
744 | $('#customSqlGroup')
745 | .collapse('hide');
746 | $('#aggregationGroup')
747 | .collapse('hide');
748 | $('#querytype_all')
749 | .click();
750 |
751 | } else if (json.queryType === 'custom') {
752 | $('#customSqlGroup')
753 | .collapse('show');
754 | $('#customSql')
755 | .val(json.customSql);
756 | $('#aggregationGroup')
757 | .collapse('hide');
758 | $('#querytype_custom')
759 | .click();
760 | }
761 | if (json.useAuth === true) {
762 | useAuth = true;
763 | $('#authGroup')
764 | .collapse('show');
765 | $('#reloadWithAuth')
766 | .prop('hidden', 'hidden');
767 | $('#reloadWithoutAuth')
768 | .prop('hidden', '');
769 | $('#username')
770 | .val(tableau.username);
771 | $('#password')
772 | .val('');
773 | } else {
774 | $('#authGroup')
775 | .collapse('hide');
776 | $('#reloadWithoutAuth')
777 | .prop('hidden', 'hidden');
778 | $('#reloadWithAuth')
779 | .prop('hidden', '');
780 | }
781 | $('#getSchemaButton')
782 | .prop('disabled', false);
783 | } catch (err) {
784 | console.log('Error restoring previous values: ' + JSON.stringify(err));
785 | influx_alert('Error restoring previous values:', JSON.stringify(err));
786 | }
787 | }
788 | }
789 | else {
790 | $('#authGroup')
791 | .collapse('hide');
792 | $('#reloadWithoutAuth')
793 | .prop('hidden', 'hidden');
794 | $('#reloadWithAuth')
795 | .prop('hidden', '');
796 | $('#aggregationGroup')
797 | .collapse('hide');
798 | }
799 | }
800 |
801 | // Init function for connector, called during every phase
802 | myConnector.init = function (initCallback) {
803 | if (debug) console.log('Calling init function in phase: ' + tableau.phase);
804 | if (useAuth) {
805 | tableau.authType = tableau.authTypeEnum.basic;
806 | } else {
807 | tableau.authType = tableau.authTypeEnum.none;
808 | }
809 | setValues();
810 | initCallback();
811 | };
812 |
813 |
814 |
815 | myConnector.getSchema = function (schemaCallback) {
816 | console.log('Schema data...');
817 | console.log(tableau.connectionData);
818 | var json = JSON.parse(tableau.connectionData);
819 | console.log(json);
820 | schemaCallback(json.schema);
821 | };
822 |
823 | myConnector.getData = function (table, doneCallback) {
824 | console.log('getData Phase...')
825 | try {
826 | if (debug) {
827 | console.log(table);
828 | console.log('lastId (for incremental refresh): ' + table.incrementValue);
829 | console.log('Using Auth: ' + useAuth);
830 | }
831 | var lastId = table.incrementValue || -1;
832 |
833 | var tableData = [];
834 | var json = JSON.parse(tableau.connectionData);
835 | var queryString = json.protocol + json.server + ':' + json.port + '/query';
836 | var dataString = 'q=';
837 |
838 | if (json.queryType === 'custom') {
839 | console.log('table: ' + table);
840 | console.log('custom sql split stored: ' + JSON.stringify(json.customSqlSplit));
841 | console.log('custom[table]: ' + json.customSqlSplit[table.tableInfo.alias]);
842 | dataString += encodeURIComponent(json.customSqlSplit[table.tableInfo.alias]);
843 | dataString += '&db=' + json.db;
844 | dataString += '&chunked=true'; // add this to force chunking
845 |
846 | if (json.useAuth) {
847 | dataString += '&u=' + tableau.username + '&p=' + tableau.password;
848 | }
849 | if (debug) console.log('Fetch custom sql: '+ queryString+'?'+dataString);
850 | }
851 | else {
852 | dataString += 'select+';
853 | if (json.queryType === 'aggregation') {
854 | dataString += json.aggregation + '(*)';
855 | } else {
856 | dataString += '*';
857 | }
858 | dataString += '+from+%22' + influx_escape_char_for_URI(table.tableInfo.alias) + '%22';
859 | if (json.queryType === 'aggregation') {
860 | if (lastId !== -1) {
861 | // incremental refresh with aggregation
862 | dataString += '+where+time+%3E+\'' + lastId + '\'+group+by+*,time(' + json.interval_time + json.interval_measure + ')';
863 | } else {
864 | // full refresh with aggregation
865 | dataString += '+where+time+<+now()+group+by+*,time(' + json.interval_time + json.interval_measure + ')';
866 | }
867 | } else {
868 | if (lastId !== -1) {
869 | // incremental refresh with NO aggregation
870 | dataString += '+where+time+%3E+\'' + lastId + '\'';
871 | } else {
872 | // full refresh with NO aggregation
873 | }
874 | }
875 | //dataString += "+limit+6" // add this to limit the number of results coming back. Good for testing.
876 | dataString += '&db=' + json.db;
877 | dataString += '&chunked=true'; // add this to force chunking
878 | //dataString += "&chunk_size=20000" // add this to force a certain data set size
879 | //dataString += "&chunked=false"
880 |
881 | if (json.useAuth) {
882 | dataString += '&u=' + tableau.username + '&p=' + tableau.password;
883 | }
884 | if (debug) console.log('Fetch data query string: ' + queryString+'?'+dataString);
885 | }
886 |
887 |
888 | var jqxhr = $.ajax({
889 | dataType: 'text',
890 | url: queryString,
891 | data: dataString,
892 | async: false,
893 | })
894 | .done(function (resp) {
895 |
896 |
897 | // NOTE: This response needs to be of dataType:"text" as of v1.2.4.
898 | // See https://github.com/influxdata/influxdb/issues/8508
899 |
900 | var resultsArray = [];
901 | // if the response includes \n that means it has multiple result sets and we need to parse through them
902 | if (resp.indexOf('\n') !== -1) {
903 | resultsArray = resp.split('\n');
904 | // there is an extra \n at the end of the string, so remove the last element of the array
905 | resultsArray.splice(resultsArray.length - 1, 1);
906 | if (debug) console.log('Multiple result arrays ('+ resultsArray.length + ') found for ' + table.tableInfo.id);
907 |
908 | // for each result set, parse it into a JSON object
909 | for (var jp = 0; jp < resultsArray.length; jp++) {
910 | resultsArray[jp] = JSON.parse(resultsArray[jp]);
911 | }
912 | resp = resultsArray;
913 | } else {
914 | if (debug) console.log('Single result array returned for table ' + table.tableInfo.id);
915 | // put it into an array so we only need one set of code to traverse the objects.
916 | resultsArray = [JSON.parse(resp)];
917 | resp = resultsArray;
918 | }
919 |
920 | var values,
921 | columns,
922 | tags,
923 | val,
924 | val_len,
925 | col,
926 | col_len,
927 | response_array,
928 | series,
929 | series_cnt,
930 | row,
931 | total_rows;
932 |
933 | // Need this line for incremental refresh. If there are no additional results than this set will be undefined.
934 | if ((resp[0].results[0]).hasOwnProperty('series') === true) {
935 |
936 | if (!json.queryType) {
937 | values = resp[0].results[0].series[0].values;
938 | columns = resp[0].results[0].series[0].columns;
939 |
940 | if (debug) {
941 | console.log('columns: ' + JSON.stringify(columns));
942 | console.log('first row of values: ' + values[0]);
943 | console.log('Total # of rows for ${table.tableInfo.alias} is: ' + values.length);
944 | console.log('Using Aggregation Type: ' + json.queryType);
945 | }
946 |
947 | total_rows = 0;
948 | for (response_array = 0; response_array < resp.length; response_array++) {
949 | values = resp[response_array].results[0].series[0].values;
950 | columns = resp[response_array].results[0].series[0].columns;
951 | //Iterate over the result set
952 |
953 | for (val = 0, val_len = values.length; val < val_len; val++) {
954 | row = {};
955 | for (col = 0, col_len = columns.length; col < col_len; col++) {
956 | row[replaceSpecialChars_forTableau_ID(columns[col])] = values[val][col];
957 | }
958 | tableData.push(row);
959 |
960 | if (total_rows % 20000 === 0 && total_rows !== 0) {
961 | console.log('Getting data: ' + total_rows + ' rows');
962 | tableau.reportProgress('Getting data: ' + numberWithCommas(total_rows) + ' rows');
963 | table.appendRows(tableData);
964 | tableData = [];
965 |
966 | } else if (total_rows === 0) {
967 | console.log('Getting data: 0 rows - Starting Extract');
968 | tableau.reportProgress('Getting data: 0 rows - Starting Extract');
969 | }
970 | total_rows++;
971 | }
972 | }
973 | // for <20k rows or any stragglers
974 | table.appendRows(tableData);
975 | tableData = [];
976 | } else {
977 |
978 | series = resp[0].results[0].series;
979 |
980 | if (debug) {
981 | console.log('first row of tags: ' + series[0].tags);
982 | console.log('first row of columns: ' + series[0].columns);
983 | console.log('first row of values: ' + series[0].values);
984 | console.log('Total # of result sets (' + resp.length + ') series (' + series.length + ') & columns (' + series[0].columns.length + ') & values (1st row: ' + series[0].values.length + ') = total rows (est: ' + resp.length * series.length * series[0].columns.length * series[0].values.length + ' for ' + table.tableInfo.alias);
985 | }
986 |
987 | total_rows = 0;
988 | for (response_array = 0; response_array < resp.length; response_array++) {
989 | series = resp[response_array].results[0].series;
990 | values = resp[response_array].results[0].series[0].values;
991 | columns = resp[response_array].results[0].series[0].columns;
992 |
993 | //Iterate over the result set
994 | for (series_cnt = 0, series_len = series.length; series_cnt < series_len; series_cnt++) {
995 |
996 | values = series[series_cnt].values;
997 | for (val = 0, val_len = values.length; val < val_len; val++) {
998 | columns = series[series_cnt].columns;
999 | row = {};
1000 |
1001 | // add tags from each series
1002 | var obj = series[series_cnt].tags;
1003 | for (var key in obj) {
1004 | if (obj.hasOwnProperty(key)) {
1005 | row[replaceSpecialChars_forTableau_ID(key)] = obj[key];
1006 | }
1007 | }
1008 | for (col = 0, col_len = columns.length; col < col_len; col++) {
1009 | row[replaceSpecialChars_forTableau_ID(series[series_cnt].columns[col])] = series[series_cnt].values[val][col];
1010 | }
1011 | tableData.push(row);
1012 |
1013 | if (total_rows % 20000 === 0 && total_rows !== 0) {
1014 | console.log('Getting data: ' + total_rows + ' rows');
1015 | tableau.reportProgress('Getting data: ' + numberWithCommas(total_rows) + ' rows');
1016 | table.appendRows(tableData);
1017 | tableData = [];
1018 | } else if (total_rows === 0) {
1019 | console.log('Getting data: 0 rows - Starting Extract');
1020 | tableau.reportProgress('Getting data: 0 rows - Starting Extract');
1021 | }
1022 | total_rows++;
1023 | }
1024 | }
1025 | // for any stragglers or <20k rows
1026 | table.appendRows(tableData);
1027 | tableData = [];
1028 | }
1029 | }
1030 |
1031 | } else {
1032 | if (debug) console.log('No additional data in table ' + table.tableInfo.id + ' or in incremental refresh after ' + table.incrementValue);
1033 | }
1034 |
1035 |
1036 | })
1037 | .done(function () {
1038 | console.log('Finished getting table data for ' + table.tableInfo.id);
1039 | // table.appendRows(tableData);
1040 | doneCallback();
1041 | })
1042 | .fail(function (jqXHR, textStatus, errorThrown) {
1043 | console.log('INFLUX ERROR loading data! ' + textStatus + ' ' + errorThrown);
1044 | // console.log(JSON.stringify(errorThrown));
1045 | // console.log(errorThrown);
1046 | tableau.abortWithError(errorThrown);
1047 | doneCallback();
1048 | });
1049 | } catch
1050 | (err) {
1051 | console.log('INFLUX ERROR getdata phase!');
1052 | console.log(JSON.stringify(err));
1053 | console.log(err);
1054 | tableau.abortWithError(err);
1055 | doneCallback();
1056 | }
1057 | }
1058 | ;
1059 |
1060 |
1061 | $(document)
1062 | .ready(function () {
1063 |
1064 | $('#authGroup')
1065 | .on('show.bs.collapse', function () {
1066 | useAuth = true;
1067 | $('#reloadWithAuth')
1068 | .prop('hidden', 'hidden');
1069 | $('#reloadWithoutAuth')
1070 | .prop('hidden', '');
1071 |
1072 | });
1073 |
1074 | $('#authGroup')
1075 | .on('hide.bs.collapse', function () {
1076 | useAuth = false;
1077 | $('#reloadWithAuth')
1078 | .prop('hidden', '');
1079 | $('#reloadWithoutAuth')
1080 | .prop('hidden', 'hidden');
1081 | });
1082 |
1083 |
1084 | // set defaults
1085 |
1086 | $('#aggregationGroup')
1087 | .collapse('hide');
1088 | $('#customSqlGroup')
1089 | .collapse('hide');
1090 |
1091 |
1092 | // function will check to make sure correct group is showing at end of show transition
1093 | // eg, if the user hits tab quickly twice than two groups would be shown
1094 | $('#aggregationGroup, #customSqlGroup').on('shown.bs.collapse', function(){
1095 | if (queryType === 'custom' && $('#aggregationGroup').hasClass('show')){
1096 | $('#aggregationGroup')
1097 | .collapse('hide');
1098 | }
1099 | else if (queryType === 'aggregation' && $('#customSqlGroup').hasClass('show')){
1100 | $('#customSqlGroup')
1101 | .collapse('hide');
1102 | }
1103 | else if (queryType === 'all'){
1104 | $('#aggregationGroup')
1105 | .collapse('hide');
1106 | $('#customSqlGroup')
1107 | .collapse('hide');
1108 | }
1109 | })
1110 |
1111 |
1112 | // function will check to make sure correct group is showing at end of hide transition
1113 | // eg, if the user hits left/right arrow quickly (from custom or aggregation) than the target group would not be shown
1114 | $('#aggregationGroup, #customSqlGroup').on('hidden.bs.collapse', function(){
1115 | if (queryType === 'aggregation' && !$('#aggregationGroup').hasClass('show')){
1116 | $('#aggregationGroup')
1117 | .collapse('show');
1118 | }
1119 | else if (queryType === 'custom' && !$('#customSqlGroup').hasClass('show')) {
1120 | $('#customSqlGroup')
1121 | .collapse('show');
1122 | }
1123 | })
1124 |
1125 |
1126 | $('#querytype')
1127 | .on('change', function () {
1128 | // $(this)
1129 | // .prop('checked', true);
1130 | if ($(this)
1131 | .find(':checked')
1132 | .data('val') === 'aggregation') {
1133 | queryType = 'aggregation';
1134 | $('#aggregationGroup')
1135 | .collapse('show');
1136 | $('#customSqlGroup')
1137 | .collapse('hide');
1138 | }
1139 | if ($(this)
1140 | .find(':checked')
1141 | .data('val') === 'all') {
1142 | queryType = 'all';
1143 | $('#aggregationGroup')
1144 | .collapse('hide');
1145 | $('#customSqlGroup')
1146 | .collapse('hide');
1147 | }
1148 | else if ($(this)
1149 | .find(':checked')
1150 | .data('val') === 'custom') {
1151 | queryType = 'custom';
1152 | $('#aggregationGroup')
1153 | .collapse('hide');
1154 | $('#customSqlGroup')
1155 | .collapse('show');
1156 | }
1157 | resetSchema();
1158 | });
1159 |
1160 | getDBs();
1161 | tableau.registerConnector(myConnector);
1162 |
1163 | // fill in previous values, if present
1164 |
1165 | // following are for testing; uncomment to see behavior in Simulator
1166 | /*tableau.username = 'admin'
1167 | tableau.connectionData = {
1168 | "db": "pool",
1169 | "server": "localhost",
1170 | "aggregation": "count",
1171 | "interval_time": "110",
1172 | "interval_measure": "h",
1173 | "interval_measure_string": "hours",
1174 | "protocol": "http://",
1175 | "port": 8086,
1176 | "useAuth": true,
1177 | "queryType": 'all',
1178 | "schema": [{
1179 | "id": "chlorinator",
1180 | "incrementColumnId": "time",
1181 | "columns": [{
1182 | "id": "time",
1183 | "dataType": "datetime"
1184 | }, {
1185 | "id": "name",
1186 | "dataType": "string"
1187 | }, {
1188 | "id": "status",
1189 | "dataType": "string"
1190 | }, {
1191 | "id": "superChlorinate",
1192 | "dataType": "string"
1193 | }, {
1194 | "id": "currentOutput",
1195 | "dataType": "float"
1196 | }, {
1197 | "id": "outputPoolPercent",
1198 | "dataType": "float"
1199 | }, {
1200 | "id": "outputSpaPercent",
1201 | "dataType": "float"
1202 | }, {
1203 | "id": "saltPPM",
1204 | "dataType": "float"
1205 | }]
1206 | }, {
1207 | "id": "circuits",
1208 | "incrementColumnId": "time",
1209 | "columns": [{
1210 | "id": "time",
1211 | "dataType": "datetime"
1212 | }, {
1213 | "id": "circuitFunction",
1214 | "dataType": "string"
1215 | }, {
1216 | "id": "colorStr",
1217 | "dataType": "string"
1218 | }, {
1219 | "id": "freeze",
1220 | "dataType": "string"
1221 | }, {
1222 | "id": "friendlyName",
1223 | "dataType": "string"
1224 | }, {
1225 | "id": "lightgroup",
1226 | "dataType": "string"
1227 | }, {
1228 | "id": "name",
1229 | "dataType": "string"
1230 | }, {
1231 | "id": "number",
1232 | "dataType": "string"
1233 | }, {
1234 | "id": "numberStr",
1235 | "dataType": "string"
1236 | }, {
1237 | "id": "freeze",
1238 | "dataType": "float"
1239 | }, {
1240 | "id": "status",
1241 | "dataType": "float"
1242 | }]
1243 | }, {
1244 | "id": "pumps",
1245 | "incrementColumnId": "time",
1246 | "columns": [{
1247 | "id": "time",
1248 | "dataType": "datetime"
1249 | }, {
1250 | "id": "gpm",
1251 | "dataType": "float"
1252 | }, {
1253 | "id": "rpm",
1254 | "dataType": "float"
1255 | }, {
1256 | "id": "watts",
1257 | "dataType": "float"
1258 | }, {
1259 | "id": "mode",
1260 | "dataType": "string"
1261 | }, {
1262 | "id": "power",
1263 | "dataType": "string"
1264 | }, {
1265 | "id": "pump",
1266 | "dataType": "string"
1267 | }, {
1268 | "id": "remotecontrol",
1269 | "dataType": "string"
1270 | }, {
1271 | "id": "run",
1272 | "dataType": "string"
1273 | }, {
1274 | "id": "type",
1275 | "dataType": "string"
1276 | }]
1277 | }, {
1278 | "id": "temperatures",
1279 | "incrementColumnId": "time",
1280 | "columns": [{
1281 | "id": "time",
1282 | "dataType": "datetime"
1283 | }, {
1284 | "id": "freeze",
1285 | "dataType": "string"
1286 | }, {
1287 | "id": "poolHeatMode",
1288 | "dataType": "string"
1289 | }, {
1290 | "id": "poolHeatModeStr",
1291 | "dataType": "string"
1292 | }, {
1293 | "id": "spaHeadModeStr",
1294 | "dataType": "string"
1295 | }, {
1296 | "id": "spaHeatMode",
1297 | "dataType": "string"
1298 | }, {
1299 | "id": "spaHeatModeStr",
1300 | "dataType": "string"
1301 | }, {
1302 | "id": "airTemp",
1303 | "dataType": "float"
1304 | }, {
1305 | "id": "poolSetPoint",
1306 | "dataType": "float"
1307 | }, {
1308 | "id": "poolTemp",
1309 | "dataType": "float"
1310 | }, {
1311 | "id": "solarTemp",
1312 | "dataType": "float"
1313 | }, {
1314 | "id": "spaSetPoint",
1315 | "dataType": "float"
1316 | }, {
1317 | "id": "spaTemp",
1318 | "dataType": "float"
1319 | }]
1320 | }]
1321 | };
1322 | tableau.connectionData = JSON.stringify(tableau.connectionData);
1323 | influx_alert("connectionData", tableau.connectionData)
1324 |
1325 | //console.log("tableau.connectionData.length: %s", tableau.connectionData.length)
1326 | */
1327 |
1328 | });
1329 |
1330 |
1331 | })
1332 | ();
1333 |
--------------------------------------------------------------------------------