⬆️ ⬇️

SparrowHub - repository of ready-made utilities for system administration

SparrowHub is a project whose goal is to distribute various ready-made solutions for the tasks of system administration and not only.



Despite the fact that there are many solutions to automate the tasks of system administration, a certain niche in this area still remains unoccupied. What do we do when we want to solve a specific problem? For example, check the logs of our ssh service for unsuccessful login attempts to take care of the security of our servers? - We take and write a one-liner consisting of bash commands like grep, sed, awk and so on, well, or we can write a script in Perl . Great, it works. There is a solution that suits us. And we use it. The question is how we want to preserve the results of our works, to share them with others, or when the time passes will again take advantage of the invented solution. This is where the problem arises.

Custom scripts written "on the knee" are good when you need to do something right here and now, but there are problems with them:





This is where the idea of ​​a portable utility repository arises. In principle, it can be anything - checking the remaining disk space, searching for a specific group of processes in the list, taking into account the running time of individual programs, analyzing the logs for the presence of certain events, and so on. You write a utility, more precisely, in terms of SparrowHub - a plugin, load it into the repository, and, voila - it becomes available to others!



It is enough to install the sparrow utility on your server that provides the interface to the SparrowHub repository and start using ready-made plugins.



Here is how it looks in my case, I will give a few examples. And although they may seem trivial to someone in terms of replacing them with their custom solutions, we still remember what I started my topic with - why custom scripts can be problematic to use. And then, because SparrowHub project is quite young, it has not had time to accumulate a sufficient number of plug-ins, this post itself is aimed at attracting new developers to the community!



So, we first put the sparrow, this is the CPAN module:



$ cpanm Sparrow 


From non-perl dependencies, we still need curl:



 $ yum install curl 


Verify that the sparrow client is installed:



 $ sparrow 


Next, create a project. A project is just a container for plug-ins that we will install and use. You can have several projects for splitting used plugins into logical groups. For example, the system project — for system checks, such as disk space or tracking long running processes, the nginx project — for various checks of the nginx server, and so on.



 $ sparrow project create system 


Next we can search for various plugins. An alternative way would be to visit the https://sparrowhub.org resource and search through the web interface.



 $ sparrow index update #     SprrowHub $ sparrow plg search 


The last command given will give us a list of all available plugins. Choose df-check - plugin to check the remaining disk space. Install the plugin:



 $ sparrow plg install df-check 


OK. In principle, you can already run the plugin as is with the command:



 $ sparrow plg run df-check 


And make sure that there is enough disk space on the server. But let's add one more step, making our plugin customizable . To do this, we use the concept of checkpoints or control points, I apologize for involuntary taftology :) The checkpoint in sparrow is an abstraction that allows you to associate a separate plugin with a specific configuration. Thus, you can use the same plugin with different configurations, it is not difficult to guess that in this case we will have several checkpoints. Checkpoints are added to projects, associated with installed plugins (here is the breakdown of plugins into logical groups) and then configured.



Create a checkpoint:



 $ sparrow check add system disk 


Connect the checkpoint with the plugin:



 $ sparrow check set system disk df-check 


And now the most interesting ... let's insist a checkpoint or a plugin, which in this case is the same ...



 $ export EDITOR=nano $ sparrow check ini system disk [disk] #           threshold = 70 


Fine. Now let's run the checkpoint, more precisely the plugin with the settings defined for this checkpoint:



 $ sparrow check run system disk 


On my machine, the result will look like this:



 vagrant@Debian-jessie-amd64-netboot:~/my/outthentic$ sparrow check run system disk # running cd /home/vagrant/sparrow/plugins/public/df-check && carton exec 'strun --root ./ --ini /home/vagrant/sparrow/proj$ /tmp/.outthentic/13248/home/vagrant/sparrow/plugins/public/df-check/disk-shortage/story.t .. ok 1 - perl /home/vagrant/sparrow/plugins/public/df-check/disk-shortage/story.pl succeeded ok 2 - stdout saved to /tmp/.outthentic/13248/KopZcyueYX # threshhold: 70 # verify ... /dev/sda1 # verify ... udev # verify ... tmpfs # verify ... tmpfs # verify ... tmpfs # verify ... tmpfs # verify ... none # verify ... none ok 3 - output match /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ ok 4 - enough disk space (84%) on /dev/sda1 ok 5 - enough disk space (0%) on udev ok 6 - enough disk space (1%) on tmpfs ok 7 - enough disk space (1%) on tmpfs ok 8 - enough disk space (0%) on tmpfs ok 9 - enough disk space (0%) on tmpfs ok 10 - enough disk space (92%) on none ok 11 - enough disk space (92%) on none 1..11 ok All tests successful. Files=1, Tests=11, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.05 cusr 0.00 csys = 0.07 CPU) Result: PASS 


Actually, on this introduction, the SparrowHub co in its practical application can be completed. There are, of course, a number of other interesting utilities developed and laid out by me on SparrowHub - among them for example - stale-proc-check - plugin for searching for long-playing (obsolete - stale) processes or logdog - utilities for searching records in logs for a given period of time with possibility of grouping and filtering. The articles on the practical application of these plug-ins were recently written by me in English and posted on e-blogs.perl.org:





Conclusion



In this article, I touched on only the main features provided by the SparrowHub repository, of course you cannot tell everything, and this is not the goal. Ask questions, write comments, upload your plugins, use existing ones or throw requests for new development - it would be very interesting to find out what other people need and implement this in the form of plugins. In the end, everyone will win!



PS> for merge requests and issues for the sparrow utility, use https://github.com/melezhik/sparrow , there you can also post requests for new plugins.



PS2> the first article about sparrow was written by me some time ago and its text can be found here , a warning — during this time, much has changed.






Aleksey Melezhik, author of sparrow and SparrowHub.



')

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



All Articles