Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to choose position of unique id in device name #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sysmon.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ HASS_MQTT_PREFIX="homeassistant"
MQTT_PUB_PATH="/home/servers"
MQTT_PUBLISH_PERIOD=15

# Choos wether the unique machine ID should be at the end or beginning of the device name. Options: 0 = beginning (default), 1 = end.
POSITION_UNIQUE_ID=0

# name of network interface (e.g. eth0) otherwise first active one will be used
NETWORK_IFACE=""

Expand Down
12 changes: 9 additions & 3 deletions sysmon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ HASS_MQTT_PREFIX="homeassistant"
MQTT_PUB_PATH="/home/servers"
MQTT_PUBLISH_PERIOD=20

# Choos wether the unique machine ID should be at the end or beginning of the device name. Options: 0 = beginning (default), 1 = end.
POSITION_UNIQUE_ID=0

# name of network interface (e.g. eth0) otherwise first active one will be used
NETWORK_IFACE=""

Expand Down Expand Up @@ -517,11 +520,15 @@ start() {
exit 1
fi

DEVICE_NAME="$MAC_ID-$(cat /proc/sys/kernel/hostname)"
if [ "$POSITION_UNIQUE_ID" = "1" ]; then
DEVICE_NAME="$(cat /proc/sys/kernel/hostname)-$MAC_ID"
else
DEVICE_NAME="$MAC_ID-$(cat /proc/sys/kernel/hostname)"
fi
STATE_TOPIC="$MQTT_PUB_PATH/$DEVICE_NAME/state"

info "using device name: $DEVICE_NAME"

setup
publish_discovery_all

Expand All @@ -542,4 +549,3 @@ else
fi

start