GNU Linux commands essential to carry out a hardware inventory
In the beginning we, as Humanity, created computers. We said “let it be electricity” and it was the light on our ballistic trajectory calculations. We saw the numbers matched and they were good. And we called the set of calculation instructions as “programs”, which were loaded straight into computer memories. And so was the first computing decade. GNU Linux commands didn’t exist yet, because there were no operating systems either.
All in all, the first computers were boring, similar to microwave ovens, very useful, but in the end, they just heat. Soon, scientists and/or mathematicians (yes, programmers as a profession would take longer to come) realized that the instructions, so carefully stamped as ones and zeroes on cardboard cards, only were useful for the machines they were created for and it was very difficult to use them in other computer models.
Punched card with a Fortran language instruction (Arnold Reinhold, Wikipedia)
For that reason, programming languages such as Fortran and Cobol were born, to train staff according to a standard. I have here summed up more than 170 years of history, since Ada Lovelace proposed to Charles Babbage for her Analytical Engine to run more than just programs. And here we are in the 21st century with operating systems interconnected to networks all over the world.
Later on, Operating Systems solved the problem of hardware compatibility and we developed a standard – with standards such as POSIX – for interacting with devices and the exchange of information among them.
This currently allows monitoring systems like Pandora FMS to find it very useful to use GNU Linux commands to return metrics from a Pandora FMS Server.
What I express here is not Pandora FMS official position or the opinion of their development team. Here you can check their official roadmap.
As we clearly saw in the previous video, Pandora FMS uses GNU Linux commands very well and in a very practical, simple and centralized way. Also, in Pandora FMS Software Agents (small programs that execute GNU Linux commands or other executables that return metric values and are later sent to Pandora FMS Server) these commands work almost the same way.
Do you remember that I told you that, at first, developing applications that could migrate to other laboratories with different hardware was a problem? Operating systems took care of that by collecting drivers, that is, specific binary instructions that allow hardware to communicate with the OS. This allows applications, by means of a programming language for that OS, to completely forget about bare-metal.
Pandora FMS Enterprise version has a huge amount of MIBs for SNMP protocol (if you like technical details, I chose this example that shows how to monitor data backup devices on magnetic tapes), and no wonder, Pandora FMS is in charge of monitoring operating systems, full networks and whatever we like in local network and wide network management.
Yes, ladies and gentlemen, this is a huge deal. But when a job or task is very large or complex, such as keeping a detailed hardware inventory, it is advisable to break it down and go for the core issue. Let’s have a look!
GNU Linux Commands
Many of them are tools created for Unix® OS, used by -at the time- very young Doctor Richard Matheus Stallman RMS at Massachusetts Institute of Technology and which were modified to be open and free and always thinking of other hardware environments.
It is a source of teasing that the Hurd kernel (its environment is called GNU Hurd) is monolithic and complicated, and many bet it will never become a solid OS for mass use, as GNU Linux is now. That is why Dr. Linus Torvalds was brilliant: he knew how to recognize the new hardware of that time (Intel® 386 processor) and create a modern and functional OS core.
That’s how, for example, Pandora FMS team decided to develop and spread all their tools to and have them run directly on the Linux kernel, with a free software license, and thus the hypothetical distributions Pandora FMS Linux were born. This is why we always write GNU Linux together to be specific; hence this article is called “GNU Linux commands” (although some of them are actually GNU licensed and not directly developed or hosted by the Free Software Foundation).
I here explain in a theoretical way the GNU Linux commands that I consider essential when inventorying hardware for subsequent monitoring with Pandora FMS.
I feel nostalgia for this program since the 1980s, when I used it as a Microsoft MS-DOS® utility to create and modify fixed disk partitions. I chose it first in the list because it illustrates and warns:
- fdisk is a program, and it also works as a library , that is, you may integrate it into your own source code and compile (remember to place the corresponding license notices). In its latest version 2.36, released in July 2020, it still supported DOS®. Keep in mind it has been forked and migrated to many platforms and is very different from its origins; just as we now as adults are different from when we were children, yet we are the same
- fdisk must be run with administrator permissions. Its aim is not to inventory any hardware, but it has a parameter called “–list” that either shows information about all the storage devices in your GNU Linux or one in particular.
- Taking into account the previous point, like everything in free software, we are the only ones responsible for the use -and abuse- of the software, which has guarantees. Having root user permissions (root user) is our exclusive competence, based on the fact that we know the source code of each of the GNU Linux programs and commands. You have been warned!
- fdisk can also take values from the file named “/proc/partitions/”. Linux makes files and directories available that directly and in real time provide information about your hardware, which you may open in a command terminal. You can open and list the special location “/proc” and you will see a lot of information that you could take “raw”, which leads us to the next point.
- fdisk has no more options to report storage hardware. However, you can use the usual GNU Linux commands (cat, ls, grep, awk,etc.) concatenating their outputs by means of the vertical bar to obtain and debug your metrics and then make them be processed locally or remotely by Pandora FMS Server.
GNU Linux awk and grep commands
- fdisk will be useful for cases where you need or want to know the disk’s geometry (if it is a magnetic plate).
sudo fdisk –list
I choose secondly the GNU Linux command called free: it was the first command I met in action within a Pandora FMS complement. Before going into the hardware inventory itself, it is an excellent example of how to develop your GNU Linux commands; free gets its information from “/proc/meminfo”. In addition, said complement uses the nomenclature -and good development standards- used by Pandora FMS to assimilate the collected metrics. Have fun for a while and learn, but please come back!
I present inxi, although the version I actually evaluated is not a command as such but ten thousand lines of code with BASH scripts. Sounds awesome right? inxi uses two must-have directories for its execution: “/proc” and “/sys” (you can use the “–recommends” parameter to fully know if you have all the necessary tools to get the most out of inxi).
GNU Linux inxi command (installation and use of -Fxz parameter)
- In the previous image you can see the installation (version 2.3.56) in my virtual machine, running Ubuntu server 18.
- I immediately executed the parameter “-Fxz”: letter f to know all the details, letter x to obtain more details (up to 3 x’s) and the most important and interesting, letter z that filters unique information (for example, the MAC of the network card shows the label “<filter>“).
- As network administrators and within our monitoring tasks we must be careful with the information we keep in Pandora FMS, if the network is not our property (we work as employees or freelancers). At least many proprietary programs identify a computer by its motherboard serial and/or network card serial and/or disk serial set and/or any other component. Changing any of them may result in an invalid use license with the consequent company stoppage (in case of an essential software). See on my old laptop that I took as a guinea pig:
inxi -i -z
- I chose this computer because it is the last one of a batch that we bought, so I myself have repaired it with spare parts from here and there: a whole Frankenstein machine. I also connect my Kindle, a USB to PS/2 converter, an old 3G USB modem and of course, it has several network cards, camera and microphone, etc. It is representative for hardware inventory with GNU Linux commands!
Tnxi from version 3.X was completely rewritten in Perl 5.X language, which makes it a proper GNU Linux command.
Another funny use of filtering unique hardware information is related to integrating inxi into IRC clients, such as Konversation. This is to show other people hardware information in real time (to be honest I was unable to install this feature when I finished this article).
Konversation version 1.7.4
The df command was one of the first I learned in 2014 when I decided to use completely free software. It is part of the GNU Kernel Utilities from the Free Software Foundation. There is a tool written in Python language, appropriately called pydf, which colors the result of df to your liking.
hwinfo must be installed from the repositories of each GNU Linux distribution. Both this application and Pandora FMS Software Agents can be massively installed with Ansible, Puppet or Chef, among other applications for Server Configuration Management.
With hwinfo I present the concept of categories for hardware inventory. Like this you can check a mouse connected to the computer, keyboards, etc. For each category it returns one or more values. This is known as key value and it is very important to store it in non-SQL based databases.
Together with the name and unique identifier of each computer, you could use artificial intelligence and give it these data to generate a change alert (a disconnected mouse, for example). Look at this concept: I am not talking about standardizing and fixing in detail each mouse in the company for its monitoring, I am talking about automata that help you mass work.
It does not mean you cannot get traditional metrics either: if you look at the image again, hwinfo is able to tell you how fast each core of the central processor works, since this in laptops varies according to workload and contributes to reducing battery consumption.
sudo apt install hwinfo
Do you remember that operating systems allow us to abstract from the hardware model we are using? Here we give it a twist and we have the command GNU Linux dmidecode, which gets its values directly from the motherboard. There are two specifications: Desktop Management Interface (1994) and System Management BIOS (1999), very complex to explain here. However, dmidecode is also practical: if necessary you can get values from “/sys/devices/virtual/dmi/id”.
Like hwinfo, you can check by hardware category with the option “-t” (in GNU Linux the parameters can be invoked in a short way with a dash and a letter; in this case the long option would be “- type”) together with a value between zero and 255… but let’s leave machine language for artificial intelligence and let it test each of those values.
We humans can use the parameter “-s” or “–string” together the keyword, look:
I say that monitoring is also an art, apart from being a science: it is not only what we have but how far we can go. Let’s look at this case study.
sudo dmidecode -t memory | grep Capacity
This will return a key and a value:
Maximum Capacity: 8 GB
If the company decides to “repower” their computers, you will be able to determine which devices you can buy more RAM memory for by just subtracting the installed memory. Pandora FMS has the ability to do post-computation on collected metrics (the most highlighting example is converting bits to bytes).
Another powerful command that must be invoked as root user: we will only use its parameter “-i” in a simple way and “-I” in an extended way (in GNU Linux environments, upper and lowercase letters really matter).
hdparm specializes in writing or setting operational values on storage devices. It struck me that it can even be used to label a sector as damaged on a RAID storage and evaluate whether it works as expected. That is why many of its parameters have the warnings “DANGEROUS”. You are warned again!
We will only use it to retrieve information, never to write values; there are the parameters “–Istdout” (which export the hexadecimal identifiers of each disk) and after filtering we send it again for a specific query, this time with the parameter “–Istdin” (again, let’s leave this task for artificial intelligence).
Data quality and artificial intelligence
We have already scratched the surface on GNU Linux commands for detailed hardware inventory. As you can see, this task is titanic. Without going into long theories, I will say that data quality is related to how reliable the collected information is. I already mentioned collecting in a non-traditional way in a SQL database and artificial intelligence to detect changes in a computer, since the redundancy of similar and/or identical values speak of the quality of the data collected (for our case, since they are metrics).
The following commands have the option of exporting reports in different formats such as XML (used by Pandora FMS), JSON, HTML, etc. The command ls in GNU Linux is used to list files and directories. I have grouped the following commands because they start with that prefix, however it does not mean they are the same programmers, and/or that they have a common origin.
I like this command for its versatility, it even has a graphical interface you can install in a Debian environment with the following execution:
sudo apt install lshw lshw-gtk
Bear in mind that if you are remotely connected by command terminal you will not have access to the graphical interface.
GTK+ front-end for lshw
XML is a technology that dates back to 1998 and that was conceived in a really complex way, so much so that it is one of those that drives Dr. Linus Torvalds crazy (although it does not take much to get him angry). XML needs programs to write and read it, with the advantage that you can easily add new fields to its data structure without any application losing compatibility with reports. In artificial intelligence, you can place all metadata you want, but I have to say it is somewhat difficult for us to work with it directly editing it.
As we did with dmidecode, you can enter a parameter with the kind of hardware you want to inventory, together with the “-xml” parameter. You can also export in JSON format with “-json”.
sudo lshw -xml -class memory
It is part of the linux-util package, an extensive set of commands carefully selected by the team that develops the Linux kernel. It is almost in each and every one of the distributions, it retrieves information from the central processor and can export in JSON format. It gets its data from “/proc”.
Although now motherboards have almost everything integrated, in the world of servers, PCI technology is very present in network cards, etc. lspci in its latest May 2020 version (3.7.0) allows working in *nix, *BSD and even Microsoft Windows environments. Excellent for collecting metrics in key and value pairs. It is rewarded from the community in a database that is updated regardless of the code, so if you have any unrecognized hardware, please report it at http://mj.ucw.cz/sw/pciutils/.
SCSI, once known as the fastest disk technology, has been dwarfed by each of the new SATA versions. It is still included in hardware for backward compatibility and you can get some information that contributes to your data quality being close to perfection (if all the obtained programs’ values match).
lsusb, as the name suggests, allows you to list USB devices. Look at the format:
If you need to be more specific with each connected device, go through the previous list and enter its identifier (it gets its names from “/var/lib/usbutils/usb.ids”) and, if it has been disabled, lsusb will return a number other than zero.
sudo lsusb –verbose -s
It is part of the Linux USB Project, so it keeps a large number of devices of this very popular peripheral technology up to date.
lsblk gets its data from “/sys/dev/block”,it allows exporting in JSON format with “-J” and in key-value pairs in quotation marks with “-P”. It is also part of the util-linux package that I mentioned.
Although this list is long, the most important GNU Linux commands are missing: those you will develop at ease and to your liking to monitor with Pandora FMS. Remember to post and share!
Before finishing, remember Pandora FMS is a flexible monitoring software, capable of monitoring devices, infrastructures, applications, services and business processes.
Would you like to find out more about what Pandora FMS can offer you? Find out clicking here .
If you have to monitor more than 100 devices, you can also enjoy a FREE 30-day Pandora FMS Enterprise TRIAL . Get it here .
Do not hesitate to send us your questions. Pandora FMS team will be happy to help you!
Programador desde 1993 en KS7000.net.ve (desde 2014 soluciones en software libre para farmacias comerciales en Venezuela). Escribe regularmente para Pandora FMS y ofrece consejos en el foro. También colaborador entusiasta en Wikipedia y Wikidata.
Machacador de hierros en gimnasios y cuando puede se ejercita en ciclismo también. Fanático de la ciencia ficción.
Programmer since 1993 in KS7000.net.ve (since 2014 free software solutions for commercial pharmacies in Venezuela). He writes regularly for Pandora FMS and offers advice in the forum. Also an enthusiastic contributor to Wikipedia and Wikidata.
Crusher of irons in gyms and when he can he exercises in cycling as well. Science fiction fan.