| 31 | class UiWebsocketPlugin(object): |
| 32 | @flag.admin |
| 33 | def actionChartDbQuery(self, to, query, params=None): |
| 34 | if config.debug or config.verbose: |
| 35 | s = time.time() |
| 36 | rows = [] |
| 37 | try: |
| 38 | if not query.strip().upper().startswith("SELECT"): |
| 39 | raise Exception("Only SELECT query supported") |
| 40 | res = db.execute(query, params) |
| 41 | except Exception as err: # Response the error to client |
| 42 | self.log.error("ChartDbQuery error: %s" % err) |
| 43 | return {"error": str(err)} |
| 44 | # Convert result to dict |
| 45 | for row in res: |
| 46 | rows.append(dict(row)) |
| 47 | if config.verbose and time.time() - s > 0.1: # Log slow query |
| 48 | self.log.debug("Slow query: %s (%.3fs)" % (query, time.time() - s)) |
| 49 | return rows |
| 50 | |
| 51 | @flag.admin |
| 52 | def actionChartGetPeerLocations(self, to): |