<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wajahat Ali Abid</title>
    <description>The latest articles on DEV Community by Wajahat Ali Abid (@wajahataliabid).</description>
    <link>https://dev.to/wajahataliabid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F197406%2Ff70359f9-e9e0-41ce-b40d-8bd556ee1c19.jpg</url>
      <title>DEV Community: Wajahat Ali Abid</title>
      <link>https://dev.to/wajahataliabid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wajahataliabid"/>
    <language>en</language>
    <item>
      <title>bash: No such file or directory</title>
      <dc:creator>Wajahat Ali Abid</dc:creator>
      <pubDate>Sat, 30 Mar 2024 18:43:03 +0000</pubDate>
      <link>https://dev.to/wajahataliabid/bash-no-such-file-or-directory-n83</link>
      <guid>https://dev.to/wajahataliabid/bash-no-such-file-or-directory-n83</guid>
      <description>&lt;p&gt;I am using KDE Neon as my daily driver on my laptop. Recently due to KDE Neon update 6.0, there have been many bugs, but one as annoying as the one I faced the other day.&lt;/p&gt;

&lt;p&gt;After system update, my bash stopped working completely. Granted I use zsh as my shell, bash is required by many programs on Linux. But everytime, I opened any such program, say pyenv, it just wouldn't work and give following error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/bin/env: ‘bash’: No such file or directory linux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I looked into /usr/bin and couldn't find bash there. I couldn't install bash using dpkg or apt. This was pretty perplexing for me. Here is how I resolved the error with bash. &lt;/p&gt;

&lt;p&gt;First of all, I edited the file /var/lib/dpkg/info/bash.prerm and changed first line to &lt;code&gt;#! /bin/sh&lt;/code&gt; from &lt;code&gt;#! /bin/bash&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#! /bin/sh
set -e  

case "$1" in  
   upgrade)  
       update-alternatives --remove builtins.7.gz \  
           /usr/share/man/man7/bash-builtins.7.gz  
       ;;  

   remove|deconfigure)  
       ;;  

   failed-upgrade)  
       ;;  
   *)  
       echo "prerm called with unknown argument \`$1'" &amp;gt;&amp;amp;2  
       exit 1  
       ;;  
esac
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next I looked into /var/cache/apt/archives/ and found the file &lt;code&gt;bash_5.1-6ubuntu1.1_amd64.deb&lt;/code&gt;. If you cannot find this file, you can download from &lt;a href="https://ubuntu.pkgs.org/22.04/ubuntu-main-amd64/bash_5.1-6ubuntu1_amd64.deb.html"&gt;here&lt;/a&gt;&lt;br&gt;
Next I ran the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo dpkg --force-remove-reinstreq -i /var/cache/apt/archives/bash_5.1-6ubuntu1.1_amd64.deb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helped me restore the bash and helped me run programs again. &lt;/p&gt;

</description>
      <category>linux</category>
      <category>kde</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Stream Windows Event Logs to Cloudwatch</title>
      <dc:creator>Wajahat Ali Abid</dc:creator>
      <pubDate>Mon, 04 Mar 2024 19:29:18 +0000</pubDate>
      <link>https://dev.to/wajahataliabid/stream-windows-event-logs-to-cloudwatch-4681</link>
      <guid>https://dev.to/wajahataliabid/stream-windows-event-logs-to-cloudwatch-4681</guid>
      <description>&lt;p&gt;I received a requirement for sending Windows event logs to Amazon Cloudwatch because we wanted to monitor user activity on various Windows servers in our environment. There can be various other use cases for this requirement, however we will focus on setting up Windows event logs to Cloudwatch in this article.&lt;/p&gt;

&lt;p&gt;To achieve this, we first need to install Amazon Cloudwatch Agent and then configure the server to push logs to Cloudwatch Logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Cloudwatch Agent
&lt;/h2&gt;

