Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 14/08/2008, à 12:28

Fiyorden

[Résolu]Dev Plugin :: Perl :: Munin-plugin :: SNMP

Bonjours voilà j'ai commencé à dévelloper un plugins pour munin pour monitorer une imprimante réseau via le snmp
j'ai reussi à créer les graphes mais il ne s'affiche pas de valeur

voici le code source:

#!/usr/bin/perl -w
# -*- perl -*-
# snmp__oki_3300_healt munin grabber script
# 2008.08 by fiyorden@gmail.com inspired by steve@kosada.com (oki_c5500_health_)
#%# family=snmpauto
#%# capabilities=snmpconf

=head2 PLUGIN CONFIGURATION

Ce plugin sert à voir la consomation d encre definie par lien ex:
ln -s /usr/share/munin/plugins/snmp__oki_3300_healt /etc/munin/plugins/snmp_router.host.domain_oki_3300_healt

Valid SNMP configuration variables are:

env.host              Overrides hostname specified in linkage
env.port              Overrides port number specified in linkage
env.community         Specify the SNMP v1 or SNMP v2c community string.
=cut


use strict;
use Net::SNMP;

my $DEBUG = 0;

my $host      = $ENV{host}      || undef;
my $port      = $ENV{port}      || 161;
my $community = $ENV{community} || "public";

my $useMibEntryDescr = $ENV{useMibEntryDescr} || undef;

my $response;

my $GRAPH_CATEGORY = "printer";
my $GRAPH_PERIOD = "minute";
my $GRAPH_VLABEL = "percent $GRAPH_PERIOD";
my $BYTES_LABEL = "percent";

if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{
        print "require 1.3.6.1.2.1.1.5.0\n";
        print "require 1.3.6.1.2.1.43.11.1.1.9.1. [2-10]\n";
        exit 0;
}

if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_oki3300_healt$/)
{
        $host  = $1;
        if ($host =~ /^([^:]+):(\d+)$/)
        {
                $host = $1;
                $port = $2;
        }
}
elsif (!defined($host))
{
        print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
        die "# Error: couldn't understand what I'm supposed to monitor.";
}

my $sysName     = "1.3.6.1.2.1.1.5.0";
my $tonerCyan = "1.3.6.1.2.1.43.11.1.1.9.1.2";
my $tonerMagenta  = "1.3.6.1.2.1.43.11.1.1.9.1.3";
my $tonerYellow  = "1.3.6.1.2.1.43.11.1.1.9.1.4";
my $tonerBlack  = "1.3.6.1.2.1.43.11.1.1.9.1.1";

my $drumCyan  = "1.3.6.1.2.1.43.11.1.1.9.1.6";
my $drumMagenta  = "1.3.6.1.2.1.43.11.1.1.9.1.7";
my $drumYellow  = "1.3.6.1.2.1.43.11.1.1.9.1.8";
my $drumBlack  = "1.3.6.1.2.1.43.11.1.1.9.1.5";

my $belt  = "1.3.6.1.2.1.43.11.1.1.9.1.9";
my $fuser  = "1.3.6.1.2.1.43.11.1.1.9.1.10";


my ($session, $error) = Net::SNMP->session(
        -hostname  => $host,
        -community => $community,
        -port      => $port
);

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

