allow checking by port
This commit is contained in:
parent
4a222c33ca
commit
e667f7043e
2 changed files with 29 additions and 0 deletions
18
sdbs_infra/dashboard/migrations/0006_service_port.py
Normal file
18
sdbs_infra/dashboard/migrations/0006_service_port.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-15 10:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dashboard', '0005_auto_20200613_2032'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='service',
|
||||
name='port',
|
||||
field=models.IntegerField(blank=True, help_text='Used for checking status', null=True),
|
||||
),
|
||||
]
|
|
@ -1,3 +1,4 @@
|
|||
import socket
|
||||
import urllib.request
|
||||
from enum import Enum
|
||||
from socket import timeout
|
||||
|
@ -20,6 +21,7 @@ class Service(OrderedModel):
|
|||
short_name = models.CharField(null=False, max_length=64)
|
||||
image = models.ImageField(null=True, blank=True, upload_to='services')
|
||||
description = models.TextField(null=True, blank=True)
|
||||
port = models.IntegerField(null=True, blank=True, help_text="Used for checking status")
|
||||
url = models.URLField()
|
||||
|
||||
def __str__(self):
|
||||
|
@ -34,6 +36,15 @@ class Service(OrderedModel):
|
|||
return None
|
||||
|
||||
def get_status(self):
|
||||
if self.port:
|
||||
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
location = ("localhost", self.port)
|
||||
result_of_check = a_socket.connect_ex(location)
|
||||
if result_of_check == 0:
|
||||
return ServiceStatus.OK
|
||||
else:
|
||||
return ServiceStatus.DOWN
|
||||
|
||||
if self.index_request and self.index_request.getcode() == 200:
|
||||
return ServiceStatus.OK
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue