Skip to content

Initial Checkin - Diode Webinar #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions netbox-diode-webinar/examples/go/diode-webinar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"context"
"log"

"github.com/netboxlabs/diode-sdk-go/diode"
)

func main() {
client, err := diode.NewClient(
"grpc://<diode.ip:diode.port>/diode",
"example-app",
"0.1.0",
diode.WithClientID("YOUR_CLIENT_ID"),
diode.WithClientSecret("YOUR_CLIENT_SECRET"),
)
if err != nil {
log.Fatal(err)
}

// Create a device
deviceEntity := &diode.Device{
Name: diode.String("PDU 05"),
DeviceType: &diode.DeviceType{
Model: diode.String("AP7955"),
Manufacturer: &diode.Manufacturer{
Name: diode.String("APC"),
},
},
Platform: &diode.Platform{
Name: diode.String("APCOS"),
Manufacturer: &diode.Manufacturer{
Name: diode.String("APC"),
},
},
Site: &diode.Site{
Name: diode.String("Sunderland"),
},
Role: &diode.DeviceRole{
Name: diode.String("Rack PDU"),
},
Status: diode.String("active"),
}

entities := []diode.Entity{
deviceEntity,
}

resp, err := client.Ingest(context.Background(), entities)
if err != nil {
log.Fatal(err)
}
if resp != nil && resp.Errors != nil {
log.Printf("Errors: %v\n", resp.Errors)
} else {
log.Printf("Success\n")
}

}
17 changes: 17 additions & 0 deletions netbox-diode-webinar/examples/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module netboxlabs.com/diode_webinar

go 1.23.4

toolchain go1.23.10

