Example #1
0
	def mail(self, host, success):
		status = 'up' if success else 'down'

		mail = DictUtil.copy(self.conf['mail'])

		mail['subject'] %= status.upper()
		mail['body'] %= host

		debug = DebugUtil.mail(self.conf['localhost']['name'], mail)

		if Mail.sendraw(mail):
			self.log.info('Mail sent %s' % debug)
		else:
			self.log.critical('Mail not sent %s' % debug)
Example #2
0
	def sms(self, host, allow, packet):
		i = isinstance(packet['to'], int)

		targets = [packet['to']] if i else packet['to']['phones']

		if not allow:
			debug = DebugUtil.sms(host, targets, packet['data'])

			self.log.info('Message dropped %s' % debug)

			return

		try:
			boxes = self.get()

			if all(d not in packet['data'] for d in self.conf['devices']):
				boxes = [boxes.pop(0)]

			for box in boxes:
				self.post(box, targets, packet['data'])

				smsfrom = {
					'host'	: host,
					'box'	: box
				}

				debug = DebugUtil.sms(smsfrom, targets, packet['data'])

				self.log.info('Message sent %s' % debug)
		except MyException:
			if i:
				self.log.critical('Test message not sent')

				return

			mail = DictUtil.copy(self.conf['mail'])

			mail['to'] = packet['to']['mails']
			mail['body'] = packet['data']

			debug = DebugUtil.mail(host, mail)

			if Mail.sendraw(mail):
				self.log.info('Mail sent %s' % debug)
			else:
				self.log.critical('Mail not sent %s' % debug)
Example #3
0
	def mail(self, up):
		status = 'up' if up else 'down'

		mail = DictUtil.copy(self.conf['mail'])

		mail['subject'] %= status.upper()

		body = self.mails[status].pop()

		if len(self.mails[status]) > 0:
			hosts = ', '.join(self.mails[status])

			body = '%s & %s' % (hosts, body)

		mail['body'] %= body

		debug = DebugUtil.mail(self.conf['localhost']['name'], mail)

		if Mail.sendraw(mail):
			self.log.info('Mail sent %s' % debug)
		else:
			self.log.critical('Mail not sent %s' % debug)