def on_open(self):
     try:
         token = verify_message(self.ws.handler.active_client.ws, ['inoffice', 'analytics'])
     except SocketException as e:
         logging.error(e)
         self.ws.handler.active_client.ws.send(json.dumps({'event':'invalid_access',  'data':e.json()}))
         return
     self.INFLUX = db.init_influxdb()
     self.MQ = db.init_mq()
     current = self.ws.handler.active_client
     current.token = token
     self.init_consumers()
Beispiel #2
0
 def on_open(self):
     try:
         token = verify_message(self.ws.handler.active_client.ws,
                                ['inoffice', 'analytics'])
     except SocketException as e:
         logging.error(e)
         self.ws.handler.active_client.ws.send(
             json.dumps({
                 'event': 'invalid_access',
                 'data': e.json()
             }))
         return
     self.INFLUX = db.init_influxdb()
     self.MQ = db.init_mq()
     current = self.ws.handler.active_client
     current.token = token
     self.init_consumers()
Beispiel #3
0
 def __init__(self, client, event, **kwargs):
     super(Event, self).__init__()
     INFLUX = db.init_influxdb()
     columns = ["type"]
     values = [event]
     for k, v in kwargs.iteritems():
         columns.append(k)
         values.append(v)
     data = [
         dict(name="events.{}.{}".format(client._id, event),
              columns=columns,
              points=[values])
     ]
     logging.info("Writing: {}".format(data))
     try:
         res = INFLUX.write_points(data)
         logging.info(res)
     except Exception as e:
         logging.warning(e)
 def __init__(self, client, event, **kwargs):
     super(Event, self).__init__()
     INFLUX = db.init_influxdb()
     columns = ["type"]
     values = [event]
     for k,v in kwargs.iteritems():
         columns.append(k)
         values.append(v)
     data = [
         dict(
             name = "events.{}.{}".format(client._id, event),
             columns = columns,
             points = [values]
         )
     ]
     logging.info("Writing: {}".format(data))
     try:
         res = INFLUX.write_points(data)
         logging.info(res)
     except Exception as e:
         logging.warning(e)
Beispiel #5
0
from celery import Celery
from celery import bootsteps
from kombu import Consumer
from lablog import config
from lablog import db
from lablog import messages
from lablog.models.client import Admin
from lablog.models.location import Location
from lablog.hooks import post_slack
from lablog.triggers import Trigger
import logging
import time

INFLUX = db.init_influxdb()
MQ = db.init_mq()
MQTT = db.init_mqtt()

app = Celery(__name__)
app.config_from_object('lablog.celeryconfig')

class TriggerConsumer(bootsteps.ConsumerStep):

    def __init__(self, *args, **kwargs):
        self.triggers = [a for a in Trigger.find()]
        super(TriggerConsumer, self).__init__(*args, **kwargs)

    def handle_trigger(self, body, msg):
        try:
            for t in self.triggers:
                if t.key == body['measurement']:
                    val = t._run(body)
Beispiel #6
0
from celery import Celery
from celery import bootsteps
from kombu import Consumer
from lablog import config
from lablog import db
from lablog import messages
from lablog.models.client import Admin
from lablog.models.location import Location
from lablog.hooks import post_slack
from lablog.triggers import Trigger
import logging

INFLUX = db.init_influxdb()
MQ = db.init_mq()

app = Celery(__name__)
app.config_from_object('lablog.celeryconfig')

class TriggerConsumer(bootsteps.ConsumerStep):

    def __init__(self, *args, **kwargs):
        self.triggers = [a for a in Trigger.find()]
        super(TriggerConsumer, self).__init__(*args, **kwargs)

    def handle_trigger(self, body, msg):
        try:
            for t in self.triggers:
                if t.key == body['measurement']:
                    val = t._run(body)
        except Exception as e:
            logging.exception(e)
Beispiel #7
0
 def init_dbs(self):
     g.ES = db.init_elasticsearch()
     g.INFLUX = db.init_influxdb()
     g.MONGO = db.init_mongodb()
     g.MQ = db.init_mq()
     humongolus.settings(logging, g.MONGO)
Beispiel #8
0
 def configure_dbs(self):
     es = db.init_elasticsearch()
     db.create_index(es)
     influx = db.init_influxdb()
     db.create_shards(influx)