Skip to content

Commit

Permalink
fix hardcoded network type issue
Browse files Browse the repository at this point in the history
  • Loading branch information
psomareddy committed Feb 12, 2019
1 parent 6fedd63 commit 1691199
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/port-monitor.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"net"
"strings"
"time"

sdkArgs "github.com/newrelic/infra-integrations-sdk/args"
Expand All @@ -24,28 +25,20 @@ const (

var args argumentList

func populateInventory(inventory sdk.Inventory) error {
// Insert here the logic of your integration to get the inventory data
// Ex: inventory.SetItem("softwareVersion", "value", "1.0.1")
// --
return nil
}

func populateMetrics(ms *metric.MetricSet) error {
// Insert here the logic of your integration to get the metrics data
// Ex: ms.SetMetric("requestsPerSecond", 10, metric.GAUGE)
// --
network := strings.TrimSpace(args.Network)
address := strings.TrimSpace(args.Address)
status := 0
conn, err := net.DialTimeout("tcp", args.Address, time.Duration(args.Timeout)*time.Second)
conn, err := net.DialTimeout(network, address, time.Duration(args.Timeout)*time.Second)
if err != nil {
status = 0
} else {
status = 1
conn.Close()
}

ms.SetMetric("network", args.Network, metric.ATTRIBUTE)
ms.SetMetric("address", args.Address, metric.ATTRIBUTE)
ms.SetMetric("network", network, metric.ATTRIBUTE)
ms.SetMetric("address", address, metric.ATTRIBUTE)
ms.SetMetric("status", status, metric.GAUGE)
return nil
}
Expand All @@ -54,10 +47,6 @@ func main() {
integration, err := sdk.NewIntegration(integrationName, integrationVersion, &args)
fatalIfErr(err)

if args.All || args.Inventory {
fatalIfErr(populateInventory(integration.Inventory))
}

if args.All || args.Metrics {
ms := integration.NewMetricSet("NetworkPortSample")
fatalIfErr(populateMetrics(ms))
Expand Down

0 comments on commit 1691199

Please sign in to comment.