diff --git a/src/helper/armis.py b/src/helper/armis.py index 9a510da..d8c1732 100644 --- a/src/helper/armis.py +++ b/src/helper/armis.py @@ -41,16 +41,29 @@ def _remove_existing_devices(deviceList): # flake8: noqa: E231 @armiscloud -def get_devices(acloud, site): +def get_devices(acloud, sites): vlan_bl = "" vlan_blacklist = armis_config['armis-server'].get('vlan_blacklist', '') vlan_bl = f"!networkInterface:(vlans:{vlan_blacklist})" if vlan_blacklist else "" + sites = ','.join(f'"{site}"' for site in sites) deviceList = acloud.get_devices( - asq=f'in:devices site:"{site.get("name")}" timeFrame:"7 Days" {vlan_bl}', + asq=f'in:devices site:{sites} timeFrame:"7 Days" {vlan_bl}', fields_wanted=['id', 'ipAddress', 'macAddress', 'name', 'boundaries'] ) return _remove_existing_devices(deviceList) # flake8: qa + +def get_boundaries(deviceList): + unique_boundaries = set() + for device in deviceList: + boundaries = [b.strip() for b in device['boundaries'].split(',')] + unique_boundaries.update(boundaries) + + return sorted(list(unique_boundaries)) + def get_tenant_url(): return 'https://{}'.format(armis_config['armis-server']['tenant_hostname']) + +def map_ids_to_names(selectedSiteIds, armisServerSites): + return [armisServerSites[id]['name'] for id in selectedSiteIds if id in armisServerSites] diff --git a/src/nac/subviews/armis.py b/src/nac/subviews/armis.py index 39958b9..a3ff8a5 100644 --- a/src/nac/subviews/armis.py +++ b/src/nac/subviews/armis.py @@ -17,7 +17,7 @@ from django.core.cache import cache from django.shortcuts import render -from helper.armis import get_armis_sites, get_devices, get_tenant_url +from helper.armis import get_armis_sites, get_devices, get_tenant_url, get_boundaries, map_ids_to_names class ArmisView(View): @@ -35,14 +35,16 @@ def _get_context(self): # sets the site-context for armis_import.html, uses cac def get(self, request, *args, **kwargs): # rendering the html base with site-context context = self._get_context() + context['display'] = True return render(request, self.template_name, context) def post(self, request, *args, **kwargs): # gets site-id chosen in html-dropdown, gets Devices based on site-id, shows them via device-context context = self._get_context() - - selected_site = request.POST.get('site-id') - context['selected_site'] = selected_site if selected_site else '' - if selected_site: - context['devices'] = get_devices(context['armis_sites'][selected_site]) + selected_sites = request.POST.getlist('site-ids[]') + context['display'] = False if selected_sites else True + context['selected_sites'] = selected_sites if selected_sites else '' + if selected_sites: + context['devices'] = get_devices(map_ids_to_names(selected_sites, context['armis_sites'])) + context['boundaries'] = get_boundaries(context['devices']) return render(request, self.template_name, context) diff --git a/src/static/default.css b/src/static/default.css index bdf81bd..d609807 100644 --- a/src/static/default.css +++ b/src/static/default.css @@ -80,4 +80,26 @@ td { margin-top: 5px; white-space: nowrap; z-index: 2000; + } + .checkbox-container { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); /* displays checkbox in 100pt width columns, as many as possible based on window size*/ + gap: 10px 20px; + padding: 10px; + } + + .checkbox-item { + display: flex; + align-items: center; + } + + .checkbox-label { + margin-left: 8px; + cursor: pointer; + } + + .custom-checkbox { + width: 20px; + height: 20px; + cursor: pointer; } \ No newline at end of file diff --git a/src/templates/armis_import.html b/src/templates/armis_import.html index c5ce752..113ffb5 100644 --- a/src/templates/armis_import.html +++ b/src/templates/armis_import.html @@ -3,19 +3,24 @@ {% load crispy_forms_tags %} {% block content %}
-

Armis Import

-
- {% csrf_token %} - - -
+

Armis Import

+ +
+
+ {% csrf_token %} +
+ {% for site_id, site_info in armis_sites.items %} +
+ + +
+ {% endfor %} +
+ +
+
{%if devices%}