#!/usr/bin/perl -w

=encoding utf8

=head1 NAME

snmp__print_supplies - SNMP plugin to monitor pages printed on
printers adhering to RFC1759.

=head1 APPLICABLE SYSTEMS

Any SNMP capable printer adhering to RFC1759.  Using a command such
as "munin-node-configure --snmp xerox.skillingstad.no --snmpversion 2c
--snmpcommunity public | sh -x" should auto-detect all applicable
interfaces.

=head1 CONFIGURATION

As a rule SNMP plugins need site specific configuration.  The default
configuration (shown here) will only work on insecure sites/devices:

   [snmp_*]
        env.version 2
        env.community public

In general SNMP is not very secure at all unless you use SNMP version
3 which supports authentication and privacy (encryption).  But in any
case the community string for your devices should not be "public".

Please see 'perldoc Munin::Plugin::SNMP' for further configuration
information.

=head1 MAGIC MARKERS

  #%# family=snmpauto
  #%# capabilities=snmpconf

=head1 BUGS

For printers having duplex module: pages != number of sheets

=head1 AUTHOR

Copyright (C) 2006-2009 Rune Nordbøe Skillingstad

=head1 LICENSE

GPLv2

=cut

use strict;
use Munin::Plugin;
use Munin::Plugin::SNMP;

my $oid = '1.3.6.1.2.1.43.10.2.1.4.1.1';
my $response;

if(defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
    print "require ${oid}.\n";
    exit 0;
}

my ($session, $error);

# SNMP needed for both config and fetch.
$session = Munin::Plugin::SNMP->session();

if(!defined ($session)) {
    die "Croaking: $error";
}

if(defined $ARGV[0] and $ARGV[0] eq "config") {
    my ($host,undef,$version) = Munin::Plugin::SNMP->config_session();

    print "host_name $host\n" unless $host eq 'localhost';
    print "graph_title Pages
graph_args --base 1000 -l 0
graph_vlabel Printed pages pr minute
graph_scale no
graph_category printing
graph_info This graph number of printed pages
graph_total Total
pages.label pages
pages.draw AREA
pages.type DERIVE
pages.cdef pages,60,*
pages.info pages printed pr minute
";

exit 0;
}

print "pages.value ", $session->get_single($oid), "\n";

