Skip to content

Commit

Permalink
Monitoring now reports on pingability of known devices and reports on…
Browse files Browse the repository at this point in the history
… devices that are present in the network but not known in NetBox
  • Loading branch information
mrmrcoleman committed Feb 26, 2024
1 parent 6c900a6 commit 60dcf86
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions netbox-event-driven-architectures/agents/.README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
```

- Install ContainerLab
```
# bash -c "$(curl -sL https://get.containerlab.dev)"
```

- Create and activate a virtual environment
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def __init__(self):
self.netbox_url = os.getenv("NETBOX_URL")
self.netbox_token = os.getenv("NETBOX_TOKEN")

self.network_cidr = "172.20.20.0/24"
self.ignore_ips = ['172.20.20.1']

# Load devices from netbox
self.network_devices = self.load_devices_from_netbox()

Expand Down Expand Up @@ -70,6 +73,32 @@ async def message_handler(self, msg) -> None:
table.add_row([device, ip, ping_status])

await self.nc.publish(self.publish_subject, f"Monitoring for devices in {self.netbox_url} \n {table}".encode())

# Scan the subnet and figure out if any devices are there that shouldn't be

# Initialise nmap PortScanner
nm = nmap.PortScanner()

# Scan the subnet
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"{current_time}: Scanning {self.network_cidr}...")
nm.scan(hosts=self.network_cidr, arguments='-sn')

print(f"Found hosts: {nm.all_hosts()}")

for host in nm.all_hosts():
print(f"Comparing host {host} to ignored IPs: {self.ignore_ips} and known IPs: {self.network_devices}")
print(f"Available keys for {host}: {nm[host].keys()}")
if host in self.ignore_ips:
print(f"Ignoring host {host} as it is present in the IP ignore list {self.ignore_ips}")
elif host in list(self.network_devices.values()):
print(f"Ignoring host {host} as it is present in the NetBox inventory: {self.netbox_url}")
else:
# We do not know about this IP so alert on it
await self.nc.publish(self.publish_subject, f"Found unknown host in monitored subnet ({self.network_cidr}) Hostname: {nm[host].hostname()} IPAddress: {host}".encode())




print(table)

Expand Down
11 changes: 10 additions & 1 deletion netbox-event-driven-architectures/lab/srl01.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@ topology:
type: ixrd3
image: ghcr.io/nokia/srlinux
nodes:
srl:
srl1:
kind: nokia_srlinux
mgmt-ipv4: 172.20.20.2

srl2:
kind: nokia_srlinux
mgmt-ipv4: 172.20.20.3

srl3:
kind: nokia_srlinux
mgmt-ipv4: 172.20.20.4

0 comments on commit 60dcf86

Please sign in to comment.