コード例 #1
0
ファイル: Monit.py プロジェクト: optionalg/HA-OSCAR
def configure():
    rules.append(init_comment)

    FILE = open("/etc/default/monit", "w")
    FILE.write(init_comment + "\nstartup=1\n")
    FILE.close()

    #TODO: Make this part automatic.
    #Configure each component for Mon-IT
    #Apache Config:
    logger.subsection("adding apache config")
    rules.append("\n")
    rules.append(apache.configure())

    #Sshd Config:
    logger.subsection("adding sshd config")
    rules.append("\n")
    rules.append(ssh.configure())

    #Syslog Config:
    logger.subsection("adding syslog config")
    rules.append("\n")
    rules.append(syslog.configure())

    #TODO: Back up previous version of monitrc
    #We can now write out to config file
    FILE = open("/etc/monit/monitrc", "w")
    try:
        for line in rules:
            FILE.write(line)
        FILE.close()
    except IOError:
        exit.open("could not write monit rules")

    return 0
コード例 #2
0
ファイル: Monit.py プロジェクト: Nakranoth/HA-OSCAR
def configure():
  rules.append(init_comment)
   
  FILE = open("/etc/default/monit", "w")  
  FILE.write(init_comment+"\nstartup=1\n")
  FILE.close()

  #TODO: Make this part automatic.
  #Configure each component for Mon-IT
  #Apache Config:
  logger.subsection("adding apache config")
  rules.append("\n")
  rules.append(apache.configure())

  #Sshd Config:
  logger.subsection("adding sshd config")
  rules.append("\n")
  rules.append(ssh.configure())

  #Syslog Config:
  logger.subsection("adding syslog config")
  rules.append("\n")
  rules.append(syslog.configure())

  #TODO: Back up previous version of monitrc
  #We can now write out to config file
  FILE = open("/etc/monit/monitrc", "w")
  try:
    for line in rules:
      FILE.write(line)
    FILE.close()
  except IOError:
    exit.open("could not write monit rules")

  return 0
コード例 #3
0
ファイル: RemoteServices.py プロジェクト: Nakranoth/HA-OSCAR
 def server(self, hash_data, ip):
    hash_data['TYPE'] = self.data_type #Control flag
    #We serialize the data to be sent
    self.data = dumps(hash_data)
    #Create server and bind to ourselves
    try:
       server = SocketServer.TCPServer((ip, self.port), RemoteSystem)
       server.handle_request()
    except socket.error, err:
       exit.open("address already in use!")
コード例 #4
0
ファイル: RemoteServices.py プロジェクト: optionalg/HA-OSCAR
 def server(self, hash_data, ip):
     hash_data['TYPE'] = self.data_type  #Control flag
     #We serialize the data to be sent
     self.data = dumps(hash_data)
     #Create server and bind to ourselves
     try:
         server = SocketServer.TCPServer((ip, self.port), RemoteSystem)
         server.handle_request()
     except socket.error, err:
         exit.open("address already in use!")
コード例 #5
0
ファイル: RemoteServices.py プロジェクト: Nakranoth/HA-OSCAR
 def client(self, ip):
    #Create a TCP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    retry = True
    count = 0
    #Initiate connection
    while(retry == True):
       try:
          retry = False
          sock.connect((ip,self.port))
       except socket.error:
          if(count < 5 ):
             retry = True
             count += 1
             logger.subsection("listening server not ready. retrying in 2 mins...")
             time.sleep(120)
       except socket.timeout:
          exit.open("could not connect to remote server")
       except:
          exit.open("a major connection error has occured. check your address and retry installation.")
    #Receive data from server
    self.data = sock.recv(self.port)
    sock.close()
    #Convert serialized object to dictionary
    self.hash_data = loads(self.data)
    try:
       if(hash_data['TYPE'] != self.data_type):
          exit.open("primary and secondary server out of sync, restart installation")
    except:
       exit.open("failed to read remote data configuration restart installation")
    return self.hash_data
コード例 #6
0
ファイル: Gather.py プロジェクト: Nakranoth/HA-OSCAR
def getActiveModules():
   #Some globals
   all_modules = []
   active_modules = []
   temp_module = dict()
   database_driver = ddriver.DbDriver()
   
   #retreive all modules and check if state is 1 or 0
   try:
      all_modules = database_driver.select_db("Gather_Modules")
      try:
         for index in xrange(len(all_modules)):
            temp_module = all_modules[index]
            if (temp_module["STATE"] != "0"):
               active_modules.append(temp_module)
      except:
         logger.subsection("an error occured when processing module state")
   except:
      exit.open("fatal error, failed to load gather modules!")
   
   return active_modules
コード例 #7
0
def getActiveModules():
    #Some globals
    all_modules = []
    active_modules = []
    temp_module = dict()
    database_driver = ddriver.DbDriver()

    #retreive all modules and check if state is 1 or 0
    try:
        all_modules = database_driver.select_db("Gather_Modules")
        try:
            for index in xrange(len(all_modules)):
                temp_module = all_modules[index]
                if (temp_module["STATE"] != "0"):
                    active_modules.append(temp_module)
        except:
            logger.subsection("an error occured when processing module state")
    except:
        exit.open("fatal error, failed to load gather modules!")

    return active_modules
コード例 #8
0
ファイル: RemoteServices.py プロジェクト: optionalg/HA-OSCAR
 def client(self, ip):
     #Create a TCP socket
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     retry = True
     count = 0
     #Initiate connection
     while (retry == True):
         try:
             retry = False
             sock.connect((ip, self.port))
         except socket.error:
             if (count < 5):
                 retry = True
                 count += 1
                 logger.subsection(
                     "listening server not ready. retrying in 2 mins...")
                 time.sleep(120)
         except socket.timeout:
             exit.open("could not connect to remote server")
         except:
             exit.open(
                 "a major connection error has occured. check your address and retry installation."
             )
     #Receive data from server
     self.data = sock.recv(self.port)
     sock.close()
     #Convert serialized object to dictionary
     self.hash_data = loads(self.data)
     try:
         if (hash_data['TYPE'] != self.data_type):
             exit.open(
                 "primary and secondary server out of sync, restart installation"
             )
     except:
         exit.open(
             "failed to read remote data configuration restart installation"
         )
     return self.hash_data
コード例 #9
0
ファイル: RemoteServices.py プロジェクト: Nakranoth/HA-OSCAR
         exit.open("failed to read remote data configuration restart installation")
      return self.hash_data
 
 
   #@des: The server is responsible for listening for connections from a
   # client and sending data. In the event of
   # an error, it resends then quits
   #@param: hash_data, data packet to be sent
   #@param: ip, external ip address of localhost
 
   def server(self, hash_data, ip):
      hash_data['TYPE'] = self.data_type #Control flag
      #We serialize the data to be sent
      self.data = dumps(hash_data)
      #Create server and bind to ourselves
      try:
         server = SocketServer.TCPServer((ip, self.port), RemoteSystem)
         server.handle_request()
      except socket.error, err:
         exit.open("address already in use!")
      except:
         exit.open("some un-anticipated error occured!")
      finally:
         try:
            server.socket.close()
         except: pass
      logger.subsection("connection closed")
 
   def handle(self):
      self.request.send(self.data)
コード例 #10
0
ファイル: RemoteServices.py プロジェクト: optionalg/HA-OSCAR
            )
        return self.hash_data

    #@des: The server is responsible for listening for connections from a
    # client and sending data. In the event of
    # an error, it resends then quits
    #@param: hash_data, data packet to be sent
    #@param: ip, external ip address of localhost

    def server(self, hash_data, ip):
        hash_data['TYPE'] = self.data_type  #Control flag
        #We serialize the data to be sent
        self.data = dumps(hash_data)
        #Create server and bind to ourselves
        try:
            server = SocketServer.TCPServer((ip, self.port), RemoteSystem)
            server.handle_request()
        except socket.error, err:
            exit.open("address already in use!")
        except:
            exit.open("some un-anticipated error occured!")
        finally:
            try:
                server.socket.close()
            except:
                pass
        logger.subsection("connection closed")

    def handle(self):
        self.request.send(self.data)