Esempio n. 1
0
                    time.sleep(CONF.watchdog()['interval'])
                except:
                    alarm_event.push_event('sonawatcher',
                                           'SONAWATCHER_DISCONNECT',
                                           'critical', 'normal',
                                           'sonawatcher server shutdown',
                                           str(datetime.now()))
                    conn.close()
                    LOG.exception()


if __name__ == "__main__":
    history_log = USER_LOG()
    history_log.set_log('event_history.log',
                        CONF.base()['log_rotate_time'],
                        CONF.base()['log_backup_count'])
    alarm_event.set_history_log(history_log)

    daemon = SonaWatchD(PIDFILE)

    if len(sys.argv) == 2:

        if 'start' == sys.argv[1]:
            try:
                daemon.start()
            except:
                pass

        elif 'stop' == sys.argv[1]:
            print "Stopping ..."
Esempio n. 2
0
    def run(self):
        db_log = USER_LOG()
        db_log.set_log('db.log',
                       CONF.base()['log_rotate_time'],
                       CONF.base()['log_backup_count'])

        pre_stat = dict()

        # DB initiation
        DB.db_initiation(db_log)

        # Start RESTful server
        try:
            REST_SVR.rest_server_start()
        except:
            print 'Rest Server failed to start'
            LOG.exception()
            self.exit()

        # Periodic monitoring
        if CONF.watchdog()['interval'] == 0:
            LOG.info("--- Not running periodic monitoring ---")
            while True:
                time.sleep(3600)
        else:
            LOG.info("--- Periodic Monitoring Start ---")
            history_log.write_log("--- Event History Start ---")

            conn = DB.connection()

            exitFlag = False
            while True:
                try:
                    i = 0
                    while i < 3:
                        i = i + 1
                        # check rest server
                        try:
                            url = 'http://' + socket.gethostbyname(
                                socket.gethostname()) + ':' + str(CONF.rest(
                                )['rest_server_port']) + '/alive-check'

                            cmd = 'curl -X GET \"' + url + '\"'
                            LOG.info('cmd = ' + cmd)
                            result = Popen(cmd,
                                           stdout=PIPE,
                                           stderr=PIPE,
                                           shell=True)
                            output, error = result.communicate()

                            if result.returncode != 0:
                                LOG.info('REST SERVER CHECK FAIL [' + str(i) +
                                         ']')

                                if i == 3:
                                    LOG.info('fail to check rest server.')
                                    alarm_event.push_event(
                                        'sonawatcher',
                                        'SONAWATCHER_DISCONNECT', 'critical',
                                        'normal',
                                        'sonawatcher server shutdown',
                                        str(datetime.now()))
                                    conn.close()
                                    exitFlag = True
                                    self.exit()
                                    break
                            else:
                                break

                        except:
                            LOG.exception()

                    if exitFlag:
                        break

                    pre_stat = watchdog.periodic(conn, pre_stat, db_log)

                    time.sleep(CONF.watchdog()['interval'])
                except:
                    alarm_event.push_event('sonawatcher',
                                           'SONAWATCHER_DISCONNECT',
                                           'critical', 'normal',
                                           'sonawatcher server shutdown',
                                           str(datetime.now()))
                    conn.close()
                    LOG.exception()
Esempio n. 3
0
                    pre_stat = watchdog.periodic(conn, pre_stat, db_log)

                    time.sleep(CONF.watchdog()['interval'])
                except:
                    alarm_event.push_event('SimpleFabricWatchd', 'PROC', 'down', 'normal', [], str(datetime.now()), False)
                    conn.close()
                    LOG.exception()


if __name__ == "__main__":

    # change to script directory for relative CONFIG_FILE path
    os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
     
    CONF.init()
    LOG.init(CONF.base()['log_file_name'])
    history_log = USER_LOG()
    history_log.set_log('event_history.log', CONF.base()['log_rotate_time'], CONF.base()['log_backup_count'])
    alarm_event.set_history_log(history_log)

    daemon = SimpleFabricWatchD(CONF.get_pid_file())

    if len(sys.argv) == 2:

        if 'start' == sys.argv[1]:
            daemon.start()

        elif 'stop' == sys.argv[1]:
            print "Stopping ..."
            alarm_event.push_event('SimpleFabricWatchd', 'PROC', 'down', 'up', [], str(datetime.now()), True)
            daemon.stop()