diff --git a/python/nav/ipdevpoll/plugins/paloaltoarp.py b/python/nav/ipdevpoll/plugins/paloaltoarp.py index b99bce79f8..a074568ab5 100644 --- a/python/nav/ipdevpoll/plugins/paloaltoarp.py +++ b/python/nav/ipdevpoll/plugins/paloaltoarp.py @@ -19,7 +19,7 @@ ipdevpoll plugin for fetching arp mappings from Palo Alto firewalls Configure a netbox to work with this plugin by assigning it a -HTTP_REST_API management profile with service set to "Palo Alto ARP" +HTTP_API management profile with service set to "Palo Alto ARP" in seedDB. """ @@ -42,13 +42,7 @@ class PaloaltoArp(Arp): @classmethod @defer.inlineCallbacks def can_handle(cls, netbox): - """ - Return True if this plugin can handle the given netbox. - - A netbox can be handled if there is any HTTP_REST_API management profile - associated with the netbox with "service" set to "Palo Alto ARP" in the - profile's configuration dict. - """ + """Return True if this plugin can handle the given netbox.""" has_configurations = yield cls._has_paloalto_configurations(netbox) returnValue(has_configurations) @@ -66,18 +60,6 @@ def handle(self): yield self._process_data(mappings) break - @classmethod - @defer.inlineCallbacks - def _get_paloalto_arp_mappings(cls, ip: IP, api_key: str): - """ - Make a HTTP request for ARP data from Paloalto device with the given - ip-address, using the given api-key. Returns a formatted list of ARP - mappings for use in NAV. - """ - arptable = yield cls._do_request(ip, api_key) - mappings = _parse_arp(arptable) if arptable else [] - returnValue(mappings) - @classmethod @db.synchronous_db_access def _has_paloalto_configurations(cls, netbox: Netbox): @@ -100,10 +82,20 @@ def _get_paloalto_configurations(cls, netbox: Netbox): @classmethod @defer.inlineCallbacks - def _do_request(cls, address: IP, key: str): + def _get_paloalto_arp_mappings(cls, address: IP, api_key: str): """ - Make a HTTP request to Paloalto device + Make a HTTP request for ARP data from Paloalto device with the given + ip-address, using the given api-key. Returns a formatted list of ARP + mappings for use in NAV. """ + arptable = yield cls._do_request(address, api_key) + mappings = _parse_arp(arptable) if arptable else [] + returnValue(mappings) + + @classmethod + @defer.inlineCallbacks + def _do_request(cls, address: IP, key: str): + """Make a HTTP request to Paloalto device""" class SslPolicy(client.BrowserLikePolicyForHTTPS): def creatorForNetloc(self, hostname, port): @@ -136,13 +128,11 @@ def creatorForNetloc(self, hostname, port): def _parse_arp(arpbytes: bytes) -> list[tuple[str, IP, str]]: """ - Create mappings from arp table. - - .. note:: xml.etree.ElementTree is considered insecure: - https://docs.python.org/3/library/xml.html#xml-vulnerabilities - However, since we are not parsing untrusted data, this should not - be a problem. + Create mappings from arp table + xml.etree.ElementTree is considered insecure: https://docs.python.org/3/library/xml.html#xml-vulnerabilities + However, since we are not parsing untrusted data, this should not be a problem. """ + arps = [] root = ET.fromstring(arpbytes.decode("utf-8"))