ovirt-node 2.2.0 release
[ovirt-node.git] / scripts / ovirt-config-snmp
blob9748c4155599f75861d4c0bb4d2f04444c946ff5
1 #!/bin/bash
3 # Configure snmpd
4 . /usr/libexec/ovirt-functions
6 trap '__st=$?; stop_log; exit $__st' 0
7 trap 'exit $?' 1 2 13 15
9 warn() { printf '%s\n' "$*" >&2; }
11 if ! is_local_storage_configured; then
12 warn "Local storage must be configured prior to configuring SNMP."
13 exit 99
16 enable_snmpd() {
17 local password=$1
18 local CONF=/var/lib/net-snmp/snmpd.conf
19 ovirt_store_config /etc/sysconfig/snmpd /var/lib/net-snmp/ >/dev/null
21 service snmpd stop
22 # reset snmpd options to defaults, image has "-v" to prevent snmpd start
23 sed -c -ie '/^OPTIONS/d' /etc/sysconfig/snmpd
24 if [ -e $CONF ]; then
25 sed -c -ie '/^createUser root/d' $CONF
27 echo "createUser root SHA $password AES" >> $CONF
28 service snmpd start
31 disable_snmpd() {
32 service snmpd stop > /dev/null
33 while umount /etc/sysconfig/snmpd; do : ; done 2> /dev/null
34 remove_config /etc/sysconfig/snmpd > /dev/null
37 if [[ "$1" == "AUTO" ]]; then
38 if [ -n "${OVIRT_SNMP_PASSWORD}" ]; then
39 enable_snmpd $OVIRT_SNMP_PASSWORD
41 else
42 ask_yes_or_no "Enable SNMP agent ([Y]es/[N]o/[A]bort)?" true true
43 case $? in
45 while true; do
46 printf "\n"
47 read -p "Enter password for SNMPv3 USM 'root' user: " -esr
48 password1="$REPLY"
49 printf "\n"
50 read -p "Confirm password: " -esr
51 password="$REPLY"
52 if [ "$password1" = "$password" ]; then break; fi
53 done
54 printf "\n"
55 enable_snmpd $password ;;
56 1) disable_snmpd ;;
57 2) ;;
58 esac
59 printf "\n"