Skip to content

Commit 16a0d44

Browse files
committed
feat: update README to include examples of metadata usage
Signed-off-by: Michal Fiedorowicz <mfiedorowicz@netboxlabs.com>
1 parent b4100dd commit 16a0d44

File tree

1 file changed

+37
-45
lines changed

1 file changed

+37
-45
lines changed

README.md

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,72 +90,62 @@ Entities support attaching custom metadata as key-value pairs. Metadata can be u
9090

9191
```python
9292
from netboxlabs.diode.sdk import DiodeClient, Entity
93-
from netboxlabs.diode.sdk.ingester import Device, Site
93+
from netboxlabs.diode.sdk.ingester import Device, Site, IPAddress
9494

9595
with DiodeClient(
9696
target="grpc://localhost:8080/diode",
9797
app_name="my-app",
9898
app_version="1.0.0",
9999
) as client:
100100
# Create a device with metadata
101-
# Note: Both the device and its nested site can have metadata
102-
device_entity = Entity(
103-
device=Device(
104-
name="Device A",
105-
device_type="Device Type A",
106-
site=Site(
107-
name="Site ABC",
108-
# Nested entities can also have metadata
109-
metadata={
110-
"site_region": "us-west",
111-
"site_cost_center": "CC-001",
112-
}
113-
),
114-
role="Role ABC",
101+
# Note: Both the device and its nested site can have its own metadata
102+
device = Device(
103+
name="Device A",
104+
device_type="Device Type A",
105+
site=Site(
106+
name="Site ABC",
107+
metadata={
108+
"site_region": "us-west",
109+
"site_cost_center": "CC-001",
110+
},
115111
),
116-
# Add metadata to track additional information about the device
112+
role="Role ABC",
117113
metadata={
118114
"source": "network_discovery",
119115
"discovered_at": "2024-01-15T10:30:00Z",
120116
"import_batch": "batch-123",
121117
"priority": 1,
122118
"verified": True,
123-
}
119+
},
124120
)
125121

126122
# Create an IP address with metadata
127-
from netboxlabs.diode.sdk.ingester import IPAddress
128-
ip_entity = Entity(
129-
ip_address=IPAddress(
130-
address="192.168.1.10/24",
131-
status="active",
132-
),
133-
# Metadata can store various data types
123+
ip_address = IPAddress(
124+
address="192.168.1.10/24",
125+
status="active",
134126
metadata={
135127
"last_scan": "2024-01-15T12:00:00Z",
136128
"scan_id": "scan-456",
137129
"response_time": 23.5,
138130
"reachable": True,
139131
"owner_team": "network-ops",
140-
}
132+
},
141133
)
142134

143135
# Create a site with metadata
144-
site_entity = Entity(
145-
site=Site(
146-
name="Data Center 1",
147-
status="active",
148-
),
136+
site = Site(
137+
name="Data Center 1",
138+
status="active",
149139
metadata={
150140
"region": "us-west",
151141
"cost_center": "CC-001",
152142
"capacity": 500,
153143
"is_primary": True,
154144
"contact_email": "dc1-ops@example.com",
155-
}
145+
},
156146
)
157147

158-
entities = [device_entity, ip_entity, site_entity]
148+
entities = [Entity(device=device), Entity(ip_address=ip_address), Entity(site=site)]
159149
response = client.ingest(entities=entities)
160150
if response.errors:
161151
print(f"Errors: {response.errors}")
@@ -174,17 +164,19 @@ with DiodeClient(
174164
app_name="my-app",
175165
app_version="1.0.0",
176166
) as client:
177-
# Create entities
178-
entities = [
179-
Entity(device=Device(
180-
name="Device A",
181-
site=Site(name="Site ABC"),
182-
)),
183-
Entity(device=Device(
184-
name="Device B",
185-
site=Site(name="Site XYZ"),
186-
)),
187-
]
167+
# Create device A
168+
device_a = Device(
169+
name="Device A",
170+
site=Site(name="Site ABC"),
171+
)
172+
173+
# Create device B
174+
device_b = Device(
175+
name="Device B",
176+
site=Site(name="Site XYZ"),
177+
)
178+
179+
entities = [Entity(device=device_a), Entity(device=device_b)]
188180

189181
# Add request-level metadata to track the ingestion batch
190182
response = client.ingest(
@@ -195,7 +187,7 @@ with DiodeClient(
195187
"import_type": "automated",
196188
"record_count": len(entities),
197189
"validated": True,
198-
}
190+
},
199191
)
200192
if response.errors:
201193
print(f"Errors: {response.errors}")
@@ -379,7 +371,7 @@ with DiodeOTLPClient(
379371
"deployment": "us-west-2",
380372
"version": "1.2.3",
381373
"priority": 5,
382-
}
374+
},
383375
)
384376
```
385377

0 commit comments

Comments
 (0)