Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
How to disable visual block in VIM?

There is a feature in vim that as you select a text inside of vim, it turns the mode into VISUAL BLOCK. This is annoying for me in case you want to disable it put the below code in ~/.vimrc:

set mouse-=a

#vim #visual_block #mouse #set #vimrc
nethogs is used to monitor network traffic. You can see which processes use the most bandwidth and hogs the network.

Installtion on debian:

apt-get install nethogs

You can give the nethogs a network interface to see what's going on under the hood:

nethogs eth0


The output would something like:

PID USER       PROGRAM                                                       DEV        SENT      RECEIVED
9023 root python eth0 6.083 175.811 KB/sec
20745 root python eth0 2.449 45.715 KB/sec
11934 www-da.. nginx: worker process eth0 131.580 20.238 KB/sec
25925 root /usr/bin/python eth0 3.674 10.090 KB/sec

When nethogs is open, you can press r in order to sort based on RECEIVED or press s to sort based on SENT packets. To change the mode that it is shown for KB/sec press m multiple times and see the output.

#network #sysadmin #linux #nethogs #nethog #network #eth0
How to turn a dictionary into a string?

extra_data = {'iso': 'IR', 'address': 'Iran - Tehran - Azadi'}
' - '.join('{}:{}'.format(key, val) for key, val in extra_data.items())

The output would be:

iso:IR - address:Iran - Tehran - Azadi

NOTE: it could come in handy in case you want to store a variable dictionary structure into NO-SQL database.

#python #dictionary #string
How do you upgrade Icinga2 from a very old version?

The short answer is that you need to do an incremental upgrade on its database.

But how exactly?

apt-get update
apt-cache policy icinga2-ido-mysql
The candidate section displays what version is available for you system. Do the same for icingaweb2:

apt-cache policy icingaweb2
Upgrade these packages alltogether:

apt-get upgrade -o Dpkg::Options::="--force-confold" -y
Update icinga2 packages:

apt-get upgrade icinga2 icinga2-bin icinga2-common icinga2-ido-mysql libicinga2
apt-get install icinga2-bin
apt-get install icinga2
Now check icinga2 log in tail -f /var/log/icinga2/icinga2.log, you may see errors like:

[2017-12-21 12:00:22 -0600] critical/IdoPgsqlConnection: Schema version '1.14.2' does not match the required version '1.14.3' (or newer)! Please check the upgrade documentation at https://docs.icinga.com/icinga2
Here you need to upgrade MySQL schemas, go to /usr/share/icinga2-ido-mysql/schema/upgrade path and now import new schemas to Icinga2 MySQL database. As I was in version 2.6.0 I went for 2.8.0:

mysql -u icinga2 -p icinga2 < 2.8.0.sql
It will prompt for password of user icinga2, enter the password and go on.

The content of MySQL Schemas is as follows:


2.0.2.sql  2.1.0.sql  2.2.0.sql  2.3.0.sql  2.4.0.sql  2.5.0.sql  2.6.0.sql  2.8.0.sql  2.8.1.sql
NOTE: to get the password for user icinga2 open /etc/icinga2/features-enabled/ido-mysql.conf file and get the password from here.


#linux #icinga2 #monitoring #icinga2 #icingaweb #upgrade
How to get list of network interfaces using nagios?

In nagios plugins there is a script called check_nwc_health that can be used to report network interfaces of a remote server. In order to check interface usage of remote server network cards:

cd /usr/lib/nagios/plugins
./check_nwc_health --mode interface-usage -H 172.17.131.12 -C YOUR_COMMUNITY_STRING

Give your host address in -H section and your community string in -C param.

#nagios #network #network_usage
Tech C**P
How do you upgrade Icinga2 from a very old version? The short answer is that you need to do an incremental upgrade on its database. But how exactly? apt-get update apt-cache policy icinga2-ido-mysql The candidate section displays what version is available…
In case your upgrade failed, try to start icinga service and in the meantime check the logs in another console:

service icinga2 start

Check logs to see what is the error:

tail -f /var/log/icinga2/icinga2.log

If it point to a specific config file, change the config as reported or in case you don't need it remove it. It happened for me on another Icinga2 server and I removed the old config and tried to apply the new schemas. It gave another error on mysql grants, I gave all permissions to the icinga2 user:

mysql -u root -p
GRANT ALL PRIVILEGES ON icinga2_database_name.* TO 'icinga2_username'@'localhost'
flush privileges;

Now all things should be up and working now.

#icinga2 #monitoring #upgrade #schema_update #icinga