Exemplo n.º 1
0
def stopnidus(pwd):
    """
     stop nidus storage manager.
     pwd: Sudo password
    """
    try:
        cmdline.service('nidusd',pwd,False)
        while cmdline.nidusrunning(wraith.NIDUSPID): time.sleep(1.0)
    except RuntimeError as e:
        return False
    else:
        return True
Exemplo n.º 2
0
def stopdyskt(pwd):
    """
     stop dyskt sensor
     pwd: Sudo password
    """
    try:
        cmdline.service('dysktd',pwd,False)
        while cmdline.nidusrunning(wraith.DYSKTPID): time.sleep(1.0)
    except RuntimeError as e:
        return False
    else:
        return True
Exemplo n.º 3
0
def startnidus(pwd):
    """
     start nidus server
     pwd: the sudo password
    """
    try:
        cmdline.service('nidusd',pwd)
        time.sleep(0.5)
        if not cmdline.nidusrunning(wraith.NIDUSPID): raise RuntimeError
    except RuntimeError:
        return False
    else:
        return True
Exemplo n.º 4
0
 def _chknidus(self):
     self._sv.set("Checking Nidus...")
     self._pb.step(0.5)
     if not cmdline.nidusrunning(wraith.NIDUSPID):
         self._sv.set("Starting Nidus")
         if startnidus(pwd):
             self._sv.set("Nidus started")
         else:
             self._sv.set("Failed to start Nidus")
     else:
         self._sv.set("Nidus already running")
     self._bnidus = True
     self._pb.step(2.0)
Exemplo n.º 5
0
 def _stopnidus(self):
     """
      stop nidus storage manager.
       NOTE: 1) no state checking done here
             2) assumes sudo password is entered
     """
     try:
         self.logwrite("Shutting down Nidus...",gui.LOG_NOTE)
         cmdline.service('nidusd',self._pwd,False)
         while cmdline.nidusrunning(wraith.NIDUSPID):
             self.logwrite("Nidus still processing data...",gui.LOG_NOTE)
             time.sleep(1.0)
     except RuntimeError as e:
         self.logwrite("Error shutting down Nidus: %s" % e,gui.LOG_ERR)
     else:
         self._setstate(_STATE_NIDUS_,False)
         self.logwrite("Nidus shut down")
Exemplo n.º 6
0
 def _startnidus(self):
     """
      start nidus storage manager
      NOTE: 1) no state checking done here
            2) assumes sudo password is entered
     """
     # attempt to start nidus
     try:
         self.logwrite("Starting Nidus...",gui.LOG_NOTE)
         cmdline.service('nidusd',self._pwd)
         time.sleep(0.5)
         if not cmdline.nidusrunning(wraith.NIDUSPID): raise RuntimeError('unknown')
     except RuntimeError as e:
         self.logwrite("Error starting Nidus: %s" % e,gui.LOG_ERR)
     else:
         self.logwrite("Nidus Started")
         self._setstate(_STATE_NIDUS_)
Exemplo n.º 7
0
 def _stopnidus(self):
     """
      stop nidus storage manager.
       NOTE: 1) no state checking done here
             2) assumes sudo password is entered
     """
     try:
         self.logwrite("Shutting down Nidus...", gui.LOG_NOTE)
         cmdline.service('nidusd', self._pwd, False)
         while cmdline.nidusrunning(wraith.NIDUSPID):
             self.logwrite("Nidus still processing data...", gui.LOG_NOTE)
             time.sleep(1.0)
     except RuntimeError as e:
         self.logwrite("Error shutting down Nidus: %s" % e, gui.LOG_ERR)
     else:
         self._setstate(_STATE_NIDUS_, False)
         self.logwrite("Nidus shut down")
Exemplo n.º 8
0
    def _updatestate(self):
        """ reevaluates internal state """
        # state of nidus
        if cmdline.nidusrunning(wraith.NIDUSPID): self._setstate(_STATE_NIDUS_)
        else: self._setstate(_STATE_NIDUS_,False)

        # state of dyskt
        if cmdline.dysktrunning(wraith.DYSKTPID): self._setstate(_STATE_DYSKT_)
        else:  self._setstate(_STATE_DYSKT_,False)

        # state of postgres i.e. store
        if cmdline.runningprocess('postgres'): self._setstate(_STATE_STORE_)
        else: self._setstate(_STATE_STORE_,False)

        # state of our connection - should figure out a way to determine if
        # connection is still 'alive'
        if self._conn: self._setstate(_STATE_CONN_)
        else: self._setstate(_STATE_CONN_,False)
