コード例 #1
0
defaults = init_defaults('eagle', 'eagle')
defaults['eagle']['poll_interval'] = 5.0
defaults['eagle']['voltage'] = 240

units = {
    'W':    1,
    'kW':   1000,
    'MW':   1000*1000,
    'Wh':   1,
    'kWh':  1000,
    'MWh':  1000*1000,
}


with shApp('eagle', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    command = '<LocalCommand>\n\
                    <Name>get_device_list</Name>\n\
               </LocalCommand>'

    r = handler.post(app.config.get('eagle', 'eagle_addr') +
                     '/cgi-bin/cgi_manager', data=command)
    app.log.debug('Fetch data: %s' % r.text)

    device = json.loads(r.text)
    device_macid = device['device_mac_id[0]']
コード例 #2
0
            'certification_body': protect.certification_body,
            'creation_time': epoch2date(protect.creation_time/1000),
            'home_alarm_link_type': protect.home_alarm_link_type,
            'latest_manual_test_end_utc_secs': protect.latest_manual_test_end_utc_secs,  # noqa
            'latest_manual_test_start_utc_secs': protect.latest_manual_test_start_utc_secs,  # noqa
            'replace_by_date_utc_secs': epoch2date(protect.replace_by_date_utc_secs),  # noqa
            'co_sequence_number': protect.co_sequence_number,
            'smoke_sequence_number': protect.smoke_sequence_number,
            'wired_or_battery': protect.wired_or_battery
            }
    }]

    return event


