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

Windows support #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions snmp/conf.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions snmp/default.sls
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ default_snmpd:
- mode: 644
- watch_in:
- service: {{ snmp.service }}

139 changes: 139 additions & 0 deletions snmp/files/distro
Original file line number Diff line number Diff line change
@@ -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:]]' </etc/gentoo-release | tr -d " ")

elif [ -f /etc/arch-release ] ; then
DIST="Arch Linux"
REV="" # Omit version since Arch Linux uses rolling releases
IGNORE_LSB=1 # /etc/lsb-release would overwrite $REV with "rolling"

elif [ -f /etc/photon-release ] ; then
DIST=$(head -1 < /etc/photon-release)
REV=$(sed -n -e 's/^.*PHOTON_BUILD_NUMBER=//p' /etc/photon-release)
IGNORE_LSB=1 # photon os does not have /etc/lsb-release nor lsb_release

elif [ -f /etc/os-release ] ; then
DIST=$(grep '^NAME=' /etc/os-release | cut -d= -f2- | tr -d '"')
REV=$(grep '^VERSION_ID=' /etc/os-release | cut -d= -f2- | tr -d '"')

elif [ -f /etc/openwrt_version ] ; then
DIST="OpenWrt"
REV=$(cat /etc/openwrt_version)

elif [ -f /etc/pld-release ] ; then
DIST=$(cat /etc/pld-release)
REV=""

elif [ -f /etc/SuSE-release ] ; then
DIST=$(echo SLES $(grep VERSION /etc/SuSE-release | cut -d = -f 2 | tr -d " "))
REV=$(echo SP$(grep PATCHLEVEL /etc/SuSE-release | cut -d = -f 2 | tr -d " "))
fi

if [ -f /etc/lsb-release -a "${IGNORE_LSB}" != 1 ] ; then
LSB_DIST=$(lsb_release -si)
LSB_REV=$(lsb_release -sr)
if [ "$LSB_DIST" != "" ] ; then
DIST=$LSB_DIST
fi
if [ "$LSB_REV" != "" ] ; then
REV=$LSB_REV
fi
fi

if [ -x "$(command -v awk)" ]; then # some distros do not ship with awk
if [ "`uname -a | awk '{print $(NF)}'`" = "DD-WRT" ] ; then
DIST="dd-wrt"
fi
if [ "`uname -a | awk '{print $(NF)}'`" = "ASUSWRT-Merlin" ] ; then
DIST="ASUSWRT-Merlin"
REV=`nvram show | grep buildno= | egrep -o '[0-9].[0-9].[0-9]'` > /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}
7 changes: 7 additions & 0 deletions snmp/files/snmpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ syscontact "{{ conf.get('syscontact', 'Root <root@localhost> (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
#
Expand Down
32 changes: 32 additions & 0 deletions snmp/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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}) %}
64 changes: 64 additions & 0 deletions snmp/windows.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% from "snmp/map.jinja" import snmp with context %}
{% set mushStamp = salt['grains.get']('osfinger', 'NA') %}

{% 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
- 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 %}
Core Package:
cmd.run:
- name: 'servermanagercmd -install {{ snmp.pkg }} -allSubFeatures'
{% endif %}

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'

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 <root@localhost> (add saltstack pillar)') }}" /f'

{% 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 %}

{%- 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 -%}

{%- 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