New Order alert on Telegram for Prestashop

I created a Prestashop Module for a project that would send an alert to a Telegarm group when ever a new order is placed.
I would like to share the same with all of you.
Please feel free to download and use 👦

You can download the module zip file from herehttps://github.com/bhaskarvyas001/TelegramOrderAlert

Requirement:
1. You will need to Telegram Bot Token
This can be got by creating a bot. Details to create a telegram bot is here - https://core.telegram.org/bots#6-botfather

2. You will need to know that Chat Id of the telegram group where you want to receive the alert
You can find out the Chat Id by following details here - https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id




Setting Screen



This is how the Telegram alert would look like





GROK Pattern in Streamsets Log Parser

Streamsets Log Parser allows you to parse and ingest Log Files from server
There are multiple pre-defined "Log Formats" to choose from such as CommonLog Format or Combined Log Format for Apache Access Logs
However, if you have defined your own log format then "GROK" patterns are great way to configure Log Parser to consume them.

The real challenge however is how should you define you GROK Pattern.
Test Grok Patterns (https://grokconstructor.appspot.com/do/matchis a great website to enter your GROK pattern and log line and test if things will work.

It also provides an "Automatic" mode (https://grokconstructor.appspot.com/do/automatic)
This will generate the GROK pattern for you based on the log line that you provide.

However, if you are using a customized version of Apache access log then you can use standard GROK patterns to match your log line.

For example, for my access log line GROK pattern is given below

Log Line
103.107.92.250 - - [21/Apr/2019:17:34:35 +0530] "GET /form/track-shipment/ HTTP/1.1" 200 8324 "http://onlinexpress.co.in/form/track-shipment/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36" 400

Grok Pattern

%{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-) %{QS:referrer} %{QS:agent} %{NUMBER:responseTime}


Streamsets Log Parser Configuration


In the screenshot MYPATTERN is the custom name that I have given for my pattern in "GROK Pattern Definition" field.
The first word is always the pattern name, which is to be entered in the "GROK Pattern" field.

Setting up ELK and Streamsets in CWP (Cent OS 7)

Though getting started with ELK itself is pretty straight-forward and simple; I ran into small hurdles lately and I thought it would make sense to make a note of it and share with all of you.

Step 1 : Missing JAVA
So the very first thing you will find missing is the JDK 8 which is mandatory for all these tools.
Please do not install OpenJDK1.8 as it has missing packages and will land you in trouble later. We need to install Oracle JAVA 8
You can download the RPM from here  -
https://www.oracle.com/technetwork/java/javaee/downloads/jdk8-downloads-2133151.html

File downloaded: jdk-8u211-linux-x64.rpm

Make it executable : chmod +x jdk-8u211-linux-x64.rpm

Install: sudo yum install jdk-8u211-linux-x64.rpm

Set the JAVA_PATH: With Non Sudo user run these commands
vi .bash_profile
Add this line at end: export JAVA_HOME=/usr/java/jdk1.8.0_211-amd64/jre/bin



Step 2: Get Elastic Search
Please do not download the ZIP package. There is an RPM version available as well and it installs as a service. You can download it from here -
https://www.elastic.co/downloads/past-releases/elasticsearch-6-2-3

File downloaded: elasticsearch-6.2.3.rpm

Make it executable : chmod +x elasticsearch-6.2.3.rpm

Install: sudo yum install elasticsearch-6.2.3.rpm

Run: 
  sudo systemctl daemon-reload
  sudo systemctl enable elasticsearch.service
  systemctl start elasticsearch.service
  systemctl status  elasticsearch.service


Step 3: Get Kibana
Please do not download the ZIP package. There is an RPM version available as well and it installs as a service. You can download it from here -
https://www.elastic.co/downloads/past-releases/kibana-6-2-3

(NOTE: The version of Elastic Search and Kibana should be same)

File downloaded: kibana-6.2.3-x86_64.rpm

Make it executable : chmod +x kibana-6.2.3-x86_64.rpm

Install: sudo yum install kibana-6.2.3-x86_64.rpm

Run:
  sudo systemctl daemon-reload
  sudo systemctl enable kibana.service
  systemctl start kibana.service
  systemctl status  kibana.service


Step 4: Configure Kibana Host in config file
Location of Config file:  /etc/kibana/kibana.yml
Update these configurations -
server.host: "0.0.0.0"
elasticsearch.url: "http://localhost:9200"
elasticsearch.username: "admin"
elasticsearch.password: "password"


Step 5: Get Streamsets
You can download the zip from here:

wget https://archives.streamsets.com/datacollector/3.8.1/tarball/streamsets-datacollector-core-3.8.1.tgz

Untar the .tgz file: tar -zxf streamsets-datacollector-core-3.8.1.tgz
Increase Ulimit: 
vi /etc/security/limits.conf
Add these lines at end of file i.e.
*    soft    nofile 65000
*    hard    nofile 65000

Run:   nohup streamsets-datacollector-3.8.1/bin/streamsets dc &

Step 6: Enable Ports in Firewall
Following ports need to be opened i.e. 5601, 9200







Extend / resize SWAP partition in Centos

Hi,

If you are running low on swap memory in your centos environment; please follow these steps to extend the swap partition.

Step 1:
Since all the space in the physical disk would already be allocated to different partitions; there would not be any free space in your "Logical Volume" to give to swap partition.
You can see the volume group details by running the command > vgs




You can verify the logical volume details by running the command > lvs



You can see that there is no free space and my swap volume has 2GB space.


Step 2:
So, first logical step is to get some free space from other partition (probably from home partition as that has maximum space in the screenshot above) so that it can be allocated to swap partition

So, first we need to un-mount the home partition.
It can be done by following command > sudo umount -fl /home

Next to change the partition size, run the command >  lvreduce -L 173.88G /dev/mapper/centos-home

NOTE: Please note that the size to be given here is the new total size i.e. if old size was 60GB and you want to reduce it to 50GB so that you get 10GB free space then give 50GB here.


Once you have done this, you can run the vgs command again to verify the free space that has been obtained.



Step 3:
Now, we need to clear and turn off SWAP
This can be done by following commands i.e.
First run this command > echo "3" > /proc/sys/vm/drop_caches
Then run this command > swapoff -v /dev/centos/swap


Step 4:
Now, the grand step of increasing the swap partition
Please run this command > lvm lvresize /dev/centos/swap -L +6G

NOTE: Since I had freed 6GB space so I am adding 6GB to existing SWAP partition. This will make the new SWAP to be 2G + 6G = 8G


Running the vgs command again will show that the free space has been used up



Step 5:
Now we need to wipe off old SWAP signature and recreate the swap so that it know the new size
Use these command for it i.e.

First > mkswap /dev/centos/swap

Next >  swapon -va

Verify using command > swapon -s



Step 6:
Check the new partition details using command > lvs




Finally, Mount the home partition > sudo mount -fl /home