Newer
Older
ldap / src / ldap-loglevel.sh
  1. #!/bin/bash
  2. ########################################################################
  3. ## Script : ldap-loglevel.sh
  4. ## Name : LDAP のログレベル変更スクリプト
  5. ## Version : 0.0.1
  6. ## Copyright : 2019 Nomura Kei
  7. ## License : BSD-2-Clause
  8. ## Usage:
  9. ## |使用法) ldap-loglevel.sh [オプション] [LogLevel]
  10. ## |
  11. ## | LDAP のログレベルを設定します。
  12. ## | LogLevel の指定が無い場合、stats を設定します。
  13. ## | LogLevel には次の Level の値または、Keyword の文字列を指定可能である。
  14. ## | 複数指定する場合は、Level の値を OR した値を指定すれば良い。
  15. ## |
  16. ## | Level Level(Hex) Keyword Description
  17. ## | -1 any enable all debugging
  18. ## | 0 no debugging (ログ出力なし)
  19. ## | 1 0x1 trace trace function calls
  20. ## | 2 0x2 packets debug packet handling
  21. ## | 4 0x4 args heavy trace debugging
  22. ## | 8 0x8 conns connection management
  23. ## | 16 0x10 BER print out packets sent and received
  24. ## | 32 0x20 filter search filter processing
  25. ## | 64 0x40 config configuration processing
  26. ## | 128 0x80 ACL access control list processing
  27. ## | 256 0x100 stats stats log connections/operations/results
  28. ## | 512 0x200 stats2 stats log entries sent
  29. ## | 1024 0x400 shell print communication with shell backends
  30. ## | 2048 0x800 parse print entry parsing debugging
  31. ## | 16384 0x4000 sync syncrepl consumer processing
  32. ## | 32768 0x8000 none only messages that get logged whatever log level is set
  33. ## |
  34. ## | 詳細は、https://www.openldap.org/doc/admin24/slapdconfig.html を参照のこと。
  35. ## |
  36. ## |[オプション]
  37. ## | -h,--help 使用法を表示します。
  38. ## | -v,--version バージョンを表示します。
  39. ## |
  40. ##
  41. ########################################################################
  42. SCRIPT_FILE=${0}
  43. SCRIPT_DIR=`dirname ${SCRIPT_FILE}`
  44. LIB_DIR=${SCRIPT_DIR}/../lib
  45.  
  46.  
  47. ########################################################################
  48. ##
  49. ## ライブラリのロード
  50. ##
  51. [ -f "${LIB_DIR}/functions.sh" ] && . ${LIB_DIR}/bash-utils.sh
  52.  
  53.  
  54.  
  55. ########################################################################
  56. ##
  57. ## デフォルト値
  58. ##
  59. LOG_LEVEL=stats
  60.  
  61.  
  62.  
  63. ########################################################################
  64. ##
  65. ## 関数群
  66. ##
  67.  
  68. # ======================================================================
  69. # LDAP のログレベルを指定されたログレベルに変更する
  70. # ldif 形式のデータを標準出力します。
  71. #
  72. # @param $1 ログレベル
  73. # ======================================================================
  74. mkldif_for_change_loglevel()
  75. {
  76. cat << EOF
  77. dn: cn=config
  78. changeType: modify
  79. replace: olcLogLevel
  80. olcLogLevel: ${LOG_LEVEL}
  81. EOF
  82. }
  83.  
  84.  
  85. ########################################################################
  86. ##
  87. ## メイン処理
  88. ##
  89. for OPT in "$@"; do
  90. case "${OPT}" in
  91. '-h'|'--help') usage; exit 1 ;;
  92. '-v'|'--version') version; exit 1 ;;
  93. -*)
  94. usage
  95. exit 1
  96. ;;
  97. *)
  98. if [[ ! -z "$1" ]] && [[ ! "$1" =~ ^-+ ]]; then
  99. LOG_LEVEL=("$1")
  100. shift 1
  101. fi
  102. ;;
  103. esac
  104. done
  105.  
  106. TMP_LDIF=$(mktemp /tmp/ldap.XXXXXXXXXXXX.ldif)
  107. trap 'rm -f ${TMP_LDIF}; exit 1' 1 2 3 15
  108.  
  109. mkldif_for_change_loglevel ${LOG_LEVEL} > ${TMP_LDIF}
  110. ldapmodify -Y EXTERNAL -H ldapi:/// -f ${TMP_LDIF}
  111. ldapsearch -Y EXTERNAL -H ldapi:/// -b 'cn=config' cn=config
  112.  
  113. rm -f ${TMP_LDIF}
  114.