miércoles, 27 de noviembre de 2024

Create a database with MongoDB

Connect to mongodb

root@mongo:/home/mongo# mongosh "mongodb://admin:adminpassword@localhost:27017"


Create the database, just command use

test> use analytics
switched to db analytics

 

Create the collection
analytics> db.createCollection("traffic"); 

 

Insert one record on the collection

analytics> db.traffic.insertOne({ message: "Analytics database initialized", timestamp: new Date() })


Use admin database

analytics> use admin
switched to db admin

 

Create a user on the database admin
admin> db.createUser({ user: "userName", pwd: "passwdthatyouwant", roles: [{ role: "readWrite", db: "DBthatyouwant" }] });
{ ok: 1 }

jueves, 21 de noviembre de 2024

Azure VM Standard BS1 mods, swap and lvm

 The azure Azure VM Standard BS1 has 65GB of hard disk for the operative system. But there is an issue with redhat running on 1GB, it crashes, and the other one is that lvm doesn't leverage the space.

The solution create a swap and extend the lvm!

 

Creation of swap

fallocate -l 3G /swap-file
chmod 600 /swap-file
mkswap /swap-file
swapon /swap-file
swapon --show
cp /etc/fstab /etc/fstab.bak
echo '/swap-file none swap sw 0 0' | sudo tee -a /etc/fstab

 

Check the lsblk and extend the partition

lsblk

lvextend --size +10GB --resizefs /dev/rootvg/rootlv

df -h

lunes, 18 de noviembre de 2024

Rsyslog with high resolution timestamp

 

By default, rsyslog uses traditional timestamp, which in date command's format would be:

%b %d %H:%M:%S

This is enabled by the following line in /etc/rsyslog.conf:

$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat 

To enable high precision timestamping, comment out the line:

# $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat 

which will make rsyslog timestamping in the RFC 3339 format.

rsyslog

 global(
  workDirectory="/var/spool/rsyslog"
)

# Load the imfile module to read logs from a file
module(load="imtcp" MaxSessions="500")
input(type="imtcp" port="514")

template(name="probe-request" type="list" option.jsonf="on") {
         property(outname="@timestamp" name="timereported" dateFormat="rfc3339" format="jsonf")
         property(outname="host" name="hostname" format="jsonf")
         property(outname="sourceaddress" name="msg" regex.type="ERE" regex.submatch="1" regex.expression="SA:([^[:space:]]*)" regex.nomatchmode="BLANK" format="jsonf")
         property(outname="signal" name="msg" field.number="10" field.delimiter="32" format="jsonf" onEmpty="null")
         property(outname="wifi" name="msg" regex.type="ERE" regex.submatch="1" regex.expression="Probe Request \\((.*?)\\)" regex.nomatchmode="BLANK" format="jsonf")
}

template(name="roamed" type="list" option.jsonf="on") {
         property(outname="@timestamp" name="timereported" dateFormat="rfc3339" format="jsonf")
         property(outname="host" name="hostname" format="jsonf")
         property(outname="sourceaddress" name="msg" field.number="18" field.delimiter="32" format="jsonf" onEmpty="null")
         property(outname="signal" name="msg" field.number="10" field.delimiter="32" format="jsonf" onEmpty="null")
         property(outname="wifi" name="msg" field.number="21" field.delimiter="32" format="jsonf")
}


# Send logs with the specified tag to the console
if $msg contains 'Probe Request (' then {
        action(type="omfile" file="/var/log/syslogs/unifi-probe.log" template="probe-request")
}

if $msg contains 'roamed' then {
        action(type="omfile" file="/var/log/syslogs/unifi-roamed.log" template="roamed")
}

Use pip in a virtual environment

 

If you haven't yet learned a tool to set up a virtual environment, I highly recommend it. All Python programmers should learn one. I recommend venv or virtualenv to beginners. To install venv, run:

sudo apt install python3-venv

Then create a virtual environment in your project directory like this:

 python3 -m venv .venv

Now activate your virtual environment by running:

 source .venv/bin/activate

This modifies your PATH environment variable to include .venv/bin/. Now you can install PyPI packages using pip into your virtual envirnoment (in this case .venv/), like this:

pip install requests

If you don't want to activate and deactivate virtual environments, you can run pip and python directly from the virtual environment, like this:

$ .venv/bin/pip install requests
$ .venv/bin/python
>>> import requests
>>> 
 
 https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3

sábado, 16 de noviembre de 2024

Razr Kiyo on Ubuntu

 Woow I am very happy with this camera. 

Cámara web Razer Kiyo Full HD 30FPS color negro 

 

It worked as soon I connected. The only issue was the zoom. So, I should run a couple of commands, you can crop the video with these:

sudo apt-get install v4l-utils

 

List the devices:

alejandro@minipc:~$ v4l2-ctl --list-devices
Razer Kiyo (usb-0000:00:14.0-3):
    /dev/video0
    /dev/video1
    /dev/media0
 

See for the options of the device video0

alejandro@minipc:~$ v4l2-ctl -d /dev/video0 --list-ctrls

User Controls

                     brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                       contrast 0x00980901 (int)    : min=0 max=255 step=1 default=128 value=128
                     saturation 0x00980902 (int)    : min=0 max=255 step=1 default=128 value=128
        white_balance_automatic 0x0098090c (bool)   : default=1 value=1
                           gain 0x00980913 (int)    : min=0 max=255 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=2 value=1 (50 Hz)
      white_balance_temperature 0x0098091a (int)    : min=2000 max=7500 step=10 default=4000 value=5630 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=255 step=1 default=128 value=128
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=3 (Aperture Priority Mode)
         exposure_time_absolute 0x009a0902 (int)    : min=3 max=2047 step=1 default=127 value=156 flags=inactive
     exposure_dynamic_framerate 0x009a0903 (bool)   : default=0 value=1
                   pan_absolute 0x009a0908 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute 0x009a0909 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute 0x009a090a (int)    : min=0 max=255 step=1 default=0 value=83
     focus_automatic_continuous 0x009a090c (bool)   : default=1 value=0
                  zoom_absolute 0x009a090d (int)    : min=100 max=140 step=10 default=100 value=130
 

 The zoom_absolute value is 130, with 100 will be the minimum!

alejandro@minipc:~$ v4l2-ctl -d /dev/video0 -c zoom_absolute=100 


Now much better!