Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Did you know you can test bash scripts line by line? Well, bash -x is here to help:

$ bash -x your_script.sh
+ a=10
+ echo 10
10


The content of the bash script is:

#!/bin/bash

a=10
echo $a

#bash #sh #shell #scripting #debug #debugging
How to ignore a specific partition in Icinga2 monitoring server?

Sometimes a specific partition has been mounted on many servers. Now if you monitor disk partitions on Icinga2 and a warning message appears on that specific partition you will get notifications as many as your servers.

Icinga2 uses Snmp Storage Check in order to get disk partitions and their data. The command is located in /etc/icinga2/conf.d/ commands/snmp-storage.conf. (Its name maybe different in your case)

This command will use check_snmp_storage.pl nagios plugin, the overall structure of it is similar to:

object CheckCommand "snmp-storage" {
import "snmp-manubulon-command"

command = [ ManubulonPluginDir + "/check_snmp_storage.pl" ]

arguments += {
"-m" = "$snmp_storage_name$"
"-f" = {
set_if = "$snmp_perf$"
}
"-w" = 87
"-c" = 95
"-H" = "$address$"
"-m" = "^Cached|^Shared|^Swap|^/run|^Physical|^Memory|^Virtual|^/dev|^/sys|^/mnt/remote_folder"
"-e" = ""
}

vars.snmp_perf = true
}

-m parameter will ignore partitions. Here we have provided many partitions like /sys or /mnt/remote_folder. These partitions will be ignored all over. Add your desired partitions to this section.

To read more about this Perl plug-in head over to the below link:
- http://nagios.manubulon.com/snmp_storage.html

#monitoring #icinga2 #snmp #storage #snmp_storage
Hello Docker geeks :)

If you run a container and attach to that container you would see its stin, stout or stderr outputs. If you press CTRL+C while you're attached to the container the container will get stopped. In order to detach from the container you can use key sequence CTRL+ p + CTRL+q.

One of the reasons that CTRL+C stops the container is that this key combination sends SIGKILL signal to the container. There is a
parameter called --sig-proxy that is true by default which makes CTRL+C to send SIGINT. You can detach from a container and leave it running using the CTRL-p CTRL-q key sequence.

If you set --sig-proxy to false then CTRL+C would not kill the running container:

docker attach YOUR_CONTAINER_ID --sig-proxy=false

NOTE: you can get container id by issuing docker ps command.

#docker #attach #detach #sig_proxy #sequence_key #SIGINT #SIGKILL
اهداف زندگی شبیه ماهی اند

اگه یک ماهی کوچیک بخوای میتونی تو قسمت های کم عمق بمونی،

اما اگه ماهی بزرگ رو بخوای باید به جاهای عمیق تری بری...
Array and loop in bash script

To define an array you can use a structure like below, be careful that we don't use comma in between:

dbs=( 'test1' 'test2' 'test3' )


Now to loop over the array elements use for:

for your_db in ${dbs[@]}
do
echo $your_db
done

This is it!

#bash #scripting #for #loop #array
آیا این جهالت نیست که :
انسان ساعت‌های شیرین امروز را
فدای روزهای آینده کند ...؟!
How to check python code correctness? pychecker is the man! :)

- http://pychecker.sourceforge.net/

It's usage:

pychecker [options] file1.py file2.py ...

Read more about the provided options in the provided link.

#python #pychecker #compiler
Tech C**P
There is a mechanism in firefox that you can record some user activities on your site in order to test it from 0 to hero! Katalon Recorder (Selenium IDE for Firefox 55+) is an add-on that can be used to record tests on firefox and export it into a file.…
Previously we have talked about Katalon. Today I had a problem that I couldn't record user flow in Google Sheets. The problem was
that google changes ids per login, and sometimes per refresh! Therefore Katalon failed to replay the recorded suite.

Katalon uses xpath in order to follow deep inner divs and elements and records those elements hierarchy. To deal with these challenges, automation testers should not set fixed XPaths for elements in test cases, but instead scripting XPaths dynamically based on certain patterns.

Some examples:

Locate the h2 tag element that has text matching exactly Make Appointment:

.//h2[text()=’Make Appointment’]


Locate any element that contains the text Login:

//*[contains(text(),’Login’)]


Locate the a tag element that has the ID starting with LoginPanel:

//a[starts-with(@id=’LoginPanel’)]

#katalon #xpath
If you have space problems on a server that hosts MySQL database, it's good idea to use compression. Make sure you are using InnoDB storage engine.

In order to compress data on a table:

alter table YOUR_DB_NAME.YOUR_TABLE_NAME ROW_FORMAT=COMPRESSED;


The output in my case squeezed data 4X:

ls -lh users.ibd | awk '{print $5}'
16G


After compression:

ls -lh users.ibd | awk '{print $5}'
3.9G


NOTE: you have to use innodb_file_per_table in your configuration. We have previously talked about this procedure step by step.

