<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amith Chandrappa on Medium]]></title>
        <description><![CDATA[Stories by Amith Chandrappa on Medium]]></description>
        <link>https://medium.com/@amithgc?source=rss-1b00aec08f84------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pGlEBCjKl0pnmBrG.</url>
            <title>Stories by Amith Chandrappa on Medium</title>
            <link>https://medium.com/@amithgc?source=rss-1b00aec08f84------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:58:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amithgc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[CRONTAB]]></title>
            <link>https://medium.com/@amithgc/crontab-8ad49bb1f7d?source=rss-1b00aec08f84------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ad49bb1f7d</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[automate]]></category>
            <category><![CDATA[crontab]]></category>
            <dc:creator><![CDATA[Amith Chandrappa]]></dc:creator>
            <pubDate>Wed, 07 Dec 2022 07:40:35 GMT</pubDate>
            <atom:updated>2022-12-07T07:40:35.850Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*qKnHPDHv8IEUL4Xa.png" /></figure><p>Crontab, also known as the “cron table,” is a powerful Linux utility that allows users to schedule tasks to be automatically performed at specified times or intervals. This can be useful for a wide range of purposes, such as automating backups, performing maintenance tasks, or running regular reports.</p><p>To use crontab, you first need to open a terminal window and log in as the root user. Once you are logged in, you can use the “crontab” command to manage your cron jobs. To create a new cron job, use the following command:</p><pre>crontab -e</pre><p>This will open the crontab editor, where you can specify the details of your cron job. Each cron job is represented by a single line in the editor, with the following format:</p><pre>minute hour day-of-month month day-of-week command</pre><p>Each field in this format represents a different aspect of the cron job. The “minute” field specifies the minute of the hour when the job should be run, the “hour” field specifies the hour of the day, and so on. For example, the following cron job would run the “my_script.sh” script at 10:15 every day:</p><pre>15 10 * * * /path/to/my_script.sh</pre><p>Alternatively, you can use special symbols in place of specific values in the fields. For example, the “*” symbol can be used to match any value, so the following cron job would run the “my_script.sh” script every hour on the hour:</p><pre>0 * * * * /path/to/my_script.sh</pre><p>Once you have entered the details of your cron job, save the file and exit the editor. Your cron job will now be scheduled to run at the specified times.</p><p>To view the list of all cron jobs currently scheduled on your system, use the following command:</p><pre>crontab -l</pre><p>To edit an existing cron job, use the following command:</p><pre>crontab -e</pre><p>This will open the crontab editor again, allowing you to modify the details of the cron job. Once you have made your changes, save the file and exit the editor.</p><p>To remove a cron job, use the following command:</p><pre>crontab -r</pre><p>This will remove all of the cron jobs currently scheduled on your system. If you only want to remove a specific cron job, use the following command instead:</p><pre>crontab -l | grep -v &#39;my_script.sh&#39; | crontab -</pre><p>This will list all of the cron jobs on your system, remove the job for “my_script.sh,” and then save the resulting list as the new set of cron jobs.</p><p>In summary, crontab is a powerful Linux utility that allows you to automate tasks and schedule them to be performed at specific times. By using the commands discussed above, you can easily manage your cron jobs and make the most of this useful tool.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ad49bb1f7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Planted Aquarium — Automated Time Lapse]]></title>
            <link>https://medium.com/@amithgc/planted-aquarium-automated-time-lapse-86fdf531965?source=rss-1b00aec08f84------2</link>
            <guid isPermaLink="false">https://medium.com/p/86fdf531965</guid>
            <category><![CDATA[time-lapse-video]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[ffmpeg]]></category>
            <category><![CDATA[aquarium]]></category>
            <category><![CDATA[rtsp]]></category>
            <dc:creator><![CDATA[Amith Chandrappa]]></dc:creator>
            <pubDate>Mon, 07 Nov 2022 09:27:25 GMT</pubDate>
            <atom:updated>2022-11-07T09:45:48.169Z</atom:updated>
            <content:encoded><![CDATA[<h3>Planted Aquarium — Automated Time Lapse</h3><p>Just Planted Aquarium? <strong><em>NO</em></strong>. You can create a TimeLapse Video for every use-case you can think of.</p><p>Today, I will show you how I created an Automated TimeLapse for my Planted Aquarium.</p><figure><a href="https://github.com/amithgc/aquarium-photos"><img alt="" src="https://cdn-images-1.medium.com/max/800/1*4vSFGXQ-Mll57IRzuwKrIw.gif" /></a></figure><p>Here is the latest TimeLapse : <a href="https://github.com/amithgc/aquarium-photos/blob/main/gif/animation.gif">https://github.com/amithgc/aquarium-photos/blob/main/gif/animation.gif</a></p><h3>Before you Start</h3><p>Before you start, you would need the following…</p><ul><li><strong>A Camera</strong> : To capture the Images</li></ul><blockquote>Yes, You will need a camera. I used a <a href="https://amzn.eu/d/h9bGNuy">TP-LINK 3MP (Tapo 110) </a>. You can use any camera you like, Make sure there is a way to capture an image or at-least the camera supports RTSP protocol. In this article we would be using <a href="https://ffmpeg.org/"><strong>ffmpeg</strong></a><strong> </strong>to capture the image from RTSP Stream.</blockquote><ul><li><strong>GitHub Account : </strong>To store the Images</li></ul><blockquote>You will need a place to store these images, I opted for GitHub ( <em>🧑‍💻 </em>). We would also be using <a href="https://github.com/features/actions"><strong>GitHub Actions</strong></a> to write scripts to Generate TimeLapse Videos and GIF Animations. Alternatively, you can just use your machine to store images and generate images.</blockquote><h3>Configuring the Camera</h3><p>I cannot speak for all the cameras available in the market. Lets look at the configurations required in <a href="https://amzn.eu/d/9SnAjjQ">Tapo 110</a></p><p>Firstly, Setting up the camera should be straightforward. You can refer to the camera manual. Then you need to enable RTSP and generate credentials to access the same.</p><p>Open the Camera, Tap on <strong>Settings</strong>, Go to <strong>Advanced Settings</strong> and then Navigate to <strong>Camera Account</strong>.</p><p>Provide a UserName and Password. You will have to use this username and password to access the RTSP Video Stream.</p><p>Also, make sure you know the IP address of your camera. You will get it in your router config.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*VJQli4tpAazMSqfpMDaRdw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*esOe3nUS3F8PlavJ9XdGpg.png" /></figure><h3>RTSP Video Stream</h3><p>What is RTSP?</p><blockquote>Real Time Streaming Protocol (RTSP) is an application-level network communication system that transfers real-time data from multimedia to an endpoint device by communicating directly with the server streaming the data.</blockquote><blockquote>RTSP started as a way to allow users to play audio and video straight from the internet, rather than having to download media files to their devices. The protocol has been applied for various uses, including internet camera sites, online education and internet radio.</blockquote><p>Check If your RTSP is working. If you are using Tapo 110 camera, Your RTSP stream will be available at</p><blockquote>rtsp://username:password@&lt;YOUR CAMERA ID&gt;:554/stream1</blockquote><blockquote>Example: rtsp://admin:admin@192.168.1.106:554/stream1</blockquote><p>You can even load this URL in VLC Player and watch the Video Stream. In VLC, Click on Open Network and paste the URL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U94x0oziUMEQSd1S_JaxRw.png" /></figure><p>Now you need a way to capture a frame from this Video stream automatically. There are multiple ways of doing this. If your camera has a URL which returns an image directly. Then you can use it. In our case we will be using <strong>ffmpeg</strong> to capture a frame from RTSP Stream.</p><blockquote>ffmpeg -i rtsp://username:password@192.168.1.106:554/stream1 -y -f image2 -frames:v 1 capture.jpg</blockquote><p>At this point you have an image “<em>capture.jpg</em>”. You can automate this script in crontab.</p><h3><strong>Push Captured Image to GitHub</strong></h3><p>Once you have an Image, You need to push it to GitHub. We will be using <a href="https://docs.github.com/en/rest">GitHub API</a> to push the image.</p><p>Before this, Create a Project in GitHub and create an <strong>images</strong> folder inside it. We will be pushing all our images into this folder.</p><p>You will also need a <a href="https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token">GitHub Personal Access Token</a>, and <a href="https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token">here</a> is how you will be able to generate it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26ae313ffd7d3a1354ba3d6d00cd8570/href">https://medium.com/media/26ae313ffd7d3a1354ba3d6d00cd8570/href</a></iframe><h3>Build Video and GIF animation</h3><p>At this point you have your images getting uploaded to GitHub, Now you can use GitHub Actions to create a Video and GIF Animation automatically.</p><p>Refer to this <a href="https://github.com/amithgc/aquarium-photos"><strong>GitHub Project</strong></a>, I have all the setup ready here. Please follow the Structure of the project.</p><p>Here is the <a href="https://github.com/amithgc/aquarium-photos/blob/main/.github/workflows/video.yml"><strong><em>GitHub Action File</em></strong></a></p><pre>name: Generate Video<br>on:</pre><pre>  schedule:<br>    - cron: &#39;0 0 * * *&#39;<br><br>  # Allows you to run this workflow manually from the Actions tab<br>  workflow_dispatch:<br><br>jobs:<br>  generate-video:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v2<br>      - name: Setup ffmpeg<br>        uses: FedericoCarboni/setup-ffmpeg@v1-beta<br>        id: setup-ffmpeg<br>      - name: Generate Video<br>        run: ffmpeg -y -framerate 10 -pattern_type glob -i &quot;images/*.jpg&quot; -c:v libx264 -crf 0 ./videos/video.mp4<br>      - name: Generate Gif<br>        run: ffmpeg -y -i ./videos/video.mp4 -vf scale=800:-1 -r 10 ./gif/animation.gif<br>      - name: Generate HD Gif<br>        run: ffmpeg -y -i ./videos/video.mp4 -vf scale=2304:-1 -r 10 ./gif/animation-HD.gif<br>      - name: Check to see if a new video file has been created<br>        id: changes<br>        run: |<br>          git add -N .<br>          echo &quot;::set-output name=count::$(git diff --name-only | wc -l)&quot;<br>      - name: Commit files<br>        run: |<br>          git config --local user.email &quot;41898282+github-actions[bot]@users.noreply.github.com&quot;<br>          git config --local user.name &quot;github-actions[bot]&quot;<br>          git add ./videos/*<br>          git add ./gif/*<br>          git commit -m &quot;Video Generated, Automated&quot; -a<br>        if: steps.changes.outputs.count &gt; 0<br>      - name: Push changes<br>        uses: ad-m/github-push-action@master<br>        with:<br>          github_token: ${{ secrets.GITHUB_TOKEN }}<br>          branch: ${{ github.ref }}<br>        if: steps.changes.outputs.count &gt; 0</pre><p>This Github WorkFlow will execute everyday, It will pickup the files in /images folder and uses <strong>ffmpeg</strong> to generate Video and GIF Animation.</p><p><em>Feel free to use this anywhere you like…. also, visit </em><a href="https://github.com/amithgc/aquarium-photos"><em>My GitHub Project</em></a><em> to see this in action.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86fdf531965" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitor API Response time in Spring Boot]]></title>
            <link>https://medium.com/@amithgc/monitor-api-response-time-in-spring-boot-f79d50d6d811?source=rss-1b00aec08f84------2</link>
            <guid isPermaLink="false">https://medium.com/p/f79d50d6d811</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[response-time]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[aspectj]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Amith Chandrappa]]></dc:creator>
            <pubDate>Fri, 13 Aug 2021 13:15:24 GMT</pubDate>
            <atom:updated>2021-08-15T03:14:26.741Z</atom:updated>
            <content:encoded><![CDATA[<h3>Monitor API Response time in Spring Boot using Grafana</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*kLNw2Tbtfb-PMKtcJYZpnQ.png" /></figure><blockquote>API Response time — Response time is <strong>the amount of time a system takes to respond to a request once it has received one</strong> . For example, the time between the instant we execute an API and this API returns the result of its computation, that’s the response time.</blockquote><p>As of today, There are numerous ways to monitor spring boot applications and the API response time. But, Many of the cases when your production environments are running old versions of Spring or there are legacy code where you will not be able to utilise the latest frameworks. You will have to use some custom and efficient ways to monitor the API’s.</p><p>Today, Let us look at one of the <em>hacky</em> way to implement the <strong><em>api monitoring</em></strong> in your legacy spring boot application.</p><h3>Before you Start</h3><p>Before you start, We expect you to have the following installed in your production environment.</p><ul><li><a href="https://grafana.com/"><strong>Grafana</strong></a></li></ul><blockquote>Grafana is an open source solution for running data analytics, pulling up metrics that make sense of the massive amount of data &amp; to monitor our apps with the help of cool customisable dashboards.</blockquote><blockquote>Grafana connects with every possible data source, commonly referred to as databases such as <em>Graphite, Prometheus, Influx DB, ElasticSearch, MySQL, PostgreSQL </em>etc.</blockquote><ul><li><a href="https://www.influxdata.com/"><strong>Influx DB</strong></a></li></ul><blockquote>InfluxDB is an open-source time series database developed by the company InfluxData. It is written in the Go programming language for storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics.</blockquote><p>If you have a <strong>TIG Stack</strong>, then you would already have the setup required to do the API Monitoring.</p><h3>Plan</h3><p>The plan is to add some piece of java code in your your spring project to monitor all the API calls. When the Monitoring code detects a slow API, It pushes the API Details and its execution time to Influx DB via <strong><em>http. </em></strong>Then we can plot this data in Grafana.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*ak_9MLjxurQXoVw6nyz-Iw.png" /></figure><h3>Code</h3><p>Add the following dependency in your pom.xml</p><pre>&lt;!-- https://mvnrepository.com/artifact/org.aspectj/aspectjtools --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;org.aspectj&lt;/groupId&gt;<br>    &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;<br>    &lt;version&gt;1.8.9&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>And, add the following java code in your project</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed8d73c9779950c3395f63337731edc2/href">https://medium.com/media/ed8d73c9779950c3395f63337731edc2/href</a></iframe><p>Thats it, Just deploy the project. Data should start showing up in the Influx DB.</p><p>Now, You can create a chart in <strong>Grafana </strong>to<strong> </strong>show this data. Also, You can set alerts in Grafana and let every one know if something is going wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*RwKUOK_XJSCrd_ZWzZyylg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f79d50d6d811" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PLEX Server Alerts in Telegram using Node-RED]]></title>
            <link>https://medium.com/@amithgc/plex-server-alerts-in-telegram-using-node-red-4d9984750d2b?source=rss-1b00aec08f84------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d9984750d2b</guid>
            <category><![CDATA[node-red]]></category>
            <category><![CDATA[plex]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[movies]]></category>
            <dc:creator><![CDATA[Amith Chandrappa]]></dc:creator>
            <pubDate>Fri, 13 Aug 2021 08:27:29 GMT</pubDate>
            <atom:updated>2021-08-13T09:24:26.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8wPBse4NZg5Aja03OsiGsg.png" /></figure><p>Wouldn&#39;t it be nice if you could receive a notification in <strong><em>telegram</em></strong> when a movie starts playing in you <a href="https://www.plex.tv/"><strong><em>plex</em></strong></a> server?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*AF-jvPh2OqGJtV183J075Q.png" /></figure><p>In this Article, We will learn how to setup a bot and make it send notifications when a movie starts playing in plex.</p><h3>Before you Start</h3><p>Before you start you would need the following…</p><ul><li><strong>PLEX Server</strong> : You will need a plex server running in any of your home servers.</li></ul><blockquote>Plex gives <strong>you one place to find and access all the media that matters to you</strong>. From personal media on your own server, to free and on-demand Movies &amp; Shows, live TV, podcasts, and web shows, to streaming music, you can enjoy it all in one app, on any device.</blockquote><ul><li><strong>Node-RED Server</strong> : You will also need a Node-RED server running in any of your home server.</li></ul><blockquote>Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.</blockquote><ul><li><strong>Pre-Configured Telegram Bot</strong> : If you don’t know how to create a Telegram Bot, Please refer to my other medium article which explains the details of creating a bot — <a href="https://medium.com/@amithgc/track-ssh-logins-via-telegram-6a501573ebfb"><strong><em>link</em></strong></a></li></ul><blockquote>Telegram bots are <strong>small programs that can embed in Telegram chats or public channels and perform a specific function</strong>. They can offer customised keyboards, produce cat memes on demand, or even accept payments and act as a digital storefront.</blockquote><h3><strong>PLEX Node-RED Palette</strong></h3><p>Firstly, you will need to install the Plex Node-RED palette in your Node-RED instance. Open Palettes and search for <a href="https://flows.nodered.org/node/node-red-contrib-plex-ws"><em>node-red-contrib-plex-ws</em></a><em> </em>and install it.</p><p>This palette has the ability to talk to plex server and receive notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*5JRxSZXdT6TUSckqhxQxDA.png" /></figure><p>To Configure the plex palette you you need the <strong>plex token</strong></p><h3>Finding the PLEX Token</h3><ol><li>Sign in to your Plex account in Plex Web App</li><li>Browse to a library item and view the XML for it</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*IXfcuEhG0OBmu_Ah.png" /></figure><p>3. Click the XML link at the bottom of the Media Info window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*yB0swobvaPQPg1Y-vIT9ZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*i1f0k11y50YRD_dkXaMxWA.png" /></figure><p>4. Look in the URL and find the token as the X-Plex-Token value</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*cOcGWniS7-nWdkXn.png" /></figure><p>5. Copy this token and save it, We will have to use this token in the next steps.</p><h3>Setup Plex Palette</h3><p>Once you have got your plex token, It is now time to setup your Plex Palette in Node-RED.</p><p>Drag and Drop the Plex Playing Node to the Flow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/183/1*FAQda70fKOc_WbLAnn11_w.png" /></figure><p>and, Double Click on the Node to Open up the node Settings, In the Server Section, Click to add a new Server. Fill in the <strong><em>host</em></strong> (ip of your plex server), <strong><em>port</em></strong> and the <strong>plex</strong> <strong><em>token.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Phfjs4H8lWeatLTA06zQtg.png" /></figure><h3>Setting up the Node-RED Flow</h3><p>Create a flow as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*E5ZyrnEPZj0REKyGssGxIA.png" /></figure><p>rbe node is added just to make sure that there are no duplicate notifications</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*EojFNc2dAgNBq7uixk1Btg.png" /></figure><p>In the Functions node, Add the following code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*jJ26YfsQKgHaDYkP1AObuA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1defa947e8031afc1aad67bfbe0b855/href">https://medium.com/media/d1defa947e8031afc1aad67bfbe0b855/href</a></iframe><p>This JavaScript code will fetch the movie images from IMDB and send it via Telegram.</p><h3>Setup Telegram in Node-RED</h3><p>You will need to configure the Telegram Bot to receive the Notifications, Please refer to the following links to setup a Telegram Bot inside Node-RED</p><ul><li>Create a Bot — <a href="https://medium.com/@amithgc/track-ssh-logins-via-telegram-6a501573ebfb"><strong><em>link</em></strong></a></li><li>Add the Bot inside Node-RED — <a href="https://flows.nodered.org/node/node-red-contrib-telegrambot"><strong><em>link</em></strong></a></li></ul><p><em>Thats it, You are all done!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d9984750d2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Track SSH Logins via Telegram]]></title>
            <link>https://medium.com/@amithgc/track-ssh-logins-via-telegram-6a501573ebfb?source=rss-1b00aec08f84------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a501573ebfb</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[telegram-bot]]></category>
            <dc:creator><![CDATA[Amith Chandrappa]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 09:55:59 GMT</pubDate>
            <atom:updated>2021-08-13T09:25:31.080Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*VjKOsf2rvKQqCX6KKRZ92A.png" /></figure><p>If you are a Dev-Ops Engineer, You and Your team may want to keep a track of who is logging in to which Servers/Virtual Machines.</p><p>In this article, We will learn how to create a Telegram Bot and write a shell script to send messages to Telegram messenger using the Curl command.</p><p>Then you will also use this shell script to send a notification to your Telegram Channel when a SSH login is detected.</p><h3><strong>Building a Telegram Bot</strong></h3><p>Bots are <strong>third-party applications that run inside Telegram</strong>. Users can interact with bots by sending them messages, commands and inline requests. You control your bots using HTTPS requests to our Bot API.</p><p>To send a message to Telegram group or channel, you should first create your own bot. Just open Telegram, find @BotFather and type /start. Then follow instructions to create bot and get token to access the HTTP API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*MMJZuBi3eO6BW8k9URJldQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*qKINnu68gDCcue80CKtx5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*Hlz9aKDryqTyfZcSX9a5bA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*4hU7vM3m3d6q0U_1nECedw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*k6BdErhEnUwquA6vqG8m6Q.png" /></figure><ol><li>Search for @BotFather and click on <strong>“Start”</strong> or type “<em>/start</em>”</li><li>Type “<em>/newbot” </em>to start creating a new Bot</li><li>Name the bot. <em>Example, in our case we are naming the bot as “</em><strong><em>test-ssh-bot</em></strong><em>”</em></li><li>You will get a HTTP Access Token <em>(marked in red). </em>Make a note of it, You will have to use it in the shell script.</li><li>Also, Tap on the link “<em> t.me/sample_test_ssh_bot</em>” to message the bot. Send a test message to the bot.</li></ol><p>Congratulations! Now at this point of time, You have a Bot ready.</p><h3><strong>Creating Telegram Chat Channel</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*Ikgold4IoiAEZU1nq8NX1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*B7nRne4Oc4aAfeHE6KFtAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*8Q3igaQc3_j98-r71SidoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*qbuNlL_Xzmtv4AS8cshRfg.png" /></figure><p>Create a new <strong>Channel </strong>and name it as <strong>SSH Channel. </strong>Also add the bot we created in the last step to this channel as a <strong>subscriber.</strong></p><p>After the Channel is created, Send a test message to the channel.</p><h3>Get the required Details</h3><p>Now that you have everything ready at Telegram’s side, Lets get the required details to write the Shell Script.</p><p>We need 2 things</p><ol><li>Bot Token — We have already got it</li><li>Group Chat ID</li></ol><p>Open the following link in any of the browser</p><p>https://api.telegram.org/bot&lt;YourBOTToken&gt;/getUpdates</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H9aGO9VAnOgEc9r9jrQCwQ.png" /></figure><p>You will see a json response, If you don’t see any data you should send a test chat message in the channel first. <strong>Highlighted</strong> in red is your <strong>Group Chat ID</strong>. Make a note of it, You will have to use it in the shell script.</p><h3>Shell Script to send a Telegram message</h3><p>To send a message we could use simple command like</p><p>curl https://api.telegram.org/bot&lt;YourBOTToken&gt;/sendMessage?chat_id=&lt;group_chat_id&gt;&amp;text=&lt;text_message&gt;</p><p>Now, Lets build a Shell Script which can send a message on every SSH</p><p>Create file as /usr/local/bin/notify-on-ssh-login.shin the server which you want to monitor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f89940fbfe7faaf3dd401bfe71610f9/href">https://medium.com/media/8f89940fbfe7faaf3dd401bfe71610f9/href</a></iframe><p>Give <em>executable</em> permission to this file</p><p>chmod 777 /usr/local/bin/notify-on-ssh-login.sh</p><p>Open the file sshd (vi /etc/pam.d/sshd) and add the following line</p><p>session optional pam_exec.so /usr/local/bin/notify-on-ssh-login.sh</p><h3>Results</h3><p>Congratulations!, You are all done. Now when anyone with the SSH Access logs into the VM, You will get a message as below.</p><p>Now you can add everyone in you Dev-Ops team to this Group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*Q_9vQ-0v3FE8Fk6I1W9H5Q.png" /></figure><p><strong>Happy Coding!!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a501573ebfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>