Skip to content

Commit

Permalink
Add lldp support (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mib1185 authored Jul 14, 2024
1 parent 8b28838 commit 8a1222d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
run: |
if [[ -z "${{ github.head_ref }}" ]] && [[ "${{ github.event_name }}" == "push" ]]; then
echo "BUILD_ARGS=--docker-hub-check" >> $GITHUB_ENV;
else
echo "BUILD_ARGS=--test" >> $GITHUB_ENV;
fi
- name: Login to DockerHub
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

![example_librenms.png](example_librenms.png)

Additional hass related infomration can be gathered via `NET-SNMP-EXTEND-MIB` - example
Additional hass related information can be gathered via `NET-SNMP-EXTEND-MIB` - example

```shell
$ snmpwalk -v2c -c public my.ha.local NET-SNMP-EXTEND-MIB::nsExtendOutLine | grep hass_
Expand Down
2 changes: 2 additions & 0 deletions snmpd/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ snmp_community: pmnsssah
snmp_name: ha
snmp_location: home
snmp_contact: me
lldp_enabled: false
```
| key | name | description |
Expand All @@ -21,6 +22,7 @@ snmp_contact: me
| `snmp_name` | SNMP system name | An administratively-assigned name for this managed device. By convention, this is the device fully-qualified domain name. |
| `snmp_location` | SNMP location | The physical location of this device |
| `snmp_contact` | SNMP contact | The textual identification of the contact person for this managed device, together with information on how to contact this person. |
| `lldp_enabled` | LLDP | Enable or disable the lldp support. |

## Support

Expand Down
2 changes: 1 addition & 1 deletion snmpd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG BUILD_FROM
FROM $BUILD_FROM

RUN apt-get update \
&& apt-get install -y snmpd \
&& apt-get install -y snmpd lldpd \
&& apt-get clean autoclean \
&& apt-get autoremove -y

Expand Down
4 changes: 3 additions & 1 deletion snmpd/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "SNMPD"
version: "0.3.0"
version: "0.4.0"
slug: "snmpd"
description: "Monitor your HA installation via snmp"
url: "https://github.com/mib1185/ha-addon-snmpd"
Expand All @@ -18,8 +18,10 @@ options:
snmp_name: ha
snmp_location: home
snmp_contact: me
lldp_enabled: false
schema:
snmp_community: str
snmp_name: str
snmp_location: str
snmp_contact: str
lldp_enabled: bool
29 changes: 22 additions & 7 deletions snmpd/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ COMMUNITY=$(bashio::config 'snmp_community')
NAME=$(bashio::config 'snmp_name')
LOCATION=$(bashio::config 'snmp_location')
CONTACT=$(bashio::config 'snmp_contact')
LLDP_ENABLED=$(bashio::config 'lldp_enabled')

HAOS_HOSTNAME=$(bashio::info.hostname)
HAOS_MACHINE=$(bashio::info.machine)
Expand All @@ -16,9 +17,10 @@ UN_KERNEL_RELEASE=$(uname -r)
UN_KERNEL_VERSION=$(uname -v)
UN_MACHINE=$(uname -m)

SNMP_CONF_FILE="/etc/snmp/snmpd.conf"
SNMPD_CONF_FILE="/etc/snmp/snmpd.conf"
LLDPD_CONF_FILE="/etc/lldpd.d/ha.conf"

cat > $SNMP_CONF_FILE <<EOF
cat > $SNMPD_CONF_FILE <<EOF
master agentx
com2sec readonly default $COMMUNITY
Expand All @@ -39,24 +41,37 @@ extend hass_supervisor_version '/usr/bin/bashio /bashio_info.sh supervisor'
extend hass_state '/usr/bin/bashio /bashio_info.sh state'
extend hass_supported '/usr/bin/bashio /bashio_info.sh supported'
#libreNMS distro detection
# libreNMS distro detection
extend distro '/bin/echo $HAOS_OPERATING_SYSTEM'
EOF

if [[ "$UN_MACHINE" == "x86"* ]]; then
cat >> $SNMP_CONF_FILE <<EOF
#libreNMS Hardware Detection
cat >> $SNMPD_CONF_FILE <<EOF
# libreNMS Hardware Detection
extend manufacturer '/bin/cat /sys/devices/virtual/dmi/id/sys_vendor'
extend hardware '/bin/cat /sys/devices/virtual/dmi/id/product_name'
extend serial '/bin/cat /sys/devices/virtual/dmi/id/product_serial'
EOF
elif [[ "$UN_MACHINE" == "arm"* ]] || [[ "$UN_MACHINE" == "aarch64"* ]]; then
cat >> $SNMP_CONF_FILE <<EOF
#libreNMS Hardware Detection
cat >> $SNMPD_CONF_FILE <<EOF
# libreNMS Hardware Detection
extend hardware '/bin/echo $HAOS_MACHINE'
EOF
fi

# write lldpd config
cat > $LLDPD_CONF_FILE <<EOF
configure system hostname $NAME
configure system description "$UN_KERNEL_NAME $HAOS_HOSTNAME $UN_KERNEL_RELEASE $UN_KERNEL_VERSION $UN_MACHINE ($HAOS_OPERATING_SYSTEM)"
configure system interface pattern *,!veth
EOF

# start LLDPd
if [[ "$LLDP_ENABLED" == "true" ]]; then
bashio::log.info "Starting the lldpd daemon..."
lldpd -x
fi

# Run daemon
bashio::log.info "Starting the snmpd daemon..."
snmpd -f -LSwd
3 changes: 3 additions & 0 deletions snmpd/translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ configuration:
snmp_contact:
name: Kontakt
description: Die textliche Identifikation der Kontaktperson für dieses Gerät, zusammen mit Informationen darüber, wie man diese Person kontaktieren kann.
lldp_enabled:
name: LLDP
description: Aktivieren oder deaktivieren der LLDP Unterstützung.
3 changes: 3 additions & 0 deletions snmpd/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ configuration:
snmp_contact:
name: Contact
description: The textual identification of the contact person for this managed device, together with information on how to contact this person.
lldp_enabled:
name: LLDP
description: Enable or disable the lldp support.

0 comments on commit 8a1222d

Please sign in to comment.