-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This module extends Nagios::Plugin with methods to help developers
writing SNMP plugins for Nagios. It includes easy to use get() and
walk() methods; it also overloads the getopts() method of Nagios::Plugin
to include parsing and setting of these options:
- —warning|-w: Warning threshold [optional]
- —critical|-c: Warning threshold [optional]
- —hostname|-H: SNMP device to query
- —port|-p: Port on remote device to connect to [default 161]
- —snmp-local-ip: Local IP to bind to for outgoing requests
- —snmp-version: SNMP version (1, 2c, 3)
- —snmp-timeout: SNMP response timeout for each SNMP get or walk performed, in seconds [default 15]
- —snmp-debug: Turn on Net::SNMP debugging
- —snmp-max-msg-size N: Set maximum SNMP message size in bytes
- —rocommunity: Read-only community string for SNMP 1/v2c
- —auth-username: Auth username for SNMP v3
- —auth-password: Auth password for SNMP v3
- —auth-protocol: Auth protocol for SNMP v3 (defaults to md5)
The module uses Net::SNMP for SNMP transport, so it works with SNMP version 1, 2c, and 3.
my $plugin = Nagios::Plugin::SNMP->new( 'process_deltas' => { 'cache' => { 'type' => 'memcache' }, 'default_interval' => 300, # seconds 'delta_compute_function' => \&my_delta_function } );
Will use any Cache::Cache compliant data cache to store counter
values and return deltas between counters to the end user. In order
to do this, Nagios::Plugin::SNMP must be passed in a cache class name.
Each cache type will cause Nagios::Plugin::SNMP to add required
arguments for the cache type in question. Additionally, enabling
counter delta code causes the script to require an interval for
time between checks. From the command line this can be specified
with —check-interval. The developer can pass in a default using
the ‘default_interval’ parameter.
- cache => { ‘type’ => ‘memcache’ }
Causes Nagios::Plugin::SNMP to use Cache::Memcached for
data persistence; also makes the following arguments to the plugin
available to the user. Defaults for both can be provided in the
memcache option hash as memcache_addr and memcache_port.
- —memcache-addr – IP address of Memcache instance
- —memcache-port – TCP port number memcache is listening on
my $plugin = Nagios::Plugin::SNMP->new( 'process_deltas' => { 'cache' => { 'type' => 'memcache', 'options => { 'memcache_port' => 11211, 'memcache_addr' => 127.0.0.1 }, 'default_interval' => 300, # seconds 'delta_compute_function' => \&my_delta_function } );
Currently ONLY Cache::Memcached is supported.
- ‘process_deltas’ => { ‘delta_compute_function’ => \&my_delta_function }
Callback to allow user to pass in a function that will compute a
smarter delta :). The default function purely does the following:
- If previous value does not exist, it stores the current value
and returns -0 - If previous value exists and is > 0, stores the current value and
returns the delta between the current value and previous value - If delta between the two values is < 0, returns -0 as counter
has wrapped.
sub my_delta_function { my ($self, $args) = @_; my $previous_value = $args->{'previous_value'}; my $current_value = $args->{'current_value'}; my $interval = $args->{'interval'}; my $previous_run_at = $args->{'previous_run_at'}; my ($value_to_store, $delta) = (); # Processing code return ($value_to_store, $delta); }
Will query the agent for values associated with the SCALAR OIDs passed
in and return a hash with the results of the query; the value for each
oid will be the delta, massaged as needed by the built in delta-computation
function or your own function.
Will perform delta computation on the passed in value; using
the key passed in in place of the OID that would be used in
get_deltas as the hash key. This routine can be used by the end
user for metrics that are created by the plugin developer as opposed to
counters retrieved by the SNMP agent.