From 4ee0691e63795ad7cf3dfdb159b874bee840e971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20M=E4kinen?= Date: Wed, 24 Apr 2013 13:59:05 +0300 Subject: [PATCH] Initial version of snmp module. --- snmp/files/snmptrapd.rc | 8 ++++ snmp/manifests/init.pp | 71 +++++++++++++++++++++++++++++++ snmp/templates/snmptrapd.conf.erb | 9 ++++ 3 files changed, 88 insertions(+) create mode 100644 snmp/files/snmptrapd.rc create mode 100644 snmp/manifests/init.pp create mode 100644 snmp/templates/snmptrapd.conf.erb diff --git a/snmp/files/snmptrapd.rc b/snmp/files/snmptrapd.rc new file mode 100644 index 0000000..2b3d049 --- /dev/null +++ b/snmp/files/snmptrapd.rc @@ -0,0 +1,8 @@ +#!/bin/sh + +daemon="/usr/local/sbin/snmptrapd" +daemon_flags="-n -u snmptrapd -g snmptrapd -c /etc/snmptrapd.conf" + +. /etc/rc.d/rc.subr + +rc_cmd $1 diff --git a/snmp/manifests/init.pp b/snmp/manifests/init.pp new file mode 100644 index 0000000..bfa887a --- /dev/null +++ b/snmp/manifests/init.pp @@ -0,0 +1,71 @@ + +# Install net-snmp utilities +# +class snmp::utils { + + package { "net-snmp": + name => $::operatingsystem ? { + "openbsd" => "net-snmp", + default => "net-snmp-utils", + }, + ensure => installed, + } + +} + +# Install snmp trap daemon +# +# === Parameters +# +# $acl: +# Array containing list of allowed SNMP community names. +# Defaults is to allow all trap messages. +# +# === Sample usage +# +# class { "snmp::trapd": +# acl => [ "public", ], +# } +# +class snmp::trapd($acl=NONE) { + + require snmp::utils + include user::system + + realize([ User["snmptrapd"], Group["snmptrapd"], ]) + + case $::operatingsystem { + "openbsd": { + file { "/etc/rc.d/snmptrapd": + ensure => present, + source => "puppet:///modules/snmp/snmptrapd.rc", + mode => "0755", + owner => "root", + group => "wheel", + notify => Service["snmptrapd"], + } + } + default: { + fail("snmp::trapd not supported in ${::operatingsystem}") + } + } + + file { "/etc/snmptrapd.conf": + ensure => present, + content => template("snmp/snmptrapd.conf.erb"), + mode => "0644", + owner => "root", + group => $::operatingsystem ? { + "openbsd" => "wheel", + default => "root", + }, + notify => Service["snmptrapd"], + } + + service { "snmptrapd": + ensure => running, + enable => true, + require => User["snmptrapd"], + } + +} diff --git a/snmp/templates/snmptrapd.conf.erb b/snmp/templates/snmptrapd.conf.erb new file mode 100644 index 0000000..850f253 --- /dev/null +++ b/snmp/templates/snmptrapd.conf.erb @@ -0,0 +1,9 @@ + +pidFile /var/run/snmptrapd.pid +<% if acl == 'NONE' -%> +disableAuthorization yes +<% else -%> +<% acl.each do |rule| -%> +authCommunity log <%= rule %> +<% end -%> +<% end -%>