source: ocsinventory-agent/trunk/fuentes/lib/Ocsinventory/Agent/Modules/Snmp/Printer_Mib.pm @ 468

Last change on this file since 468 was 468, checked in by mabarracus, 4 years ago

Copyt trusty code

File size: 5.6 KB
Line 
1###
2# SNMP: OID: 43 SYSTEM: Printer_Mib
3###
4package Ocsinventory::Agent::Modules::Snmp::Printer_Mib;
5
6use strict;
7
8sub snmp_info {
9   #TODO: find a common OID from Printer_Mib (compatible with most printers) instead of using hrPrinterStatus from Host_Ressources_Mib
10   return ( { oid_value => "1.3.6.1.2.1.25.3.5.1.1.1",
11            oid_name => "Printer_Mib" } );
12}
13
14sub snmp_run {
15  my ($session , $snmp )= @_;
16  my $logger=$snmp->{logger};
17  my $common=$snmp->{common};
18
19  my ($result,$name,$serialnumber,$lifecount,$countunit,$printerstatus,$errorstate);
20
21  $logger->debug("Running Printer MIB module");
22
23  $common->setSnmpCommons( {TYPE => "Printer"} );
24
25  #prtGeneralPrinterName
26  my $snmp_name="1.3.6.1.2.1.43.5.1.1.16.1";
27  #prtInputSerialNumber
28  my $snmp_serialnumber="1.3.6.1.2.1.43.5.1.1.17.1";
29  #prtMarkerLifeCount
30  my $snmp_lifecount="1.3.6.1.2.1.43.10.2.1.4.1.1";
31  #prtMarkerCounterUnit
32  my $snmp_countunit="1.3.6.1.2.1.43.10.2.1.3.1.1";
33  #prtInputTable       
34  my $snmp_inputable="1.3.6.1.2.1.43.8.2";
35  #prtMarkerSuppliesTable
36  my $snmp_markersuppliestable="1.3.6.1.2.1.43.11.1";
37  #prtMarkerColorantValue
38  my $snmp_colorantvalue="1.3.6.1.2.1.43.12.1.1.4";
39  #hrPrinterStatus
40  my $snmp_printerstatus="1.3.6.1.2.1.25.3.5.1.1.1";
41  #PrinterDetectedErrorState
42  my $snmp_errorstate="1.3.6.1.2.1.25.3.5.1.2.1";
43
44  #Trays informations we want to get
45  my $trayinfos = {
46    name => "1.3.6.1.2.1.43.8.2.1.13",    #prtInputName
47    description => "1.3.6.1.2.1.43.8.2.1.18",   #prtInputDescription
48    level => "1.3.6.1.2.1.43.8.2.1.10",    #prtInputLevel
49    maxcapacity => "1.3.6.1.2.1.43.8.2.1.9",   #prtInputMaxCapacity
50  };
51
52  #Cartridges informations we want to get
53  my $cartridgeinfos = {
54    description => "1.3.6.1.2.1.43.11.1.1.6",   #prtMarkerSuppliesDescription
55    type => "1.3.6.1.2.1.43.11.1.1.5",     #prtMarkerSuppliesType
56    level => "1.3.6.1.2.1.43.11.1.1.9",    #prtMarkerSuppliesSupplyLevel
57    maxcapacity => "1.3.6.1.2.1.43.11.1.1.8",   #prtMarkerSuppliesMaxCapacity
58  };
59
60  #Translation for the prtMarkerCounterUnit integer
61  my $countunit_translation = { 
62    3 => 'tenThousandthsOfInches',
63    4 => 'micrometers',
64    5 => 'characters',
65    6 => 'lines',
66    7 => 'impressions',
67    8 => 'sheets',
68    9 => 'dotRow',
69    11 => 'hours',
70    16 => 'feet',
71    17 => 'meters',
72  };
73
74  #Translation for the prtMarkerSuppliesType integer
75  my $suppliestype_translation = {
76    1 => 'other',
77    2 => 'unknown',
78    3 => 'toner',
79    4 => 'wasteToner',
80    5 => 'ink',
81    6 => 'inkCartridge',
82    7 => 'inkRibbon',
83    8 => 'wasteInk',
84    9 => 'opc',
85    10 => 'developer',
86    11 => 'fuserOil',
87    12 => 'solidWax',
88    13 => 'ribbonWax',
89    14 => 'wasteWax',
90  };
91
92  my $printerstatus_translation = {
93    1 => 'other',
94    2 => 'unknown',
95    3 => 'idle',
96    4 => 'printing',
97    5 => 'warmup',
98  };
99
100  my $errorstate_translation = {
101    '0x00' => 'lowPaper',
102    '0x01' => 'noPaper',
103    '0x02' => 'lowToner',
104    '0x03' => 'noToner',
105    '0x04' => 'doorOpen',
106    '0x05' => 'jammed',
107    '0x06' => 'offline',
108    '0x07' => 'serviceRequested',
109    '0x08' => 'inputTrayMissing',
110    '0x09' => 'outputTrayMissing',
111    '0x10' => 'markerSupplyMissing',
112    '0x11' => 'outputNearFull',
113    '0x12' => 'outputFull',
114    '0x13' => 'inputTrayEmpty',
115    '0x14' => 'overduePreventMaint',
116  };
117
118  #####
119
120  #Getting printer informations
121  $result=$session->get_request( -varbindlist => [$snmp_name]);
122  $name=$result->{$snmp_name};
123
124  $result=$session->get_request(-varbindlist => [$snmp_serialnumber]);
125  $serialnumber=$result->{$snmp_serialnumber};
126
127  $result=$session->get_request(-varbindlist => [$snmp_lifecount]);
128  $lifecount=$result->{$snmp_lifecount};
129
130  $result=$session->get_request(-varbindlist => [$snmp_countunit]);
131  $countunit=$countunit_translation->{ $result->{$snmp_countunit} };
132
133  $result=$session->get_request(-varbindlist => [$snmp_printerstatus]);
134  $printerstatus=$result->{$snmp_printerstatus};
135
136  $result=$session->get_request(-varbindlist => [$snmp_errorstate]);
137  $errorstate=$result->{$snmp_errorstate};
138
139  #Adding informations to XML
140  $common->setSnmpPrinter({
141    NAME => $name,
142    SERIALNUMBER => $serialnumber,
143    COUNTER => "$lifecount $countunit",
144    STATUS => $printerstatus_translation->{$printerstatus},
145    ERRORSTATE => $errorstate_translation->{$errorstate},
146  }); 
147
148  #Getting trays informations using the table
149  my $inputable=$session->get_table(-baseoid => $snmp_inputable) ;
150  my $trays = $common->getSnmpTable($inputable,$snmp_inputable,$trayinfos);
151
152  for my $tray ( keys %$trays ) {
153  #Adding informations about trays in XML
154    $common->addSnmpPrinterTray({
155      NAME => $trays->{$tray}->{name},
156      DESCRIPTION => $trays->{$tray}->{description},
157      LEVEL => $trays->{$tray}->{level},
158      MAXCAPACITY => $trays->{$tray}->{maxcapacity},
159    }); 
160  }
161
162
163  #Getting cartridges informations using the table
164  my $markersuppliestable=$session->get_table(-baseoid => $snmp_markersuppliestable) ; 
165  my $cartridges = $common->getSnmpTable($markersuppliestable,$snmp_markersuppliestable,$cartridgeinfos);
166
167  for my $cartridge ( keys %$cartridges ) {
168    #Getting colorant value
169    $result = $session->get_request(-varbindlist => [$snmp_colorantvalue.$cartridge]);
170    my $colorantvalue = $result->{$snmp_colorantvalue.$cartridge};
171
172    #Adding informations about cartridges in XML
173    $common->addSnmpPrinterCartridge({
174      DESCRIPTION => $cartridges->{$cartridge}->{description},
175      TYPE => $suppliestype_translation->{ $cartridges->{$cartridge}->{type} },
176      LEVEL => $cartridges->{$cartridge}->{level},
177      MAXCAPACITY => $cartridges->{$cartridge}->{maxcapacity},
178      COLOR => $colorantvalue,
179    });
180  }
181
182}
1831;
Note: See TracBrowser for help on using the repository browser.