def notify(topic, subject, message): configs = OmeletConfigParser() aws_key = Credential() omelet_notifier = Notifier(configs.get_sns_region(), aws_key.get_aws_access_key(), aws_key.get_aws_secret_key()) omelet_notifier.send(configs.get_sns_topic('patch'), subject, message)
def send_notification(self, template, success, output, committer_name, committer_email, version="-", causedby=None): success_tag = "success" if success else "failure" subject = "[Image build %s] Template %s Version %s" % (success_tag, os.path.basename(template), version) message = "Committer: %s <%s>\nPath: %s\nOutput:\n%s" % (committer_name, committer_email, template, output) if causedby: message = "%s\nCaused by: %s" % (message, causedby) notifier = Notifier(self._configs.get_sns_region(), self._aws_key.get_aws_access_key(), self._aws_key.get_aws_secret_key()) notifier.send(self._configs.get_sns_topic("amipacker"), subject, message)
# should be ~/clone or ~/src/github.com/TrendMicroDCS parser.add_argument("-r", "--repo", type=str, help="target packer template repo master", required=True) # configs args = parser.parse_args() configs = OmeletConfigParser() # logging logging.config.fileConfig(os.path.join(configs.get_omelet_config_dir(), 'logging.ini')) logger = logging.getLogger(__name__) # aws key aws_key = Credential() # mail sender omelet_notifier = Notifier(configs.get_sns_region(), aws_key.get_aws_access_key(), aws_key.get_aws_secret_key()) try: amipacker_launcher = OmeletAMIPacker(configs, aws_key, args.repo) ret = amipacker_launcher.launch() if ret: omelet_notifier.send(configs.get_sns_topic("amipacker"), "Validation error: template is in the wrong path", ret) except Exception as err: logger.error(err) cause = "Omelet AMIPacker Error:\n\t%s\n\nTraceback:\n\t%s" % (err, traceback.format_exc()) omelet_notifier.send(configs.get_sns_topic("admin"), "Omelet Program Error", cause)
def testSend(self): self.aws_key = Credential() notify = Notifier("us-east-1", self.aws_key.get_aws_access_key(), self.aws_key.get_aws_secret_key()) notify.send("omelet", "hello", "can you see my message?")