Skip to content

Instantly share code, notes, and snippets.

@sshimko
Created July 30, 2021 16:00
Show Gist options
  • Save sshimko/2a4b0cc3985be0fe50ca4ebe220d9962 to your computer and use it in GitHub Desktop.
Save sshimko/2a4b0cc3985be0fe50ca4ebe220d9962 to your computer and use it in GitHub Desktop.
snmpd.com for MacOS with extend for distro, serial, hardware, and manufacturer.
# Sort out your own auth.
com2sec mynetwork 192.168.0.1/24 COMMUNITYNAME
rocommunity COMMUNITYNAME default .1
syscontact My Name <MyEmail@address.com>
syslocation Judecca
# LibreNMS had some example extends for Linux so I put these together for macOS.
extend distro /bin/bash -c '/usr/bin/sw_vers|grep -v Build|sed -e "s/^.*:.//"|tr "\\n" " "'
# This gives a pretty name, but a pretty name isn't always available in a system-wide place and pointing into /Users/ somewhere is bad.
# so in those cases return the ugly name instead. An example is a 2019 MBP. The pretty name doesn't exist in this plist in 11.5 or 12.0.
extend hardware /bin/bash -c -o pipefail "(/usr/libexec/PlistBuddy -c \"print :$(sysctl hw.model | cut -f 2 -d ' '):_LOCALIZABLE_:marketingModel\" /System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/en.lproj/SIMachineAttributes.plist 2>/dev/null|sed 's/\"/-inch/') || (sysctl hw.model |cut -f 2 -d ' ')"
extend manufacturer /bin/bash -c "/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice | awk -F\\< ' /manufacturer/ { print substr($2, 2, length($2) - 3); exit 0; }'
extend serial /bin/bash -c "/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice | awk ' /IOPlatformSerialNumber/ { print substr($3, 2, length($3) - 2); exit 0; }'"
# Sample output for the extends (sanitized to protect the guilty).
# snmpwalk -c COMMUNITYNAME -v 2c localhost NET-SNMP-EXTEND-MIB::nsExtendObjects
#
# NET-SNMP-EXTEND-MIB::nsExtendOutLine."distro".1 = STRING: macOS 12.0
# NET-SNMP-EXTEND-MIB::nsExtendOutLine."serial".1 = STRING: SOMESERIAL
# NET-SNMP-EXTEND-MIB::nsExtendOutLine."hardware".1 = STRING: 27-inch iMac (Early 2019)
# NET-SNMP-EXTEND-MIB::nsExtendOutLine."manufacturer".1 = STRING: Apple Inc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment