How to send Email to customer when quota policy failure occurs for excess rate limit?

mpatil
New Member

Hi,

I am developing a proxy where email needs to be sent out to customers when they exceed requests over a certain number. I am trying to find out the best way to handle this functionality.

  • Is there an out of the box default feature from Apigee for such a case when quota policy failure occurs?
    (Unanswered or not clear: https://docs.apigee.com/api-platform/monetization/set-limit-notifications)
  • How do I set up email callout using javascript or python script in Apigee?
    check below python code snippet using python call execution at quota policy failure. I found above code snippet in one of the pages of Apigee community which is not working for me.

I have confusion over SMTP host,username and password.

import smtplib

from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText


smtpserver.connect()

host = flow.getVariable("emailhost");

port = flow.getVariable("emailport");


username = flow.getVariable("emailusername");

password = flow.getVariable("emailpassword");

mailTo = flow.getVariable("email");

bodyMessage = "Quota Exceeded";

subject = flow.getVariable("emailsubject");

mailFrom = flow.getVariable("emailfrom");

ssl = 'true';

auth = 'true';

msg = MIMEMultipart()

msg['Subject'] = subject

msg['From'] = mailFrom

msg['To'] = mailTo


msg.attach( MIMEText(bodyMessage, 'html'))

smtpserver = smtplib.SMTP(host,port)

if ssl=='true':

    smtpserver.ehlo()

    smtpserver.starttls()

    smtpserver.ehlo

if auth=='true':

    smtpserver.login(username, password)

    smtpserver.sendmail(mailFrom, mailTo, msg.as_string())

    smtpserver.quit()
0 3 188
3 REPLIES 3

Not applicable

I have come across this scenario earlier. We didn't have any notification in apigee. We had used two ways. one was with monitoring through nagios and notifying when there is a quota excess limit error. Another way is setting notification in KIBANA logger when there is a quota error.

But third-party tools like Kibana can get called in proxy when there is quota policy failure?
As the tools I have are within network and Apigee will be in google cloud right

mpatil
New Member

I used API monitoring Alerts. I found a solution for my problem over there. I did setup with faultcode of 429 and it shows alerts via email