Exemple #1
0
    def __init__(self, app):
        Module.__init__(self, app)
        # add template path
        app.jinja_loader.searchpath.append(
            u"{}/emonitor/modules/printers/templates".format(
                app.config.get('PROJECT_ROOT')))

        # add events and handler
        events.addHandlerClass('*',
                               'emonitor.modules.printers.printers.Printers',
                               Printers.handleEvent, ['in.printerid'])

        # subnavigation
        self.adminsubnavigation = [('/admin/printers', 'printers.main'),
                                   ('/admin/printers/settings',
                                    'module.printers.settings')]

        # static folders
        @app.route('/printer/inc/<path:filename>')
        def printer_static(filename):
            return send_from_directory(
                u"{}/emonitor/modules/printers/inc/".format(
                    app.config.get('PROJECT_ROOT')), filename)

        # translations
        babel.gettext(u'module.printers')
        babel.gettext(u'printers.main')
        babel.gettext(u'module.printers.settings')
        babel.gettext(u'emonitor.modules.printers.printers.Printers')
        babel.gettext(u'template.alarm_sum')
        babel.gettext(u'template.alarm_original')
Exemple #2
0
    def init_app(self, app):
        Communication.app = app

        try:  # try telegram
            import telegram
            self.__dict__['telegram'] = TelegramBot(
                app=app,
                token=Settings.get('telegramsettings')['telegramkey']
                or app.config.get('TELEGRAMKEY'))
        except TypeError:
            Settings.set('telegramsettings', {'telegramkey': ''})
            self.__dict__['telegram'] = None
        except ImportError:
            logger.error("error telegram")
            self.__dict__['telegram'] = None

        try:  # try mail
            # TODO: add Mail communicator
            pass
            self.__dict__['mail'] = Mailer
        except ImportError:
            self.__dict__['mail'] = None
            logger.error("error Mail")
            # Mail = None

        app.extensions['communication'] = self

        logger.info("{} Communicator(s) loaded: {}".format(
            len(self.__dict__.keys()), ", ".join(self.__dict__.keys())))
        events.addHandlerClass(
            '*', 'emonitor.communication.Communication',
            Communication.handleEvent,
            ['in.sendertype', 'in.group', 'in.id', 'in.style'])
Exemple #3
0
    def init_app(self, app):
        Communication.app = app

        try:  # try telegram
            import telegram
            self.__dict__['telegram'] = TelegramBot(app=app, token=Settings.get('telegramsettings')['telegramkey'] or app.config.get('TELEGRAMKEY'))
        except TypeError:
            Settings.set('telegramsettings', {'telegramkey': ''})
            self.__dict__['telegram'] = None
        except ImportError:
            logger.error("error telegram")
            self.__dict__['telegram'] = None

        try:  # try mail
            # TODO: add Mail communicator
            pass
            self.__dict__['mail'] = Mailer
        except ImportError:
            self.__dict__['mail'] = None
            logger.error("error Mail")
            # Mail = None

        app.extensions['communication'] = self

        logger.info("{} Communicator(s) loaded: {}".format(len(self.__dict__.keys()), ", ".join(self.__dict__.keys())))
        events.addHandlerClass('*', 'emonitor.communication.Communication', Communication.handleEvent, ['in.sendertype', 'in.group', 'in.id', 'in.style'])
    def __init__(self, app):
        """
        Add event handler for *script-event*

        :param app: *Flask* app object
        """
        Module.__init__(self, app)

        # eventhandlers
        events.addHandlerClass('*', 'emonitor.modules.scripts.script.Script', Script.handleEvent, ['in.scriptname'])

        # translations
        babel.gettext(u'emonitor.modules.scripts.script.Script')
Exemple #5
0
    def __init__(self, app):
        """
        Add event handler for *script-event*

        :param app: *Flask* app object
        """
        Module.__init__(self, app)

        # eventhandlers
        events.addHandlerClass('*', 'emonitor.modules.scripts.script.Script',
                               Script.handleEvent, ['in.scriptname'])

        # translations
        babel.gettext(u'emonitor.modules.scripts.script.Script')
Exemple #6
0
    def init_app(self, app):
        events.addHandlerClass('*', 'emonitor.monitorserver.MonitorServer', self.handleEvent, ['in.params', 'in.condition'])

        self.ANY = app.config.get('MONITORSERVER_ANY', "0.0.0.0")
        self.MCAST_ADDR = app.config.get('MONITORSERVER_MCAST_ADDR', "224.168.2.9")
        self.MCAST_PORT = app.config.get('MONITORSERVER_MCAST_PORT', 1600)
        self.host = app.config.get('HOST', '')

        ip = socket.gethostbyname(socket.gethostname())
        if ip and self.host != ip:
            self.host = ip
        self.port = app.config.get('PORT')

        signal.addSignal('monitorserver', 'clientsearchstart')
        signal.addSignal('monitorserver', 'clientsearchdone')
        signal.addSignal('monitorserver', 'clientanswer')
Exemple #7
0
    def init_app(self, app):
        events.addHandlerClass('*', 'emonitor.monitorserver.MonitorServer',
                               self.handleEvent, ['in.params', 'in.condition'])

        self.ANY = app.config.get('MONITORSERVER_ANY', "0.0.0.0")
        self.MCAST_ADDR = app.config.get('MONITORSERVER_MCAST_ADDR',
                                         "224.168.2.9")
        self.MCAST_PORT = app.config.get('MONITORSERVER_MCAST_PORT', 1600)
        self.host = app.config.get('HOST', '')

        ip = socket.gethostbyname(socket.gethostname())
        if ip and self.host != ip:
            self.host = ip
        self.port = app.config.get('PORT')

        signal.addSignal('monitorserver', 'clientsearchstart')
        signal.addSignal('monitorserver', 'clientsearchdone')
        signal.addSignal('monitorserver', 'clientanswer')
Exemple #8
0
    def __init__(self, app):
        Module.__init__(self, app)
        # add template path
        app.jinja_loader.searchpath.append("%s/emonitor/modules/textmod/templates" % app.config.get('PROJECT_ROOT'))

        # subnavigation
        self.adminsubnavigation = [('/admin/textmod', 'module.textmod.replace'), ('/admin/textmod/ocr', 'module.textmod.ocr'), ('/admin/textmod/ocrcustom', 'module.textmod.ocrcustom'), ('/admin/textmod/convert', 'module.textmod.convert')]
        
        # create database tables
        from .replace import Replace
        from .ocr import Ocr

        # eventhandlers
        events.addHandlerClass('file_added', 'emonitor.modules.textmod.TextmodModule', TextmodModule.handleEvent, ['in.path', 'in.filename', 'out.filename'])
        events.addHandlerClass('file_added', 'emonitor.modules.textmod.ocr.Ocr', Ocr.handleEvent, ['in.path', 'in.filename', 'out.text'])
        events.addHandlerClass('file_added', 'emonitor.modules.textmod.replace.Replace', Replace.handleEvent, ['in.text', 'out.text'])
        
        # translations
        babel.gettext(u'module.textmod')
        babel.gettext(u'module.textmod.replace')
        babel.gettext(u'module.textmod.ocr')
        babel.gettext(u'module.textmod.ocrcustom')
        babel.gettext(u'module.textmod.convert')
        babel.gettext(u'emonitor.modules.textmod.ocr.Ocr')
        babel.gettext(u'emonitor.modules.textmod.replace.Replace')
        babel.gettext(u'emonitor.modules.textmod.TextmodModule')
