<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://blog.nishchith.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.nishchith.com/" rel="alternate" type="text/html" /><updated>2026-08-03T02:46:48+00:00</updated><id>https://blog.nishchith.com/feed.xml</id><title type="html">blog.nishchith.com</title><subtitle>old blog</subtitle><entry><title type="html">Setup server alerts using webhooks</title><link href="https://blog.nishchith.com/server-alerts-using-webhooks/" rel="alternate" type="text/html" title="Setup server alerts using webhooks" /><published>2020-12-20T04:54:32+00:00</published><updated>2020-12-20T04:54:32+00:00</updated><id>https://blog.nishchith.com/server-alerts-using-webhooks</id><content type="html" xml:base="https://blog.nishchith.com/server-alerts-using-webhooks/"><![CDATA[<p>If you’re using self-hosted servers, you might have run into <a href="https://feross.org/how-to-setup-your-linode/">this</a> (or similar) blog which covers most of the things you need to do on your first login to the server.</p>

<p>Over the past weeks, I’ve failed to setup mail alerts on ssh login, sudo, and other events due to the various cloud providers blocking the <code class="language-plaintext highlighter-rouge">SMTP</code> ports for <a href="https://www.linode.com/blog/linode/a-new-policy-to-help-fight-spam/">security reasons</a> and making it difficult to setup a Mail Transfer Agent (MTA) quickly.</p>

<p>Slack alerts seemed to be the next logical step, and it takes considerably less time to setup. We’ll be leveraging Unix systems’ Pluggable Authentication Module (PAM) – which can be configured under <code class="language-plaintext highlighter-rouge">/etc/pam.d</code> – to setup slack alert on ssh login and logout events.</p>

<p>The following steps shall guide you to easily setup the same and maybe adapt the process to other services like discord, telegram, or what have you.</p>

<ul>
  <li>Setup incoming webhook in slack
    <ul>
      <li>Follow the instructions under the <code class="language-plaintext highlighter-rouge">Getting Started</code> section on <a href="https://api.slack.com/incoming-webhooks">slack’s webhook documentation</a> for creating an app and tieing it to a <code class="language-plaintext highlighter-rouge">#channel</code> under your desired workspace. This should land you with a <code class="language-plaintext highlighter-rouge">Webhook URL</code>.</li>
    </ul>
  </li>
  <li>We’ll use the following script which sends a <code class="language-plaintext highlighter-rouge">POST</code> request with the details (<code class="language-plaintext highlighter-rouge">IP ADDRESS</code>, <code class="language-plaintext highlighter-rouge">HOSTNAME</code>) on either <code class="language-plaintext highlighter-rouge">open_session</code> (login) or <code class="language-plaintext highlighter-rouge">close_session</code> (logout) event as payload to the <code class="language-plaintext highlighter-rouge">WEBHOOK URL</code>.</li>
</ul>

<figure class="highlight">
  <pre><code class="language-bash" data-lang="bash"><span class="c">#!/bin/bash</span>

<span class="nv">WEBHOOK_URL</span><span class="o">=</span><span class="s2">"&lt;WEBHOOK_URL&gt;"</span>
<span class="nv">CHANNEL</span><span class="o">=</span><span class="s2">"#&lt;CHANNEL_NAME&gt;"</span>
<span class="nv">HOST</span><span class="o">=</span><span class="s2">"</span><span class="si">$(</span><span class="nb">hostname</span><span class="si">)</span><span class="s2">"</span>

