Forum: CFEngine Help Subject: Find network interfaces that did not autonegotiate to 1000fdx Author: msvob...@linkedin.com Link to topic: https://cfengine.com/forum/read.php?3,27223,27223#msg-27223
We had an issue where a network switch rebooted and once it came back up, all machines on the switch auto-negotiated to 100 full duplex instead of 1 gigabit full duplex. This is a perfect case for Cfengine to detect a class and report on the condition... So, here you go. A policy to detect network interfaces for Linux / Solaris that are active and have not negotiated to 1000fdx. Cheers Mike bundle agent network_configuration { vars: linux:: "network_interfaces" slist => splitstring(execresult("/sbin/ip link | /bin/egrep -v 'link|DOWN|LOOPBACK' | /bin/awk '{print $2}' | /bin/grep -v bond | /bin/sed 's/://'", "useshell"), "$(const.n)", "99999999999"), handle => "linux_generate_network_interface_list"; sunos_5_10:: "network_interfaces" slist => splitstring(execresult("/sbin/dladm show-dev | /bin/grep 'link: up' | /bin/awk '{print $1}'", "useshell"), "$(const.n)", "99999999999"), handle => "solaris_generate_network_interface_list"; linux:: "$(network_interfaces)_speed" string => execresult("/sbin/ethtool $(network_interfaces) | /bin/grep Speed | /bin/awk '{print $2}'", "useshell"), handle => "linux_get_per_interface_speed"; linux:: "$(network_interfaces)_duplex" string => execresult("/sbin/ethtool $(network_interfaces) | /bin/grep Duplex | /bin/awk '{print $2}'", "useshell"), handle => "linux_get_per_interface_duplex"; sunos_5_10:: "$(network_interfaces)_speed" string => execresult("/sbin/dladm show-dev | /bin/grep $(network_interfaces) | /bin/awk '{print $5}'", "useshell"), handle => "solaris_get_per_interface_speed"; sunos_5_10:: "$(network_interfaces)_duplex" string => execresult("/sbin/dladm show-dev | /bin/grep $(network_interfaces) | /bin/awk '{print $8}'", "useshell"), handle => "solaris_get_per_interface_duplex"; classes: linux:: "$(network_interfaces)_not_gigabit" not => regcmp("1000Mb/s", "$($(network_interfaces)_speed)" ); linux:: "$(network_interfaces)_not_fdx" not => regcmp("Full", "$($(network_interfaces)_duplex)" ); sunos_5_10:: "$(network_interfaces)_not_gigabit" not => regcmp("1000", "$($(network_interfaces)_speed)" ); sunos_5_10:: "$(network_interfaces)_not_fdx" not => regcmp("full", "$($(network_interfaces)_duplex)" ); reports: sunos_5_10|linux:: "cf3: The machine $(sys.host) has the network interface $(network_interfaces) that did not negotiate to 1 gigabit speeds", handle => "report_on_non_gigabit_interfaces", ifvarclass => canonify("$(network_interfaces)_not_gigabit"); "cf3: The machine $(sys.host) has the network interface $(network_interfaces) that did not negotiate to full duplex", handle => "report_on_half_duplex_interfaces", ifvarclass => canonify("$(network_interfaces)_not_fdx"); } The policy in action for Solaris: $ /var/cfengine/bin/cf-agent -I -K -b network_configuration >> Using command line specified bundlesequence R: cf3: The machine has the network interface e1000g0 that did not negotiate to 1 gigabit speeds $ dladm show-dev e1000g0 link: up speed: 100 Mbps duplex: full e1000g1 link: up speed: 1000 Mbps duplex: full e1000g2 link: unknown speed: 0 Mbps duplex: half e1000g3 link: unknown speed: 0 Mbps duplex: half The policy in action for Linux: # ethtool -s eth2 speed 100 duplex half # /var/cfengine/bin/cf-agent -I -K -b network_configuration >> Using command line specified bundlesequence R: cf3: The machine esv4-linux-test04.corp.linkedin.com has the network interface eth2 that did not negotiate to 1 gigabit speeds R: cf3: The machine esv4-linux-test04.corp.linkedin.com has the network interface eth2 that did not negotiate to full duplex _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine