Skip to content
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

Submit device scan type #34485

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion cmd/agent/subcommands/snmp/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
metricscompression "github.com/DataDog/datadog-agent/comp/serializer/metricscompression/fx"
snmpscan "github.com/DataDog/datadog-agent/comp/snmpscan/def"
snmpscanfx "github.com/DataDog/datadog-agent/comp/snmpscan/fx"
"github.com/DataDog/datadog-agent/pkg/networkdevice/metadata"
"github.com/DataDog/datadog-agent/pkg/snmp/snmpparse"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -288,7 +289,7 @@ func scanDevice(connParams *snmpparse.SNMPConfig, args argsType, snmpScanner snm
deviceID := namespace + ":" + connParams.IPAddress
// Start the scan
fmt.Printf("Launching scan for device: %s\n", deviceID)
err := snmpScanner.ScanDeviceAndSendData(connParams, namespace)
err := snmpScanner.ScanDeviceAndSendData(connParams, namespace, metadata.ManualScan)
if err != nil {
fmt.Printf("Unable to perform device scan for device %s : %e", deviceID, err)
}
Expand Down
2 changes: 1 addition & 1 deletion comp/snmpscan/def/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ type Component interface {
RunDeviceScan(snmpConection *gosnmp.GoSNMP, deviceNamespace string, deviceID string) error
RunSnmpWalk(snmpConection *gosnmp.GoSNMP, firstOid string) error
SendPayload(payload metadata.NetworkDevicesMetadata) error
ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig, namespace string) error
ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig, namespace string, scanType metadata.ScanType) error
}
6 changes: 5 additions & 1 deletion comp/snmpscan/impl/devicescan.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func gatherPDUs(snmp *gosnmp.GoSNMP) ([]*gosnmp.SnmpPDU, error) {
return pdus, nil
}

func (s snmpScannerImpl) ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig, namespace string) error {
func (s snmpScannerImpl) ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig, namespace string, scanType metadata.ScanType) error {
// Establish connection
snmp, err := snmpparse.NewSNMP(connParams, s.log)
if err != nil {
Expand All @@ -70,6 +70,7 @@ func (s snmpScannerImpl) ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig,
DeviceScanStatus: &metadata.ScanStatusMetadata{
DeviceID: deviceID,
ScanStatus: metadata.ScanStatusInProgress,
ScanType: scanType,
},
CollectTimestamp: time.Now().Unix(),
Namespace: namespace,
Expand All @@ -83,6 +84,7 @@ func (s snmpScannerImpl) ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig,
DeviceScanStatus: &metadata.ScanStatusMetadata{
DeviceID: deviceID,
ScanStatus: metadata.ScanStatusError,
ScanType: scanType,
},
CollectTimestamp: time.Now().Unix(),
Namespace: namespace,
Expand All @@ -99,6 +101,7 @@ func (s snmpScannerImpl) ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig,
DeviceScanStatus: &metadata.ScanStatusMetadata{
DeviceID: deviceID,
ScanStatus: metadata.ScanStatusError,
ScanType: scanType,
},
CollectTimestamp: time.Now().Unix(),
Namespace: namespace,
Expand All @@ -113,6 +116,7 @@ func (s snmpScannerImpl) ScanDeviceAndSendData(connParams *snmpparse.SNMPConfig,
DeviceScanStatus: &metadata.ScanStatusMetadata{
DeviceID: deviceID,
ScanStatus: metadata.ScanStatusCompleted,
ScanType: scanType,
},
CollectTimestamp: time.Now().Unix(),
Namespace: namespace,
Expand Down
3 changes: 2 additions & 1 deletion comp/snmpscan/impl/snmpscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatform"
rcclienttypes "github.com/DataDog/datadog-agent/comp/remote-config/rcclient/types"
snmpscan "github.com/DataDog/datadog-agent/comp/snmpscan/def"
"github.com/DataDog/datadog-agent/pkg/networkdevice/metadata"
"github.com/DataDog/datadog-agent/pkg/snmp/snmpparse"
)

Expand Down Expand Up @@ -75,6 +76,6 @@ func (s snmpScannerImpl) startDeviceScan(task rcclienttypes.AgentTaskConfig) err
if err != nil {
return err
}
return s.ScanDeviceAndSendData(instance, ns)
return s.ScanDeviceAndSendData(instance, ns, metadata.RCTriggeredScan)

}
2 changes: 1 addition & 1 deletion comp/snmpscan/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ func (m mock) RunSnmpWalk(_ *gosnmp.GoSNMP, _ string) error {
func (m mock) SendPayload(_ metadata.NetworkDevicesMetadata) error {
return nil
}
func (m mock) ScanDeviceAndSendData(_ *snmpparse.SNMPConfig, _ string) error {
func (m mock) ScanDeviceAndSendData(_ *snmpparse.SNMPConfig, _ string, _ metadata.ScanType) error {
return nil
}
11 changes: 11 additions & 0 deletions pkg/networkdevice/metadata/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,21 @@ const (
ScanStatusError ScanStatus = "error"
)

// ScanType type for the different possible scan types manual or rc_triggered
type ScanType string

const (
// ManualScan represents a manual scan
ManualScan ScanType = "manual"
// RCTriggeredScan represents a rc triggered scan
RCTriggeredScan ScanType = "rc_triggered"
)

// ScanStatusMetadata contains scan status metadata
type ScanStatusMetadata struct {
DeviceID string `json:"device_id"`
ScanStatus ScanStatus `json:"scan_status"`
ScanType ScanType `json:"scan_type,omitempty"`
}

// InterfaceMetadata contains interface metadata
Expand Down