:::: MENU ::::

Home

  • Sep 07 / 2016
  • 0
Linux

Send an UDP packet with NetCat

It can be needed to test an UDP connection with a server to ensure that connectivity is working and double check the data received.

Let’s take a simple example with a remote logstash server:
– Server mylogstash.mydomain.local
– Listening on port 5000

On emitter side, we are sending an UDP packet simulating a log line coming from an application:

echo -e '{"version": "1.1","host":"myapp.org","message":"My message","backtrace":"Backtrace of my app\n\nmore stuff"}\0' | nc -u -w 1 mylogstash.mydomain.local 5000

On receiving server side, we are executing a tcpdump to check that packet is correctly coming with good content:

# tcpdump -i any udp port 5000 -A
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
10:43:47.621172 IP mylogstash.mydomain.local.49435 > localhost.5000: UDP, length 108
[email protected]@............./..t..{"version": "1.1","host":"myapp.org","message":"My message","backtrace":"Backtrace of my app

more stuff"}.

Here we are! It’s very simple to control UDP flows or simply check connection between 2 servers.

  • Aug 22 / 2016
  • 0
Linux

Find and identify where inodes are used

Your monitoring system is claiming that your server is running out of free inodes but your disks are not full at all? Maybe you just need to check your filesystem usage and how many files are being used at the same time… Here are some tips to check and identify the inodes being used.

First of all, you can check percentage of inodes used with this simple command:

df -ih

You will see inode usage for your partitions and mouting points:

#dh -ih
Filesystem                                    Inodes IUsed IFree IUse% Mounted on
rootfs                                          120K  7.1K  112K    6% /
udev                                            495K   356  495K    1% /dev
tmpfs                                           497K   299  496K    1% /run
/dev/mapper/vg-root                             120K  7.1K  112K    6% /
tmpfs                                           497K     6  497K    1% /run/lock
tmpfs                                           497K     2  497K    1% /run/shm
/dev/sda1                                       122K   241  122K    1% /boot
/dev/mapper/vg-usr                              179K   51K  129K   29% /usr
/dev/mapper/vg-var                              242K  199K   43K   83% /var

Here, we can easily see that /var is using 83% of inodes, which is quite high.

Let’s now identify how those inodes are used with a compound command using find:

find /var -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n

You will get a sorted result like this (I truncated to display only the last lines which are the most important):

#find /var -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
     52 /var/lib/ucf/cache
    106 /var/spool/exim4/input
    153 /var/log
    184 /var/log/apache2
    301 /var/lib/mibs/ietf
    319 /var/cache/apt/archives
   2289 /var/lib/dpkg/info
  10893 /var/spool/postfix/maildrop

We can clearly see that inodes are mostly used by /var/spool/postfix/maildrop. You just have to go in that folder and check if files are useful and/or if you can do some cleaning there.
Then, once files are removed and directory clean, your inodes will be freed and everything will be back to normal!

  • Aug 11 / 2016
  • 0
Database

Calculate Database/Table size in MySQL

MySQL is an open-source relational database management system (RDBMS) available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements.

Thanks to some few functions, it’s possible to retrieve important information about database size and/or table size for a MySQL instance.

Size for all databases

SELECT table_schema "Database Name", SUM(data_length+index_length)/1024/1024
"Database Size (MB)"  FROM information_schema.TABLES GROUP BY table_schema;
+---------------------+--------------------+
| Database Name       | Database Size (MB) |
+---------------------+--------------------+
| db_1                |       113.51562500 |
| db_2                |       172.59375000 |
| db_3                |        48.70312500 |
| db_4                |      1830.53125000 |
| db_5                |       432.89062500 |
| information_schema  |         0.07812500 |
| mysql               |         1.03164101 |
| performance_schema  |         0.00000000 |
+---------------------+--------------------+
8 rows in set (0.41 sec)

Size of tables for a specific database

SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2) "Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "db_4";
+-------------------------------+------------+-----------------+
| Table Name                    | Rows Count | Table Size (MB) |
+-------------------------------+------------+-----------------+
| table_1                       |        245 |            0.05 |
| table_2                       |          1 |            0.03 |
| table_3                       |        537 |            0.11 |
| table_4                       |          1 |            0.05 |
| table_5                       |         57 |            0.05 |
| table_6                       |          0 |            0.05 |
| table_7                       |          2 |            0.05 |
| table_8                       |        584 |            0.13 |
| table_9                       |         48 |            0.03 |
| table_10                      |      12972 |            2.16 |
| table_11                      |        584 |            0.11 |
   [ ... ]
