Linux Login Update Notifier Script With Python

Introduction Do you ever want to get a notification with the number of updates required when logging into XFCE in debian/ubuntu like systems ? There is a simple python script that can do just that. It uses notify-send command and paired with the magic command that returns the update count, we get the next python script: #!/usr/bin/env python3 import os import subprocess # Run the apt-get command and grep the output command = 'apt-get --simulate upgrade | grep "upgraded.*newly installed"' output = subprocess.getoutput(command) # If there's output, send it as a notification, otherwise send a default message if output: os.system(f'notify-send "Upgrade Check" "{output}"') else: os.system('notify-send "Upgrade Check" "No upgrades available or no packages to be installed."') # Check if the file /var/run/reboot-required exists reboot_file = '/var/run/reboot-required' if os.path.exists(reboot_file): os.system('notify-send "System Update" "Reboot is required to complete updates."') All you need is to make it executable: ...

August 29, 2024 · 2 min · Alex Popescu

Environment variables at build time with Docker

Introduction Do you need a certain environment variable at build time in Docker as opposed to runtime? There is an easy way to achieve this. Use Docker build arguments in combination with environment variables. An example of this is below of a React JS docker build that needs the environment variable REACT_APP_BACKEND_API and build time in the command npm run build. # Declare the build argument in the global scope ARG REACT_APP_BACKEND_API_ARG=TEST # Use an official Node runtime as a parent image FROM node:20-alpine # Set the working directory WORKDIR /app # Copy package.json and package-lock.json COPY package*.json ./ # Install the dependencies RUN npm install # Copy the rest of the application code COPY . . # Consume the build argument in the build stage ARG REACT_APP_BACKEND_API_ARG ENV REACT_APP_BACKEND_API=${REACT_APP_BACKEND_API_ARG} RUN echo $REACT_APP_BACKEND_API # Build the React app # WE need the env variable to be available at BUILD TIME RUN npm run build # Serve the app using serve RUN npm install -g serve # Expose the port the app runs on EXPOSE 3000 # Command to run the app CMD ["serve", "-s", "build", "-l", "3000"] The trick is to declare a build argument REACT_APP_BACKEND_API_ARG, use it in a stage and set the value of the required environment variable (in this case REACT_APP_BACKEND_API_ARG) to the argument value (${REACT_APP_BACKEND_API_ARG}) ...

August 1, 2024 · 2 min · Alex Popescu

Build Go with AIX

Introduction Did you ever wanted to program go in AIX ? Now you can. Installing GoLang on AIX First, add /opt/freeware/bin to the beginning of the current PATH. For example: export PATH=/opt/freeware/bin:$PATH Next install Go on AIX (and increase /opt and /var sizes if needed): chfs -a size=+512M /opt chfs -a size=+260M /var dnf install golang Create a sample program Next, let’s create a sample Go Hello World program: package main import "fmt" func main() { fmt.Println("hello world") } Building and running the program First, lets’s initialize the main module ...

July 19, 2024 · 1 min · Alex Popescu

Ubuntu Desktop with XRDP: A Quick Guide

Introduction Have you ever wanted to install Ubuntu Desktop and configure it with XRDP? Here’s a short guide to get you through it. Step 1: Installing Ubuntu Desktop Let’s start by installing Ubuntu Desktop. Just run this command: sudo apt -y install ubuntu-desktop Grab a coffee while your terminal goes wild with text. It takes some time for the packages to install. Step 2: Installing XRDP Next, install XRDP to allow remote access: ...

June 15, 2024 · 1 min · Alex Popescu

Azure AD Authentication for C# WebAPI with Swagger

Introduction Have you ever wanted to add Azure AD authentication to a C# WebApi project for .NET 8? Now you can. The Code First, let’s create a new WebAPI project: dotnet new webapi --use-controllers Next, add the required package: dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer Next, we need to add the Azure AD settings in appsettings.json: "AzureAd": { "Instance": "https://login.microsoftonline.com/", "TenantId": "yyyy", "ClientId": "xxxxx" } Replace yyyy with the correct TenantId and xxxxx with the correct Azure SPN Client Id. ...

April 23, 2024 · 2 min · Alex Popescu

Automated Fake Database Population with Python

