Parsing ini files

PostImage

Photo by Sincerely Media on Unsplash

Good afternoon, casual reader.

For one project, it was required to get the value of a variable from an ini file.

And it seems like the solution is simple, a one-line script like:

grep dbname db.conf | awk -F '=' '{ print $2 }'

But what if there are several values in different sections? Then a one-line script will not work anymore.

Search for a solution for linux gave no results :(, although maybe I'm just lazy and have not looked through all the search results.

The decision was made quickly, we take Python and the configparser package. Result ini-file.

Test task for applicants. Linux.

PostImage

Photo by Arian Darvishi on Unsplash

Colleagues, good afternoon!

Having moved to the position of team leader, I began to conduct interviews more often. And the problem with personnel in the region is making itself felt.

There is only one way out - to create a specialist!

And the main question becomes, is he ready?! It was decided to make a test task that was sent to potential colleagues. For verification, a specially broken image of the virtual machine was created.

Restoring this VM answer the following questions:
  • Reset password root

  • Working with fstab

  • iptables|firewalld

  • Routing Linux

  • systemd

  • LVM

  • Extended file attributes

  • Recovery of work PostgreSQL

  • Recovery of work bash scripts.

Links on image VM:

Next plans, i will create one more VM for advanced admins. Bye, bye.

Collect TCP|UDP sessions in Linux

PostImage

Photo by Hans-Peter Gauster on Unsplash

Hello my friend!

As the saying goes, "he called himself a computer technician, get into the IT department."

Preamble

Somehow I caught sight of a script to collect all connections on the host, well, that is a good idea, we put it in a zabbix, wait ... 5 minutes ... 10 minutes ... No values.

The error struck, the script could not keep within the allotted 30 seconds.

I will not describe my surprise when I read the script. a bunch of external utilities were used, regexp was superimposed, etc.

And that's all on Linux, where you can get any value simply by reading file!!!

Read more…

Solution to the problem SSH(pam_limits.so)

PostImage

Photo by Florian Krumm on Unsplash

Colleagues, good afternoon!

Having worked in support since 2007, I faced many problems, one of which I would like to talk about.

Introduction

One Friday at the end of the working day, a message is received about errors from one production server serving clients from Kaliningrad to Sakhalin.

A quick analysis of the server status showed that the problem is only with triggers that call the Bash shell to run, which seemed very strange. The second oddity seemed that the server was in production, and the problem had been fixed for about 30 minutes, there were no user requests! A survey of colleagues in a working chat, determined that today on this server they solved the problem with “too many open files” and solved it. We launch an SSH session on the server, and ... NO connection !!!

Read more…

pySpoolerRenamer — or how to rename a file stream

PostImage

Photo by Ankush Minda on Unsplash

Hello my friend!

Working with large data streams and analyzing them, you face a problem determining the ownership of the file, its source, since 99% of all flows generate soulless electric machines.

Sometimes it can be difficult to determine where the sasder345asd.txt or 123_HDR-Tas.csv file came from (in fact, this is just a set of letters, in most cases the file names have a structured name, but this is still hard to read for a person).

Read more…

pyRsyncBackup

PostImage

Photo by Everyday basics on Unsplash

Good day, casual reader!

And so what I want to tell you today, in the depths of one small department, one small company, a small script - and named this script pyRsyncBackup

For what?! The task was as follows:
  • Backing up configuration files.

  • The initiator must be from outside. Because NAT.

  • Not all nodes have direct access.

First, a prototype was created that performed all these functions, worked on CRON and everyone was happy while the number of servers did not exceed over 100. + the release of the new software added work on re-configuring pyRsyncBackup.

More requirements have appeared:
  • Auto detection of backup modules.

  • Working in Linux daemon mode.

Which was implemented in the current version pyRsyncBackup:
  • run as daemon.

  • Auto detection of backup modules.

  • Backing up via intermediate nodes.

What to expect next:
  • moving away from PostgreSQL, possibly into memory, perhaps into SQLite.

  • redesign of the proxy functionality, since some hosts shoot SSH connections (PAM)

  • Web interface for collecting backup files

But I will deal with these improvements, after creating a prototype of the access control system, if I have enough time and energy, then possibly this year as well.

Thank you.

Nagios Monitoring Black Cartridge Printer Brother DCP-7065DN

PostImage

Photo by Bank Phrom on Unsplash

The IT farm has 4 Brother DCP-7065DN printers, I wanted to monitor the status of the cartridges, and ran into problems:
  1. The plugin for Nagios check_snmp_printer is not suitable, it returns the wrong value, although it is perfect for monitoring the state of the drum.

  2. I could not find on the network what SNMP OID of the cartridge status for this printer.

I wrote to Brother support ... And unexpectedly for themselves they answered and gave me the OID for my printer. Opened my favorite VIM and wrote a bash script for Nagios. And now I share it check_snmp_brother.

We put this script in the folder with Nagios plugins, set the necessary rights, and set the flag for execution.

Configuring Nagios

define command{
command_name  check_snmp_brother
command_line  $USER1$/check_snmp_brother $ARG1$ $HOSTADDRESS$ $ARG2$ $ARG3$
}
define service{
        use                          default-service
        host_name                    PRINTER
        service_description          Toner Black
        check_command                check_snmp_brother!public!20!10
        }

The script works correctly for Brother DCP-7065DN model. If it works for other models, I will be glad if you let me know.