| table_50                      |          0 |            0.05 |
| table_51                      |     119864 |           16.03 |
| table_52                      |     146688 |            9.55 |
| table_53                      |         48 |            0.05 |
| table_54                      |     852591 |          208.30 |
| table_55                      |     138786 |           66.64 |
| table_56                      |         47 |            0.08 |
| table_57                      |        169 |            0.09 |
| table_58                      |          0 |            0.03 |
+-------------------------------+------------+-----------------+
58 rows in set (0.00 sec)

For a complete documentation, please refer to the official documentation on their website https://www.mysql.com

  • Aug 02 / 2016
  • 0
Linux

Skype group chat not working on linux

With Linux version for Skype, it can happen that group conversation are not working as expected (conversations do not start, or updates are not working, or group members do not appear, …).

You can check MSNP version you are using by typing this command in any conversation chat:

/dumpmsnp

If you are getting this message (“LoggedOut”), this means that you have the MSNP issue:

System: MSNP: Connection Data:
 * Status: LoggedOut

You can so enter in the chat:

/msnp24

Then, restart Skype.

Once restarted, you can check again the MSNP version:

/dumpmsnp

You should now get “LoggedIn”:

System: MSNP: Connection Data (MSNP24):
 * Status: LoggedIn

Et voila, Skype will now work correctly 🙂Avec la version Linux de Skype, il arrive parfois que les conversations de groupe rencontrent des soucis (elles ne dĂ©marrent pas, ou les mises Ă  jour ne se font pas, ou les participants n’apparaissent pas, …).

Vous pouvez vĂ©rifier la version de MSNP utilisĂ©e en tapant cette commande dans n’importe quelle conversation :

/dumpmsnp

Si vous obtenez ce message (“LoggedOut”), c’est que vous avez le problème de MSNP :

System: MSNP: Connection Data:
 * Status: LoggedOut

Vous pouvez alors taper :

/msnp24

Puis redémarrez votre Skype.

Une fois redémarré, vous pouvez vérifier à nouveau la version de MSNP :

/dumpmsnp

Et vous devriez maintenant avoir “LoggedIn” :

System: MSNP: Connection Data (MSNP24):
 * Status: LoggedIn

Et voilà, Skype fonctionnera désormais correctement 🙂

  • Jul 21 / 2016
  • 0
Linux

Open bash session into a docker container

Once a docker container is started, it’s always hard to get access into and see what’s happening inside. As a workaround, the easiest way to understand what’s happening in a container is to get a CLI on it and investigate.

Since version 1.3, you can easily open a bash session into a running container by using:

  • The ID of the container:
    sudo docker exec -i -t 43f10328e4e9 /bin/bash
    
  • Or the name of the container:
    sudo docker exec -i -t super_docker /bin/bash
    

You will get access with a bash session to your container:

$ [email protected]:/#

  • Jun 09 / 2016
  • 0
Linux, Python

openssl/pyOpenSSL – “SSL23_GET_SERVER_HELLO:tlsv1 alert internal error”

You’re getting this annoying error message again and again when trying to fetch certificate and/or establish a connection to your website using openssl:

139647967614624:error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error:s23_clnt.c:769:

This issue is well known in several openssl versions, and a bug has been addressed for Ubuntu repositories:
https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/1475228

For now, there’s a simple workaround that works to quickly fix it!

For openssl

If you’re facing it while using openssl directly, you can fix it by specifying the servername on command-line:

openssl s_client -connect www.mywebsite.com:443 -servername www.mywebsite.com

For pyOpenSSL

If you’re having this issue while using pyOpenSSL (python wrapper for OpenSSL), it can also be fixed with a quick workaround by adding the option set_tlsext_host_name() to specify the server name in your “Connection” object.
You will get something like this:

import socket
from OpenSSL import SSL

# REPLACE WITH YOUR OWN WEBSITE
hostname = 'www.mywebsite.com'
ctx = SSL.Context(SSL.TLSv1_METHOD)
sock = socket.socket()
ssl_sock = SSL.Connection(ctx, sock)
ssl_sock.set_tlsext_host_name(hostname)
ssl_sock.connect((hostname, 443))
ssl_sock.do_handshake()
cert = ssl_sock.get_peer_certificate()
print cert.get_subject().commonName

Pages:1...567891011...18
Question ? Contact