-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #910 from MichalRebisz/snmp_agent
Add SNMP agent plugin
- Loading branch information
Showing
7 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}), | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
}] |