Add Project Files
This commit is contained in:
22
hosts/management/commands/check_hosts.py
Normal file
22
hosts/management/commands/check_hosts.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import requests
|
||||
from django.core.management import BaseCommand
|
||||
from ...models import Host
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Check Hosts Django Management Command
|
||||
"""
|
||||
def handle(self, *args, **kwargs):
|
||||
hosts = Host.objects.all()
|
||||
for host in hosts:
|
||||
try:
|
||||
r = requests.get(host.host_name)
|
||||
if r.status_code == 200:
|
||||
host.status = True
|
||||
else:
|
||||
host.status = False
|
||||
|
||||
except requests.exceptions.RequestException:
|
||||
host.status = False
|
||||
host.save()
|
||||
Reference in New Issue
Block a user