Introduction In this article, we’ll explore a Python script that leverages mimesis library to populate an (Azure) SQL database with fake data. The Code import logging import random import pandas as pd import pymssql import sqlalchemy from dotenv import dotenv_values from mimesis import Address, Datetime, Person from mimesis.enums import Gender from sqlalchemy import create_engine # Load environment variables config = dotenv_values(".env") # Configure logging to both console and file logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s") rootLogger = logging.getLogger() rootLogger.setLevel(logging.INFO) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) rootLogger.addHandler(consoleHandler) def create_rows_mimesis(num=1): gender = random.choice([Gender.FEMALE, Gender.MALE]) output = [{"first_name": person.first_name(gender), "last_name": person.last_name(gender), "address": address.address(), "email": person.email(), "city": address.city(), "state": address.state(), "date_time": datetime.datetime(), "randomdata": random.randint(1000, 2000) } for x in range(num)] return output try: # Create SQLAlchemy engine engine = create_engine(config["CONNECTION_STRING"]) # Connect to the database with engine.connect() as conn: logging.info(f"Connected to database: {engine}") # Initialize mimesis objects person = Person('en') address = Address() datetime = Datetime() num_rows = int(config["ROWS"]) rows_per_batch=int(config["INSERT_LIMIT"]) logging.info(f"Generating {num_rows} rows") if num_rows > rows_per_batch: for i in range(0, num_rows, rows_per_batch): batch_df = pd.DataFrame(create_rows_mimesis(min(1000, num_rows - i))) batch_df.to_sql(config["TABLE_NAME"], engine, method='multi', index=False, if_exists='append') logging.info(f"Inserted {min(1000, num_rows - i)} rows into table: {config['TABLE_NAME']}") else: df = pd.DataFrame(create_rows_mimesis(num_rows)) df.to_sql(config["TABLE_NAME"], engine, method='multi', index=False, if_exists='replace') logging.info(f"Inserted {num_rows} rows into table: {config['TABLE_NAME']}") conn.commit() except Exception as e: logging.error(f"An error occurred: {str(e)}") logging.info("Database connection closed.") The packages needed are: ...

March 17, 2024 · 3 min · Alex Popescu

Install NewRelic on JBoss EAP 7

Introduction This tutorial provides a step-by-step guide on installing NewRelic APM on Jboss EAP 7 in standalone mode Download NewRelic Download the current new relic APM from the website, or using the next powershell command: Invoke-WebRequest -Uri https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip -OutFile newrelic-java.zip Configuring Jboss Create a folder named lib in JBOSS_HOME folder, and a new folder named endorsed in the lib folder. In case you are wondering, the JBOSS_HOME is the folder that has Jboss installed, and the folder with the bin/docs/etc folders. ...

February 22, 2024 · 2 min · Alex Popescu

Securing Quarkus Backend App with IBM App ID

Introduction This tutorial provides a step-by-step guide on securing a Quarkus backend application using IBM App ID. Configure IBM App ID Login to IBM Cloud and create an App ID instance using the lite (free) plan. Then create an application as a regular web app. Next, create a test user using Cloud Directory -> Users menu. Configure Quarkus First, update Maven pom.xml : <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-oidc</artifactId> </dependency> Next, find the client ID/secret/login URL in IBM App id application details: ...

December 30, 2023 · 3 min · Alex Popescu

Using Serilog with Azure Log Stream

Continuing of our previous article here, let’s explore how to show the logs in Azure Log Stream. Integrating Serilog To begin, incorporate Serilog into your project using Visual Studio or the .NET CLI: # Using Visual Studio Install-Package Serilog.AspNetCore # Using .NET CLI dotnet add package Serilog.AspNetCore Configuring Serilog Add the necessary configuration settings in your appsettings.json file, resembling the structure below: "Serilog": { "Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"], "MinimumLevel": "Debug", "WriteTo": [ { "Name": "Console" }, { "Name": "File", "Args": { "path": "Logs/applog-.txt", "rollingInterval": "Day" } } ], "Enrich": ["FromLogContext", "WithMachineName"], "Properties": { "ApplicationName": "Your ASP.NET Core App" } } Deploying Your App to Azure Deploy your application to Azure using the steps outlined in our previous article: ...

December 6, 2023 · 2 min · Alex Popescu

Configuring CTCI Device on Windows with WiFi Adaptor

Have you ever struggled with setting up a CTCI device on Windows 10/11 with a WiFi adapter? Fear not! This guide will walk you through the process using the versatile Microsoft Loopback Adapter. Now you can using Microsoft Loopback Adaptor. Install Microsoft Loopback Adapter Begin by installing the Microsoft Loopback Adapter, also known as the Microsoft KM-TEST Loopback Adapter. You can follow a similar method outlined here Configuring After successful installation, proceed to configure the Loopback adapter with the IP address 192.168.100.1. Simultaneously, set up the CTCI device (aka [REDACTED]) with the IP address 192.168.100.2. ...

November 27, 2023 · 1 min · Alex Popescu