1. #!/usr/bin/php -q
  2. <?php
  3. #
  4. # Program : groupwise-handler.php
  5. # :
  6. # Author : Karim vaes <kvaes@vangenechten.com>
  7. # :
  8. # Purpose : Nagios plugin to check the C/S Handler Threads
  9. # :
  10. # Notes : No Support Given
  11. #============:==============================================================
  12. # 1.0 : 25/09/2006
  13. # : Initial coding
  14.  
  15. // FUNCTIONS
  16. function print_usage()
  17. {
  18. echo "Usage: groupwise-handler.php yourgroupwiseserver.yourdomain.com\n";
  19. return 0;
  20. }
  21.  
  22. // CONFIGURATION VARIABLES
  23. $server = $argv[1];
  24. $user = gwweb;
  25. $pass = gwweb;
  26. $port = 7181;
  27. $warn = 1;
  28. $error = 2;
  29.  
  30. // LOAD PAGE FROM MTA
  31. exec("/usr/bin/wget http://$user:$pass@$server:$port/ --output-document=$server-handler.txt -q", $output, $return);
  32.  
  33. // CHECK IF CONNECTION WAS SUCCESFULL
  34. if ($return != 0) { exec("rm $server-handler.txt"); echo "Connection to groupwise -$server- FAILED!"; exit(2);}
  35.  
  36. // PARSING OF THE FILE
  37. $lines = file($server."-handler.txt");
  38. $numSupport = count ($lines);
  39. for ($i = 0; $i < $numSupport; $i++) {
  40. $pos1 = strpos($lines[$i],"csthrd");
  41. if ($pos1 <> false) {
  42. $one = $i;
  43. $two = $i+2;
  44. $thr = $i+4;
  45. $name = trim(strip_tags($lines[$one]));
  46. $max = trim(strip_tags($lines[$two]));
  47. $curr = trim(strip_tags($lines[$thr]));
  48. $info = "$name : current($curr) - max($max)";
  49. }
  50. }
  51.  
  52. // CLEANUP
  53. exec("rm $server-handler.txt");
  54.  
  55. // EXIT
  56. switch (TRUE)
  57. {
  58. case ($curr > $error):
  59. {
  60. $status=2;
  61. echo "ERROR - $info";
  62. break;
  63. }
  64. case ($curr > $warn):
  65. {
  66. $status=1;
  67. echo "WARN - $info";
  68. break;
  69. }
  70. case (1 == 1):
  71. {
  72. $status=0;
  73. echo "INFO - $info";
  74. break;
  75. }
  76. }
  77. exit($status);
  78. ?>
  79.