Exemple #9
0
    def __init__(self, app):
        """
        Add specific parameters and configuration to app object

        :param app: flask wsgi application
        """
        Module.__init__(self, app)
        # add template path
        app.jinja_loader.searchpath.append("{}/emonitor/modules/alarms/templates".format(app.config.get('PROJECT_ROOT')))

        # subnavigation
        self.adminsubnavigation = [('/admin/alarms', 'alarms.base'), ('/admin/alarms/types', 'module.alarms.types'), ('/admin/alarms/report', 'module.alarms.report'), ('/admin/alarms/config', 'module.alarms.config'), ('/admin/alarms/test', 'module.alarms.test')]
        
        # create database tables
        from emonitor.modules.alarms.alarm import Alarm
        from emonitor.modules.alarms.alarmhistory import AlarmHistory
        from emonitor.modules.alarms.alarmattribute import AlarmAttribute
        from emonitor.modules.alarms.alarmsection import AlarmSection
        from emonitor.modules.alarms.alarmtype import AlarmType

        self.widgets = [AlarmIncomeWidget('alarms_income'), AlarmWidget('alarms'), AlarmTimerWidget('alarms_timer'), AlarmRemarkWidget('alarms_remark')]
        
        # eventhandlers
        for f in [f for f in os.listdir('{}/emonitor/modules/alarms/inc/'.format(app.config.get('PROJECT_ROOT'))) if f.endswith('.py')]:
            if not f.startswith('__'):
                cls = imp.load_source('emonitor.modules.alarms.inc', '{}/emonitor/modules/alarms/inc/{}'.format(app.config.get('PROJECT_ROOT'), f))
                checker = getattr(cls, cls.__all__[0])()
                if isinstance(checker, AlarmFaxChecker) and checker.getId() != 'Dummy':
                    events.addEvent('alarm_added.{}'.format(checker.getId()), handlers=[], parameters=['out.alarmid'])
                    events.addEvent('alarm_changestate.{}'.format(checker.getId()), handlers=[], parameters=['out.alarmid', 'out.state'])

        events.addEvent('alarm_added', handlers=[], parameters=['out.alarmid'])  # for all checkers
        events.addEvent('alarm_changestate', handlers=[], parameters=['out.alarmid', 'out.state'])  # for all checkers
        
        events.addHandlerClass('file_added', 'emonitor.modules.alarms.alarm.Alarms', Alarm.handleEvent, ['in.text', 'out.id', 'out.fields'])
        events.addHandlerClass('file_added', 'emonitor.modules.alarms.alarmtype.AlarmTypes', AlarmType.handleEvent, ['in.text', 'out.type'])

        # signals and handlers
        signal.addSignal('alarm', 'changestate')
        signal.addSignal('alarm', 'added')
        signal.addSignal('alarm', 'updated')
        signal.connect('alarm', 'changestate', frontendAlarmHandler.handleAlarmChanges)
        signal.connect('alarm', 'added', frontendAlarmHandler.handleAlarmChanges)
        signal.connect('alarm', 'updated', frontendAlarmHandler.handleAlarmChanges)
        signal.connect('alarm', 'deleted', frontendAlarmHandler.handleAlarmChanges)

        signal.connect('alarm', 'testupload_start', adminAlarmHandler.handleAlarmTestUpload)

        # static folders
        @app.route('/alarms/inc/<path:filename>')
        def alarms_static(filename):
            return send_from_directory("{}/emonitor/modules/alarms/inc/".format(app.config.get('PROJECT_ROOT')), filename)

        @app.route('/alarms/export/<path:filename>')  # filename = [id]-[style].pdf
        def export_static(filename):
            filename, extension = os.path.splitext(filename)
            try:
                id, template = filename.split('-')
                if extension not in ['.pdf', '.html', '.png']:
                    abort(404)
                elif extension == '.pdf':
                    return Response(Module.getPdf(Alarm.getExportData('.html', id=id, style=template, args=request.args)), mimetype="application/pdf")
                elif extension == '.html':
                    return Response(Alarm.getExportData(extension, id=id, style=template, args=request.args), mimetype="text/html")
                elif extension == '.png':
                    return Response(Alarm.getExportData(extension, id=id, style=template, filename=filename, args=request.args), mimetype="image/png")
            except ValueError:
                return abort(404)

        # add reportfolder
        if not os.path.exists('{}/alarmreports/'.format(app.config.get('PATH_DATA'))):
            os.makedirs('{}/alarmreports/'.format(app.config.get('PATH_DATA')))
            
        # translations
        babel.gettext(u'module.alarms')
        babel.gettext(u'alarms.base')
        babel.gettext(u'module.alarms.types')
        babel.gettext(u'module.alarms.report')
        babel.gettext(u'module.alarms.config')
        babel.gettext(u'module.alarms.test')
        babel.gettext(u'alarms_income')
        babel.gettext(u'alarms_timer')
        babel.gettext(u'alarms_remark')
        babel.gettext(u'alarms')
        babel.gettext(u'alarms.prio0')
        babel.gettext(u'alarms.prio1')
        babel.gettext(u'alarms.prio2')
        babel.gettext(u'emonitor.modules.alarms.alarm.Alarms')
        babel.gettext(u'emonitor.modules.alarms.alarmtype.AlarmTypes')
        babel.gettext(u'alarms.test.protocol')
        babel.gettext(u'alarms.test.result')
        babel.gettext(u'alarmstate.active')
        babel.gettext(u'alarmstate.created')
        babel.gettext(u'alarmstate.done')
        babel.gettext(u'alarmstate.archive')
        babel.gettext(u'active')
        babel.gettext(u'created')
        babel.gettext(u'done')
        babel.gettext(u'archive')
        babel.gettext(u'alarms.statechangeactivated')
        babel.gettext(u'alarms.prioshort0')
        babel.gettext(u'alarms.prioshort1')
        babel.gettext(u'alarms.prioshort2')
        babel.gettext(u'alarms.carsinuse')
        babel.gettext(u'history.autochangeState')
        babel.gettext(u'history.message')
        babel.gettext(u'trigger.alarm_added')
        babel.gettext(u'trigger.alarm_changestate')

        babel.gettext(u'trigger.alarm_added_sub')
        babel.gettext(u'trigger.alarm_changestate_sub')

        babel.gettext(u'alarms.print.slightleft')
        babel.gettext(u'alarms.print.slightright')
        babel.gettext(u'alarms.print.right')
        babel.gettext(u'alarms.print.left')
        babel.gettext(u'alarms.print.straight')
        babel.gettext(u'alarms.print.exit')
        babel.gettext(u'alarms.print.bus')
        babel.gettext(u'alarms.print.positive')
        babel.gettext(u'alarms.print.negative')

        babel.gettext(u'alarms.filter.0')
        babel.gettext(u'alarms.filter.1')
        babel.gettext(u'alarms.filter.7')
        babel.gettext(u'alarms.filter.31')

        babel.gettext(u'internal')
        babel.gettext(u'external')

        babel.gettext(u'AFAlerting')
        babel.gettext(u'AFCars')
        babel.gettext(u'AFMaterial')
        babel.gettext(u'AFReport')
        babel.gettext(u'AFTime')
        babel.gettext(u'AFDamage')
        babel.gettext(u'AFOthers')
        babel.gettext(u'AFPersons')

        babel.gettext(u'alarms.fields.simple')
        babel.gettext(u'alarms.fields.extended')
        babel.gettext(u'alarms.fields.persons.field.sum')
        babel.gettext(u'alarms.fields.persons.field.house')
        babel.gettext(u'alarms.fields.persons.field.pa_alarm')
        babel.gettext(u'alarms.fields.persons.field.el')
        babel.gettext(u'alarms.fields.persons.field.alarm')
        babel.gettext(u'alarms.fields.persons.field.pa')
        babel.gettext(u'alarms.fields.persons.field.pa_house')
        babel.gettext(u'alarms.fields.persons.field.elgrade')
        babel.gettext(u'alarms.fields.persons.field.style.simple')
        babel.gettext(u'alarms.fields.persons.field.style.extended')

        # init
        # Do init script for alarms at start and add alarms (state = 1 or 2) (active or done)
        for aalarm in Alarm.query.filter(Alarm.state in [1, 2]).all():
            aalarm.updateSchedules(reference=1)
