|
@@ -12,13 +12,13 @@ class Command(BaseCommand):
|
|
|
def handle(self, *args, **options):
|
|
|
dell_iface_regex = re.compile('^Interface TenGigabitEthernet 0/(?P<id>[0-9]+)$')
|
|
|
ubnt_iface_regex = re.compile('^Interface Slot: 0 Port: (?P<id>[0-9]+) (Gigabit|10G) - Level$')
|
|
|
- status_regex = re.compile('^OK .* \((?P<status>up|down)\)')
|
|
|
+ status_regex = re.compile('\w+ - \[[\w-]+\] \((?P<status>up|down|admin down)\)')
|
|
|
for sw in Switch.objects.all():
|
|
|
up_count, down_count, unknown_count = sw.ports.filter(up=True).count(), sw.ports.filter(up=False).count(), sw.ports.filter(up__isnull=True).count()
|
|
|
up, down = [], []
|
|
|
hosts = from_livestatus('hosts', query=['Filter: host_name = %s' % sw.name], columns=['services_with_info'])
|
|
|
if len(hosts) != 1:
|
|
|
- return
|
|
|
+ continue
|
|
|
host = hosts[0]
|
|
|
for service in host.services_with_info:
|
|
|
description, _, _, info = service
|
|
@@ -32,12 +32,13 @@ class Command(BaseCommand):
|
|
|
continue
|
|
|
g = status_regex.match(info)
|
|
|
if not g:
|
|
|
+ self.stdout.write(self.style.WARNING("Switch %s port %d status unknown: %s" % (sw.name, port, info)))
|
|
|
continue
|
|
|
status = g.group('status')
|
|
|
if status == 'up':
|
|
|
up.append(port)
|
|
|
else:
|
|
|
- assert(status == 'down')
|
|
|
+ assert(status == 'down' or status == 'admin down')
|
|
|
down.append(port)
|
|
|
unknown = set(range(sw.first_port, sw.last_port + 1)) - set(up) - set(down)
|
|
|
sw.ports.filter(port__in=up).exclude(up=True).update(up=True)
|
|
@@ -45,5 +46,5 @@ class Command(BaseCommand):
|
|
|
sw.ports.filter(port__in=unknown).exclude(up__isnull=True).update(up=None)
|
|
|
upped, downed, unknowned = len(up) - up_count, len(down) - down_count, len(unknown) - unknown_count
|
|
|
if upped or downed or unknowned:
|
|
|
- print("Switch %s: UP: %d (%+d), DOWN: %d (%+d), UNKNOWN: %d (%+d)" \
|
|
|
- % (sw.name, len(up), upped, len(down), downed, len(unknown), unknowned))
|
|
|
+ self.stdout.write("Switch %s: UP: %d (%+d), DOWN: %d (%+d), UNKNOWN: %d (%+d)" \
|
|
|
+ % (sw.name, len(up), upped, len(down), downed, len(unknown), unknowned))
|