From 5318237f81f4e8ab48e9023033d42a3af8051be9 Mon Sep 17 00:00:00 2001 From: slerena Date: Tue, 29 Dec 2009 16:40:50 +0000 Subject: [PATCH] 2009-12-29 Sancho Lerena * lib/PandoraFMS/Core.pm: Fixed problem generating events with character ' that makes SQL queries in console to fail. * util/plugin/webcheck_plugin.sh: Christmas extra :-). Plugin to check WEB content change (by MD5 stamp). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2255 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 8 ++ pandora_server/lib/PandoraFMS/Core.pm | 2 +- pandora_server/util/plugin/webcheck_plugin.sh | 81 +++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 pandora_server/util/plugin/webcheck_plugin.sh diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 44bcedd134..691ff432eb 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2009-12-29 Sancho Lerena + + * lib/PandoraFMS/Core.pm: Fixed problem generating events with + character ' that makes SQL queries in console to fail. + + * util/plugin/webcheck_plugin.sh: Christmas extra :-). Plugin + to check WEB content change (by MD5 stamp). + 2009-12-28 Sancho Lerena * lib/Config.pm: pandora_exec default at /usr/bin diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 4244e74ac6..992693bff3 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -814,7 +814,7 @@ sub pandora_create_agent ($$$$$$$$$$$) { my $agent_id = db_insert ($dbh, 'INSERT INTO tagente (`nombre`, `direccion`, `comentarios`, `id_grupo`, `id_os`, `server_name`, `intervalo`, `id_parent`, `modo`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)', $agent_name, $address, $description, $group_id, $os_id, $server_name, $interval, $parent_id); - pandora_event ($pa_config, "Agent '$agent_name' created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', $dbh); + pandora_event ($pa_config, "Agent [$agent_name] created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', $dbh); return $agent_id; } diff --git a/pandora_server/util/plugin/webcheck_plugin.sh b/pandora_server/util/plugin/webcheck_plugin.sh new file mode 100755 index 0000000000..0caaae83d0 --- /dev/null +++ b/pandora_server/util/plugin/webcheck_plugin.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# WEB Content Stampg server pluin +# (c) Sancho Lerena 2010 + + +# Default values +URL="" +HASH="" +TEST=0 +TIMEOUT=10 + +function help { + echo -e "" + echo -e "WEB content stamp Plugin for Pandora FMS Plugin server. http://pandorafms.com" + echo -e "Syntax:" + echo -e "\t\t-u url For example: http://pandorafms.org/index.html" + echo -e "\t\t-m md5hash MD5 hash passed as parameter to check remote content" + echo -e "\t\t-g Use this parameter to get MD5 on command line" + echo -e "Samples:\n" + echo " ./webcheck_plugin.sh -u http://pandorafms.org -m 79ea72005e5505d99d2548e1b2189857" + echo "" + echo -e "Please note that -g parameter is used only in command line to get the valid MD5sum to use in the check" + exit +} + +if [ $# -eq 0 ] +then + help +fi + +# Sample of full exec +# wget http://192.168.70.103/pandora_console/index.php -O /dev/stdout -o /dev/null | md5sum + +# Main parsing code + +while getopts ":h:gm:u:" optname + do + case "$optname" in + "h") + help + ;; + "m") + HASH=$OPTARG + ;; + "u") + URL=$OPTARG + ;; + "g") + TEST=1 + ;; + ?) + help + ;; + default) + help + ;; + + esac +done + +if [ -z "$URL" ] +then + help +fi + +if [ $TEST == 1 ] +then + wget $URL -T $TIMEOUT -O /dev/stdout -o /dev/null | md5sum | awk '{ print $1 }' + exit +fi + + +# execution +REAL_HASH=`wget $URL -T $TIMEOUT -O /dev/stdout -o /dev/null | md5sum | awk '{ print $1 }'` +if [ "$REAL_HASH" == "$HASH" ] +then + echo 1 +else + echo 0 +fi +