Example #1
0
 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)
Example #2
0
 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)
Example #3
0
        def link_callback(uri, rel):
            """
            Callback method for links

            :param uri:
            :param rel:
            :return: fixed string for link
            """
            if '/export/' in uri and not rel:  # create tmp-files for export items
                if "/alarms/" in uri and uri.endswith('png'):
                    f, ext = os.path.splitext(uri)
                    from emonitor.modules.alarms.alarm import Alarm
                    fname = '{}{}'.format(current_app.config.get('PATH_TMP'),
                                          '{}.png'.format(random.random()))
                    with open(fname, 'wb') as tmpimg:  # write tmp image file
                        tmpimg.write(
                            Alarm.getExportData(
                                '.png',
                                style=uri.split('-')[1][:-4],
                                id=f.split('/')[-1].split('-')[0]))
                        images.append(fname)
                    return fname
            return "%s/emonitor/modules%s" % (
                current_app.config.get('PROJECT_ROOT'), uri
            )  # make absolute links
Example #4
0
    def handleEvent(eventname, **kwargs):
        hdl = [hdl for hdl in Eventhandler.getEventhandlers(event=eventname) if hdl.handler == 'emonitor.communication.Communication'][0]
        if hdl:
            from emonitor.extensions import communication
            params = {}
            for p in hdl.getParameterValues('in'):
                params[p[0].split('.')[-1]] = p[1]
            if params["sendertype"] == 'telegram':
                for group, members in Settings.getYaml('telegramsettings').__dict__['groups'].items():
                    if group == params['group']:
                        from telegram import InlineKeyboardMarkup, InlineKeyboardButton
                        args = {'id': int(kwargs.get('alarmid')), 'style': params['style'], 'addressees': members[:-1], 'keyboard': InlineKeyboardMarkup, 'button': InlineKeyboardButton}
                        attrs = Alarm.getExportData('telegram', **args)
                        for member in members[:-1]:
                            if params['id'] == 'alarmid':  # send alarm details with location
                                try:
                                    if params.get('style') in ['text', 'details']:
                                        communication.telegram.sendMessage(member, attrs['details'], reply_markup=attrs['reply'])
                                    elif params.get('style') == 'venue':
                                        communication.telegram.sendVenue(member, attrs['text'], lat=attrs['lat'], lng=attrs['lng'], address=attrs['address'], reply_markup=attrs['reply'])
                                except:
                                    print "error handleEvent"
                                return kwargs

            elif params["sendertype"] == 'mailer':
                # TODO: implement mail notification
                pass

        return kwargs
Example #5
0
    def handleEvent(eventname, **kwargs):
        hdl = [
            hdl for hdl in Eventhandler.getEventhandlers(event=eventname)
            if hdl.handler == 'emonitor.communication.Communication'
        ][0]
        if hdl:
            from emonitor.extensions import communication
            params = {}
            for p in hdl.getParameterValues('in'):
                params[p[0].split('.')[-1]] = p[1]
            if params["sendertype"] == 'telegram':
                for group, members in Settings.getYaml(
                        'telegramsettings').__dict__['groups'].items():
                    if group == params['group']:
                        from telegram import InlineKeyboardMarkup, InlineKeyboardButton
                        args = {
                            'id': int(kwargs.get('alarmid')),
                            'style': params['style'],
                            'addressees': members[:-1],
                            'keyboard': InlineKeyboardMarkup,
                            'button': InlineKeyboardButton
                        }
                        attrs = Alarm.getExportData('telegram', **args)
                        for member in members[:-1]:
                            if params[
                                    'id'] == 'alarmid':  # send alarm details with location
                                try:
                                    if params.get('style') in [
                                            'text', 'details'
                                    ]:
                                        communication.telegram.sendMessage(
                                            member,
                                            attrs['details'],
                                            reply_markup=attrs['reply'])
                                    elif params.get('style') == 'venue':
                                        communication.telegram.sendVenue(
                                            member,
                                            attrs['text'],
                                            lat=attrs['lat'],
                                            lng=attrs['lng'],
                                            address=attrs['address'],
                                            reply_markup=attrs['reply'])
                                except:
                                    print "error handleEvent"
                                return kwargs

            elif params["sendertype"] == 'mailer':
                # TODO: implement mail notification
                pass

        return kwargs
