def job(self, run: "Run", payload: dict, device: Optional[Device] = None) -> dict: app.send_email( run.sub(run.title, locals()), run.sub(run.body, locals()), sender=run.sender, recipients=run.recipients, ) return {"success": True, "result": {}}
def job(self, run, payload, device=None): app.send_email( run.sub(run.title, locals()), run.sub(run.body, locals()), sender=run.sender, recipients=run.recipients, ) return {"success": True, "result": {}}
def mail_feedback_notification(self, run: "Run", payload: dict) -> dict: name = payload["job"]["name"] app.send_email( f"{name} ({'PASS' if payload['results']['success'] else 'FAILED'})", payload["content"], recipients=payload["job"]["mail_recipient"], filename=f"results-{run.runtime.replace('.', '').replace(':', '')}.txt", file_content=app.str_dict(payload["results"]), ) return {"success": True}
def notify(self, results): notification = self.build_notification(results) results["notification"] = {"content": notification} try: if self.send_notification_method == "mail": filename = self.runtime.replace(".", "").replace(":", "") result = app.send_email( f"{self.name} ({'PASS' if results['success'] else 'FAILED'})", notification, recipients=self.mail_recipient, filename=f"results-{filename}.txt", file_content=app.str_dict(results), ) elif self.send_notification_method == "slack": result = SlackClient(app.slack_token).api_call( "chat.postMessage", channel=app.slack_channel, text=notification) else: result = post( app.mattermost_url, verify=app.mattermost_verify_certificate, data=dumps({ "channel": app.mattermost_channel, "text": notification }), ) results["notification"].update({"success": True, "result": result}) except Exception as exc: results["notification"].update({ "success": False, "result": str(exc) }) return results
def notify(self, results): self.log("info", f"Sending {self.send_notification_method} notification...") notification = self.build_notification(results) file_content = deepcopy(notification) if self.include_device_results: file_content["Device Results"] = {} for device in self.devices: device_result = fetch( "result", service_id=self.service_id, parent_runtime=self.parent_runtime, device_id=device.id, allow_none=True, ) if device_result: file_content["Device Results"][ device.name] = device_result.result try: if self.send_notification_method == "mail": filename = self.runtime.replace(".", "").replace(":", "") status = "PASS" if results["success"] else "FAILED" result = app.send_email( f"{status}: {self.service.name} run by {self.creator}", app.str_dict(notification), recipients=self.mail_recipient, filename=f"results-{filename}.txt", file_content=app.str_dict(file_content), ) elif self.send_notification_method == "slack": result = SlackClient(environ.get("SLACK_TOKEN")).api_call( "chat.postMessage", channel=app.settings["slack"]["channel"], text=notification, ) else: result = post( app.settings["mattermost"]["url"], verify=app.settings["mattermost"]["verify_certificate"], data=dumps({ "channel": app.settings["mattermost"]["channel"], "text": notification, }), ).text results["notification"] = {"success": True, "result": result} except Exception: results["notification"] = { "success": False, "error": "\n".join(format_exc().splitlines()), } return results
def notify(self, results): notification = self.build_notification(results) file_content = deepcopy(notification) if self.include_device_results: file_content["Device Results"] = { device.name: fetch( "result", service_id=self.service_id, parent_runtime=self.parent_runtime, device_id=device.id, ).result for device in self.devices } try: if self.send_notification_method == "mail": filename = self.runtime.replace(".", "").replace(":", "") result = app.send_email( f"{self.name} ({'PASS' if results['success'] else 'FAILED'})", app.str_dict(notification), recipients=self.mail_recipient, filename=f"results-{filename}.txt", file_content=app.str_dict(file_content), ) elif self.send_notification_method == "slack": result = SlackClient(environ.get("SLACK_TOKEN")).api_call( "chat.postMessage", channel=app.config["slack"]["channel"], text=notification, ) else: result = post( app.config["mattermost"]["url"], verify=app.config["mattermost"]["verify_certificate"], data=dumps({ "channel": app.config["mattermost"]["channel"], "text": notification, }), ).text results["notification"] = {"success": True, "result": result} except Exception: results["notification"] = { "success": False, "error": "\n".join(format_exc().splitlines()), } return results