added ds18b20-over-ssh.sh
This commit is contained in:
parent
c2096f5205
commit
37699c6427
78
README.md
78
README.md
|
@ -4,6 +4,7 @@ Small tools needed to solve immediate tasks independently or as part of a projec
|
|||
|
||||
* [`build-python`.sh](https://git.hmp.today/pavel.muhortov/utils#build-python-sh)
|
||||
* [`cert-info`.sh](https://git.hmp.today/pavel.muhortov/utils#cert-info-sh)
|
||||
* [`ds18b20-over-ssh`.sh](https://git.hmp.today/pavel.muhortov/utils#ds18b20-over-ssh-sh)
|
||||
* [`sendmail`.py](https://git.hmp.today/pavel.muhortov/utils#sendmail-py)
|
||||
* [`simplewc`.py](https://git.hmp.today/pavel.muhortov/utils#simplewc-py)
|
||||
|
||||
|
@ -75,7 +76,7 @@ bash <(curl -s https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/cert
|
|||
bash <(wget -qO- https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/cert-info.sh) www.hmp.today
|
||||
```
|
||||
|
||||
### `Example usage in Zabbix`
|
||||
### `Example usage cert-info.sh in Zabbix`
|
||||
|
||||
```bash
|
||||
# download
|
||||
|
@ -92,19 +93,82 @@ sudo chmod +x /usr/lib/zabbix/externalscripts/cert-info.sh
|
|||
|Execute on |Zabbix server (proxy)|
|
||||
|Commands |/usr/lib/zabbix/externalscripts/cert-info.sh {$URL}|
|
||||
|Description|Load certificate info from {$URL} host macro|
|
||||
`Add`
|
||||
|
||||
`Zabbix Server` - `Configuration` - `Hosts` - `"hostname"` - `Macros` - `Add`
|
||||
| PARAMETER | VALUE |
|
||||
|-----------|--------------|
|
||||
|Macro |{$URL}|
|
||||
|Value |hostname:port|
|
||||
`Update`
|
||||
| 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`
|
||||
| PARAMETER | VALUE |
|
||||
|-----------|--------------|
|
||||
|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|
|
||||
|
||||
`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`
|
||||
|
||||
____
|
||||
|
||||
## `sendmail`.py
|
||||
|
||||
**Description:**
|
||||
|
|
61
ds18b20-over-ssh.sh
Normal file
61
ds18b20-over-ssh.sh
Normal file
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# DESCRIPTION:
|
||||
# get ds18b20 sensor value
|
||||
#
|
||||
# DEPENDENCIES:
|
||||
# - sshpass
|
||||
#
|
||||
# PARAMETERS:
|
||||
# 1: ssh host
|
||||
# 2: ssh port
|
||||
# 3: ssh username
|
||||
# 4: ssh password
|
||||
# 5: ds18b20 node
|
||||
#
|
||||
# FUNCTIONS:
|
||||
#
|
||||
#
|
||||
# VARIABLES:
|
||||
#
|
||||
|
||||
if [ -z "${1}" ] || \
|
||||
[ -z "${2}" ] || \
|
||||
[ -z "${3}" ] || \
|
||||
[ -z "${4}" ] || \
|
||||
[ -z "${5}" ]; then
|
||||
printf "%s\n" \
|
||||
"Usage example: ${0} 'host' 'port' 'username' 'password' 'node'"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v sshpass &> /dev/null; then
|
||||
printf "%s\n" "Not found dependencies"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
host=${1}
|
||||
port=${2}
|
||||
user=${3}
|
||||
pass=${4}
|
||||
node=${5}
|
||||
|
||||
#
|
||||
# MAIN:
|
||||
#
|
||||
|
||||
temp=$(sshpass -p "${pass}" ssh "${user}@${host}" -p "${port}" \
|
||||
-o "StrictHostKeyChecking=no" \
|
||||
-o "UserKnownHostsFile=/dev/null" \
|
||||
-o "LogLevel=ERROR" \
|
||||
"cat /sys/bus/w1/devices/${node}/temperature"
|
||||
)
|
||||
if [ "${temp}" -lt 0 ]; then
|
||||
printf "%s\n" "$(("${temp}" / 1000)).$((-1 * "${temp}" % 1000))"
|
||||
else
|
||||
printf "%s\n" "$(("${temp}" / 1000)).$(("${temp}" % 1000))"
|
||||
fi
|
||||
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user