Exemplo n.º 9
0
 def _startnidus(self):
     """
      start nidus storage manager
      NOTE: 1) no state checking done here
            2) assumes sudo password is entered
     """
     # attempt to start nidus
     try:
         self.logwrite("Starting Nidus...", gui.LOG_NOTE)
         cmdline.service('nidusd', self._pwd)
         time.sleep(0.5)
         if not cmdline.nidusrunning(wraith.NIDUSPID):
             raise RuntimeError('unknown')
     except RuntimeError as e:
         self.logwrite("Error starting Nidus: %s" % e, gui.LOG_ERR)
     else:
         self.logwrite("Nidus Started")
         self._setstate(_STATE_NIDUS_)
Exemplo n.º 10
0
    def _create(self):
        # read in conf file, exit on error
        msgs = [(time.strftime('%H:%M:%S'),
                 "Wraith v%s" % wraith.__version__,
                 gui.LOG_NOERR)]
        self._conf = readconf()
        if 'err' in self._conf:
            msgs.append((time.strftime('%H:%M:%S'),
                          "Configuration file is invalid. %s" % self._conf['err'],
                          gui.LOG_ERR))
            return

        # determine if postgresql is running
        if cmdline.runningprocess('postgres'):
            # update self,msg and connect
            msgs.append((time.strftime('%H:%M:%S'),
                         'PostgreSQL is running',
                         gui.LOG_NOERR))
            if not self._pwd: self._bSQL = True
            self._setstate(_STATE_STORE_)
            (self._conn,ret) = psqlconnect(self._conf['store'])
            if not self._conn is None: self._setstate(_STATE_CONN_)
            else:
                msgs.append((time.strftime('%H:%M:%S'),
                             "Error connecting to PostgreSQL: %s" % ret,
                             gui.LOG_ERR))
                return
        else:
            msgs.append((time.strftime('%H:%M:%S'),
                         "PostgreSQL is not running",
                         gui.LOG_WARN))
            msgs.append((time.strftime('%H:%M:%S'),
                         "Not connected to database",
                         gui.LOG_WARN))

        # nidus running?
        if cmdline.nidusrunning(wraith.NIDUSPID):
            msgs.append((time.strftime('%H:%M:%S'),
                         "Nidus is running",
                         gui.LOG_NOERR))
            self._setstate(_STATE_NIDUS_)
        else:
            msgs.append((time.strftime('%H:%M:%S'),
                         "Nidus is not running",
                         gui.LOG_WARN))

        # dyskt running?
        if cmdline.dysktrunning(wraith.DYSKTPID):
            msgs.append((time.strftime('%H:%M:%S'),
                         "DySKT is running",
                         gui.LOG_NOERR))
            self._setstate(_STATE_DYSKT_)
        else:
            msgs.append((time.strftime('%H:%M:%S'),
                         "DySKt is not running",
                         gui.LOG_WARN))

        # set initial state to initialized
        self._setstate(_STATE_INIT_)

        # adjust menu options accordingly
        self._menuenable()

        # show log and write messages
        self.viewlog()
        self.getpanel("log",True).delayedwrite(msgs)
Exemplo n.º 11
0
    if stop:
        # verify pwd has been set
        i = 2
        pwd = getpass.unix_getpass(prompt="Password [for %s]:" % getpass.getuser())
        while not cmdline.testsudopwd(pwd) and i > 0:
            pwd = getpass.unix_getpass(prompt="Incorrect password, try again:")
            i -= 1
        if not pwd: ap.error("Three incorrect password attempts")

        # stop DySKT, then Nidus, then PostgreSQL
        sd = sn = sp = True
        if cmdline.dysktrunning(wraith.DYSKTPID):
            ret = 'ok' if stopdyskt(pwd) else 'fail'
            print "Stopping DySKT\t\t\t\t[%s]" % ret
        else: print "DySKT not running"
        if cmdline.nidusrunning(wraith.NIDUSPID):
            ret = 'ok' if stopnidus(pwd) else 'fail'
            print "Stopping Nidus\t\t\t\t[%s]" % ret
        else: print "Nidus not running"
        if cmdline.runningprocess('postgres') and not exclude:
            ret = 'ok' if stoppsql(pwd) else 'fail'
            print "Stopping PostgreSQL\t\t\t[%s]" % ret
        else: print "PostgreSQL not running"
        sys.exit(0)

    # start specified services
    if sopts == 'nogui':
        # verify pwd is present
        i = 2
        pwd = getpass.unix_getpass(prompt="Password [for %s]:" % getpass.getuser())
        while not cmdline.testsudopwd(pwd) and i > 0:
