24 lines
811 B
Python
24 lines
811 B
Python
from django.apps import AppConfig
|
||
from django.conf import settings
|
||
|
||
def check_server_connection():
|
||
from .ssh_client import SSHManager # utils yerine ssh_client'dan import et
|
||
from .models import SSHCredential
|
||
|
||
# Tüm SSH bağlantılarını kontrol et
|
||
for credential in SSHCredential.objects.all():
|
||
ssh_manager = SSHManager(credential)
|
||
is_online = ssh_manager.check_connection()
|
||
|
||
# Bağlantı durumunu güncelle
|
||
credential.is_online = is_online
|
||
credential.save(update_fields=['is_online', 'last_check'])
|
||
|
||
ssh_manager.close()
|
||
|
||
class SshManagerConfig(AppConfig):
|
||
default_auto_field = 'django.db.models.BigAutoField'
|
||
name = 'ssh_manager'
|
||
|
||
def ready(self):
|
||
import ssh_manager.signals # signals'ı import et |