Exemplo n.º 1
0
    def updateScilentVm(self):
        from pinger import Pinger

        alivestatus = self.engine.getModel('AliveStatus')
        ne_server = self.engine.getModel('NEServer')

        dtnow = datetime.now()
        interval = dtnow - timedelta(minutes=self.interval)

        ping = Pinger()
        hosts = []

        for alive_rs in self.db_session.query(alivestatus).filter(
                alivestatus.updated_at < interval):
            ne_rs = self.db_session.query(ne_server).filter(
                ne_server.uuid == alive_rs.uuid).one()
            if ping.ping(ne_rs.nic2):
                self.db_session.query(alivestatus).filter_by(uuid=uuid).update(
                    {'updated_at': datetime.now()})
                self.db_session.commit()
Exemplo n.º 2
0
if __name__ == '__main__':

    monitor_port = 5000

    app_port = 5001
    if len(sys.argv) == 2:
        app_port = sys.argv[1]
    interval = 60
    log.info('PORT {} ARGS {}'.format(app_port, len(sys.argv)))
    log.info(sys.argv)

    pinger = Pinger(app_name='reporting',
                    app_host='127.0.0.1',
                    app_port=app_port,
                    monitor_host='127.0.0.1',
                    monitor_port=monitor_port,
                    interval=interval)
    rt = RepeatedTimer(interval=interval, function=pinger.ping)

    try:
        # app = Flask(__name__)
        # app.run(host='127.0.0.1', port=5001)
        app = connexion.App(__name__, specification_dir='./openapi')
        app.add_api('swagger.yml')
        # NOTE: debug=True causes the restart
        pinger.ping()
        app.run(host='127.0.0.1', port=app_port, debug=False)
    finally:
        pinger.shutdown()
        rt.stop()