if ($ARGV[0] and $ARGV[0] eq "config")
{
        print "host_name $host\n";
        if (!defined ($response = $session->get_request($sysName)))
        {
                die "Croaking: " . $session->error();
        }
        my $name = $response->{$sysName};
        my $warn = undef;
		print "host_name $host
graph_category $GRAPH_CATEGORY
graph_args --lower-limit 0 --upper-limit 15000
graph_period $GRAPH_PERIOD
graph_title oki c3300 consomable:
graph_info This graph shows consomable on \"$name\"
graph_order tonerCyan tonerMagenta tonerYellow tonerBlack drumCyan drumMagenta  drumYellow drumBlack belt fuser
graph_vlabel $GRAPH_VLABEL
tonerCyan.label $BYTES_LABEL
tonerCyan.info Toner Cyan allow (1.3.6.1.2.1.43.11.1.1.9.1.2)
tonerCyan.type DERIVE
tonerCyan.graph yes
tonerCyan.warning 10:
tonerCyan.critical 1:
tonerCyan.color 00FFFF
tonerMagenta.label $BYTES_LABEL
tonerMagenta.info Toner Magenta allow (1.3.6.1.2.1.43.11.1.1.9.1.3)
tonerMagenta.type DERIVE
tonerMagenta.graph yes
tonerMagenta.warning 10:
tonerMagenta.critical 1:
tonerMagenta.color FF00FF
tonerYellow.label $BYTES_LABEL
tonerYellow.info Toner Yellow allow (1.3.6.1.2.1.43.11.1.1.9.1.4)
tonerYellow.type DERIVE
tonerYellow.graph yes
tonerYellow.warning 10:
tonerYellow.critical 1:
tonerYellow.color FFFF00
tonerBlack.label $BYTES_LABEL
tonerBlack.info Toner Black allow (1.3.6.1.2.1.43.11.1.1.9.1.1)
tonerBlack.type DERIVE
tonerBlack.graph yes
tonerBlack.warning 10:
tonerBlack.critical 1:
tonerBlack.color 000000
drumCyan.label $BYTES_LABEL
drumCyan.info Drum Cyan allow (1.3.6.1.2.1.43.11.1.1.9.1.6)
drumCyan.type DERIVE
drumCyan.graph yes
drumCyan.warning 10:
drumCyan.critical 1:
drumCyan.color 00FFFF
drumMagenta.label $BYTES_LABEL
drumMagenta.info Drum Magenta allow (1.3.6.1.2.1.43.11.1.1.9.1.7)
drumMagenta.type DERIVE
drumMagenta.graph yes
drumMagenta.warning 10:
drumMagenta.critical 1:
drumMagenta.color FF00FF
drumYellow.label $BYTES_LABEL
drumYellow.info Drum Yellow allow (1.3.6.1.2.1.43.11.1.1.9.1.8)
drumYellow.type DERIVE
drumYellow.graph yes
drumYellow.warning 10:
drumYellow.critical 1:
drumYellow.color FFFF00
drumBlack.label $BYTES_LABEL
drumBlack.info Drum Black allow (1.3.6.1.2.1.43.11.1.1.9.1.5)
drumBlack.type DERIVE
drumBlack.graph yes
drumBlack.warning 10:
drumBlack.critical 1:
drumBlack.color 000000
fuser.label $BYTES_LABEL
fuser.info Fuser allow (1.3.6.1.2.1.43.11.1.1.9.1.5)
fuser.type DERIVE
fuser.graph yes
fuser.warning 10:
fuser.critical 1:
fuser.color 020202
belt.label $BYTES_LABEL
belt.info Belt allow (1.3.6.1.2.1.43.11.1.1.9.1.9)
belt.type DERIVE
belt.graph yes
belt.warning 10:
belt.critical 1:
belt.color 010101";
        exit 0;
}

	print "tonerCyan.value ", &get_single ($session,$tonerCyan), "\n";
	print "tonerMagenta.value ", &get_single ($session,$tonerMagenta), "\n";
	print "tonerYellow.value ", &get_single ($session,$tonerYellow), "\n";
	print "tonerBlack.value ", &get_single ($session,$tonerBlack), "\n";
	
	print "drumCyan.value ", &get_single ($session,$drumCyan), "\n";
	print "drumMagenta.value ", &get_single ($session,$drumMagenta), "\n";
	print "drumYellow.value ", &get_single ($session,$drumYellow), "\n";
	print "drumBlack.value ", &get_single ($session,$drumBlack), "\n";
	
	print "belt.value ", &get_single ($session,$belt), "\n";
	print "fuser.value ", &get_single ($session,$fuser), "\n";
	
sub get_single
{
    my $handle = shift;
    my $oid    = shift;

    print "# Getting single $oid...\n" if $DEBUG;

    $response = $handle->get_request ($oid);

    if (!defined $response->{$oid})
    {
        return undef;
    }
    else
    {
        return $response->{$oid};
    }
}

Quand j'execute:

