Пример #1
0
    def run(self):
        # As long as we weren't asked to stop, try to take new data from the
        # queue. The tasks are taken with a blocking 'get', so no CPU
        # cycles are wasted while waiting.
        params = config.getParams(db_name)
        folder = params["path"][1]
        if folder[-1] != "/":
            folder = folder + "/"

        print "Writer Started"
        while True:
            print "Reading"
            msg = self.writer_q.get()
            print "AAAAAAAAAAA" + str(msg.data)
            if msg is None:  # This will probably never reached
                print "None Received"
                continue
#        self.writeLog(msg)
# if it is message add timestamp to the message
            if msg.data[0] == '#' and msg.data[-1] == ';':
                col = msg.data[1:-1].split(',')
                d_out = col[0] + "," + str(
                    msg.millis) + "," + msg.ip + "," + ",".join(col[1:])
                file = col[0]
                writeLog(folder, file, msg.ts, d_out)
            elif msg.data[0] == '$' and msg.data[-1] == ';':
                print "$$$$$$ is " + msg.data
                # $ needs to be handled in a different way
                col = msg.data[1:-1].split(',')
                file = col[0]
                d_out = col[0] + "," + str(
                    msg.millis) + "," + msg.ip + "," + ",".join(col[1:])
                writeLog(folder, file, msg.ts, d_out)
                if col[0] == "shutdown":
                    break
                if col[0] == "set":
                    if len(col) == 3:
                        config.setParam(db_name, col[1], col[2])
                        params = config.getParams(db_name)
                        folder = params["path"][1]
                        if folder[-1] != "/":
                            folder = folder + "/"

            else:
                file = "Error"
                d_out = str(msg.millis) + "," + msg.ip + "," + msg.data
                writeLog(folder, file, msg.ts, d_out)

            print "logWriter", msg.data
Пример #2
0
  def run(self):
    # As long as we weren't asked to stop, try to take new data from the
    # queue. The tasks are taken with a blocking 'get', so no CPU
    # cycles are wasted while waiting.
    params = config.getParams(db_name)
    folder = params["path"][1]
    if folder[-1] != "/":
      folder = folder + "/"

    print "Writer Started"
    while True:
      print "Reading"
      msg = self.writer_q.get()
      print "AAAAAAAAAAA" + str(msg.data)
      if msg is None: # This will probably never reached 
        print "None Received"
        continue
#        self.writeLog(msg)
      # if it is message add timestamp to the message 
      if msg.data[0] == '#' and msg.data[-1] == ';': 
        col =  msg.data[1:-1].split(',')
        d_out  = col[0] + "," + str(msg.millis)  + "," + msg.ip + "," + ",".join(col[1:])
        file = col[0]
        writeLog(folder,file,msg.ts,d_out)
      elif msg.data[0] == '$' and msg.data[-1] == ';':
        print "$$$$$$ is " + msg.data
		# $ needs to be handled in a different way
        col =  msg.data[1:-1].split(',')
        file = col[0]
        d_out  = col[0] + "," + str(msg.millis)  + "," + msg.ip + "," + ",".join(col[1:])
        writeLog(folder,file,msg.ts,d_out)
        if col[0] == "shutdown":
          break;
        if col[0] == "set":
          if len(col) == 3:
            config.setParam(db_name,col[1],col[2])
            params = config.getParams(db_name)
            folder = params["path"][1]
            if folder[-1] != "/":
              folder = folder + "/"
            
      else:
        file = "Error"
        d_out  = str(msg.millis)  + "," + msg.ip + "," + msg.data
        writeLog(folder,file,msg.ts,d_out)


      print "logWriter", msg.data
Пример #3
0
def getDataConfig(debug=False):

    config = c.getParams(debug=debug)

    feature_indices = list()
    target_indices = list()
    ind = -1

    with open(config['Data'], 'rb') as f:

        header = f.readline()
        features = [
            config['Features'].split(',')[i].strip().lower()
            for i in range(len(config['Features'].split(',')))
        ]
        targets = [
            config['Target'].split(',')[i].strip().lower()
            for i in range(len(config['Target'].split(',')))
        ]

        for i in range(len(header.split(','))):
            col = header.split(',')[i].strip()
            if col == 'timeindex':
                ind = i
            if col == 'id1':
                id1 = i
            if 'feature' in col or col == 'timeindex' or 'risk' in col or 'Category0' in col:
                feature_indices.append(i)
            if col in targets or col == 'timeindex':
                target_indices.append(i)

    return config, feature_indices, target_indices, ind, id1
Пример #4
0
  def run(self):

    HOST = [l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) if l][0][0]

    g_params = config.getParams(db_name)

    # Listning port
    PORT = int(g_params["port"][1]) 

    #insert proxy ip , port in datbase

    try:
      con = mdb.connect('10.129.23.100', 'rohit' , '' , 'BuildingAutomation'  )
      
      cur = con.cursor()
      cur.execute("select count(*) from proxy_info where proxy_id = %s ;",("proxy_" + str(proxy_id)))
      row = cur.fetchone()

      if str(row[0]) == "0":
        cur.execute("insert into proxy_info values(%s,%s,%s);",('proxy_'+proxy_id,HOST,str(PORT)))
        con.commit()
      else:
        cur.execute("update proxy_info set proxy_ip = %s , proxy_listen_port = %s where proxy_id = %s ;",(HOST , str(PORT) , 'proxy_' + proxy_id))
        con.commit()

    except mdb.Error, e:
      
      print "Error %d: %s" % (e.args[0], e.args[1])
      sys.exit(1)
Пример #5
0
  def run(self):

    HOST = [l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) if l][0][0]

    g_params = config.getParams(db_name)

    # Listning port
    PORT = int(g_params["port"][1]) 

    #insert proxy ip , port in datbase

    try:
      con = mdb.connect('10.129.23.100', 'rohit' , '' , 'BuildingAutomation'  )
      
      cur = con.cursor()
      cur.execute("select count(*) from proxy_info where proxy_id = %s ;",("proxy_" + str(proxy_id)))
      row = cur.fetchone()

      #if str(row[0]) == "0":
      #  cur.execute("insert into proxy_info values(%s,%s,%s);",('proxy_'+proxy_id,HOST,str(PORT)))
      #  con.commit()
      #else:
      #  cur.execute("update proxy_info set proxy_ip = %s , proxy_listen_port = %s where proxy_id = %s ;",(HOST , str(PORT) , 'proxy_' + proxy_id))
      #  con.commit()

    except mdb.Error, e:
      
      print "Error %d: %s" % (e.args[0], e.args[1])
      sys.exit(1)