with shApp('nest', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    nest = Nest(app.config.get('nest', 'nest_user'),
                app.config.get('nest', 'nest_pass'),
                access_token_cache_file=os.path.expanduser(
                    app.config.get('nest', 'nest_cache')),
                cache_ttl=9)

    while True:
        retries = 0

        # app.log.info(json.dumps(nest._status, sort_keys=True))
        # exit(1)
コード例 #3
0
    elif module['type'] == 'NAModule3':  # Rain
        fields['rain'] = dashboard['Rain']
        fields['sum_rain_1'] = dashboard['sum_rain_1']
        fields['sum_rain_24'] = dashboard['sum_rain_24']
        fields['raini'] = mmtoin(dashboard['Rain'])
        fields['sum_rain_1i'] = mmtoin(dashboard['sum_rain_1'])
        fields['sum_rain_24i'] = mmtoin(dashboard['sum_rain_24'])

    if module['type'] == 'NAModule4':  # Additional for Indoor
        # tags['temp_trend'] = dashboard['temp_trend']
        fields['co2'] = int(dashboard['CO2'])

    return event


with shApp('netatmo', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    # Start the Oauth2 dance...
    oauth2Params = {
        'grant_type': 'password',
        'client_id': app.config.get('netatmo', 'netatmo_client_id'),
        'client_secret': app.config.get('netatmo', 'netatmo_client_secret'),
        'username': app.config.get('netatmo', 'netatmo_user'),
        'password': app.config.get('netatmo', 'netatmo_pass'),
        'scope': 'read_station'
        }

    r = handler.post(_OAUTH2_REQ, data=oauth2Params)
コード例 #4
0
from cement.utils.misc import init_defaults

defaults = init_defaults('eagle', 'eagle')
defaults['eagle']['poll_interval'] = 5.0
defaults['eagle']['voltage'] = 240

units = {
    'W': 1,
    'kW': 1000,
    'MW': 1000 * 1000,
    'Wh': 1,
    'kWh': 1000,
    'MWh': 1000 * 1000,
}

with shApp('eagle', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    command = '<LocalCommand>\n\
                    <Name>get_device_list</Name>\n\
               </LocalCommand>'

    r = handler.post(app.config.get('eagle', 'eagle_addr') +
                     '/cgi-bin/cgi_manager',
                     data=command)
    app.log.debug('Fetch data: %s' % r.text)

    device = json.loads(r.text)
    device_macid = device['device_mac_id[0]']
コード例 #5
0
    },
    '1.3.6.1.4.1.318.1.1.1.4.2.4.0': {
        'name': 'outcurrent',
        'desc': 'Output Current [A]'
    },
    '1.3.6.1.4.1.318.1.1.1.7.2.3.0': {
        'name': 'lasttestres',
        'desc': 'Last Test Result'
    },
    '1.3.6.1.4.1.318.1.1.1.7.2.4.0': {
        'name': 'lasttestdate',
        'desc': 'Last Test Date'
    },
}

with shApp('apcups', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    try:
        cmdGen = cmdgen.CommandGenerator()

        errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
            cmdgen.CommunityData('public'),
            cmdgen.UdpTransportTarget((app.config.get('apcups',
                                                      'apcups_addr'), 161)),
            cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
            lookupNames=True,
            lookupValues=True)
    except Exception as e:
コード例 #6
0
        rekeyed_quote = dict([(CODES_GOOGLE.get(key, key), value)
                             for key, value in quote.items()])

        tags = extract_tags(rekeyed_quote, ['id', 'exchange', 'symbol'])

        event = [{
            'measurement': series_name,
            'tags': tags,
            'fields': rekeyed_quote
            }]

        app.log.debug('Event data: %s' % event)

        handler.postEvent(event, batch=True)

with shApp('finance', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        finance_path = app.config.get('finance', 'finance_provider_addr') +\
            ":" + app.config.get('finance', 'finance_provider_port') +\
            app.config.get('finance', 'finance_provider_path')
        app.log.debug("Finance Path: %s", finance_path)

        quotes_feed(app, handler, finance_path, 'finance.indexes',
                    app.config.get('finance', 'finance_index_list'))

        quotes_feed(app, handler, finance_path, 'finance.stockquotes',
                    app.config.get('finance', 'finance_stock_list'))
コード例 #7
0
    if feature['properties']['rms'] is not None:
        fields['rms'] = float(feature['properties']['rms'])

    if feature['properties']['mag'] is not None:
        fields['mag'] = float(feature['properties']['mag'])

    if feature['properties']['cdi'] is not None:
        fields['cdi'] = float(feature['properties']['cdi'])

    if feature['properties']['mag'] is not None:
        fields['mag'] = float(feature['properties']['mag'])

    return event


with shApp('usgs_quake', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app, dedupe=True)

    path = app.config.get('usgs_quake', 'path')

    while True:
        # Get all earthquakes of the past hour
        r = handler.get(app.config.get('usgs_quake', 'addr') + path)
        data = json.loads(r.text)
        # app.log.debug('Raw data: %s' % r.text)

        event = mapMetadata(data['metadata'])
        app.log.debug('Event data: %s' % event)
コード例 #8
0
from common.sheventhandler import shEventHandler

import json
import hashlib

units = {"W": 1, "kW": 1000, "MW": 1000 * 1000, "Wh": 1, "kWh": 1000, "MWh": 1000 * 1000}

rpcrequest = {"version": "1.0", "proc": "GetPlantOverview", "id": "1", "format": "JSON"}

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults("sma_webbox", "sma_webbox")
defaults["sma_webbox"]["poll_interval"] = 30.0

with shApp("sma_webbox", config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        # First check if there is a new password in the config
        try:
            passwd = app.config.get("sma_webbox", "sma_webbox_pass")
        except:
            passwd = None
            pass

        if passwd is not None:
            rpcrequest["passwd"] = hashlib.md5(passwd.encode("utf-8")).hexdigest()
        else:
コード例 #9
0
    elif module['type'] == 'NAModule3':  # Rain
        fields['rain'] = dashboard['Rain']
        fields['sum_rain_1'] = dashboard['sum_rain_1']
        fields['sum_rain_24'] = dashboard['sum_rain_24']
        fields['raini'] = mmtoin(dashboard['Rain'])
        fields['sum_rain_1i'] = mmtoin(dashboard['sum_rain_1'])
        fields['sum_rain_24i'] = mmtoin(dashboard['sum_rain_24'])

    if module['type'] == 'NAModule4':  # Additional for Indoor
        # tags['temp_trend'] = dashboard['temp_trend']
        fields['co2'] = int(dashboard['CO2'])

    return event


with shApp('netatmo', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    # Start the Oauth2 dance...
    oauth2Params = {
        'grant_type': 'password',
        'client_id': app.config.get('netatmo', 'netatmo_client_id'),
        'client_secret': app.config.get('netatmo', 'netatmo_client_secret'),
        'username': app.config.get('netatmo', 'netatmo_user'),
        'password': app.config.get('netatmo', 'netatmo_pass'),
        'scope': 'read_station'
    }

    r = handler.post(_OAUTH2_REQ, data=oauth2Params)
コード例 #10
0
    sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
except:
    exit(1)

# Sentient Home Application
from common.shapp import shApp
from common.shutil import xml_to_dict, extract_tags
from common.sheventhandler import shEventHandler

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('autelis', 'autelis')
defaults['autelis']['poll_interval'] = 10.0

with shApp('autelis', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        try:
            r = handler.get(app.config.get('autelis', 'autelis_addr') +
                            '/status.xml',
                            auth=(app.config.get('autelis', 'autelis_user'),
                                  app.config.get('autelis', 'autelis_pass')))
            # Data Structure Documentation:
            # http://www.autelis.com/wiki/index.php?
            # title=Pool_Control_(PI)_HTTP_Command_Reference
        except Exception as e:
            # If event handler was unsuccessful retrying stop
コード例 #11
0
    fields = event[0]['fields']

    for key in data.keys():
        if key == 'stats':
            for stat in data[key].keys():
                try:
                    fields[stat] = float(data[key][stat])
                except ValueError:
                    fields[stat] = data[key][stat]
        else:
            fields[key] = data[key]

    return event


with shApp('ubnt_toughswitch', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app, dedupe=True)

    retries = 0
    sessions = []

    addresses = app.config.get('ubnt_toughswitch', 'addr').split(', ')
    switch_port = app.config.get('ubnt_toughswitch', 'port')
    switch_user = app.config.get('ubnt_toughswitch', 'user')
    passwords = app.config.get('ubnt_toughswitch', 'pass').split(', ')
    switch_verify_ssl = app.config.get('ubnt_toughswitch', 'verify_ssl')

    # Setup sessions for each individual switch
    for i in range(len(addresses)):
コード例 #12
0
from common.shapp import shApp
from common.shutil import flatten_dict, extract_tags
from common.sheventhandler import shEventHandler

import time

# Add path to submodule dependencies.ISYlib-python
try:
    sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
                    '/../dependencies/ISYlib-python')
    from ISY.IsyClass import Isy
    from ISY.IsyEvent import ISYEvent
except:
    exit(1)

app = shApp('isy')
app.setup()
app.run()

handler = shEventHandler(app)

isy_addr = app.config.get('isy', 'isy_addr')
isy_user = app.config.get('isy', 'isy_user')
isy_pass = app.config.get('isy', 'isy_pass')

app.log.debug('Connecting to ISY controller @%s' % isy_addr, __name__)

try:
    isy = Isy(addr=isy_addr, userl=isy_user, userp=isy_pass)
except Exception as e:
    app.log.error('Unable to connect to ISY controller @%s' % isy_addr,
コード例 #13
0
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

# Sentient Home Application
from common.shapp import shApp
from common.sheventhandler import shEventHandler

import json

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('usgs_quake', 'usgs_quake')
defaults['usgs_quake']['poll_interval'] = 10.0

with shApp('usgs_quake', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app, dedupe=True)

    # Initial poll - most likely a day if the increments are hourly data
    # We do this to catchup on events in case the feed was down for some time
    path = app.config.get('usgs_quake', 'usgs_quake_init_path')

    while True:
        # Get all earthquakes of the past hour
        r = handler.get(app.config.get('usgs_quake', 'usgs_quake_addr') +
                        path)
        data = json.loads(r.text)

        m = data['metadata']
コード例 #14
0
ファイル: grafana.py プロジェクト: SentientHome/SentientHome
# Sentient Home Application
from common.shapp import shApp
from common.sheventhandler import shEventHandler

import json

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('grafana', 'grafana')
defaults['grafana']['addr'] = 'http://192.168.99.100:3000'
defaults['grafana']['user'] = '******'
defaults['grafana']['pass'] = '******'
defaults['grafana']['debug'] = 1

with shApp('grafana', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    try:
        # Get list of all Grafana dashboards
        r = handler.get(app.config.get('grafana', 'addr') +
                        '/api/search',
                        auth=(app.config.get('grafana', 'user'),
                              app.config.get('grafana', 'pass')))
    except Exception as e:
        # If event handler was unsuccessful retrying stop
        app.log.fatal(e)
        app.close(1)
コード例 #15
0
    sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
except:
    exit(1)

# Sentient Home Application
from common.shapp import shApp
from common.shutil import xml_to_dict
from common.sheventhandler import shEventHandler

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('zillow', 'zillow')
defaults['zillow']['poll_interval'] = 3600.0

with shApp('zillow', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        r = handler.get(app.config.get('zillow', 'zillow_addr') + ":" +
                        app.config.get('zillow', 'zillow_port') +
                        app.config.get('zillow', 'zillow_path') + "?zws-id=" +
                        app.config.get('zillow', 'zillow_zws_id') + "&zpid=" +
                        app.config.get('zillow', 'zillow_zpid'))
        # app.log.debug('Fetch data: %s' % r.text)

        data = xml_to_dict(r.text)
        app.log.debug('Raw data: %s' % data)
コード例 #16
0
    sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
except:
    exit(1)

# Sentient Home Application
from common.shapp import shApp
from common.shutil import xml_to_dict
from common.sheventhandler import shEventHandler

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('zillow', 'zillow')
defaults['zillow']['poll_interval'] = 3600.0

with shApp('zillow', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        r = handler.get(
            app.config.get('zillow', 'zillow_addr') + ":" +
            app.config.get('zillow', 'zillow_port') +
            app.config.get('zillow', 'zillow_path') + "?zws-id=" +
            app.config.get('zillow', 'zillow_zws_id') + "&zpid=" +
            app.config.get('zillow', 'zillow_zpid'))
        # app.log.debug('Fetch data: %s' % r.text)

        data = xml_to_dict(r.text)
        app.log.debug('Raw data: %s' % data)
コード例 #17
0
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

# Sentient Home Application
from common.shapp import shApp
from common.shutil import xml_to_dict
from common.sheventhandler import shEventHandler

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('autelis', 'autelis')
defaults['autelis']['poll_interval'] = 10.0

with shApp('autelis', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        try:
            r = handler.get(app.config.get('autelis', 'autelis_addr') +
                            '/status.xml',
                            auth=(app.config.get('autelis', 'autelis_user'),
                                  app.config.get('autelis', 'autelis_pass')))
            # Data Structure Documentation:
            # http://www.autelis.com/wiki/index.php?
            # title=Pool_Control_(PI)_HTTP_Command_Reference
        except Exception as e:
            # If event handler was unsuccessful retrying stop
コード例 #18
0
# Sentient Home Application
from common.shapp import shApp
from common.sheventhandler import shEventHandler

import json

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('grafana', 'grafana')
defaults['grafana']['addr'] = 'http://192.168.99.100:3000'
defaults['grafana']['user'] = '******'
defaults['grafana']['pass'] = '******'
defaults['grafana']['debug'] = 1

with shApp('grafana', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    try:
        # Get list of all Grafana dashboards
        r = handler.get(app.config.get('grafana', 'addr') + '/api/search',
                        auth=(app.config.get('grafana', 'user'),
                              app.config.get('grafana', 'pass')))
    except Exception as e:
        # If event handler was unsuccessful retrying stop
        app.log.fatal(e)
        app.close(1)

    app.log.debug('response: %s' % r.text)
コード例 #19
0
# Sentient Home Application
from common.shapp import shApp
from common.sheventhandler import shEventHandler
from common.shutil import CtoF

import requests
import json

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('ubnt_mfi', 'ubnt_mfi')
defaults['ubnt_mfi']['poll_interval'] = 5.0

with shApp('ubnt_mfi', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app, dedupe=True)

    retries = 0

    # Setup session and login
    session = requests.session()

    while True:
        try:
            r = session.post(app.config.get('ubnt_mfi', 'ubnt_mfi_addr') + ':' +
                             app.config.get('ubnt_mfi', 'ubnt_mfi_port') +
                             '/login',
                             {'username': app.config.get('ubnt_mfi',
コード例 #20
0
            fields[key] = epoch2date(sensor[key] / 1000)
        else:
            try:
                fields[key] = float(sensor[key])

                if key == 'temperature':
                    fields['temperatureF'] = CtoF(sensor[key])
            except ValueError:
                fields[key] = sensor[key]
            except TypeError:
                fields[key] = None

    return event


with shApp('ubnt_mfi', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app, dedupe=True)

    retries = 0

    # Setup session and login
    session = requests.session()

    while True:
        try:
            r = session.post(
                app.config.get('ubnt_mfi', 'ubnt_mfi_addr') + ':' +
                app.config.get('ubnt_mfi', 'ubnt_mfi_port') + '/login', {
                    'username': app.config.get('ubnt_mfi', 'ubnt_mfi_user'),
コード例 #21
0
# Sentient Home Application
from common.shapp import shApp
from common.sheventhandler import shEventHandler

import time

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('shTracer', 'shTracer')
defaults['shTracer']['poll_interval'] = 10.0

# Simple tracer that 'fires' events on a predefined interval

with shApp('shTracer', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)
    # Simple Tracer counter
    count = 0

    while True:
        count += 1

        event = [{
            'measurement': 'tracer',
            'fields': {
                'tracer_time': time.time(),
                'tracer_count': count
            }
コード例 #22
0
                              for key, value in quote.items()])

        tags = extract_tags(rekeyed_quote, ['id', 'exchange', 'symbol'])

        event = [{
            'measurement': series_name,
            'tags': tags,
            'fields': rekeyed_quote
        }]

        app.log.debug('Event data: %s' % event)

        handler.postEvent(event, batch=True)


with shApp('finance', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        finance_path = app.config.get('finance', 'finance_provider_addr') +\
            ":" + app.config.get('finance', 'finance_provider_port') +\
            app.config.get('finance', 'finance_provider_path')
        app.log.debug("Finance Path: %s", finance_path)

        quotes_feed(app, handler, finance_path, 'finance.indexes',
                    app.config.get('finance', 'finance_index_list'))

        quotes_feed(app, handler, finance_path, 'finance.stockquotes',
                    app.config.get('finance', 'finance_stock_list'))
コード例 #23
0
# Make sure we have access to SentientHome commons
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

# Sentient Home Application
from common.shapp import shApp
from common.shutil import flatten_dict
from common.sheventhandler import shEventHandler

# Add path to submodule dependencies.ISYlib-python
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
                '/../dependencies/ISYlib-python')
from ISY.IsyEvent import ISYEvent

app = shApp('isy')
app.setup()
app.run()

handler = shEventHandler(app)


# Realtime event feeder
def eventFeed(*arg):

    # Flatten dict and turn embedded structure into dot notation
    data = flatten_dict(arg[0])

    event = [{
        'name': 'isy',
        'columns': list(data.keys()),
コード例 #24
0
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

# Sentient Home Application
from common.shapp import shApp
from common.sheventhandler import shEventHandler
from common.shutil import CtoF, m2toft2, boolify2int

from nest import Nest

# Default settings
from cement.utils.misc import init_defaults

defaults = init_defaults('nest', 'nest')
defaults['nest']['poll_interval'] = 60.0

with shApp('nest', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app, dedupe=True)

    nest = Nest(app.config.get('nest', 'nest_user'),
                app.config.get('nest', 'nest_pass'),
                access_token_cache_file=os.path.expanduser(
                    app.config.get('nest', 'nest_cache')))

    while True:
        retries = 0

        while True:
            try:
                for structure in nest.structures:
コード例 #25
0
__author__ = 'Oliver Ratzesberger <https://github.com/fxstein>'
__copyright__ = 'Copyright (C) 2015 Oliver Ratzesberger'
__license__ = 'Apache License, Version 2.0'

# Make sure we have access to SentientHome commons
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

# Sentient Home Application
from common.shapp import shApp
from common.sheventhandler import shEventHandler

# Simple loadtest that 'fires' events as fast as possible

with shApp('loadtest') as app:
    app.run()
    handler = shEventHandler(app)

    count = 0

    while True:
        count += 1

        event = [{
            'name': 'loadtest',    # Time Series Name
            'columns': ['count'],  # Keys
            'points': [[count]]    # Data points
        }]

        handler.postEvent(event)
コード例 #26
0
                    if channel['unit'] == 'degC':
                        fields[names[channel['name']] + 'f'] =\
                            CtoF(fields[names[channel['name']]])
                except ValueError:
                    # Skip none numeric portions of the result
                    pass

        # At night the sma webbox gives us all empty fields
        # We need at least on valid field to post the event
        if at_least_one is True:
            events.append(event)

    return events


with shApp('sma_webbox', config_defaults=defaults) as app:
    app.run()

    handler = shEventHandler(app)

    while True:
        # First check if there is a new password in the config
        try:
            passwd = app.config.get('sma_webbox', 'sma_webbox_pass')
        except:
            passwd = None
            pass

        if passwd is not None:
            rpcRequest['passwd'] = hashlib.md5(
                passwd.encode('utf-8')).hexdigest()