Exemplo n.º 1
0
	def post(self):
		recepient_id = self.get_argument('recepient', None)

		recepient = email_recepient_model.get_by_id(recepient_id)
	
		send_mail(recepients=[recepient],
			subject='Amon test email',
			template='test')

		self.session['message'] = 'Test email sent, check your inbox({0})'.format(recepient['email'])
		self.redirect(self.reverse_url('test_email'))
Exemplo n.º 2
0
    def post(self):
        recepient_id = self.get_argument('recepient', None)

        recepient = email_recepient_model.get_by_id(recepient_id)

        send_mail(recepients=[recepient],
                  subject='Amon test email',
                  template='test')

        self.session[
            'message'] = 'Test email sent, check your inbox({0})'.format(
                recepient['email'])
        self.redirect(self.reverse_url('test_email'))
Exemplo n.º 3
0
	def send_alerts(self, test=None):
		rules = alerts_model.get_all_alerts()
		alerts = []
		for rule in rules:
			history = rule.get('history', [])
			threshold = rule.get('threshold', 1)
			mute = rule.get('mute', False)

			last_trigger = rule.get('last_trigger', 1)
			trigger = True if int(last_trigger) >= int(threshold) else False

			if trigger is True:
				# Don't append rules for non exisiting servers, check if the alert is muted
				if mute == False:
					alerts.append(rule)

		if len(alerts)> 0:
			# Send emails for each alert
			for alert in alerts: 
				rule_type = alert.get("rule_type", "server") 

				if rule_type == 'process':
					title = "{0}/{1}".format(alert.get('process', ''), alert.get('check',''))
				else:
					title = alert.get('metric', 'System') 
				

				email_recepients = alert.get('email_recepients', [])

				if len(email_recepients) > 0:
					try:
						send_mail(template_data=alert, 
							recepients=email_recepients,
							subject='Amon alert - ({0})'.format(title),
							template='{0}_alert'.format(rule_type)
							)
					except Exception, e:
						logging.exception("Error sending an alert email")
				

				sms_recepients = alert.get('sms_recepients', [])
				
				if len(sms_recepients) > 0:
					try:
						send_sms(alert=alert,
							recepients=sms_recepients,
							template='{0}_alert.txt'.format(rule_type))
					except Exception, e:
						logging.exception("Error sending an alert SMS")
Exemplo n.º 4
0
    def send_alerts(self, test=None):
        rules = alerts_model.get_all_alerts()
        alerts = []
        for rule in rules:
            history = rule.get('history', [])
            threshold = rule.get('threshold', 1)
            mute = rule.get('mute', False)

            last_trigger = rule.get('last_trigger', 1)
            trigger = True if int(last_trigger) >= int(threshold) else False

            if trigger is True:
                # Don't append rules for non exisiting servers, check if the alert is muted
                if mute == False:
                    alerts.append(rule)

        if len(alerts) > 0:
            # Send emails for each alert
            for alert in alerts:
                rule_type = alert.get("rule_type", "server")

                if rule_type == 'process':
                    title = "{0}/{1}".format(alert.get('process', ''),
                                             alert.get('check', ''))
                else:
                    title = alert.get('metric', 'System')

                email_recepients = alert.get('email_recepients', [])

                if len(email_recepients) > 0:
                    try:
                        send_mail(template_data=alert,
                                  recepients=email_recepients,
                                  subject='Amon alert - ({0})'.format(title),
                                  template='{0}_alert'.format(rule_type))
                    except Exception, e:
                        logging.exception("Error sending an alert email")

                sms_recepients = alert.get('sms_recepients', [])

                if len(sms_recepients) > 0:
                    try:
                        send_sms(alert=alert,
                                 recepients=sms_recepients,
                                 template='{0}_alert.txt'.format(rule_type))
                    except Exception, e:
                        logging.exception("Error sending an alert SMS")