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

Issue #111: Fix LinuxIpNetwork #157

Merged
merged 8 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
extends:
- ../Hardware/Hardware
- ../../Hardware/Hardware
- ../LinuxNetwork-header/LinuxNetwork-header
constants:
GLOBAL_COMMAND_LINE: /sbin/ip a
Expand All @@ -19,4 +19,4 @@ connector:
- Linux
supersedes:
- LinuxIfConfigNetwork
tags: [ hardware, linux ]
tags: [ hardware, linux ]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {
}

# ip a
$2 ~ /^eth[0-9][0-9]*:?|^vmnic[0-9][0-9]*:?|^em[0-9]*:?|^[Pp][0-9][0-9]*[Pp][0-9][0-9]*:?|^en[os][0-9]*:?|^enp[0-9]*s[0-9]*:?/ {
$1 ~/^[0-9]+:/ && $2 ~ /^.*:/ {
deviceID = $2
gsub(":", "", deviceID)
}
Expand All @@ -29,5 +29,4 @@ $1 ~ /TX:/ && $2 ~ /bytes/ && $3 ~ /packets/ {

END {
print "MSHW;" deviceID ";" receivePackets ";" transmitPackets ";" (receiveErrors + transmitErrors) ";" receiveBytes ";" transmitBytes
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ BEGIN {
deviceID = ""
}

/^lo[0-9]* / {
deviceID = ""
}

# ip a
$2 ~ /^lo[0-9]*/ {
deviceID = ""
}

$2 ~ /^eth[0-9][0-9]*:?|^vmnic[0-9][0-9]*:?|^em[0-9]*:?|^[Pp][0-9][0-9]*[Pp][0-9][0-9]*:?|^en[os][0-9]*:?|^enp[0-9]*s[0-9]*:?/ {
$1 ~/^[0-9]+:/ && $2 ~ /^.*:/ {
deviceID = $2
gsub(":", "", deviceID)
ports[deviceID] = deviceID
Expand Down Expand Up @@ -39,5 +30,4 @@ END {
print "MSHW;" deviceID ";" macAddress[deviceID] ";" ipAddress[deviceID] ";"
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
extends:
- ../Hardware/Hardware
- ../../Hardware/Hardware
Copy link
Member

@bertysentry bertysentry Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lowercase or uppercase h for the directory name?

Sorry, don't bother! 😅

- ../LinuxNetwork-header/LinuxNetwork-header
constants:
GLOBAL_COMMAND_LINE: /sbin/ifconfig -a
Expand All @@ -17,4 +17,4 @@ connector:
- local
appliesTo:
- Linux
tags: [ hardware, linux ]
tags: [ hardware, linux ]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {
}

# ifconfig
$1 ~ /^eth[0-9][0-9]*:?|^vmnic[0-9][0-9]*:?|^em[0-9]*:?|^[Pp][0-9][0-9]*[Pp][0-9][0-9]*:?|^en[os][0-9]*:?|^enp[0-9]*s[0-9]*:?/ {
$1 ~ /:$/ && $2 ~ /flags/ {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure flags is always available.

deviceID = $1
gsub(":", "", deviceID)
}
Expand Down Expand Up @@ -48,5 +48,4 @@ $1 == "TX" && $2 == "errors" {

END {
print "MSHW;" deviceID ";" receivePackets ";" transmitPackets ";" (receiveErrors + transmitErrors) ";" receiveBytes ";" transmitBytes
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ BEGIN {
deviceID = ""
}

/^lo[0-9]* / {
deviceID = ""
}

#ifconfig
$1 ~ /^eth[0-9][0-9]*:?|^vmnic[0-9][0-9]*:?|^em[0-9]*:?|^[Pp][0-9][0-9]*[Pp][0-9][0-9]*:?|^en[os][0-9]*:?|^enp[0-9]*s[0-9]*:?/ {
$1 ~ /:$/ && $2 ~ /flags/ {
deviceID = $1
gsub(":", "", deviceID)
ports[deviceID] = deviceID
Expand All @@ -19,7 +15,7 @@ $1 ~ /^eth[0-9][0-9]*:?|^vmnic[0-9][0-9]*:?|^em[0-9]*:?|^[Pp][0-9][0-9]*[Pp][0-9
}
}

/ +inet addr:[0-9]+/ {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still support addr:

/ +inet / {
ipAddress[deviceID] = $2
gsub("addr:", "", ipAddress[deviceID])
}
Expand All @@ -38,5 +34,4 @@ END {
print "MSHW;" deviceID ";" macAddress[deviceID] ";" ipAddress[deviceID] ";"
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,29 @@ monitors:
keep: ^MSHW;
separators: ;
selectColumns: "2,3,4"
source(2):
# Discovery
# Source(2) = output of the command ls -l /sys/class/net
type: commandLine
commandLine: ls -l /sys/class/net
computes:
- type: awk
script: |
$0 !~ /virtual/ && $0 !~ /total/ {print $9}
source(3):
type: tableJoin
leftTable: ${source::monitors.network.discovery.sources.source(2)}
rightTable: ${source::monitors.network.discovery.sources.source(1)}
leftKeyColumn: 1
rightKeyColumn: 1
mapping:
# InstanceTable = Source(1)
source: ${source::monitors.network.discovery.sources.source(1)}
source: ${source::monitors.network.discovery.sources.source(3)}
attributes:
id: $1
physical_address: $2
physical_address: $3
physical_address_type: MAC
logical_address: $3
logical_address: $4
logical_address_type: IP
hw.parent.type: enclosure
name: $1
Expand Down Expand Up @@ -88,4 +103,4 @@ monitors:
hw.network.io{direction="transmit"}: $6
hw.network.up: legacyLinkStatus($8)
hw.network.bandwidth.limit: megaBit2Byte($9)
hw.network.full_duplex: legacyFullDuplex($10)
hw.network.full_duplex: legacyFullDuplex($10)
Loading