&lt;p&gt;There are a couple of ways you can install Amazon Cloudwatch Agent on your servers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/installing-cloudwatch-agent-commandline.html" rel="noopener noreferrer"&gt;Using the CLI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/installing-cloudwatch-agent-ssm.html" rel="noopener noreferrer"&gt;Using AWS Systems Manager&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0l9r6vv2zc1rn0rok19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0l9r6vv2zc1rn0rok19.png" alt="Windows Services app showing Cloudwatch Agent running"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Iam Role
&lt;/h2&gt;

&lt;p&gt;Create a policy &lt;code&gt;CloudwatchAgentPolicyForWindowsLogging&lt;/code&gt;  with following body&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "CloudwatchLogsStatement",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:DescribeLogStreams"
            ],
            "Resource": [
                "arn:aws:logs:us-west-2:123456789012:log-group:windows-event-viewer-logs",
                "arn:aws:logs:us-west-2:123456789012:log-group:windows-event-viewer-logs:log-stream:*"
            ]
        }
    ]
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Attach this policy to any server you want to enable Cloudwatch Logs on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Cloudwatch Agent
&lt;/h2&gt;

&lt;p&gt;Go to &lt;code&gt;C:\Program Files\Amazon\AmazonCloudWatchAgent&lt;/code&gt; and create a file config.json&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsiclgrdf2o119xj3l8ik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsiclgrdf2o119xj3l8ik.png" alt="Required directory open showing config.json file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add logs section to Amazon Cloudwatch Agent configuration file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{ 
    ...,
    "logs": {
        "logs_collected": {
            "windows_events": {
                "collect_list": [
                    {
                        "event_format": "xml",
                        "event_levels": [
                            "VERBOSE",
                            "INFORMATION",
                            "WARNING",
                            "ERROR",
                            "CRITICAL"
                        ],
                        "event_name": "System",
                        "log_group_name": "windows-event-viewer-logs",
                        "log_stream_name": "{instance_id}/System",
                        "retention_in_days": 365
                    },
                    {
                        "event_format": "xml",
                        "event_levels": [
                            "VERBOSE",
                            "INFORMATION",
                            "WARNING",
                            "ERROR",
                            "CRITICAL"
                        ],
                        "event_name": "Security",
                        "log_group_name": "windows-event-viewer-logs",
                        "log_stream_name": "{instance_id}/Security",
                        "retention_in_days": 365
                    }
                ]
            }
        }
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Open Powershell and run the following command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; cd 'C:/Program Files/Amazon/AmazonCloudWatchAgent/'
&amp;gt; ./amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c file:config.json -s


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxhgavbnxt8ebgksh7iwl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxhgavbnxt8ebgksh7iwl.png" alt="Showing output of above command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start the Amazon Cloudwatch Agent Service and after some time, you'll see log stream created in the log group &lt;code&gt;windows-event-viewer-logs&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify
&lt;/h2&gt;

&lt;p&gt;Open Cloudwatch Logs and open the log group &lt;code&gt;windows-event-viewer-logs&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ipultxtvov0eowb7vpo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ipultxtvov0eowb7vpo.png" alt="CloudWatch log group windows-event-viewer-logs"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>cloudwatch</category>
      <category>logging</category>
    </item>
    <item>
      <title>Enable ContainerLogV2 on AKS</title>
      <dc:creator>Wajahat Ali Abid</dc:creator>
      <pubDate>Wed, 28 Feb 2024 22:09:43 +0000</pubDate>
      <link>https://dev.to/wajahataliabid/enable-containerlogv2-on-aks-28d6</link>
      <guid>https://dev.to/wajahataliabid/enable-containerlogv2-on-aks-28d6</guid>
      <description>&lt;p&gt;ContainerLogV2 provides additional data over ContainerLog (which is v1). The additional data includes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ContainerName&lt;/li&gt;
&lt;li&gt;PodName&lt;/li&gt;
&lt;li&gt;PodNamespace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To enable ContainerLogV2 on an existing AKS cluster, you need to create a configmap. Here's how you do this&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download the &lt;a href="https://aka.ms/container-azm-ms-agentconfig"&gt;template ConfigMap YAML file&lt;/a&gt; for ContainerLog&lt;/li&gt;
&lt;li&gt;Set containerlog_schema_version = "v2" in the yaml file&lt;/li&gt;
&lt;li&gt;Update the exclude_namespaces under &lt;code&gt;log_collection_settings.stdout&lt;/code&gt; and &lt;code&gt;log_collection_settings.stderr&lt;/code&gt; as per your use case&lt;/li&gt;
&lt;li&gt;Save the changes&lt;/li&gt;
&lt;li&gt;Connect to Kubernetes cluster using CLI
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectx my-cluster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run the following command to create the configmap.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f container-azm-ms-agentconfig.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Done&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this helps. Refer to &lt;a href="https://learn.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-logs-schema"&gt;Container insights log schema&lt;/a&gt; and &lt;a href="https://learn.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-data-collection-configmap"&gt;Configure data collection in Container insights using ConfigMap&lt;/a&gt; for more insights.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>aks</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Yet another implementation for Slack Commands</title>
      <dc:creator>Wajahat Ali Abid</dc:creator>
      <pubDate>Mon, 19 Sep 2022 13:27:48 +0000</pubDate>
      <link>https://dev.to/wajahataliabid/yet-another-implementation-for-slack-commands-4bmd</link>
      <guid>https://dev.to/wajahataliabid/yet-another-implementation-for-slack-commands-4bmd</guid>
      <description>&lt;p&gt;We're using slack for communication within our team. Using slack slash commands, we also handle common day-to-day tasks like triggering deployments on different servers based on requirements. For a long time, that remained our primary use case, so we had a single AWS Lambda function taking care of this job, however, with the growing team and business, we felt the need to handle several other tasks this way. Thus we created a few more lambda functions that handled different tasks but the behavior among different lambda functions wasn't consistent, since every lambda was maintained separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  General Idea
&lt;/h2&gt;

&lt;p&gt;We decided to create a single lambda function that will be solely used for handling all the slash command requirements. The commands will follow a similar structure as normal shell commands do. Some examples are as follows&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;help&lt;/td&gt;
&lt;td&gt;List down all the slash commands with usage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;help deploy&lt;/td&gt;
&lt;td&gt;List down help text for deploy commands, including all the options it takes and flags&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;deploy&lt;/td&gt;
&lt;td&gt;Deploy for a specific client&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Some examples of slack slash commands are as follows (assuming our slash command is /example)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/example help
/example help deploy
/example help deploy --client test-client --branch master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can limit users who can issue a command as well as channels where the command can be issued from by using a very simple configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"deploy"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"users"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"example.user"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"channels"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"channel_id"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;We implemented this solution in python with the help of some useful packages from the open source community. Some of these packages are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://fastapi.tiangolo.com/" rel="noopener noreferrer"&gt;Fast Api&lt;/a&gt;: For the implementation of the APIs&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://mangum.io/" rel="noopener noreferrer"&gt;Mangum&lt;/a&gt;: For the integration of the Aws Lambda and the Api Gateway with the FastApi &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://python-jenkins.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;Python Jenkins&lt;/a&gt;: For interacting with the Jenkins server that handles deployments&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.python.org/3/library/argparse.html" rel="noopener noreferrer"&gt;Argparse&lt;/a&gt;: For handling argument parsing &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The way our implementation worked was as follows&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The User sends a command via slack&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Lambda function verifies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the command exists&lt;/li&gt;
&lt;li&gt;If the user is allowed to run the command&lt;/li&gt;
&lt;li&gt;If the command is allowed to be run from the specified channel&lt;/li&gt;
&lt;li&gt;If the command has all the required parameters&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;and responds appropriately&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Execute the command and send the response back to the slack channel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offload the long running commands to the Ecs container (e.g, database backup or restore)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The general architecture of this solution is as follows&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rczuzsg7f1cbaz0p22f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rczuzsg7f1cbaz0p22f.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This helps us implement new slack commands really quickly. All the error handling is similar across the different commands, so we don't need to handle the errors separately for every new command.&lt;/p&gt;

</description>
      <category>python</category>
      <category>devops</category>
      <category>api</category>
    </item>
  </channel>
</rss>
