<commit_before>from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings

from ui.models import Location

from pysnmp.entity.rfc3413.oneliner import cmdgen


class Command(BaseCommand):
    help = '''Capture network status of all the hosts within the specified
            network and map hostname with ip address for registered locations'''
    args = '<network_prefix network_prefix...>'

    def handle(self, *args, **options):

        if len(args) < 1:
            raise CommandError("Please pass atleast one network prefix to " +
                               "perform the SNMP walk for mapping network " +
                               "hostnames with ip addresses.")

        cmdGen = cmdgen.CommandGenerator()
        for network_prefix in args:
            for i in range(256):
                ip_address = str(network_prefix) + '.' + str(i)
                errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
                    cmdgen.CommunityData(settings.SNMP_COMMUNITY_STRING),
                    cmdgen.UdpTransportTarget((ip_address, 161)),
                    '1.3.6.1.4.1.25071.1.2.6.1.1.2',
                    '1.3.6.1.4.1.25071.1.1.2.1.1.3',)

                if errorIndication:
                    print(str(ip_address) + ': ' + str(errorIndication))
                else:
                    if errorStatus:
                        print('%s at %s' % (errorStatus.prettyPrint(),
                                            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'))
                    else:
                        hostname = varBindTable[0][0][1]
                        try:
                            location = Location.objects.get(hostname=hostname)
                            if location.ip_address != ip_address:
                                location.ip_aadress = ip_address
                                print 'Updated IP address for host - %s' % location.hostname
                                location.save()
                        except ObjectDoesNotExist:
                            print 'Location with hostname <' + hostname + '> does not exist.'<commit_msg>Modified query compare on hostname to be case-insensitive.  Fixes #89.<commit_after>from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings

from ui.models import Location

from pysnmp.entity.rfc3413.oneliner import cmdgen


class Command(BaseCommand):
    help = '''Capture network status of all the hosts within the specified
            network and map hostname with ip address for registered locations'''
    args = '<network_prefix network_prefix...>'

    def handle(self, *args, **options):

        if len(args) < 1:
            raise CommandError("Please pass atleast one network prefix to " +
                               "perform the SNMP walk for mapping network " +
                               "hostnames with ip addresses.")

        cmdGen = cmdgen.CommandGenerator()
        for network_prefix in args:
            for i in range(256):
                ip_address = str(network_prefix) + '.' + str(i)
                errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
                    cmdgen.CommunityData(settings.SNMP_COMMUNITY_STRING),
                    cmdgen.UdpTransportTarget((ip_address, 161)),
                    '1.3.6.1.4.1.25071.1.2.6.1.1.2',
                    '1.3.6.1.4.1.25071.1.1.2.1.1.3',)

                if errorIndication:
                    print(str(ip_address) + ': ' + str(errorIndication))
                else:
                    if errorStatus:
                        print('%s at %s' % (errorStatus.prettyPrint(),
                                            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'))
                    else:
                        hostname = varBindTable[0][0][1]
                        try:
                            location = Location.objects.get(hostname__iexact=hostname)
                            if location.ip_address != ip_address:
                                location.ip_aadress = ip_address
                                print 'Updated IP address for host - %s' % location.hostname
                                location.save()
                        except ObjectDoesNotExist:
                            print 'Location with hostname <' + hostname + '> does not exist.'
{'fraction_non_alphanumeric': 0.08861592454485633, 'fraction_numerical': 0.02237332748409739, 'mean_word_length': 1.5418060200668897, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6608439', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1123, 'n_words': 290}