mk_agentdata.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. # +------------------------------------------------------------------+
  3. # | ____ _ _ __ __ _ __ |
  4. # | / ___| |__ ___ ___| | __ | \/ | |/ / |
  5. # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
  6. # | | |___| | | | __/ (__| < | | | | . \ |
  7. # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
  8. # | |
  9. # | Copyright Jonas Nickl 2016 development@ichalsroot.de |
  10. # +------------------------------------------------------------------+
  11. #
  12. # This file is an addon for Check_MK.
  13. # The official homepage for this check is at https://blog.ichalsroot.de
  14. #
  15. # check_mk is free software; you can redistribute it and/or modify it
  16. # under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation in version 2. check_mk is distributed
  18. # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
  19. # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  20. # PARTICULAR PURPOSE. See the GNU General Public License for more de-
  21. # tails. You should have received a copy of the GNU General Public
  22. # License along with GNU Make; see the file COPYING. If not, write
  23. # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  24. # Boston, MA 02110-1301 USA.
  25. ## just for debug
  26. #error_reporting(E_ALL);
  27. ## read given data
  28. $HOSTNAME = $_POST["HOSTNAME"];
  29. $MESSAGE = base64_decode($_POST["DATA"]);
  30. $DEBUG = $_POST["DEBUG"];
  31. ## Check if data given
  32. if (!$HOSTNAME){ die( "No hostname!"); }
  33. if (!$MESSAGE){ die( "No data!"); }
  34. ## get omd path
  35. $FULLPATH = getcwd();
  36. $SITEROOT = str_replace("var/www", "", "$FULLPATH");
  37. ## debug output
  38. if ($DEBUG){ echo "[DEBUG] SITEROOT = $SITEROOT"; }
  39. ## open filehandle
  40. $FILEHANDLE = fopen( $SITEROOT."var/tmp/cmkresult.".$HOSTNAME,"w");
  41. ## write agentoutput
  42. fwrite($FILEHANDLE, $MESSAGE );
  43. ## check if file written correctly
  44. if ($FILEHANDLE === false) {
  45. die("ERROR: Unable to write cmkresult_".$HOSTNAME);
  46. } else {
  47. if ($DEBUG){ echo "DEBUG=$MESSAGE"; }
  48. echo "OK";
  49. }
  50. fclose($FILEHANDLE);
  51. ?>