Prechádzať zdrojové kódy

- check_mk_push hinzugefügt

erdoking 4 rokov pred
rodič
commit
b6d0efbb4c

+ 86 - 0
check_mk_push/cmk_send_agentdata.sh

@@ -0,0 +1,86 @@
+#!/bin/bash
+# +------------------------------------------------------------------+
+# |             ____ _               _        __  __ _  __           |
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
+# |                                                                  |
+# | Copyright Jonas Nickl 2016             development@ichalsroot.de |
+# +------------------------------------------------------------------+
+#
+# This file is an addon for Check_MK.
+# The official homepage for this check is at https://blog.ichalsroot.de
+#
+# check_mk is free software;  you can redistribute it and/or modify it
+# under the  terms of the  GNU General Public License  as published by
+# the Free Software Foundation in version 2.  check_mk is  distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
+# tails. You should have  received  a copy of the  GNU  General Public
+# License along with GNU Make; see the file  COPYING.  If  not,  write
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+HOSTNAME=`hostname`
+MK_CONFDIR=/etc/check_mk
+
+## DEBUG Level (BOOL)
+if [ "$1" == "--debug" ] ; then DEBUG="1"; fi
+
+be_done()
+{
+    echo "RC=$STATUS"
+    ## bad returncode if status nok
+    if [ "$STATUS" != "OK" ]; then exit 1; fi
+}
+
+validate()
+## Verify config dir exists and that the config file exists
+{
+    if [ -d $MK_CONFDIR ]                                    && 
+       [ -r $MK_CONFDIR/cmkserver.cfg ]                      &&
+         OMDURL=`grep OMDURL      $MK_CONFDIR/cmkserver.cfg | cut -f2 -d\= | sed 's/"//g'` &&
+         OMDUSER=`grep OMDUSER    $MK_CONFDIR/cmkserver.cfg | cut -f2 -d\= | sed 's/"//g'` &&
+         OMDPASS=`grep OMDPASS    $MK_CONFDIR/cmkserver.cfg | cut -f2 -d\= | sed 's/"//g'`    
+    then
+        export OMDURL OMDUSER OMDPASS
+    else
+        echo "Please set OMDURL, OMDUSER and OMDPASS in"
+        echo "$MK_CONFDIR/cmkserver.cfg"
+        exit 1
+    fi
+    if ! `which check_mk_agent >/dev/null`; then
+        echo "check_mk_agent was not found in path, please install it." 
+        exit 1
+    fi
+    if ! `which curl >/dev/null`; then
+        echo "curl was not found in path, please install it." 
+        exit 1
+    fi
+
+}
+
+get_result()
+{
+   ## decode agent output with base64, remove line breaks and replace plus with html +
+   export DATA=$(check_mk_agent | base64 --wrap=0 | sed 's/+/%2b/g' )
+}
+
+send_result()
+{
+    [ $DEBUG ] && echo "curl -X POST --silent --user $OMDUSER:$OMDPASS --data \"DATA=$DATA&HOSTNAME=$HOSTNAME&DEBUG=$DEBUG\" $OMDURL" 
+    STATUS=$(curl -X POST --silent --user $OMDUSER:$OMDPASS --data "DATA=$DATA&HOSTNAME=$HOSTNAME&DEBUG=$DEBUG" "$OMDURL")
+    
+    if [ $? != 0 ]; then
+        echo "Failed to submit agent output via CURL"
+    fi
+}
+
+   ## main :)
+   validate    &&
+   get_result  &&
+   send_result 
+   ## print return
+   be_done

+ 4 - 0
check_mk_push/cmkserver.cfg

@@ -0,0 +1,4 @@
+## Don't use inverted comma!
+OMDURL=https://www.meinhost.de/omd/mk_agentdata.php
+OMDUSER=remoteuser
+OMDPASS=abC123supergeheimesPassWort

+ 61 - 0
check_mk_push/mk_agentdata.php

@@ -0,0 +1,61 @@
+<?php
+# +------------------------------------------------------------------+
+# |             ____ _               _        __  __ _  __           |
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
+# |                                                                  |
+# | Copyright Jonas Nickl 2016             development@ichalsroot.de |
+# +------------------------------------------------------------------+
+#
+# This file is an addon for Check_MK.
+# The official homepage for this check is at https://blog.ichalsroot.de
+#
+# check_mk is free software;  you can redistribute it and/or modify it
+# under the  terms of the  GNU General Public License  as published by
+# the Free Software Foundation in version 2.  check_mk is  distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
+# tails. You should have  received  a copy of the  GNU  General Public
+# License along with GNU Make; see the file  COPYING.  If  not,  write
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+## just for debug
+#error_reporting(E_ALL);
+
+## read given data
+$HOSTNAME = $_POST["HOSTNAME"];
+$MESSAGE = base64_decode($_POST["DATA"]);
+$DEBUG = $_POST["DEBUG"];
+
+## Check if data given
+if (!$HOSTNAME){ die( "No hostname!"); }
+if (!$MESSAGE){ die( "No data!"); }
+
+## get omd path
+$FULLPATH = getcwd();
+$SITEROOT = str_replace("var/www", "", "$FULLPATH");
+
+## debug output
+if ($DEBUG){ echo "[DEBUG] SITEROOT = $SITEROOT"; }
+
+## open filehandle
+$FILEHANDLE = fopen( $SITEROOT."var/tmp/cmkresult.".$HOSTNAME,"w");
+
+## write agentoutput
+fwrite($FILEHANDLE, $MESSAGE );
+
+## check if file written correctly
+if ($FILEHANDLE === false) {
+        die("ERROR: Unable to write cmkresult_".$HOSTNAME);
+} else {
+        if ($DEBUG){ echo "DEBUG=$MESSAGE"; }
+        echo "OK";
+
+}
+fclose($FILEHANDLE);
+
+?>

+ 2 - 0
check_mk_push/readme.txt

@@ -0,0 +1,2 @@
+ - Vollständige Dokumentation hier: https://blog.ichalsroot.de/entfernte-checkmk-agents-ueberwachen-sshtls/
+ - Die Scripte werden hier nur zur Versionsdokumentation gesammelt