<span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$PAM_TYPE</span><span class="s2">"</span> <span class="o">==</span> <span class="s2">"open_session"</span> <span class="o">]</span> <span class="o">||</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$PAM_TYPE</span><span class="s2">"</span> <span class="o">==</span> <span class="s2">"close_session"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then
    </span><span class="nv">content</span><span class="o">=</span><span class="s2">"</span><span class="se">\"</span><span class="s2">attachments</span><span class="se">\"</span><span class="s2">: [{ 
        </span><span class="se">\"</span><span class="s2">mrkdwn_in</span><span class="se">\"</span><span class="s2">: [</span><span class="se">\"</span><span class="s2">text</span><span class="se">\"</span><span class="s2">, </span><span class="se">\"</span><span class="s2">fallback</span><span class="se">\"</span><span class="s2">], 
        </span><span class="se">\"</span><span class="s2">fallback</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">Event : </span><span class="nv">$PAM_TYPE</span><span class="s2"> to </span><span class="se">\`</span><span class="nv">$HOST</span><span class="se">\`\"</span><span class="s2">, 
        </span><span class="se">\"</span><span class="s2">text</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">SSH: </span><span class="nv">$PAM_TYPE</span><span class="s2"> to </span><span class="se">\`</span><span class="nv">$HOST</span><span class="se">\`\"</span><span class="s2">, 
        </span><span class="se">\"</span><span class="s2">fields</span><span class="se">\"</span><span class="s2">: [ { 
                </span><span class="se">\"</span><span class="s2">title</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">User</span><span class="se">\"</span><span class="s2">, 
                </span><span class="se">\"</span><span class="s2">value</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="nv">$PAM_USER</span><span class="se">\"</span><span class="s2">, 
                </span><span class="se">\"</span><span class="s2">short</span><span class="se">\"</span><span class="s2">: true 
            }, { 
                </span><span class="se">\"</span><span class="s2">title</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">IP Address</span><span class="se">\"</span><span class="s2">, 
                </span><span class="se">\"</span><span class="s2">value</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="nv">$PAM_RHOST</span><span class="se">\"</span><span class="s2">, 
                </span><span class="se">\"</span><span class="s2">short</span><span class="se">\"</span><span class="s2">: true 
        } ],
        </span><span class="se">\"</span><span class="s2">color</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">#f30c00</span><span class="se">\"</span><span class="s2"> 
    }]"</span>
    curl <span class="nt">-X</span> POST <span class="nt">--data-urlencode</span> <span class="se">\</span>
        <span class="s2">"payload={
                </span><span class="se">\"</span><span class="s2">channel</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="nv">$CHANNEL</span><span class="se">\"</span><span class="s2">,
                </span><span class="se">\"</span><span class="s2">mrkdwn</span><span class="se">\"</span><span class="s2">: true, 
                </span><span class="se">\"</span><span class="s2">username</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">SSH Notifications</span><span class="se">\"</span><span class="s2">, 
                </span><span class="nv">$content</span><span class="s2">, 
                </span><span class="se">\"</span><span class="s2">icon_emoji</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">:warning:</span><span class="se">\"</span><span class="s2">}"</span> <span class="se">\</span>
        <span class="s2">"</span><span class="nv">$WEBHOOK_URL</span><span class="s2">"</span> &amp;
<span class="k">fi
</span><span class="nb">exit</span></code></pre>
</figure>

<ul>
  <li>
    <p>You can name the script anything you want and place it anywhere; For this example, I’ve placed it in <code class="language-plaintext highlighter-rouge">/usr/local/sbin/ssh-slack</code></p>
  </li>
  <li>
    <p>Make the script executable.</p>
  </li>
</ul>

<figure class="highlight">
  <pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">chmod</span> +x /usr/local/sbin/ssh-slack</code></pre>
</figure>

<ul>
  <li>One of the modules of PAM - <code class="language-plaintext highlighter-rouge">pam_exec.so</code> helps us trigger the scripts based on various authentication events. We’ll add the path to our script under <code class="language-plaintext highlighter-rouge">/etc/pam.d/sshd</code> which will trigger our script on any ssh authentication-related events.</li>
</ul>

<figure class="highlight">
  <pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">sudo echo</span> <span class="s2">"session   optional   pam_exec.so   /usr/local/sbin/ssh-slack"</span> <span class="o">&gt;&gt;</span> /etc/pam.d/sshd</code></pre>
</figure>

<ul>
  <li>That’s It! You should have the slack alerts working now.</li>
</ul>

<p><br /></p>

<p><strong><code class="language-plaintext highlighter-rouge">Note</code></strong></p>
<ul>
  <li>The process described isn’t limited to ssh authentication-related events; We can configure it to work with other deamons like fail2ban and others to setup alerts or send logs to services on critical events.</li>
</ul>

<p><br /></p>]]></content><author><name></name></author><category term="webhook" /><category term="alerts" /><summary type="html"><![CDATA[If you’re using self-hosted servers, you might have run into this (or similar) blog which covers most of the things you need to do on your first login to the server.]]></summary></entry><entry><title type="html">Accepted for Google Summer of Code</title><link href="https://blog.nishchith.com/acceptance-gsoc/" rel="alternate" type="text/html" title="Accepted for Google Summer of Code" /><published>2019-05-19T04:54:32+00:00</published><updated>2019-05-19T04:54:32+00:00</updated><id>https://blog.nishchith.com/acceptance-gsoc</id><content type="html" xml:base="https://blog.nishchith.com/acceptance-gsoc/"><![CDATA[<p>I got accepted for Google Summer of Code 2019 under <a href="https://github.com/chaoss">CHAOSS</a>: A linux foundation, for the project: “<a href="https://github.com/chaoss/grimoirelab/issues/182">Support of Source Code Related Metrics</a>”. I’ll be working towards adding <a href="https://github.com/chaoss/grimoirelab-graal/">Graal</a> to the GrimoireLab toolchain in order to produce source code related metrics.</p>

<p>My mentors for the project will be: <a href="https://github.com/valeriocos">@valeriocos</a> <a href="https://github.com/jgbarah">@jgbarah</a> <a href="https://github.com/aswanipranjal">@aswanipranjal</a></p>

<h2> <b># What would I be working on? </b> </h2>

<ul>
  <li>I will mainly be focusing on:
    <ul>
      <li>Adding support of source code related metrics to Grimoirelab with the help of analysis data produced by Graal.</li>
      <li>Adapting Grimoirelab toolchain to be able to execute Graal and process the data produced by it.</li>
      <li>Writing appropriate unit tests for additional backends, their corresponding supporting connectors, and methods.</li>
      <li>Producing analytics related to proposed and calculated metrics*.</li>
      <li>Adding documentation related to additional features and improvements in existing ones.</li>
    </ul>
  </li>
</ul>

<h2> <b># What this is all about? </b> </h2>

<ul>
  <li><strong>This</strong> is me learning to manage a project, keeping track of the incremental process of development and documenting the work, which would later on (in the process) help to understand and explain things in a better way to newcomer or a community member.</li>
  <li>Also there will be some of the things that i’ll be learning throughout the process for the first time, will be following some guidelines, some of the best practices, which i’ll try and share.</li>
</ul>

<h2> <b># Community Bonding Period: Meeting </b> </h2>

<p>We had our 1st meeting for the community bonding period on Monday, 13th May 2019 at 14:00 CEST or 17:30 IST ; which was intended to answer the following questions:</p>

<ul>
  <li>
    <h3> <b> How do we keep a track of what’s being worked on? </b> </h3>

    <ul>
      <li>One of my mentors (<a href="https://github.com/aswanipranjal">@aswanipranjal</a>) for the project had shared an extensive list of guidelines (which i found really helpful) which included ideas such as maintaining a project-tracker repository which can work as a lab for experiment and a log for all the things that happens related to the project during the period. I liked the idea and I made one 😛 <a href="https://github.com/inishchith/gsoc-graal">gsoc-graal</a></li>
    </ul>
  </li>
  <li>
    <h3> <b> How do we keep the community aware of the same? </b> </h3>

    <ul>
      <li>
        <p>We have planned to keep all the communication open so that everyone can sync and is free to participate and help us grow! If you have suggestions / comments about anything please do not hesitate to share them with us.</p>
      </li>
      <li>
        <p>We will be discussing about the progress of this project every week at the #grimoirelab channel on Freenode IRC.</p>
      </li>
      <li>
        <p>There will be a weekly report added to the project tracker, which i’ll make sure to also post on the <a href="https://lists.linuxfoundation.org/mailman/listinfo/oss-health-metrics">mailing lists</a> of CHAOSS.</p>
      </li>
    </ul>
  </li>
</ul>

<p><br /></p>

<h2 id="-update-"><b> <code class="language-plaintext highlighter-rouge">Update:</code> </b></h2>
<ul>
  <li>I successfully completed my Google Summer of Code project with CHAOSS on 22nd August 2019</li>
  <li>All the project related information can be found in the <a href="https://github.com/inishchith/gsoc-graal"> project tracker</a>.</li>
</ul>

<p><br /></p>]]></content><author><name></name></author><category term="gsoc" /><summary type="html"><![CDATA[I got accepted for Google Summer of Code 2019 under CHAOSS: A linux foundation, for the project: “Support of Source Code Related Metrics”. I’ll be working towards adding Graal to the GrimoireLab toolchain in order to produce source code related metrics.]]></summary></entry></feed>