def do_notify_webhook_type(**kwargs): webhook = kwargs["webhook"] user = kwargs["user"] pw = kwargs["pw"] verify = kwargs["verify"] subvars = kwargs["subvars"] payload = kwargs["payload"] if not user and not pw: auth = None else: auth = (user, pw) url = webhook["url"] if not url: raise Exception("Cannot send webhook, no URL configured") for subkey, subval in subvars: url = url.replace(subkey, subval) try: logger.info("webhook post: " + str(url) + " : " + payload) headers = {"Content-Type": "application/json"} result = http.anchy_post(url, data=payload, auth=auth, timeout=2.0, verify=verify, headers=headers) logger.info("webhook response: " + str(result)) return result except Exception as err: raise Exception( "failed to post notification to webhook - exception: " + str(err))
def do_notify_webhook_type(**kwargs): webhook = kwargs['webhook'] user = kwargs['user'] pw = kwargs['pw'] verify = kwargs['verify'] subvars = kwargs['subvars'] payload = kwargs['payload'] if not user and not pw: auth = None else: auth = (user, pw) url = webhook['url'] if not url: raise Exception('Cannot send webhook, no URL configured') for subkey, subval in subvars: url = url.replace(subkey, subval) try: logger.info("webhook post: " + str(url) + " : " + payload) headers = {'Content-Type': 'application/json'} result = http.anchy_post(url, data=payload, auth=auth, timeout=2.0, verify=verify, headers=headers) logger.info("webhook response: " + str(result)) return result except Exception as err: raise Exception("failed to post notification to webhook - exception: " + str(err))
def do_notify_webhook(user_record, notification): logger.spew("webhook notify user: "******"webhook notify user: "******"could not prepare notification as JSON - exception: " + str(err)) webhooks = {} localconfig = anchore_engine.configuration.localconfig.get_config() if 'webhooks' in localconfig: webhooks.update(localconfig['webhooks']) if webhooks: rootuser = webhooks.pop('webhook_user', None) rootpw = webhooks.pop('webhook_pass', None) rootverify = webhooks.pop('ssl_verify', None) for ntype in [notification_type, 'general']: if ntype in webhooks: webhook = webhooks[ntype] user = webhook.pop('webhook_user', rootuser) pw = webhook.pop('webhook_pass', rootpw) verify = webhook.pop('ssl_verify', rootverify) if not user and not pw: auth = None else: auth = (user, pw) url = webhook['url'] for subkey, subval in subvars: url = url.replace(subkey, subval) try: logger.debug("webhook post: " + str(url) + " : " + str(notification)) #result = http.post(url, data=payload, auth=auth, timeout=2.0, verify=verify) headers = {'Content-Type': 'application/json'} result = http.anchy_post(url, data=payload, auth=auth, timeout=2.0, verify=verify, headers=headers) logger.debug("webhook response: " + str(result)) return (True) except Exception as err: raise Exception( "failed to post notification to webhook - exception: " + str(err)) logger.debug( "warning: notification generated, but no matching webhook could be found in config to send it to - dropping notification" ) return (False)