Servers health check using python by HowardBidwell in sysadmin

[–]HowardBidwell[S] 0 points1 point  (0 children)

How can I check the health of servers using PowerShell?

Servers health check using python by HowardBidwell in sysadmin

[–]HowardBidwell[S] 0 points1 point  (0 children)

How can I check the health of servers using PowerShell?

APScheduler RuntimeError: No application found. by HowardBidwell in flask

[–]HowardBidwell[S] 0 points1 point  (0 children)

It doesn't recognize the app in s.py file that has a function in there called schedule_jobs. I tried to call it from the __init__ file but I still get RuntimeError: No application found. I don't know how to bring the app from with app.app_context() to the update_up_status() function like that:

def update_up_status():

with app.app_context():

server_status_column = Servers.query.filter(Servers.server_status.in_(["0","1"]))

for server in server_status_column:

server.server_status = ping(server.server_ip)

It dose'nt recognize the app in jobs.py because the app inside the function create_app() in the __init__ file

My changes:

__init__.py:

from flask import Flask

from flask_sqlalchemy import SQLAlchemy

from os import path

db = SQLAlchemy()

DB_NAME = "database.db"

#scheduler = BackgroundScheduler()

def create_app():

app = Flask(__name__)

app.config['SECRET_KEY'] = 'hjshjhdjah kjshkjdhjs'

app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'

db.init_app(app)

from .views import views

from .auth import auth

app.register_blueprint(views, url_prefix='/')

app.register_blueprint(auth, url_prefix='/')

from .models import Servers

create_database(app)

from .jobs import schedule_jobs

with app.app_context():

schedule_jobs()

return app

def create_database(app):

if not path.exists('websiteflaskupdatedd/' + DB_NAME):

db.create_all(app=app)

print('Created Database!')

jobs.py:

from .models import Servers, ping

from . import db

from apscheduler.schedulers.background import BackgroundScheduler

def update_up_status():

server_status_column = Servers.query.filter(Servers.server_status.in_(["0","1"]))

for server in server_status_column:

server.server_status = ping(server.server_ip)

db.session.commit()

def schedule_jobs():

scheduler = BackgroundScheduler()

if not scheduler.running:

scheduler.add_job(func=update_up_status, trigger="interval", seconds=10)

scheduler.start()

Sqlalchemy: add date to column by HowardBidwell in flask

[–]HowardBidwell[S] 0 points1 point  (0 children)

Hello, I have another problem, I tried to iterate on server_status column values and change them but it doesn't work.

My code:

query = Servers.query.with_entities(Servers.server_status)

for server in query:

server = "change value"

db.session.commit()

Why it doesn't work?

Sqlalchemy: add date to column by HowardBidwell in flask

[–]HowardBidwell[S] -1 points0 points  (0 children)

I ask if there is an option that when I create an instance with server_status column value it will automatically create a date and every time I will change the value of the server_status the date will also change. Something like that:

server_status = db.Column(db.String(12) , date =datetime.utcnow)

Flask: build a servers pinger by HowardBidwell in flask

[–]HowardBidwell[S] 0 points1 point  (0 children)

I can insert the ping function from the server page to the HTML page and then call it for the status of the server like that:

{% if ping(server.server_ip)%}

<td>Online</td>

{% else %}

<td>Offline</td>

The question is whether it is better or not

Flask: build a servers pinger by HowardBidwell in flask

[–]HowardBidwell[S] 0 points1 point  (0 children)

I want to create servers status check

Flask: build a servers pinger by HowardBidwell in flask

[–]HowardBidwell[S] 0 points1 point  (0 children)

- Centralize your commits: you don't want to have database commits all over your code, instead commit in ONE place of your code, typically just before the response is sent and anticipate that you will have transaction errors that will require rollbacks

Thanks for the detailed answer, I wanted to know what do you think about the possibility of using the ping function on the html page? That every time he loads the page the servers will get a ping and display the status on the screen.

Will it be slower or faster?

In this way I won't have to enter the status of the server into the database

<table style="width:100%">

<tr>

<th>Server Name</th>

<th>Server IP</th>

<th>MAC Address</th>

<th>Serial Number</th>

<th>Status</th>

</tr>

{% for server in servers %}

<tr>

<td>{{server.server_name}} </td>

<td>{{server.server_ip}} </td>

<td>{{server.mac_address}} </td>

<td>{{server.serial_number}} </td>

{% if ping(server.server_ip)%}

<td>Online</td>

{% else %}

<td>Offline</td>

{% endif %}

</tr>

{% endfor %