groupwise.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/bin/bash
  2. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  3. # License: GNU General Public License v2
  4. # v1.0:
  5. # - Initial release of the script
  6. # v1.1:
  7. # - Aligned quotation marks around variables cosistently
  8. # v1.2:
  9. # - started refining the script to a more modern bash-style
  10. #
  11. # Current active version of the script
  12. SCRIPT_VERSION=1.2
  13. ################################################################
  14. # Global definitions for the script - change to fit your needs #
  15. ################################################################
  16. # Look for a process if a GroupWise MailTransferAgent (MTA) should be running (0 if no MTA is on the client, else set 1)
  17. gwMTA=1
  18. # Look for a process if a GroupWise PostOffice (POA) should be running (0 if no POA is on the client, else set 1)
  19. gwPOA=1
  20. # Look for a process if a GroupWise Internet Agent (GWIA) should be running (0 if no GWIA is on the client, else set 1)
  21. gwIA=1
  22. # Debug switch for development purposes ( 0 for no debug, 1 for debug information )
  23. debug=0
  24. #####################################################################
  25. # DO NOT CHANGE BELOW UNLESS YOU EXACTLY KNOW WHAT YOU ARE DOING #
  26. #####################################################################
  27. if [ "$gwMTA" -eq 1 ]
  28. then
  29. if [ "$debug" -eq 1 ]
  30. then
  31. echo "DEBUG: gwMTA is enabled in config, checking for the process."
  32. fi
  33. gwMTAProcess=$(pgrep -x gwmta)
  34. if [[ -n "$gwMTAProcess" ]]
  35. then
  36. if [ "$debug" -eq 1 ]
  37. then
  38. echo "DEBUG:We found a gwMTA process ID: $gwMTAProcess"
  39. fi
  40. gwMTAListener=$(ss -lpn | grep "$gwMTAProcess" |awk '{print $5}' | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'| sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
  41. if [ ! -z "$gwMTAListener" ]
  42. then
  43. if [ "$debug" -eq 1 ]
  44. then
  45. echo "DEBUG:We found atleast one gwMTA listener: $gwMTAListener"
  46. fi
  47. echo "P \"Groupwise MTA\" status=1;;;1 GroupWise Mail Transfer Agent is running with PID: $gwMTAProcess and listening.\n $gwMTAListener"
  48. else
  49. if [ "$debug" -eq 1 ]
  50. then
  51. echo "DEBUG:We found no listeners for the gwMTA process with process ID: $gwMTAProcess"
  52. fi
  53. echo "P \"Groupwise MTA\" status=0.5;;;1GroupWise Mail Transfer Agent is running with PID: $gwMTAProcess but not listening."
  54. fi
  55. else
  56. if [ "$debug" -eq 1 ]
  57. then
  58. echo "DEBUG: gwMTA is enabled in config, but no processes could be found."
  59. fi
  60. echo "P \"GroupWise MTA\" status=0;;;1 GroupWise Mail Transfer Agent process is not Running."
  61. fi
  62. else
  63. echo "DEBUG: gwMTA is not enabled in config, skipping."
  64. fi
  65. if [ "$gwPOA" -eq 1 ]
  66. then
  67. if [ "$debug" -eq 1 ]
  68. then
  69. echo "DEBUG: gwPOA is enabled in config, checking for the process."
  70. fi
  71. gwPOAProcess=$(pgrep -x gwpoa)
  72. if [ ! -z "$gwPOAProcess" ]
  73. then
  74. if [ "$debug" -eq 1 ]
  75. then
  76. echo "DEBUG:We found a gwPOA process ID: $gwPOAProcess"
  77. fi
  78. gwPOAListener=$(ss -lpn | grep "$gwPOAProcess" |awk '{print $5}' | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' )
  79. if [ ! -z "$gwPOAListener" ]
  80. then
  81. if [ "$debug" -eq 1 ]
  82. then
  83. echo "DEBUG:We found atleast one gwPOA listener: $gwPOAListener"
  84. fi
  85. echo "P \"Groupwise POA\" status=1;;;1 GroupWise Post Office Agent is running with PID: $gwPOAProcess and listening.\n $gwPOAListener"
  86. else
  87. if [ "$debug" -eq 1 ]
  88. then
  89. echo "DEBUG:We found no listeners for the gwPOA process with process ID: $gwPOAProcess"
  90. fi
  91. echo "P \"Groupwise POA\" status=0.5;;;1GroupWise Post Office Agent is running with PID: $gwPOAProcess but not listening."
  92. fi
  93. else
  94. if [ "$debug" -eq 1 ]
  95. then
  96. echo "DEBUG: gwPOA is enabled in config, but no processes could be found."
  97. fi
  98. echo "P \"GroupWise POA\" status=0;;;1 GroupWise Post Office Agent process is not Running."
  99. fi
  100. fi
  101. if [ "$gwIA" -eq 1 ]
  102. then
  103. if [ "$debug" -eq 1 ]
  104. then
  105. echo "DEBUG: gwIA is enabled in config, checking for the process."
  106. fi
  107. gwIAProcess=$(pgrep -x gwia)
  108. if [ ! -z "$gwIAProcess" ]
  109. then
  110. gwIAListener=$(ss -lpn | grep "$gwIAProcess" |awk '{print $5}' | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
  111. if [ ! -z "$gwIAListener" ]
  112. then
  113. if [ "$debug" -eq 1 ]
  114. then
  115. echo "DEBUG:We found atleast one gwIA listener: $gwIAListener"
  116. fi
  117. echo "P \"Groupwise GWIA\" status=1;;;1 GroupWise Internet Agent is running with PID: $gwIAProcess and listening.\n $gwIAListener"
  118. else
  119. if [ "$debug" -eq 1 ]
  120. then
  121. echo "DEBUG:We found no listeners for the gwIA process with process ID: $gwIAProcess"
  122. fi
  123. echo "P \"Groupwise GWIA\" status=0.5;;;1 GroupWise Internet Agent is running with PID: $gwIAProcess but not listening."
  124. fi
  125. else
  126. if [ "$debug" -eq 1 ]
  127. then
  128. echo "DEBUG: gwIA is enabled in config, but no processes could be found."
  129. fi
  130. echo "P \"GroupWise GWIA\" status=0;;;1 GroupWise Internet Agent process is not Running."
  131. fi
  132. fi
  133. gwAdminProcess=$(pgrep -f 'gwadmin\.jar')
  134. if [ ! -z "$gwAdminProcess" ]
  135. then
  136. if [ "$debug" -eq 1 ]
  137. then
  138. echo "DEBUG:We found a gwAdmin process ID: $gwAdminProcess"
  139. fi
  140. gwAdminListener=$(ss -lpn| grep "$gwAdminProcess" | awk '{print $5}' | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u | sed 's/^::ffff://' | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
  141. if [ ! -z "$gwAdminListener" ]
  142. then
  143. if [ "$debug" -eq 1 ]
  144. then
  145. echo "DEBUG:We found atleast one gwAdmin listener: $gwAdminListener"
  146. fi
  147. echo "P \"Groupwise AdminService\" count=1;;;1 GroupWise AdminService process is running with PID: $gwAdminProcess and listening.\n $gwAdminListener"
  148. else
  149. if [ "$debug" -eq 1 ]
  150. then
  151. echo "DEBUG:We found no listeners for the gwAdminService process with process ID: $gwAdminProcess"
  152. fi
  153. echo "P \"Groupwise AdminService\" status=0.5;;;1 GroupWise AdminService is running with PID: $gwAdminProcess but not listening."
  154. fi
  155. else
  156. echo "P \"GroupWise AdminService\" status=0;;;1 GroupWise AdminService process is not Running."
  157. fi