📜 ⬆️ ⬇️

Experienced trivia-6, or “Accounting and control of the printer Ivan Fedorov”

image The continuation of "experienced trifles." Previous parts: one , two , three , four , five .

In this post I will talk about a small, but in my own interesting experience using the SNMP protocol to collect print statistics in an organization.

In the company in question, they print quite a lot. There are large, powerful printers (such as the HP 9000) and medium-sized ones, and very much Home class. Fortunately, they are all networked, and the range of manufacturers is narrow, only two: HP and Ricoh (in different guises, from NRG to MB). And then one fine spring day, looking at the accounts for the office, the careful management was given the task: to regularly collect print statistics, “so that they could be analyzed later” . And they didn’t bother much: “All printers are networked, they have a statistics page, in the morning they got around by a list, recorded digits in Excel, that's all - business !

')
Naturally, in our opinion, it was uninteresting, stupid and "tiring", because There are a lot of printers in the organization. And we began to think "how to make it work itself." In general, it seems to me that this desire (“so that it works itself”) is key and necessary for each system administrator, and those who succeed over and over again always make me feel good, white envy.

With the move rejecting the web page parsers (this is wrong, and, for example, Ricoh pages were dynamic, there was no hard URL where to go), we turned to the good old SNMP. And that's what came out of it.

Here you should probably make a small digression for those for whom the abbreviation SNMP does not mean anything yet. Gentlemen, you are missing a lot! I urgently recommend that you spend the evening different and study the question at least at a basic level. In short, SNMP is a management and monitoring protocol based on UDP. The overwhelming majority of devices (if not all) that have a network interface support this protocol and allow using it not only to collect data on the operation of the device, but also to control the device itself. Data (objects) that are available via the SNMP protocol, the so-called OIDs are organized hierarchically. On the domestic plan, this means that if you ask the device for the OID value with a “number” .1.3.6.1.4.1.11, the device will respond and transmit this value. And knowing which OID corresponds to the value we need, you can write a small script that will poll the devices and collect their answers into the database. You can interrogate devices, for example, with the help of these wonderful and free utilities . Looking ahead, I’ll say that Snmpget and SnmpWalk were useful in our particular case.

The algorithm as a whole was clear, the utilities were at hand, the only thing left was to understand which OIDs mean what we need: a counter of printed pages. Full description of device variables, so-called. MIB-base is quite difficult to find (you can try to search here ), but you can go the other way.

With the help of the SnmpWalk utility, once having interrogated the device, you get ALL the OID from it with their values, which it is able to issue. For our part, we clearly know what exactly the VALUES we need (after all, we can find out their current status on the web page). Next is the case for small:

image
A few notes



As a bonus, I will cite the text of the script , the Excel macro, and give a few explanations:



To be continued

Source: https://habr.com/ru/post/122260/


All Articles