> root@sargeras[10.1.1.3]:/etc/munin/plugins# ./snmp_oki3300.dinopol.lan_oki3300_healt 
tonerCyan.value 50
tonerMagenta.value 60
tonerYellow.value 70
tonerBlack.value 40
drumCyan.value 6655
drumMagenta.value 6655
drumYellow.value 6655
drumBlack.value 2142
belt.value 12858
fuser.value 10100
> root@sargeras[10.1.1.3]:/etc/munin/plugins# ./snmp_oki3300.dinopol.lan_oki3300_healt config
host_name oki3300.dinopol.lan
host_name oki3300.dinopol.lan
graph_category printer
graph_args --lower-limit 0 --upper-limit 15000
graph_period minute
graph_title oki c3300 consomable:
graph_info This graph shows consomable on "OKI-C3300-DPL"
graph_order tonerCyan tonerMagenta tonerYellow tonerBlack drumCyan drumMagenta  drumYellow drumBlack belt fuser
graph_vlabel percent minute
tonerCyan.label percent
tonerCyan.info Toner Cyan allow (1.3.6.1.2.1.43.11.1.1.9.1.2)
tonerCyan.type DERIVE
tonerCyan.graph yes
tonerCyan.warning 10:
tonerCyan.critical 1:
tonerCyan.color 00FFFF
tonerMagenta.label percent
tonerMagenta.info Toner Magenta allow (1.3.6.1.2.1.43.11.1.1.9.1.3)
tonerMagenta.type DERIVE
tonerMagenta.graph yes
tonerMagenta.warning 10:
tonerMagenta.critical 1:
tonerMagenta.color FF00FF
tonerYellow.label percent
tonerYellow.info Toner Yellow allow (1.3.6.1.2.1.43.11.1.1.9.1.4)
tonerYellow.type DERIVE
tonerYellow.graph yes
tonerYellow.warning 10:
tonerYellow.critical 1:
tonerYellow.color FFFF00
tonerBlack.label percent
tonerBlack.info Toner Black allow (1.3.6.1.2.1.43.11.1.1.9.1.1)
tonerBlack.type DERIVE
tonerBlack.graph yes
tonerBlack.warning 10:
tonerBlack.critical 1:
tonerBlack.color 000000
drumCyan.label percent
drumCyan.info Drum Cyan allow (1.3.6.1.2.1.43.11.1.1.9.1.6)
drumCyan.type DERIVE
drumCyan.graph yes
drumCyan.warning 10:
drumCyan.critical 1:
drumCyan.color 00FFFF
drumMagenta.label percent
drumMagenta.info Drum Magenta allow (1.3.6.1.2.1.43.11.1.1.9.1.7)
drumMagenta.type DERIVE
drumMagenta.graph yes
drumMagenta.warning 10:
drumMagenta.critical 1:
drumMagenta.color FF00FF
drumYellow.label percent
drumYellow.info Drum Yellow allow (1.3.6.1.2.1.43.11.1.1.9.1.8)
drumYellow.type DERIVE
drumYellow.graph yes
drumYellow.warning 10:
drumYellow.critical 1:
drumYellow.color FFFF00
drumBlack.label percent
drumBlack.info Drum Black allow (1.3.6.1.2.1.43.11.1.1.9.1.5)
drumBlack.type DERIVE
drumBlack.graph yes
drumBlack.warning 10:
drumBlack.critical 1:
drumBlack.color 000000
fuser.label percent
fuser.info Fuser allow (1.3.6.1.2.1.43.11.1.1.9.1.5)
fuser.type DERIVE
fuser.graph yes
fuser.warning 10:
fuser.critical 1:
fuser.color 020202
belt.label percent
belt.info Belt allow (1.3.6.1.2.1.43.11.1.1.9.1.9)
belt.type DERIVE
belt.graph yes
belt.warning 10:
belt.critical 1:
belt.color 010101

Voilà j'aurai besoin de conseil et de debugger cet affichage hmm

Dernière modification par Fiyorden (Le 19/08/2008, à 09:18)


J'ai fais le pas ... Pourquoi pas vous???
Passer a Ubuntu

Hors ligne

#2 Le 17/08/2008, à 07:13

Fiyorden

Re : [Résolu]Dev Plugin :: Perl :: Munin-plugin :: SNMP

Personne ne peux m'aider?


J'ai fais le pas ... Pourquoi pas vous???
Passer a Ubuntu

Hors ligne