From 76674b4a631623bf7f82c43eb8532ef5ea8b9d06 Mon Sep 17 00:00:00 2001
From: darode <drd.sqki@gmail.com>
Date: Tue, 15 Mar 2011 18:30:31 +0000
Subject: [PATCH] 2011-03-13 Dario Rodriguez <dario.rodriguez@artica.es>

	*util/plugin/babel_plugin/plugin_definition.ini,
	util/plugin/babel_plugin/babel_plugin.sh: Created plugin to connect
	Pandora FMS with Babel Enterprise. You can create a pspz package for
	this plugin.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4093 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_server/ChangeLog                      |  7 ++
 .../util/plugin/babel_plugin/babel_plugin.sh  | 96 +++++++++++++++++++
 .../plugin/babel_plugin/plugin_definition.ini | 14 +++
 3 files changed, 117 insertions(+)
 create mode 100755 pandora_server/util/plugin/babel_plugin/babel_plugin.sh
 create mode 100644 pandora_server/util/plugin/babel_plugin/plugin_definition.ini

diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog
index 0b0872daba..7a5b0ff129 100644
--- a/pandora_server/ChangeLog
+++ b/pandora_server/ChangeLog
@@ -1,3 +1,10 @@
+2011-03-13 Dario Rodriguez <dario.rodriguez@artica.es>
+
+	*util/plugin/babel_plugin/plugin_definition.ini, 
+	util/plugin/babel_plugin/babel_plugin.sh: Created plugin to connect 
+	Pandora FMS with Babel Enterprise. You can create a pspz package for
+	this plugin.
+
 2011-03-15  Sancho Lerena <slerena@artica.es>
 
 	* util/recon_scripts/snmpdevices.pl: Fixed a typo in interface
diff --git a/pandora_server/util/plugin/babel_plugin/babel_plugin.sh b/pandora_server/util/plugin/babel_plugin/babel_plugin.sh
new file mode 100755
index 0000000000..9906a044f7
--- /dev/null
+++ b/pandora_server/util/plugin/babel_plugin/babel_plugin.sh
@@ -0,0 +1,96 @@
+#!/bin/bash
+# Babel Integration Plugin for Pandora FMS
+# This plugin uses Bable Enterprise API
+# (c) Dario Rodriguez 2011
+
+BABEL_CONSOLE_PATH=""
+USER=""
+KEY=""
+REQUEST=""
+PARAMS=""
+TOKEN=","
+
+# Help menu
+
+function help {
+	echo -e "Babel Integration Pandora FMS Plugin. http://pandorafms.com" 
+	echo -e "Syntax:" 
+	echo -e "\t\t-c   : babel console path"	
+	echo -e "\t\t-u   : user"
+	echo -e "\t\t[-k] : API key (required if key is set on babel console)"	
+	echo -e "\t\t-r   : request"
+	echo -e "\t\t[-f] : parameters (default '')"
+	echo -e "\t\t[-s] : separator token (default ',')"
+	echo -e "Samples:"
+	echo "   ./babel_plugin.sh -s http://127.0.0.1/babel_console -u user -r host_risk -f main_server"
+	echo ""
+	exit
+}
+
+# Show help if there is no parameters
+
+if [ $# -eq 0 ]
+then
+	help
+fi
+
+# Main parsing code
+
+while getopts ":hc:u:k:r:f:s:" optname
+  do
+    case "$optname" in
+      "h")
+	        help
+		;;
+      "c")
+		BABEL_CONSOLE_PATH=$OPTARG
+        ;;
+      "u")
+		USER=$OPTARG
+        ;;
+      "k")
+		KEY=$OPTARG
+        ;;
+      "r")
+		REQUEST=$OPTARG
+        ;;
+      "f")
+		PARAMS=$OPTARG
+        ;;                        
+      "s")
+		TOKEN=$OPTARG
+        ;;        
+       ?)
+		help
+		;;
+      default) 
+		help
+	;;
+     
+    esac
+done
+
+# Create API call
+
+API_CALL=$BABEL_CONSOLE_PATH"/include/api.php?user="$USER"&pass="$KEY"&op="$REQUEST"&params="$PARAMS"&token="$TOKEN
+
+# Execute call with wget
+DATE=`date +%s%N`
+FILE_OUTPUT="temp$DATE"
+
+wget $API_CALL -o /dev/null -O "$FILE_OUTPUT"
+
+# Check if wget was OK
+
+if [ $? -eq 0 ]; then
+ output=`cat "$FILE_OUTPUT"`
+ 
+ # Check if API call returns some valuer not
+ 
+ if [ "$output" != "" ]; then
+	echo -n $output
+ fi
+ 
+fi
+
+rm "$FILE_OUTPUT"
diff --git a/pandora_server/util/plugin/babel_plugin/plugin_definition.ini b/pandora_server/util/plugin/babel_plugin/plugin_definition.ini
new file mode 100644
index 0000000000..e1a0e3ddca
--- /dev/null
+++ b/pandora_server/util/plugin/babel_plugin/plugin_definition.ini
@@ -0,0 +1,14 @@
+; This is a sample configuration file
+; Comments start with ';', as in php.ini
+
+[plugin_definition]
+name = Bable Integration Plugin
+filename = babel_plugin.sh
+description = This plugin allow the integration between Pandora FMS and Babel Enterprise.
+timeout = 300
+ip_opt = -c
+user_opt = -u
+port_opt = 
+pass_opt =
+plugin_type = 0
+total_modules_provided = 0