Skip to content

Commit

Permalink
Merge pull request #910 from MichalRebisz/snmp_agent
Browse files Browse the repository at this point in the history
Add SNMP agent plugin
  • Loading branch information
bastelfreak authored Feb 24, 2020
2 parents 1293661 + 6478341 commit 974a4c3
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ documentation for each plugin for configurable attributes.
* `sensors` (see [collectd::plugin::sensors](#class-collectdpluginsensors) below)
* `smart` (see [collectd::plugin::smart](#class-collectdpluginsmart) below)
* `snmp` (see [collectd::plugin::snmp](#class-collectdpluginsnmp) below)
* `snmp_agent` (see [collectd::plugin::snmp_agent](#class-collectdpluginsnmpagent) below)
* `statsd` (see [collectd::plugin::statsd](#class-collectdpluginstatsd) below)
* `swap` (see [collectd::plugin::swap](#class-collectdpluginswap) below)
* `syslog` (see [collectd::plugin::syslog](#class-collectdpluginsyslog) below)
Expand Down Expand Up @@ -1726,7 +1727,39 @@ class { 'collectd::plugin::snmp':
},
}
```
#### Class: `collectd::plugin::snmp_agent`

```puppet
class {'collectd::plugin::snmp_agent':
table => {
ifTable => {
'indexoid' => 'IF-MIB::ifIndex',
'sizeoid' => 'IF-MIB::ifNumber',
data => [{
ifDescr => {
'plugin' => 'interface',
'oids' => 'IF-MIB::ifDescr'
},
'ifDescr2' => {
'plugin' => 'interface2',
'oids' => 'IF-MIB::ifDescr2'
}
}]
}
},
data => {
memAvailReal => {
'plugin' => 'memory',
'type' => 'memory',
'oids' => '1.3.6.1.4.1.2021.4.6.0',
'typeinstance' => 'free',
'indexkey' => {
'source' => 'PluginInstance'
}
}
}
}
```
#### Class: `collectd::plugin::statsd`

```puppet
Expand Down
54 changes: 54 additions & 0 deletions manifests/plugin/snmp_agent.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Class: collectd::plugin::snmp_agent
#
# @see https://wiki.opnfv.org/display/fastpath/SNMP+Agent+HLD
#
# Configues snmp agent plugin.
#
# @param ensure String Passed to package and collectd::plugin resources (both). Default: present
# @param data Optional[Hash[String[1],Collectd::SNMP_AGENT::Data]] Defines scalar field, must be put outside Table block.
# @param table Hash[String[1], Collectd::SNMP_AGENT::Table] Defines a table consisting of several Data blocks being its columns
class collectd::plugin::snmp_agent(
Enum['present', 'absent'] $ensure = 'present',
Optional[Hash[String[1],Collectd::SNMP_AGENT::Data]] $data = {
'memAvailReal' => {
'oids' => '1.3.6.1.4.1.2021.4.6.0',
'plugin' => 'memory',
'type' => 'memory',
'typeinstance' => 'free',
},
},
Hash[String[1], Collectd::SNMP_AGENT::Table] $table = {
'ifTable' => {
'indexoid' => 'IF-MIB::ifIndex',
'sizeoid' => 'IF-MIB::ifNumber',
'data'=> {
'ifDescr' => {
'plugin' => 'interface',
'oids' => 'IF-MIB::ifDescr',
'indexkey' => {
'source' => 'PluginInstance',
},
},
'ifOctets' => {
'plugin' => 'interface',
'oids' => 'F-MIB::ifInOctets" "IF-MIB::ifOutOctets',
'type' => 'if_octets',
'typeinstance' => '',
},
},
},
}
) {

include collectd

collectd::plugin { 'snmp_agent':
ensure => $ensure,
content => epp('collectd/plugin/snmp_agent.conf.epp', {
'data' => $data,
'table' => $table
}),
}
}


29 changes: 29 additions & 0 deletions spec/classes/collectd_plugin_snmp_agent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe 'collectd::plugin::snmp_agent', type: :class do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

it { is_expected.to compile.with_all_deps }
options = os_specific_options(facts)

context ':ensure => present and default parameters' do
it "Will create #{options[:plugin_conf_dir]}/10-snmp_agent.conf to load the plugin" do
is_expected.to contain_file('snmp_agent.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-snmp_agent.conf"
)
end
end

it { is_expected.to contain_file('snmp_agent.load').with_content(%r{OIDs "F-MIB::ifInOctets" "IF-MIB::ifOutOctets"}) }
it { is_expected.to contain_file('snmp_agent.load').with_content(%r{<Data "ifOctets">}) }
it { is_expected.to contain_file('snmp_agent.load').with_content(%r{<Table "ifTable">}) }
it { is_expected.to contain_file('snmp_agent.load').with_content(%r{<Data "memAvailReal">}) }
it { is_expected.to contain_file('snmp_agent.load').with_content(%r{OIDs "1.3.6.1.4.1.2021.4.6.0"}) }
end
end
end
108 changes: 108 additions & 0 deletions templates/plugin/snmp_agent.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<%- | Optional $data = undef,
Optional $table = undef,
| -%>
# THIS FILE IS MANAGED BY PUPPET
<Plugin snmp_agent>
<% if $data { -%>
<% $data.keys.sort.each |$key| { -%>
<Data "<%= $key %>">
<% $data[$key].each |$keyvalue, $value| { -%>
<% if $keyvalue == 'plugin' { -%>
Plugin "<%= $value %>"
<% } -%>
<% if $keyvalue == 'oids' { -%>
OIDs "<%= $value %>"
<% } -%>
<% if $keyvalue == 'type' { -%>
Type "<%= $value %>"
<% } -%>
<% if $keyvalue == 'typeinstance' { -%>
TypeInstance "<%= $value %>"
<% } -%>
<% if $keyvalue == 'scale' { -%>
Scale "<%= $value %>"
<% } -%>
<% if $keyvalue == 'shift' { -%>
Shift "<%= $value %>"
<% } -%>
<% if $keyvalue == 'plugininstance' { -%>
PluginInstance "<%= $value %>"
<% } -%>
<% if $keyvalue == 'indexkey' { -%>
<IndexKey>
<% $value.keys.sort.each |$indexkey| { -%>
<% if $indexkey == 'source' { -%>
Source "<%= $value[$indexkey] %>"
<% } -%>
<% if $indexkey == 'regex' { -%>
Regex "<%= $value[$indexkey] %>"
<% } -%>
<% if $indexkey == 'group' { -%>
Group "<%= $value[$indexkey] %>"
<% } -%>
<% } -%>
</IndexKey>
<% } -%>
<% } -%>
</Data>
<% } -%>
<% } -%>
<% if $table { -%>
<% $table.keys.sort.each |$key| { -%>
<Table "<%= $key %>">
<% $table[$key].each |$keyvalue, $value| { -%>
<% if $keyvalue == 'indexoid' { -%>
IndexOID "<%= $value %>"
<% } -%>
<% if $keyvalue == 'sizeoid' { -%>
SizeOID "<%= $value %>"
<% } -%>
<% if $keyvalue == 'data' { -%>
<% $value.keys.sort.each |$key| { -%>
<Data "<%= $key %>">
<% $value[$key].each |$keyvalue, $value| { -%>
<% if $keyvalue == 'plugin' { -%>
Plugin "<%= $value %>"
<% } -%>
<% if $keyvalue == 'oids' { -%>
OIDs "<%= $value %>"
<% } -%>
<% if $keyvalue == 'type' { -%>
Type "<%= $value %>"
<% } -%>
<% if $keyvalue == 'typeinstance' { -%>
TypeInstance "<%= $value %>"
<% } -%>
<% if $keyvalue == 'scale' { -%>
Scale "<%= $value %>"
<% } -%>
<% if $keyvalue == 'shift' { -%>
Shift "<%= $value %>"
<% } -%>
<% if $keyvalue == 'plugininstance' { -%>
PluginInstance "<%= $value %>"
<% } -%>
<% if $keyvalue == 'indexkey' { -%>
<IndexKey>
<% $value.keys.sort.each |$indexkey| { -%>
<% if $indexkey == 'source' { -%>
Source "<%= $value[$indexkey] %>"
<% } -%>
<% if $indexkey == 'regex' { -%>
Regex "<%= $value[$indexkey] %>"
<% } -%>
<% if $indexkey == 'group' { -%>
Group "<%= $value[$indexkey] %>"
<% } -%>
<% } -%>
</IndexKey>
<% } -%>
<% } -%>
</Data>
<% } -%>
<% } -%>
<% } -%>
</Table>
<% } -%>
<% } -%>
</Plugin>
11 changes: 11 additions & 0 deletions types/snmp_agent/data.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://wiki.opnfv.org/display/fastpath/SNMP+Agent+HLD
type Collectd::SNMP_AGENT::Data = Struct[{
'plugin' => String,
'oids' => String,
Optional['type'] => String,
Optional['typeinstance'] => String,
Optional['scale'] => String,
Optional['shift'] => String,
Optional['indexkey'] => Collectd::SNMP_AGENT::IndexKey,
Optional['plugininstance'] => String,
}]
6 changes: 6 additions & 0 deletions types/snmp_agent/indexkey.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://wiki.opnfv.org/display/fastpath/SNMP+Agent+HLD
type Collectd::SNMP_AGENT::IndexKey = Struct[
'source' => String,
Optional['regex'] => String,
Optional['group'] => String,
]
6 changes: 6 additions & 0 deletions types/snmp_agent/table.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://wiki.opnfv.org/display/fastpath/SNMP+Agent+HLD
type Collectd::SNMP_AGENT::Table = Struct[{
Optional['indexoid'] => String,
Optional['sizeoid'] => String,
Optional['data'] => Hash[String[1], Collectd::SNMP_AGENT::Data]
}]

0 comments on commit 974a4c3

Please sign in to comment.