Skip to content

Commit

Permalink
add find ip function
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanNyschuk1 committed Jun 19, 2019
1 parent 94d4238 commit a7db107
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 14 additions & 1 deletion device42.py
Expand Up @@ -132,7 +132,7 @@ def doql(self, url=None, query=None):
result = self._post(path, data)
return result

def create_ipaddress_if_not_exist(self, ip_address):
def create_ipaddress(self, ip_address):
path = "api/1.0/ips/"

data = {"ipaddress": ip_address}
Expand All @@ -144,3 +144,16 @@ def create_ipaddress_if_not_exist(self, ip_address):
return None
except:
return None

def find_ipaddress(self, ip_address):
path = "api/1.0/ips/"

data = {"ip": ip_address}

try:
ret = self._get(path, data)
if ret["total_count"] > 0:
return ret["ips"][0]["id"]
return None
except:
return None
8 changes: 5 additions & 3 deletions traceroute_tags.py
Expand Up @@ -83,10 +83,12 @@ def task_execute(settings, device42):
else:
ip_address = source["ip_address"]

ip_id = device42.create_ipaddress_if_not_exist(ip_address)
ip_id = device42.find_ipaddress(ip_address)
if ip_id is None:
logger.info("Can't get id for ip %s." % ip_address)
continue
ip_id = device42.create_ipaddress(ip_address)
if ip_id is None:
logger.info("Can't get id for ip %s." % ip_address)
continue

logger.info("Processing ipaddress %s" % ip_address)
success, last_ip = tracert(ip_address, settings)
Expand Down

0 comments on commit a7db107

Please sign in to comment.