Example #6
0
        def link_callback(uri, rel):
            """
            Callback method for links

            :param uri:
            :param rel:
            :return: fixed string for link
            """
            if '/export/' in uri and not rel:  # create tmp-files for export items
                if "/alarms/" in uri and uri.endswith('png'):
                    f, ext = os.path.splitext(uri)
                    from emonitor.modules.alarms.alarm import Alarm
                    fname = '{}{}'.format(current_app.config.get('PATH_TMP'), '{}.png'.format(random.random()))
                    with open(fname, 'wb') as tmpimg:  # write tmp image file
                        tmpimg.write(Alarm.getExportData('.png', style=uri.split('-')[1][:-4], id=f.split('/')[-1].split('-')[0]))
                        images.append(fname)
                    return fname
            return "%s/emonitor/modules%s" % (current_app.config.get('PROJECT_ROOT'), uri)  # make absolute links
Example #7
0
    def msg_responder(bot, update, **kwargs):
        """
        Responder for incoming messages
        :param bot:
        :param update:
        :param kwargs:
        """
        if update.callback_query.data.startswith('file_'):  # send file
            bot.sendDocument(update.callback_query.message.chat_id, open(TelegramBot.app.config.get('PATH_DONE') + update.callback_query.data.split('_')[-1], 'rb'), 'details.pdf', 'details')

        elif update.callback_query.data.startswith('details_'):  # details_[type]_[id]
            if update.callback_query.data.split('_')[1] == 'alarm':
                from telegram import InlineKeyboardMarkup, InlineKeyboardButton
                args = {'id': int(update.callback_query.data.split('_')[-1]), 'style': 'details', 'addressees': [update.callback_query.message.chat_id], 'keyboard': InlineKeyboardMarkup, 'button': InlineKeyboardButton}
                attrs = Alarm.getExportData('telegram', **args)
                for addressee in [update.callback_query.message.chat_id]:
                    bot.sendMessage(addressee, attrs['details'], reply_markup=attrs['reply'], parse_mode='Markdown')
                return

        elif update.callback_query.data.startswith('location_'):
            bot.sendLocation(update.callback_query.message.chat_id, update.callback_query.data.split('_')[1], update.callback_query.data.split('_')[2])
Example #8
0
    def msg_responder(bot, update, **kwargs):
        """
        Responder for incoming messages
        :param bot:
        :param update:
        :param kwargs:
        """
        if update.callback_query.data.startswith('file_'):  # send file
            bot.sendDocument(
                update.callback_query.message.chat_id,
                open(
                    TelegramBot.app.config.get('PATH_DONE') +
                    update.callback_query.data.split('_')[-1], 'rb'),
                'details.pdf', 'details')

        elif update.callback_query.data.startswith(
                'details_'):  # details_[type]_[id]
            if update.callback_query.data.split('_')[1] == 'alarm':
                from telegram import InlineKeyboardMarkup, InlineKeyboardButton
                args = {
                    'id': int(update.callback_query.data.split('_')[-1]),
                    'style': 'details',
                    'addressees': [update.callback_query.message.chat_id],
                    'keyboard': InlineKeyboardMarkup,
                    'button': InlineKeyboardButton
                }
                attrs = Alarm.getExportData('telegram', **args)
                for addressee in [update.callback_query.message.chat_id]:
                    bot.sendMessage(addressee,
                                    attrs['details'],
                                    reply_markup=attrs['reply'],
                                    parse_mode='Markdown')
                return

        elif update.callback_query.data.startswith('location_'):
            bot.sendLocation(update.callback_query.message.chat_id,
                             update.callback_query.data.split('_')[1],
                             update.callback_query.data.split('_')[2])