diff options
author | Jon Clausen <jac@nordu.net> | 2018-08-15 08:56:38 +0200 |
---|---|---|
committer | Jon Clausen <jac@nordu.net> | 2018-08-15 08:56:38 +0200 |
commit | 9a266bcc29864b85410b55882d83cceedfb613a8 (patch) | |
tree | d4e572fbb0732bc05cf754adb627c75ba590922c | |
parent | ba1db95ee734775847111e88eaa17f2b9e58603a (diff) |
handle empty juniper config
-rwxr-xr-x | code/vlanscrape | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/code/vlanscrape b/code/vlanscrape index 25a05da..5da322e 100755 --- a/code/vlanscrape +++ b/code/vlanscrape @@ -183,30 +183,35 @@ def is_juniper(hostName): f = open(inFile) hostConfig=f.readlines() f.close() - - # find device model - for l in hostConfig: - if re.match('^# Chassis', l): - l = re.sub('[\s]+', ':', l) - ll = l.split(':') - model = ll[3] - - if "EX" in model: - vlanList=look_in_juniper_vlans_section(hostName, hostConfig) - check_out_vs_dst(hostName,vlanList) - elif "MX" in model: - vlanList=look_in_juniper_interfaces(hostName, hostConfig) - check_out_vs_dst(hostName, vlanList) - elif "SRX" in model: - vlanListInterfaces=look_in_juniper_interfaces(hostName, hostConfig) - vlanListVlanSection=look_in_juniper_vlans_section(hostName, hostConfig) - vlanList=vlanListInterfaces + vlanListVlanSection - check_out_vs_dst(hostName, vlanList) - elif "Virtual" in model: - vlanList=look_in_juniper_vlans_section(hostName, hostConfig) - check_out_vs_dst(hostName, vlanList) + if len(hostConfig) == 0: + check_out_vs_dst(hostName, '') else: - print "model not recognized, skipping" + # find device model + model = "unset" + for l in hostConfig: + if re.match('^# Chassis', l): + l = re.sub('[\s]+', ':', l) + ll = l.split(':') + model = ll[3] + + if "EX" in model: + vlanList=look_in_juniper_vlans_section(hostName, hostConfig) + check_out_vs_dst(hostName,vlanList) + elif "MX" in model: + vlanList=look_in_juniper_interfaces(hostName, hostConfig) + check_out_vs_dst(hostName, vlanList) + elif "SRX" in model: + vlanListInterfaces=look_in_juniper_interfaces(hostName, hostConfig) + vlanListVlanSection=look_in_juniper_vlans_section(hostName, hostConfig) + vlanList=vlanListInterfaces + vlanListVlanSection + check_out_vs_dst(hostName, vlanList) + elif "Virtual" in model: + vlanList=look_in_juniper_vlans_section(hostName, hostConfig) + check_out_vs_dst(hostName, vlanList) + elif "unset" in model: + print "Model info missing for", hostName, "- skipping" + else: + print "model not recognized, skipping" try: |