123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/usr/bin/python
- from __future__ import print_function
- from copy import deepcopy
- import daemon
- import logging
- import sys
- import time
- from ffstatus import *
- INTERVAL = 15
- LOGFILE = '/var/log/ffstatus.log'
- DUMMY_MODE = 1
- logger = logging.getLogger()
- logger.setLevel(logging.DEBUG)
- fh = logging.FileHandler(LOGFILE)
- fh.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S'))
- logger.addHandler(fh)
- logger.info('Starting up')
- a = AlfredParser()
- b = BatmanParser()
- d = DashingClient('dashing.krombel.de', 'TODO')
- g = GraphitePush('fdca:ffee:ff12:a254::da7a', 2003)
- data = { }
- if DUMMY_MODE:
- import os
- mydir = os.path.realpath(os.path.dirname(__file__))
- a.alfred_json = os.path.join(mydir, 'alfred-json')
- print('DUMMY.a =', a.alfred_json)
- b.batadv_vis = os.path.join(mydir, 'batadv_vis')
- print('DUMMY.b =', b.batadv_vis)
- g.dont_send = True
- for i in [ ('AlfredParser', a), ('BatmanParser', b) ]:
- try:
- i[1].sanitycheck()
- except Exception as err:
- logger.critical(i[0] + '.sanitycheck() failed: ' + str(err))
- print('FAILED SANITY CHECK: ' + str(err))
- sys.exit(1)
- daemon_context = daemon.DaemonContext(
- files_preserve = [ fh.stream ],
- )
- with daemon_context:
- while True:
- try:
- ts = int(time.time())
- logger.debug('Step 1/3: Fetching data ...')
- alfreddata = a.fetch()
- batmandata = b.fetch()
- newdata = dict_merge(alfreddata, batmandata)
- logger.info('Fetched data: {0} ALFRED with {1} BATMAN makes {2} total'.format(len(alfreddata), len(batmandata), len(newdata)))
- logger.debug('Step 2/3: Pushing update data ...')
- graphitedata = g.push(newdata, ts=ts)
- d.push(newdata)
- logger.info('Sent ' + str(graphitedata.count('\n')+1) + ' lines to Graphite.')
- logger.debug('Step 3/3: Merging current data ...')
- data = dict_merge(data, newdata)
- logger.info('I have data for ' + str(len(data)) + ' nodes.')
- except Exception as err:
- logger.error(str(err))
- time.sleep(INTERVAL)
- logger.info('Shutting down')
|