require (
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/netboxlabs/diode-sdk-go v1.1.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
18 changes: 18 additions & 0 deletions netbox-diode-webinar/examples/go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/netboxlabs/diode-sdk-go v1.1.0 h1:+W2VwTFoofgG8CZcwQ1x0EcmDo9yFbyPwAH4gaKbswc=
github.com/netboxlabs/diode-sdk-go v1.1.0/go.mod h1:UNUmF3TJrvPVUutjKqMPpcRPm29myBjgc5c3CjHduis=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
59 changes: 59 additions & 0 deletions netbox-diode-webinar/examples/python/1_direct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'''
ensure DIODE_CLIENT_ID and DIODE_CLIENT_SECRET are set before running this
'''

from netboxlabs.diode.sdk import DiodeClient
from netboxlabs.diode.sdk.ingester import (
Device,
DeviceRole,
DeviceType,
Site,
Entity,
CustomFieldValue,
)


def generate_entities() -> list[Entity]:
''' generate a list of entitles for return to Diode '''
entities = []

device = Device(
name="PDU 1",
device_type=DeviceType(
manufacturer="APC",
model="7951"
),
role=DeviceRole(
name="Rack PDU"
),
site=Site(
name="Sunderland"
),
custom_fields={
'software_version': CustomFieldValue(
text="1.1"
)
}
)

entities.append(Entity(device=device))

return entities


if __name__ == "__main__":
''' main function '''

entities = generate_entities()

with DiodeClient(
target="grpc://<diode.ip:diode.port>/diode",
app_name="my-app",
app_version="1",

) as client:
try:
response = client.ingest(entities=entities)
print(response)
except Exception as exc:
print(f"\n!! An Exception Happened: {exc}")
62 changes: 62 additions & 0 deletions netbox-diode-webinar/examples/python/2_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'''
ensure DIODE_CLIENT_ID and DIODE_CLIENT_SECRET are set before running this
'''

from netboxlabs.diode.sdk import DiodeClient
from google.protobuf.json_format import ParseDict
from netboxlabs.diode.sdk.ingester import (
Entity,
)


def generate_entities() -> list[Entity]:
''' generate a list of entitles for return to Diode '''
entities = []
devices = [
{
"device": {
"name": "Device PDU2",
"site": {
"name": "Sunderland"
},
"role": {
"name": "Rack PDU"
},
"device_type": {
"manufacturer": {
"name": "APC"
},
"model": "AP7952"
},
"custom_fields": {
"software_version": {
"text": "1.2"
}
}
}
}
]

for jsonEntity in devices:
entity = Entity()
entity = ParseDict(jsonEntity, entity)
entities.append(entity)

return entities


if __name__ == "__main__":
''' main function '''

entities = generate_entities()

with DiodeClient(
target="grpc://<diode.ip:diode.port>/diode",
app_name="my-app",
app_version="1",

) as client:
try:
response = client.ingest(entities=entities)
except Exception as exc:
print(f"\n!! An Exception Happened: {exc}")
97 changes: 97 additions & 0 deletions netbox-diode-webinar/examples/python/3_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'''
ensure DIODE_CLIENT_ID and DIODE_CLIENT_SECRET are set before running this
'''

from netboxlabs.diode.sdk import DiodeClient
from netboxlabs.diode.sdk.ingester import (
Entity,
Device,
IPAddress,
Interface,
CustomFieldValue
)
import csv


def load_from_csv(filename: str) -> list:
''' function to read a csv file and return it as a list '''
pdu_list = []

''' read the csv file and look through creating a dict for each row,
then append to our list '''
with open(filename, newline='') as csvfile:
''' use a dict reader so we can reference via column names '''
reader = csv.DictReader(csvfile)
for row in reader:
pdu = {
'name': row['name'],
'serial': row['serial'],
'model': row['model'],
'manufacturer': row['manufacturer'],
'management_ip': row['management_ip'],
'software_version': row['software_version']
}
pdu_list.append(pdu)
return pdu_list


def generate_entities() -> list[Entity]:
''' generate a list of entitles for return to Diode '''

pdu_list = load_from_csv("ourdata.csv")

entities = []
for pdu in pdu_list:
''' create Device Entity, an IP Address and an Interface '''
device = Device(
name=pdu['name'],
device_type=pdu['model'],
manufacturer=pdu['manufacturer'],
site='Prague',
role='pdu',
serial=pdu['serial'],
status='active',
custom_fields={
"software_version": CustomFieldValue(
text=pdu['software_version']
)
},
primary_ip4=IPAddress(
address=pdu['management_ip'],
status='active',
description='loaded from csv',
assigned_object_interface=Interface(
name='eth0',
type='1000base-t',
device=Device(
name=pdu['name'],
device_type=pdu['model'],
manufacturer=pdu['manufacturer'],
site='Prague',
role='pdu',
serial=pdu['serial'],
status='active',
)
)
)
)

entities.append(Entity(device=device))
return entities


if __name__ == "__main__":
''' main function '''

entities = generate_entities()

with DiodeClient(
target="grpc://<diode.ip:diode.port>/diode",
app_name="my-app",
app_version="1",

) as client:
try:
response = client.ingest(entities=entities)
except Exception as exc:
print(f"\n!! An Exception Happened: {exc}")
3 changes: 3 additions & 0 deletions netbox-diode-webinar/examples/python/ourdata.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,manufacturer,model,management_ip,serial,software_version
"PDU 03",APC,APC6732,10.163.3.3,345678,"1.3"
"PDU 04",APC,APC6734,10.163.3.4,456789,"1.4"
2 changes: 2 additions & 0 deletions netbox-diode-webinar/examples/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
netboxlabs-diode-sdk
google
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ac3-integration-tutorial
Related files for the AutoCon3 - NetBox Discovery and Assurance 101 (Discovery Integration)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
orb:
backends:
worker:
host: 0.0.0.0
common:
diode:
target: grpc://<YOUR INFRA IP>:8080/diode
client_id: ${DIODE_CLIENT_ID}
client_secret: ${DIODE_CLIENT_SECRET}
agent_name: agent01
policies:
worker:
custom_policy:
config:
package: lab_integration
schedule: "* * * * *"
custom_config: custom
csv_filename: ${CSV_FILENAME}
method: ${METHOD}
scope:
custom: any
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python
#

from lab_integration.runner import LabIntegration

__all__ = ["LabIntegration"]
Loading
Loading