Guest User

Untitled

a guest
Dec 24th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. ## machine info
  2.  
  3. [root@VIRTCENT11 ~]# cat /etc/redhat-release
  4. CentOS release 5.6 (Final)
  5.  
  6. [root@VIRTCENT11 ~]# uname -a
  7. Linux VIRTCENT11 2.6.18-194.el5xen #1 SMP Fri Apr 2 15:34:40 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
  8.  
  9. ## nagios version
  10.  
  11. [root@VIRTCENT11 ~]# /usr/local/nagios/bin/nagios --version
  12.  
  13. Nagios Core 3.2.3
  14. Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
  15. Copyright (c) 1999-2009 Ethan Galstad
  16. Last Modified: 10-03-2010
  17. License: GPL
  18.  
  19.  
  20. ## check_mysqllag plugin error
  21.  
  22. (Return code of 127 is out of bounds - plugin may be missing)
  23.  
  24. ## here is the command definition
  25.  
  26. # check_mysql
  27.  
  28. define command{
  29. command_name check_mysqllag
  30. command_line $USER1$/check_mysqllag -H $HOSTADDRESS$ -p 3306 -v $ARG1$ $ARG2$
  31. }
  32.  
  33.  
  34. ## here is the service definition
  35.  
  36. define service{
  37. use generic-service ; Name of service template to use
  38. hostgroup_name db-servers
  39. service_description MySQL Lag
  40. check_command check_mysqllag
  41. notifications_enabled 0
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48. ## check_mysqllag script
  49.  
  50. [root@virtcent10:/usr/local/nagios/libexec] #cat check_mysqllag
  51. #! /bin/sh
  52.  
  53. STATE_OK=0
  54. STATE_WARNING=1
  55. STATE_CRITICAL=2
  56. STATE_UNKNOWN=3
  57. STATE_DEPENDENT=4
  58. mysqlpath='/usr/bin/mysql'
  59. warn=30
  60. crit=60
  61. null="NULL"
  62. usage1="Usage: $0 -uroot -psecret [-w <warn>] [-c <crit>]"
  63. usage2="<warn> is lag time, in seconds, to warn at. Default is 30."
  64. usage3="<crit> is lag time, in seconds, to be critical at. Default is 60."
  65.  
  66. exitstatus=$STATE_WARNING #default
  67. while test -n "$1"; do
  68. case "$1" in
  69. -c)
  70. crit=$2
  71. shift
  72. ;;
  73. -w)
  74. warn=$2
  75. shift
  76. ;;
  77. -u)
  78. user=$2
  79. shift
  80. ;;
  81. -p)
  82. pass=$2
  83. shift
  84. ;;
  85. -h)
  86. echo $usage1;
  87. echo
  88. echo $usage2;
  89. echo $usage3;
  90. exit $STATE_UNKNOWN
  91. ;;
  92. -H)
  93. host=$2
  94. shift
  95. ;;
  96. *)
  97. echo "Unknown argument: $1"
  98. echo $usage1;
  99. echo
  100. echo $usage2;
  101. echo $usage3;
  102. exit $STATE_UNKNOWN
  103. ;;
  104. esac
  105. shift
  106. done
  107.  
  108. seconds=`$mysqlpath/mysql -u $user -p$pass -e 'show slave status\G' | /bin/grep Seconds_Behind_Master | /bin/cut -f2 -d:`
  109.  
  110. # on the number line, we need to test 6 cases:
  111. # 0-----w-----c----->
  112. # 0, 0<lag<w, w, w<lag<c, c, c<lag
  113. # which we simplify to
  114. # lag>=c, w<=lag<c, 0<=lag<warn
  115.  
  116. # if null, critical
  117. if [ $seconds = $null ]; then
  118. echo CRITICAL - Slave is $seconds seconds behind
  119. exit $STATE_CRITICAL;
  120. fi
  121.  
  122. #w<=lag<c
  123. if [ $seconds -lt $crit ]; then
  124. if [ $seconds -ge $warn ]; then
  125. echo WARNING - Slave is $seconds seconds behind
  126. exit $STATE_WARNING;
  127. fi
  128. fi
  129.  
  130. if [ $seconds -ge $crit ]; then
  131. echo CRITICAL - Slave is $seconds seconds behind
  132. exit $STATE_CRITICAL;
  133. fi
  134.  
  135. # 0<=lag<warn
  136. if [ $seconds -lt $warn ]; then
  137. echo OK - Slave is $seconds seconds behind
  138. exit $STATE_OK;
  139. fi
Add Comment
Please, Sign In to add comment