Nagios-traffic light from Chinese cubes

As usual, for starters, a little "written excuse from responsibility."

  • The purpose of all the ridiculous gestures described in the article is one - to facilitate monitoring of servers and applications.
  • This bold trick can be repeated at home and at work, even untrained athletes.
  • I hope that this text is useful not only to Nagios adherents, but also to the luminous Jedi of Zabbix and the neophytes of other denominations of monitoring.
  • There will be no demonstration of aerobatics in the use of a soldering station, oscilloscope, and mastery of Ruby / Fortran / etc. Everything described is primitive, disgusting, but cheap and cheerful. And most importantly - it works.

Probably, many of those whom the spinner of samsara brought to the field of system administration and maintenance of servers in commodity quantities, thought about easing their difficult burden and more than once fantasized how to make it feel like in a song: “work robots, people are happy” . I will share my recipe for gaining samadhi.

The main ways to monitor the monitoring system are few. The most common ones are reading emails and spying on the web interface. This functionality is usually available in any monitoring system. We will not talk about sending SMS and other esoterics yet. But there is one thing. Emails and the web interface are not always convenient. And they do not always have time and energy. In a situation where there is no dedicated specialist (or even a whole department) of monitoring, you need an alarm tool:

  1. Not distracting from other tasks.
  2. Attracting attention in case of problems.
  3. Cheap and angry.

The initial conditions of the problem are as follows:

  1. Used by Nagios.
  2. All servers are located in the DC, far from the office of the escort department. Ordinary situation.
  3. Corporate policies prohibit the use of USB network devices (and drives, by the way). This means that it will not work to use ready-made WiFi and BT controllers of various LED garlands and other joys of a smart home and the Internet of things. Remains the good old serial port. Or USB-COM adapter. This great device is not prohibited by domain policies.

Thus the following configuration emerges. On the Nagios server, the script checks the status and sends a command over the network to turn on the light located in the support department.

The conditions of the problem are set, we proceed to the solution.

First, we’ll determine how to obtain monitoring status. In Nagios, this is done thanks to the livestatus component. Setup and installation are described here . After installation, you can get real-time monitoring status with a simple script. Such a request is quite informative:

GET services
Stats: state = 2
Stats: state = 1
Stats: state = 3
Separators: 10 32 44 124

At the output, we get three numbers on one line, separated by a space. This is the number of services in the CRITICAL, WARNING, and UNKNOWN state, respectively. We will leave aside the issue of processing monitoring statuses, we will return to this later. Obtaining statuses from your favorite monitoring system is up to you.

We pass to the most delicious part of our adventure, to the glands and wires.

Now you need to select the transmission channel and the method of indicating the monitoring status. After some deliberation and searching, the choice fell on a set of light bulbs with infrared control, infrared decoder and USB-COM adapter. This kit connects to the workstation where the Nagios client (nsclient ++) is deployed.

So, all the ingredients are listed, it remains to shake but not mix.

Let's start with the light bulb.

Remote control lamp

The light bulb (like all other components) was bought on Ali. Search by keywords for “IR RGB LED bulb”. Very powerful is not needed, 3-5 watts is enough. This is important, because the lamp is in direct line of sight all day, and too bright will interfere and dazzle.

And it’s also important that it is managed by the NEC protocol. Since the finished decoder supports only this protocol. At the same time, do not forget to buy any table or floor lamp cover, if you do not have one. It’s enough to simply screw the light bulb into the lampshade and plug it into a 220V network.

The next component is the infrared decoder module (complete with USB-COM adapter).

Decoder

In Chinese bins you can find the words “ir decoder”. For this beautiful module, there is even a schematic and documentation set available atlink .

Any Prolific / Silicon Labs / FTDI / CH340 / etc is suitable as a USB-COM adapter. Searched for ali by the spell “serial converter usb ttl”. Just in case, let me remind you that at least two of the brands listed (FTDI and Prolific) are seen in an unequal struggle with users of their products. This is reflected in the inoperability of fresh drivers with pirated adapters from China. You have to force rollback to previous versions of drivers. I will not dwell on this in more detail, there is a lot of information on the network.

Further narration implies that you have completed a tantric privacy session with the USB-COM adapter and an additional COM port has appeared on your system. Now we connect the decoder to the adapter (after disconnecting the adapter from the USB port!) To do this, just connect the 8 pins with 4 wires (in no case, vice versa!). Like that:
decoderusb-com
5v5v
txrx
rxtx
gndgnd

It's time, with bated breath, to connect our design to the USB port. If white smoke has not left the product, you can check the performance of the entire chain. You must make sure that the IR signal is received and sent, as well as write down all the codes from the remote control lamp. For this, the RealTerm program is perfect . I will not give screenshots, everything is simple and transparent there. I don’t want to deprive readers of the pleasure of slightly increasing the blood supply to their neocortex. It's nice.

Now that you have the captured Enigma codes in your hands”Remote control, it remains to check the lamp operation from the decoder. In the same RealTerm program, send the received codes and observe the lamp operation. There is a slight nuance in sending codes. If you are too lazy to read the documentation for the adapter, I will give a hint. By default, after turning on, the decoder works with the adapter at a speed of 9600. For sending a few bytes this is more than enough. But it is possible to increase the exchange rate with the adapter via RS232. In addition, before sending the code to the decoder, you must first send the A1 F1 prefix. For example, when capturing the code of the red button, RealTerm issued 00 FF 09. To get this code to the lamp through the decoder, you need to send the sequence A1 F1 00 FF 09. All the codes, of course, are hexadecimal.

I hope you got to this stage without casualties and destruction. It remains to pack everything into the case and configure Nagios and the agent. I used an old mouse as a case . Everything fit perfectly, it looks stylish, fashionable, youth. The main thing is not to forget to drill a hole for the LED according to GOST.

Now a few words about the signaling algorithm. Since there is only one light bulb, and simultaneously different services can be in different states, it means that there may not be enough light bulbs for everyone. Therefore, it is necessary to display the worst state at the current time. It's time to get back to the status request results via livestatus. Having received a string of numbers, we look at the very first number. If it is not 0, turn on the red color and complete the processing of the query results. All other statuses are no longer interesting to us, because There are no channels to display them. If the first number is 0, look at the next number, etc. If all the received values ​​are 0, then all services are in the OK status and you can safely turn on the green color.

image

The number of services in the OK status is not requested and not analyzed. In addition to displaying the status of services, the algorithm implements a kind of “heartbeat”. This is necessary to understand that the whole chain is working and working. Before any lamp switching, the violet color turns on for one second, and then the corresponding one (red, yellow, orange or green). After turning on the desired color, a dimming code is sent three times to reduce the lamp brightness to a minimum. In this lamp there are only 4 gradations of brightness, and the lamp after switching always turns on the maximum.

That's the whole simple light bulb algorithm. Plus, at night the lamp turns off and turns on in the morning.

For those who liked the recipe, posted scripts and pieces of configs on github .

Everything is very simple there. If you do everything carefully and accurately, then you will definitely ride a quadriga. Good luck.

Also popular now: