aten_pdu: First version of role
This commit is contained in:
parent
2b8b9f69f7
commit
211e04ae99
4 changed files with 5153 additions and 0 deletions
5065
roles/aten_pdu/files/ATEN-PE-CFG_str_1.3.128.mib
Normal file
5065
roles/aten_pdu/files/ATEN-PE-CFG_str_1.3.128.mib
Normal file
File diff suppressed because it is too large
Load diff
54
roles/aten_pdu/files/aten-mqtt-publish.sh
Normal file
54
roles/aten_pdu/files/aten-mqtt-publish.sh
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
umask 077
|
||||
|
||||
community="public"
|
||||
|
||||
mqtt_send() {
|
||||
topic="$1"
|
||||
value="$2"
|
||||
|
||||
tlsdir="$(openssl version -d | sed -e 's/^OPENSSLDIR: "\(.\+\)"$/\1/')"
|
||||
mosquitto_pub -h mqtt02.home.foo.sh -t "$topic" -m "$value" \
|
||||
--cafile "${tlsdir}/certs/ca.crt" \
|
||||
--key "${tlsdir}/private/$(hostname -f).key" \
|
||||
--cert "${tlsdir}/certs/$(hostname -f).crt"
|
||||
}
|
||||
|
||||
snmp_get() {
|
||||
host="$1"
|
||||
key="$2"
|
||||
snmpget -v 1 -c "$community" "$host" -Oqv -m ATEN-PE-CFG "$key" | tr -d '"'
|
||||
}
|
||||
|
||||
# only run script if first vrrp interface is in master state
|
||||
for state in /run/keepalived/*.state ; do
|
||||
if [ "$(cat "$state")" != "MASTER" ]; then
|
||||
exit 0
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
ldapsearch -Q -LLL "(&(objectClass=device)(description=Aten PE*))" cn | \
|
||||
awk '{ if ($1 == "cn:") print $2 }' | while read -r name
|
||||
do
|
||||
location="$(snmp_get "$name" RFC1213-MIB::sysLocation.0 | \
|
||||
tr '[:upper:]' '[:lower:]' | tr ' ' '_')"
|
||||
snmpwalk -v 1 -c "$community" "$name" -Oq \
|
||||
-m ATEN-PE-CFG ATEN-PE-CFG::outletName | while read -r port device
|
||||
do
|
||||
port="$(echo "$port" | cut -d '.' -f 2)"
|
||||
device="$(echo "$device" | tr -d '"')"
|
||||
case "$device" in
|
||||
"N/A"|"00 "|"unused")
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
for key in Current Power Voltage ; do
|
||||
topic="home/${location}/${device}/$(echo "$key" | tr '[:upper:]' '[:lower:]')"
|
||||
value="$(snmp_get "$name" "ATEN-PE-CFG::outlet${key}.${port}")"
|
||||
mqtt_send "$topic" "$value"
|
||||
done
|
||||
done
|
||||
done
|
3
roles/aten_pdu/meta/main.yml
Normal file
3
roles/aten_pdu/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
dependencies:
|
||||
- {role: ldap}
|
31
roles/aten_pdu/tasks/main.yml
Normal file
31
roles/aten_pdu/tasks/main.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
- name: Install packages
|
||||
ansible.builtin.package:
|
||||
name: "{{ item }}"
|
||||
state: installed
|
||||
with_items:
|
||||
- mosquitto
|
||||
- net-snmp-utils
|
||||
|
||||
# https://www.aten.com/eu/en/products/power-distribution-&-racks/rack-pdu/pe8108/
|
||||
- name: Install custom mib
|
||||
ansible.builtin.copy:
|
||||
dest: /usr/share/snmp/mibs/ATEN-PE-CFG.txt
|
||||
src: ATEN-PE-CFG_str_1.3.128.mib
|
||||
mode: "0644"
|
||||
owner: root
|
||||
group: "{{ ansible_wheel }}"
|
||||
|
||||
- name: Install mqtt publish script
|
||||
ansible.builtin.copy:
|
||||
dest: /usr/local/bin/aten-mqtt-publish
|
||||
src: aten-mqtt-publish.sh
|
||||
mode: "0755"
|
||||
owner: root
|
||||
group: "{{ ansible_wheel }}"
|
||||
|
||||
- name: Add mqtt publish cron job
|
||||
ansible.builtin.cron:
|
||||
name: aten-mqtt-publish
|
||||
job: /usr/local/bin/aten-mqtt-publish
|
||||
minute: "*/5"
|
Loading…
Add table
Add a link
Reference in a new issue