Skip to content

Commit

Permalink
Add interface fields at inventory-networks root level (#573)
Browse files Browse the repository at this point in the history
* Add interface fields to the root level

Expected at root level on the inventory-networks index

* Update inventory-networks index events generator and docs

* Add network interface custom fields to event generator

* Fix event generator

* Normalize

---------

Signed-off-by: Kevin Ledesma <[email protected]>
Co-authored-by: Alex Ruiz <[email protected]>
  • Loading branch information
QU3B1M and AlexRuiz7 authored Dec 2, 2024
1 parent a5b41a5 commit b9a8ff3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
26 changes: 19 additions & 7 deletions ecs/states-inventory-networks/event-generator/event_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def generate_random_agent():
return agent


def generate_random_host(is_root_level=False):
if is_root_level:
def generate_random_host(is_root_level_level=False):
if is_root_level_level:
host = {
'ip': f'{random.randint(1, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}',
'mac': f'{random.randint(0, 255):02x}:{random.randint(0, 255):02x}:{random.randint(0, 255):02x}:{random.randint(0, 255):02x}:{random.randint(0, 255):02x}:{random.randint(0, 255):02x}',
Expand Down Expand Up @@ -158,14 +158,25 @@ def generate_random_network():
}
return network

def generate_random_interface(is_root_level=False):
if is_root_level:
interface = {
'mtu': f'{random.randint(1000000, 99999999)}',
'state': random.choice(['Active', 'Inactive', 'Unknown']),
'type': random.choice(['wireless', 'ethernet'])
}
else:
interface = {
'alias': f'alias{random.randint(0, 9999)}',
'name': f'name{random.randint(0, 9999)}',
}

return interface

def generate_random_observer():
observer = {
'ingress': {
'interface': {
'alias': f'alias{random.randint(0, 9999)}',
'name': f'name{random.randint(0, 9999)}'
}
'interface': generate_random_interface(False)
}
}
return observer
Expand All @@ -179,7 +190,8 @@ def generate_random_data(number):
'agent': generate_random_agent(),
'host': generate_random_host(True),
'network': generate_random_network(),
'observer': generate_random_observer()
'observer': generate_random_observer(),
'interface': generate_random_interface(True)
}
data.append(event_data)
return data
Expand Down
4 changes: 4 additions & 0 deletions ecs/states-inventory-networks/fields/custom/interface.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
- name: interface
reusable:
top_level: true
expected:
- { at: observer.egress.interface, as: observer.ingress.interface }
title: Interface
type: group
group: 2
Expand Down

0 comments on commit b9a8ff3

Please sign in to comment.