#mysql #innodb #compression #alter #row_format #compressed
In Python you can use setattr to set an attribute on a class. Let's say we have a very simple class like below:

class User:
def register(self, key, val):
setattr(self, key, val)


Now if you want to set an attribute called name on User class:

>>> user = User()
>>> user.register('name', 'alireza')
>>> user.name
'alireza'

With a little bit of code you can automatically get data from a source and set dynamic attributes.

#python #setattr
What is zip function in Python?

zip function gets iterables as input and returns a tuple as output, it actually aggregates data:

zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]

Returns a list of tuples, where each tuple contains the i-th element from each of the argument sequences. The returned list is truncated in length to the length of the shortest argument sequence.

So the syntax is:

zip(*iterables)


The real world example:

numberList = [1, 2, 3]
strList = ['one', 'two', 'three']

# Two iterables are passed
result = zip(numberList, strList)

{(2, 'two'), (3, 'three'), (1, 'one')}


If number of elements differ:

numbersList = [1, 2, 3]

numbersTuple = ('ONE', 'TWO', 'THREE', 'FOUR')

result = zip(numbersList, numbersTuple)

print(set(result))
{(2, 'TWO'), (3, 'THREE'), (1, 'ONE')}

As you can see from above, list is truncated to the length of the shortest argument sequence numbersList.


You can also use zip to actually unzip data:

coordinate = ['x', 'y', 'z']
value = [3, 4, 5, 0, 9]

result = zip(coordinate, value)
resultList = list(result)
print(resultList)

c, v = zip(*resultList)
print('c =', c)
print('v =', v)

The output:

[('x', 3), ('y', 4), ('z', 5)]
c = ('x', 'y', 'z')
v = (3, 4, 5)

#python #zip #unzip #iterators
If your pyCharm does not recognize specific python files as a Python file and does not provide syntax highlighting for you, you need to navigate to File > Settings > Editor > File Types > Text and Under Registered Patterns, you can see the new myfilename.py in the list. Remove it from the list with the - button and click OK at the end.

#python #pycharm #file_types #syntax_highlighting
How to start a jetbrains license server on your own host using Docker:

docker run -d -p 8000:80 --name jetbrains-license-server \
-e TZ="Europe/Paris" \
-e JLS_VIRTUAL_HOSTS=jetbrains-license-server.example.com \
-v $(pwd)/data:/data \
crazymax/jetbrains-license-server:latest


There are many env variables you can set as JLS_VIRTUAL_HOSTS above:

TZ : The timezone assigned to the container (default UTC)
JLS_VIRTUAL_HOSTS : Virtual hosts where license server will be available (comma delimited for several hosts)
JLS_CONTEXT : Context path used by the license server (default /)
JLS_ACCESS_CONFIG : JSON file to configure user restrictions (default /data/access-config.json)
JLS_STATS_RECIPIENTS : Reports recipients email addresses for stats (comma delimited)
JLS_REPORT_OUT_OF_LICENSE : Warn about lack of licenses every hour following the percentage threshold (default 0)
JLS_SMTP_SERVER : SMTP server host to use for sending stats (stats disabled if empty)
JLS_SMTP_PORT : SMTP server port (default 25)
JLS_SMTP_USERNAME : SMTP username (auth disabled if empty)
JLS_SMTP_PASSWORD : SMTP password (auth disabled if empty)
JLS_STATS_FROM : From address for stats emails
JLS_STATS_TOKEN : Enables an auth token for the stats API at /reportApi (HTTP POST)

Volumes:
/data : Contains registration data and configuration

Ports:
`80 : Jetbrains License Server HTTP port

Github removes repos related to crack and license, copy or download content from the below link:

- https://github.com/crazy-max/docker-jetbrains-license-server

#docker #license_server #jetbrains #crazymax
If you use Icinga2 you are difinitely familiar with snmp. There are times that you need to debug the system. For exampe to see if
you can connect to snmp on the other side (firewall issues), or to find a specific mib.

For this you can use snmpwalk as below:

snmpwalk -Os -c YOUR_COMMUNITY_STRING -v 1 YOUR_SNMP_IP_ADDRESS

NOTE: this command is ran from Icinga2 server.

NOTE: snmp should be installed on server you want to monitor: apt-get install snmpd

#snmp #snmpd #snmpwalk
Sharing a piece of code in order to get a solution is a way everone follows, but the difference is about people who shares a piece of code professionally and those who just takes a picture from the screen in front! You should be happy in case the artistic photo is straight otherwise you have to tilt your head :)))

One of the greatest tools to do this job is codeshare. ou paste your code there and other people involve into the code concurrently with you.

Head over to link below to and use websites similar to the below website to share codes, never ever ever share a code with a photo taken from screen. This shows how negligible the time is for you and the person you're asking from, `cause it takes much more time to see what is on the screen:

- https://codeshare.io/

#codeshare #codeshare_io