|
NAMEMunin::Plugin::SNMP - Net::SNMP subclass for Munin pluginsSYNOPSISThe Munin::Plugin::SNMP module extends Net::SNMP with methods useful for Munin plugins.SNMP CONFIGURATIONSNMP plugins (that use this module) share a common configuration interface implemented in the function session(). Please see the documentation for that function for complete instructions and examples on how to configure SNMP. The documentation is located there to ensure that it is up to date and matches the code.DEBUGGINGAdditional debugging messages can be enabled by setting $Munin::Plugin::SNMP::DEBUG, $Munin::Plugin::DEBUG, or by exporting the "MUNIN_DEBUG" environment variable before running the plugin (by passing the "--pidebug" option to "munin-run", for instance).METHODSconfig_session() - Decode environment to get the needed plugin configuration parameters($host, $port, $version, $tail) = Munin::Plugin::SNMP->config_session(); This is a convenience function for the "config" 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:
The tail can be interesting for the "fetch" part of the plugin as well. session([optional Net::SNMP options]) - create new Munin::Plugin::SNMP object$session = Munin::Plugin::SNMP->session(); 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. The host name is taken from the plugin symlink, which must be on the form "snmp[v3]_<hostname>_<plugin_name>[_args]". The "v3" form is taken to mean that SNMPv3 is to be used. It is also a name trick providing a separate "namespace" for devices that use SNMPv3 so it can be configured separately in munin/plugin-conf.d/ files. E.g.: [snmp_*] env.version 2 env.community public [snmpv3_*] env.v3username snmpoperator env.v3authpassword s3cr1tpa55w0rd See below for how to configure for each different case. The first case above shows Munin's default configuration. NOTE: munin-node-configure does not yet utilize the "v3" thing. The following environment variables are consulted:
get_hash() - retrieve a table as a hash of hashes$result = $session->get_hash( [-callback => sub {},] # non-blocking [-delay => $seconds,] # non-blocking [-contextengineid => $engine_id,] # v3 [-contextname => $name,] # v3 -baseoid => $oid, -cols => \%columns ); This method transforms the -baseoid and -cols to a array of -columns and calls "get_entries()" with all the other arguments. It then transforms the data into a hash of hashes in the following manner: The keys of the main hash are the last element(s) of the OIDs, after $oid and the matching keys from %columns are removed. The values are hashes with keys corresponding to the values of %columns hash and values from the subtables corresponding to the keys of %columns. For this to work, all the keys of "-cols" 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 "get_entries" and the logic in "get_hash". If (all) the OIDs are unavailable a defined but empty hashref is returned. Example: $session->get_hash( -baseoid => '1.3.6.1.2.1.2.2.1', # IF-MIB -cols => { 1 => 'index', 2 => 'descr', 4 => 'mtu', } ); given the following SNMP table: 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 ... will return a hash like this: '1' => { 'index' => '1', 'mtu' => '32768', 'descr' => 'lo0' }, '2' => { 'index' => '2', 'descr' => 'lna0', 'mtu' => '1500' } get_single() - Retrieve a single value by OID$uptime = $session->get_single("1.3.6.1.2.1.1.3.0") || 'U'; If the call fails to get a value the above call sets $uptime to 'U' which Munin interprets as "Undefined" and handles accordingly. If you stop to think about it you should probably use "get_hash()" (it gets too much, but is good for arrays) or "get_entries()" - it gets exactly what you want, so you mus get_by_regex() - Retrieve table of values filtered by regex applied to the valueThis example shows the usage for a netstat plugin.my $tcpConnState = "1.3.6.1.2.1.6.13.1.1."; my $connections = $session->get_by_regex($tcpConnState, "[1-9]"); It gets all OIDs based at $tcpConnState and only returns the ones that contain a number in the value. TODOLots.BUGSIlmari wrote: "get_hash()" doesn't handle tables with sparse indices.Nicolai Langfeldt: Actually I think it does. SEE ALSONet::SNMPAUTHORDagfinn Ilmari Mannsaaker, Nicolai Langfeldt Rune Nordboe Skillingstad added timeout support.COPYRIGHT/License.Copyright (c) 2004-2009 Dagfinn Ilmari Mannsaaker and Nicolai Langfeldt.All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 dated June, 1991.
Visit the GSP FreeBSD Man Page Interface. |