def test_pipeline(self, extraction=None): try: data = extraction.fetch() except Exception as e: return dict( result=[dict(errors=stringfy_exc(e)[0], columns=[], data=[])]) result = [] for step in extraction.steps: try: data = step.apply(data) result.append( dict(errors=None, columns=(str(col) for col in data.columns), data=list( (truncate(force_text(d), 50) for d in r) for r in itertools.islice(data.itertuples(), 3)))) except Exception as e: # the shown error should be enough to understand the issue, # if it isn't then the full exception is logged, # the user should open a ticket or call you to fix it shown, logged = stringfy_exc(e) log.exception(logged) result.append(dict(errors=shown, columns=[], data=[])) return dict(results=result)
def notify_reports(self, **kwargs): """ Notify user of individual reports kwargs: application: application that the event applies for, user: user that should be notified request: request object since_when: reports are newer than this time value, reports: list of reports to render """ template_vars = self.report_alert_notification_vars(kwargs) if template_vars['confirmed_total'] > 1: template_vars["title"] = "AppEnlight :: %s - %s reports" % ( template_vars['resource_name'], template_vars['confirmed_total'], ) else: error_title = truncate( template_vars['reports'][0][1].error or 'slow report', 20) template_vars["title"] = "AppEnlight :: %s - '%s' report" % ( template_vars['resource_name'], error_title) UserService.send_email(kwargs['request'], [self.channel_value], template_vars, '/email_templates/notify_reports.jinja2') log_msg = 'NOTIFY : %s via %s :: %s reports' % ( kwargs['user'].user_name, self.channel_visible_value, template_vars['confirmed_total']) log.warning(log_msg)
def notify_reports(self, **kwargs): """ Notify user of individual reports kwargs: application: application that the event applies for, user: user that should be notified request: request object since_when: reports are newer than this time value, reports: list of reports to render """ template_vars = self.report_alert_notification_vars(kwargs) app_url = kwargs["request"].registry.settings["_mail_url"] destination_url = kwargs["request"].route_url("/", _app_url=app_url) f_args = ( "report", template_vars["resource"].resource_id, template_vars["url_start_date"].strftime("%Y-%m-%dT%H:%M"), template_vars["url_end_date"].strftime("%Y-%m-%dT%H:%M"), ) destination_url += "ui/{}?resource={}&start_date={}&end_date={}".format( *f_args) if template_vars["confirmed_total"] > 1: template_vars["title"] = "%s - %s reports" % ( template_vars["resource_name"], template_vars["confirmed_total"], ) else: error_title = truncate( template_vars["reports"][0][1].error or "slow report", 90) template_vars["title"] = "%s - '%s' report" % ( template_vars["resource_name"], error_title, ) template_vars["title"] += " " + destination_url log_msg = "NOTIFY : %s via %s :: %s reports" % ( kwargs["user"].user_name, self.channel_visible_value, template_vars["confirmed_total"], ) log.warning(log_msg) client = HipchatIntegration.create_client( self.integration.config["api_token"]) for room in self.integration.config["rooms"].split(","): client.send({ "message_format": "text", "message": template_vars["title"], "from": "AppEnlight", "room_id": room.strip(), "color": "yellow", })
def notify_reports(self, **kwargs): """ Notify user of individual reports kwargs: application: application that the event applies for, user: user that should be notified request: request object since_when: reports are newer than this time value, reports: list of reports to render """ template_vars = self.report_alert_notification_vars(kwargs) template_vars["title"] = template_vars["resource_name"] if template_vars["confirmed_total"] > 1: template_vars[ "subtext"] = "%s reports" % template_vars["confirmed_total"] else: error_title = truncate( template_vars["reports"][0][1].error or "slow report", 90) template_vars["subtext"] = error_title log_msg = "NOTIFY : %s via %s :: %s reports" % ( kwargs["user"].user_name, self.channel_visible_value, template_vars["confirmed_total"], ) log.warning(log_msg) client = SlackIntegration.create_client( self.integration.config["webhook_url"]) report_data = { "username": "******", "icon_emoji": ":fire:", "attachments": [{ "mrkdwn_in": ["text", "pretext", "title", "fallback"], "fallback": "*%s* - <%s| Browse>" % (template_vars["title"], template_vars["destination_url"]), "pretext": "*%s* - <%s| Browse>" % (template_vars["title"], template_vars["destination_url"]), "color": "warning", "fields": [{ "value": "Info: %s" % template_vars["subtext"], "short": False }], }], } client.make_request(data=report_data)
def notify_reports(self, **kwargs): """ Notify user of individual reports kwargs: application: application that the event applies for, user: user that should be notified request: request object since_when: reports are newer than this time value, reports: list of reports to render """ template_vars = self.report_alert_notification_vars(kwargs) app_url = kwargs['request'].registry.settings['_mail_url'] destination_url = kwargs['request'].route_url('/', _app_url=app_url) f_args = ('report', template_vars['resource'].resource_id, template_vars['url_start_date'].strftime('%Y-%m-%dT%H:%M'), template_vars['url_end_date'].strftime('%Y-%m-%dT%H:%M')) destination_url += 'ui/{}?resource={}&start_date={}&end_date={}'.format( *f_args) if template_vars['confirmed_total'] > 1: template_vars["title"] = "%s - %s reports" % ( template_vars['resource_name'], template_vars['confirmed_total'], ) else: error_title = truncate(template_vars['reports'][0][1].error or 'slow report', 90) template_vars["title"] = "%s - '%s' report" % ( template_vars['resource_name'], error_title) log_msg = 'NOTIFY : %s via %s :: %s reports' % ( kwargs['user'].user_name, self.channel_visible_value, template_vars['confirmed_total']) log.warning(log_msg) client = FlowdockIntegration.create_client( self.integration.config['api_token']) payload = { "source": "AppEnlight", "from_address": kwargs['request'].registry.settings[ 'mailing.from_email'], "subject": template_vars["title"], "content": "New report present", "tags": ["appenlight"], "link": destination_url } client.send_to_inbox(payload)
def api_json(self): """ Generates the pool in Json :return: json-representation of the AppEnsemble-Pool """ ae_info = dict() try: for key in self.pool.get_all_AppEnsembles(): ae = self.pool.get_AppEnsemble(key) path = ae.ae_pkg_path documentation = text.truncate(ae.getDocumentation(), length=100, indicator='...', whole_word=True) apps = ae.getRequiredApps().serialize(format='json').decode() ae_info[key] = {'uri': key, 'path': path, 'apps': apps, 'documentation': documentation} except AttributeError: ae_info[key] = {'uri': key, 'path': path, 'apps': {}, 'documentation':''} return ae_info
def notify_reports(self, **kwargs): """ Notify user of individual reports kwargs: application: application that the event applies for, user: user that should be notified request: request object since_when: reports are newer than this time value, reports: list of reports to render """ template_vars = self.report_alert_notification_vars(kwargs) app_url = kwargs['request'].registry.settings['_mail_url'] destination_url = kwargs['request'].route_url('/', app_url=app_url) f_args = ('report', template_vars['resource'].resource_id, template_vars['url_start_date'].strftime('%Y-%m-%dT%H:%M'), template_vars['url_end_date'].strftime('%Y-%m-%dT%H:%M')) destination_url += 'ui/{}?resource={}&start_date={}&end_date={}'.format( *f_args) if template_vars['confirmed_total'] > 1: template_vars["title"] = "%s - %s reports" % ( template_vars['resource_name'], template_vars['confirmed_total'], ) else: error_title = truncate( template_vars['reports'][0][1].error or 'slow report', 90) template_vars["title"] = "%s - '%s' report" % ( template_vars['resource_name'], error_title) template_vars["title"] += ' ' + destination_url log_msg = 'NOTIFY : %s via %s :: %s reports' % ( kwargs['user'].user_name, self.channel_visible_value, template_vars['confirmed_total']) log.warning(log_msg) for room in self.integration.config['rooms'].split(','): self.client.speak_to_room(room.strip(), template_vars["title"])
def api_page_details(self): ae = self.pool.get_AppEnsemble(self.uri) api_ae_uri=self.build_URI('api-appensembles-ae-package','{URI:.*}',self.uri) ae_apps = ae.getRequiredApps(use_json=True) for app in ae_apps: app['app_details_uri'] = self.build_URI('app-details',"{URI:.*}",self.pool._hash_value(app['app_uri'])) custom_args = { 'ae_uri': self.uri, 'documentation': text.truncate(ae.getDocumentation(), length=1000, indicator='...', whole_word=True), 'ae_api_path':api_ae_uri, 'qrcode': self.pool.get_QRCode(api_ae_uri), 'direct_download_uri':self.build_URI('api-appensembles-ae-package',"{URI:.*}",self.uri), 'ae_has_bpm': ae.has_bpm(), 'ae_apps': ae_apps, 'bpmn_view_uri':self.build_URI('ae-view-bpm',"{URI}",self.uri), 'bpmn_edit_uri':self.build_URI('ae-edit-bpm',"{URI}",self.uri), 'bpmn_delete_uri':self.build_URI('api-appensembles-delete',"{URI}",self.uri) } return custom_args
def page_overview(self): """ Generates the parameters for the AppPool-Homepage """ self._setTitle('App-Pool') apps = list() app_uris = self.pool.get_app_uris() for app_uri in app_uris: app = { 'uri': app_uri, 'details_uri':self.build_URI('app-details',"{URI:.*}",self.pool._hash_value(app_uri)),#/apps/"+quote_plus(app_uri)+"/details", 'name': self.pool.get_name(app_uri), 'icon': self.pool.get_icon_uri(app_uri), 'binary': self.pool.get_install_uri(app_uri), 'description': text.truncate(self.pool.get_description(app_uri), length=200, indicator='...', whole_word=True) } apps.append(app) apps = sorted(apps, key=lambda app: (app['name'], app['uri'])) custom_args = {'apps': apps} return self._returnCustomDict(custom_args)