Пример #1
0
def send_email(subject,
               message,
               objs=None,
               error_msg=None,
               from_addr='*****@*****.**'):
    """
	Form an email message and send it.
	"""
    # form the email message
    # error first...
    if error_msg:
        message += "\nError:\n"
        try:
            for line in str(error_msg).split("\n"):
                message += line
        except:
            message += "%s\n" % str(error_msg)

    # print the contents of the obj(s) if any
    if objs and type(objs) is not list:
        objs = [objs]
    elif not objs:
        objs = []
    for obj in objs:
        message += "\n\nObject: %s:\n" % obj
        for k, v in obj.data.iteritems():
            message += "  %s: %s\n" % (k, v)
    if not options.dry_run:
        if options.email:
            messenger.Email(from_addr, to_addrs, subject, message)
Пример #2
0
	def rsync(self):
		"""
		rsync handler:
			- checks for the dry_run flag
			- handles log entries
			- handles errors and notifications
		"""
		if options.dry_run:
			_command = "%s -n" % (self.command)
		else:
			_command = self.command

		self.start_time = datetime.datetime.now()
		start_message = "START: %s" % (_command)
		rsync_log.info(start_message)
		print "\t\t%s" % (_command)

		if options.run_exec:
			try:
				self._rsync(_command)
			except RsyncException,error:
				from_addr = '*****@*****.**'
				to_addrs = '*****@*****.**'
				#to_addrs = '*****@*****.**'
				subject = "Framestore mirror error"
				msg = "Error received from rsync:\n"
				msg+= "Command: %s\n" % _command
				msg+= "Logfile: %s\n" % rsync_log.abs_logfile
				# grab the end of the logfile to 
				# put in the email
				#rsync_log.flush()
				tail = commands.getoutput('tail %s' % rsync_log.abs_logfile)
				msg+= "\nTail of logfile...\n"
				msg+= tail
				messenger.Email(from_addr,to_addrs,subject,msg)
Пример #3
0
	def stone_wire(self,action):
		"""
		start / stop stone+wire
		"""
		if not options.sw_ctl:
			log.info("Stone and wire control not set (--sw). Will not try to %s stone+wire." % (action))
			return False
		if self.is_locked():
			message = "WARNING: %s is locked. Cannot shut down stone+wire" % (self.host)
			log.info(message)
			print "\t\t%s" % (message)
			log.info("Host is locked. Will not try to %s stone+wire." % (action))
			if options.email:
				subject = "DL Mirror Warning: Could not %s stone+wire" % (action)
				messenger.Email(from_addr,to_addrs,subject,message)
			return False

		if action == 'start':
			message = "Starting up stone+wire on %s" % (self.host)
			log.info(message)
			print "\t\t%s" % message
			# startup stone+wire 
			_out,_err = self._cmd('/etc/init.d/stone+wire start')
		elif action == 'stop':
			message = "Shutting down stone+wire on %s" % (self.host)
			log.info(message)
			print "\t\t%s" % message
			# shutdown stone+wire 
			_out,_err = self._cmd('/etc/init.d/stone+wire stop')
			#_out,_err = self._cmd('date')

		if _err:
			message = "ERROR starting / stopping stone+wire on %s" % (self.host)
			print "\t\t%s" % message
			log.info(message)
			if options.email:
				subject = "DL Mirror Error starting / stopping stone+wire on %s" % (self.host)
				messenger.Email(from_addr,to_addrs,subject,message)
			return False
		return True
        thread.start()

    ttl = queue.qsize()
    while not queue.empty():
        crnt = ttl - queue.qsize()
        pct = int(round(crnt / float(ttl) * 100))
        print "  Progress: %d of %d [%d%%]\r" % (crnt, ttl, pct),
        sys.stdout.flush()
        time.sleep(1)

    # one last update to catch the 100%
    time.sleep(1)
    crnt = ttl - queue.qsize()
    pct = int(round(crnt / float(ttl) * 100))
    print "  Progress: %d of %d [%d%%]" % (crnt, ttl, pct),
    sys.stdout.flush()

    stop = datetime.today()
    # email completion
    from_addr = '*****@*****.**'
    to_addrs = '*****@*****.**'
    subject = 'cr2_to_exr complete'
    message = "\nStarted at:    %s\n" % start
    message += "Completed at:  %s\n" % stop
    message += "Elapsed:       %s \n" % (stop - start)
    message += 'Command: %s\n' % (' '.join(sys.argv))
    print message
    messenger.Email(from_addr, to_addrs, subject, message)

    sys.exit()
Пример #5
0
def send_email(subject, message):
    from_addr = '*****@*****.**'
    messenger.Email(from_addr, to_addrs, subject, message)
Пример #6
0
def send_email(msg_type, message):
    from_addr = '*****@*****.**'
    subject = "Tina Restore %s" % msg_type
    messenger.Email(from_addr, to_addrs, subject, message)
Пример #7
0
	if not options.exclude_globals:
		#print "%-20s" % ("Global Files:")
		print "%-20s" % ("Global Files:")
		events = ["Global File rsync elapsed times:"]
		for host in m.hosts:
			rsync_log = host.rsync_log
			print "\t %s:" % (host.name)
			log.info("Syncing global files for %s" % host.name)
			start_time = datetime.datetime.now()
			host.run_queue('global')
			stop_time = datetime.datetime.now()
			events.append("%s: %s" % (host.name,stop_time-start_time))
		if options.email:
			msg = "\n".join(events)
			subject = "DL Mirror : Global Files"
			messenger.Email(from_addr,to_addrs,subject,msg)
	#
	#  CLIP DIRECTORIES
	#
	if not options.exclude_clips:
		#print "%-20s" % ("Clip Directories:")
		print "%-20s" % ("Clip Directories:")
		events = ["Clip Directory elapsed times:"]
		for stone in m.stones:
			host = Host(stone.host)
			rsync_log = host.rsync_log
			log.info("Syncing clip directories for %s (%s)" % (stone.name,stone.host))
			print "\t %s:%s" % (stone.host,stone.name)
			start_time = datetime.datetime.now()
			stone.run_queue('clip')
			stop_time = datetime.datetime.now()