📜 ⬆️ ⬇️

Small usefulness for a GLPI + FusionInventory bundle

How many copies were broken about this bundle - do not count. The forum of both products is full of questions. But I did not find answers there, like questions like mine. Well, or at least a clear answer to them.

I had only two questions:
  1. How to make the counter change printed pages for network printers? FusionInventory internally stores the value obtained by SNMP during the inventory, but does not update the main field.
  2. How to run an inventory on diskless stations running Thinstation? As in any not too large company, licensing money is given with gritting teeth for the whole district, and even then once in five years. As a result, there is a variegated park of diskless stations assembled from what was at hand.

Naturally, I wanted to solve both issues without getting up from the chair. Let the technology is not so much, but geographically it is in several regions, so that you can not avoid all.

All further gestures were performed on the following configuration: KVM virtual machine, 1Gb RAM, 10 GB HDD, Debian 7, GLPI 0.85.4, FusionInventory Plugin 1.2
')
With the first question, everything was quite simple. All values ​​are stored in MySQL, so all that was left was to find all the dependencies and check if the direct entry to the database breaks any accounting inside GLPI.

As a result, this is how the script turned out (Caution: Bydlokod!):

#!/bin/bash msql_u='glpi' # MySQL msql_p='glpi' # MySQL msql_db='glpi' # MySQL mysql -u $msql_u -p$msql_p -D $msql_db -B -N -s -e 'select id,last_pages_counter from glpi_printers where (have_ethernet = 1);'| while read -r line do printer_glpi_counter=$(echo $line | awk '{print $2}') printer_ip=$(mysql -u $msql_u -p$msql_p -D $msql_db -B -N -s -e "SELECT name FROM glpi_ipaddresses WHERE mainitems_id = $(echo $line | awk '{print $1}') AND mainitemtype = 'Printer';") printer_cur_counter=$(snmpwalk -Ovq -c public -v 1 $printer_ip 1.3.6.1.2.1.43.10.2.1.4.1.1 2>/dev/null) if [ $printer_cur_counter -gt $printer_glpi_counter ] ; then mysql -u $msql_u -p$msql_p -D $msql_db -B -N -s -e "UPDATE glpi_printers SET last_pages_counter=$printer_cur_counter,date_mod=NOW() WHERE id=$(echo $line | awk '{print $1}')" fi done 

Two tables are used:

We get the current page count from the printer via SNMP, compare it with the current one in GLPI, and if it is more, write it to the database and change the date of the record change.

A week of tests showed that the records are kept correctly, nothing breaks and the script was set on working GLPI. The result is the power of this picture:

image

It is strange that the high-capacity cartridge printed 100 pages more. And I thought, it only seemed to me that they change at approximately the same interval. But these are questions for those who run them.

The second question put my laziness to a standstill. Either reassemble the thinstation, which pulls the next headaches with rdesktop, freerdp, sound and modules, or as much as possible to erase perl, for the fusioninventory-agent is written entirely and completely on it, and assemble your module.

Actually, I won the second option, because I didn’t want to burden the assembly once more, and the inventory is not a matter of everyday life, I started it once a week and normally.

For a couple of days of unhurriedly digging an agent, the necessary (well, actually regular) utilities for hardware inventory were found: lspci, lsusb, fdisk, arch, dmidecode, get-edid, ifconfig, parse-edid, and others. It was here that the first underwater stone was revealed: lspci, fdisk and many other utilities in Thinstation - only aliases to busybox and with the necessary keys, of course, do not work.

The second pitfall was the definition of architecture. For some reason, the agent received the value of linux-thread-multi and then everything stalled, since the processing of such an architecture is not provided. I had to put a crutch in Agent / Task / Inventory / Linux / i386.pm:

It was:

 return $Config{archname} =~ /^(i686|x86_64)/; 

It became:

 return $Config{archname} =~ /^(i686|x86_64|linux-thread-multi)/; 

The remaining stones were from the series “the required utility does not work correctly, it does not return values, therefore we will not take inventory”. To fix this, I had to push lspci, lsusb, fdisk, arch, dmidecode, get-edid, parse-edid into the build and change the paths to these utilities in agent scripts. Strange, but almost all the ways were written as absolute. Well, yes, this is a matter of developers.

The executable script that runs the agent turned out like this:
 #!/bin/sh export PERL5LIB=/FusionInventory/perl/lib/:/FusionInventory/agent/:/FusionInventory/perl/agent/:/FusionInventory/perl/site/lib:/FusionInventory/perl/vendor/lib/ cd /FusionInventory/perl/bin ./perl fusioninventory-agent -f 

The script is run crown, twice a day inventory. Inventory day is selected independently. I have - every Monday.
The first working assembly of the module was born large in size - 13 mb. But it worked. And she worked with a bang.
Thinstation Inventory Screens





As a result of “file completion”, the module size was reduced to 5.1 mb. Just throw out nothing more.

Link to the final version of the module

Before using the module, it is necessary to correct the path to your GLPI. The file is opened and unpacked as a regular tar.gz archive. Edit the ./FusionInventory/etc/agent.cfg file
I know that this is a flaw, but I have not found how to get my settings from thinstation.conf.network when it is loaded.

Thanks for attention!

For information on Thinstation, thanks to thinstation.pro , who explained to me how to build my modules for thin clients.

UPD:
Understood with the transfer of parameters. Now, to set the address of the inventory server, it is enough to add the line in the thinstation.conf.network file
 FUSION_SERVER="http://__/plugins/fusioninventory/" 

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


All Articles