コード例 #1
0
ファイル: zensnpp.py プロジェクト: rubenhenriques/ZenDash
	def run(self):
		try:
			self.log.clear()

			while True:
				read = self.server.select()

				for socket in read:
					if self.server.accept(socket):
						try:
							client, ip, packet = self.server.recv()

							client = ClientProxy(client)

							self.server.attach(client)

							host = Util.hostname(ip)

							d = {'host': host}

							self.send(d)

							pkt = self.recv()

							self.sms(host, pkt['allow'], packet)
						except MyException:
							pass
					else:
						client = ClientProxy(socket)

						self.server.dettach(client)
		except KeyboardInterrupt:
			pass
コード例 #2
0
ファイル: zenstatus.py プロジェクト: rubenhenriques/ZenDash
	def start(self, ip):
		up = False

		host = Util.hostname(ip)

		for _ in range(self.conf['start']['retries']):
			if 'backup' in self.hosts[host] and self.hosts[host]['backup']:
				up = True

				break

			cmd = ['ssh', ip, 'service', 'serviced', 'start']

			check_call(cmd, stderr=PIPE)

			cmd = ['ssh', ip, 'service', 'serviced', 'status']

			output = check_output(cmd, stderr=PIPE)

			if 'running' not in output:
				sleep(self.conf['start']['timeout'])

				continue

			cmd = ['ssh', ip, 'serviced', 'service', 'start', 'Zenoss.core']

			output = check_output(cmd)

			if 'started' not in output:
				sleep(self.conf['start']['timeout'])

				continue

			up = True

			break

		if host in self.down:
			if up:
				self.mail(host, True)

				self.down.remove(host)
		else:
			if not up:
				self.mail(host, False)

				self.down.append(host)

		return up
コード例 #3
0
ファイル: zensmtp.py プロジェクト: rubenhenriques/ZenDash
	def process_message(self, peer, mailfrom, rcpttos, data):
		ip, _ = peer

		host = Util.hostname(ip)

		fr = '(%s, %s)' % (Util.repr(host), Util.repr(mailfrom))

		fr = '%s: %s' % (Util.repr('From'), fr)

		to = ', '.join(map(Util.repr, rcpttos))

		if len(rcpttos) > 1:
			to = '(%s)' % to

		to = '%s: %s' % (Util.repr('To'), to)

		msg = message_from_string(data)

		subject = Util.repr(msg['Subject'])

		subject = '%s: %s' % (Util.repr('Subject'), subject)

		debug = '(%s, %s, %s)' % (fr, to, subject)

		d = {'host': host}

		self.send(d)

		packet = self.recv()

		if packet['allow']:
			if Mail.send(mailfrom, rcpttos, data):
				self.log.info('Mail sent %s' % debug)
			else:
				self.log.critical('Mail not sent %s' % debug)
		else:
			self.log.info('Mail dropped %s' % debug)