Example #1
0
 def handleconnection(self):
     try:
         data = str(self.transnit_data())
         #data = 'test'
         print data
         logging.info(("Otomat agent started Successfully!"))
         while True:
             try:
                 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                 s.connect((self.host, int(self.port)))
                 logging.info((
                     "Otomat agent has been successfully connected to the server!!"
                 ))
                 s.sendall(data)
                 logging.debug(data)
                 buf = s.recv(8092)
                 if not len(data): break
                 s.close()
             except:
                 continue
                 logging.error(
                     'socket.error: [Errno 111] Connection refused')
             finally:
                 time.sleep(300)
     except:
         logging.error('The socket connect to the server failed!!!')
Example #2
0
	def  handleconnection(self,clientconn):
		"""handle an incoming connection."""
		logging.info("Received new Client %s connection.",  clientconn.getpeername())
		try:
			logging.debug("Got connection from %s",  clientconn.getpeername())
			if (active_count()-1) >= self.MaxThreads:
				clientconn.close()
				return
			"""Main loop of client-process threads."""
			name = current_thread().getName()
			clientconn.sendall('Greetings. You are being serviced by recviled' )
			while True:
				data = clientconn.recv(4096)
				if  not len(data):
					logging.warning(("Did not receive the client data!"))
					break

				clientconn.sendall(data)
				recv_data = eval(data)
				#print   data
				print recv_data
				logging.debug(data)
				self.pysql(recv_data)
		except (KeyboardInterrupt, SystemExit):
			raise
		except:
			traceback.print_exc()
		#close the connection
		try:
			clientconn.close()
		except KeyboardInterrupt:
			raise
		except:
			traceback.print_exc()
Example #3
0
    def handleconnection(self, clientconn):
        """handle an incoming connection."""
        logging.info("Received new Client %s connection.",
                     clientconn.getpeername())
        try:
            logging.debug("Got connection from %s", clientconn.getpeername())
            if (active_count() - 1) >= self.MaxThreads:
                clientconn.close()
                return
            """Main loop of client-process threads."""
            name = current_thread().getName()
            clientconn.sendall('Greetings. You are being serviced by recviled')
            while True:
                data = clientconn.recv(4096)
                if not len(data):
                    logging.warning(("Did not receive the client data!"))
                    break

                clientconn.sendall(data)
                recv_data = eval(data)
                #print   data
                print recv_data
                logging.debug(data)
                self.pysql(recv_data)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            traceback.print_exc()
        #close the connection
        try:
            clientconn.close()
        except KeyboardInterrupt:
            raise
        except:
            traceback.print_exc()
Example #4
0
	def  startthread(self):
		# Called by handleconnection when a new thread is need.
		# Note:lockpool is already acquired when this fuction is called.
		logging.info(("Starting netw Client processor thread."))
		global queue
		threads = []
		pool = self.MaxThreads
		t = Thread(target = self.handleconnection(),args = (clientconn,queue))
		for x in xrange(1, pool+1):
			threads.append(t)
		for i in threads:
			t.setDaemon(1)
			t.start()
Example #5
0
 def startthread(self):
     # Called by handleconnection when a new thread is need.
     # Note:lockpool is already acquired when this fuction is called.
     logging.info(("Starting netw Client processor thread."))
     global queue
     threads = []
     pool = self.MaxThreads
     t = Thread(target=self.handleconnection(), args=(clientconn, queue))
     for x in xrange(1, pool + 1):
         threads.append(t)
     for i in threads:
         t.setDaemon(1)
         t.start()
Example #6
0
def main(argv=sys.argv[1:]):
	create_pdf = pdf.create_pdf()
	logging.info(("The otomat-generate-pdf-server has been launched successfully !!!"))
	while True:
		# now is 0
		n = time.localtime(time.time())
		now = str(n.tm_hour)+str(n.tm_min)
		print "This is test hours:%s" % (now)
		# week is 6
		cmd = 'date +%w'
		day_today = shell.shell_cmd(cmd)
		day_week = day_today[0].split()[0]
		# day is 1
		day_month = str(datetime.date.today().day)
		# Beginning of month
		if (now == '10') and (day_week == '6'):
			create_pdf.create_pdf_report('day')
			create_pdf.create_pdf_report('week')
			logging.info((" System generated weekly to complete successfully !!!"))
			print 'weekend'
		if (now == '10') and (day_month == '1'):
			create_pdf.create_pdf_report('day')
			create_pdf.create_pdf_report('month')
			logging.info((" System generated monthly to complete successfully !!!"))
			print 'month end'
		if (now == '1030'):
			create_pdf.create_pdf_report('day')
			logging.info((" System generated daily to complete successfully !!!"))
			print 'day end'
		
		print "This is test end !!" 
		time.sleep(60)
		continue
Example #7
0
	def listener(self):
                s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
		s.bind((self.host,int(self.port)))
		s.listen(5)
		logging.info(("The otomat-server has been launched successfully "))
		while True:
			try:
				clientconn, clientaddr = s.accept()
			except (KeyboardInterrupt,SystemError):
				raise
				logging.error(("The otomat-server start  failure"))
			except:
				traceback.print_exc()
				logging.error(trackback.print_exc())
				logging.error(("The otomat-server start  failure"))
				continue
			self.handleconnection(clientconn)
Example #8
0
 def listener(self):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     s.bind((self.host, int(self.port)))
     s.listen(5)
     logging.info(("The otomat-server has been launched successfully "))
     while True:
         try:
             clientconn, clientaddr = s.accept()
         except (KeyboardInterrupt, SystemError):
             raise
             logging.error(("The otomat-server start  failure"))
         except:
             traceback.print_exc()
             logging.error(trackback.print_exc())
             logging.error(("The otomat-server start  failure"))
             continue
         self.handleconnection(clientconn)
Example #9
0
    def handleconnection(self):
		try:
			data = str(self.transnit_data())
			#data = 'test'
			print data
			logging.info(("Otomat agent started Successfully!"))
			while True:
                                try:
				    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
				    s.connect((self.host,int(self.port)))
				    logging.info(("Otomat agent has been successfully connected to the server!!"))
				    s.sendall(data)
				    logging.debug(data)
				    buf = s.recv(8092)
				    if not len(data): break
				    s.close()
                                except:
                                        continue
                                        logging.error('socket.error: [Errno 111] Connection refused')
                                finally:
				    time.sleep(300)
		except:
			logging.error('The socket connect to the server failed!!!')
Example #10
0
def main(argv=sys.argv[1:]):
    t = rrdtool_data_collector.rrdtool_collector(argv)
    garph_day = rrdtool_drafting.graph_rrdtool(argv)
    garph_week = rrdtool_drafting.graph_rrdtool(argv)
    garph_month = rrdtool_drafting.graph_rrdtool(argv)
    logging.info(
        ("The otomat-report-server has been launched successfully !!!"))
    while True:
        t.rrdb()
        t.rrdb_update()
        # now is 0
        n = time.localtime(time.time())
        now = str(n.tm_hour) + str(n.tm_min)
        print "This is test hours:%s" % (now)
        # week is 6
        cmd = 'date +%w'
        day_today = shell.shell_cmd(cmd)
        day_week = day_today[0].split()[0]
        print "This is test day_week:%s" % (day_week)
        # day is 1
        day_month = str(datetime.date.today().day)
        # Beginning of month
        if (now == '01' or now == '02' or now == '03' or now == '04'
                or now == '05') and (day_week == '6'):
            garph_day.graph_rrdtool('-1d')
            garph_week.graph_rrdtool('-1w')
            logging.info(
                (" Garph generated weekly to complete successfully !!!"))
            print 'weekend'
        if (now == '01' or now == '02' or now == '03' or now == '04'
                or now == '05') and (day_month == '1'):
            garph_day.graph_rrdtool('-1d')
            garph_week.graph_rrdtool('-1M')
            logging.info(
                (" Garph generated monthly to complete successfully !!!"))
            print 'month end'
        if (now == '01' or now == '02' or now == '03' or now == '04'
                or now == '05'):
            garph_day.graph_rrdtool('-1d')
            logging.info(
                (" Garph generated daily to complete successfully !!!"))
            print 'day end'

        print "This is test end !!"
        time.sleep(300)
        continue
Example #11
0
def main(argv=sys.argv[1:]):
	t = rrdtool_data_collector.rrdtool_collector(argv)
	garph_day = rrdtool_drafting.graph_rrdtool(argv)
	garph_week = rrdtool_drafting.graph_rrdtool(argv)
	garph_month = rrdtool_drafting.graph_rrdtool(argv)
	logging.info(("The otomat-report-server has been launched successfully !!!"))
	while True:
		t.rrdb()
		t.rrdb_update()
		# now is 0
		n = time.localtime(time.time())
		now = str(n.tm_hour)+str(n.tm_min)
		print "This is test hours:%s" % (now)
		# week is 6
		cmd = 'date +%w'
		day_today = shell.shell_cmd(cmd)
		day_week = day_today[0].split()[0]
		print "This is test day_week:%s" % (day_week)
		# day is 1
		day_month = str(datetime.date.today().day)
		# Beginning of month
		if (now == '01' or now == '02' or now == '03' or now == '04' or now == '05') and (day_week == '6'):
			garph_day.graph_rrdtool('-1d')
			garph_week.graph_rrdtool('-1w')
			logging.info((" Garph generated weekly to complete successfully !!!"))
			print 'weekend'
		if (now == '01' or now == '02' or now == '03' or now == '04' or now == '05') and (day_month == '1'):
			garph_day.graph_rrdtool('-1d')
			garph_week.graph_rrdtool('-1M')
			logging.info((" Garph generated monthly to complete successfully !!!"))
			print 'month end'
		if (now == '01' or now == '02' or now == '03' or now == '04' or now == '05'):
			garph_day.graph_rrdtool('-1d')
			logging.info((" Garph generated daily to complete successfully !!!"))
			print 'day end'
		
		print "This is test end !!" 
		time.sleep(300)
		continue