Postări

Se afișează postări din aprilie, 2024

Powershel script notify users with unchanged password

    $servermail="192.168.11.1" [string]$userName = 'dom\user' [string]$userPassword = 'goodpass'  [string]$from = 'user#dom.test' $secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force $credObject = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword) Function SendMail{   param ($credentials , $mailServer,  $from, $to, $subject, $body)   Send-MailMessage" "-To $to -From $from  -Subject $subject -Body $body -SmtpServer  $mailServer  -ErrorAction Stop -Credential $credentials" } #generate list with all users $usrlist = Get-ADUser -Properties PasswordLastSet,Created,whenChanged,msDS-UserPasswordExpiryTimeComputed,lastlogon,EmailAddress,memberOf -Filter * | Select-Object Name,sAMAccountName,ObjectClass,EmailAddress,Enabled,Created,whenChanged,PasswordLastSet,@{Name='LastLogon';Expression={[DateTime]::FromFileTime($_.LastLogon)}},@{N="msDS-UserPasswordExpiryTimeComputed"...

Python poetry

Poetry manage dependency,  virtual environment, versioning  -config file: pyproject.toml -create .venv folder with virtual environment files Commands: #show packages included: poetry show #add depedency poetry add <pkgx> #add a specific version: poetry add requests@2.10.2 #add a version higher then specific version poetry add requests^2.10.2 #add a version higher then specific version but not upper then minor version ( in our case 10) poetry add requests^2.10.2 #remove dependency poetry remove requests #install all dependencies (from pyproject.toml) poetry  install  #if there is no specific root folder: poetry  install  --no-root #enter in virtual environment: poetry shell #increase version number of project: poetry shell (pyproject1) poetry version minor

Python venv

Using venv in python3  sudo apt -y install python3-venv #create virtual environment for python3 python3 -m venv dirvenv #activate virtualenv source dirvenv/bin/activate (dirvenv):> Using virtualenv sudo pip3 install virtualenv mkdir ./virtenvs cd ./virtenvs #create virtualenv virtest1 #activate source ./virtest1/bin/activate (virtest1):>

Convert timestamp column in logs from unix time to date-time

  Convert timestamp column in logs from unix time to date-time: cat logfile.log | awk -F ] '{"cat /proc/uptime | cut -d \" \" -f 1" | getline st;a=substr( $1,2, length($1) - 1);print strftime("%F %H:%M:%S %Z",systime()-st+a)" -> "$0}'
 Grafana dashboard for UPS (Eaton, Riello) {   "annotations": {     "list": [       {         "$$hashKey": "object:35",         "builtIn": 1,         "datasource": {           "type": "datasource",           "uid": "grafana"         },         "enable": true,         "hide": true,         "iconColor": "rgba(0, 211, 255, 1)",         "name": "Annotations & Alerts",         "type": "dashboard"       }     ]   },   "description": "Displays monitoring data collected from Riello uninterruptible power supplies via SNMP.",   "editable": true,   "fiscalYearStartMonth": 0,   "gnetId": 12340,   "graphTooltip": 0,   "id": 10,   "links": [],   "liveNow": false, ...