+

Last commit for install.sh: 61169b603dd2afb7eb193e9826e206863131bf89

Initial commit

Benjamin Renard [2011-01-17 22:19:20]
Initial commit
  1. #!/bin/bash
  2.  
  3. SD=$( dirname $0 )
  4. SD=$( pwd $SD )
  5. SRC=$SD/check_mysql_with_perfdata
  6. DD=/usr/local/lib/nagios/plugins
  7. DST=$DD/check_mysql_with_perfdata
  8.  
  9. NAGIOS_PLUGINS_CFG_DIR=/etc/nagios-plugins/config
  10. NAGIOS_PLUGINS_CFG_DST=$NAGIOS_PLUGINS_CFG_DIR/mysql_with_perfdata.cfg
  11.  
  12. case "$1" in
  13. "-u")
  14. echo "Uninstall plugin : "
  15. echo " - Remove plugin (symbolic link) : $DST"
  16. rm $DST
  17. echo " - Remove configuration file : $NAGIOS_PLUGINS_CFG_DST"
  18. rm $NAGIOS_PLUGINS_CFG_DST
  19. exit 0
  20. ;;
  21. "--reinstall")
  22. $SD/$0 -u
  23. ;;
  24. "-h")
  25. echo "Usage : $0 [-u] [--reinstall] [-h]"
  26. echo " -u Uninstall plugin"
  27. echo " --reinstall Reinstall plugin"
  28. echo " -h Display this message"
  29. exit 0
  30. ;;
  31. esac
  32.  
  33. [ ! -d $DD ] && mkdir -p $DD
  34.  
  35. DO=1
  36. if [ -e $DST ]
  37. then
  38. ASK=1
  39. if [ -L $DST ]
  40. then
  41. D=`ls -l $DST|sed 's/.* -> //'`
  42. if [ "$D" = "$SRC" ]
  43. then
  44. echo "Symbolic link $DST already exist. Pass."
  45. ASK=0
  46. DO=0
  47. fi
  48. fi
  49. if [ $ASK -eq 1 ]
  50. then
  51. echo "File $DST already exists."
  52. echo -n "Abort (Y,n) ? "
  53. read a
  54. [ "$a" != "N" -a "$a" != "n" ] && exit
  55. echo "Saved old file in $DST.orig"
  56. mv $DST $DST.orig
  57. fi
  58. fi
  59.  
  60. [ $DO -eq 1 ] && echo "Create symbolic link for plugin : $DST" && ln -s $SRC $DST
  61.  
  62. [ ! -d $NAGIOS_PLUGINS_CFG_DIR ] && mkdir -p $NAGIOS_PLUGINS_CFG_DIR
  63.  
  64. DO=1
  65. TMP=`mktemp`
  66. echo "# 'check_mysql_with_perfdata' command definition
  67. define command{
  68. command_name check_mysql_with_perfdata
  69. command_line $DST -H '\$HOSTADDRESS\$'
  70. }
  71.  
  72. # 'check_mysql_with_perfdata_cmdlinecred' command definition
  73. define command{
  74. command_name check_mysql_with_perfdata_cmdlinecred
  75. command_line $DST -H '\$HOSTADDRESS\$' -u '\$ARG1\$' -p '\$ARG2\$'
  76. }
  77.  
  78. # 'check_mysql_with_perfdata_database' command definition
  79. define command{
  80. command_name check_mysql_with_perfdata_database
  81. command_line $DST -d '\$ARG3\$' -H '\$HOSTADDRESS\$' -u '\$ARG1\$' -p '\$ARG2\$'
  82. }" > $TMP
  83.  
  84. if [ -e $NAGIOS_PLUGINS_CFG_DST ]
  85. then
  86. ASK=1
  87. if [ ! -n "`diff $NAGIOS_PLUGINS_CFG_DST $TMP`" ]
  88. then
  89. echo "Configuration file $NAGIOS_PLUGINS_CFG_DST already and is correct. Pass."
  90. ASK=0
  91. DO=0
  92. fi
  93. if [ $ASK -eq 1 ]
  94. then
  95. echo "File $NAGIOS_PLUGINS_CFG_DST already exists."
  96. echo -n "Abort (Y,n) ? "
  97. read a
  98. [ "$a" != "N" -a "$a" != "n" ] && exit
  99. echo "Saved old configuration file in $NAGIOS_PLUGINS_CFG_DST.orig"
  100. mv "$NAGIOS_PLUGINS_CFG_DST" "$NAGIOS_PLUGINS_CFG_DST.orig"
  101. fi
  102. fi
  103.  
  104. [ $DO -eq 1 ] && echo "Create configuration file : $NAGIOS_PLUGINS_CFG_DST" && cp $TMP $NAGIOS_PLUGINS_CFG_DST && chmod 644 $NAGIOS_PLUGINS_CFG_DST
  105. rm -f $TMP
  106.  
  107.