def splunk(**options): splunk = Splunk() splunk.start() percent = splunk.progress while percent < 100: if options['verbose']: print(percent) time.sleep(30) percent = splunk.progress hosts = {} total_mb = 0 for item in splunk.results: host = item['host'] mb = float(item['MBytes']) total_mb += mb if host in hosts: hosts[host] += mb else: hosts[host] = mb if options['verbose']: print(len(hosts), 'hosts used', total_mb, ' MiBs total.') for host, usage in hosts.iteritems(): ip = IPAddress.objects.filter( hostname__startswith=host).order_by('-last_seen') if not ip.count(): if options['verbose']: print('Warning: host', host, 'not found in device database.') continue dev = ip[0].device if not dev: if options['verbose']: print('Warning: host', host, 'not tied to a device in the ' 'database.') continue name = 'Splunk Volume 100 GiB' symbol = 'splunkvolume' model, created = ComponentModel.create( ComponentType.unknown, family=symbol, name=name, priority=0, ) res, created = SplunkUsage.concurrent_get_or_create( device=dev, day=date.today(), defaults={'model': model}, ) res.size = usage res.save() return True, 'done.', options
def splunk(**options): splunk = Splunk() splunk.start() percent = splunk.progress while percent < 100: if options['verbose']: print(percent) time.sleep(30) percent = splunk.progress hosts = {} total_mb = 0 for item in splunk.results: host = item['host'] mb = float(item['MBytes']) total_mb += mb if host in hosts: hosts[host] += mb else: hosts[host] = mb if options['verbose']: print(len(hosts), 'hosts used', total_mb, ' MiBs total.') for host, usage in hosts.iteritems(): ip = IPAddress.objects.filter(hostname__startswith=host).order_by( '-last_seen') if not ip.count(): if options['verbose']: print('Warning: host', host, 'not found in device database.') continue dev = ip[0].device if not dev: if options['verbose']: print('Warning: host', host, 'not tied to a device in the ' 'database.') continue name = 'Splunk Volume 100 GiB' symbol = 'splunkvolume' model, created = ComponentModel.create( ComponentType.unknown, family=symbol, name=name, priority=0, ) res, created = SplunkUsage.concurrent_get_or_create( device=dev, day=date.today(), defaults={'model': model}, ) res.size = usage res.save() return True, 'done.', options
def splunk(**options): splunk = Splunk() splunk.start() percent = splunk.progress while percent < 100: if options["verbose"]: print(percent) time.sleep(30) percent = splunk.progress hosts = {} total_mb = 0 for item in splunk.results: host = item["host"] mb = float(item["MBytes"]) total_mb += mb if host in hosts: hosts[host] += mb else: hosts[host] = mb if options["verbose"]: print(len(hosts), "hosts used", total_mb, " MiBs total.") for host, usage in hosts.iteritems(): ip = IPAddress.objects.filter(hostname__startswith=host).order_by("-last_seen") if not ip.count(): if options["verbose"]: print("Warning: host", host, "not found in device database.") continue dev = ip[0].device if not dev: if options["verbose"]: print("Warning: host", host, "not tied to a device in the " "database.") continue name = "Splunk Volume 100 GiB" symbol = "splunkvolume" model, created = ComponentModel.concurrent_get_or_create( type=ComponentType.unknown.id, speed=0, cores=0, size=0, family=symbol, extra_hash="" ) if created: model.name = name model.save() res, created = SplunkUsage.concurrent_get_or_create(model=model, device=dev, day=date.today()) res.size = usage res.save() return True, "done.", options
def setUp(self): super(DeviceWithPricingResourceTest, self).setUp() self.resource = 'devicewithpricing' self.user = User.objects.create_user( 'ralph', '*****@*****.**', 'ralph' ) self.venture = Venture(name='Infra').save() self.deprecation_kind = DeprecationKind( name='12 months', months=12 ).save() srv1 = { 'sn': 'srv-1', 'model_name': 'server', 'model_type': DeviceType.virtual_server, 'venture': self.venture, 'name': 'Srv 1', 'purchase_date': datetime.datetime(2020, 1, 1, 0, 0), 'deprecation_kind': self.deprecation_kind, } srv1_cpu = { 'model_name': 'Intel PCU1', 'label': 'CPU 1', 'priority': 0, 'family': 'Intsels', 'price': 120, 'count': 2, 'speed': 1200, } srv1_memory = { 'priority': 0, 'family': 'Noname RAM', 'label': 'Memory 1GB', 'price': 100, 'speed': 1033, 'size': 512, 'count': 6, } srv1_storage = { 'model_name': 'Store 1TB', 'label': 'store 1TB', 'priority': 0, 'family': 'Noname Store', 'price': 180, 'count': 10, } self.device = create_device( device=srv1, cpu=srv1_cpu, memory=srv1_memory, storage=srv1_storage, ) self.device.save() name = 'Splunk Volume 100 GiB' symbol = 'splunkvolume' model, created = ComponentModel.create( ComponentType.unknown, family=symbol, name=name, priority=0, ) model_group, created = ComponentModelGroup.objects.get_or_create( name='Group Splunk', price=128, type=ComponentType.unknown, ) model.group = model_group model.save() res, created = SplunkUsage.concurrent_get_or_create( device=self.device, day=datetime.date.today(), defaults={'model': model}, ) res.size = 10 res.save()
def setUp(self): super(DeviceWithPricingResourceTest, self).setUp() self.resource = 'devicewithpricing' self.user = User.objects.create_user('ralph', '*****@*****.**', 'ralph') self.venture = Venture(name='Infra').save() self.deprecation_kind = DeprecationKind(name='12 months', months=12).save() srv1 = { 'sn': 'srv-1', 'model_name': 'server', 'model_type': DeviceType.virtual_server, 'venture': self.venture, 'name': 'Srv 1', 'purchase_date': datetime.datetime(2020, 1, 1, 0, 0), 'deprecation_kind': self.deprecation_kind, } srv1_cpu = { 'model_name': 'Intel PCU1', 'label': 'CPU 1', 'priority': 0, 'family': 'Intsels', 'price': 120, 'count': 2, 'speed': 1200, } srv1_memory = { 'priority': 0, 'family': 'Noname RAM', 'label': 'Memory 1GB', 'price': 100, 'speed': 1033, 'size': 512, 'count': 6, } srv1_storage = { 'model_name': 'Store 1TB', 'label': 'store 1TB', 'priority': 0, 'family': 'Noname Store', 'price': 180, 'count': 10, } self.device = create_device( device=srv1, cpu=srv1_cpu, memory=srv1_memory, storage=srv1_storage, ) self.device.save() name = 'Splunk Volume 100 GiB' symbol = 'splunkvolume' model, created = ComponentModel.create( ComponentType.unknown, family=symbol, name=name, priority=0, ) model_group, created = ComponentModelGroup.objects.get_or_create( name='Group Splunk', price=128, type=ComponentType.unknown, ) model.group = model_group model.save() res, created = SplunkUsage.concurrent_get_or_create( device=self.device, day=datetime.date.today(), defaults={'model': model}, ) res.size = 10 res.save()