Skip to content

Commit

Permalink
extend by org id/name, project id/name, os slug
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mk committed Jul 14, 2019
1 parent e61a3d5 commit 12070b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ The following meta labels are available on targets during relabeling at the mome
* `__meta_packet_public_ipv6`
* `__meta_packet_state`
* `__meta_packet_tags`
* `__meta_packet_project_id`
* `__meta_packet_project_name`
* `__meta_packet_organization_id`
* `__meta_packet_organization_name`
* `__meta_packet_operating_system`



Expand Down
29 changes: 17 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,30 @@ func (d *packetDiscoverer) createTarget(device *packngo.Device) *targetgroup.Gro
Labels: model.LabelSet{
model.AddressLabel: model.LabelValue(addr),

model.LabelName(labelName("hostname")): model.LabelValue(device.Hostname),
model.LabelName(labelName("state")): model.LabelValue(device.State),
model.LabelName(labelName("billing_cycle")): model.LabelValue(device.BillingCycle),
model.LabelName(labelName("plan")): model.LabelValue(device.Plan.Slug),
model.LabelName(labelName("facility")): model.LabelValue(device.Facility.Code),
model.LabelName(labelName("private_ipv4")): model.LabelValue(networkInfo.PrivateIPv4),
model.LabelName(labelName("public_ipv4")): model.LabelValue(networkInfo.PublicIPv4),
model.LabelName(labelName("public_ipv6")): model.LabelValue(networkInfo.PublicIPv6),
model.LabelName(labelName("tags")): model.LabelValue(tags),
model.LabelName(labelName("project_id")): model.LabelValue(device.Project.ID),
model.LabelName(labelName("hostname")): model.LabelValue(device.Hostname),
model.LabelName(labelName("state")): model.LabelValue(device.State),
model.LabelName(labelName("billing_cycle")): model.LabelValue(device.BillingCycle),
model.LabelName(labelName("plan")): model.LabelValue(device.Plan.Slug),
model.LabelName(labelName("facility")): model.LabelValue(device.Facility.Code),
model.LabelName(labelName("private_ipv4")): model.LabelValue(networkInfo.PrivateIPv4),
model.LabelName(labelName("public_ipv4")): model.LabelValue(networkInfo.PublicIPv4),
model.LabelName(labelName("public_ipv6")): model.LabelValue(networkInfo.PublicIPv6),
model.LabelName(labelName("tags")): model.LabelValue(tags),
model.LabelName(labelName("device_id")): model.LabelValue(device.ID),
model.LabelName(labelName("project_id")): model.LabelValue(device.Project.ID),
model.LabelName(labelName("project_name")): model.LabelValue(device.Project.Name),
model.LabelName(labelName("organization_name")): model.LabelValue(device.Project.Organization.Name),
model.LabelName(labelName("operating_system")): model.LabelValue(device.OS.Slug),
},
}
}

func (d *packetDiscoverer) getTargets() ([]*targetgroup.Group, error) {
now := time.Now()
devices := []packngo.Device{}
lopts := packngo.ListOptions{Includes: []string{"project.organization"}}
if *projectid == "" {
projects, _, err := d.client.Projects.List(nil)
projects, _, err := d.client.Projects.List(&lopts)
requestDuration.Observe(time.Since(now).Seconds())

if err != nil {
Expand All @@ -165,7 +170,7 @@ func (d *packetDiscoverer) getTargets() ([]*targetgroup.Group, error) {
}
for _, p := range projects {
now = time.Now()
ds, _, err := d.client.Devices.List(p.ID, nil)
ds, _, err := d.client.Devices.List(p.ID, &lopts)
requestDuration.Observe(time.Since(now).Seconds())
if err != nil {
requestFailures.Inc()
Expand Down

0 comments on commit 12070b9

Please sign in to comment.