__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)
Example #2
0
    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)

        handler.postEvent(event, dedupe=True, batch=True)

        # Need to revser the order of incoming events as news are on top but we
Example #3
0
        '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:
        app.log.fatal('Unhandled exception: %s' % e)
        app.close(1)
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',
                                                         'ubnt_mfi_user'),
                              'password': app.config.get('ubnt_mfi',
                                                         'ubnt_mfi_pass'),