Question

I currently have a working DSLAM Management site for DSL connections. Currently want I want to get working is to have the DSLAM status update on its own, by automatically pinging the DSLAM ip address. If a request is good, then it will return boolean=True and save, else boolean=False and save. So far its not working and not sure where to go from here.

models.py

from django.db import models
import os,sys

class DslamManager(models.Manager):
    def dslam_status(self, ip_address):
        if os.system('ping' + ip_address):
            dslam_status = super(DslamManager, self).get(ip_address)
            dslam_status = True
            dslam_status.save()
        else:
            dslam_status = super(DslamManager, self)
            dslam_status = False
            dslam_status.save()


class Location(models.Model):
    location_name = models.CharField(max_length=30)
    island_name = models.CharField(max_length=30)

    class Meta:
        ordering = ['location_name']

    def __unicode__(self):
        return self.location_name


class Dslam(models.Model):
    dslam_name = models.CharField(max_length=32)
    ip_address = models.CharField(max_length=128)
    location = models.ForeignKey(Location)
    notes = models.TextField(blank=True)
    dslam_status = models.BooleanField()
    objects = DslamManager()

    class Meta:
        ordering = ['location', 'id']
    
    def __unicode__(self):
        return self.dslam_name
Was it helpful?

Solution

I sort of fixed this by adding it to the ModelAdmin. It just takes a bit of time to refresh, but it's because its trying to ping a list of IP addreses.

list_display = ('DSLAM_STATUS',)

def DSLAM_STATUS(self, obj):

    if os.system('ping -w 1 -n 1 ' + obj.ip_address):
        DSLAM_STATUS = False
    else:
        DSLAM_STATUS = True
    return DSLAM_STATUS

DSLAM_STATUS.boolean = True
DSLAM_STATUS.allow_tags = True

This only works some of the time, but I believe the time it takes to ping the ip_address is too quick at times.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top