Exemplo n.º 12
0
    def _initialize(self):
        """ initialize gui, determine initial state """
        # configure panel & write initial message
        # have to manually enter the desired size, as the menu does not expand
        # the visibile portion automatically
        self.tk.wm_geometry("300x1+0+0")
        self.tk.resizable(0,0)
        self.logwrite("Wraith v%s" % wraith.__version__)

        # read in conf file, exit on error
        confMsg = self._readconf()
        if confMsg:
            self.logwrite("Configuration file is invalid. " + confMsg,gui.LOG_ERR)
            return

        # determine if postgresql is running
        if cmdline.runningprocess('postgres'):
            self.logwrite('PostgreSQL is running',gui.LOG_NOTE)
            self._bSQL = True

            # update state
            self._setstate(_STATE_STORE_)

            curs = None
            try:
                # attempt to connect and set state accordingly
                self._conn = psql.connect(host=self._conf['store']['host'],
                                          dbname=self._conf['store']['db'],
                                          user=self._conf['store']['user'],
                                          password=self._conf['store']['pwd'])

                # set to use UTC and enable CONN flag
                curs = self._conn.cursor()
                curs.execute("set time zone 'UTC';")
                self._conn.commit()
                self._setstate(_STATE_CONN_)
                self.logwrite("Connected to database",gui.LOG_NOTE)
            except psql.OperationalError as e:
                if e.__str__().find('connect') > 0:
                    self.logwrite("PostgreSQL is not running",gui.LOG_WARN)
                    self._setstate(_STATE_STORE_,False)
                elif e.__str__().find('authentication') > 0:
                    self.logwrite("Authentication string is invalid",gui.LOG_ERR)
                else:
                    self.logwrite("Unspecified DB error occurred",gui.LOG_ERR)
                    self._conn.rollback()
                self.logwrite("Not connected to database",gui.LOG_WARN)
            finally:
                if curs: curs.close()
        else:
            self.logwrite("PostgreSQL is not running",gui.LOG_WARN)
            self.logwrite("Not connected to database",gui.LOG_WARN)

        # nidus running?
        if cmdline.nidusrunning(wraith.NIDUSPID):
            self.logwrite("Nidus is running")
            self._setstate(_STATE_NIDUS_)
        else:
            self.logwrite("Nidus is not running",gui.LOG_WARN)

        if cmdline.dysktrunning(wraith.DYSKTPID):
            self.logwrite("DySKT is running")
            self._setstate(_STATE_DYSKT_)
        else:
            self.logwrite("DySKT is not running",gui.LOG_WARN)

        # set initial state to initialized
        self._setstate(_STATE_INIT_)

        # adjust menu options accordingly
        self._menuenable()
Exemplo n.º 13
0
    def _initialize(self):
        """ initialize gui, determine initial state """
        # configure panel & write initial message
        # have to manually enter the desired size, as the menu does not expand
        # the visibile portion automatically
        self.tk.wm_geometry("300x1+0+0")
        self.tk.resizable(0, 0)
        self.logwrite("Wraith v%s" % wraith.__version__)

        # read in conf file, exit on error
        confMsg = self._readconf()
        if confMsg:
            self.logwrite("Configuration file is invalid. " + confMsg,
                          gui.LOG_ERR)
            return

        # determine if postgresql is running
        if cmdline.runningprocess('postgres'):
            self.logwrite('PostgreSQL is running', gui.LOG_NOTE)
            self._bSQL = True

            # update state
            self._setstate(_STATE_STORE_)

            curs = None
            try:
                # attempt to connect and set state accordingly
                self._conn = psql.connect(host=self._conf['store']['host'],
                                          dbname=self._conf['store']['db'],
                                          user=self._conf['store']['user'],
                                          password=self._conf['store']['pwd'])

                # set to use UTC and enable CONN flag
                curs = self._conn.cursor()
                curs.execute("set time zone 'UTC';")
                self._conn.commit()
                self._setstate(_STATE_CONN_)
                self.logwrite("Connected to database", gui.LOG_NOTE)
            except psql.OperationalError as e:
                if e.__str__().find('connect') > 0:
                    self.logwrite("PostgreSQL is not running", gui.LOG_WARN)
                    self._setstate(_STATE_STORE_, False)
                elif e.__str__().find('authentication') > 0:
                    self.logwrite("Authentication string is invalid",
                                  gui.LOG_ERR)
                else:
                    self.logwrite("Unspecified DB error occurred", gui.LOG_ERR)
                    self._conn.rollback()
                self.logwrite("Not connected to database", gui.LOG_WARN)
            finally:
                if curs: curs.close()
        else:
            self.logwrite("PostgreSQL is not running", gui.LOG_WARN)
            self.logwrite("Not connected to database", gui.LOG_WARN)

        # nidus running?
        if cmdline.nidusrunning(wraith.NIDUSPID):
            self.logwrite("Nidus is running")
            self._setstate(_STATE_NIDUS_)
        else:
            self.logwrite("Nidus is not running", gui.LOG_WARN)

        if cmdline.dysktrunning(wraith.DYSKTPID):
            self.logwrite("DySKT is running")
            self._setstate(_STATE_DYSKT_)
        else:
            self.logwrite("DySKT is not running", gui.LOG_WARN)

        # set initial state to initialized
        self._setstate(_STATE_INIT_)

        # adjust menu options accordingly
        self._menuenable()