Exemple #10
0
    def __init__(self, app):
        """
        Add specific parameters and configuration to app object

        :param app: flask wsgi application
        """
        Module.__init__(self, app)
        # add template path
        app.jinja_loader.searchpath.append(
            "{}/emonitor/modules/alarms/templates".format(
                app.config.get('PROJECT_ROOT')))

        # subnavigation
        self.adminsubnavigation = [
            ('/admin/alarms', 'alarms.base'),
            ('/admin/alarms/types', 'module.alarms.types'),
            ('/admin/alarms/report', 'module.alarms.report'),
            ('/admin/alarms/config', 'module.alarms.config'),
            ('/admin/alarms/test', 'module.alarms.test')
        ]

        # create database tables
        from emonitor.modules.alarms.alarm import Alarm
        from emonitor.modules.alarms.alarmhistory import AlarmHistory
        from emonitor.modules.alarms.alarmattribute import AlarmAttribute
        from emonitor.modules.alarms.alarmsection import AlarmSection
        from emonitor.modules.alarms.alarmtype import AlarmType

        self.widgets = [
            AlarmIncomeWidget('alarms_income'),
            AlarmWidget('alarms'),
            AlarmTimerWidget('alarms_timer'),
            AlarmRemarkWidget('alarms_remark')
        ]

        # eventhandlers
        for f in [
                f for f in os.listdir('{}/emonitor/modules/alarms/inc/'.format(
                    app.config.get('PROJECT_ROOT'))) if f.endswith('.py')
        ]:
            if not f.startswith('__'):
                cls = imp.load_source(
                    'emonitor.modules.alarms.inc',
                    '{}/emonitor/modules/alarms/inc/{}'.format(
                        app.config.get('PROJECT_ROOT'), f))
                checker = getattr(cls, cls.__all__[0])()
                if isinstance(checker,
                              AlarmFaxChecker) and checker.getId() != 'Dummy':
                    for at in AlarmType.getAlarmTypes():
                        if at.interpreter == f:
                            events.addEvent('alarm_added.{}'.format(at.name),
                                            handlers=[],
                                            parameters=['out.alarmid'])
                            events.addEvent(
                                'alarm_changestate.{}'.format(at.name),
                                handlers=[],
                                parameters=['out.alarmid', 'out.state'])

        events.addEvent('alarm_added', handlers=[],
                        parameters=['out.alarmid'])  # for all checkers
        events.addEvent('alarm_changestate',
                        handlers=[],
                        parameters=['out.alarmid',
                                    'out.state'])  # for all checkers

        events.addHandlerClass('file_added',
                               'emonitor.modules.alarms.alarm.Alarms',
                               Alarm.handleEvent,
                               ['in.text', 'out.id', 'out.fields'])
        events.addHandlerClass('file_added',
                               'emonitor.modules.alarms.alarmtype.AlarmTypes',
                               AlarmType.handleEvent, ['in.text', 'out.type'])

        events.addHandlerClass('incoming_serial_data',
                               'emonitor.modules.alarms.alarm.Alarms',
                               Alarm.handleSerialEvent,
                               ['in.text', 'out.id', 'out.fields'])
        events.addHandlerClass('incoming_serial_data',
                               'emonitor.modules.alarms.alarmtype.AlarmTypes',
                               AlarmType.handleEvent, ['in.text', 'out.type'])

        # signals and handlers
        signal.addSignal('alarm', 'changestate')
        signal.addSignal('alarm', 'added')
        signal.addSignal('alarm', 'updated')
        signal.addSignal('alarm', 'error')
        signal.connect('alarm', 'changestate',
                       frontendAlarmHandler.handleAlarmChanges)
        signal.connect('alarm', 'added',
                       frontendAlarmHandler.handleAlarmChanges)
        signal.connect('alarm', 'updated',
                       frontendAlarmHandler.handleAlarmChanges)
        signal.connect('alarm', 'deleted',
                       frontendAlarmHandler.handleAlarmChanges)
        signal.connect('alarm', 'error',
                       frontendAlarmHandler.handleAlarmErrors)

        signal.connect('alarm', 'testupload_start',
                       adminAlarmHandler.handleAlarmTestUpload)

        # static folders
        @app.route('/alarms/inc/<path:filename>')
        def alarms_static(filename):
            if filename.startswith('sample_'):  # deliver sample checker file
                clsname = filename.split('_')[1]
                return Response(AlarmType.getAlarmTypes(
                    clsname).interpreterclass().getSampleLayout(),
                                mimetype="image/jpeg")

            return send_from_directory(
                "{}/emonitor/modules/alarms/inc/".format(
                    app.config.get('PROJECT_ROOT')), filename)

        @app.route('/alarms/export/<path:filename>'
                   )  # filename = [id]-[style].pdf
        def export_static(filename):
            filename, extension = os.path.splitext(filename)
            try:
                id, template = filename.split('-')
                if extension not in ['.pdf', '.html', '.png']:
                    abort(404)
                elif extension == '.pdf':
                    return Response(Module.getPdf(
                        Alarm.getExportData('.html',
                                            id=id,
                                            style=template,
                                            args=request.args)),
                                    mimetype="application/pdf")
                elif extension == '.html':
                    return Response(Alarm.getExportData(extension,
                                                        id=id,
                                                        style=template,
                                                        args=request.args),
                                    mimetype="text/html")
                elif extension == '.png':
                    return Response(Alarm.getExportData(extension,
                                                        id=id,
                                                        style=template,
                                                        filename=filename,
                                                        args=request.args),
                                    mimetype="image/png")
            except ValueError:
                return abort(404)

        # add reportfolder
        if not os.path.exists('{}/alarmreports/'.format(
                app.config.get('PATH_DATA'))):
            os.makedirs('{}/alarmreports/'.format(app.config.get('PATH_DATA')))

        # translations
        babel.gettext(u'module.alarms')
        babel.gettext(u'alarms.base')
        babel.gettext(u'module.alarms.types')
        babel.gettext(u'module.alarms.report')
        babel.gettext(u'module.alarms.config')
        babel.gettext(u'module.alarms.test')
        babel.gettext(u'alarms_income')
        babel.gettext(u'alarms_timer')
        babel.gettext(u'alarms_remark')
        babel.gettext(u'alarms')
        babel.gettext(u'alarms.prio0')
        babel.gettext(u'alarms.prio1')
        babel.gettext(u'alarms.prio2')
        babel.gettext(u'emonitor.modules.alarms.alarm.Alarms')
        babel.gettext(u'emonitor.modules.alarms.alarmtype.AlarmTypes')
        babel.gettext(u'alarms.test.protocol')
        babel.gettext(u'alarms.test.result')
        babel.gettext(u'alarmstate.active')
        babel.gettext(u'alarmstate.created')
        babel.gettext(u'alarmstate.done')
        babel.gettext(u'alarmstate.archive')
        babel.gettext(u'active')
        babel.gettext(u'created')
        babel.gettext(u'done')
        babel.gettext(u'archive')
        babel.gettext(u'alarms.statechangeactivated')
        babel.gettext(u'alarms.prioshort0')
        babel.gettext(u'alarms.prioshort1')
        babel.gettext(u'alarms.prioshort2')
        babel.gettext(u'alarms.carsinuse')
        babel.gettext(u'history.autochangeState')
        babel.gettext(u'history.message')
        babel.gettext(u'trigger.alarm_added')
        babel.gettext(u'trigger.alarm_changestate')

        babel.gettext(u'trigger.alarm_added_sub')
        babel.gettext(u'trigger.alarm_changestate_sub')

        babel.gettext(u'alarms.print.slightleft')
        babel.gettext(u'alarms.print.slightright')
        babel.gettext(u'alarms.print.right')
        babel.gettext(u'alarms.print.left')
        babel.gettext(u'alarms.print.straight')
        babel.gettext(u'alarms.print.exit')
        babel.gettext(u'alarms.print.bus')
        babel.gettext(u'alarms.print.positive')
        babel.gettext(u'alarms.print.negative')

        babel.gettext(u'alarms.filter.0')
        babel.gettext(u'alarms.filter.1')
        babel.gettext(u'alarms.filter.7')
        babel.gettext(u'alarms.filter.31')

        babel.gettext(u'internal')
        babel.gettext(u'external')

        babel.gettext(u'AFAlerting')
        babel.gettext(u'AFCars')
        babel.gettext(u'AFMaterial')
        babel.gettext(u'AFReport')
        babel.gettext(u'AFTime')
        babel.gettext(u'AFDamage')
        babel.gettext(u'AFOthers')
        babel.gettext(u'AFPersons')

        babel.gettext(u'alarms.fields.simple')
        babel.gettext(u'alarms.fields.extended')
        babel.gettext(u'alarms.fields.persons.field.sum')
        babel.gettext(u'alarms.fields.persons.field.house')
        babel.gettext(u'alarms.fields.persons.field.pa_alarm')
        babel.gettext(u'alarms.fields.persons.field.el')
        babel.gettext(u'alarms.fields.persons.field.alarm')
        babel.gettext(u'alarms.fields.persons.field.pa')
        babel.gettext(u'alarms.fields.persons.field.pa_house')
        babel.gettext(u'alarms.fields.persons.field.elgrade')
        babel.gettext(u'alarms.fields.persons.field.style.simple')
        babel.gettext(u'alarms.fields.persons.field.style.extended')

        # init
        # Do init script for alarms at start and add alarms (state = 1 or 2) (active or done)
        for aalarm in Alarm.query.filter(Alarm.state == 1
                                         or Alarm.state == 2).all():
            aalarm.updateSchedules(reference=1)