check_nt_memory_process.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. #Date: 11.04.08
  3. #Author: Christian Mies (cmies@itnovum.de)
  4. #Version 0.0.1
  5. #About: Take Working Set Perfmon Value of specified Process and calculate it to MB
  6. # ./check_nt -H <HOSTNAME> -p 1248 -v COUNTER -l "\\Process(NSClient++)\Working Set","Belegter Arbeitsspeicher NSClient++,Byte"
  7. #typeset -i mb crit warn
  8. pluginpath="/usr/lib/nagios/plugins"
  9. pluginname=`basename $0`
  10. . $pluginpath/utils.sh
  11. while getopts "H:p:s:P:L:w:c:" options; do
  12. case $options in
  13. H)hostname=$OPTARG;;
  14. p)port=$OPTARG;;
  15. P)process=$OPTARG;;
  16. L)language=$OPTARG;;
  17. s)secret=$OPTARG;;
  18. w)warn=$OPTARG;;
  19. c)crit=$OPTARG;;
  20. *)
  21. echo "$pluginname Help:"
  22. echo "-----------------"
  23. echo "-H <Hostname> : Hostname/IP of Citrix Enterprise Server 4"
  24. echo "-p <portnumber>: NSClient++ Port Default: 1248"
  25. echo "-s <secret>: NSClient++ secret"
  26. echo "-P Process: Which Process to check?"
  27. echo "-L Language: Language for Perfmon. Values: german/english Default: english"
  28. echo "-----------------"
  29. echo "Usage: $pluginname -H <HOSTADDRESS> -p <port> -s <secret> -P <processname> -L <language> -w <warn> -c <crit>"
  30. exit 3
  31. ;;
  32. esac
  33. done
  34. if [ -z $port ]; then
  35. port=1248;
  36. fi;
  37. if [ -z $language ]; then
  38. language="english";
  39. fi;
  40. if [ -z $process ]; then
  41. echo "UNKNOWN: Missing Process Name";
  42. exit $STATE_UNKNOWN;
  43. fi;
  44. if [ -z $crit ] || [ -z $warn ]; then
  45. echo "UNKNOWN: Critical / Warning Value must be set";
  46. exit $STATE_UNKNOWN;
  47. fi;
  48. if [ -z $secret ]; then
  49. echo "UNKNOWN: Secret not defined!";
  50. exit $STATE_UNKNOWN;
  51. fi;
  52. if [ $language = "english" ]; then
  53. perfcount_name="Process"
  54. perfcount_value="Working Set"
  55. output="Used Memory of"
  56. perfout="UsedMemory"
  57. fi;
  58. if [ $language = "german" ]; then
  59. perfcount_name="Prozess"
  60. perfcount_value="Arbeitsseiten"
  61. output="Belegter Speicher von"
  62. perfout="Speicer"
  63. fi;
  64. if [ $language = "russian" ]; then
  65. perfcount_name="Процесс"
  66. perfcount_value="Рабочий набор"
  67. output="Использовано памяти"
  68. perfout="UsedMemory"
  69. fi;
  70. command="\\$perfcount_name($process)\\$perfcount_value"
  71. memory=`$pluginpath/check_nt -H $hostname -p $port -s $secret -v COUNTER -l "$command" | tr -d '\n'`
  72. mb=`echo "scale=0; $memory/1048576"|bc -l`
  73. if [ $mb -ge $crit ]; then
  74. echo "CRITICAL: $output $process: $mb MB|$perfout=${mb}MB;$warn;$crit;;;"
  75. exit $STATE_CRITICAL;
  76. fi;
  77. if [ $mb -ge $warn ] && [ $mb -lt $crit ]; then
  78. echo "WARNING: $output $process: $mb MB|$perfout=${mb}MB;$warn;$crit;;;"
  79. exit $STATE_WARNING;
  80. fi;
  81. echo "OK: $output $process: $mb MB|$perfout=${mb}MB;$warn;$crit;;;"
  82. exit $STATE_OK;