From 8c6cdc72b7b9023f2f5ec9b65f94c30a5b58bd7e Mon Sep 17 00:00:00 2001 From: "Joshua M. Schmidlkofer" Date: Wed, 16 May 2018 11:07:34 -0700 Subject: [PATCH 1/3] Windows: Add support for Windows 10, Windows Server 2008r2-2016 --- snmp/map.jinja | 32 +++++++++++++++++++++++ snmp/windows.sls | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 snmp/windows.sls diff --git a/snmp/map.jinja b/snmp/map.jinja index 873a64f..ddc4d04 100644 --- a/snmp/map.jinja +++ b/snmp/map.jinja @@ -50,6 +50,9 @@ FreeBSD: pkg: net-snmp pkgutils: net-snmp rootgroup: wheel +Windows: + pkg: SNMP-Service + pkgutils: SNMP-WMI-Provider {% endload %} {% load_yaml as rhel_specific %} @@ -74,3 +77,32 @@ FreeBSD: {% if user_override %} {% do snmp.update(user_override) %} {% endif %} + +{% set Sources = [] %} +{% for rocommunity in salt['pillar.get']('snmp:conf:rocommunities', '') %} + Community: {{ rocommunity }} + {% set source = salt['pillar.get']('snmp:conf:rocommunities:'+ rocommunity +':source', '') %} + {% if source.__class__ in (().__class__, [].__class__) %} + {% for i in source %} + {% set WinManager = Sources.append(i) %} + {% endfor %} + {% elif source != '' %} + {% set WinManager = Sources.append(source) %} + {% else %} + {% endif %} +{% endfor %} + +{% for rwcommunity in salt['pillar.get']('snmp:conf:rwcommunities', '') %} + Community: {{ rwcommunity }} + {% set source = salt['pillar.get']('snmp:conf:rwcommunities:'+ rwcommunity +':source', '') %} + {% if source.__class__ in (().__class__, [].__class__) %} + {% for i in source %} + {% set WinManager = Sources.append(i) %} + {% endfor %} + {% elif source != '' %} + {% set WinManager = Sources.append(source) %} + {% else %} + {% endif %} +{% endfor %} + +{% do snmp.update({'Sources': Sources}) %} diff --git a/snmp/windows.sls b/snmp/windows.sls new file mode 100644 index 0000000..2dba68c --- /dev/null +++ b/snmp/windows.sls @@ -0,0 +1,67 @@ +{% from "snmp/map.jinja" import snmp with context %} +{% set mushStamp = salt['grains.get']('osfinger', 'NA') %} + +{% if mushStamp in ('Windows-2016Server', 'Windows-2012Server') %} +Core Package: + win_servermanager.installed: + - force: True + - recurse: True + - name: {{ snmp.pkg }} + +WMI Poller Package: + win_servermanager.installed: + - force: True + - recurse: True + - name: {{ snmp.pkgutils }} +{% elif mushStamp in ('Windows-10') %} +Core Package: + cmd.run: + - name: 'dism.exe /online /enable-feature /featurename:"SNMP" /featurename:"WMISnmpProvider"' +{% else %} +### Windows 2008r2 Fallback +Core Package: + cmd.run: + - name: 'servermanagercmd -install {{ snmp.pkg }} -allSubFeatures' +{% endif %} + +#### Location Key +sysLocation: + cmd.run: + - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\RFC1156Agent" /v sysLocation /t REG_SZ /d "{{ salt['pillar.get']('snmp:conf:location', 'Unknown (add saltstack pillar)') }}" /f' + +#### System Contact Key +sysContact: + cmd.run: + - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\RFC1156Agent" /v sysContact /t REG_SZ /d "{{ salt['pillar.get']('snmp:conf:syscontact', 'Root (add saltstack pillar)') }}" /f' + +{% for manager in snmp.WindowsManager %} +HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers{{ loop.index }}: + cmd.run: + - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v {{ loop.index }} /t REG_SZ /d observium.erickson.is /f' +{% endfor %} + +# Version 1/2c users (read/write) +#1/1 - None +#2/2 - Notify +#4/4 - Read Only +#8/10 - Read Write +{%- for rwcommunity in salt['pillar.get']('snmp:conf:rwcommunities', '') %} +HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities: + cmd.run: + - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v {{ rwcommunity }} /t REG_DWORD /d 10 /f' +{%- endfor -%} + +#4/4 - Read Only +{%- for rocommunity in salt['pillar.get']('snmp:conf:rocommunities', '') %} +HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities: + cmd.run: + - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v {{ rocommunity }} /t REG_DWORD /d 4 /f' +{% endfor -%} + +snmp: + service.running: + - reload: True + - watch: + - cmd: HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/services/SNMP/Parameters/ValidCommunities + - cmd: syslocation + - cmd: sysContact From 36dbd5c8a595f3ad64b164689207042b14b38a79 Mon Sep 17 00:00:00 2001 From: "Joshua M. Schmidlkofer" Date: Wed, 16 May 2018 11:12:02 -0700 Subject: [PATCH 2/3] Windows: Add support for Windows 10, Windows 2008 R2 to 2016 --- snmp/windows.sls | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/snmp/windows.sls b/snmp/windows.sls index 2dba68c..3ef1bc4 100644 --- a/snmp/windows.sls +++ b/snmp/windows.sls @@ -18,40 +18,31 @@ Core Package: cmd.run: - name: 'dism.exe /online /enable-feature /featurename:"SNMP" /featurename:"WMISnmpProvider"' {% else %} -### Windows 2008r2 Fallback Core Package: cmd.run: - name: 'servermanagercmd -install {{ snmp.pkg }} -allSubFeatures' {% endif %} -#### Location Key sysLocation: cmd.run: - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\RFC1156Agent" /v sysLocation /t REG_SZ /d "{{ salt['pillar.get']('snmp:conf:location', 'Unknown (add saltstack pillar)') }}" /f' -#### System Contact Key sysContact: cmd.run: - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\RFC1156Agent" /v sysContact /t REG_SZ /d "{{ salt['pillar.get']('snmp:conf:syscontact', 'Root (add saltstack pillar)') }}" /f' -{% for manager in snmp.WindowsManager %} +{% for manager in snmp.Sources %} HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers{{ loop.index }}: cmd.run: - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v {{ loop.index }} /t REG_SZ /d observium.erickson.is /f' {% endfor %} -# Version 1/2c users (read/write) -#1/1 - None -#2/2 - Notify -#4/4 - Read Only -#8/10 - Read Write {%- for rwcommunity in salt['pillar.get']('snmp:conf:rwcommunities', '') %} HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities: cmd.run: - name: 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v {{ rwcommunity }} /t REG_DWORD /d 10 /f' {%- endfor -%} -#4/4 - Read Only {%- for rocommunity in salt['pillar.get']('snmp:conf:rocommunities', '') %} HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities: cmd.run: From f989e60acbf7993e6d83be51904f9f9575b6f4df Mon Sep 17 00:00:00 2001 From: "Joshua M. Schmidlkofer" Date: Tue, 22 Jan 2019 11:23:21 -0800 Subject: [PATCH 3/3] Update: update default config, add Librenms distro agent to stock config --- snmp/conf.sls | 8 +++ snmp/default.sls | 1 + snmp/files/distro | 139 ++++++++++++++++++++++++++++++++++++++++++ snmp/files/snmpd.conf | 7 +++ snmp/windows.sls | 8 ++- 5 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 snmp/files/distro diff --git a/snmp/conf.sls b/snmp/conf.sls index b560d08..30f546c 100644 --- a/snmp/conf.sls +++ b/snmp/conf.sls @@ -4,6 +4,14 @@ include: - snmp + +/usr/local/bin/distro: + file.managed: + - user: root + - group: root + - mode: 750 + - source: salt://snmp/files/distro + snmp_conf: file.managed: - name: {{ snmp.config }} diff --git a/snmp/default.sls b/snmp/default.sls index e48de2d..7455008 100644 --- a/snmp/default.sls +++ b/snmp/default.sls @@ -13,3 +13,4 @@ default_snmpd: - mode: 644 - watch_in: - service: {{ snmp.service }} + diff --git a/snmp/files/distro b/snmp/files/distro new file mode 100644 index 0000000..cd9e814 --- /dev/null +++ b/snmp/files/distro @@ -0,0 +1,139 @@ +#!/usr/bin/env bash +# Detects which OS and if it is Linux then it will detect which Linux Distribution. + +OS=`uname -s` +REV=`uname -r` +MACH=`uname -m` + +if [ "${OS}" = "SunOS" ] ; then + OS=Solaris + ARCH=`uname -p` + OSSTR="${OS} ${REV}(${ARCH} `uname -v`)" + +elif [ "${OS}" = "AIX" ] ; then + OSSTR="${OS} `oslevel` (`oslevel -r`)" + +elif [ "${OS}" = "Linux" ] ; then + KERNEL=`uname -r` + + if [ -f /etc/fedora-release ]; then + DIST=$(cat /etc/fedora-release | awk '{print $1}') + REV=`cat /etc/fedora-release | sed s/.*release\ // | sed s/\ .*//` + + elif [ -f /etc/redhat-release ] ; then + DIST=$(cat /etc/redhat-release | awk '{print $1}') + if [ "${DIST}" = "CentOS" ]; then + DIST="CentOS" + elif [ "${DIST}" = "CloudLinux" ]; then + DIST="CloudLinux" + elif [ "${DIST}" = "Mandriva" ]; then + DIST="Mandriva" + PSEUDONAME=`cat /etc/mandriva-release | sed s/.*\(// | sed s/\)//` + REV=`cat /etc/mandriva-release | sed s/.*release\ // | sed s/\ .*//` + elif [ -f /etc/oracle-release ]; then + DIST="Oracle" + elif [ -f /etc/rockstor-release ]; then + DIST="Rockstor" + else + DIST="RedHat" + fi + + PSEUDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//` + REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` + + elif [ -f /etc/mandrake-release ] ; then + DIST='Mandrake' + PSEUDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//` + REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//` + + elif [ -f /etc/devuan_version ] ; then + DIST="Devuan `cat /etc/devuan_version`" + REV="" + + elif [ -f /etc/debian_version ] ; then + DIST="Debian `cat /etc/debian_version`" + REV="" + if [ -f /usr/bin/lsb_release ] ; then + ID=`lsb_release -i | awk -F ':' '{print $2}' | sed 's/ //g'` + fi + if [ "${ID}" = "Raspbian" ] ; then + DIST="Raspbian `cat /etc/debian_version`" + fi + if [ -f /usr/bin/pveversion ]; then + DIST="${DIST}/PVE `/usr/bin/pveversion | cut -d '/' -f 2`" + fi + + elif [ -f /etc/gentoo-release ] ; then + DIST="Gentoo" + REV=$(tr -d '[[:alpha:]]' /dev/null 2>&1 + fi + fi + + if [ -n "${REV}" ] + then + OSSTR="${DIST} ${REV}" + else + OSSTR="${DIST}" + fi + +elif [ "${OS}" = "Darwin" ] ; then + if [ -f /usr/bin/sw_vers ] ; then + OSSTR=`/usr/bin/sw_vers|grep -v Build|sed 's/^.*:.//'| tr "\n" ' '` + fi + +elif [ "${OS}" = "FreeBSD" ] ; then + DIST=$(cat /etc/version | cut -d'-' -f 1) + if [ "${DIST}" = "FreeNAS" ]; then + OSSTR=`cat /etc/version | cut -d' ' -f 1` + else + OSSTR=`/usr/bin/uname -mior` + fi +fi + +echo ${OSSTR} diff --git a/snmp/files/snmpd.conf b/snmp/files/snmpd.conf index 5275494..fb3bd2a 100644 --- a/snmp/files/snmpd.conf +++ b/snmp/files/snmpd.conf @@ -197,6 +197,13 @@ syscontact "{{ conf.get('syscontact', 'Root (add saltstack pill # system.sysServices.0 = 72 +#Distro Detection +extend .1.3.6.1.4.1.2021.7890.1 distro /usr/local/bin/distro +#Hardware Detection (uncomment to enable) +extend .1.3.6.1.4.1.2021.7890.2 hardware '/bin/cat /sys/devices/virtual/dmi/id/product_name' +extend .1.3.6.1.4.1.2021.7890.3 manufacturer '/bin/cat /sys/devices/virtual/dmi/id/sys_vendor' +extend .1.3.6.1.4.1.2021.7890.4 serial '/bin/cat /sys/devices/virtual/dmi/id/product_serial' + ############################################################################### # Logging # diff --git a/snmp/windows.sls b/snmp/windows.sls index 3ef1bc4..6968f70 100644 --- a/snmp/windows.sls +++ b/snmp/windows.sls @@ -1,7 +1,13 @@ {% from "snmp/map.jinja" import snmp with context %} {% set mushStamp = salt['grains.get']('osfinger', 'NA') %} -{% if mushStamp in ('Windows-2016Server', 'Windows-2012Server') %} +{% if mushStamp in ('Windows-2016Server', 'Windows-2012ServerR2', 'Windows-2012Server') %} +Remote Server Admin: + win_servermanager.installed: + - force: True + - recurse: True + - name: RSAT + Core Package: win_servermanager.installed: - force: True