Node-Red configuration
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

snmp-test.sh 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/bash
  2. # snmp-test.sh - run snmp tests
  3. # Usage: snmp-test.sh [ -6 ] [ -e <engineId> ] [ -h host ] [ -l v1 | v2c | noauthnopriv | authnopriv | authpriv ] [ -p ]
  4. HOME_DIR=.
  5. HOST=localhost
  6. LEVEL=authpriv
  7. PRINT_ONLY=0
  8. TRAP_ENGINEID="010203040a"
  9. IPV6=0
  10. CMDS=/var/tmp/snmp-test.$$
  11. # Auth parameters - change as necessary
  12. RO_COMMUNITY=public
  13. RW_COMMUNITY=private
  14. USER_NONE=fred
  15. USER_AUTH=betty
  16. USER_PRIV=barney
  17. USER_TRAP_NONE=fred
  18. USER_TRAP_AUTH=betty
  19. USER_TRAP_PRIV=wilma
  20. USER_SET_NONE=trapnone
  21. USER_SET_AUTH=trapshaonly
  22. USER_SET_PRIV=trapshades
  23. AUTH_PROTOCOL=sha
  24. AUTH_KEY=illhavesomeauth
  25. PRIV_PROTOCOL=aes
  26. PRIV_KEY=andsomepriv
  27. usage() {
  28. echo "Usage: $0 [ -6 ] [ -e <engineId> ] [ -h <host> ] [ -l v1 | v2c | noauthnopriv | authnopriv | authpriv ] [ -p ]"
  29. echo
  30. echo "Options:"
  31. echo " -6 use IPv6"
  32. echo " -e <engineId> local snmpEngineID - used for traps only"
  33. echo " -h print usage message"
  34. echo " -l <level> v1 | v2c | noauthnopriv | authnopriv | authpriv"
  35. echo " -p print commands but do not run them"
  36. echo " -t <host> target host"
  37. exit 1
  38. }
  39. get_auth_parameters() {
  40. LEVEL=$1
  41. if [[ ${LEVEL} == "v1" ]] ; then
  42. PARAMS="-v 1 -c ${RO_COMMUNITY}"
  43. TRAP_PARAMS="-v 1 -c ${RO_COMMUNITY}"
  44. SET_PARAMS="-v 1 -c ${RW_COMMUNITY}"
  45. elif [[ ${LEVEL} == "v2c" ]] ; then
  46. PARAMS="-v 2c -c ${RO_COMMUNITY}"
  47. TRAP_PARAMS="-v 2c -c ${RO_COMMUNITY}"
  48. SET_PARAMS="-v 2c -c ${RW_COMMUNITY}"
  49. elif [[ ${LEVEL} == "noauthnopriv" ]] ; then
  50. PARAMS="-v 3 -u ${USER_NONE} -l noAuthNoPriv"
  51. TRAP_PARAMS="-v 3 -u ${USER_TRAP_NONE} -l noAuthNoPriv"
  52. SET_PARAMS="-v 3 -u ${USER_NONE} -l noAuthNoPriv"
  53. elif [[ ${LEVEL} == "authnopriv" ]] ; then
  54. PARAMS="-v 3 -u ${USER_AUTH} -l authNoPriv -a ${AUTH_PROTOCOL} -A ${AUTH_KEY}"
  55. TRAP_PARAMS="-v 3 -u ${USER_TRAP_AUTH} -l authNoPriv -a ${AUTH_PROTOCOL} -A ${AUTH_KEY}"
  56. SET_PARAMS="-v 3 -u ${USER_AUTH} -l authNoPriv -a ${AUTH_PROTOCOL} -A ${AUTH_KEY}"
  57. elif [[ ${LEVEL} == "authpriv" ]] ; then
  58. PARAMS="-v 3 -u ${USER_PRIV} -l authPriv -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} -x ${PRIV_PROTOCOL} -X ${PRIV_KEY}"
  59. TRAP_PARAMS="-v 3 -u ${USER_TRAP_PRIV} -l authPriv -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} -x ${PRIV_PROTOCOL} -X ${PRIV_KEY}"
  60. SET_PARAMS="-v 3 -u ${USER_PRIV} -l authPriv -a ${AUTH_PROTOCOL} -A ${AUTH_KEY} -x ${PRIV_PROTOCOL} -X ${PRIV_KEY}"
  61. else
  62. echo "$0: Unsupported level: $1"
  63. fi
  64. }
  65. while getopts "6e:hl:pt:" OPT ; do
  66. case ${OPT} in
  67. 6) IPV6=1 ;;
  68. e) TRAP_ENGINEID=${OPTARG} ;;
  69. h) usage ;;
  70. l) LEVEL=${OPTARG} ;;
  71. p) PRINT_ONLY=1 ;;
  72. t) HOST=${OPTARG} ;;
  73. esac
  74. done
  75. shift $((OPTIND - 1))
  76. get_auth_parameters ${LEVEL}
  77. if (( IPV6 )) ; then
  78. PARAMS="${PARAMS} -t udp6"
  79. TRAP_PARAMS="${TRAP_PARAMS} -t udp6"
  80. SET_PARAMS="${SET_PARAMS} -t udp6"
  81. fi
  82. cat >>${CMDS} <<ENDOFCMDS
  83. node ${HOME_DIR}/example/snmp-get.js ${PARAMS} ${HOST} 1.3.6.1.2.1.1.1.0
  84. node ${HOME_DIR}/example/snmp-get-next.js ${PARAMS} ${HOST} 1.3.6.1.2.1.1.1.0
  85. node ${HOME_DIR}/example/snmp-get-bulk.js ${PARAMS} -n 0 -r 5 ${HOST} 1.3.6.1.2.1.1.2.0
  86. node ${HOME_DIR}/example/snmp-walk.js ${PARAMS} ${HOST} 1.3.6.1.6.3.16.1.5.2.1.6.9
  87. node ${HOME_DIR}/example/snmp-subtree.js ${PARAMS} ${HOST} 1.3.6.1.6.3.16.1.5.2.1.4.5
  88. node ${HOME_DIR}/example/snmp-table.js ${PARAMS} ${HOST} 1.3.6.1.2.1.1.9
  89. node ${HOME_DIR}/example/snmp-table-columns.js ${PARAMS} ${HOST} 1.3.6.1.2.1.2.2 2
  90. node ${HOME_DIR}/example/snmp-set.js ${SET_PARAMS} ${HOST} 1.3.6.1.2.1.1.6.0 OctetString Auckland
  91. node ${HOME_DIR}/example/snmp-trap.js -e ${TRAP_ENGINEID} ${TRAP_PARAMS} ${HOST} 1.3.6.1.6.3.1.1.5.2
  92. node ${HOME_DIR}/example/snmp-inform.js ${PARAMS} ${HOST} 1.3.6.1.6.3.1.1.5.2
  93. ENDOFCMDS
  94. COUNT=1
  95. while read CMD ; do
  96. if (( PRINT_ONLY )) ; then
  97. echo ${CMD}
  98. else
  99. CMD_NAME=$(echo ${CMD} | awk '{print $2}' | xargs basename)
  100. echo "${COUNT}. ${CMD_NAME}"
  101. echo ${CMD}
  102. eval ${CMD}
  103. echo
  104. fi
  105. COUNT=$((COUNT+1))
  106. done <${CMDS}
  107. rm -f ${CMDS}