.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Munin::Plugin::SNMP 3pm" .TH Munin::Plugin::SNMP 3pm "2021-03-08" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Munin::Plugin::SNMP \- Net::SNMP subclass for Munin plugins .SH "SYNOPSIS" .IX Header "SYNOPSIS" The Munin::Plugin::SNMP module extends Net::SNMP with methods useful for Munin plugins. .SH "SNMP CONFIGURATION" .IX Header "SNMP CONFIGURATION" \&\s-1SNMP\s0 plugins (that use this module) share a common configuration interface implemented in the function \fBsession()\fR. Please see the documentation for that function for complete instructions and examples on how to configure \s-1SNMP.\s0 The documentation is located there to ensure that it is up to date and matches the code. .SH "DEBUGGING" .IX Header "DEBUGGING" Additional debugging messages can be enabled by setting \&\f(CW$Munin::Plugin::SNMP::DEBUG\fR, \f(CW$Munin::Plugin::DEBUG\fR, or by exporting the \f(CW\*(C`MUNIN_DEBUG\*(C'\fR environment variable before running the plugin (by passing the \f(CW\*(C`\-\-pidebug\*(C'\fR option to \f(CW\*(C`munin\-run\*(C'\fR, for instance). .SH "METHODS" .IX Header "METHODS" .SS "\fBconfig_session()\fP \- Decode environment to get the needed plugin configuration parameters" .IX Subsection "config_session() - Decode environment to get the needed plugin configuration parameters" .Vb 1 \& ($host, $port, $version, $tail) = Munin::Plugin::SNMP\->config_session(); .Ve .PP This is a convenience function for the \*(L"config\*(R" part of the plugin \- it decodes the environment/plugin name to retrieve the information needed in the configuration phase. It returns a 4 tuple consisting of: .IP "1) the host name" 4 .IX Item "1) the host name" .PD 0 .IP "2) the \s-1UDP\s0 port to use" 4 .IX Item "2) the UDP port to use" .IP "3) the \s-1SNMP\s0 version to use (3 for version 3, 2 for version 1 or 2c)" 4 .IX Item "3) the SNMP version to use (3 for version 3, 2 for version 1 or 2c)" .ie n .IP "4) the tail of the plugin name: whatever is left of the plugin name after ""snmp__""." 4 .el .IP "4) the tail of the plugin name: whatever is left of the plugin name after ``snmp__''." 4 .IX Item "4) the tail of the plugin name: whatever is left of the plugin name after snmp__." .PD .PP The tail can be interesting for the \*(L"fetch\*(R" part of the plugin as well. .SS "session([optional Net::SNMP options]) \- create new Munin::Plugin::SNMP object" .IX Subsection "session([optional Net::SNMP options]) - create new Munin::Plugin::SNMP object" .Vb 1 \& $session = Munin::Plugin::SNMP\->session(); .Ve .PP This method overrides the Net::SNMP constructor to get the connection information from the plugin name and/or environment. Please note that no error string is returned. The function handles errors internally \- giving a error message and calling die. Calling die is the right thing to do. .PP The host name is taken from the plugin symlink, which must be on the form \f(CW\*(C`snmp[v3]__[_args]\*(C'\fR. .PP The \*(L"v3\*(R" form is taken to mean that SNMPv3 is to be used. It is also a name trick providing a separate \*(L"namespace\*(R" for devices that use SNMPv3 so it can be configured separately in munin/plugin\-conf.d/ files. E.g.: .PP .Vb 3 \& [snmp_*] \& env.version 2 \& env.community public \& \& [snmpv3_*] \& env.v3username snmpoperator \& env.v3authpassword s3cr1tpa55w0rd .Ve .PP See below for how to configure for each different case. The first case above shows Munin's default configuration. .PP \&\s-1NOTE:\s0 munin-node-configure does not yet utilize the \*(L"v3\*(R" thing. .PP The following environment variables are consulted: .ie n .IP """env.host""" 4 .el .IP "\f(CWenv.host\fR" 4 .IX Item "env.host" If the plugin name (symlink) does not contain the host name this is used as the host name to connect to. .Sp The host name must be specified, but is usually specified in the plugin name. If the hostname somehow does not resolve in \s-1DNS\s0 (or the hosts file) it is possible to do this: .Sp .Vb 3 \& [snmp_*] \& env.version 2c \& env.community floppa \& \& [snmp_switch1.langfeldt.net] \& env.host 192.168.2.45 \& \& [snmp_switch2.langfeldt.net] \& env.host 192.168.2.46 .Ve .ie n .IP """env.port""" 4 .el .IP "\f(CWenv.port\fR" 4 .IX Item "env.port" The port to connect to. Default 161. .ie n .IP """env.timeout""" 4 .el .IP "\f(CWenv.timeout\fR" 4 .IX Item "env.timeout" The timeout in seconds to use. Default 5. .ie n .IP """env.domain""" 4 .el .IP "\f(CWenv.domain\fR" 4 .IX Item "env.domain" The Transport Domain to use for exchanging \s-1SNMP\s0 messages. The default is UDP/IPv4. Possible values: 'udp', 'udp4', 'udp/ipv4'; 'udp6', \&'udp/ipv6'; 'tcp', 'tcp4', 'tcp/ipv4'; 'tcp6', 'tcp/ipv6'. .ie n .IP """env.version""" 4 .el .IP "\f(CWenv.version\fR" 4 .IX Item "env.version" The \s-1SNMP\s0 version to use for the connection. One of 1, 2, 3, snmpv1, snmpv2c or snmpv3. \s-1SNMP\s0 v2 is better as it supports bulk operations. Therefore 2 is the default in \f(CW\*(C`Munin::Plugin::SNMP\*(C'\fR. If your device supports v3 that may be even better as it supports proper security \- but the encryption may slow things down. .Sp Security is handled differently for versions 1/2c and 3. See below. .IP "\s-1SNMP\s0 1/2c authentication" 4 .IX Item "SNMP 1/2c authentication" .PD 0 .ie n .IP """env.community""" 4 .el .IP "\f(CWenv.community\fR" 4 .IX Item "env.community" .PD The community name for version 1 and 2c agents. The default is \&'public'. If this works your device is probably very insecure and needs a security checkup. .IP "\s-1SNMP 3\s0 authentication" 4 .IX Item "SNMP 3 authentication" \&\s-1SNMP\s0 v3 has three security levels. Lowest is \f(CW\*(C`noAuthNoPriv\*(C'\fR, which provides neither authentication nor encryption. If a username and \&\f(CW\*(C`authpassword\*(C'\fR are given it goes up to \f(CW\*(C`authNoPriv\*(C'\fR, and the connection is authenticated. If \f(CW\*(C`privpassword\*(C'\fR is given the security level becomes \f(CW\*(C`authPriv\*(C'\fR \- the connection is authenticated and encrypted. .Sp \&\fBNote\fR: Encryption can slow down slow or heavily loaded network devices. For most uses \f(CW\*(C`authNoPriv\*(C'\fR will be secure enough \*(-- the password is sent over the network encrypted in any case. .Sp \&\f(CW\*(C`Munin::Plugin::SNMP\*(C'\fR does not support ContextEngineIDs and such for authentication/privacy. If you see the need and know how it should be done please send patches! .Sp For further reading on \s-1SNMP\s0 v3 security models please consult \s-1RFC3414\s0 and the documentation for Net::SNMP. .Sp If version is set to 3 or snmpv3 the following variables are used to define authentication: .RS 4 .ie n .IP """env.v3username""" 4 .el .IP "\f(CWenv.v3username\fR" 4 .IX Item "env.v3username" Username. There is no default. .ie n .IP """env.v3authpassword""" 4 .el .IP "\f(CWenv.v3authpassword\fR" 4 .IX Item "env.v3authpassword" Authentication password. Optional when encryption is also enabled, in which case defaults to the privacy password (\f(CW\*(C`env.v3privpassword\*(C'\fR). The password is sent encrypted (one way hash) over the network. .ie n .IP """env.v3authprotocol""" 4 .el .IP "\f(CWenv.v3authprotocol\fR" 4 .IX Item "env.v3authprotocol" Authentication protocol. One of 'md5' or 'sha' (\s-1HMAC\-MD5\-96, RFC1321\s0 and \s-1SHA\-1/HMAC\-SHA\-96, NIST FIPS PIB 180, RFC2264\s0). The default is \&'md5'. .ie n .IP """env.v3privpassword""" 4 .el .IP "\f(CWenv.v3privpassword\fR" 4 .IX Item "env.v3privpassword" Privacy password to enable encryption. An empty ('') password is considered as no password and will not enable encryption. .Sp Privacy requires a v3privprotocol as well as a v3authprotocol and a v3authpassword, but all of these are defaulted (to 'des', 'md5', and the v3privpassword value, respectively) and may therefore be left unspecified. .ie n .IP """env.v3privprotocol""" 4 .el .IP "\f(CWenv.v3privprotocol\fR" 4 .IX Item "env.v3privprotocol" If the v3privpassword is set this setting controls what kind of encryption is used to achieve privacy in the session. Only the very weak \&'des' encryption method is supported officially. The default is 'des'. .Sp The implementing perl module (Net::SNMP) also supports '3des' (\s-1CBC\-3DES\-EDE\s0 aka Triple-DES, \s-1NIST FIPS 46\-3\s0) as specified in \s-1IETF\s0 draft\-reeder\-snmpv3\-usm\-3desede. Whether or not this works with any particular device, we do not know. .RE .RS 4 .RE .SS "\fBget_hash()\fP \- retrieve a table as a hash of hashes" .IX Subsection "get_hash() - retrieve a table as a hash of hashes" .Vb 8 \& $result = $session\->get_hash( \& [\-callback => sub {},] # non\-blocking \& [\-delay => $seconds,] # non\-blocking \& [\-contextengineid => $engine_id,] # v3 \& [\-contextname => $name,] # v3 \& \-baseoid => $oid, \& \-cols => \e%columns \& ); .Ve .PP This method transforms the \-baseoid and \-cols to a array of \-columns and calls \f(CW\*(C`get_entries()\*(C'\fR with all the other arguments. It then transforms the data into a hash of hashes in the following manner: .PP The keys of the main hash are the last element(s) of the OIDs, after \&\f(CW$oid\fR and the matching keys from \f(CW%columns\fR are removed. The values are hashes with keys corresponding to the values of \f(CW%columns\fR hash and values from the subtables corresponding to the keys of \f(CW%columns\fR. .PP For this to work, all the keys of \f(CW\*(C`\-cols\*(C'\fR must have the same number of elements. Also, don't try to specify a next-to-next-to-leaf-node baseoid, the principle it breaks both \f(CW\*(C`get_entries\*(C'\fR and the logic in \&\f(CW\*(C`get_hash\*(C'\fR. .PP If (all) the OIDs are unavailable a defined but empty hashref is returned. .PP Example: .PP .Vb 8 \& $session\->get_hash( \& \-baseoid => \*(Aq1.3.6.1.2.1.2.2.1\*(Aq, # IF\-MIB \& \-cols => { \& 1 => \*(Aqindex\*(Aq, \& 2 => \*(Aqdescr\*(Aq, \& 4 => \*(Aqmtu\*(Aq, \& } \& ); .Ve .PP given the following \s-1SNMP\s0 table: .PP .Vb 9 \& IF\-MIB::ifIndex.1 = INTEGER: 1 \& IF\-MIB::ifIndex.2 = INTEGER: 2 \& IF\-MIB::ifDescr.1 = STRING: lo0 \& IF\-MIB::ifDescr.2 = STRING: lna0 \& IF\-MIB::ifType.1 = INTEGER: softwareLoopback(24) \& IF\-MIB::ifType.2 = INTEGER: ethernetCsmacd(6) \& IF\-MIB::ifMtu.1 = INTEGER: 32768 \& IF\-MIB::ifMtu.2 = INTEGER: 1500 \& ... .Ve .PP will return a hash like this: .PP .Vb 10 \& \*(Aq1\*(Aq => { \& \*(Aqindex\*(Aq => \*(Aq1\*(Aq, \& \*(Aqmtu\*(Aq => \*(Aq32768\*(Aq, \& \*(Aqdescr\*(Aq => \*(Aqlo0\*(Aq \& }, \& \*(Aq2\*(Aq => { \& \*(Aqindex\*(Aq => \*(Aq2\*(Aq, \& \*(Aqdescr\*(Aq => \*(Aqlna0\*(Aq, \& \*(Aqmtu\*(Aq => \*(Aq1500\*(Aq \& } .Ve .SS "\fBget_single()\fP \- Retrieve a single value by \s-1OID\s0" .IX Subsection "get_single() - Retrieve a single value by OID" .Vb 1 \& $uptime = $session\->get_single("1.3.6.1.2.1.1.3.0") || \*(AqU\*(Aq; .Ve .PP If the call fails to get a value the above call sets \f(CW$uptime\fR to 'U' which Munin interprets as \*(L"Undefined\*(R" and handles accordingly. .PP If you stop to think about it you should probably use \f(CW\*(C`get_hash()\*(C'\fR (it gets too much, but is good for arrays) or \f(CW\*(C`get_entries()\*(C'\fR \- it gets exactly what you want, so you mus .SS "\fBget_by_regex()\fP \- Retrieve table of values filtered by regex applied to the value" .IX Subsection "get_by_regex() - Retrieve table of values filtered by regex applied to the value" This example shows the usage for a netstat plugin. .PP .Vb 2 \& my $tcpConnState = "1.3.6.1.2.1.6.13.1.1."; \& my $connections = $session\->get_by_regex($tcpConnState, "[1\-9]"); .Ve .PP It gets all OIDs based at \f(CW$tcpConnState\fR and only returns the ones that contain a number in the value. .SH "TODO" .IX Header "TODO" Lots. .SH "BUGS" .IX Header "BUGS" Ilmari wrote: \f(CW\*(C`get_hash()\*(C'\fR doesn't handle tables with sparse indices. .PP Nicolai Langfeldt: Actually I think it does. .SH "SEE ALSO" .IX Header "SEE ALSO" Net::SNMP .SH "AUTHOR" .IX Header "AUTHOR" Dagfinn Ilmari Mannsa\*oker, Nicolai Langfeldt Rune Nordbo\*/e Skillingstad added timeout support. .SH "COPYRIGHT/License." .IX Header "COPYRIGHT/License." Copyright (c) 2004\-2009 Dagfinn Ilmari Mannsa\*oker and Nicolai Langfeldt. .PP All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; version 2 dated June, 1991.