check_procr.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. #
  3. # Check_procr.sh
  4. #
  5. # Program: Process running check plugin for Nagios
  6. # License : GPL
  7. # Copyright (c) 2002 Jerome Tytgat (j.tytgat@sioban.net)
  8. #
  9. # check_procr.sh,v 1.0 2002/09/18 15:28
  10. #
  11. # Description :
  12. #
  13. # This plugin check if at least one process is running
  14. #
  15. # Usage :
  16. #
  17. # check_procr.sh -p process_name
  18. #
  19. # Example :
  20. #
  21. # To know if snort is running
  22. # check_procr.sh -p snort
  23. # > OK - total snort running : PID=23441
  24. #
  25. # Linux Redhat 7.3
  26. #
  27. help_usage() {
  28. echo "Usage:"
  29. echo " $0 -p <process_name>"
  30. echo " $0 (-v | --version)"
  31. echo " $0 (-h | --help)"
  32. }
  33. help_version() {
  34. echo "check_procr.sh (nagios-plugins) 1.0"
  35. echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute"
  36. echo "copies of the plugins under the terms of the GNU General Public License."
  37. echo "For more information about these matters, see the file named COPYING."
  38. echo "Copyright (c) 2002 Jerome Tytgat - j.tytgat@sioban.net"
  39. echo "Greetings goes to Websurg which kindly let me took time to develop this"
  40. echo " Manu Feig and Jacques Kern who were my beta testers, thanks to them !"
  41. }
  42. verify_dep() {
  43. needed="bash cut egrep expr grep let ps sed sort tail test tr wc"
  44. for i in `echo $needed`
  45. do
  46. type $i > /dev/null 2>&1 /dev/null
  47. if [ $? -eq 1 ]
  48. then
  49. echo "I am missing an important component : $i"
  50. echo "Cannot continue, sorry, try to find the missing one..."
  51. exit 3
  52. fi
  53. done
  54. }
  55. myself=$0
  56. verify_dep
  57. if [ "$1" = "-h" -o "$1" = "--help" ]
  58. then
  59. help_version
  60. echo ""
  61. echo "This plugin will check if a process is running."
  62. echo ""
  63. help_usage
  64. echo ""
  65. echo "Required Arguments:"
  66. echo " -p, --process STRING"
  67. echo " process name we want to verify"
  68. echo ""
  69. exit 3
  70. fi
  71. if [ "$1" = "-v" -o "$1" = "--version" ]
  72. then
  73. help_version
  74. exit 3
  75. fi
  76. if [ `echo $@|tr "=" " "|wc -w` -lt 2 ]
  77. then
  78. echo "Bad arguments number (need two)!"
  79. help_usage
  80. exit 3
  81. fi
  82. tt=0
  83. process_name=""
  84. exclude_process_name=""
  85. wt=""
  86. ct=""
  87. # Test of the command lines arguments
  88. while test $# -gt 0
  89. do
  90. case "$1" in
  91. -p|--process)
  92. if [ -n "$process_name" ]
  93. then
  94. echo "Only one --process argument is useful..."
  95. help_usage
  96. exit 3
  97. fi
  98. shift
  99. process_name="`echo $1|tr \",\" \"|\"`"
  100. ;;
  101. *)
  102. echo "Unknown argument $1"
  103. help_usage
  104. exit 3
  105. ;;
  106. esac
  107. shift
  108. done
  109. # ps line construction set...
  110. for i in `ps ho pid -C $process_name`
  111. do
  112. pid_list="$pid_list $i"
  113. done
  114. if [ -z "$pid_list" ]
  115. then
  116. crit=1
  117. else
  118. crit=0
  119. fi
  120. # Finally Inform Nagios of what we found...
  121. if [ $crit -eq 1 ]
  122. then
  123. echo "CRITICAL - process $process_name is not running !"
  124. exit 2
  125. else
  126. echo "OK - process $process_name is running : PID=$pid_list "
  127. exit 0
  128. fi
  129. # Hey what are we doing here ???
  130. exit 3