[OHAI-531] Regex for getting data from arp -na output is incorrect on Solaris2 #229

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@jacques

  "network": {
    "interfaces": {
      "lo0": {
        "mtu": "8252",
        "index": "1",
        "flags": [
          "UP",
          "LOOPBACK",
          "RUNNING",
          "MULTICAST",
          "IPv6",
          "VIRTUAL"
        ],
        "type": "lo",
        "number": "0",
        "encapsulation": "Loopback",
        "addresses": {
          "127.0.0.1": {
            "family": "inet",
            "netmask": "255.0.0.0"
          },
          "::1": {
            "family": "inet6",
            "prefixlen": "128"
          }
        }
      },
      "net0": {
        "mtu": "1500",
        "index": "2",
        "flags": [
          "UP",
          "BROADCAST",
          "RUNNING",
          "MULTICAST",
          "IPv4",
          "CoS",
          "L3PROTECT"
        ],
        "type": "net",
        "number": "0",
        "encapsulation": "Ethernet",
        "addresses": {
          "37.153.96.33": {
            "family": "inet",
            "netmask": "255.255.254.0",
            "broadcast": "37.153.97.255"
          },
          "90:b8:d0:3e:81:c9": {
            "family": "lladdr"
          }
        },
        "arp": {
          "37.153.96.85": "90:b8:d0:2a:0a:23",
          "37.153.96.1": "00:00:5e:00:01:01",
          "37.153.96.57": "90:b8:d0:9d:d6:63",
          "37.153.96.33": "90:b8:d0:3e:81:c9"
        }
      },
      "net1": {
        "mtu": "1500",
        "index": "3",
        "flags": [
          "UP",
          "BROADCAST",
          "RUNNING",
          "MULTICAST",
          "IPv4",
          "CoS",
          "L3PROTECT"
        ],
        "type": "net",
        "number": "1",
        "encapsulation": "Ethernet",
        "addresses": {
          "10.224.0.34": {
            "family": "inet",
            "netmask": "255.255.248.0",
            "broadcast": "10.224.7.255"
          },
          "90:b8:d0:6c:08:fa": {
            "family": "lladdr"
          }
        },
        "arp": {
          "10.224.0.34": "90:b8:d0:6c:08:fa",
          "10.224.0.1": "00:00:5e:00:01:01"
        }
      }
    },
    "default_interface": "net0",
    "default_gateway": "37.153.96.1"
  },
@jacques jacques [OHAI-531] Regex for getting data from arp -na output is incorrect on…
… Solaris2

Signed-off-by: Jacques Marneweck <jacques@powertrip.co.za>
258a6fa
@btm
Chef Software, Inc. member

Could you please add a unit test for this output?

@btm btm commented on the diff Nov 18, 2013
lib/ohai/plugins/solaris2/network.rb
so = shell_out("arp -an")
so.stdout.lines do |line|
- if line =~ /([0-9a-zA-Z]+)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\w+)\s+([a-zA-Z0-9\.\:\-]+)/
+ if line =~ /^([0-9a-zA-Z\.\:\-]+)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([SPLA]+)?\s+([a-fA-F0-9\:]+)/
@btm
btm Nov 18, 2013

Could this be more readable? Do we need to match IP addresses with \s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) or could we match on something simpler? Perhaps move those into local variables and use string interpolation to make the regex more clear.

r_interface_name = "([0-9a-zA-Z\.\:\-]+)"
r_ip_address = "(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
r_mac_address = "([a-fA-F0-9\:]+)"
if line =~ /^#{r_interface_name}\s+#{r_ip_address}\s+#{r_ip_address}\s+([SPLA]+)?\s+#{r_mac_address}/

Thoughts?

@jacques
jacques Apr 18, 2014

Never did get the regex working on Solaris hosts with the string interpolation. Redoing this on OHAI-531-fix-arp-na-data for Ohai 7.0.x

@btm
Chef Software, Inc. member

Replaced by #318

@btm btm closed this Apr 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment