oacron.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. * Copyright (C) 2012 Leah Rowe <info@minifree.org>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /*
  25. * This checks each server in the database and emails all admins if a server
  26. * goes down or if an offline server comes back online.
  27. * In addition to email, this will create a log entry in the database if any
  28. * event is found.
  29. */
  30. include "common.php";
  31. function serverCheck()
  32. {
  33. $qstat = qstatArray();
  34. $server = serverArray();
  35. for ($i = 0; $i < count($server["full"]); $i++)
  36. {
  37. $serverfound = false;
  38. for ($j = 0; $j < count($qstat["content"]); $j++)
  39. {
  40. $serverfound |= strpos($qstat["content"][$j],
  41. $server["full"][$i]) !== false;
  42. }
  43. if ($serverfound && $server["serverdown"][$i] == "1")
  44. /*
  45. * Server was listed as down (serverdown='1'), but is
  46. * now back online, so update serverdown='0', then
  47. * record a log and send an email to all admins
  48. */
  49. inject("UPDATE servers SET serverdown='0' WHERE ".
  50. "(ipaddr = '".$server["ipaddr"][$i]."' AND ".
  51. "portnum = '".$server["portnum"][$i]."')");
  52. record("Server '".$server["full"][$i]."' back online,".
  53. " having previously been offline",
  54. "oacron.php");
  55. compose("Server '".$server["full"][$i]."' back online",
  56. "Please check log entries.\n\nGenerated by ".
  57. "oacron.php");
  58. }
  59. // server not found on any specified QStat v2.11 lists
  60. else if ($server["serverdown"][$i] == "0")
  61. /*
  62. * Server was listed as online (serverdown='0'), but
  63. * is now offline, so update serverdown='1', then
  64. * record a log and send an email to all admins
  65. */
  66. inject("UPDATE servers SET serverdown='1' WHERE ".
  67. "(ipaddr = '".$server["ipaddr"][$i]."' AND ".
  68. "portnum = '".$server["portnum"][$i]."')");
  69. record("Server '".$server["full"][$i]."' has gone ".
  70. "offline, having previously been online",
  71. "oacron.php");
  72. compose("Server '".$server["full"][$i]."' has gone ".
  73. "offline","Please check log entries.".
  74. "\n\nGenerated by oacron.php");
  75. }
  76. }
  77. return "server check was performed";
  78. }
  79. serverCheck();
  80. ?>