2021-06-14 08:52:58 +03:00
|
|
|
# utils
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2021-06-24 19:00:59 +03:00
|
|
|
Small tools needed to solve immediate tasks independently or as part of a project
|
|
|
|
|
2024-06-28 00:02:15 +03:00
|
|
|
* [check.business.ru_monitor](/check.business.ru_monitor)
|
2024-06-19 18:39:13 +03:00
|
|
|
* [`build-python`.sh](https://git.hmp.today/pavel.muhortov/utils#build-pythonsh)
|
|
|
|
* [`cert-info`.sh](https://git.hmp.today/pavel.muhortov/utils#cert-infosh)
|
|
|
|
* [`ds18b20-over-ssh`.sh](https://git.hmp.today/pavel.muhortov/utils#ds18b20-over-sshsh)
|
|
|
|
* [`sendmail`.py](https://git.hmp.today/pavel.muhortov/utils#sendmailpy)
|
|
|
|
* [`simplewc`.py](https://git.hmp.today/pavel.muhortov/utils#simplewcpy)
|
2021-06-23 01:10:06 +03:00
|
|
|
|
2021-06-24 18:30:44 +03:00
|
|
|
____
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-03-25 18:17:23 +03:00
|
|
|
## `build-python`.sh
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
> Building Python from sources.
|
|
|
|
|
|
|
|
**Dependencies:**
|
|
|
|
>
|
2023-03-26 15:15:39 +03:00
|
|
|
> * [bash](https://www.gnu.org/software/bash/) (tested versions: 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/), 5.0.17 on [Ubuntu 20](https://wiki.ubuntu.com/FocalFossa/ReleaseNotes), 4.2.46 on [CentOS 7](https://wiki.centos.org/Manuals/ReleaseNotes/CentOS7.2009))
|
2023-03-25 18:17:23 +03:00
|
|
|
|
|
|
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
|
|
|
|-----------|--------------|------------------------|---------------|
|
|
|
|
| 1 |**[qn]**|execution without pauses||
|
|
|
|
| 2 |**[version]**|version of Python|`3.9.5`|
|
|
|
|
| 3 |**[path/to/log]**|path to log|`/dev/null`|
|
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage build-python.sh in terminal with make the script executable`
|
2023-03-25 18:17:23 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/build-python.sh
|
|
|
|
chmod u+x ./build-python.sh
|
2023-03-26 15:15:39 +03:00
|
|
|
sudo ./build-python.sh - 3.9.5
|
|
|
|
```
|
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage build-python.sh in terminal without download`
|
2023-03-26 15:15:39 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo su - -c "bash <(curl -s https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/build-python.sh) qn 3.9.5 install-python.log"
|
2023-03-25 18:17:23 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
____
|
|
|
|
|
2023-08-26 09:23:00 +03:00
|
|
|
## `cert-info`.sh
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
> Get certificate info.
|
|
|
|
|
|
|
|
**Dependencies:**
|
|
|
|
>
|
|
|
|
> * [bash](https://www.gnu.org/software/bash/) (tested versions: 4.2.46 on [CentOS 7](https://wiki.centos.org/Manuals/ReleaseNotes/CentOS7.2009))
|
|
|
|
> * [openssl](https://www.openssl.org/) (tested version 1.0.2k on [CentOS 7](https://wiki.centos.org/Manuals/ReleaseNotes/CentOS7.2009))
|
|
|
|
|
|
|
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
|
|
|
|-----------|--------------|------------------------|---------------|
|
|
|
|
| 1 |**[hostname:port \| /path/to/cert]**|certificate location||
|
|
|
|
| 2 |**[-e]**|print of the expired date timestamp||
|
|
|
|
| 2 |**[-f]**|print of the fingerprint||
|
|
|
|
| 2 |**[-r]**|print of the remaining days||
|
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage cert-info.sh in terminal with make the script executable`
|
2023-08-26 09:23:00 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# download
|
|
|
|
sudo wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/cert-info.sh -O /usr/local/bin/cert-info.sh
|
|
|
|
sudo chmod +x /usr/local/bin/cert-info.sh
|
|
|
|
# check cert
|
|
|
|
cert-info.sh www.hmp.today
|
|
|
|
cert-info.sh /etc/ssl/certs/ca-certificates.crt
|
|
|
|
```
|
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage cert-info.sh in terminal without download`
|
2023-08-26 10:19:45 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
bash <(curl -s https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/cert-info.sh) www.hmp.today
|
|
|
|
bash <(wget -qO- https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/cert-info.sh) www.hmp.today
|
|
|
|
```
|
|
|
|
|
2023-12-13 01:24:40 +03:00
|
|
|
### `Example usage cert-info.sh in Zabbix`
|
2023-08-26 11:28:03 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# download
|
|
|
|
sudo wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/cert-info.sh -O /usr/lib/zabbix/externalscripts/cert-info.sh
|
|
|
|
sudo chmod +x /usr/lib/zabbix/externalscripts/cert-info.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
`Zabbix Server` - `Administration` - `Scripts` - `Create scripts`
|
|
|
|
| PARAMETER | VALUE |
|
|
|
|
|-----------|--------------|
|
|
|
|
|Name |Check SSL certificate|
|
|
|
|
|Scope |Manual host action|
|
|
|
|
|Type |Script|
|
|
|
|
|Execute on |Zabbix server (proxy)|
|
|
|
|
|Commands |/usr/lib/zabbix/externalscripts/cert-info.sh {$URL}|
|
|
|
|
|Description|Load certificate info from {$URL} host macro|
|
|
|
|
|
|
|
|
`Zabbix Server` - `Configuration` - `Hosts` - `"hostname"` - `Macros` - `Add`
|
2023-12-13 01:24:40 +03:00
|
|
|
| MACRO | VALUE |
|
|
|
|
|-------|--------------|
|
|
|
|
|{$URL} |hostname:port |
|
|
|
|
|
|
|
|
`Zabbix Server` - `Monitoring` - `Hosts` - `"hostname"` - `Check SSL certificate`
|
|
|
|
|
|
|
|
____
|
|
|
|
|
|
|
|
## `ds18b20-over-ssh`.sh
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
> Get ds18b20 sensor value.
|
|
|
|
|
|
|
|
**Dependencies:**
|
|
|
|
>
|
|
|
|
> * [bash](https://www.gnu.org/software/bash/) (tested versions: 5.1.16 on [Ubuntu 22.04](https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes))
|
|
|
|
> * [sshpass](https://sourceforge.net/projects/sshpass/) (tested version 1.0.9 on [Ubuntu 22.04](https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes))
|
|
|
|
|
|
|
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
|
|
|
|-----------|--------------|------------------------|---------------|
|
|
|
|
| 1 |**[host]**|ssh host|**REQUIRED**|
|
|
|
|
| 2 |**[port]**|ssh port|**REQUIRED**|
|
|
|
|
| 3 |**[user]**|ssh username|**REQUIRED**|
|
|
|
|
| 4 |**[pass]**|ssh password|**REQUIRED**|
|
|
|
|
| 5 |**[node]**|ds18b20 node|**REQUIRED**|
|
|
|
|
|
|
|
|
### `Example usage ds18b20-over-ssh.sh in terminal with make the script executable`
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# download
|
|
|
|
sudo wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/ds18b20-over-ssh.sh -O /usr/local/bin/ds18b20-over-ssh.sh
|
|
|
|
sudo chmod +x /usr/local/bin/ds18b20-over-ssh.sh
|
|
|
|
# check ds18b20 value
|
|
|
|
ds18b20-over-ssh.sh host.domain.zone 22 root password 28-0a1b2c3d4e5f
|
|
|
|
```
|
|
|
|
|
|
|
|
### `Example usage ds18b20-over-ssh.sh in terminal without download`
|
|
|
|
|
|
|
|
```bash
|
|
|
|
bash <(curl -s https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/ds18b20-over-ssh.sh) host.domain.zone 22 root password 28-0a1b2c3d4e5f
|
|
|
|
bash <(wget -qO- https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/ds18b20-over-ssh.sh) host.domain.zone 22 root password 28-0a1b2c3d4e5f
|
|
|
|
```
|
|
|
|
|
|
|
|
### `Example usage ds18b20-over-ssh.sh in Zabbix`
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# download
|
|
|
|
sudo wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/ds18b20-over-ssh.sh -O /usr/lib/zabbix/externalscripts/ds18b20-over-ssh.sh
|
|
|
|
sudo chmod +x /usr/lib/zabbix/externalscripts/ds18b20-over-ssh.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
`Zabbix Server` - `Administration` - `Scripts` - `Create scripts`
|
2023-08-26 11:28:03 +03:00
|
|
|
| PARAMETER | VALUE |
|
|
|
|
|-----------|--------------|
|
2023-12-13 01:24:40 +03:00
|
|
|
|Name |Check ds18b20 over SSH|
|
|
|
|
|Scope |Manual host action|
|
|
|
|
|Type |Script|
|
|
|
|
|Execute on |Zabbix server (proxy)|
|
|
|
|
|Commands |/usr/lib/zabbix/externalscripts/ds18b20-over-ssh.sh {$HOST} {$PORT} {$USER} {$PASS} {$NODE}|
|
|
|
|
|Description|Get temperature from {$NODE} sensor over SSH|
|
2023-08-26 11:28:03 +03:00
|
|
|
|
2023-12-13 01:24:40 +03:00
|
|
|
`Zabbix Server` - `Configuration` - `Hosts` - `"hostname"` - `Macros` - `Add`
|
|
|
|
| MACRO | VALUE |
|
|
|
|
|-------|-----------------|
|
|
|
|
|{$HOST}|host.domain.zone |
|
|
|
|
|{$PORT}|22 |
|
|
|
|
|{$USER}|root |
|
|
|
|
|{$PASS}|password |
|
|
|
|
|{$NODE}|28-0a1b2c3d4e5f |
|
|
|
|
|
|
|
|
`Zabbix Server` - `Monitoring` - `Hosts` - `"hostname"` - `Check ds18b20 over SSH`
|
2023-08-26 11:28:03 +03:00
|
|
|
|
2023-08-26 09:23:00 +03:00
|
|
|
____
|
|
|
|
|
2021-06-24 19:00:59 +03:00
|
|
|
## `sendmail`.py
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-03-25 18:17:23 +03:00
|
|
|
**Description:**
|
|
|
|
> Sending email from Python.
|
|
|
|
|
|
|
|
**Dependencies:**
|
|
|
|
>
|
|
|
|
> * [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
2021-06-20 15:56:25 +03:00
|
|
|
|
2021-06-15 15:34:01 +03:00
|
|
|
| PARAMETERS | DESCRIPTION | DEFAULT|
|
|
|
|
|-------------|-------------|--------|
|
|
|
|
|**-u**, **--user**|smtp valid user|**REQUIRED**|
|
|
|
|
|**-p**, **--pass**|smtp valid password|**REQUIRED**|
|
|
|
|
|**-d**, **--dest**|destination addresses|**REQUIRED**|
|
|
|
|
|**[-h]**|print help and exit||
|
|
|
|
|**[--smtp]**|smtp hostname or ip address|smtp.gmail.com|
|
|
|
|
|**[--port]**|smtp port number|587|
|
|
|
|
|**[--stls]**|smtp required TLS|`True`|
|
|
|
|
|**[--from]**|mail from alias|**--user** value|
|
|
|
|
|**[--subj]**|mail subject|'no subject'|
|
|
|
|
|**[--text]**|mail body text|'no text'|
|
|
|
|
|**[--type]**|mail body type: plain, html|plain|
|
|
|
|
|**[--file]**|mail attachment files|`None`|
|
2021-12-19 17:52:18 +03:00
|
|
|
|**[--time]**|minutes of attempts to send|3|
|
2021-06-16 20:20:35 +03:00
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage sendmail.py in terminal with make the script executable`
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-03-25 18:17:23 +03:00
|
|
|
```bash
|
2023-05-01 16:50:38 +03:00
|
|
|
# download
|
|
|
|
sudo wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/sendmail.py -O /usr/local/bin/sendmail.py
|
|
|
|
sudo chmod +x /usr/local/bin/sendmail.py
|
2021-06-15 15:34:01 +03:00
|
|
|
```
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-05-01 16:50:38 +03:00
|
|
|
```bash
|
|
|
|
# example 1
|
2023-08-26 10:22:04 +03:00
|
|
|
sendmail.py -u user@gmail.com -p password -d addr1@gmail.com,addr2@gmail.com
|
2023-05-01 16:50:38 +03:00
|
|
|
```
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-03-25 18:17:23 +03:00
|
|
|
```bash
|
2023-05-01 16:50:38 +03:00
|
|
|
# example 2
|
2023-08-26 10:22:04 +03:00
|
|
|
/usr/local/opt/python-3.9/bin/python3.9 /usr/local/bin/sendmail.py -u user@gmail.com -p password -d addr1@gmail.com,addr2@gmail.com --file "/path/to/file1,/path/to/file2"
|
|
|
|
```
|
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage sendmail.py in terminal without download`
|
2023-08-26 10:22:04 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
python3 <(curl -s https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/sendmail.py) \
|
|
|
|
--user user@gmail.com \
|
|
|
|
--pass password \
|
|
|
|
--dest addr1@gmail.com,addr2@gmail.com \
|
|
|
|
--subj "test subject" \
|
|
|
|
--text "test body" \
|
|
|
|
--file "/path/to/file1,/path/to/file2"
|
2021-06-15 15:34:01 +03:00
|
|
|
```
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage sendmail.py in Python`
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2021-06-15 15:34:01 +03:00
|
|
|
```Python
|
|
|
|
from sendmail import Mail
|
|
|
|
|
2023-08-26 10:22:04 +03:00
|
|
|
msg = Mail(smtp_user='user@gmail.com', smtp_pass='password', mail_dest='addr1@gmail.com,addr2@gmail.com')
|
2021-06-15 15:34:01 +03:00
|
|
|
log = msg.send()
|
|
|
|
print(log)
|
2021-06-16 20:20:35 +03:00
|
|
|
```
|
2021-06-20 19:23:02 +03:00
|
|
|
|
2021-06-16 20:20:35 +03:00
|
|
|
____
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2021-07-10 11:06:54 +03:00
|
|
|
## `simplewc`.py
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-03-25 18:17:23 +03:00
|
|
|
**Description:**
|
|
|
|
> Update Let's Encrypt wildcard certificate with DNS-01 challenge.
|
|
|
|
|
|
|
|
**Dependencies:**
|
|
|
|
>
|
|
|
|
> * [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
|
|
|
> * installed or downloaded [acme.sh](https://github.com/Neilpang/acme.sh)
|
|
|
|
> * installed [dnspython](https://github.com/rthalley/dnspython) package
|
|
|
|
> * dns is supported to [dynamic update](https://en.wikipedia.org/wiki/Dynamic_DNS)
|
2021-07-10 11:06:54 +03:00
|
|
|
|
|
|
|
| PARAMETERS | DESCRIPTION | DEFAULT|
|
|
|
|
|-------------|-------------|--------|
|
|
|
|
|**--domain**|domain for which the wildcard certificate is issued|**REQUIRED**|
|
|
|
|
|**--server**|master server containing the domain zone|**REQUIRED**|
|
|
|
|
|**--keyname**|name of the key to update the zone|**REQUIRED**|
|
|
|
|
|**--keydata**|content of the key to update the zone|**REQUIRED**|
|
|
|
|
|**[-h]**|print help and exit||
|
|
|
|
|**[--acmepath]**|alternative path to bin (example: ~/.acme.sh/acme.sh)|`None`|
|
|
|
|
|**[--force]**|"force" argument for the acme.sh|`False`|
|
|
|
|
|**[--test]**|"test" argument for the acme.sh|`False`|
|
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage simplewc.py in cron with Python`
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-03-25 18:17:23 +03:00
|
|
|
```bash
|
2021-07-10 11:06:54 +03:00
|
|
|
# at 00:00 on Monday
|
|
|
|
0 0 * * 1 /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT > /dev/null
|
2022-04-19 16:08:19 +03:00
|
|
|
# 00:00 on day-of-month 1 and 15
|
|
|
|
0 0 1,15 * * /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY > /dev/null
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2021-07-10 11:06:54 +03:00
|
|
|
```
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-08-26 11:37:39 +03:00
|
|
|
### `Example usage simplewc.py in terminal with make the script executable`
|
2023-03-11 23:18:58 +03:00
|
|
|
|
2023-03-25 18:17:23 +03:00
|
|
|
```bash
|
2021-07-10 11:06:54 +03:00
|
|
|
chmod u+x ./simplewc.py
|
|
|
|
./simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT --test --force
|
2022-04-19 16:08:19 +03:00
|
|
|
./simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY --test --force
|
2021-07-10 11:06:54 +03:00
|
|
|
```
|